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"
17 #include "roc_audio/mixer.h"
18 #include "roc_core/iarena.h"
19 #include "roc_core/list.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/format_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 ReceiverConfig& receiver_config,
42  ReceiverState& receiver_state,
43  audio::Mixer& mixer,
44  const rtp::FormatMap& format_map,
45  packet::PacketFactory& packet_factory,
46  core::BufferFactory<uint8_t>& byte_buffer_factory,
47  core::BufferFactory<audio::sample_t>& sample_buffer_factory,
49 
50  //! Add endpoint.
52 
53  //! Pull packets and refresh sessions according to current time.
54  //! @returns
55  //! deadline (absolute time) when refresh should be invoked again
56  //! if there are no frames
58 
59  //! Adjust sessions clock to match consumer clock.
60  //! @remarks
61  //! @p playback_time specified absolute time when first sample of last frame
62  //! retrieved from pipeline will be actually played on sink
63  void reclock(core::nanoseconds_t playback_time);
64 
65  //! Get number of alive sessions.
66  size_t num_sessions() const;
67 
68  //! Get metrics for slot and its sessions.
69  void get_metrics(ReceiverSlotMetrics& slot_metrics,
70  ReceiverSessionMetrics* sess_metrics,
71  size_t* sess_metrics_size) const;
72 
73 private:
74  ReceiverEndpoint* create_source_endpoint_(address::Protocol proto);
75  ReceiverEndpoint* create_repair_endpoint_(address::Protocol proto);
76  ReceiverEndpoint* create_control_endpoint_(address::Protocol proto);
77 
78  const rtp::FormatMap& format_map_;
79 
80  ReceiverState& receiver_state_;
81  ReceiverSessionGroup session_group_;
82 
83  core::Optional<ReceiverEndpoint> source_endpoint_;
84  core::Optional<ReceiverEndpoint> repair_endpoint_;
85  core::Optional<ReceiverEndpoint> control_endpoint_;
86 };
87 
88 } // namespace pipeline
89 } // namespace roc
90 
91 #endif // ROC_PIPELINE_RECEIVER_SLOT_H_
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:26
Optionally constructed object.
Definition: optional.h:25
Base class for object with reference counter.
Definition: ref_counted.h:40
Receiver endpoint sub-pipeline.
ReceiverEndpoint * add_endpoint(address::Interface iface, address::Protocol proto)
Add endpoint.
ReceiverSlot(const ReceiverConfig &receiver_config, ReceiverState &receiver_state, audio::Mixer &mixer, 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.
void get_metrics(ReceiverSlotMetrics &slot_metrics, ReceiverSessionMetrics *sess_metrics, size_t *sess_metrics_size) const
Get metrics for slot and its sessions.
core::nanoseconds_t refresh(core::nanoseconds_t current_time)
Pull packets and refresh sessions according to current time.
void reclock(core::nanoseconds_t playback_time)
Adjust sessions clock to match consumer clock.
size_t num_sessions() const
Get number of alive sessions.
Receiver pipeline state. Thread-safe.
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.
Interface ID.
Intrusive doubly-linked list.
Linked list node.
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.
Receiver pipeline state.
Base class for object with reference counter.
Pipeline metrics.
Receiver parameters.
Definition: config.h:238
Metrics of receiver session (connection from sender).
Definition: metrics.h:38
Metrics of receiver slot.
Definition: metrics.h:44