1 /* 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 package org.webrtc; 12 13 import java.util.Map; 14 15 /** 16 * Java version of webrtc::RTCStatsReport. Each RTCStatsReport produced by 17 * getStats contains multiple RTCStats objects; one for each underlying object 18 * (codec, stream, transport, etc.) that was inspected to produce the stats. 19 */ 20 public class RTCStatsReport { 21 private final long timestampUs; 22 private final Map<String, RTCStats> stats; 23 RTCStatsReport(long timestampUs, Map<String, RTCStats> stats)24 public RTCStatsReport(long timestampUs, Map<String, RTCStats> stats) { 25 this.timestampUs = timestampUs; 26 this.stats = stats; 27 } 28 29 // Timestamp in microseconds. getTimestampUs()30 public double getTimestampUs() { 31 return timestampUs; 32 } 33 34 // Map of stats object IDs to stats objects. Can be used to easily look up 35 // other stats objects, when they refer to each other by ID. getStatsMap()36 public Map<String, RTCStats> getStatsMap() { 37 return stats; 38 } 39 40 @Override toString()41 public String toString() { 42 StringBuilder builder = new StringBuilder(); 43 builder.append("{ timestampUs: ").append(timestampUs).append(", stats: [\n"); 44 boolean first = true; 45 for (RTCStats stat : stats.values()) { 46 if (!first) { 47 builder.append(",\n"); 48 } 49 builder.append(stat); 50 first = false; 51 } 52 builder.append(" ] }"); 53 return builder.toString(); 54 } 55 56 // TODO(bugs.webrtc.org/8557) Use ctor directly with full Map type. 57 @SuppressWarnings("unchecked") 58 @CalledByNative create(long timestampUs, Map stats)59 private static RTCStatsReport create(long timestampUs, Map stats) { 60 return new RTCStatsReport(timestampUs, stats); 61 } 62 } 63