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 |
11 #include "webrtc/api/java/jni/androidvideocapturer_jni.h" | 11 #include "webrtc/api/java/jni/androidvideocapturer_jni.h" |
12 #include "webrtc/api/java/jni/classreferenceholder.h" | 12 #include "webrtc/api/java/jni/classreferenceholder.h" |
13 #include "webrtc/api/java/jni/native_handle_impl.h" | 13 #include "webrtc/api/java/jni/native_handle_impl.h" |
14 #include "webrtc/api/java/jni/surfacetexturehelper_jni.h" | 14 #include "webrtc/api/java/jni/surfacetexturehelper_jni.h" |
15 #include "third_party/libyuv/include/libyuv/convert.h" | 15 #include "third_party/libyuv/include/libyuv/convert.h" |
16 #include "third_party/libyuv/include/libyuv/scale.h" | |
17 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
18 | 17 |
19 namespace webrtc_jni { | 18 namespace webrtc_jni { |
20 | 19 |
21 jobject AndroidVideoCapturerJni::application_context_ = nullptr; | 20 jobject AndroidVideoCapturerJni::application_context_ = nullptr; |
22 | 21 |
23 // static | 22 // static |
24 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni, | 23 int AndroidVideoCapturerJni::SetAndroidObjects(JNIEnv* jni, |
25 jobject appliction_context) { | 24 jobject appliction_context) { |
26 if (application_context_) { | 25 if (application_context_) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 libyuv::NV12ToI420Rotate( | 215 libyuv::NV12ToI420Rotate( |
217 y_plane + width * crop_y + crop_x, width, | 216 y_plane + width * crop_y + crop_x, width, |
218 uv_plane + uv_width * crop_y + crop_x, width, | 217 uv_plane + uv_width * crop_y + crop_x, width, |
219 buffer->MutableData(webrtc::kYPlane), buffer->stride(webrtc::kYPlane), | 218 buffer->MutableData(webrtc::kYPlane), buffer->stride(webrtc::kYPlane), |
220 // Swap U and V, since we have NV21, not NV12. | 219 // Swap U and V, since we have NV21, not NV12. |
221 buffer->MutableData(webrtc::kVPlane), buffer->stride(webrtc::kVPlane), | 220 buffer->MutableData(webrtc::kVPlane), buffer->stride(webrtc::kVPlane), |
222 buffer->MutableData(webrtc::kUPlane), buffer->stride(webrtc::kUPlane), | 221 buffer->MutableData(webrtc::kUPlane), buffer->stride(webrtc::kUPlane), |
223 crop_width, crop_height, static_cast<libyuv::RotationMode>( | 222 crop_width, crop_height, static_cast<libyuv::RotationMode>( |
224 capturer_->apply_rotation() ? rotation : 0)); | 223 capturer_->apply_rotation() ? rotation : 0)); |
225 | 224 |
226 if (adapted_width != rotated_width || adapted_height != rotated_height) { | 225 if (adapted_width != buffer->width() || adapted_height != buffer->height()) { |
227 rtc::scoped_refptr<webrtc::VideoFrameBuffer> scaled = | 226 rtc::scoped_refptr<webrtc::I420Buffer> scaled_buffer( |
228 post_scale_pool_.CreateBuffer(adapted_width, adapted_height); | 227 post_scale_pool_.CreateBuffer(adapted_width, adapted_height)); |
229 // TODO(nisse): This should be done by some Scale method in | 228 scaled_buffer->ScaleFrom(buffer); |
230 // I420Buffer, but we can't do that right now, since | 229 buffer = scaled_buffer; |
231 // I420BufferPool uses a wrapper object. | |
232 if (libyuv::I420Scale(buffer->DataY(), buffer->StrideY(), | |
233 buffer->DataU(), buffer->StrideU(), | |
234 buffer->DataV(), buffer->StrideV(), | |
235 rotated_width, rotated_height, | |
236 scaled->MutableDataY(), scaled->StrideY(), | |
237 scaled->MutableDataU(), scaled->StrideU(), | |
238 scaled->MutableDataV(), scaled->StrideV(), | |
239 adapted_width, adapted_height, | |
240 libyuv::kFilterBox) < 0) { | |
241 LOG(LS_WARNING) << "I420Scale failed"; | |
242 return; | |
243 } | |
244 buffer = scaled; | |
245 } | 230 } |
246 // TODO(nisse): Use microsecond time instead. | 231 // TODO(nisse): Use microsecond time instead. |
247 capturer_->OnFrame(cricket::WebRtcVideoFrame( | 232 capturer_->OnFrame(cricket::WebRtcVideoFrame( |
248 buffer, timestamp_ns, | 233 buffer, timestamp_ns, |
249 capturer_->apply_rotation() | 234 capturer_->apply_rotation() |
250 ? webrtc::kVideoRotation_0 | 235 ? webrtc::kVideoRotation_0 |
251 : static_cast<webrtc::VideoRotation>(rotation)), | 236 : static_cast<webrtc::VideoRotation>(rotation)), |
252 width, height); | 237 width, height); |
253 } | 238 } |
254 | 239 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 331 |
347 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) | 332 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) |
348 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 333 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
349 jint j_fps) { | 334 jint j_fps) { |
350 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; | 335 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; |
351 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( | 336 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( |
352 j_width, j_height, j_fps); | 337 j_width, j_height, j_fps); |
353 } | 338 } |
354 | 339 |
355 } // namespace webrtc_jni | 340 } // namespace webrtc_jni |
OLD | NEW |