| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 | 88 |
| 89 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { | 89 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { |
| 90 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; | 90 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void AndroidVideoCapturerJni::Start(int width, int height, int framerate, | 93 void AndroidVideoCapturerJni::Start(int width, int height, int framerate, |
| 94 webrtc::AndroidVideoCapturer* capturer) { | 94 webrtc::AndroidVideoCapturer* capturer) { |
| 95 LOG(LS_INFO) << "AndroidVideoCapturerJni start"; | 95 LOG(LS_INFO) << "AndroidVideoCapturerJni start"; |
| 96 DCHECK(thread_checker_.CalledOnValidThread()); | 96 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 97 { | 97 { |
| 98 rtc::CritScope cs(&capturer_lock_); | 98 rtc::CritScope cs(&capturer_lock_); |
| 99 CHECK(capturer_ == nullptr); | 99 RTC_CHECK(capturer_ == nullptr); |
| 100 CHECK(invoker_.get() == nullptr); | 100 RTC_CHECK(invoker_.get() == nullptr); |
| 101 capturer_ = capturer; | 101 capturer_ = capturer; |
| 102 invoker_.reset(new rtc::GuardedAsyncInvoker()); | 102 invoker_.reset(new rtc::GuardedAsyncInvoker()); |
| 103 } | 103 } |
| 104 jobject j_frame_observer = | 104 jobject j_frame_observer = |
| 105 jni()->NewObject(*j_observer_class_, | 105 jni()->NewObject(*j_observer_class_, |
| 106 GetMethodID(jni(), *j_observer_class_, "<init>", "(J)V"), | 106 GetMethodID(jni(), *j_observer_class_, "<init>", "(J)V"), |
| 107 jlongFromPointer(this)); | 107 jlongFromPointer(this)); |
| 108 CHECK_EXCEPTION(jni()) << "error during NewObject"; | 108 CHECK_EXCEPTION(jni()) << "error during NewObject"; |
| 109 | 109 |
| 110 jmethodID m = GetMethodID( | 110 jmethodID m = GetMethodID( |
| 111 jni(), *j_video_capturer_class_, "startCapture", | 111 jni(), *j_video_capturer_class_, "startCapture", |
| 112 "(IIILandroid/content/Context;" | 112 "(IIILandroid/content/Context;" |
| 113 "Lorg/webrtc/VideoCapturerAndroid$CapturerObserver;)V"); | 113 "Lorg/webrtc/VideoCapturerAndroid$CapturerObserver;)V"); |
| 114 jni()->CallVoidMethod(*j_capturer_global_, | 114 jni()->CallVoidMethod(*j_capturer_global_, |
| 115 m, width, height, | 115 m, width, height, |
| 116 framerate, | 116 framerate, |
| 117 application_context_, | 117 application_context_, |
| 118 j_frame_observer); | 118 j_frame_observer); |
| 119 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.startCapture"; | 119 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.startCapture"; |
| 120 } | 120 } |
| 121 | 121 |
| 122 void AndroidVideoCapturerJni::Stop() { | 122 void AndroidVideoCapturerJni::Stop() { |
| 123 LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; | 123 LOG(LS_INFO) << "AndroidVideoCapturerJni stop"; |
| 124 DCHECK(thread_checker_.CalledOnValidThread()); | 124 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 125 { | 125 { |
| 126 rtc::CritScope cs(&capturer_lock_); | 126 rtc::CritScope cs(&capturer_lock_); |
| 127 // Destroying |invoker_| will cancel all pending calls to |capturer_|. | 127 // Destroying |invoker_| will cancel all pending calls to |capturer_|. |
| 128 invoker_ = nullptr; | 128 invoker_ = nullptr; |
| 129 capturer_ = nullptr; | 129 capturer_ = nullptr; |
| 130 } | 130 } |
| 131 jmethodID m = GetMethodID(jni(), *j_video_capturer_class_, | 131 jmethodID m = GetMethodID(jni(), *j_video_capturer_class_, |
| 132 "stopCapture", "()V"); | 132 "stopCapture", "()V"); |
| 133 jni()->CallVoidMethod(*j_capturer_global_, m); | 133 jni()->CallVoidMethod(*j_capturer_global_, m); |
| 134 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.stopCapture"; | 134 CHECK_EXCEPTION(jni()) << "error during VideoCapturerAndroid.stopCapture"; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnFrameCaptured) | 213 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnFrameCaptured) |
| 214 (JNIEnv* jni, jclass, jlong j_capturer, jbyteArray j_frame, jint length, | 214 (JNIEnv* jni, jclass, jlong j_capturer, jbyteArray j_frame, jint length, |
| 215 jint width, jint height, jint rotation, jlong ts) { | 215 jint width, jint height, jint rotation, jlong ts) { |
| 216 jboolean is_copy = true; | 216 jboolean is_copy = true; |
| 217 jbyte* bytes = jni->GetByteArrayElements(j_frame, &is_copy); | 217 jbyte* bytes = jni->GetByteArrayElements(j_frame, &is_copy); |
| 218 // If this is a copy of the original frame, it means that the memory | 218 // If this is a copy of the original frame, it means that the memory |
| 219 // is not direct memory and thus VideoCapturerAndroid does not guarantee | 219 // is not direct memory and thus VideoCapturerAndroid does not guarantee |
| 220 // that the memory is valid when we have released |j_frame|. | 220 // that the memory is valid when we have released |j_frame|. |
| 221 // TODO(magjed): Move ReleaseByteArrayElements() into ReturnBuffer() and | 221 // TODO(magjed): Move ReleaseByteArrayElements() into ReturnBuffer() and |
| 222 // remove this check. | 222 // remove this check. |
| 223 CHECK(!is_copy) << "NativeObserver_nativeOnFrameCaptured: frame is a copy"; | 223 RTC_CHECK(!is_copy) |
| 224 << "NativeObserver_nativeOnFrameCaptured: frame is a copy"; |
| 224 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) | 225 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer) |
| 225 ->OnIncomingFrame(bytes, length, width, height, rotation, ts); | 226 ->OnIncomingFrame(bytes, length, width, height, rotation, ts); |
| 226 jni->ReleaseByteArrayElements(j_frame, bytes, JNI_ABORT); | 227 jni->ReleaseByteArrayElements(j_frame, bytes, JNI_ABORT); |
| 227 } | 228 } |
| 228 | 229 |
| 229 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeCapturerStarted) | 230 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeCapturerStarted) |
| 230 (JNIEnv* jni, jclass, jlong j_capturer, jboolean j_success) { | 231 (JNIEnv* jni, jclass, jlong j_capturer, jboolean j_success) { |
| 231 LOG(LS_INFO) << "NativeObserver_nativeCapturerStarted"; | 232 LOG(LS_INFO) << "NativeObserver_nativeCapturerStarted"; |
| 232 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnCapturerStarted( | 233 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnCapturerStarted( |
| 233 j_success); | 234 j_success); |
| 234 } | 235 } |
| 235 | 236 |
| 236 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnOutputFormatRequest) | 237 JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnOutputFormatRequest) |
| 237 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 238 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
| 238 jint j_fps) { | 239 jint j_fps) { |
| 239 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; | 240 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; |
| 240 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( | 241 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( |
| 241 j_width, j_height, j_fps); | 242 j_width, j_height, j_fps); |
| 242 } | 243 } |
| 243 | 244 |
| 244 } // namespace webrtc_jni | 245 } // namespace webrtc_jni |
| OLD | NEW |