OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include <jni.h> |
| 12 |
| 13 #include "webrtc/api/videosourceproxy.h" |
| 14 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" |
| 15 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" |
| 16 #include "webrtc/rtc_base/logging.h" |
| 17 #include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h" |
| 18 #include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h" |
| 19 #include "webrtc/sdk/android/src/jni/androidvideotracksource.h" |
| 20 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" |
| 21 #include "webrtc/sdk/android/src/jni/ownedfactoryandthreads.h" |
| 22 #include "webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h" |
| 23 #include "webrtc/sdk/android/src/jni/videodecoderfactorywrapper.h" |
| 24 |
| 25 namespace webrtc_jni { |
| 26 |
| 27 // TODO(sakal): Remove this once MediaCodecVideoDecoder/Encoder are no longer |
| 28 // used and all applications inject their own codecs. |
| 29 // This is semi broken if someone wants to create multiple peerconnection |
| 30 // factories. |
| 31 static bool use_media_codec_decoder_factory; |
| 32 |
| 33 cricket::WebRtcVideoEncoderFactory* CreateVideoEncoderFactory( |
| 34 JNIEnv* jni, |
| 35 jobject j_encoder_factory) { |
| 36 RTC_DCHECK(j_encoder_factory == nullptr) |
| 37 << "Injectable video encoders are not supported yet."; |
| 38 return new MediaCodecVideoEncoderFactory(); |
| 39 } |
| 40 |
| 41 cricket::WebRtcVideoDecoderFactory* CreateVideoDecoderFactory( |
| 42 JNIEnv* jni, |
| 43 jobject j_decoder_factory) { |
| 44 use_media_codec_decoder_factory = j_decoder_factory == nullptr; |
| 45 |
| 46 if (use_media_codec_decoder_factory) { |
| 47 return new MediaCodecVideoDecoderFactory(); |
| 48 } else { |
| 49 return new VideoDecoderFactoryWrapper(jni, j_decoder_factory); |
| 50 } |
| 51 } |
| 52 |
| 53 jobject GetJavaSurfaceTextureHelper( |
| 54 const rtc::scoped_refptr<SurfaceTextureHelper>& surface_texture_helper) { |
| 55 return surface_texture_helper |
| 56 ? surface_texture_helper->GetJavaSurfaceTextureHelper() |
| 57 : nullptr; |
| 58 } |
| 59 |
| 60 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource) |
| 61 (JNIEnv* jni, |
| 62 jclass, |
| 63 jlong native_factory, |
| 64 jobject j_surface_texture_helper, |
| 65 jboolean is_screencast) { |
| 66 OwnedFactoryAndThreads* factory = |
| 67 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
| 68 |
| 69 rtc::scoped_refptr<webrtc::AndroidVideoTrackSource> source( |
| 70 new rtc::RefCountedObject<webrtc::AndroidVideoTrackSource>( |
| 71 factory->signaling_thread(), jni, j_surface_texture_helper, |
| 72 is_screencast)); |
| 73 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source = |
| 74 webrtc::VideoTrackSourceProxy::Create(factory->signaling_thread(), |
| 75 factory->worker_thread(), source); |
| 76 |
| 77 return (jlong)proxy_source.release(); |
| 78 } |
| 79 |
| 80 JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack) |
| 81 (JNIEnv* jni, jclass, jlong native_factory, jstring id, jlong native_source) { |
| 82 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
| 83 factoryFromJava(native_factory)); |
| 84 rtc::scoped_refptr<webrtc::VideoTrackInterface> track( |
| 85 factory->CreateVideoTrack( |
| 86 JavaToStdString(jni, id), |
| 87 reinterpret_cast<webrtc::VideoTrackSourceInterface*>(native_source))); |
| 88 return (jlong)track.release(); |
| 89 } |
| 90 |
| 91 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions) |
| 92 (JNIEnv* jni, |
| 93 jclass, |
| 94 jlong native_factory, |
| 95 jobject local_egl_context, |
| 96 jobject remote_egl_context) { |
| 97 OwnedFactoryAndThreads* owned_factory = |
| 98 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
| 99 |
| 100 jclass j_eglbase14_context_class = |
| 101 FindClass(jni, "org/webrtc/EglBase14$Context"); |
| 102 |
| 103 MediaCodecVideoEncoderFactory* encoder_factory = |
| 104 static_cast<MediaCodecVideoEncoderFactory*>( |
| 105 owned_factory->encoder_factory()); |
| 106 if (encoder_factory && |
| 107 jni->IsInstanceOf(local_egl_context, j_eglbase14_context_class)) { |
| 108 LOG(LS_INFO) << "Set EGL context for HW encoding."; |
| 109 encoder_factory->SetEGLContext(jni, local_egl_context); |
| 110 } |
| 111 |
| 112 MediaCodecVideoDecoderFactory* decoder_factory = |
| 113 static_cast<MediaCodecVideoDecoderFactory*>( |
| 114 owned_factory->decoder_factory()); |
| 115 if (use_media_codec_decoder_factory && decoder_factory) { |
| 116 LOG(LS_INFO) << "Set EGL context for HW decoding."; |
| 117 decoder_factory->SetEGLContext(jni, remote_egl_context); |
| 118 } |
| 119 } |
| 120 |
| 121 } // namespace webrtc_jni |
OLD | NEW |