Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: talk/app/webrtc/java/jni/peerconnection_jni.cc

Issue 1304063011: Move shared EGL context initialization to a separate function. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address comment + fix Linux build. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 82 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
83 #include "talk/app/webrtc/androidvideocapturer.h" 83 #include "talk/app/webrtc/androidvideocapturer.h"
84 #include "talk/app/webrtc/java/jni/androidmediadecoder_jni.h" 84 #include "talk/app/webrtc/java/jni/androidmediadecoder_jni.h"
85 #include "talk/app/webrtc/java/jni/androidmediaencoder_jni.h" 85 #include "talk/app/webrtc/java/jni/androidmediaencoder_jni.h"
86 #include "talk/app/webrtc/java/jni/androidvideocapturer_jni.h" 86 #include "talk/app/webrtc/java/jni/androidvideocapturer_jni.h"
87 #include "webrtc/modules/video_render/video_render_internal.h" 87 #include "webrtc/modules/video_render/video_render_internal.h"
88 #include "webrtc/system_wrappers/interface/logcat_trace_context.h" 88 #include "webrtc/system_wrappers/interface/logcat_trace_context.h"
89 using webrtc::LogcatTraceContext; 89 using webrtc::LogcatTraceContext;
90 #endif 90 #endif
91 91
92 using cricket::WebRtcVideoDecoderFactory;
93 using cricket::WebRtcVideoEncoderFactory;
92 using rtc::Bind; 94 using rtc::Bind;
93 using rtc::Thread; 95 using rtc::Thread;
94 using rtc::ThreadManager; 96 using rtc::ThreadManager;
95 using rtc::scoped_ptr; 97 using rtc::scoped_ptr;
96 using webrtc::AudioSourceInterface; 98 using webrtc::AudioSourceInterface;
97 using webrtc::AudioTrackInterface; 99 using webrtc::AudioTrackInterface;
98 using webrtc::AudioTrackVector; 100 using webrtc::AudioTrackVector;
99 using webrtc::CreateSessionDescriptionObserver; 101 using webrtc::CreateSessionDescriptionObserver;
100 using webrtc::DataBuffer; 102 using webrtc::DataBuffer;
101 using webrtc::DataChannelInit; 103 using webrtc::DataChannelInit;
(...skipping 19 matching lines...) Expand all
121 using webrtc::kVideoCodecVP8; 123 using webrtc::kVideoCodecVP8;
122 124
123 namespace webrtc_jni { 125 namespace webrtc_jni {
124 126
125 // Field trials initialization string 127 // Field trials initialization string
126 static char *field_trials_init_string = NULL; 128 static char *field_trials_init_string = NULL;
127 129
128 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 130 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
129 // Set in PeerConnectionFactory_initializeAndroidGlobals(). 131 // Set in PeerConnectionFactory_initializeAndroidGlobals().
130 static bool factory_static_initialized = false; 132 static bool factory_static_initialized = false;
131 static bool vp8_hw_acceleration_enabled = true; 133 static bool video_hw_acceleration_enabled = true;
132 #endif 134 #endif
133 135
134 extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { 136 extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
135 jint ret = InitGlobalJniVariables(jvm); 137 jint ret = InitGlobalJniVariables(jvm);
136 if (ret < 0) 138 if (ret < 0)
137 return -1; 139 return -1;
138 140
139 CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()"; 141 CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()";
140 LoadGlobalClassReferenceHolder(); 142 LoadGlobalClassReferenceHolder();
141 143
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 993
992 JOW(jlong, PeerConnectionFactory_nativeCreateObserver)( 994 JOW(jlong, PeerConnectionFactory_nativeCreateObserver)(
993 JNIEnv * jni, jclass, jobject j_observer) { 995 JNIEnv * jni, jclass, jobject j_observer) {
994 return (jlong)new PCOJava(jni, j_observer); 996 return (jlong)new PCOJava(jni, j_observer);
995 } 997 }
996 998
997 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 999 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
998 JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)( 1000 JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)(
999 JNIEnv* jni, jclass, jobject context, 1001 JNIEnv* jni, jclass, jobject context,
1000 jboolean initialize_audio, jboolean initialize_video, 1002 jboolean initialize_audio, jboolean initialize_video,
1001 jboolean vp8_hw_acceleration, jobject render_egl_context) { 1003 jboolean video_hw_acceleration) {
1002 bool failure = false; 1004 bool failure = false;
1003 vp8_hw_acceleration_enabled = vp8_hw_acceleration; 1005 video_hw_acceleration_enabled = video_hw_acceleration;
1004 if (!factory_static_initialized) { 1006 if (!factory_static_initialized) {
1005 if (initialize_video) { 1007 if (initialize_video) {
1006 failure |= webrtc::SetRenderAndroidVM(GetJVM()); 1008 failure |= webrtc::SetRenderAndroidVM(GetJVM());
1007 failure |= AndroidVideoCapturerJni::SetAndroidObjects(jni, context); 1009 failure |= AndroidVideoCapturerJni::SetAndroidObjects(jni, context);
1008 } 1010 }
1009 if (initialize_audio) 1011 if (initialize_audio)
1010 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context); 1012 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context);
1011 factory_static_initialized = true; 1013 factory_static_initialized = true;
1012 } 1014 }
1013 if (initialize_video) {
1014 failure |= MediaCodecVideoDecoderFactory::SetAndroidObjects(jni,
1015 render_egl_context);
1016 }
1017 return !failure; 1015 return !failure;
1018 } 1016 }
1019 #endif // defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 1017 #endif // defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
1020 1018
1021 JOW(void, PeerConnectionFactory_initializeFieldTrials)( 1019 JOW(void, PeerConnectionFactory_initializeFieldTrials)(
1022 JNIEnv* jni, jclass, jstring j_trials_init_string) { 1020 JNIEnv* jni, jclass, jstring j_trials_init_string) {
1023 field_trials_init_string = NULL; 1021 field_trials_init_string = NULL;
1024 if (j_trials_init_string != NULL) { 1022 if (j_trials_init_string != NULL) {
1025 const char* init_string = 1023 const char* init_string =
1026 jni->GetStringUTFChars(j_trials_init_string, NULL); 1024 jni->GetStringUTFChars(j_trials_init_string, NULL);
1027 int init_string_length = jni->GetStringUTFLength(j_trials_init_string); 1025 int init_string_length = jni->GetStringUTFLength(j_trials_init_string);
1028 field_trials_init_string = new char[init_string_length + 1]; 1026 field_trials_init_string = new char[init_string_length + 1];
1029 rtc::strcpyn(field_trials_init_string, init_string_length + 1, init_string); 1027 rtc::strcpyn(field_trials_init_string, init_string_length + 1, init_string);
1030 jni->ReleaseStringUTFChars(j_trials_init_string, init_string); 1028 jni->ReleaseStringUTFChars(j_trials_init_string, init_string);
1031 LOG(LS_INFO) << "initializeFieldTrials: " << field_trials_init_string; 1029 LOG(LS_INFO) << "initializeFieldTrials: " << field_trials_init_string;
1032 } 1030 }
1033 webrtc::field_trial::InitFieldTrialsFromString(field_trials_init_string); 1031 webrtc::field_trial::InitFieldTrialsFromString(field_trials_init_string);
1034 } 1032 }
1035 1033
1036 // Helper struct for working around the fact that CreatePeerConnectionFactory() 1034 // Helper struct for working around the fact that CreatePeerConnectionFactory()
1037 // comes in two flavors: either entirely automagical (constructing its own 1035 // comes in two flavors: either entirely automagical (constructing its own
1038 // threads and deleting them on teardown, but no external codec factory support) 1036 // threads and deleting them on teardown, but no external codec factory support)
1039 // or entirely manual (requires caller to delete threads after factory 1037 // or entirely manual (requires caller to delete threads after factory
1040 // teardown). This struct takes ownership of its ctor's arguments to present a 1038 // teardown). This struct takes ownership of its ctor's arguments to present a
1041 // single thing for Java to hold and eventually free. 1039 // single thing for Java to hold and eventually free.
1042 class OwnedFactoryAndThreads { 1040 class OwnedFactoryAndThreads {
1043 public: 1041 public:
1044 OwnedFactoryAndThreads(Thread* worker_thread, 1042 OwnedFactoryAndThreads(Thread* worker_thread,
1045 Thread* signaling_thread, 1043 Thread* signaling_thread,
1044 WebRtcVideoEncoderFactory* encoder_factory,
1045 WebRtcVideoDecoderFactory* decoder_factory,
1046 PeerConnectionFactoryInterface* factory) 1046 PeerConnectionFactoryInterface* factory)
1047 : worker_thread_(worker_thread), 1047 : worker_thread_(worker_thread),
1048 signaling_thread_(signaling_thread), 1048 signaling_thread_(signaling_thread),
1049 encoder_factory_(encoder_factory),
1050 decoder_factory_(decoder_factory),
1049 factory_(factory) {} 1051 factory_(factory) {}
1050 1052
1051 ~OwnedFactoryAndThreads() { CHECK_RELEASE(factory_); } 1053 ~OwnedFactoryAndThreads() { CHECK_RELEASE(factory_); }
1052 1054
1053 PeerConnectionFactoryInterface* factory() { return factory_; } 1055 PeerConnectionFactoryInterface* factory() { return factory_; }
1056 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; }
1057 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; }
1054 1058
1055 private: 1059 private:
1056 const scoped_ptr<Thread> worker_thread_; 1060 const scoped_ptr<Thread> worker_thread_;
1057 const scoped_ptr<Thread> signaling_thread_; 1061 const scoped_ptr<Thread> signaling_thread_;
1062 WebRtcVideoEncoderFactory* encoder_factory_;
1063 WebRtcVideoDecoderFactory* decoder_factory_;
1058 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. 1064 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor.
1059 }; 1065 };
1060 1066
1061 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)( 1067 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
1062 JNIEnv* jni, jclass) { 1068 JNIEnv* jni, jclass) {
1063 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but 1069 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but
1064 // ThreadManager only WrapCurrentThread()s the thread where it is first 1070 // ThreadManager only WrapCurrentThread()s the thread where it is first
1065 // created. Since the semantics around when auto-wrapping happens in 1071 // created. Since the semantics around when auto-wrapping happens in
1066 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think 1072 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think
1067 // about ramifications of auto-wrapping there. 1073 // about ramifications of auto-wrapping there.
1068 rtc::ThreadManager::Instance()->WrapCurrentThread(); 1074 rtc::ThreadManager::Instance()->WrapCurrentThread();
1069 webrtc::Trace::CreateTrace(); 1075 webrtc::Trace::CreateTrace();
1070 Thread* worker_thread = new Thread(); 1076 Thread* worker_thread = new Thread();
1071 worker_thread->SetName("worker_thread", NULL); 1077 worker_thread->SetName("worker_thread", NULL);
1072 Thread* signaling_thread = new Thread(); 1078 Thread* signaling_thread = new Thread();
1073 signaling_thread->SetName("signaling_thread", NULL); 1079 signaling_thread->SetName("signaling_thread", NULL);
1074 CHECK(worker_thread->Start() && signaling_thread->Start()) 1080 CHECK(worker_thread->Start() && signaling_thread->Start())
1075 << "Failed to start threads"; 1081 << "Failed to start threads";
1076 scoped_ptr<cricket::WebRtcVideoEncoderFactory> encoder_factory; 1082 WebRtcVideoEncoderFactory* encoder_factory = nullptr;
1077 scoped_ptr<cricket::WebRtcVideoDecoderFactory> decoder_factory; 1083 WebRtcVideoDecoderFactory* decoder_factory = nullptr;
1078 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 1084 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
1079 if (vp8_hw_acceleration_enabled) { 1085 if (video_hw_acceleration_enabled) {
1080 encoder_factory.reset(new MediaCodecVideoEncoderFactory()); 1086 encoder_factory = new MediaCodecVideoEncoderFactory();
1081 decoder_factory.reset(new MediaCodecVideoDecoderFactory()); 1087 decoder_factory = new MediaCodecVideoDecoderFactory();
1082 } 1088 }
1083 #endif 1089 #endif
1084 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( 1090 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
1085 webrtc::CreatePeerConnectionFactory(worker_thread, 1091 webrtc::CreatePeerConnectionFactory(worker_thread,
1086 signaling_thread, 1092 signaling_thread,
1087 NULL, 1093 NULL,
1088 encoder_factory.release(), 1094 encoder_factory,
1089 decoder_factory.release())); 1095 decoder_factory));
1090 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( 1096 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
1091 worker_thread, signaling_thread, factory.release()); 1097 worker_thread, signaling_thread,
1098 encoder_factory, decoder_factory,
1099 factory.release());
1092 return jlongFromPointer(owned_factory); 1100 return jlongFromPointer(owned_factory);
1093 } 1101 }
1094 1102
1095 JOW(void, PeerConnectionFactory_freeFactory)(JNIEnv*, jclass, jlong j_p) { 1103 JOW(void, PeerConnectionFactory_freeFactory)(JNIEnv*, jclass, jlong j_p) {
1096 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); 1104 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p);
1097 if (field_trials_init_string) { 1105 if (field_trials_init_string) {
1098 webrtc::field_trial::InitFieldTrialsFromString(NULL); 1106 webrtc::field_trial::InitFieldTrialsFromString(NULL);
1099 delete field_trials_init_string; 1107 delete field_trials_init_string;
1100 field_trials_init_string = NULL; 1108 field_trials_init_string = NULL;
1101 } 1109 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 1188
1181 PeerConnectionFactoryInterface::Options options_to_set; 1189 PeerConnectionFactoryInterface::Options options_to_set;
1182 1190
1183 // This doesn't necessarily match the c++ version of this struct; feel free 1191 // This doesn't necessarily match the c++ version of this struct; feel free
1184 // to add more parameters as necessary. 1192 // to add more parameters as necessary.
1185 options_to_set.network_ignore_mask = network_ignore_mask; 1193 options_to_set.network_ignore_mask = network_ignore_mask;
1186 options_to_set.disable_encryption = disable_encryption; 1194 options_to_set.disable_encryption = disable_encryption;
1187 factory->SetOptions(options_to_set); 1195 factory->SetOptions(options_to_set);
1188 } 1196 }
1189 1197
1198 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)(
1199 JNIEnv* jni, jclass, jlong native_factory, jobject render_egl_context) {
1200 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
1201 OwnedFactoryAndThreads* owned_factory =
1202 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory);
1203 MediaCodecVideoDecoderFactory* decoder_factory =
1204 static_cast<MediaCodecVideoDecoderFactory*>
1205 (owned_factory->decoder_factory());
1206 if (decoder_factory) {
1207 LOG(LS_INFO) << "Set EGL context for HW acceleration.";
1208 decoder_factory->SetEGLContext(jni, render_egl_context);
1209 }
1210 #endif
1211 }
1212
1213
1190 static std::string 1214 static std::string
1191 GetJavaEnumName(JNIEnv* jni, const std::string& className, jobject j_enum) { 1215 GetJavaEnumName(JNIEnv* jni, const std::string& className, jobject j_enum) {
1192 jclass enumClass = FindClass(jni, className.c_str()); 1216 jclass enumClass = FindClass(jni, className.c_str());
1193 jmethodID nameMethod = 1217 jmethodID nameMethod =
1194 GetMethodID(jni, enumClass, "name", "()Ljava/lang/String;"); 1218 GetMethodID(jni, enumClass, "name", "()Ljava/lang/String;");
1195 jstring name = 1219 jstring name =
1196 reinterpret_cast<jstring>(jni->CallObjectMethod(j_enum, nameMethod)); 1220 reinterpret_cast<jstring>(jni->CallObjectMethod(j_enum, nameMethod));
1197 CHECK_EXCEPTION(jni) << "error during CallObjectMethod for " 1221 CHECK_EXCEPTION(jni) << "error during CallObjectMethod for "
1198 << className << ".name"; 1222 << className << ".name";
1199 return JavaToStdString(jni, name); 1223 return JavaToStdString(jni, name);
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 } 1726 }
1703 1727
1704 JOW(void, VideoTrack_nativeRemoveRenderer)( 1728 JOW(void, VideoTrack_nativeRemoveRenderer)(
1705 JNIEnv* jni, jclass, 1729 JNIEnv* jni, jclass,
1706 jlong j_video_track_pointer, jlong j_renderer_pointer) { 1730 jlong j_video_track_pointer, jlong j_renderer_pointer) {
1707 reinterpret_cast<VideoTrackInterface*>(j_video_track_pointer)->RemoveRenderer( 1731 reinterpret_cast<VideoTrackInterface*>(j_video_track_pointer)->RemoveRenderer(
1708 reinterpret_cast<VideoRendererInterface*>(j_renderer_pointer)); 1732 reinterpret_cast<VideoRendererInterface*>(j_renderer_pointer));
1709 } 1733 }
1710 1734
1711 } // namespace webrtc_jni 1735 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « talk/app/webrtc/java/jni/androidmediadecoder_jni.cc ('k') | talk/app/webrtc/java/src/org/webrtc/PeerConnectionFactory.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698