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/base/logging.h" |
| 15 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" |
| 16 #include "webrtc/media/engine/webrtcvideoencoderfactory.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 |
| 24 using cricket::WebRtcVideoDecoderFactory; |
| 25 using cricket::WebRtcVideoEncoderFactory; |
| 26 using webrtc::AndroidVideoTrackSource; |
| 27 using webrtc::AudioSourceInterface; |
| 28 using webrtc::VideoTrackSourceInterface; |
| 29 using webrtc::VideoTrackInterface; |
| 30 |
| 31 namespace webrtc_jni { |
| 32 |
| 33 WebRtcVideoEncoderFactory* CreateVideoEncoderFactory() { |
| 34 return new MediaCodecVideoEncoderFactory(); |
| 35 } |
| 36 |
| 37 WebRtcVideoDecoderFactory* CreateVideoDecoderFactory() { |
| 38 return new MediaCodecVideoDecoderFactory(); |
| 39 } |
| 40 |
| 41 jobject GetJavaSurfaceTextureHelper( |
| 42 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper) { |
| 43 return surface_texture_helper |
| 44 ? surface_texture_helper->GetJavaSurfaceTextureHelper() |
| 45 : nullptr; |
| 46 } |
| 47 |
| 48 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource) |
| 49 (JNIEnv* jni, |
| 50 jclass, |
| 51 jlong native_factory, |
| 52 jobject j_surface_texture_helper, |
| 53 jboolean is_screencast) { |
| 54 OwnedFactoryAndThreads* factory = |
| 55 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
| 56 |
| 57 rtc::scoped_refptr<webrtc::AndroidVideoTrackSource> source( |
| 58 new rtc::RefCountedObject<webrtc::AndroidVideoTrackSource>( |
| 59 factory->signaling_thread(), jni, j_surface_texture_helper, |
| 60 is_screencast)); |
| 61 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source = |
| 62 webrtc::VideoTrackSourceProxy::Create(factory->signaling_thread(), |
| 63 factory->worker_thread(), source); |
| 64 |
| 65 return (jlong)proxy_source.release(); |
| 66 } |
| 67 |
| 68 JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack) |
| 69 (JNIEnv* jni, jclass, jlong native_factory, jstring id, jlong native_source) { |
| 70 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
| 71 factoryFromJava(native_factory)); |
| 72 rtc::scoped_refptr<VideoTrackInterface> track(factory->CreateVideoTrack( |
| 73 JavaToStdString(jni, id), |
| 74 reinterpret_cast<VideoTrackSourceInterface*>(native_source))); |
| 75 return (jlong)track.release(); |
| 76 } |
| 77 |
| 78 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions) |
| 79 (JNIEnv* jni, |
| 80 jclass, |
| 81 jlong native_factory, |
| 82 jobject local_egl_context, |
| 83 jobject remote_egl_context) { |
| 84 OwnedFactoryAndThreads* owned_factory = |
| 85 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
| 86 |
| 87 jclass j_eglbase14_context_class = |
| 88 FindClass(jni, "org/webrtc/EglBase14$Context"); |
| 89 |
| 90 MediaCodecVideoEncoderFactory* encoder_factory = |
| 91 static_cast<MediaCodecVideoEncoderFactory*>( |
| 92 owned_factory->encoder_factory()); |
| 93 if (encoder_factory && |
| 94 jni->IsInstanceOf(local_egl_context, j_eglbase14_context_class)) { |
| 95 LOG(LS_INFO) << "Set EGL context for HW encoding."; |
| 96 encoder_factory->SetEGLContext(jni, local_egl_context); |
| 97 } |
| 98 |
| 99 MediaCodecVideoDecoderFactory* decoder_factory = |
| 100 static_cast<MediaCodecVideoDecoderFactory*>( |
| 101 owned_factory->decoder_factory()); |
| 102 if (decoder_factory) { |
| 103 LOG(LS_INFO) << "Set EGL context for HW decoding."; |
| 104 decoder_factory->SetEGLContext(jni, remote_egl_context); |
| 105 } |
| 106 } |
| 107 |
| 108 } // namespace webrtc_jni |
OLD | NEW |