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 |