Expose peer connection's getStats by RtpSender/Receiver in Android SDK

Currently if you want to obtain the stats for a specific sender/receiver
in Android, you need to call peerConnection.getStats() and filter
manually the result by sender.

pc.getStats(receiver/sender) exists in c++ and ios but was not exposed
in Android

Bug: webrtc:14547
Change-Id: I9954434880f0f93821fcd2e2de24a875e8d136ae
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/275880
Reviewed-by: Xavier Lepaul‎ <xalep@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38428}
This commit is contained in:
Roberto Perez
2022-10-07 10:50:46 +02:00
committed by WebRTC LUCI CQ
parent 048f5c7516
commit 4dc6e05ac9
5 changed files with 68 additions and 0 deletions

View File

@ -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<RtpSender> nativeGetSenders();
private native List<RtpReceiver> nativeGetReceivers();

View File

@ -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();