You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.0KB

  1. /*
  2. * log functions
  3. * Copyright (c) 2003 Michel Bardiaux
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. /**
  20. * @file log.c
  21. * log.
  22. */
  23. #include "avutil.h"
  24. int av_log_level = AV_LOG_INFO;
  25. static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
  26. {
  27. static int print_prefix=1;
  28. AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
  29. if(level>av_log_level)
  30. return;
  31. #undef fprintf
  32. if(print_prefix && avc) {
  33. fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc);
  34. }
  35. #define fprintf please_use_av_log
  36. print_prefix= strstr(fmt, "\n") != NULL;
  37. vfprintf(stderr, fmt, vl);
  38. }
  39. #if LIBAVUTIL_VERSION_INT < (50<<16)
  40. static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
  41. #else
  42. void (*av_vlog)(void*, int, const char*, va_list) = av_log_default_callback;
  43. #endif
  44. void av_log(void* avcl, int level, const char *fmt, ...)
  45. {
  46. va_list vl;
  47. va_start(vl, fmt);
  48. av_vlog(avcl, level, fmt, vl);
  49. va_end(vl);
  50. }
  51. #if LIBAVUTIL_VERSION_INT < (50<<16)
  52. void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
  53. {
  54. av_log_callback(avcl, level, fmt, vl);
  55. }
  56. int av_log_get_level(void)
  57. {
  58. return av_log_level;
  59. }
  60. void av_log_set_level(int level)
  61. {
  62. av_log_level = level;
  63. }
  64. void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
  65. {
  66. av_log_callback = callback;
  67. }
  68. #endif