OLD | NEW |
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 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 signaling_thread_(signaling_thread), | 1064 signaling_thread_(signaling_thread), |
1065 encoder_factory_(encoder_factory), | 1065 encoder_factory_(encoder_factory), |
1066 decoder_factory_(decoder_factory), | 1066 decoder_factory_(decoder_factory), |
1067 factory_(factory) {} | 1067 factory_(factory) {} |
1068 | 1068 |
1069 ~OwnedFactoryAndThreads() { CHECK_RELEASE(factory_); } | 1069 ~OwnedFactoryAndThreads() { CHECK_RELEASE(factory_); } |
1070 | 1070 |
1071 PeerConnectionFactoryInterface* factory() { return factory_; } | 1071 PeerConnectionFactoryInterface* factory() { return factory_; } |
1072 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } | 1072 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } |
1073 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } | 1073 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } |
| 1074 void InvokeJavaCallbacksOnFactoryThreads(); |
1074 | 1075 |
1075 private: | 1076 private: |
| 1077 void JavaCallbackOnFactoryThreads(); |
| 1078 |
1076 const scoped_ptr<Thread> worker_thread_; | 1079 const scoped_ptr<Thread> worker_thread_; |
1077 const scoped_ptr<Thread> signaling_thread_; | 1080 const scoped_ptr<Thread> signaling_thread_; |
1078 WebRtcVideoEncoderFactory* encoder_factory_; | 1081 WebRtcVideoEncoderFactory* encoder_factory_; |
1079 WebRtcVideoDecoderFactory* decoder_factory_; | 1082 WebRtcVideoDecoderFactory* decoder_factory_; |
1080 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. | 1083 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. |
1081 }; | 1084 }; |
1082 | 1085 |
| 1086 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { |
| 1087 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
| 1088 ScopedLocalRefFrame local_ref_frame(jni); |
| 1089 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); |
| 1090 jmethodID m = nullptr; |
| 1091 if (Thread::Current() == worker_thread_) { |
| 1092 LOG(LS_INFO) << "Worker thread JavaCallback"; |
| 1093 m = GetStaticMethodID(jni, j_factory_class, "onWorkerThreadReady", "()V"); |
| 1094 } |
| 1095 if (Thread::Current() == signaling_thread_) { |
| 1096 LOG(LS_INFO) << "Signaling thread JavaCallback"; |
| 1097 m = GetStaticMethodID( |
| 1098 jni, j_factory_class, "onSignalingThreadReady", "()V"); |
| 1099 } |
| 1100 if (m != nullptr) { |
| 1101 jni->CallStaticVoidMethod(j_factory_class, m); |
| 1102 CHECK_EXCEPTION(jni) << "error during JavaCallback::CallStaticVoidMethod"; |
| 1103 } |
| 1104 } |
| 1105 |
| 1106 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() { |
| 1107 LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads."; |
| 1108 worker_thread_->Invoke<void>( |
| 1109 Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this)); |
| 1110 signaling_thread_->Invoke<void>( |
| 1111 Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this)); |
| 1112 } |
| 1113 |
1083 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)( | 1114 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)( |
1084 JNIEnv* jni, jclass) { | 1115 JNIEnv* jni, jclass) { |
1085 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but | 1116 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but |
1086 // ThreadManager only WrapCurrentThread()s the thread where it is first | 1117 // ThreadManager only WrapCurrentThread()s the thread where it is first |
1087 // created. Since the semantics around when auto-wrapping happens in | 1118 // created. Since the semantics around when auto-wrapping happens in |
1088 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think | 1119 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think |
1089 // about ramifications of auto-wrapping there. | 1120 // about ramifications of auto-wrapping there. |
1090 rtc::ThreadManager::Instance()->WrapCurrentThread(); | 1121 rtc::ThreadManager::Instance()->WrapCurrentThread(); |
1091 webrtc::Trace::CreateTrace(); | 1122 webrtc::Trace::CreateTrace(); |
1092 Thread* worker_thread = new Thread(); | 1123 Thread* worker_thread = new Thread(); |
(...skipping 15 matching lines...) Expand all Loading... |
1108 signaling_thread, | 1139 signaling_thread, |
1109 NULL, | 1140 NULL, |
1110 encoder_factory, | 1141 encoder_factory, |
1111 decoder_factory)); | 1142 decoder_factory)); |
1112 RTC_CHECK(factory) << "Failed to create the peer connection factory; " | 1143 RTC_CHECK(factory) << "Failed to create the peer connection factory; " |
1113 << "WebRTC/libjingle init likely failed on this device"; | 1144 << "WebRTC/libjingle init likely failed on this device"; |
1114 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( | 1145 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( |
1115 worker_thread, signaling_thread, | 1146 worker_thread, signaling_thread, |
1116 encoder_factory, decoder_factory, | 1147 encoder_factory, decoder_factory, |
1117 factory.release()); | 1148 factory.release()); |
| 1149 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); |
1118 return jlongFromPointer(owned_factory); | 1150 return jlongFromPointer(owned_factory); |
1119 } | 1151 } |
1120 | 1152 |
1121 JOW(void, PeerConnectionFactory_freeFactory)(JNIEnv*, jclass, jlong j_p) { | 1153 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { |
1122 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1154 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1123 if (field_trials_init_string) { | 1155 if (field_trials_init_string) { |
1124 webrtc::field_trial::InitFieldTrialsFromString(NULL); | 1156 webrtc::field_trial::InitFieldTrialsFromString(NULL); |
1125 delete field_trials_init_string; | 1157 delete field_trials_init_string; |
1126 field_trials_init_string = NULL; | 1158 field_trials_init_string = NULL; |
1127 } | 1159 } |
1128 webrtc::Trace::ReturnTrace(); | 1160 webrtc::Trace::ReturnTrace(); |
1129 } | 1161 } |
1130 | 1162 |
1131 static PeerConnectionFactoryInterface* factoryFromJava(jlong j_p) { | 1163 static PeerConnectionFactoryInterface* factoryFromJava(jlong j_p) { |
1132 return reinterpret_cast<OwnedFactoryAndThreads*>(j_p)->factory(); | 1164 return reinterpret_cast<OwnedFactoryAndThreads*>(j_p)->factory(); |
1133 } | 1165 } |
1134 | 1166 |
| 1167 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks)( |
| 1168 JNIEnv*, jclass, jlong j_p) { |
| 1169 OwnedFactoryAndThreads *factory = |
| 1170 reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
| 1171 factory->InvokeJavaCallbacksOnFactoryThreads(); |
| 1172 } |
| 1173 |
1135 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( | 1174 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( |
1136 JNIEnv* jni, jclass, jlong native_factory, jstring label) { | 1175 JNIEnv* jni, jclass, jlong native_factory, jstring label) { |
1137 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1176 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1138 factoryFromJava(native_factory)); | 1177 factoryFromJava(native_factory)); |
1139 rtc::scoped_refptr<MediaStreamInterface> stream( | 1178 rtc::scoped_refptr<MediaStreamInterface> stream( |
1140 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); | 1179 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); |
1141 return (jlong)stream.release(); | 1180 return (jlong)stream.release(); |
1142 } | 1181 } |
1143 | 1182 |
1144 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource)( | 1183 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource)( |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1865 rtc::scoped_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size))); | 1904 rtc::scoped_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size))); |
1866 stream->ReadAll(buffer.get(), log_size, &read, nullptr); | 1905 stream->ReadAll(buffer.get(), log_size, &read, nullptr); |
1867 | 1906 |
1868 jbyteArray result = jni->NewByteArray(read); | 1907 jbyteArray result = jni->NewByteArray(read); |
1869 jni->SetByteArrayRegion(result, 0, read, buffer.get()); | 1908 jni->SetByteArrayRegion(result, 0, read, buffer.get()); |
1870 | 1909 |
1871 return result; | 1910 return result; |
1872 } | 1911 } |
1873 | 1912 |
1874 } // namespace webrtc_jni | 1913 } // namespace webrtc_jni |
OLD | NEW |