Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
link_meter.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_rtp/link_meter.h
10//! @brief RTP link meter.
11
12#ifndef ROC_RTP_LINK_METER_H_
13#define ROC_RTP_LINK_METER_H_
14
17#include "roc_core/time.h"
19#include "roc_packet/ireader.h"
20#include "roc_packet/iwriter.h"
21#include "roc_rtcp/reports.h"
22#include "roc_rtp/encoding.h"
24
25namespace roc {
26namespace rtp {
27
28//! RTP link meter.
29//!
30//! Computes various link metrics based on sequence of RTP packets.
31//! Inserted into pipeline in two points:
32//!
33//! - As a writer, right after receiving packet, before storing
34//! packet in incoming queue. Here LinkMeter computes metrics
35//! that should be updated as early as possible.
36//!
37//! - As a reader, right before decoding packet. Here LinkMeter
38//! computes metrics that can be updated only when packets
39//! are going to be played.
40//!
41//! In both cases, LinkMeter passes through packets to/from nested
42//! writer/reader, and updates metrics.
44 public packet::IWriter,
45 public packet::IReader,
46 public core::NonCopyable<> {
47public:
48 //! Initialize.
49 explicit LinkMeter(const EncodingMap& encoding_map);
50
51 //! Check if metrics are already gathered and can be reported.
52 virtual bool has_metrics() const;
53
54 //! Get metrics.
55 virtual const packet::LinkMetrics& metrics() const;
56
57 //! Check if packet encoding already detected.
58 bool has_encoding() const;
59
60 //! Get detected encoding.
61 //! @remarks
62 //! Panics if no encoding detected.
63 const Encoding& encoding() const;
64
65 //! Process RTCP report from sender.
66 //! @remarks
67 //! Obtains additional information that can't be measured directly.
68 void process_report(const rtcp::SendReport& report);
69
70 //! Write packet and update metrics.
71 //! @remarks
72 //! Invoked early in pipeline right after the packet is received.
74
75 //! Read packet and update metrics.
76 //! @remarks
77 //! Invoked late in pipeline right before the packet is decoded.
79
80 //! Set nested packet writer.
81 //! @remarks
82 //! Should be called before first write() call.
84
85 //! Set nested packet reader.
86 //! @remarks
87 //! Should be called before first read() call.
89
90private:
91 void update_metrics_(const packet::Packet& packet);
92
93 const EncodingMap& encoding_map_;
94 const Encoding* encoding_;
95
96 packet::IWriter* writer_;
97 packet::IReader* reader_;
98
99 bool first_packet_;
100 bool has_metrics_;
101
102 packet::LinkMetrics metrics_;
103
104 uint16_t first_seqnum_;
105 uint32_t last_seqnum_hi_;
106 uint16_t last_seqnum_lo_;
107};
108
109} // namespace rtp
110} // namespace roc
111
112#endif // ROC_RTP_LINK_METER_H_
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
Base class for non-copyable objects.
Definition noncopyable.h:23
Link meter interface.
Definition ilink_meter.h:71
Packet reader interface.
Definition ireader.h:23
Packet writer interface.
Definition iwriter.h:23
RTP encoding map. Thread-safe. Returned encodings are immutable and can be safely used from any threa...
RTP link meter.
Definition link_meter.h:46
bool has_encoding() const
Check if packet encoding already detected.
const Encoding & encoding() const
Get detected encoding.
void process_report(const rtcp::SendReport &report)
Process RTCP report from sender.
void set_reader(packet::IReader &reader)
Set nested packet reader.
void set_writer(packet::IWriter &writer)
Set nested packet writer.
LinkMeter(const EncodingMap &encoding_map)
Initialize.
virtual status::StatusCode write(const packet::PacketPtr &packet)
Write packet and update metrics.
virtual bool has_metrics() const
Check if metrics are already gathered and can be reported.
virtual status::StatusCode read(packet::PacketPtr &packet)
Read packet and update metrics.
virtual const packet::LinkMetrics & metrics() const
Get metrics.
RTP encoding.
RTP encoding map.
Packet reader interface.
Packet writer interface.
StatusCode
Status code.
Definition status_code.h:19
Root namespace.
Non-copyable object.
RTCP reports.
Sample specifications.
Sender report, for inspection on receiver.
Definition reports.h:27
RTP encoding.
Definition encoding.h:27
Time definitions.