Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
receiver_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/receiver_slot.h
10 //! @brief Receiver slot.
11 
12 #ifndef ROC_PIPELINE_RECEIVER_SLOT_H_
13 #define ROC_PIPELINE_RECEIVER_SLOT_H_
14 
15 #include "roc_address/interface.h"
16 #include "roc_address/protocol.h"
18 #include "roc_audio/mixer.h"
19 #include "roc_core/iarena.h"
20 #include "roc_core/list_node.h"
21 #include "roc_core/ref_counted.h"
23 #include "roc_pipeline/metrics.h"
27 #include "roc_rtp/encoding_map.h"
28 
29 namespace roc {
30 namespace pipeline {
31 
32 //! Receiver slot.
33 //!
34 //! Contains:
35 //! - one or more related receiver endpoints, one per each type
36 //! - one session group associated with those endpoints
37 class ReceiverSlot : public core::RefCounted<ReceiverSlot, core::ArenaAllocation>,
38  public core::ListNode<> {
39 public:
40  //! Initialize.
41  ReceiverSlot(const ReceiverSourceConfig& source_config,
42  const ReceiverSlotConfig& slot_config,
43  StateTracker& state_tracker,
44  audio::Mixer& mixer,
45  const rtp::EncodingMap& encoding_map,
46  packet::PacketFactory& packet_factory,
47  audio::FrameFactory& frame_factory,
49 
50  //! Check if the slot was succefully constructed.
51  bool is_valid() const;
52 
53  //! Add endpoint.
55  address::Protocol proto,
56  const address::SocketAddr& inbound_address,
57  packet::IWriter* outbound_writer);
58 
59  //! Pull packets and refresh sessions according to current time.
60  //! @returns
61  //! deadline (absolute time) when refresh should be invoked again
62  //! if there are no frames
64 
65  //! Adjust sessions clock to match consumer clock.
66  //! @remarks
67  //! @p playback_time specified absolute time when first sample of last frame
68  //! retrieved from pipeline will be actually played on sink
69  void reclock(core::nanoseconds_t playback_time);
70 
71  //! Get number of alive sessions.
72  size_t num_sessions() const;
73 
74  //! Get metrics for slot and its participants.
75  void get_metrics(ReceiverSlotMetrics& slot_metrics,
76  ReceiverParticipantMetrics* party_metrics,
77  size_t* party_count) const;
78 
79 private:
80  ReceiverEndpoint* create_source_endpoint_(address::Protocol proto,
81  const address::SocketAddr& inbound_address,
82  packet::IWriter* outbound_writer);
83  ReceiverEndpoint* create_repair_endpoint_(address::Protocol proto,
84  const address::SocketAddr& inbound_address,
85  packet::IWriter* outbound_writer);
86  ReceiverEndpoint* create_control_endpoint_(address::Protocol proto,
87  const address::SocketAddr& inbound_address,
88  packet::IWriter* outbound_writer);
89 
90  const rtp::EncodingMap& encoding_map_;
91 
92  StateTracker& state_tracker_;
93  ReceiverSessionGroup session_group_;
94 
95  core::Optional<ReceiverEndpoint> source_endpoint_;
96  core::Optional<ReceiverEndpoint> repair_endpoint_;
97  core::Optional<ReceiverEndpoint> control_endpoint_;
98 
99  bool valid_;
100 };
101 
102 } // namespace pipeline
103 } // namespace roc
104 
105 #endif // ROC_PIPELINE_RECEIVER_SLOT_H_
Socket address.
Definition: socket_addr.h:26
Mixer. Mixes multiple input streams into one output stream.
Definition: mixer.h:46
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
Packet writer interface.
Definition: iwriter.h:23
Receiver endpoint sub-pipeline.
core::nanoseconds_t refresh(core::nanoseconds_t current_time)
Pull packets and refresh sessions according to current time.
void get_metrics(ReceiverSlotMetrics &slot_metrics, ReceiverParticipantMetrics *party_metrics, size_t *party_count) const
Get metrics for slot and its participants.
ReceiverSlot(const ReceiverSourceConfig &source_config, const ReceiverSlotConfig &slot_config, StateTracker &state_tracker, audio::Mixer &mixer, const rtp::EncodingMap &encoding_map, packet::PacketFactory &packet_factory, audio::FrameFactory &frame_factory, core::IArena &arena)
Initialize.
bool is_valid() const
Check if the slot was succefully constructed.
ReceiverEndpoint * add_endpoint(address::Interface iface, address::Protocol proto, const address::SocketAddr &inbound_address, packet::IWriter *outbound_writer)
Add endpoint.
void reclock(core::nanoseconds_t playback_time)
Adjust sessions clock to match consumer clock.
size_t num_sessions() const
Get number of alive sessions.
Pipeline state tracker.
Definition: state_tracker.h:30
RTP encoding map. Thread-safe. Returned encodings are immutable and can be safely used from any threa...
Definition: encoding_map.h:33
RTP encoding map.
Frame factory.
Memory arena interface.
Interface ID.
Linked list node.
Pipeline metrics.
Mixer.
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.
Packet factory.
Protocol ID.
Receiver endpoint pipeline.
Receiver session group.
Base class for object with reference counter.
Pipeline state tracker.
Receiver-side metrics specific to one participant (remote sender).
Definition: metrics.h:54
Parameters of receiver slot.
Definition: config.h:202
Receiver-side metrics of the whole slot.
Definition: metrics.h:66
Parameters of receiver session.
Definition: config.h:184