ijksdl_extra_log.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*****************************************************************************
  2. * ijksdl_extra_log.c
  3. *****************************************************************************
  4. *
  5. * Copyright (c) 2017 Bilibili
  6. * copyright (c) 2017 Raymond Zheng <raymondzheng1412@gmail.com>
  7. *
  8. * This file is part of ijkPlayer.
  9. *
  10. * ijkPlayer is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * ijkPlayer is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with ijkPlayer; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include "ijksdl_extra_log.h"
  25. #include "ijksdl/android/ijksdl_android_jni.h"
  26. #include <stdio.h>
  27. #define LOG_BUF_SIZE 1024
  28. #ifdef EXTRA_LOG_PRINT
  29. void ffp_log_extra_print(int level, const char *tag, const char *fmt, ...)
  30. {
  31. JNIEnv *env = NULL;
  32. if (JNI_OK != SDL_JNI_SetupThreadEnv(&env)) {
  33. return;
  34. }
  35. va_list ap;
  36. char log_buffer[LOG_BUF_SIZE] = {0};
  37. va_start(ap, fmt);
  38. vsnprintf(log_buffer, LOG_BUF_SIZE, fmt, ap);
  39. va_end(ap);
  40. switch (level) {
  41. case ANDROID_LOG_UNKNOWN:
  42. case ANDROID_LOG_DEFAULT:
  43. case ANDROID_LOG_VERBOSE:
  44. J4AC_BLog__v__withCString__catchAll(env, tag, log_buffer);
  45. break;
  46. case ANDROID_LOG_DEBUG:
  47. J4AC_BLog__d__withCString__catchAll(env, tag, log_buffer);
  48. break;
  49. case ANDROID_LOG_INFO:
  50. J4AC_BLog__i__withCString__catchAll(env, tag, log_buffer);
  51. break;
  52. case ANDROID_LOG_WARN:
  53. J4AC_BLog__w__withCString__catchAll(env, tag, log_buffer);
  54. break;
  55. case ANDROID_LOG_FATAL:
  56. case ANDROID_LOG_SILENT:
  57. case ANDROID_LOG_ERROR:
  58. J4AC_BLog__e__withCString__catchAll(env, tag, log_buffer);
  59. break;
  60. default:
  61. break;
  62. }
  63. }
  64. void ffp_log_extra_vprint(int level, const char *tag, const char *fmt, va_list ap)
  65. {
  66. JNIEnv *env = NULL;
  67. if (JNI_OK != SDL_JNI_SetupThreadEnv(&env)) {
  68. return;
  69. }
  70. char log_buffer[LOG_BUF_SIZE] = {0};
  71. vsnprintf(log_buffer, LOG_BUF_SIZE, fmt, ap);
  72. switch (level) {
  73. case ANDROID_LOG_UNKNOWN:
  74. case ANDROID_LOG_DEFAULT:
  75. case ANDROID_LOG_VERBOSE:
  76. J4AC_BLog__v__withCString__catchAll(env, tag, log_buffer);
  77. break;
  78. case ANDROID_LOG_DEBUG:
  79. J4AC_BLog__d__withCString__catchAll(env, tag, log_buffer);
  80. break;
  81. case ANDROID_LOG_INFO:
  82. J4AC_BLog__i__withCString__catchAll(env, tag, log_buffer);
  83. break;
  84. case ANDROID_LOG_WARN:
  85. J4AC_BLog__w__withCString__catchAll(env, tag, log_buffer);
  86. break;
  87. case ANDROID_LOG_FATAL:
  88. case ANDROID_LOG_SILENT:
  89. case ANDROID_LOG_ERROR:
  90. J4AC_BLog__e__withCString__catchAll(env, tag, log_buffer);
  91. break;
  92. default:
  93. break;
  94. }
  95. }
  96. #endif // EXTRA_LOG_PRINT