blob: de4a0790325091776ee22672993e197c521d52b1 [file] [log] [blame]
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +00001/*
2 * Copyright (c) 2014 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef VIDEO_REPORT_BLOCK_STATS_H_
12#define VIDEO_REPORT_BLOCK_STATS_H_
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000016#include <map>
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000017
Niels Möller53382cb2018-11-27 14:05:08 +010018#include "modules/rtp_rtcp/include/rtcp_statistics.h"
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000019
20namespace webrtc {
21
Niels Möller77d3efc2019-08-01 15:09:51 +020022// TODO(nisse): Usefulness of this class is somewhat unclear. The inputs are
23// cumulative counters, from which we compute deltas, and then accumulate the
24// deltas. May be needed on the send side, to handle wraparound in the short
25// counters received over RTCP, but should not be needed on the receive side
26// where we can use large enough types for all counters we need.
27
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000028// Helper class for rtcp statistics.
29class ReportBlockStats {
30 public:
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000031 ReportBlockStats();
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020032 ~ReportBlockStats();
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000033
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000034 // Updates stats and stores report block.
Niels Möller77d3efc2019-08-01 15:09:51 +020035 void Store(uint32_t ssrc, const RtcpStatistics& rtcp_stats);
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000036
asapersson@webrtc.orge7358ea2015-01-21 09:00:19 +000037 // Returns the total fraction of lost packets (or -1 if less than two report
38 // blocks have been stored).
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000039 int FractionLostInPercent() const;
40
41 private:
Niels Möller77d3efc2019-08-01 15:09:51 +020042 // The information from an RTCP report block that we need.
43 struct Report {
44 uint32_t extended_highest_sequence_number;
45 int32_t packets_lost;
46 };
47
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000048 // Updates the total number of packets/lost packets.
Niels Möller77d3efc2019-08-01 15:09:51 +020049 // Stores the report.
50 void StoreAndAddPacketIncrement(uint32_t ssrc, const Report& report);
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000051
52 // The total number of packets/lost packets.
53 uint32_t num_sequence_numbers_;
54 uint32_t num_lost_sequence_numbers_;
55
Niels Möller77d3efc2019-08-01 15:09:51 +020056 // Map holding the last stored report (mapped by the source SSRC).
57 std::map<uint32_t, Report> prev_reports_;
asapersson@webrtc.org823c9b82015-01-08 07:50:56 +000058};
59
60} // namespace webrtc
61
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020062#endif // VIDEO_REPORT_BLOCK_STATS_H_