Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
receiver_loop.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_loop.h
10//! @brief Receiver pipeline loop.
11
12#ifndef ROC_PIPELINE_RECEIVER_LOOP_H_
13#define ROC_PIPELINE_RECEIVER_LOOP_H_
14
16#include "roc_core/iallocator.h"
17#include "roc_core/mutex.h"
18#include "roc_core/optional.h"
19#include "roc_core/stddefs.h"
21#include "roc_pipeline/config.h"
24#include "roc_sndio/isource.h"
25
26namespace roc {
27namespace pipeline {
28
29//! Receiver pipeline loop.
30//!
31//! This class acts as a task-based facade for the receiver pipeline subsystem
32//! of roc_pipeline module (ReceiverSource, ReceiverSlot, ReceiverEndpoint,
33//! ReceiverSessionGroup, ReceiverSession).
34//!
35//! It provides two interfaces:
36//!
37//! - sndio::ISource - can be used to retrieve samples from the pipeline
38//! (should be used from sndio thread)
39//!
40//! - PipelineLoop - can be used to schedule tasks on the pipeline
41//! (can be used from any thread)
42//!
43//! @note
44//! Private inheritance from ISource is used to decorate actual implementation
45//! of ISource - ReceiverSource, in order to integrate it with PipelineLoop.
46class ReceiverLoop : public PipelineLoop, private sndio::ISource {
47public:
48 //! Opaque slot handle.
49 typedef struct SlotHandle* SlotHandle;
50
51 //! Base task class.
52 class Task : public PipelineTask {
53 protected:
54 friend class ReceiverLoop;
55
56 Task();
57
58 bool (ReceiverLoop::*func_)(Task&); //!< Task implementation method.
59
60 ReceiverSlot* slot_; //!< Slot.
61 address::Interface iface_; //!< Interface.
62 address::Protocol proto_; //!< Protocol.
63 packet::IWriter* writer_; //!< Packet writer.
64 };
65
66 //! Subclasses for specific tasks.
67 class Tasks {
68 public:
69 //! Add new slot.
70 class CreateSlot : public Task {
71 public:
72 //! Set task parameters.
74
75 //! Get created slot handle.
77 };
78
79 //! Create endpoint on given interface of the slot.
80 class CreateEndpoint : public Task {
81 public:
82 //! Set task parameters.
83 //! @remarks
84 //! Each slot can have one source and zero or one repair endpoint.
85 //! The protocols of endpoints in one slot should be compatible.
88 address::Protocol proto);
89
90 //! Get packet writer for the endpoint.
91 //! @remarks
92 //! The returned writer may be used from any thread.
94 };
95
96 //! Delete endpoint on given interface of the slot, if it exists.
97 class DeleteEndpoint : public Task {
98 public:
99 //! Set task parameters.
101 };
102 };
103
104 //! Initialize.
106 const ReceiverConfig& config,
107 const rtp::FormatMap& format_map,
108 packet::PacketFactory& packet_factory,
109 core::BufferFactory<uint8_t>& byte_buffer_factory,
110 core::BufferFactory<audio::sample_t>& sample_buffer_factory,
111 core::IAllocator& allocator);
112
113 //! Check if the pipeline was successfully constructed.
114 bool valid() const;
115
116 //! Get receiver sources.
117 //! @remarks
118 //! Samples received from remote peers become available in this source.
120
121private:
122 // Methods of sndio::ISource
123 virtual audio::SampleSpec sample_spec() const;
124 virtual core::nanoseconds_t latency() const;
125 virtual bool has_clock() const;
126 virtual State state() const;
127 virtual void pause();
128 virtual bool resume();
129 virtual bool restart();
130 virtual void reclock(packet::ntp_timestamp_t timestamp);
131 virtual bool read(audio::Frame&);
132
133 // Methods of PipelineLoop
134 virtual core::nanoseconds_t timestamp_imp() const;
135 virtual bool process_subframe_imp(audio::Frame& frame);
136 virtual bool process_task_imp(PipelineTask& task);
137
138 // Methods for tasks
139 bool task_create_slot_(Task& task);
140 bool task_create_endpoint_(Task& task);
141 bool task_delete_endpoint_(Task& task);
142
143 ReceiverSource source_;
144
146 packet::timestamp_t timestamp_;
147
148 core::Mutex read_mutex_;
149
150 bool valid_;
151};
152
153} // namespace pipeline
154} // namespace roc
155
156#endif // ROC_PIPELINE_RECEIVER_LOOP_H_
Buffer factory.
Audio frame.
Definition: frame.h:22
Sample stream specification. Defines sample rate and channel layout.
Definition: sample_spec.h:24
Memory allocator interface.
Definition: iallocator.h:23
Mutex.
Definition: mutex.h:30
Optionally constructed object.
Definition: optional.h:25
Packet writer interface.
Definition: iwriter.h:21
Pipeline task scheduler interface. PipelineLoop uses this interface to schedule asynchronous work....
Base class for task-based pipelines.
Base class for pipeline tasks.
Definition: pipeline_task.h:27
bool(ReceiverLoop::* func_)(Task &)
Task implementation method.
Definition: receiver_loop.h:58
packet::IWriter * writer_
Packet writer.
Definition: receiver_loop.h:63
address::Interface iface_
Interface.
Definition: receiver_loop.h:61
address::Protocol proto_
Protocol.
Definition: receiver_loop.h:62
Create endpoint on given interface of the slot.
Definition: receiver_loop.h:80
CreateEndpoint(SlotHandle slot, address::Interface iface, address::Protocol proto)
Set task parameters.
packet::IWriter * get_writer() const
Get packet writer for the endpoint.
SlotHandle get_handle() const
Get created slot handle.
Delete endpoint on given interface of the slot, if it exists.
Definition: receiver_loop.h:97
DeleteEndpoint(SlotHandle slot, address::Interface iface)
Set task parameters.
Subclasses for specific tasks.
Definition: receiver_loop.h:67
Receiver pipeline loop.
Definition: receiver_loop.h:46
sndio::ISource & source()
Get receiver sources.
struct SlotHandle * SlotHandle
Opaque slot handle.
Definition: receiver_loop.h:49
ReceiverLoop(IPipelineTaskScheduler &scheduler, 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::IAllocator &allocator)
Initialize.
bool valid() const
Check if the pipeline was successfully constructed.
Receiver source pipeline.
RTP payload format map.
Definition: format_map.h:22
Source interface.
Definition: isource.h:23
State
Source state.
Definition: isource.h:28
Memory allocator interface.
Source interface.
Mutex.
Interface
Interface ID.
Definition: interface.h:19
Protocol
Protocol ID.
Definition: protocol.h:19
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
uint32_t timestamp_t
Audio packet timestamp.
Definition: units.h:25
uint64_t ntp_timestamp_t
NTP timestamp.
Definition: units.h:91
Root namespace.
Optionally constructed object.
Packet factory.
Base class for pipelines.
Receiver source pipeline.
Pipeline config.
Commonly used types and functions.
Receiver parameters.
Definition: config.h:247