diff --git a/AUTHORS b/AUTHORS index 2fdd9fd4f4..a0632d20fa 100644 --- a/AUTHORS +++ b/AUTHORS @@ -141,6 +141,7 @@ CoSMo Software Consulting, Pte Ltd <*@cosmosoftware.io> Facebook Inc. <*@fb.com> Google Inc. <*@google.com> Highfive, Inc. <*@highfive.com> +Hopin Ltd. <*@hopin.to> HyperConnect Inc. <*@hpcnt.com> Intel Corporation <*@intel.com> LG Electronics, Inc. <*@lge.com> diff --git a/sdk/android/api/org/webrtc/PeerConnection.java b/sdk/android/api/org/webrtc/PeerConnection.java index 724f70468d..2d592a5973 100644 --- a/sdk/android/api/org/webrtc/PeerConnection.java +++ b/sdk/android/api/org/webrtc/PeerConnection.java @@ -1176,6 +1176,22 @@ public class PeerConnection { nativeNewGetStats(callback); } + /** + * Gets stats using the new stats collection API, see webrtc/api/stats/. These + * will replace old stats collection API when the new API has matured enough. + */ + public void getStats(RtpSender sender, RTCStatsCollectorCallback callback) { + nativeNewGetStatsSender(sender.getNativeRtpSender(), callback); + } + + /** + * Gets stats using the new stats collection API, see webrtc/api/stats/. These + * will replace old stats collection API when the new API has matured enough. + */ + public void getStats(RtpReceiver receiver, RTCStatsCollectorCallback callback) { + nativeNewGetStatsReceiver(receiver.getNativeRtpReceiver(), callback); + } + /** * Limits the bandwidth allocated for all RTP streams sent by this * PeerConnection. Pass null to leave a value unchanged. @@ -1310,6 +1326,8 @@ public class PeerConnection { private native void nativeRemoveLocalStream(long stream); private native boolean nativeOldGetStats(StatsObserver observer, long nativeTrack); private native void nativeNewGetStats(RTCStatsCollectorCallback callback); + private native void nativeNewGetStatsSender(long sender, RTCStatsCollectorCallback callback); + private native void nativeNewGetStatsReceiver(long receiver, RTCStatsCollectorCallback callback); private native RtpSender nativeCreateSender(String kind, String stream_id); private native List nativeGetSenders(); private native List nativeGetReceivers(); diff --git a/sdk/android/api/org/webrtc/RtpReceiver.java b/sdk/android/api/org/webrtc/RtpReceiver.java index a5710f92e3..c3cff3dd31 100644 --- a/sdk/android/api/org/webrtc/RtpReceiver.java +++ b/sdk/android/api/org/webrtc/RtpReceiver.java @@ -49,6 +49,12 @@ public class RtpReceiver { return nativeGetId(nativeRtpReceiver); } + /** Returns a pointer to webrtc::RtpReceiverInterface. */ + long getNativeRtpReceiver() { + checkRtpReceiverExists(); + return nativeRtpReceiver; + } + @CalledByNative public void dispose() { checkRtpReceiverExists(); diff --git a/sdk/android/instrumentationtests/src/org/webrtc/PeerConnectionEndToEndTest.java b/sdk/android/instrumentationtests/src/org/webrtc/PeerConnectionEndToEndTest.java index f71bd36063..d763ff2190 100644 --- a/sdk/android/instrumentationtests/src/org/webrtc/PeerConnectionEndToEndTest.java +++ b/sdk/android/instrumentationtests/src/org/webrtc/PeerConnectionEndToEndTest.java @@ -931,6 +931,23 @@ public class PeerConnectionEndToEndTest { assertTrue(offeringPC.setBitrate(100000, 5000000, 500000000)); assertFalse(offeringPC.setBitrate(3, 2, 1)); + // Test getStats by Sender interface + offeringExpectations.expectNewStatsCallback(); + offeringPC.getStats(videoSender, offeringExpectations); + assertTrue(offeringExpectations.waitForAllExpectationsToBeSatisfied(DEFAULT_TIMEOUT_SECONDS)); + + // Test getStats by Receiver interface + RtpReceiver videoReceiver = null; + for (RtpReceiver receiver : answeringPC.getReceivers()) { + if (receiver.track().kind().equals("video")) { + videoReceiver = receiver; + } + } + assertNotNull(videoReceiver); + answeringExpectations.expectNewStatsCallback(); + answeringPC.getStats(videoReceiver, answeringExpectations); + assertTrue(answeringExpectations.waitForAllExpectationsToBeSatisfied(DEFAULT_TIMEOUT_SECONDS)); + // Free the Java-land objects and collect them. shutdownPC(offeringPC, offeringExpectations); offeringPC = null; diff --git a/sdk/android/src/jni/pc/peer_connection.cc b/sdk/android/src/jni/pc/peer_connection.cc index 03321a53c1..8c76b4256a 100644 --- a/sdk/android/src/jni/pc/peer_connection.cc +++ b/sdk/android/src/jni/pc/peer_connection.cc @@ -842,6 +842,32 @@ static void JNI_PeerConnection_NewGetStats( ExtractNativePC(jni, j_pc)->GetStats(callback.get()); } +static void JNI_PeerConnection_NewGetStatsSender( + JNIEnv* jni, + const JavaParamRef& j_pc, + jlong native_sender, + const JavaParamRef& j_callback) { + auto callback = + rtc::make_ref_counted(jni, j_callback); + ExtractNativePC(jni, j_pc)->GetStats( + rtc::scoped_refptr( + reinterpret_cast(native_sender)), + rtc::scoped_refptr(callback.get())); +} + +static void JNI_PeerConnection_NewGetStatsReceiver( + JNIEnv* jni, + const JavaParamRef& j_pc, + jlong native_receiver, + const JavaParamRef& j_callback) { + auto callback = + rtc::make_ref_counted(jni, j_callback); + ExtractNativePC(jni, j_pc)->GetStats( + rtc::scoped_refptr( + reinterpret_cast(native_receiver)), + rtc::scoped_refptr(callback.get())); +} + static jboolean JNI_PeerConnection_SetBitrate( JNIEnv* jni, const JavaParamRef& j_pc,