blob: a77e4facb00db738ae495a5267c84bca8b76899d [file] [edit]
/*
* 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/video_sink.h"
#include <jni.h>
#include "api/video/video_frame.h"
#include "rtc_base/logging.h"
#include "sdk/android/generated_video_jni/VideoSink_jni.h"
#include "sdk/android/native_api/jni/jvm.h"
#include "sdk/android/native_api/jni/scoped_java_ref.h"
#include "sdk/android/src/jni/video_frame.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();
ScopedJavaLocalRef<jobject> j_frame = NativeToJavaVideoFrame(jni, frame);
if (!j_frame) {
RTC_LOG(LS_WARNING) << "NativeToJavaVideoFrame failed. Dropping frame.";
return;
}
Java_VideoSink_onFrame(jni, j_sink_, j_frame);
ReleaseJavaVideoFrame(jni, j_frame);
}
} // namespace jni
} // namespace webrtc
DEFINE_JNI(VideoSink)