Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
sender_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/sender_loop.h
10//! @brief Sender pipeline loop.
11
12#ifndef ROC_PIPELINE_SENDER_LOOP_H_
13#define ROC_PIPELINE_SENDER_LOOP_H_
14
16#include "roc_core/iallocator.h"
17#include "roc_core/mutex.h"
18#include "roc_core/ticker.h"
19#include "roc_pipeline/config.h"
22#include "roc_sndio/isink.h"
23
24namespace roc {
25namespace pipeline {
26
27//! Sender pipeline loop.
28//
29//! This class acts as a task-based facade for the sender pipeline subsystem of
30//! roc_pipeline module (SenderSink, SenderSlot, SenderEndpoint, SenderSession).
31//!
32//! It provides two interfaces:
33//!
34//! - sndio::ISink - can be used to pass samples to the pipeline
35//! (should be used from sndio thread)
36//!
37//! - PipelineLoop - can be used to schedule tasks on the pipeline
38//! (can be used from any thread)
39//!
40//! @note
41//! Private inheritance from ISink is used to decorate actual implementation
42//! of ISink - SenderSource, in order to integrate it with PipelineLoop.
43class SenderLoop : public PipelineLoop, private sndio::ISink {
44public:
45 //! Opaque slot handle.
46 typedef struct SlotHandle* SlotHandle;
47
48 //! Opaque endpoint handle.
50
51 //! Base task class.
52 class Task : public PipelineTask {
53 protected:
54 friend class SenderLoop;
55
56 Task();
57
58 bool (SenderLoop::*func_)(Task&); //!< Task implementation method.
59
60 SenderSlot* slot_; //!< Slot.
61 SenderEndpoint* endpoint_; //!< Endpoint.
62 address::Interface iface_; //!< Interface.
63 address::Protocol proto_; //!< Protocol.
64 packet::IWriter* writer_; //!< Packet writer.
65 address::SocketAddr addr_; //!< Endpoint address.
66 };
67
68 //! Subclasses for specific tasks.
69 class Tasks {
70 public:
71 //! Add new slot.
72 class CreateSlot : public Task {
73 public:
74 //! Set task parameters.
76
77 //! Get created slot handle.
79 };
80
81 //! Create endpoint on given interface of the slot.
82 class CreateEndpoint : public Task {
83 public:
84 //! Set task parameters.
85 //! @remarks
86 //! Each slot can have one source and zero or one repair endpoint.
87 //! The protocols of endpoints in one slot should be compatible.
90 address::Protocol proto);
91
92 //! Get created endpoint handle.
94 };
95
96 //! Set writer to which endpoint will write packets.
98 public:
99 //! Set task parameters.
101 packet::IWriter& writer);
102 };
103
104 //! Set UDP address for output packets of endpoint.
106 public:
107 //! Set task parameters.
109 const address::SocketAddr& addr);
110 };
111
112 //! Check if the slot configuration is done.
113 //! This is true when all necessary endpoints are added and configured.
114 class CheckSlotIsReady : public Task {
115 public:
116 //! Set task parameters.
118 };
119 };
120
121 //! Initialize.
123 const SenderConfig& config,
124 const rtp::FormatMap& format_map,
125 packet::PacketFactory& packet_factory,
126 core::BufferFactory<uint8_t>& byte_buffer_factory,
127 core::BufferFactory<audio::sample_t>& sample_buffer_factory,
128 core::IAllocator& allocator);
129
130 //! Check if the pipeline was successfully constructed.
131 bool valid() const;
132
133 //! Get sender sink.
134 //! @remarks
135 //! Samples written to the sink are sent to remote peers.
137
138private:
139 // Methods of sndio::ISink
140 virtual audio::SampleSpec sample_spec() const;
141 virtual core::nanoseconds_t latency() const;
142 virtual bool has_clock() const;
143 virtual void write(audio::Frame& frame);
144
145 // Methods of PipelineLoop
146 virtual core::nanoseconds_t timestamp_imp() const;
147 virtual bool process_subframe_imp(audio::Frame&);
148 virtual bool process_task_imp(PipelineTask&);
149
150 // Methods for tasks
151 bool task_create_slot_(Task&);
152 bool task_create_endpoint_(Task&);
153 bool task_set_endpoint_destination_writer_(Task&);
154 bool task_set_endpoint_destination_address_(Task&);
155 bool task_check_slot_is_ready_(Task&);
156
157 SenderSink sink_;
158
160 packet::timestamp_t timestamp_;
161
162 core::Mutex write_mutex_;
163
164 bool valid_;
165};
166
167} // namespace pipeline
168} // namespace roc
169
170#endif // ROC_PIPELINE_SENDER_LOOP_H_
Buffer factory.
Socket address.
Definition: socket_addr.h:25
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
Sender endpoint sub-pipeline.
address::Protocol proto_
Protocol.
Definition: sender_loop.h:63
address::SocketAddr addr_
Endpoint address.
Definition: sender_loop.h:65
bool(SenderLoop::* func_)(Task &)
Task implementation method.
Definition: sender_loop.h:58
address::Interface iface_
Interface.
Definition: sender_loop.h:62
packet::IWriter * writer_
Packet writer.
Definition: sender_loop.h:64
SenderEndpoint * endpoint_
Endpoint.
Definition: sender_loop.h:61
Check if the slot configuration is done. This is true when all necessary endpoints are added and conf...
Definition: sender_loop.h:114
CheckSlotIsReady(SlotHandle slot)
Set task parameters.
Create endpoint on given interface of the slot.
Definition: sender_loop.h:82
EndpointHandle get_handle() const
Get created endpoint handle.
CreateEndpoint(SlotHandle slot, address::Interface iface, address::Protocol proto)
Set task parameters.
SlotHandle get_handle() const
Get created slot handle.
Set UDP address for output packets of endpoint.
Definition: sender_loop.h:105
SetEndpointDestinationAddress(EndpointHandle endpoint, const address::SocketAddr &addr)
Set task parameters.
Set writer to which endpoint will write packets.
Definition: sender_loop.h:97
SetEndpointDestinationWriter(EndpointHandle endpoint, packet::IWriter &writer)
Set task parameters.
Subclasses for specific tasks.
Definition: sender_loop.h:69
Sender pipeline loop.
Definition: sender_loop.h:43
sndio::ISink & sink()
Get sender sink.
struct EndpointHandle * EndpointHandle
Opaque endpoint handle.
Definition: sender_loop.h:49
SenderLoop(IPipelineTaskScheduler &scheduler, const SenderConfig &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.
struct SlotHandle * SlotHandle
Opaque slot handle.
Definition: sender_loop.h:46
bool valid() const
Check if the pipeline was successfully constructed.
Sender sink pipeline.
Definition: sender_sink.h:48
RTP payload format map.
Definition: format_map.h:22
Sink interface.
Definition: isink.h:22
Memory allocator interface.
Sink 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
Root namespace.
Base class for pipelines.
Pipeline config.
Sender sink pipeline.
Sender parameters.
Definition: config.h:101
Ticker.