OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/sdk/android/src/jni/ownedfactoryandthreads.h" | 11 #include "webrtc/rtc_base/logsinks.h" |
12 | |
13 #include "webrtc/rtc_base/logging.h" | |
14 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" | |
15 #include "webrtc/sdk/android/src/jni/jni_helpers.h" | 12 #include "webrtc/sdk/android/src/jni/jni_helpers.h" |
16 | 13 |
17 namespace webrtc_jni { | 14 namespace webrtc_jni { |
18 | 15 |
19 PeerConnectionFactoryInterface* factoryFromJava(jlong j_p) { | 16 JOW(jlong, CallSessionFileRotatingLogSink_nativeAddSink) |
20 return reinterpret_cast<OwnedFactoryAndThreads*>(j_p)->factory(); | 17 (JNIEnv* jni, jclass, jstring j_dirPath, jint j_maxFileSize, jint j_severity) { |
| 18 std::string dir_path = JavaToStdString(jni, j_dirPath); |
| 19 rtc::CallSessionFileRotatingLogSink* sink = |
| 20 new rtc::CallSessionFileRotatingLogSink(dir_path, j_maxFileSize); |
| 21 if (!sink->Init()) { |
| 22 LOG_V(rtc::LoggingSeverity::LS_WARNING) |
| 23 << "Failed to init CallSessionFileRotatingLogSink for path " |
| 24 << dir_path; |
| 25 delete sink; |
| 26 return 0; |
| 27 } |
| 28 rtc::LogMessage::AddLogToStream( |
| 29 sink, static_cast<rtc::LoggingSeverity>(j_severity)); |
| 30 return (jlong)sink; |
21 } | 31 } |
22 | 32 |
23 OwnedFactoryAndThreads::~OwnedFactoryAndThreads() { | 33 JOW(void, CallSessionFileRotatingLogSink_nativeDeleteSink) |
24 CHECK_RELEASE(factory_); | 34 (JNIEnv* jni, jclass, jlong j_sink) { |
25 if (network_monitor_factory_ != nullptr) { | 35 rtc::CallSessionFileRotatingLogSink* sink = |
26 rtc::NetworkMonitorFactory::ReleaseFactory(network_monitor_factory_); | 36 reinterpret_cast<rtc::CallSessionFileRotatingLogSink*>(j_sink); |
27 } | 37 rtc::LogMessage::RemoveLogToStream(sink); |
| 38 delete sink; |
28 } | 39 } |
29 | 40 |
30 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { | 41 JOW(jbyteArray, CallSessionFileRotatingLogSink_nativeGetLogData) |
31 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 42 (JNIEnv* jni, jclass, jstring j_dirPath) { |
32 ScopedLocalRefFrame local_ref_frame(jni); | 43 std::string dir_path = JavaToStdString(jni, j_dirPath); |
33 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); | 44 std::unique_ptr<rtc::CallSessionFileRotatingStream> stream( |
34 jmethodID m = nullptr; | 45 new rtc::CallSessionFileRotatingStream(dir_path)); |
35 if (network_thread_->IsCurrent()) { | 46 if (!stream->Open()) { |
36 LOG(LS_INFO) << "Network thread JavaCallback"; | 47 LOG_V(rtc::LoggingSeverity::LS_WARNING) |
37 m = GetStaticMethodID(jni, j_factory_class, "onNetworkThreadReady", "()V"); | 48 << "Failed to open CallSessionFileRotatingStream for path " << dir_path; |
| 49 return jni->NewByteArray(0); |
38 } | 50 } |
39 if (worker_thread_->IsCurrent()) { | 51 size_t log_size = 0; |
40 LOG(LS_INFO) << "Worker thread JavaCallback"; | 52 if (!stream->GetSize(&log_size) || log_size == 0) { |
41 m = GetStaticMethodID(jni, j_factory_class, "onWorkerThreadReady", "()V"); | 53 LOG_V(rtc::LoggingSeverity::LS_WARNING) |
| 54 << "CallSessionFileRotatingStream returns 0 size for path " << dir_path; |
| 55 return jni->NewByteArray(0); |
42 } | 56 } |
43 if (signaling_thread_->IsCurrent()) { | |
44 LOG(LS_INFO) << "Signaling thread JavaCallback"; | |
45 m = GetStaticMethodID(jni, j_factory_class, "onSignalingThreadReady", | |
46 "()V"); | |
47 } | |
48 if (m != nullptr) { | |
49 jni->CallStaticVoidMethod(j_factory_class, m); | |
50 CHECK_EXCEPTION(jni) << "error during JavaCallback::CallStaticVoidMethod"; | |
51 } | |
52 } | |
53 | 57 |
54 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() { | 58 size_t read = 0; |
55 LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads."; | 59 std::unique_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size))); |
56 network_thread_->Invoke<void>(RTC_FROM_HERE, | 60 stream->ReadAll(buffer.get(), log_size, &read, nullptr); |
57 [this] { JavaCallbackOnFactoryThreads(); }); | 61 |
58 worker_thread_->Invoke<void>(RTC_FROM_HERE, | 62 jbyteArray result = jni->NewByteArray(read); |
59 [this] { JavaCallbackOnFactoryThreads(); }); | 63 jni->SetByteArrayRegion(result, 0, read, buffer.get()); |
60 signaling_thread_->Invoke<void>(RTC_FROM_HERE, | 64 |
61 [this] { JavaCallbackOnFactoryThreads(); }); | 65 return result; |
62 } | 66 } |
63 | 67 |
64 } // namespace webrtc_jni | 68 } // namespace webrtc_jni |
OLD | NEW |