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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 jfloatArray sampling_matrix = native_handle_.sampling_matrix.ToJava(jni); | 315 jfloatArray sampling_matrix = native_handle_.sampling_matrix.ToJava(jni); |
316 jni->CallVoidMethod(surface_texture_helper_, | 316 jni->CallVoidMethod(surface_texture_helper_, |
317 transform_mid, | 317 transform_mid, |
318 byte_buffer, width(), height(), stride, | 318 byte_buffer, width(), height(), stride, |
319 native_handle_.oes_texture_id, sampling_matrix); | 319 native_handle_.oes_texture_id, sampling_matrix); |
320 CHECK_EXCEPTION(jni) << "textureToYUV throwed an exception"; | 320 CHECK_EXCEPTION(jni) << "textureToYUV throwed an exception"; |
321 | 321 |
322 return copy; | 322 return copy; |
323 } | 323 } |
324 | 324 |
| 325 rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBuffer::WrapReference( |
| 326 JNIEnv* jni, |
| 327 jmethodID j_release_id, |
| 328 int width, |
| 329 int height, |
| 330 jobject j_video_frame_buffer) { |
| 331 return new rtc::RefCountedObject<AndroidVideoBuffer>( |
| 332 jni, j_release_id, width, height, j_video_frame_buffer); |
| 333 } |
| 334 |
325 AndroidVideoBuffer::AndroidVideoBuffer(JNIEnv* jni, | 335 AndroidVideoBuffer::AndroidVideoBuffer(JNIEnv* jni, |
326 jmethodID j_retain_id, | 336 jmethodID j_retain_id, |
327 jmethodID j_release_id, | 337 jmethodID j_release_id, |
328 int width, | 338 int width, |
329 int height, | 339 int height, |
330 jobject j_video_frame_buffer) | 340 jobject j_video_frame_buffer) |
| 341 : AndroidVideoBuffer(jni, |
| 342 j_release_id, |
| 343 width, |
| 344 height, |
| 345 j_video_frame_buffer) { |
| 346 jni->CallVoidMethod(j_video_frame_buffer, j_retain_id); |
| 347 } |
| 348 |
| 349 AndroidVideoBuffer::AndroidVideoBuffer(JNIEnv* jni, |
| 350 jmethodID j_release_id, |
| 351 int width, |
| 352 int height, |
| 353 jobject j_video_frame_buffer) |
331 : j_release_id_(j_release_id), | 354 : j_release_id_(j_release_id), |
332 width_(width), | 355 width_(width), |
333 height_(height), | 356 height_(height), |
334 j_video_frame_buffer_(jni, j_video_frame_buffer) { | 357 j_video_frame_buffer_(jni, j_video_frame_buffer) {} |
335 jni->CallVoidMethod(j_video_frame_buffer, j_retain_id); | |
336 } | |
337 | 358 |
338 AndroidVideoBuffer::~AndroidVideoBuffer() { | 359 AndroidVideoBuffer::~AndroidVideoBuffer() { |
339 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 360 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
340 jni->CallVoidMethod(*j_video_frame_buffer_, j_release_id_); | 361 jni->CallVoidMethod(*j_video_frame_buffer_, j_release_id_); |
341 } | 362 } |
342 | 363 |
343 jobject AndroidVideoBuffer::video_frame_buffer() const { | 364 jobject AndroidVideoBuffer::video_frame_buffer() const { |
344 return *j_video_frame_buffer_; | 365 return *j_video_frame_buffer_; |
345 } | 366 } |
346 | 367 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 webrtc::VideoFrame AndroidVideoBufferFactory::CreateFrame( | 436 webrtc::VideoFrame AndroidVideoBufferFactory::CreateFrame( |
416 JNIEnv* jni, | 437 JNIEnv* jni, |
417 jobject j_video_frame, | 438 jobject j_video_frame, |
418 uint32_t timestamp_rtp) const { | 439 uint32_t timestamp_rtp) const { |
419 jobject j_video_frame_buffer = | 440 jobject j_video_frame_buffer = |
420 jni->CallObjectMethod(j_video_frame, j_get_buffer_id_); | 441 jni->CallObjectMethod(j_video_frame, j_get_buffer_id_); |
421 int rotation = jni->CallIntMethod(j_video_frame, j_get_rotation_id_); | 442 int rotation = jni->CallIntMethod(j_video_frame, j_get_rotation_id_); |
422 uint32_t timestamp_ns = | 443 uint32_t timestamp_ns = |
423 jni->CallLongMethod(j_video_frame, j_get_timestamp_ns_id_); | 444 jni->CallLongMethod(j_video_frame, j_get_timestamp_ns_id_); |
424 rtc::scoped_refptr<AndroidVideoBuffer> buffer = | 445 rtc::scoped_refptr<AndroidVideoBuffer> buffer = |
425 CreateBuffer(j_video_frame_buffer); | 446 CreateBuffer(jni, j_video_frame_buffer); |
426 return webrtc::VideoFrame(buffer, timestamp_rtp, | 447 return webrtc::VideoFrame(buffer, timestamp_rtp, |
427 timestamp_ns / rtc::kNumNanosecsPerMillisec, | 448 timestamp_ns / rtc::kNumNanosecsPerMillisec, |
428 static_cast<webrtc::VideoRotation>(rotation)); | 449 static_cast<webrtc::VideoRotation>(rotation)); |
429 } | 450 } |
430 | 451 |
| 452 rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBufferFactory::WrapBuffer( |
| 453 JNIEnv* jni, |
| 454 jobject j_video_frame_buffer) const { |
| 455 int width = jni->CallIntMethod(j_video_frame_buffer, j_get_width_id_); |
| 456 int height = jni->CallIntMethod(j_video_frame_buffer, j_get_height_id_); |
| 457 return AndroidVideoBuffer::WrapReference(jni, j_release_id_, width, height, |
| 458 j_video_frame_buffer); |
| 459 } |
| 460 |
431 rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBufferFactory::CreateBuffer( | 461 rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBufferFactory::CreateBuffer( |
| 462 JNIEnv* jni, |
432 jobject j_video_frame_buffer) const { | 463 jobject j_video_frame_buffer) const { |
433 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | |
434 int width = jni->CallIntMethod(j_video_frame_buffer, j_get_width_id_); | 464 int width = jni->CallIntMethod(j_video_frame_buffer, j_get_width_id_); |
435 int height = jni->CallIntMethod(j_video_frame_buffer, j_get_height_id_); | 465 int height = jni->CallIntMethod(j_video_frame_buffer, j_get_height_id_); |
436 return new rtc::RefCountedObject<AndroidVideoBuffer>( | 466 return new rtc::RefCountedObject<AndroidVideoBuffer>( |
437 jni, j_retain_id_, j_release_id_, width, height, j_video_frame_buffer); | 467 jni, j_retain_id_, j_release_id_, width, height, j_video_frame_buffer); |
438 } | 468 } |
439 | 469 |
440 JavaVideoFrameFactory::JavaVideoFrameFactory(JNIEnv* jni) | 470 JavaVideoFrameFactory::JavaVideoFrameFactory(JNIEnv* jni) |
441 : j_video_frame_class_(jni, FindClass(jni, "org/webrtc/VideoFrame")) { | 471 : j_video_frame_class_(jni, FindClass(jni, "org/webrtc/VideoFrame")) { |
442 j_video_frame_constructor_id_ = | 472 j_video_frame_constructor_id_ = |
443 GetMethodID(jni, *j_video_frame_class_, "<init>", | 473 GetMethodID(jni, *j_video_frame_class_, "<init>", |
(...skipping 12 matching lines...) Expand all Loading... |
456 AndroidVideoBuffer* android_video_buffer = | 486 AndroidVideoBuffer* android_video_buffer = |
457 static_cast<AndroidVideoBuffer*>(android_buffer); | 487 static_cast<AndroidVideoBuffer*>(android_buffer); |
458 jobject buffer = android_video_buffer->video_frame_buffer(); | 488 jobject buffer = android_video_buffer->video_frame_buffer(); |
459 return jni->NewObject( | 489 return jni->NewObject( |
460 *j_video_frame_class_, j_video_frame_constructor_id_, buffer, | 490 *j_video_frame_class_, j_video_frame_constructor_id_, buffer, |
461 static_cast<jint>(frame.rotation()), | 491 static_cast<jint>(frame.rotation()), |
462 static_cast<jlong>(frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec)); | 492 static_cast<jlong>(frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec)); |
463 } | 493 } |
464 | 494 |
465 } // namespace webrtc_jni | 495 } // namespace webrtc_jni |
OLD | NEW |