Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
sender_slot.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_slot.h
10 //! @brief Sender slot.
11 
12 #ifndef ROC_PIPELINE_SENDER_SLOT_H_
13 #define ROC_PIPELINE_SENDER_SLOT_H_
14 
15 #include "roc_address/interface.h"
16 #include "roc_address/protocol.h"
17 #include "roc_audio/fanout.h"
19 #include "roc_core/iarena.h"
20 #include "roc_core/noncopyable.h"
21 #include "roc_core/optional.h"
22 #include "roc_core/ref_counted.h"
24 #include "roc_pipeline/config.h"
25 #include "roc_pipeline/metrics.h"
28 
29 namespace roc {
30 namespace pipeline {
31 
32 //! Sender slot.
33 //!
34 //! Contains:
35 //! - one or more related sender endpoints, one per each type
36 //! - one session associated with those endpoints
37 class SenderSlot : public core::RefCounted<SenderSlot, core::ArenaAllocation>,
38  public core::ListNode {
39 public:
40  //! Initialize.
41  SenderSlot(const SenderConfig& config,
42  const rtp::FormatMap& format_map,
43  audio::Fanout& fanout,
44  packet::PacketFactory& packet_factory,
45  core::BufferFactory<uint8_t>& byte_buffer_factory,
46  core::BufferFactory<audio::sample_t>& sample_buffer_factory,
48 
49  ~SenderSlot();
50 
51  //! Add endpoint.
53  address::Protocol proto,
54  const address::SocketAddr& dest_address,
55  packet::IWriter& dest_writer);
56 
57  //! Get audio writer.
58  //! @returns NULL if slot is not ready.
60 
61  //! Check if slot configuration is complete.
62  bool is_complete() const;
63 
64  //! Refresh pipeline according to current time.
65  //! @returns
66  //! deadline (absolute time) when refresh should be invoked again
67  //! if there are no frames
69 
70  //! Get metrics for slot and its session.
71  void get_metrics(SenderSlotMetrics& slot_metrics,
72  SenderSessionMetrics* sess_metrics) const;
73 
74 private:
75  SenderEndpoint* create_source_endpoint_(address::Protocol proto,
76  const address::SocketAddr& dest_address,
77  packet::IWriter& dest_writer);
78  SenderEndpoint* create_repair_endpoint_(address::Protocol proto,
79  const address::SocketAddr& dest_address,
80  packet::IWriter& dest_writer);
81  SenderEndpoint* create_control_endpoint_(address::Protocol proto,
82  const address::SocketAddr& dest_address,
83  packet::IWriter& dest_writer);
84 
85  const SenderConfig& config_;
86 
87  audio::Fanout& fanout_;
88 
89  core::Optional<SenderEndpoint> source_endpoint_;
90  core::Optional<SenderEndpoint> repair_endpoint_;
91  core::Optional<SenderEndpoint> control_endpoint_;
92 
93  SenderSession session_;
94 };
95 
96 } // namespace pipeline
97 } // namespace roc
98 
99 #endif // ROC_PIPELINE_SENDER_SLOT_H_
Buffer factory.
Socket address.
Definition: socket_addr.h:26
Fanout. Duplicates audio stream to multiple output writers.
Definition: fanout.h:26
Frame writer interface.
Definition: iframe_writer.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
Packet writer interface.
Definition: iwriter.h:23
Sender endpoint sub-pipeline.
Sender session sub-pipeline.
audio::IFrameWriter * writer()
Get audio writer.
void get_metrics(SenderSlotMetrics &slot_metrics, SenderSessionMetrics *sess_metrics) const
Get metrics for slot and its session.
SenderEndpoint * add_endpoint(address::Interface iface, address::Protocol proto, const address::SocketAddr &dest_address, packet::IWriter &dest_writer)
Add endpoint.
SenderSlot(const SenderConfig &config, const rtp::FormatMap &format_map, audio::Fanout &fanout, packet::PacketFactory &packet_factory, core::BufferFactory< uint8_t > &byte_buffer_factory, core::BufferFactory< audio::sample_t > &sample_buffer_factory, core::IArena &arena)
Initialize.
core::nanoseconds_t refresh(core::nanoseconds_t current_time)
Refresh pipeline according to current time.
bool is_complete() const
Check if slot configuration is complete.
RTP payload format map. Thread-safe. Returned formats are immutable and can be safely used from any t...
Definition: format_map.h:33
Fanout.
Memory arena interface.
Interface ID.
Interface
Interface ID.
Definition: interface.h:19
Protocol
Protocol ID.
Definition: protocol.h:19
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
Root namespace.
Non-copyable object.
Optionally constructed object.
Packet factory.
Protocol ID.
Base class for object with reference counter.
Pipeline config.
Pipeline metrics.
Sender endpoint pipeline.
Sender session.
Sender parameters.
Definition: config.h:102
Metrics of sender session (connection to receiver).
Definition: metrics.h:22
Metrics of sender slot.
Definition: metrics.h:28