AndroidCodecFactoryHelper.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "AndroidCodecFactoryHelper.h"
  2. #include <pthread.h>
  3. #include <memory>
  4. #include "rtc_base/checks.h"
  5. #include "rtc_base/ignore_wundef.h"
  6. #include "rtc_base/logging.h"
  7. #include "sdk/android/native_api/base/init.h"
  8. #include "sdk/android/native_api/codecs/wrapper.h"
  9. #include "sdk/android/native_api/jni/class_loader.h"
  10. #include "sdk/android/native_api/jni/jvm.h"
  11. #include "sdk/android/native_api/jni/scoped_java_ref.h"
  12. using namespace ::webrtc;
  13. namespace unity {
  14. namespace webrtc {
  15. std::unique_ptr<VideoEncoderFactory> CreateAndroidEncoderFactory() {
  16. JNIEnv* env = AttachCurrentThreadIfNeeded();
  17. RTC_DCHECK(env);
  18. ScopedJavaLocalRef<jclass> factory_class =
  19. GetClass(env, "org/webrtc/HardwareVideoEncoderFactory");
  20. jmethodID factory_constructor = env->GetMethodID(
  21. factory_class.obj(), "<init>", "(Lorg/webrtc/EglBase$Context;ZZ)V");
  22. ScopedJavaLocalRef<jobject> factory_object(
  23. env, env->NewObject(factory_class.obj(), factory_constructor,
  24. nullptr /* shared_context */,
  25. false /* enable_intel_vp8_encoder */,
  26. true /* enable_h264_high_profile */));
  27. return JavaToNativeVideoEncoderFactory(env, factory_object.obj());
  28. }
  29. std::unique_ptr<VideoDecoderFactory> CreateAndroidDecoderFactory() {
  30. JNIEnv* env = AttachCurrentThreadIfNeeded();
  31. RTC_DCHECK(env);
  32. ScopedJavaLocalRef<jclass> factory_class =
  33. GetClass(env, "org/webrtc/HardwareVideoDecoderFactory");
  34. jmethodID factory_constructor = env->GetMethodID(
  35. factory_class.obj(), "<init>", "(Lorg/webrtc/EglBase$Context;)V");
  36. ScopedJavaLocalRef<jobject> factory_object(
  37. env, env->NewObject(factory_class.obj(), factory_constructor,
  38. nullptr /* shared_context */));
  39. return JavaToNativeVideoDecoderFactory(env, factory_object.obj());
  40. }
  41. } // namespace webrtc
  42. } // namespace unity