Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
receiver.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Roc 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.h
10//! @brief Receiver pipeline.
11
12#ifndef ROC_PIPELINE_RECEIVER_H_
13#define ROC_PIPELINE_RECEIVER_H_
14
15#include "roc_audio/ireader.h"
16#include "roc_audio/mixer.h"
19#include "roc_core/cond.h"
20#include "roc_core/iallocator.h"
21#include "roc_core/list.h"
22#include "roc_core/mutex.h"
24#include "roc_core/unique_ptr.h"
25#include "roc_fec/codec_map.h"
26#include "roc_packet/ireader.h"
27#include "roc_packet/iwriter.h"
29#include "roc_pipeline/config.h"
32#include "roc_rtp/format_map.h"
33#include "roc_sndio/isource.h"
34
35namespace roc {
36namespace pipeline {
37
38//! Receiver pipeline.
39class Receiver : public sndio::ISource,
40 public packet::IWriter,
41 public core::NonCopyable<> {
42public:
43 //! Initialize.
44 Receiver(const ReceiverConfig& config,
45 const fec::CodecMap& codec_map,
46 const rtp::FormatMap& format_map,
47 packet::PacketPool& packet_pool,
48 core::BufferPool<uint8_t>& byte_buffer_pool,
49 core::BufferPool<audio::sample_t>& sample_buffer_pool,
50 core::IAllocator& allocator);
51
52 //! Check if the pipeline was successfully constructed.
53 bool valid();
54
55 //! Add receiving port.
56 bool add_port(const PortConfig& config);
57
58 //! Iterate added ports.
59 void iterate_ports(void (*fn)(void*, const PortConfig&), void* arg) const;
60
61 //! Get number of alive sessions.
62 size_t num_sessions() const;
63
64 //! Get current receiver state.
65 virtual State state() const;
66
67 //! Wait until the receiver status becomes active.
68 virtual void wait_active() const;
69
70 //! Get source sample rate.
71 virtual size_t sample_rate() const;
72
73 //! Check if the source has own clock.
74 virtual bool has_clock() const;
75
76 //! Write packet.
77 virtual void write(const packet::PacketPtr&);
78
79 //! Read frame.
80 virtual bool read(audio::Frame&);
81
82private:
83 State state_() const;
84
85 void prepare_();
86
87 void fetch_packets_();
88
89 bool parse_packet_(const packet::PacketPtr& packet);
90 bool route_packet_(const packet::PacketPtr& packet);
91
92 bool can_create_session_(const packet::PacketPtr& packet);
93
94 bool create_session_(const packet::PacketPtr& packet);
95 void remove_session_(ReceiverSession& sess);
96
97 void update_sessions_();
98
99 ReceiverSessionConfig make_session_config_(const packet::PacketPtr& packet) const;
100
101 const fec::CodecMap& codec_map_;
102 const rtp::FormatMap& format_map_;
103
104 packet::PacketPool& packet_pool_;
105 core::BufferPool<uint8_t>& byte_buffer_pool_;
106 core::BufferPool<audio::sample_t>& sample_buffer_pool_;
107 core::IAllocator& allocator_;
108
111
113
114 core::Ticker ticker_;
115
118
119 audio::IReader* audio_reader_;
120
121 ReceiverConfig config_;
122
123 packet::timestamp_t timestamp_;
124 size_t num_channels_;
125
126 core::Mutex control_mutex_;
127 core::Mutex pipeline_mutex_;
128 core::Cond active_cond_;
129};
130
131} // namespace pipeline
132} // namespace roc
133
134#endif // ROC_PIPELINE_RECEIVER_H_
Buffer pool.
Audio frame.
Definition: frame.h:22
Audio reader interface.
Definition: ireader.h:22
Condition variable.
Definition: cond.h:25
Memory allocator interface.
Definition: iallocator.h:23
Intrusive doubly-linked list.
Definition: list.h:31
Mutex.
Definition: mutex.h:27
Base class for non-copyable objects.
Definition: noncopyable.h:23
Ticker.
Definition: ticker.h:23
Unique ownrship pointer.
Definition: unique_ptr.h:27
FEC codec map.
Definition: codec_map.h:26
Packet writer interface.
Definition: iwriter.h:21
Receiver session pipeline.
Receiver pipeline.
Definition: receiver.h:41
virtual void write(const packet::PacketPtr &)
Write packet.
bool add_port(const PortConfig &config)
Add receiving port.
virtual void wait_active() const
Wait until the receiver status becomes active.
void iterate_ports(void(*fn)(void *, const PortConfig &), void *arg) const
Iterate added ports.
Receiver(const ReceiverConfig &config, const fec::CodecMap &codec_map, const rtp::FormatMap &format_map, packet::PacketPool &packet_pool, core::BufferPool< uint8_t > &byte_buffer_pool, core::BufferPool< audio::sample_t > &sample_buffer_pool, core::IAllocator &allocator)
Initialize.
size_t num_sessions() const
Get number of alive sessions.
virtual bool read(audio::Frame &)
Read frame.
virtual size_t sample_rate() const
Get source sample rate.
virtual bool has_clock() const
Check if the source has own clock.
virtual State state() const
Get current receiver state.
bool valid()
Check if the pipeline was successfully constructed.
RTP payload format map.
Definition: format_map.h:22
Source interface.
Definition: isource.h:21
State
Source state.
Definition: isource.h:32
FEC codec map.
Condition variable.
RTP payload format map.
Memory allocator interface.
Source interface.
Intrusive doubly-linked list.
Mixer.
Mutex.
uint32_t timestamp_t
Audio packet timestamp.
Definition: units.h:46
Root namespace.
Non-copyable object.
Packet pool.
Poison reader.
Receiver port pipeline.
Receiver session pipeline.
Audio reader interface.
Packet reader interface.
Packet writer interface.
Pipeline config.
Port parameters.
Definition: config.h:56
Receiver parameters.
Definition: config.h:196
Receiver session parameters.
Definition: config.h:122
Unique ownrship pointer.