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

Side by Side Diff: webrtc/sdk/android/src/jni/videotrack_jni.cc

Issue 3002553002: Add support for adding VideoSinks to VideoTracks. (Closed)
Patch Set: Add documentation, fix bug. 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <jni.h> 11 #include <jni.h>
12 12
13 #include "webrtc/api/mediastreaminterface.h" 13 #include "webrtc/api/mediastreaminterface.h"
14 #include "webrtc/rtc_base/logging.h" 14 #include "webrtc/rtc_base/logging.h"
15 #include "webrtc/sdk/android/src/jni/classreferenceholder.h"
16 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
17 #include "webrtc/sdk/android/src/jni/native_handle_impl.h"
15 18
16 namespace webrtc_jni { 19 namespace webrtc_jni {
17 20
21 namespace {
22
23 class VideoSinkWrapper : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
24 public:
25 VideoSinkWrapper(JNIEnv* jni, jobject j_sink);
26 ~VideoSinkWrapper() override {}
27
28 private:
29 void OnFrame(const webrtc::VideoFrame& frame) override;
30
31 jmethodID j_on_frame_method_;
32
33 const JavaVideoFrameFactory java_video_frame_factory_;
34 const ScopedGlobalRef<jobject> j_sink_;
35 };
36
37 VideoSinkWrapper::VideoSinkWrapper(JNIEnv* jni, jobject j_sink)
38 : java_video_frame_factory_(jni), j_sink_(jni, j_sink) {
39 jclass j_video_sink_class = FindClass(jni, "org/webrtc/VideoSink");
40 j_on_frame_method_ = jni->GetMethodID(j_video_sink_class, "onFrame",
41 "(Lorg/webrtc/VideoFrame;)V");
42 }
43
44 void VideoSinkWrapper::OnFrame(const webrtc::VideoFrame& frame) {
45 JNIEnv* jni = AttachCurrentThreadIfNeeded();
46 ScopedLocalRefFrame local_ref_frame(jni);
47 jni->CallVoidMethod(*j_sink_, j_on_frame_method_,
48 java_video_frame_factory_.ToJavaFrame(jni, frame));
49 }
50
51 } // namespace
52
18 extern "C" JNIEXPORT void JNICALL 53 extern "C" JNIEXPORT void JNICALL
19 Java_org_webrtc_VideoTrack_nativeAddRenderer(JNIEnv* jni, 54 Java_org_webrtc_VideoTrack_nativeAddSink(JNIEnv* jni,
20 jclass, 55 jclass,
21 jlong j_video_track_pointer, 56 jlong j_native_track,
22 jlong j_renderer_pointer) { 57 jlong j_native_sink) {
23 LOG(LS_INFO) << "VideoTrack::nativeAddRenderer"; 58 reinterpret_cast<webrtc::VideoTrackInterface*>(j_native_track)
24 reinterpret_cast<webrtc::VideoTrackInterface*>(j_video_track_pointer)
25 ->AddOrUpdateSink( 59 ->AddOrUpdateSink(
26 reinterpret_cast<rtc::VideoSinkInterface<webrtc::VideoFrame>*>( 60 reinterpret_cast<rtc::VideoSinkInterface<webrtc::VideoFrame>*>(
27 j_renderer_pointer), 61 j_native_sink),
28 rtc::VideoSinkWants()); 62 rtc::VideoSinkWants());
29 } 63 }
30 64
31 extern "C" JNIEXPORT void JNICALL 65 extern "C" JNIEXPORT void JNICALL
32 Java_org_webrtc_VideoTrack_nativeRemoveRenderer(JNIEnv* jni, 66 Java_org_webrtc_VideoTrack_nativeRemoveSink(JNIEnv* jni,
33 jclass, 67 jclass,
34 jlong j_video_track_pointer, 68 jlong j_native_track,
35 jlong j_renderer_pointer) { 69 jlong j_native_sink) {
36 reinterpret_cast<webrtc::VideoTrackInterface*>(j_video_track_pointer) 70 reinterpret_cast<webrtc::VideoTrackInterface*>(j_native_track)
37 ->RemoveSink( 71 ->RemoveSink(
38 reinterpret_cast<rtc::VideoSinkInterface<webrtc::VideoFrame>*>( 72 reinterpret_cast<rtc::VideoSinkInterface<webrtc::VideoFrame>*>(
39 j_renderer_pointer)); 73 j_native_sink));
74 }
75
76 extern "C" JNIEXPORT jlong JNICALL
77 Java_org_webrtc_VideoTrack_nativeWrapSink(JNIEnv* jni, jclass, jobject sink) {
78 return jlongFromPointer(new VideoSinkWrapper(jni, sink));
79 }
80
81 extern "C" JNIEXPORT void JNICALL
82 Java_org_webrtc_VideoTrack_nativeFreeSink(JNIEnv* jni,
83 jclass,
84 jlong j_native_sink) {
85 delete reinterpret_cast<rtc::VideoSinkInterface<webrtc::VideoFrame>*>(
86 j_native_sink);
40 } 87 }
41 88
42 } // namespace webrtc_jni 89 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/native_handle_impl.cc ('k') | webrtc/sdk/android/src/jni/wrapped_native_i420_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698