| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni, | 23 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni, |
| 24 jobject appliction_context) { | 24 jobject appliction_context) { |
| 25 if (application_context_) { | 25 if (application_context_) { |
| 26 jni->DeleteGlobalRef(application_context_); | 26 jni->DeleteGlobalRef(application_context_); |
| 27 } | 27 } |
| 28 application_context_ = NewGlobalRef(jni, appliction_context); | 28 application_context_ = NewGlobalRef(jni, appliction_context); |
| 29 | 29 |
| 30 return 0; | 30 return 0; |
| 31 } | 31 } |
| 32 | 32 |
| 33 AndroidVideoCapturerJni::AndroidVideoCapturerJni(JNIEnv* jni, | 33 AndroidVideoCapturerJni::AndroidVideoCapturerJni( |
| 34 jobject j_video_capturer, | 34 JNIEnv* jni, |
| 35 jobject j_egl_context) | 35 jobject j_video_capturer, |
| 36 rtc::scoped_refptr<SurfaceTextureHelper> helper) |
| 36 : j_video_capturer_(jni, j_video_capturer), | 37 : j_video_capturer_(jni, j_video_capturer), |
| 37 j_video_capturer_class_(jni, FindClass(jni, "org/webrtc/VideoCapturer")), | 38 j_video_capturer_class_(jni, FindClass(jni, "org/webrtc/VideoCapturer")), |
| 38 j_observer_class_( | 39 j_observer_class_( |
| 39 jni, | 40 jni, |
| 40 FindClass(jni, | 41 FindClass(jni, "org/webrtc/VideoCapturer$NativeObserver")), |
| 41 "org/webrtc/VideoCapturer$NativeObserver")), | 42 surface_texture_helper_(helper), |
| 42 surface_texture_helper_(SurfaceTextureHelper::create( | |
| 43 jni, "Camera SurfaceTextureHelper", j_egl_context)), | |
| 44 capturer_(nullptr) { | 43 capturer_(nullptr) { |
| 45 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor"; | 44 LOG(LS_INFO) << "AndroidVideoCapturerJni ctor"; |
| 46 thread_checker_.DetachFromThread(); | 45 thread_checker_.DetachFromThread(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { | 48 AndroidVideoCapturerJni::~AndroidVideoCapturerJni() { |
| 50 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; | 49 LOG(LS_INFO) << "AndroidVideoCapturerJni dtor"; |
| 51 jni()->CallVoidMethod( | 50 jni()->CallVoidMethod( |
| 52 *j_video_capturer_, | 51 *j_video_capturer_, |
| 53 GetMethodID(jni(), *j_video_capturer_class_, "dispose", "()V")); | 52 GetMethodID(jni(), *j_video_capturer_class_, "dispose", "()V")); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 &webrtc::AndroidVideoCapturer::OnCapturerStarted, | 161 &webrtc::AndroidVideoCapturer::OnCapturerStarted, |
| 163 success); | 162 success); |
| 164 } | 163 } |
| 165 | 164 |
| 166 void AndroidVideoCapturerJni::OnMemoryBufferFrame(void* video_frame, | 165 void AndroidVideoCapturerJni::OnMemoryBufferFrame(void* video_frame, |
| 167 int length, | 166 int length, |
| 168 int width, | 167 int width, |
| 169 int height, | 168 int height, |
| 170 int rotation, | 169 int rotation, |
| 171 int64_t timestamp_ns) { | 170 int64_t timestamp_ns) { |
| 172 const uint8_t* y_plane = static_cast<uint8_t*>(video_frame); | 171 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || |
| 173 const uint8_t* vu_plane = y_plane + width * height; | 172 rotation == 270); |
| 174 | 173 rtc::CritScope cs(&capturer_lock_); |
| 175 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer = | 174 capturer_->OnNV21Frame(static_cast<uint8_t*>(video_frame), length, |
| 176 buffer_pool_.CreateBuffer(width, height); | 175 width, height, |
| 177 libyuv::NV21ToI420( | 176 static_cast<webrtc::VideoRotation>(rotation), |
| 178 y_plane, width, | 177 timestamp_ns); |
| 179 vu_plane, width, | |
| 180 buffer->MutableData(webrtc::kYPlane), buffer->stride(webrtc::kYPlane), | |
| 181 buffer->MutableData(webrtc::kUPlane), buffer->stride(webrtc::kUPlane), | |
| 182 buffer->MutableData(webrtc::kVPlane), buffer->stride(webrtc::kVPlane), | |
| 183 width, height); | |
| 184 AsyncCapturerInvoke("OnIncomingFrame", | |
| 185 &webrtc::AndroidVideoCapturer::OnIncomingFrame, | |
| 186 buffer, rotation, timestamp_ns); | |
| 187 } | 178 } |
| 188 | 179 |
| 189 void AndroidVideoCapturerJni::OnTextureFrame(int width, | 180 void AndroidVideoCapturerJni::OnTextureFrame(int width, |
| 190 int height, | 181 int height, |
| 191 int rotation, | 182 int rotation, |
| 192 int64_t timestamp_ns, | 183 int64_t timestamp_ns, |
| 193 const NativeHandleImpl& handle) { | 184 const NativeHandleImpl& handle) { |
| 194 rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer( | 185 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || |
| 195 surface_texture_helper_->CreateTextureFrame(width, height, handle)); | 186 rotation == 270); |
| 196 | 187 rtc::CritScope cs(&capturer_lock_); |
| 197 AsyncCapturerInvoke("OnIncomingFrame", | 188 // TODO(nisse): Give the capturer access to the SurfaceTextureHelper |
| 198 &webrtc::AndroidVideoCapturer::OnIncomingFrame, | 189 // in some better way. |
| 199 buffer, rotation, timestamp_ns); | 190 capturer_->OnTextureFrame(width, height, |
| 191 static_cast<webrtc::VideoRotation>(rotation), |
| 192 timestamp_ns, handle); |
| 200 } | 193 } |
| 201 | 194 |
| 202 void AndroidVideoCapturerJni::OnOutputFormatRequest(int width, | 195 void AndroidVideoCapturerJni::OnOutputFormatRequest(int width, |
| 203 int height, | 196 int height, |
| 204 int fps) { | 197 int fps) { |
| 205 AsyncCapturerInvoke("OnOutputFormatRequest", | 198 AsyncCapturerInvoke("OnOutputFormatRequest", |
| 206 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest, | 199 &webrtc::AndroidVideoCapturer::OnOutputFormatRequest, |
| 207 width, height, fps); | 200 width, height, fps); |
| 208 } | 201 } |
| 209 | 202 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 239 | 232 |
| 240 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) | 233 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) |
| 241 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 234 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
| 242 jint j_fps) { | 235 jint j_fps) { |
| 243 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; | 236 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; |
| 244 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( | 237 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( |
| 245 j_width, j_height, j_fps); | 238 j_width, j_height, j_fps); |
| 246 } | 239 } |
| 247 | 240 |
| 248 } // namespace webrtc_jni | 241 } // namespace webrtc_jni |
| OLD | NEW |