Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
receiver_source.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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_source.h
10 //! @brief Receiver source pipeline.
11 
12 #ifndef ROC_PIPELINE_RECEIVER_SOURCE_H_
13 #define ROC_PIPELINE_RECEIVER_SOURCE_H_
14 
16 #include "roc_audio/mixer.h"
20 #include "roc_core/iarena.h"
21 #include "roc_core/mutex.h"
22 #include "roc_core/optional.h"
23 #include "roc_core/stddefs.h"
24 #include "roc_packet/ireader.h"
25 #include "roc_packet/iwriter.h"
27 #include "roc_pipeline/config.h"
31 #include "roc_rtp/format_map.h"
32 #include "roc_sndio/isource.h"
33 
34 namespace roc {
35 namespace pipeline {
36 
37 //! Receiver source pipeline.
38 //!
39 //! Contains:
40 //! - one or more receiver slots
41 //! - mixer, to mix audio from all slots
42 //!
43 //! Pipeline:
44 //! - input: packets
45 //! - output: frames
47 public:
48  //! Initialize.
50  const rtp::FormatMap& format_map,
51  packet::PacketFactory& packet_factory,
52  core::BufferFactory<uint8_t>& byte_buffer_factory,
53  core::BufferFactory<audio::sample_t>& sample_buffer_factory,
54  core::IArena& arena);
55 
56  //! Check if the pipeline was successfully constructed.
57  bool is_valid() const;
58 
59  //! Create slot.
61 
62  //! Delete slot.
64 
65  //! Get number of connected sessions.
66  size_t num_sessions() const;
67 
68  //! Pull packets and refresh pipeline according to current time.
69  //! @remarks
70  //! Should be invoked before reading each frame.
71  //! Also should be invoked after provided deadline if no frames were
72  //! read until that deadline expires.
73  //! @returns
74  //! deadline (absolute time) when refresh should be invoked again
75  //! if there are no frames
77 
78  //! Get device type.
79  virtual sndio::DeviceType type() const;
80 
81  //! Get current receiver state.
82  virtual sndio::DeviceState state() const;
83 
84  //! Pause reading.
85  virtual void pause();
86 
87  //! Resume paused reading.
88  virtual bool resume();
89 
90  //! Restart reading from the beginning.
91  virtual bool restart();
92 
93  //! Get sample specification of the source.
94  virtual audio::SampleSpec sample_spec() const;
95 
96  //! Get latency of the source.
97  virtual core::nanoseconds_t latency() const;
98 
99  //! Check if the source supports latency reports.
100  virtual bool has_latency() const;
101 
102  //! Check if the source has own clock.
103  virtual bool has_clock() const;
104 
105  //! Adjust sessions clock to match consumer clock.
106  //! @remarks
107  //! @p playback_time specified absolute time when first sample of last frame
108  //! retrieved from pipeline will be actually played on sink
109  virtual void reclock(core::nanoseconds_t playback_time);
110 
111  //! Read audio frame.
112  virtual bool read(audio::Frame&);
113 
114 private:
115  const rtp::FormatMap& format_map_;
116 
117  packet::PacketFactory& packet_factory_;
118  core::BufferFactory<uint8_t>& byte_buffer_factory_;
119  core::BufferFactory<audio::sample_t>& sample_buffer_factory_;
120  core::IArena& arena_;
121 
122  ReceiverState state_;
123 
127 
129 
130  audio::IFrameReader* audio_reader_;
131 
132  ReceiverConfig config_;
133 };
134 
135 } // namespace pipeline
136 } // namespace roc
137 
138 #endif // ROC_PIPELINE_RECEIVER_SOURCE_H_
Buffer factory.
Audio frame.
Definition: frame.h:25
Frame reader interface.
Definition: iframe_reader.h:22
Sample specification. Describes sample rate and channels.
Definition: sample_spec.h:26
Memory arena interface.
Definition: iarena.h:23
Intrusive doubly-linked list.
Definition: list.h:35
Base class for non-copyable objects.
Definition: noncopyable.h:23
Optionally constructed object.
Definition: optional.h:25
Receiver source pipeline.
bool is_valid() const
Check if the pipeline was successfully constructed.
virtual void reclock(core::nanoseconds_t playback_time)
Adjust sessions clock to match consumer clock.
virtual void pause()
Pause reading.
virtual sndio::DeviceState state() const
Get current receiver state.
ReceiverSource(const ReceiverConfig &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.
virtual core::nanoseconds_t latency() const
Get latency of the source.
virtual bool restart()
Restart reading from the beginning.
virtual bool resume()
Resume paused reading.
void delete_slot(ReceiverSlot *slot)
Delete slot.
virtual bool has_clock() const
Check if the source has own clock.
virtual audio::SampleSpec sample_spec() const
Get sample specification of the source.
virtual bool has_latency() const
Check if the source supports latency reports.
virtual bool read(audio::Frame &)
Read audio frame.
size_t num_sessions() const
Get number of connected sessions.
virtual sndio::DeviceType type() const
Get device type.
ReceiverSlot * create_slot()
Create slot.
core::nanoseconds_t refresh(core::nanoseconds_t current_time)
Pull packets and refresh pipeline according to current time.
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
Source interface.
Definition: isource.h:23
RTP payload format map.
Memory arena interface.
Frame reader interface.
Packet reader interface.
Source interface.
Packet writer interface.
Mixer.
Mutex.
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
DeviceType
Device type.
Definition: device_type.h:19
DeviceState
Device state.
Definition: device_state.h:19
Root namespace.
Optionally constructed object.
Packet factory.
Poison reader.
Profiling reader.
Receiver endpoint pipeline.
Receiver slot.
Receiver pipeline state.
Pipeline config.
Commonly used types and functions.
Receiver parameters.
Definition: config.h:238