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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/sdk/android/src/jni/native_handle_impl.cc
diff --git a/webrtc/sdk/android/src/jni/native_handle_impl.cc b/webrtc/sdk/android/src/jni/native_handle_impl.cc
index f0070b9ee9e2edce474a74fa128f411a6b12726b..eebfba403575bcd8fe8f104fb5b24698dfdcb690 100644
--- a/webrtc/sdk/android/src/jni/native_handle_impl.cc
+++ b/webrtc/sdk/android/src/jni/native_handle_impl.cc
@@ -375,8 +375,7 @@ rtc::scoped_refptr<webrtc::I420BufferInterface> AndroidVideoBuffer::ToI420() {
height_, j_i420_buffer);
}
-jobject AndroidVideoBuffer::ToJavaI420Frame(JNIEnv* jni,
- int rotation) {
+jobject AndroidVideoBuffer::ToJavaI420Frame(JNIEnv* jni, int rotation) {
jclass j_byte_buffer_class = jni->FindClass("java/nio/ByteBuffer");
jclass j_i420_frame_class =
FindClass(jni, "org/webrtc/VideoRenderer$I420Frame");
@@ -438,4 +437,29 @@ rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBufferFactory::CreateBuffer(
jni, j_retain_id_, j_release_id_, width, height, j_video_frame_buffer);
}
+JavaVideoFrameFactory::JavaVideoFrameFactory(JNIEnv* jni)
+ : j_video_frame_class_(jni, FindClass(jni, "org/webrtc/VideoFrame")) {
+ j_video_frame_constructor_id_ =
+ GetMethodID(jni, *j_video_frame_class_, "<init>",
+ "(Lorg/webrtc/VideoFrame$Buffer;IJ)V");
+}
+
+jobject JavaVideoFrameFactory::ToJavaFrame(
+ JNIEnv* jni,
+ const webrtc::VideoFrame& frame) const {
+ RTC_DCHECK(frame.video_frame_buffer()->type() ==
+ webrtc::VideoFrameBuffer::Type::kNative);
+ AndroidVideoFrameBuffer* android_buffer =
+ static_cast<AndroidVideoFrameBuffer*>(frame.video_frame_buffer().get());
+ RTC_DCHECK(android_buffer->android_type() ==
+ AndroidVideoFrameBuffer::AndroidType::kJavaBuffer);
+ AndroidVideoBuffer* android_video_buffer =
+ static_cast<AndroidVideoBuffer*>(android_buffer);
+ jobject buffer = android_video_buffer->video_frame_buffer();
+ return jni->NewObject(
+ *j_video_frame_class_, j_video_frame_constructor_id_, buffer,
+ static_cast<jint>(frame.rotation()),
+ static_cast<jlong>(frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec));
+}
+
} // namespace webrtc_jni
« 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