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 
17 #include "roc_audio/iresampler.h"
18 #include "roc_audio/packetizer.h"
22 #include "roc_core/iarena.h"
23 #include "roc_core/noncopyable.h"
24 #include "roc_core/optional.h"
25 #include "roc_core/scoped_ptr.h"
26 #include "roc_fec/iblock_encoder.h"
27 #include "roc_fec/writer.h"
28 #include "roc_packet/interleaver.h"
30 #include "roc_packet/router.h"
31 #include "roc_pipeline/config.h"
32 #include "roc_pipeline/metrics.h"
34 #include "roc_rtcp/composer.h"
35 #include "roc_rtcp/session.h"
36 #include "roc_rtp/format_map.h"
38 
39 namespace roc {
40 namespace pipeline {
41 
42 //! Sender session sub-pipeline.
43 //!
44 //! Contains:
45 //! - a pipeline for processing audio frames from single sender and converting
46 //! them into packets
48 public:
49  //! Initialize.
50  SenderSession(const SenderConfig& config,
51  const rtp::FormatMap& format_map,
52  packet::PacketFactory& packet_factory,
53  core::BufferFactory<uint8_t>& byte_buffer_factory,
54  core::BufferFactory<audio::sample_t>& sample_buffer_factory,
55  core::IArena& arena);
56 
57  //! Create transport sub-pipeline.
59  SenderEndpoint* repair_endpoint);
60 
61  //! Create control sub-pipeline.
62  bool create_control_pipeline(SenderEndpoint* control_endpoint);
63 
64  //! Get audio writer.
66 
67  //! Refresh pipeline according to current time.
68  //! @returns
69  //! deadline (absolute time) when refresh should be invoked again
70  //! if there are no frames
72 
73  //! Get session metrics.
75 
76 private:
77  // Implementation of rtcp::ISenderHooks interface.
78  // These methods are invoked by rtcp::Session.
79  virtual size_t on_get_num_sources();
80  virtual packet::stream_source_t on_get_sending_source(size_t source_index);
81  virtual rtcp::SendingMetrics on_get_sending_metrics(core::nanoseconds_t report_time);
82  virtual void on_add_reception_metrics(const rtcp::ReceptionMetrics& metrics);
83  virtual void on_add_link_metrics(const rtcp::LinkMetrics& metrics);
84 
85  core::IArena& arena_;
86 
87  const SenderConfig& config_;
88 
89  const rtp::FormatMap& format_map_;
90 
91  packet::PacketFactory& packet_factory_;
92  core::BufferFactory<uint8_t>& byte_buffer_factory_;
93  core::BufferFactory<audio::sample_t>& sample_buffer_factory_;
94 
96 
98 
100  core::Optional<fec::Writer> fec_writer_;
101 
102  core::Optional<rtp::TimestampExtractor> timestamp_extractor_;
103 
104  core::ScopedPtr<audio::IFrameEncoder> payload_encoder_;
106 
107  core::Optional<audio::ChannelMapperWriter> channel_mapper_writer_;
108 
109  core::Optional<audio::ResamplerWriter> resampler_writer_;
111 
112  core::Optional<rtcp::Composer> rtcp_composer_;
113  core::Optional<rtcp::Session> rtcp_session_;
114 
115  audio::IFrameWriter* audio_writer_;
116 
117  size_t num_sources_;
118 };
119 
120 } // namespace pipeline
121 } // namespace roc
122 
123 #endif // ROC_PIPELINE_SENDER_SESSION_H_
Buffer factory.
Channel mapper writer.
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
Shared ownership intrusive pointer.
Definition: shared_ptr.h:32
Sender endpoint sub-pipeline.
Sender session sub-pipeline.
bool create_control_pipeline(SenderEndpoint *control_endpoint)
Create control sub-pipeline.
audio::IFrameWriter * writer() const
Get audio writer.
SenderSessionMetrics get_metrics() const
Get session metrics.
core::nanoseconds_t refresh(core::nanoseconds_t current_time)
Refresh pipeline according to current time.
bool create_transport_pipeline(SenderEndpoint *source_endpoint, SenderEndpoint *repair_endpoint)
Create transport sub-pipeline.
SenderSession(const SenderConfig &config, 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.
Sender hooks interface.
Definition: isender_hooks.h:23
RTP payload format map. Thread-safe. Returned formats are immutable and can be safely used from any t...
Definition: format_map.h:33
RTP payload format map.
Memory arena interface.
FEC block encoder interface.
Audio frame encoder interface.
Interleaves packets before transmit.
Audio resampler interface.
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.
Resampler map.
Pipeline config.
Pipeline metrics.
RTCP packet composer.
Route packets to writers.
Unique ownrship pointer.
Sender endpoint pipeline.
RTCP session.
Sender parameters.
Definition: config.h:102
Metrics of sender session (connection to receiver).
Definition: metrics.h:22
Metrics for network link. Calculated independently on both sender and receiver.
Definition: metrics.h:53
Metrics sent from receiver to sender per source.
Definition: metrics.h:38
Metrics sent from sender to receiver.
Definition: metrics.h:23
Extracts capture timestamp field from packets.
FEC writer.