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

Unified Diff: webrtc/sdk/android/api/org/webrtc/RTCStats.java

Issue 2807933003: Add Java binding for new getStats implementation. (Closed)
Patch Set: Addressing hbos's comments. Created 3 years, 8 months 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/sdk/android/api/org/webrtc/RTCStats.java
diff --git a/webrtc/sdk/android/api/org/webrtc/RTCStats.java b/webrtc/sdk/android/api/org/webrtc/RTCStats.java
new file mode 100644
index 0000000000000000000000000000000000000000..4d6618af0244aad2cb7b5ca9b8175d4ec6101bf5
--- /dev/null
+++ b/webrtc/sdk/android/api/org/webrtc/RTCStats.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+package org.webrtc;
+
+import java.util.Map;
+import java.util.SortedMap;
+
+/**
+ * Java version of webrtc::RTCStats. Represents an RTCStats object, as
+ * described in https://w3c.github.io/webrtc-stats/. The |id|, |timestampUs|
+ * and |type| accessors have the same meaning for this class as for the
+ * RTCStats dictionary.
sakal 2017/04/11 12:50:50 nit: Please comment this is inner piece for RTCSta
Taylor Brandstetter 2017/04/13 02:33:15 Done.
+ */
+public class RTCStats {
+ private final long timestampUs;
+ private final String type;
+ private final String id;
+ private final SortedMap<String, Object> members;
+
+ public RTCStats(long timestampUs, String type, String id, SortedMap<String, Object> members) {
+ this.timestampUs = timestampUs;
+ this.type = type;
+ this.id = id;
+ this.members = members;
+ }
+
+ // Timestamp in nanoseconds.
+ public double timestampUs() {
sakal 2017/04/11 12:50:50 It's common in Java to prefix getters with get. I
Taylor Brandstetter 2017/04/13 02:33:15 Done.
+ return timestampUs;
+ }
+
+ // Equivalent to RTCStatsType in the stats spec.
+ public String type() {
+ return type;
+ }
+
+ // Unique ID representing this stats object. May be referred to by members of
+ // other stats objects.
+ public String id() {
+ return id;
+ }
+
+ /**
+ * Returns map of member names to values. Returns as an ordered map so that
+ * the stats object can be serialized with a consistent ordering.
+ *
+ * Values will be one of the following objects:
+ * - Boolean
+ * - Integer (for 32-bit signed integers)
+ * - Long (for 32-bit unsigned and 64-bit signed integers)
+ * - BigInteger (for 64-bit unsigned integers)
+ * - Double
+ * - String
+ * - The array form of any of the above (e.g., Integer[])
+ */
+ public SortedMap<String, Object> members() {
sakal 2017/04/11 12:50:50 nit: I'd prefer to return Map here. It would give
hbos 2017/04/11 13:02:37 (Oh yeah, consistent ordering doesn't have to mean
Taylor Brandstetter 2017/04/13 02:33:15 I completely goofed here. "Predictable iteration o
+ return members;
+ }
+
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("{ timestampUs: ")
+ .append(timestampUs)
+ .append(", type: ")
+ .append(type)
+ .append(", id: ")
+ .append(id);
+ boolean first = true;
+ for (Map.Entry<String, Object> entry : members.entrySet()) {
+ builder.append(", ").append(entry.getKey()).append(": ");
+ appendValue(builder, entry.getValue());
+ }
+ builder.append(" }");
+ return builder.toString();
+ }
+
+ private static void appendValue(StringBuilder builder, Object value) {
+ if (value instanceof Object[]) {
+ Object[] arrayValue = (Object[]) value;
+ builder.append('[');
+ for (int i = 0; i < arrayValue.length; ++i) {
+ if (i != 0) {
+ builder.append(", ");
+ }
+ appendValue(builder, arrayValue[i]);
+ }
+ builder.append(']');
+ } else if (value instanceof String) {
+ // Enclose strings in quotes to make it clear they're strings.
+ builder.append('"').append(value).append('"');
+ } else {
+ builder.append(value);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698