xref: /aosp_15_r20/external/webrtc/api/voip/voip_statistics.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2020 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 #ifndef API_VOIP_VOIP_STATISTICS_H_
12 #define API_VOIP_VOIP_STATISTICS_H_
13 
14 #include "api/neteq/neteq.h"
15 #include "api/voip/voip_base.h"
16 
17 namespace webrtc {
18 
19 struct IngressStatistics {
20   // Stats included from api/neteq/neteq.h.
21   NetEqLifetimeStatistics neteq_stats;
22 
23   // Represents the total duration in seconds of all samples that have been
24   // received.
25   // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-totalsamplesduration
26   double total_duration = 0.0;
27 };
28 
29 // Remote statistics obtained via remote RTCP SR/RR report received.
30 struct RemoteRtcpStatistics {
31   // Jitter as defined in RFC 3550 [6.4.1] expressed in seconds.
32   double jitter = 0.0;
33 
34   // Cumulative packets lost as defined in RFC 3550 [6.4.1]
35   int64_t packets_lost = 0;
36 
37   // Fraction lost as defined in RFC 3550 [6.4.1] expressed as a floating
38   // pointer number.
39   double fraction_lost = 0.0;
40 
41   // https://w3c.github.io/webrtc-stats/#dom-rtcremoteinboundrtpstreamstats-roundtriptime
42   absl::optional<double> round_trip_time;
43 
44   // Last time (not RTP timestamp) when RTCP report received in milliseconds.
45   int64_t last_report_received_timestamp_ms;
46 };
47 
48 struct ChannelStatistics {
49   // https://w3c.github.io/webrtc-stats/#dom-rtcsentrtpstreamstats-packetssent
50   uint64_t packets_sent = 0;
51 
52   // https://w3c.github.io/webrtc-stats/#dom-rtcsentrtpstreamstats-bytessent
53   uint64_t bytes_sent = 0;
54 
55   // https://w3c.github.io/webrtc-stats/#dom-rtcreceivedrtpstreamstats-packetsreceived
56   uint64_t packets_received = 0;
57 
58   // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-bytesreceived
59   uint64_t bytes_received = 0;
60 
61   // https://w3c.github.io/webrtc-stats/#dom-rtcreceivedrtpstreamstats-jitter
62   double jitter = 0.0;
63 
64   // https://w3c.github.io/webrtc-stats/#dom-rtcreceivedrtpstreamstats-packetslost
65   int64_t packets_lost = 0;
66 
67   // SSRC from remote media endpoint as indicated either by RTP header in RFC
68   // 3550 [5.1] or RTCP SSRC of sender in RFC 3550 [6.4.1].
69   absl::optional<uint32_t> remote_ssrc;
70 
71   absl::optional<RemoteRtcpStatistics> remote_rtcp;
72 };
73 
74 // VoipStatistics interface provides the interfaces for querying metrics around
75 // the jitter buffer (NetEq) performance.
76 class VoipStatistics {
77  public:
78   // Gets the audio ingress statistics by `ingress_stats` reference.
79   // Returns following VoipResult;
80   //  kOk - successfully set provided IngressStatistics reference.
81   //  kInvalidArgument - `channel_id` is invalid.
82   virtual VoipResult GetIngressStatistics(ChannelId channel_id,
83                                           IngressStatistics& ingress_stats) = 0;
84 
85   // Gets the channel statistics by `channel_stats` reference.
86   // Returns following VoipResult;
87   //  kOk - successfully set provided ChannelStatistics reference.
88   //  kInvalidArgument - `channel_id` is invalid.
89   virtual VoipResult GetChannelStatistics(ChannelId channel_id,
90                                           ChannelStatistics& channel_stats) = 0;
91 
92  protected:
93   virtual ~VoipStatistics() = default;
94 };
95 
96 }  // namespace webrtc
97 
98 #endif  // API_VOIP_VOIP_STATISTICS_H_
99