2
0

jni.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * JNI public API functions
  3. *
  4. * Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "config.h"
  23. #include <stdlib.h>
  24. #include "libavutil/error.h"
  25. #include "jni.h"
  26. #if CONFIG_JNI
  27. #include <jni.h>
  28. #include <pthread.h>
  29. #include "libavutil/log.h"
  30. #include "ffjni.h"
  31. void *java_vm;
  32. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  33. int av_jni_set_java_vm(void *vm, void *log_ctx)
  34. {
  35. int ret = 0;
  36. pthread_mutex_lock(&lock);
  37. if (java_vm == NULL) {
  38. java_vm = vm;
  39. } else if (java_vm != vm) {
  40. ret = AVERROR(EINVAL);
  41. av_log(log_ctx, AV_LOG_ERROR, "A Java virtual machine has already been set");
  42. }
  43. pthread_mutex_unlock(&lock);
  44. return ret;
  45. }
  46. void *av_jni_get_java_vm(void *log_ctx)
  47. {
  48. void *vm;
  49. pthread_mutex_lock(&lock);
  50. vm = java_vm;
  51. pthread_mutex_unlock(&lock);
  52. return vm;
  53. }
  54. #else
  55. int av_jni_set_java_vm(void *vm, void *log_ctx)
  56. {
  57. return AVERROR(ENOSYS);
  58. }
  59. void *av_jni_get_java_vm(void *log_ctx)
  60. {
  61. return NULL;
  62. }
  63. #endif