Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
sender_session.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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/sender_session.h
10 //! @brief Sender session.
11 
12 #ifndef ROC_PIPELINE_SENDER_SESSION_H_
13 #define ROC_PIPELINE_SENDER_SESSION_H_
14 
20 #include "roc_audio/iresampler.h"
21 #include "roc_audio/packetizer.h"
23 #include "roc_core/iarena.h"
24 #include "roc_core/noncopyable.h"
25 #include "roc_core/optional.h"
26 #include "roc_core/scoped_ptr.h"
27 #include "roc_fec/iblock_encoder.h"
28 #include "roc_fec/writer.h"
29 #include "roc_packet/interleaver.h"
31 #include "roc_packet/router.h"
32 #include "roc_pipeline/config.h"
33 #include "roc_pipeline/metrics.h"
35 #include "roc_rtcp/communicator.h"
36 #include "roc_rtcp/composer.h"
37 #include "roc_rtcp/iparticipant.h"
38 #include "roc_rtp/encoding_map.h"
39 #include "roc_rtp/identity.h"
40 #include "roc_rtp/sequencer.h"
42 #include "roc_status/status_code.h"
43 
44 namespace roc {
45 namespace pipeline {
46 
47 //! Sender session sub-pipeline.
48 //!
49 //! Contains:
50 //! - a pipeline for processing audio frames from single sender and converting
51 //! them into packets
53 public:
54  //! Initialize.
55  SenderSession(const SenderSinkConfig& sink_config,
56  const rtp::EncodingMap& encoding_map,
57  packet::PacketFactory& packet_factory,
58  audio::FrameFactory& frame_factory,
59  core::IArena& arena);
60 
61  //! Check if the session was succefully constructed.
62  bool is_valid() const;
63 
64  //! Create transport sub-pipeline.
66  SenderEndpoint* repair_endpoint);
67 
68  //! Create control sub-pipeline.
69  bool create_control_pipeline(SenderEndpoint* control_endpoint);
70 
71  //! Get frame writer.
72  //! @remarks
73  //! This way samples reach the pipeline.
74  //! Most of the processing, like encoding packets, generating redundancy packets,
75  //! etc, happens during the write operation.
77 
78  //! Route a packet to the session.
79  //! @remarks
80  //! This way feedback packets from receiver reach sender pipeline.
81  //! Packets are stored inside internal pipeline queues, and then fetched
82  //! when frame are passed from frame_writer().
84  core::nanoseconds_t current_time);
85 
86  //! Refresh pipeline according to current time.
87  //! @returns
88  //! deadline (absolute time) when refresh should be invoked again
89  //! if there are no frames
91 
92  //! Get slot metrics.
93  //! @remarks
94  //! These metrics are for the whole slot.
95  //! For metrics for specific participant, see get_participant_metrics().
96  void get_slot_metrics(SenderSlotMetrics& slot_metrics) const;
97 
98  //! Get metrics for remote participants.
99  //! @remarks
100  //! On sender, all participants corresponds to a single SenderSession.
101  //! In case of unicast, there is only one participant (remote receiver),
102  //! but in case of multicast, multiple participants may be present.
103  //! @note
104  //! @p party_metrics points to array of metrics structs, and @p party_count
105  //! defines number of array elements. Metrics are written to given array,
106  //! and @p party_count is updated of actual number of elements written.
107  //! If there is not enough space for all metrics, result is truncated.
109  size_t* party_count) const;
110 
111 private:
112  // Implementation of rtcp::IParticipant interface.
113  // These methods are invoked by rtcp::Communicator.
114  virtual rtcp::ParticipantInfo participant_info();
115  virtual void change_source_id();
116  virtual bool has_send_stream();
117  virtual rtcp::SendReport query_send_stream(core::nanoseconds_t report_time);
118  virtual status::StatusCode notify_send_stream(packet::stream_source_t recv_source_id,
119  const rtcp::RecvReport& recv_report);
120 
121  void start_feedback_monitor_();
122 
123  status::StatusCode route_control_packet_(const packet::PacketPtr& packet,
124  core::nanoseconds_t current_time);
125 
126  core::IArena& arena_;
127 
128  const SenderSinkConfig sink_config_;
129 
130  const rtp::EncodingMap& encoding_map_;
131 
132  packet::PacketFactory& packet_factory_;
133  audio::FrameFactory& frame_factory_;
134 
137 
139 
141 
143  core::Optional<fec::Writer> fec_writer_;
144 
145  core::Optional<rtp::TimestampExtractor> timestamp_extractor_;
146 
147  core::ScopedPtr<audio::IFrameEncoder> payload_encoder_;
149 
150  core::Optional<audio::ChannelMapperWriter> channel_mapper_writer_;
151 
152  core::Optional<audio::ResamplerWriter> resampler_writer_;
154 
155  core::Optional<audio::FeedbackMonitor> feedback_monitor_;
156 
157  core::Optional<rtcp::Communicator> rtcp_communicator_;
158  address::SocketAddr rtcp_outbound_addr_;
159 
160  audio::IFrameWriter* frame_writer_;
161 
162  bool valid_;
163 };
164 
165 } // namespace pipeline
166 } // namespace roc
167 
168 #endif // ROC_PIPELINE_SENDER_SESSION_H_
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition: attributes.h:31
Channel mapper writer.
Socket address.
Definition: socket_addr.h:26
Frame writer interface.
Definition: iframe_writer.h:22
Memory arena interface.
Definition: iarena.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Optionally constructed object.
Definition: optional.h:25
Unique ownrship pointer.
Definition: scoped_ptr.h:33
Sender endpoint sub-pipeline.
Sender session sub-pipeline.
void get_participant_metrics(SenderParticipantMetrics *party_metrics, size_t *party_count) const
Get metrics for remote participants.
bool create_control_pipeline(SenderEndpoint *control_endpoint)
Create control sub-pipeline.
audio::IFrameWriter * frame_writer() const
Get frame writer.
ROC_ATTR_NODISCARD status::StatusCode route_packet(const packet::PacketPtr &packet, core::nanoseconds_t current_time)
Route a packet to the session.
core::nanoseconds_t refresh(core::nanoseconds_t current_time)
Refresh pipeline according to current time.
bool is_valid() const
Check if the session was succefully constructed.
bool create_transport_pipeline(SenderEndpoint *source_endpoint, SenderEndpoint *repair_endpoint)
Create transport sub-pipeline.
SenderSession(const SenderSinkConfig &sink_config, const rtp::EncodingMap &encoding_map, packet::PacketFactory &packet_factory, audio::FrameFactory &frame_factory, core::IArena &arena)
Initialize.
void get_slot_metrics(SenderSlotMetrics &slot_metrics) const
Get slot metrics.
RTCP participant.
Definition: iparticipant.h:49
RTP encoding map. Thread-safe. Returned encodings are immutable and can be safely used from any threa...
Definition: encoding_map.h:33
RTCP communicator.
RTP encoding map.
Feedback monitor.
Frame factory.
Memory arena interface.
FEC block encoder interface.
RTP participant identity.
Audio frame encoder interface.
Interleaves packets before transmit.
RTCP participant.
Audio resampler interface.
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.
Non-copyable object.
Optionally constructed object.
Packet factory.
Packetizer.
Pipeline config.
RTCP packet composer.
Route packets to writers.
Unique ownrship pointer.
Sender endpoint pipeline.
RTP packet sequencer.
Socket address.
Status codes.
StatusCode
Status code.
Definition: status_code.h:19
Sender-side metrics specific to one participant (remote receiver).
Definition: metrics.h:24
Parameters of sender sink and sender session.
Definition: config.h:58
Sender-side metrics of the whole slot.
Definition: metrics.h:36
Receiver report, for inspection on sender.
Definition: reports.h:94
Sender report, for inspection on receiver.
Definition: reports.h:27
Extracts capture timestamp field from packets.
FEC writer.