Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: webrtc/sdk/android/src/jni/native_handle_impl.cc

Issue 2997663002: Support Java VideoFrames in MediaCodecVideoEncoder. (Closed)
Patch Set: Address comments. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/sdk/android/src/jni/native_handle_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 368
369 jobject j_i420_buffer = 369 jobject j_i420_buffer =
370 jni->CallObjectMethod(*j_video_frame_buffer_, j_to_i420_id); 370 jni->CallObjectMethod(*j_video_frame_buffer_, j_to_i420_id);
371 371
372 // We don't need to retain the buffer because toI420 returns a new object that 372 // We don't need to retain the buffer because toI420 returns a new object that
373 // we are assumed to take the ownership of. 373 // we are assumed to take the ownership of.
374 return AndroidVideoI420Buffer::WrapReference(jni, j_release_id_, width_, 374 return AndroidVideoI420Buffer::WrapReference(jni, j_release_id_, width_,
375 height_, j_i420_buffer); 375 height_, j_i420_buffer);
376 } 376 }
377 377
378 jobject AndroidVideoBuffer::ToJavaI420Frame(JNIEnv* jni, 378 jobject AndroidVideoBuffer::ToJavaI420Frame(JNIEnv* jni, int rotation) {
379 int rotation) {
380 jclass j_byte_buffer_class = jni->FindClass("java/nio/ByteBuffer"); 379 jclass j_byte_buffer_class = jni->FindClass("java/nio/ByteBuffer");
381 jclass j_i420_frame_class = 380 jclass j_i420_frame_class =
382 FindClass(jni, "org/webrtc/VideoRenderer$I420Frame"); 381 FindClass(jni, "org/webrtc/VideoRenderer$I420Frame");
383 jmethodID j_i420_frame_ctor_id = GetMethodID( 382 jmethodID j_i420_frame_ctor_id = GetMethodID(
384 jni, j_i420_frame_class, "<init>", "(ILorg/webrtc/VideoFrame$Buffer;J)V"); 383 jni, j_i420_frame_class, "<init>", "(ILorg/webrtc/VideoFrame$Buffer;J)V");
385 // Java code just uses the native frame to hold a reference to the buffer so 384 // Java code just uses the native frame to hold a reference to the buffer so
386 // this is okay. 385 // this is okay.
387 webrtc::VideoFrame* native_frame = new webrtc::VideoFrame( 386 webrtc::VideoFrame* native_frame = new webrtc::VideoFrame(
388 this, 0 /* timestamp */, 0 /* render_time_ms */, 387 this, 0 /* timestamp */, 0 /* render_time_ms */,
389 webrtc::VideoRotation::kVideoRotation_0 /* rotation */); 388 webrtc::VideoRotation::kVideoRotation_0 /* rotation */);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 430
432 rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBufferFactory::CreateBuffer( 431 rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBufferFactory::CreateBuffer(
433 jobject j_video_frame_buffer) const { 432 jobject j_video_frame_buffer) const {
434 JNIEnv* jni = AttachCurrentThreadIfNeeded(); 433 JNIEnv* jni = AttachCurrentThreadIfNeeded();
435 int width = jni->CallIntMethod(j_video_frame_buffer, j_get_width_id_); 434 int width = jni->CallIntMethod(j_video_frame_buffer, j_get_width_id_);
436 int height = jni->CallIntMethod(j_video_frame_buffer, j_get_height_id_); 435 int height = jni->CallIntMethod(j_video_frame_buffer, j_get_height_id_);
437 return new rtc::RefCountedObject<AndroidVideoBuffer>( 436 return new rtc::RefCountedObject<AndroidVideoBuffer>(
438 jni, j_retain_id_, j_release_id_, width, height, j_video_frame_buffer); 437 jni, j_retain_id_, j_release_id_, width, height, j_video_frame_buffer);
439 } 438 }
440 439
440 JavaVideoFrameFactory::JavaVideoFrameFactory(JNIEnv* jni)
441 : j_video_frame_class_(jni, FindClass(jni, "org/webrtc/VideoFrame")) {
442 j_video_frame_constructor_id_ =
443 GetMethodID(jni, *j_video_frame_class_, "<init>",
444 "(Lorg/webrtc/VideoFrame$Buffer;IJ)V");
445 }
446
447 jobject JavaVideoFrameFactory::ToJavaFrame(
448 JNIEnv* jni,
449 const webrtc::VideoFrame& frame) const {
450 RTC_DCHECK(frame.video_frame_buffer()->type() ==
451 webrtc::VideoFrameBuffer::Type::kNative);
452 AndroidVideoFrameBuffer* android_buffer =
453 static_cast<AndroidVideoFrameBuffer*>(frame.video_frame_buffer().get());
454 RTC_DCHECK(android_buffer->android_type() ==
455 AndroidVideoFrameBuffer::AndroidType::kJavaBuffer);
456 AndroidVideoBuffer* android_video_buffer =
457 static_cast<AndroidVideoBuffer*>(android_buffer);
458 jobject buffer = android_video_buffer->video_frame_buffer();
459 return jni->NewObject(
460 *j_video_frame_class_, j_video_frame_constructor_id_, buffer,
461 static_cast<jint>(frame.rotation()),
462 static_cast<jlong>(frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec));
463 }
464
441 } // namespace webrtc_jni 465 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/native_handle_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698