Add wrapper for VideoSink and VideoFrame to Android native_api.
Bug: webrtc:8769 Change-Id: If944b2a52a86666bebf094ec0e3c74c076d6c3d2 Reviewed-on: https://webrtc-review.googlesource.com/50740 Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22001}
This commit is contained in:
@ -212,6 +212,8 @@ rtc_static_library("video_jni") {
|
|||||||
"src/jni/videoencoderwrapper.h",
|
"src/jni/videoencoderwrapper.h",
|
||||||
"src/jni/videoframe.cc",
|
"src/jni/videoframe.cc",
|
||||||
"src/jni/videoframe.h",
|
"src/jni/videoframe.h",
|
||||||
|
"src/jni/videosink.cc",
|
||||||
|
"src/jni/videosink.h",
|
||||||
"src/jni/videotrack.cc",
|
"src/jni/videotrack.cc",
|
||||||
"src/jni/wrapped_native_i420_buffer.cc",
|
"src/jni/wrapped_native_i420_buffer.cc",
|
||||||
"src/jni/wrapped_native_i420_buffer.h",
|
"src/jni/wrapped_native_i420_buffer.h",
|
||||||
@ -807,6 +809,7 @@ group("native_api") {
|
|||||||
":native_api_base",
|
":native_api_base",
|
||||||
":native_api_codecs",
|
":native_api_codecs",
|
||||||
":native_api_jni",
|
":native_api_jni",
|
||||||
|
":native_api_video",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -893,6 +896,23 @@ rtc_static_library("native_api_codecs") {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# API for creating C++ wrapper implementations of api/mediastreaminterface.h
|
||||||
|
# video interfaces from their Java equivalents.
|
||||||
|
rtc_static_library("native_api_video") {
|
||||||
|
visibility = [ "*" ]
|
||||||
|
sources = [
|
||||||
|
"native_api/video/wrapper.cc",
|
||||||
|
"native_api/video/wrapper.h",
|
||||||
|
]
|
||||||
|
deps = [
|
||||||
|
":native_api_jni",
|
||||||
|
":video_jni",
|
||||||
|
"//api:libjingle_peerconnection_api",
|
||||||
|
"//api:video_frame_api",
|
||||||
|
"//rtc_base:rtc_base_approved",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
generate_jni("generated_native_unittests_jni") {
|
generate_jni("generated_native_unittests_jni") {
|
||||||
testonly = true
|
testonly = true
|
||||||
|
|
||||||
|
|||||||
32
sdk/android/native_api/video/wrapper.cc
Normal file
32
sdk/android/native_api/video/wrapper.cc
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sdk/android/native_api/video/wrapper.h"
|
||||||
|
|
||||||
|
#include "rtc_base/ptr_util.h"
|
||||||
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
#include "sdk/android/src/jni/videoframe.h"
|
||||||
|
#include "sdk/android/src/jni/videosink.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>> JavaToNativeVideoSink(
|
||||||
|
JNIEnv* jni,
|
||||||
|
jobject video_sink) {
|
||||||
|
return rtc::MakeUnique<jni::VideoSinkWrapper>(
|
||||||
|
jni, JavaParamRef<jobject>(video_sink));
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaVideoFrame(JNIEnv* jni,
|
||||||
|
const VideoFrame& frame) {
|
||||||
|
return jni::NativeToJavaFrame(jni, frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
35
sdk/android/native_api/video/wrapper.h
Normal file
35
sdk/android/native_api/video/wrapper.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SDK_ANDROID_NATIVE_API_VIDEO_WRAPPER_H_
|
||||||
|
#define SDK_ANDROID_NATIVE_API_VIDEO_WRAPPER_H_
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "api/mediastreaminterface.h"
|
||||||
|
#include "api/video/video_frame.h"
|
||||||
|
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
|
||||||
|
// Creates an instance of rtc::VideoSinkInterface<VideoFrame> from Java
|
||||||
|
// VideoSink.
|
||||||
|
std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>> JavaToNativeVideoSink(
|
||||||
|
JNIEnv* jni,
|
||||||
|
jobject video_sink);
|
||||||
|
|
||||||
|
// Creates a Java VideoFrame object from a native VideoFrame.
|
||||||
|
ScopedJavaLocalRef<jobject> NativeToJavaVideoFrame(JNIEnv* jni,
|
||||||
|
const VideoFrame& frame);
|
||||||
|
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_NATIVE_API_VIDEO_WRAPPER_H_
|
||||||
@ -59,7 +59,7 @@ class SurfaceTextureHelper : public rtc::RefCountInterface {
|
|||||||
void ReturnTextureFrame() const;
|
void ReturnTextureFrame() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~SurfaceTextureHelper();
|
~SurfaceTextureHelper() override;
|
||||||
SurfaceTextureHelper(JNIEnv* jni,
|
SurfaceTextureHelper(JNIEnv* jni,
|
||||||
const JavaRef<jobject>& j_surface_texture_helper);
|
const JavaRef<jobject>& j_surface_texture_helper);
|
||||||
|
|
||||||
|
|||||||
@ -285,6 +285,10 @@ rtc::scoped_refptr<I420BufferInterface> AndroidTextureBuffer::ToI420() {
|
|||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AndroidVideoFrameBuffer::AndroidType AndroidTextureBuffer::android_type() {
|
||||||
|
return AndroidType::kTextureBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBuffer::Adopt(
|
rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBuffer::Adopt(
|
||||||
JNIEnv* jni,
|
JNIEnv* jni,
|
||||||
const JavaRef<jobject>& j_video_frame_buffer) {
|
const JavaRef<jobject>& j_video_frame_buffer) {
|
||||||
@ -351,6 +355,10 @@ rtc::scoped_refptr<I420BufferInterface> AndroidVideoBuffer::ToI420() {
|
|||||||
return AndroidVideoI420Buffer::Adopt(jni, width_, height_, j_i420_buffer);
|
return AndroidVideoI420Buffer::Adopt(jni, width_, height_, j_i420_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AndroidVideoFrameBuffer::AndroidType AndroidVideoBuffer::android_type() {
|
||||||
|
return AndroidType::kJavaBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
VideoFrame JavaToNativeFrame(JNIEnv* jni,
|
VideoFrame JavaToNativeFrame(JNIEnv* jni,
|
||||||
const JavaRef<jobject>& j_video_frame,
|
const JavaRef<jobject>& j_video_frame,
|
||||||
uint32_t timestamp_rtp) {
|
uint32_t timestamp_rtp) {
|
||||||
|
|||||||
@ -84,7 +84,7 @@ class AndroidTextureBuffer : public AndroidVideoFrameBuffer {
|
|||||||
int height,
|
int height,
|
||||||
const NativeHandleImpl& native_handle,
|
const NativeHandleImpl& native_handle,
|
||||||
const rtc::scoped_refptr<SurfaceTextureHelper>& surface_texture_helper);
|
const rtc::scoped_refptr<SurfaceTextureHelper>& surface_texture_helper);
|
||||||
~AndroidTextureBuffer();
|
~AndroidTextureBuffer() override;
|
||||||
|
|
||||||
NativeHandleImpl native_handle_impl() const;
|
NativeHandleImpl native_handle_impl() const;
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ class AndroidTextureBuffer : public AndroidVideoFrameBuffer {
|
|||||||
|
|
||||||
rtc::scoped_refptr<I420BufferInterface> ToI420() override;
|
rtc::scoped_refptr<I420BufferInterface> ToI420() override;
|
||||||
|
|
||||||
AndroidType android_type() override { return AndroidType::kTextureBuffer; }
|
AndroidType android_type() override;
|
||||||
|
|
||||||
const int width_;
|
const int width_;
|
||||||
const int height_;
|
const int height_;
|
||||||
@ -143,7 +143,7 @@ class AndroidVideoBuffer : public AndroidVideoFrameBuffer {
|
|||||||
|
|
||||||
rtc::scoped_refptr<I420BufferInterface> ToI420() override;
|
rtc::scoped_refptr<I420BufferInterface> ToI420() override;
|
||||||
|
|
||||||
AndroidType android_type() override { return AndroidType::kJavaBuffer; }
|
AndroidType android_type() override;
|
||||||
|
|
||||||
const int width_;
|
const int width_;
|
||||||
const int height_;
|
const int height_;
|
||||||
|
|||||||
30
sdk/android/src/jni/videosink.cc
Normal file
30
sdk/android/src/jni/videosink.cc
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sdk/android/src/jni/videosink.h"
|
||||||
|
|
||||||
|
#include "sdk/android/generated_video_jni/jni/VideoSink_jni.h"
|
||||||
|
#include "sdk/android/src/jni/videoframe.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace jni {
|
||||||
|
|
||||||
|
VideoSinkWrapper::VideoSinkWrapper(JNIEnv* jni, const JavaRef<jobject>& j_sink)
|
||||||
|
: j_sink_(jni, j_sink) {}
|
||||||
|
|
||||||
|
VideoSinkWrapper::~VideoSinkWrapper() {}
|
||||||
|
|
||||||
|
void VideoSinkWrapper::OnFrame(const VideoFrame& frame) {
|
||||||
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||||
|
Java_VideoSink_onFrame(jni, j_sink_, NativeToJavaFrame(jni, frame));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace jni
|
||||||
|
} // namespace webrtc
|
||||||
36
sdk/android/src/jni/videosink.h
Normal file
36
sdk/android/src/jni/videosink.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SDK_ANDROID_SRC_JNI_VIDEOSINK_H_
|
||||||
|
#define SDK_ANDROID_SRC_JNI_VIDEOSINK_H_
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
#include "api/mediastreaminterface.h"
|
||||||
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace jni {
|
||||||
|
|
||||||
|
class VideoSinkWrapper : public rtc::VideoSinkInterface<VideoFrame> {
|
||||||
|
public:
|
||||||
|
VideoSinkWrapper(JNIEnv* jni, const JavaRef<jobject>& j_sink);
|
||||||
|
~VideoSinkWrapper() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void OnFrame(const VideoFrame& frame) override;
|
||||||
|
|
||||||
|
const ScopedJavaGlobalRef<jobject> j_sink_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace jni
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_SRC_JNI_VIDEOSINK_H_
|
||||||
@ -11,38 +11,13 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include "api/mediastreaminterface.h"
|
#include "api/mediastreaminterface.h"
|
||||||
#include "rtc_base/logging.h"
|
|
||||||
#include "sdk/android/generated_video_jni/jni/VideoSink_jni.h"
|
|
||||||
#include "sdk/android/generated_video_jni/jni/VideoTrack_jni.h"
|
#include "sdk/android/generated_video_jni/jni/VideoTrack_jni.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
#include "sdk/android/src/jni/videoframe.h"
|
#include "sdk/android/src/jni/videosink.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
class VideoSinkWrapper : public rtc::VideoSinkInterface<VideoFrame> {
|
|
||||||
public:
|
|
||||||
VideoSinkWrapper(JNIEnv* jni, const JavaRef<jobject>& j_sink);
|
|
||||||
~VideoSinkWrapper() override {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void OnFrame(const VideoFrame& frame) override;
|
|
||||||
|
|
||||||
const ScopedJavaGlobalRef<jobject> j_sink_;
|
|
||||||
};
|
|
||||||
|
|
||||||
VideoSinkWrapper::VideoSinkWrapper(JNIEnv* jni, const JavaRef<jobject>& j_sink)
|
|
||||||
: j_sink_(jni, j_sink) {}
|
|
||||||
|
|
||||||
void VideoSinkWrapper::OnFrame(const VideoFrame& frame) {
|
|
||||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
|
||||||
Java_VideoSink_onFrame(jni, j_sink_, NativeToJavaFrame(jni, frame));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
static void JNI_VideoTrack_AddSink(JNIEnv* jni,
|
static void JNI_VideoTrack_AddSink(JNIEnv* jni,
|
||||||
const JavaParamRef<jclass>&,
|
const JavaParamRef<jclass>&,
|
||||||
jlong j_native_track,
|
jlong j_native_track,
|
||||||
|
|||||||
Reference in New Issue
Block a user