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

Unified Diff: webrtc/api/android/jni/peerconnection_jni.cc

Issue 2513723002: Created a java wrapper for the callback OnAddTrack to PeerConnection.Observer (Closed)
Patch Set: Create java wrapper for callback. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/api/android/jni/peerconnection_jni.cc
diff --git a/webrtc/api/android/jni/peerconnection_jni.cc b/webrtc/api/android/jni/peerconnection_jni.cc
index 7012fc355a3f24257abf2326d918ed41e173ab9c..1a2c6e7eee4cb73196be2ecaf2ad9a8db1057b4f 100644
--- a/webrtc/api/android/jni/peerconnection_jni.cc
+++ b/webrtc/api/android/jni/peerconnection_jni.cc
@@ -173,18 +173,20 @@ class PCOJava : public PeerConnectionObserver {
: j_observer_global_(jni, j_observer),
j_observer_class_(jni, GetObjectClass(jni, *j_observer_global_)),
j_media_stream_class_(jni, FindClass(jni, "org/webrtc/MediaStream")),
- j_media_stream_ctor_(GetMethodID(
- jni, *j_media_stream_class_, "<init>", "(J)V")),
+ j_media_stream_ctor_(
+ GetMethodID(jni, *j_media_stream_class_, "<init>", "(J)V")),
j_audio_track_class_(jni, FindClass(jni, "org/webrtc/AudioTrack")),
- j_audio_track_ctor_(GetMethodID(
- jni, *j_audio_track_class_, "<init>", "(J)V")),
+ j_audio_track_ctor_(
+ GetMethodID(jni, *j_audio_track_class_, "<init>", "(J)V")),
j_video_track_class_(jni, FindClass(jni, "org/webrtc/VideoTrack")),
- j_video_track_ctor_(GetMethodID(
- jni, *j_video_track_class_, "<init>", "(J)V")),
+ j_video_track_ctor_(
+ GetMethodID(jni, *j_video_track_class_, "<init>", "(J)V")),
j_data_channel_class_(jni, FindClass(jni, "org/webrtc/DataChannel")),
- j_data_channel_ctor_(GetMethodID(
- jni, *j_data_channel_class_, "<init>", "(J)V")) {
- }
+ j_data_channel_ctor_(
+ GetMethodID(jni, *j_data_channel_class_, "<init>", "(J)V")),
+ j_rtp_receiver_class_(jni, FindClass(jni, "org/webrtc/RtpReceiver")),
+ j_rtp_receiver_ctor_(
+ GetMethodID(jni, *j_rtp_receiver_class_, "<init>", "(J)V")) {}
virtual ~PCOJava() {
ScopedLocalRefFrame local_ref_frame(jni());
@@ -374,6 +376,23 @@ class PCOJava : public PeerConnectionObserver {
CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
}
+ void OnAddTrack(
+ rtc::scoped_refptr<RtpReceiverInterface> receiver,
+ std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams) override {
+ ScopedLocalRefFrame local_ref_frame(jni());
+ jobject j_rtp_receiver = jni()->NewObject(
+ *j_rtp_receiver_class_, j_rtp_receiver_ctor_, (jlong)receiver.get());
+ CHECK_EXCEPTION(jni()) << "error during NewObject";
Taylor Brandstetter 2016/11/17 23:02:53 Need to call receiver->AddRef() after this, like i
Zhi Huang 2016/11/18 02:22:11 Good catch! This could be a potential problem.
+
+ jobjectArray j_stream_array = ToJavaMediaStreamArray(jni(), streams);
+ jmethodID m =
+ GetMethodID(jni(), *j_observer_class_, "onAddTrack",
+ "(Lorg/webrtc/RtpReceiver;[Lorg/webrtc/MediaStream;)V");
+ jni()->CallVoidMethod(*j_observer_global_, m, j_rtp_receiver,
+ j_stream_array);
+ CHECK_EXCEPTION(jni()) << "Error during CallVoidMethod";
+ }
+
void SetConstraints(ConstraintsWrapper* constraints) {
RTC_CHECK(!constraints_.get()) << "constraints already set!";
constraints_.reset(constraints);
@@ -423,6 +442,23 @@ class PCOJava : public PeerConnectionObserver {
return java_candidates;
}
+ jobjectArray ToJavaMediaStreamArray(
+ JNIEnv* jni,
+ std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams) {
+ jobjectArray java_streams =
+ jni->NewObjectArray(streams.size(), *j_media_stream_class_, nullptr);
+ int i = 0;
+ for (rtc::scoped_refptr<MediaStreamInterface> stream : streams) {
+ NativeToJavaStreamsMap::iterator it = remote_streams_.find(stream);
+ if (it != remote_streams_.end()) {
+ jobject j_stream = it->second;
+ CHECK_EXCEPTION(jni) << "error during NewObject";
Taylor Brandstetter 2016/11/17 23:02:53 I think this CHECK_EXCEPTION needs to be right aft
Zhi Huang 2016/11/18 02:22:10 Done.
+ jni->SetObjectArrayElement(java_streams, i++, j_stream);
+ }
Taylor Brandstetter 2016/11/17 23:02:53 There should be an "else" with an RTC_DCHECK.
Zhi Huang 2016/11/18 02:22:10 What about always creating new stream if we cannot
+ }
+ return java_streams;
+ }
+
JNIEnv* jni() {
return AttachCurrentThreadIfNeeded();
}
@@ -437,6 +473,8 @@ class PCOJava : public PeerConnectionObserver {
const jmethodID j_video_track_ctor_;
const ScopedGlobalRef<jclass> j_data_channel_class_;
const jmethodID j_data_channel_ctor_;
+ const ScopedGlobalRef<jclass> j_rtp_receiver_class_;
+ const jmethodID j_rtp_receiver_ctor_;
// C++ -> Java remote streams. The stored jobects are global refs and must be
// manually deleted upon removal. Use DisposeRemoteStream().
NativeToJavaStreamsMap remote_streams_;

Powered by Google App Engine
This is Rietveld 408576698