Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
receiver_session.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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_pipeline/receiver_session.h
10 //! @brief Receiver session pipeline.
11 
12 #ifndef ROC_PIPELINE_RECEIVER_SESSION_H_
13 #define ROC_PIPELINE_RECEIVER_SESSION_H_
14 
17 #include "roc_audio/depacketizer.h"
21 #include "roc_audio/iresampler.h"
24 #include "roc_audio/watchdog.h"
25 #include "roc_core/iarena.h"
26 #include "roc_core/list_node.h"
27 #include "roc_core/optional.h"
28 #include "roc_core/ref_counted.h"
29 #include "roc_core/scoped_ptr.h"
30 #include "roc_fec/iblock_decoder.h"
31 #include "roc_fec/reader.h"
33 #include "roc_packet/iparser.h"
34 #include "roc_packet/ireader.h"
35 #include "roc_packet/iwriter.h"
36 #include "roc_packet/packet.h"
38 #include "roc_packet/router.h"
40 #include "roc_packet/units.h"
41 #include "roc_pipeline/config.h"
42 #include "roc_pipeline/metrics.h"
43 #include "roc_rtcp/reports.h"
44 #include "roc_rtp/encoding_map.h"
45 #include "roc_rtp/filter.h"
46 #include "roc_rtp/link_meter.h"
47 #include "roc_rtp/parser.h"
49 
50 namespace roc {
51 namespace pipeline {
52 
53 //! Receiver session sub-pipeline.
54 //!
55 //! Contains:
56 //! - a pipeline for processing packets from single sender and converting
57 //! them into audio frames
58 class ReceiverSession : public core::RefCounted<ReceiverSession, core::ArenaAllocation>,
59  public core::ListNode<> {
60 public:
61  //! Initialize.
62  ReceiverSession(const ReceiverSessionConfig& session_config,
63  const ReceiverCommonConfig& common_config,
64  const rtp::EncodingMap& encoding_map,
65  packet::PacketFactory& packet_factory,
66  audio::FrameFactory& frame_factory,
68 
69  //! Check if the session was succefully constructed.
70  bool is_valid() const;
71 
72  //! Get frame reader.
73  //! @remarks
74  //! This way samples are fetched from the pipeline.
75  //! Most of the processing, like decoding packets, restoring losses, and adjust
76  //! clock, happens during the read operation.
78 
79  //! Route a packet to the session.
80  //! @remarks
81  //! This way packets from sender reach receiver pipeline.
82  //! Packets are stored inside internal pipeline queues, and then fetched
83  //! when frame are requested from frame_reader().
85 
86  //! Refresh pipeline according to current time.
87  //! @remarks
88  //! writes to @p next_refresh deadline (absolute time) when refresh should
89  //! be invoked again if there are no frames
90  //! @returns
91  //! false if the session is ended
92  bool refresh(core::nanoseconds_t current_time, core::nanoseconds_t* next_refresh);
93 
94  //! Adjust session clock to match consumer clock.
95  //! @remarks
96  //! @p playback_time specified absolute time when first sample of last frame
97  //! retrieved from pipeline will be actually played on sink
98  //! @returns
99  //! false if the session is ended
100  bool reclock(core::nanoseconds_t playback_time);
101 
102  //! Get number of RTCP reports to be generated.
103  size_t num_reports() const;
104 
105  //! Generate RTCP reports to be delivered to sender.
106  void generate_reports(const char* report_cname,
107  packet::stream_source_t report_ssrc,
108  core::nanoseconds_t report_time,
109  rtcp::RecvReport* reports,
110  size_t n_reports) const;
111 
112  //! Process RTCP report obtained from sender.
113  void process_report(const rtcp::SendReport& report);
114 
115  //! Get session metrics.
117 
118 private:
119  audio::IFrameReader* frame_reader_;
120 
121  core::Optional<packet::Router> packet_router_;
122 
125 
126  core::Optional<rtp::LinkMeter> source_meter_;
127  core::Optional<rtp::LinkMeter> repair_meter_;
128 
129  core::ScopedPtr<audio::IFrameDecoder> payload_decoder_;
130 
134 
135  core::Optional<rtp::Parser> fec_parser_;
137  core::Optional<fec::Reader> fec_reader_;
138  core::Optional<rtp::Filter> fec_filter_;
139 
140  core::Optional<rtp::TimestampInjector> timestamp_injector_;
141 
143 
144  core::Optional<audio::ChannelMapperReader> channel_mapper_reader_;
145 
146  core::Optional<audio::ResamplerReader> resampler_reader_;
148 
149  core::Optional<audio::LatencyMonitor> latency_monitor_;
150 
151  bool valid_;
152 };
153 
154 } // namespace pipeline
155 } // namespace roc
156 
157 #endif // ROC_PIPELINE_RECEIVER_SESSION_H_
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition: attributes.h:31
Channel mapper reader.
Frame reader interface.
Definition: iframe_reader.h:22
IArena & arena() const
Get arena.
Memory arena interface.
Definition: iarena.h:23
Base class for List element.
Definition: list_node.h:48
Optionally constructed object.
Definition: optional.h:25
Base class for object with reference counter.
Definition: ref_counted.h:40
Unique ownrship pointer.
Definition: scoped_ptr.h:33
Receiver session sub-pipeline.
ReceiverParticipantMetrics get_metrics() const
Get session metrics.
audio::IFrameReader & frame_reader()
Get frame reader.
void generate_reports(const char *report_cname, packet::stream_source_t report_ssrc, core::nanoseconds_t report_time, rtcp::RecvReport *reports, size_t n_reports) const
Generate RTCP reports to be delivered to sender.
ReceiverSession(const ReceiverSessionConfig &session_config, const ReceiverCommonConfig &common_config, const rtp::EncodingMap &encoding_map, packet::PacketFactory &packet_factory, audio::FrameFactory &frame_factory, core::IArena &arena)
Initialize.
bool refresh(core::nanoseconds_t current_time, core::nanoseconds_t *next_refresh)
Refresh pipeline according to current time.
bool reclock(core::nanoseconds_t playback_time)
Adjust session clock to match consumer clock.
size_t num_reports() const
Get number of RTCP reports to be generated.
bool is_valid() const
Check if the session was succefully constructed.
ROC_ATTR_NODISCARD status::StatusCode route_packet(const packet::PacketPtr &packet)
Route a packet to the session.
void process_report(const rtcp::SendReport &report)
Process RTCP report obtained from sender.
RTP encoding map. Thread-safe. Returned encodings are immutable and can be safely used from any threa...
Definition: encoding_map.h:33
Delayed reader.
Depacketizer.
RTP encoding map.
RTP filter.
Frame factory.
Memory arena interface.
FEC block decoder interface.
Audio frame decoder interface.
Frame reader interface.
Packet parser interface.
Packet reader interface.
Audio resampler interface.
Packet writer interface.
Latency monitor.
Linked list node.
Pipeline metrics.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
uint32_t stream_source_t
Packet stream identifier.
Definition: units.h:27
Root namespace.
Optionally constructed object.
Packet.
Packet factory.
FEC reader.
Base class for object with reference counter.
RTCP reports.
Pipeline config.
RTP packet parser.
Route packets to writers.
Unique ownrship pointer.
Socket address.
Sorted packet queue.
StatusCode
Status code.
Definition: status_code.h:19
Parameters common for all receiver sessions.
Definition: config.h:124
Receiver-side metrics specific to one participant (remote sender).
Definition: metrics.h:54
Parameters of receiver session.
Definition: config.h:154
Receiver report, for inspection on sender.
Definition: reports.h:94
Sender report, for inspection on receiver.
Definition: reports.h:27
Fills capture timestamp field in packets.
Various units used in packets.
Watchdog.