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"
20 #include "roc_audio/iresampler.h"
24 #include "roc_audio/watchdog.h"
26 #include "roc_core/iarena.h"
27 #include "roc_core/list_node.h"
28 #include "roc_core/optional.h"
29 #include "roc_core/ref_counted.h"
30 #include "roc_core/scoped_ptr.h"
31 #include "roc_fec/iblock_decoder.h"
32 #include "roc_fec/reader.h"
34 #include "roc_packet/iparser.h"
35 #include "roc_packet/ireader.h"
36 #include "roc_packet/iwriter.h"
37 #include "roc_packet/packet.h"
39 #include "roc_packet/router.h"
41 #include "roc_pipeline/config.h"
42 #include "roc_pipeline/metrics.h"
43 #include "roc_rtcp/metrics.h"
44 #include "roc_rtp/format_map.h"
45 #include "roc_rtp/parser.h"
46 #include "roc_rtp/populator.h"
48 #include "roc_rtp/validator.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 address::SocketAddr& src_address,
65  const rtp::FormatMap& format_map,
66  packet::PacketFactory& packet_factory,
67  core::BufferFactory<uint8_t>& byte_buffer_factory,
68  core::BufferFactory<audio::sample_t>& sample_buffer_factory,
70 
71  //! Check if the session pipeline was succefully constructed.
72  bool is_valid() const;
73 
74  //! Try to route a packet to this session.
76 
77  //! Refresh pipeline according to current time.
78  //! @remarks
79  //! writes to @p next_refresh deadline (absolute time) when refresh should
80  //! be invoked again if there are no frames
81  //! @returns
82  //! false if the session is ended
83  bool refresh(core::nanoseconds_t current_time, core::nanoseconds_t* next_refresh);
84 
85  //! Adjust session clock to match consumer clock.
86  //! @remarks
87  //! @p playback_time specified absolute time when first sample of last frame
88  //! retrieved from pipeline will be actually played on sink
89  //! @returns
90  //! false if the session is ended
91  bool reclock(core::nanoseconds_t playback_time);
92 
93  //! Get session metrics.
95 
96  //! Get audio reader.
98 
99  //! Handle metrics obtained from sender.
101 
102  //! Handle estimated link metrics.
103  void add_link_metrics(const rtcp::LinkMetrics& metrics);
104 
105 private:
106  const address::SocketAddr src_address_;
107 
108  audio::IFrameReader* audio_reader_;
109 
110  core::Optional<packet::Router> queue_router_;
111 
114 
115  core::ScopedPtr<audio::IFrameDecoder> payload_decoder_;
116 
121 
122  core::Optional<rtp::Parser> fec_parser_;
124  core::Optional<fec::Reader> fec_reader_;
125  core::Optional<rtp::Validator> fec_validator_;
126  core::Optional<rtp::Populator> fec_populator_;
127 
128  core::Optional<rtp::TimestampInjector> timestamp_injector_;
129 
131 
132  core::Optional<audio::ChannelMapperReader> channel_mapper_reader_;
133 
134  core::Optional<audio::PoisonReader> resampler_poisoner_;
135  core::Optional<audio::ResamplerReader> resampler_reader_;
137 
138  core::Optional<audio::PoisonReader> session_poisoner_;
139 
140  core::Optional<audio::LatencyMonitor> latency_monitor_;
141 };
142 
143 } // namespace pipeline
144 } // namespace roc
145 
146 #endif // ROC_PIPELINE_RECEIVER_SESSION_H_
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition: attributes.h:31
Buffer factory.
Channel mapper reader.
Socket address.
Definition: socket_addr.h:26
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:26
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.
audio::IFrameReader & reader()
Get audio reader.
void add_link_metrics(const rtcp::LinkMetrics &metrics)
Handle estimated link metrics.
void add_sending_metrics(const rtcp::SendingMetrics &metrics)
Handle metrics obtained from sender.
ROC_ATTR_NODISCARD status::StatusCode route(const packet::PacketPtr &packet)
Try to route a packet to this session.
ReceiverSession(const ReceiverSessionConfig &session_config, const ReceiverCommonConfig &common_config, const address::SocketAddr &src_address, const rtp::FormatMap &format_map, packet::PacketFactory &packet_factory, core::BufferFactory< uint8_t > &byte_buffer_factory, core::BufferFactory< audio::sample_t > &sample_buffer_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.
ReceiverSessionMetrics get_metrics() const
Get session metrics.
bool is_valid() const
Check if the session pipeline was succefully constructed.
RTP payload format map. Thread-safe. Returned formats are immutable and can be safely used from any t...
Definition: format_map.h:33
Delayed reader.
Depacketizer.
RTP payload format map.
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.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
Root namespace.
Optionally constructed object.
Packet.
Packet factory.
Poison reader.
RTP populator.
FEC reader.
Base class for object with reference counter.
Pipeline config.
Pipeline metrics.
RTCP-derived metrics.
RTP packet parser.
Route packets to writers.
Unique ownrship pointer.
Socket address.
Sorted packet queue.
StatusCode
Status code.
Definition: status_code.h:19
Receiver common parameters.
Definition: config.h:209
Receiver session parameters.
Definition: config.h:158
Metrics of receiver session (connection from sender).
Definition: metrics.h:38
Metrics for network link. Calculated independently on both sender and receiver.
Definition: metrics.h:53
Metrics sent from sender to receiver.
Definition: metrics.h:23
Fills capture timestamp field in packets.
RTP validator.
Watchdog.