org.webrtc.StatsReport Java Examples
The following examples show how to use
org.webrtc.StatsReport.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PeerConnectionClient.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") // TODO(sakal): getStats is deprecated. public boolean getStats() { if (peerConnection == null || isError) { return false; } boolean success = peerConnection.getStats(new StatsObserver() { @Override public void onComplete(final StatsReport[] reports) { events.onPeerConnectionStatsReady(reports); } }, null); if (!success) { Log.e(TAG, "getStats() returns false!"); return false; } return true; }
Example #2
Source File: PeerConnectionClient.java From sample-videoRTC with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") // TODO(sakal): getStats is deprecated. private void getStats() { if (peerConnection == null || isError) { return; } boolean success = peerConnection.getStats(new StatsObserver() { @Override public void onComplete(final StatsReport[] reports) { events.onPeerConnectionStatsReady(reports); } }, null); if (!success) { Log.e(TAG, "getStats() returns false!"); } }
Example #3
Source File: AppRTCDemoActivity.java From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void updateHUD(StatsReport[] reports) { StringBuilder builder = new StringBuilder(); for (StatsReport report : reports) { if (!report.id.equals("bweforvideo")) { continue; } for (StatsReport.Value value : report.values) { String name = value.name.replace("goog", "").replace("Available", "") .replace("Bandwidth", "").replace("Bitrate", "").replace("Enc", ""); builder.append(name).append("=").append(value.value).append(" "); } builder.append("\n"); } hudView.setText(builder.toString() + hudView.getText()); }
Example #4
Source File: RCConnection.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onPeerConnectionStatsReady(final StatsReport[] reports) { Handler mainHandler = new Handler(device.getMainLooper()); Runnable myRunnable = new Runnable() { @Override public void run() { // by the time stats are returned (when requested at disconnect(), iceConnected might have transitioned to disconnected webrtcReportsJsonString = webrtcStatsReports2JsonString(reports); try { //String statsJsonString = webrtcReportsJsonString; String statsJsonString = "WebRTC getStats() reports in json format: " + new JSONObject(webrtcReportsJsonString).toString(3); //RCLogger.i(TAG, "Stats: " + statsJsonString); // Logcat enforces a max size to logged messages, so to avoid getting truncated logs, let's break // the json reports that tend to be huge in 1000-byte chunks final int CHUNK_SIZE = 1000; for (int i = 0; i <= statsJsonString.length() / CHUNK_SIZE; i++) { int start = i * CHUNK_SIZE; int end = (i + 1) * CHUNK_SIZE; end = end > statsJsonString.length() ? statsJsonString.length() : end; RCLogger.i(TAG, statsJsonString.substring(start, end)); } } catch (JSONException e) { e.printStackTrace(); } handleDisconnect(null); } }; mainHandler.post(myRunnable); }
Example #5
Source File: AppRTCDemoActivity.java From WebRTCDemo with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void updateHUD(StatsReport[] reports) { StringBuilder builder = new StringBuilder(); for (StatsReport report : reports) { // bweforvideo to show statistics for video Bandwidth Estimation, // which is global per-session. if (report.id.equals("bweforvideo")) { for (StatsReport.Value value : report.values) { String name = value.name.replace("goog", "") .replace("Available", "").replace("Bandwidth", "") .replace("Bitrate", "").replace("Enc", ""); builder.append(name).append("=").append(value.value) .append(" "); } builder.append("\n"); } else if (report.type.equals("googCandidatePair")) { String activeConnectionStats = getActiveConnectionStats(report); if (activeConnectionStats == null) { continue; } builder.append(activeConnectionStats); } else { continue; } builder.append("\n"); } hudView.setText(builder.toString() + hudView.getText()); }
Example #6
Source File: PeerConnectionClient.java From voip_android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void getStats() { if (peerConnection == null || isError) { return; } boolean success = peerConnection.getStats(new StatsObserver() { @Override public void onComplete(final StatsReport[] reports) { events.onPeerConnectionStatsReady(reports); } }, null); if (!success) { Log.e(TAG, "getStats() returns false!"); } }
Example #7
Source File: WebRTCActivity.java From voip_android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onPeerConnectionStatsReady(final StatsReport[] reports) { runOnUiThread(new Runnable() { @Override public void run() { if (!isError && iceConnected) { updateEncoderStatistics(reports); } } }); }
Example #8
Source File: WebRTCActivity.java From voip_android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Map<String, String> getReportMap(StatsReport report) { Map<String, String> reportMap = new HashMap<String, String>(); for (StatsReport.Value value : report.values) { reportMap.put(value.name, value.value); } return reportMap; }
Example #9
Source File: CallActivity.java From Yahala-Messenger with MIT License | 5 votes |
@Override public void onPeerConnectionStatsReady(final StatsReport[] reports) { runOnUiThread(new Runnable() { @Override public void run() { if (!isError && iceConnected) { hudFragment.updateEncoderStatistics(reports); } } }); }
Example #10
Source File: PeerConnectionClient.java From Yahala-Messenger with MIT License | 5 votes |
private void getStats() { if (peerConnection == null || isError) { return; } boolean success = peerConnection.getStats(new StatsObserver() { @Override public void onComplete(final StatsReport[] reports) { events.onPeerConnectionStatsReady(reports); } }, null); if (!success) { Log.e(TAG, "getStats() returns false!"); } }
Example #11
Source File: HudFragment.java From Yahala-Messenger with MIT License | 5 votes |
private Map<String, String> getReportMap(StatsReport report) { Map<String, String> reportMap = new HashMap<String, String>(); for (StatsReport.Value value : report.values) { reportMap.put(value.name, value.value); } return reportMap; }
Example #12
Source File: PeerConnectionClient.java From janus-gateway-android with MIT License | 5 votes |
private void getStats(final BigInteger handleId) { PeerConnection peerConnection = peerConnectionMap.get(handleId).peerConnection; boolean success = peerConnection.getStats(new StatsObserver() { @Override public void onComplete(final StatsReport[] reports) { events.onPeerConnectionStatsReady(reports); } }, null); if (!success) { Log.e(TAG, "getStats() returns false!"); } }
Example #13
Source File: AppRTCDemoActivity.java From WebRTCDemo with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onIceServers(List<PeerConnection.IceServer> iceServers) { factory = new PeerConnectionFactory(); MediaConstraints pcConstraints = appRtcClient.pcConstraints(); pcConstraints.optional.add( new MediaConstraints.KeyValuePair("RtpDataChannels", "true")); pc = factory.createPeerConnection(iceServers, pcConstraints, pcObserver); createDataChannelToRegressionTestBug2302(pc); // See method comment. // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging. // NOTE: this _must_ happen while |factory| is alive! // Logging.enableTracing( // "logcat:", // EnumSet.of(Logging.TraceLevel.TRACE_ALL), // Logging.Severity.LS_SENSITIVE); { final PeerConnection finalPC = pc; final Runnable repeatedStatsLogger = new Runnable() { public void run() { synchronized (quit[0]) { if (quit[0]) { return; } final Runnable runnableThis = this; if (hudView.getVisibility() == View.INVISIBLE) { vsv.postDelayed(runnableThis, 1000); return; } boolean success = finalPC.getStats(new StatsObserver() { public void onComplete(final StatsReport[] reports) { runOnUiThread(new Runnable() { public void run() { updateHUD(reports); } }); for (StatsReport report : reports) { Log.d(TAG, "Stats: " + report.toString()); } vsv.postDelayed(runnableThis, 1000); } }, null); if (!success) { throw new RuntimeException("getStats() return false!"); } } } }; vsv.postDelayed(repeatedStatsLogger, 1000); } { logAndToast("Creating local video source..."); MediaStream lMS = factory.createLocalMediaStream("ARDAMS"); if (appRtcClient.videoConstraints() != null) { VideoCapturer capturer = getVideoCapturer(); videoSource = factory.createVideoSource( capturer, appRtcClient.videoConstraints()); VideoTrack videoTrack = factory.createVideoTrack("ARDAMSv0", videoSource); videoTrack.addRenderer(new VideoRenderer(localRender)); lMS.addTrack(videoTrack); } if (appRtcClient.audioConstraints() != null) { lMS.addTrack(factory.createAudioTrack( "ARDAMSa0", factory.createAudioSource(appRtcClient.audioConstraints()))); } pc.addStream(lMS, new MediaConstraints()); } logAndToast("Waiting for ICE candidates..."); }
Example #14
Source File: CallActivity.java From sample-videoRTC with Apache License 2.0 | 4 votes |
@Override public void onPeerConnectionStatsReady(final StatsReport[] reports) { }
Example #15
Source File: AppRTCDemoActivity.java From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onIceServers(List<PeerConnection.IceServer> iceServers) { factory = new PeerConnectionFactory(); MediaConstraints pcConstraints = appRtcClient.pcConstraints(); pcConstraints.optional.add( new MediaConstraints.KeyValuePair("RtpDataChannels", "true")); pc = factory.createPeerConnection(iceServers, pcConstraints, pcObserver); createDataChannelToRegressionTestBug2302(pc); // See method comment. // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging. // NOTE: this _must_ happen while |factory| is alive! // Logging.enableTracing( // "logcat:", // EnumSet.of(Logging.TraceLevel.TRACE_ALL), // Logging.Severity.LS_SENSITIVE); { final PeerConnection finalPC = pc; final Runnable repeatedStatsLogger = new Runnable() { public void run() { synchronized (quit[0]) { if (quit[0]) { return; } final Runnable runnableThis = this; if (hudView.getVisibility() == View.INVISIBLE) { vsv.postDelayed(runnableThis, 1000); return; } boolean success = finalPC.getStats(new StatsObserver() { public void onComplete(final StatsReport[] reports) { runOnUiThread(new Runnable() { public void run() { updateHUD(reports); } }); for (StatsReport report : reports) { Log.d(TAG, "Stats: " + report.toString()); } vsv.postDelayed(runnableThis, 1000); } }, null); if (!success) { throw new RuntimeException("getStats() return false!"); } } } }; vsv.postDelayed(repeatedStatsLogger, 1000); } { logAndToast("Creating local video source..."); MediaStream lMS = factory.createLocalMediaStream("ARDAMS"); if (appRtcClient.videoConstraints() != null) { VideoCapturer capturer = getVideoCapturer(); videoSource = factory.createVideoSource( capturer, appRtcClient.videoConstraints()); VideoTrack videoTrack = factory.createVideoTrack("ARDAMSv0", videoSource); videoTrack.addRenderer(new VideoRenderer(localRender)); lMS.addTrack(videoTrack); } if (appRtcClient.audioConstraints() != null) { lMS.addTrack(factory.createAudioTrack( "ARDAMSa0", factory.createAudioSource(appRtcClient.audioConstraints()))); } pc.addStream(lMS, new MediaConstraints()); } logAndToast("Waiting for ICE candidates..."); }
Example #16
Source File: RCConnection.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 3 votes |
/** * Converts a WebRTC stats report array as provided by PeerConnection to a valid json string * * The input reports are in the format used by Google facilities at this point and for the most part resemble what is * described in the WebRTC PeerConnection spec: http://w3c.github.io/webrtc-pc/#sec.stats-model, but still there are * inconsistencies. The general idea is that stats are a series of reports, each of which has the following structure: * id, type, timestamp, series of key/value pairs. Here are 2 reports as they are returned from PeerConnection.getStats() * after being converted toString(): * * id: ssrc_2321116827_send, type: ssrc, timestamp: 1.501168721148511E12, values: [audioInputLevel:188], [bytesSent:22532], [mediaType:audio], [packetsSent:131], * [ssrc:2321116827], [transportId:Channel-audio-1], [googCodecName:PCMU], [googEchoCancellationReturnLoss:-100], [googEchoCancellationReturnLossEnhancement:-100], * [googResidualEchoLikelihood:0.0581064], [googResidualEchoLikelihoodRecentMax:0.0581064], [googTrackId:ARDAMSa0], [googTypingNoiseState:false], * id: Channel-audio-1, type: googComponent, timestamp: 1.501168721148511E12, values: [selectedCandidatePairId: Conn-audio-1-0], [googComponent: 1], * [dtlsCipher: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256], [localCertificateId: googCertificate_34:0E:F4:9B:39:06:49:14:E0:25:34:96:95:9E:E3:4B:95:B4:86:31:86:4E:74:5D:4D:A4:C5:13:46:A1:31:17], [remoteCertificateId: googCertificate_82:1E:5E:EB:B5:0D:F8:CF:7A:72:43:FE:91:3A:CE:DC:20:D1:4E:F4:69:4B:06:B4:AA:03:41:67:19:F1:E5:24], [srtpCipher: AES_CM_128_HMAC_SHA1_80], * * We use a conversion mechanism to turn that into a usable json string of the following format. Here's how the previous * 2 reports look like to get an idea of the changes involved: * { * "media":[ * { * "id":"ssrc_2321116827_send", * "type":"ssrc", * "timestamp":"1.501168721148511E12", * "values":{ * "audioInputLevel":"188", * "bytesSent":"22532", * "mediaType":"audio", * "packetsSent":"131", * "ssrc":"2321116827", * "transportId":"Channel-audio-1", * "googCodecName":"PCMU", * "googEchoCancellationReturnLoss":"-100", * "googEchoCancellationReturnLossEnhancement":"-100", * "googResidualEchoLikelihood":"0.0581064", * "googResidualEchoLikelihoodRecentMax":"0.0581064", * "googTrackId":"ARDAMSa0", * "googTypingNoiseState":"false" * } * }, * { * "id":"Channel-audio-1", * "type":"googComponent", * "timestamp":"1.501168721148511E12", * "values":{ * "selectedCandidatePairId":"Conn-audio-1-0", * "googComponent":"1", * "dtlsCipher":"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", * "localCertificateId":"googCertificate_34:0E:F4:9B:39:06:49:14:E0:25:34:96:95:9E:E3:4B:95:B4:86:31:86:4E:74:5D:4D:A4:C5:13:46:A1:31:17", * "remoteCertificateId":"googCertificate_82:1E:5E:EB:B5:0D:F8:CF:7A:72:43:FE:91:3A:CE:DC:20:D1:4E:F4:69:4B:06:B4:AA:03:41:67:19:F1:E5:24", * "srtpCipher":"AES_CM_128_HMAC_SHA1_80" * } * }, * ... * ] * } * * For now we only support stats relevant to the media of the call, but later we can introduce more keys apart from 'media', like 'signaling' or 'cellular' * * @param reports * @return the stats into a valid json string for easy parsing by the application */ private String webrtcStatsReports2JsonString(StatsReport[] reports) { // This is a 'special' sequence of chars that is guaranteed to not exist inside the stats string. Reason we want that is that // we want to be able to differentiate in our regex processing between ': ' and ':'. And the reason is that the former is the // the delimiter between keys and values in json, while the second is just a color character that can be found inside values. final String SPECIAL_CHARS = "++"; // Add a 'media' key that will contain all webrtc media related stats and open an array that will contain all reports coming from PeerConnection.getStats() StringBuilder statsStringBuilder = new StringBuilder("{\"media\": ["); for (StatsReport report : reports) { // First do the regex work using a String. Strings aren't very efficient due to being immutable, but they have nice regex facilities. // Given that this only happens once every call I think we 're good String stringReport = report.toString().replaceFirst("\\[", "{") // replace the first '[' found after the 'values' section to '{', so that all key/values in the 'values' section are grouped together .replace("[", "") // remove all other '[' characters from the values section as they would break json .replace("]", "") // same for all other '[' characters .replace(": ", SPECIAL_CHARS + " ") // replace the delimiting character between original report string (i.e. ': ') to some special chars, so that other occurences of ':', like in the DTLS section isn't messed up .replaceAll("([^,\\[\\]\\{\\} ]+)", "\"$1\"") // add double quotes around all words as they need to be quoted to be valid json .replace(SPECIAL_CHARS + "\"", "\":") // replace special chars back to ':' now that the previous step is done and there is no fear for confusion .replace(": ,", ": \"\","); // fix any non existing values and replace with empty string in the key/values pairs of the 'values' section // Then combine everything using StringBuilder statsStringBuilder.append("{") // append new section in json before the report starts .append(stringReport) // append report we generated before .replace(statsStringBuilder.lastIndexOf(","), statsStringBuilder.lastIndexOf(",") + 1, "") // remove last comma in report that would mess json, since there is not any other element afterwards .append("}},"); // wrap the report by closing all open braces, and adding a comma, so that reports are separated properly between themselves } // go back and remove comma from last report, to avoid ruining json statsStringBuilder.replace(statsStringBuilder.lastIndexOf(","), statsStringBuilder.lastIndexOf(",") + 1, ""); // close array of reports and initial section statsStringBuilder.append("]}"); return statsStringBuilder.toString(); }
Example #17
Source File: PeerConnectionClient.java From Yahala-Messenger with MIT License | 2 votes |
/** * Callback fired once peer connection statistics is ready. */ public void onPeerConnectionStatsReady(final StatsReport[] reports);
Example #18
Source File: PeerConnectionClient.java From voip_android with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Callback fired once peer connection statistics is ready. */ void onPeerConnectionStatsReady(final StatsReport[] reports);
Example #19
Source File: PeerConnectionClient.java From janus-gateway-android with MIT License | 2 votes |
/** * Callback fired once peer connection statistics is ready. */ void onPeerConnectionStatsReady(final StatsReport[] reports);
Example #20
Source File: PeerConnectionClient.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 2 votes |
/** * Callback fired once peer connection statistics is ready. */ void onPeerConnectionStatsReady(final StatsReport[] reports);
Example #21
Source File: MainActivity.java From janus-gateway-android with MIT License | 2 votes |
@Override public void onPeerConnectionStatsReady(StatsReport[] reports) { }
Example #22
Source File: PeerConnectionClient.java From sample-videoRTC with Apache License 2.0 | 2 votes |
/** * Callback fired once peer connection statistics is ready. */ void onPeerConnectionStatsReady(final StatsReport[] reports);