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:
@ -59,7 +59,7 @@ class SurfaceTextureHelper : public rtc::RefCountInterface {
|
||||
void ReturnTextureFrame() const;
|
||||
|
||||
protected:
|
||||
~SurfaceTextureHelper();
|
||||
~SurfaceTextureHelper() override;
|
||||
SurfaceTextureHelper(JNIEnv* jni,
|
||||
const JavaRef<jobject>& j_surface_texture_helper);
|
||||
|
||||
|
||||
@ -285,6 +285,10 @@ rtc::scoped_refptr<I420BufferInterface> AndroidTextureBuffer::ToI420() {
|
||||
return copy;
|
||||
}
|
||||
|
||||
AndroidVideoFrameBuffer::AndroidType AndroidTextureBuffer::android_type() {
|
||||
return AndroidType::kTextureBuffer;
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<AndroidVideoBuffer> AndroidVideoBuffer::Adopt(
|
||||
JNIEnv* jni,
|
||||
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);
|
||||
}
|
||||
|
||||
AndroidVideoFrameBuffer::AndroidType AndroidVideoBuffer::android_type() {
|
||||
return AndroidType::kJavaBuffer;
|
||||
}
|
||||
|
||||
VideoFrame JavaToNativeFrame(JNIEnv* jni,
|
||||
const JavaRef<jobject>& j_video_frame,
|
||||
uint32_t timestamp_rtp) {
|
||||
|
||||
@ -84,7 +84,7 @@ class AndroidTextureBuffer : public AndroidVideoFrameBuffer {
|
||||
int height,
|
||||
const NativeHandleImpl& native_handle,
|
||||
const rtc::scoped_refptr<SurfaceTextureHelper>& surface_texture_helper);
|
||||
~AndroidTextureBuffer();
|
||||
~AndroidTextureBuffer() override;
|
||||
|
||||
NativeHandleImpl native_handle_impl() const;
|
||||
|
||||
@ -95,7 +95,7 @@ class AndroidTextureBuffer : public AndroidVideoFrameBuffer {
|
||||
|
||||
rtc::scoped_refptr<I420BufferInterface> ToI420() override;
|
||||
|
||||
AndroidType android_type() override { return AndroidType::kTextureBuffer; }
|
||||
AndroidType android_type() override;
|
||||
|
||||
const int width_;
|
||||
const int height_;
|
||||
@ -143,7 +143,7 @@ class AndroidVideoBuffer : public AndroidVideoFrameBuffer {
|
||||
|
||||
rtc::scoped_refptr<I420BufferInterface> ToI420() override;
|
||||
|
||||
AndroidType android_type() override { return AndroidType::kJavaBuffer; }
|
||||
AndroidType android_type() override;
|
||||
|
||||
const int width_;
|
||||
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 "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/src/jni/jni_helpers.h"
|
||||
#include "sdk/android/src/jni/videoframe.h"
|
||||
#include "sdk/android/src/jni/videosink.h"
|
||||
|
||||
namespace webrtc {
|
||||
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,
|
||||
const JavaParamRef<jclass>&,
|
||||
jlong j_native_track,
|
||||
|
||||
Reference in New Issue
Block a user