Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
config.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/config.h
10 //! @brief Pipeline config.
11 
12 #ifndef ROC_PIPELINE_CONFIG_H_
13 #define ROC_PIPELINE_CONFIG_H_
14 
15 #include "roc_address/protocol.h"
18 #include "roc_audio/profiler.h"
22 #include "roc_audio/sample_spec.h"
23 #include "roc_audio/watchdog.h"
24 #include "roc_core/stddefs.h"
25 #include "roc_core/time.h"
26 #include "roc_fec/codec_config.h"
27 #include "roc_fec/reader.h"
28 #include "roc_fec/writer.h"
29 #include "roc_packet/units.h"
30 #include "roc_rtp/headers.h"
31 #include "roc_rtp/validator.h"
32 
33 namespace roc {
34 namespace pipeline {
35 
36 //! Default sample rate, number of samples per second.
37 const size_t DefaultSampleRate = 44100;
38 
39 //! Default sample specification.
40 static const audio::SampleSpec DefaultSampleSpec(DefaultSampleRate,
43  audio::ChanMask_Surround_Stereo);
44 
45 //! Default packet length.
46 //! @remarks
47 //! 5ms works well on majority Wi-Fi networks and allows rather low latencies. However,
48 //! a lower length may be required depending on network MTU, e.g. for Internet.
50 
51 //! Default latency.
52 //! @remarks
53 //! 200ms works well on majority Wi-Fi networks and is not too annoying. However, many
54 //! networks allow lower latencies, and some networks require higher.
56 
57 //! Task processing parameters.
58 struct TaskConfig {
59  //! Enable precise task scheduling mode (default).
60  //! The other settings have effect only when this is set to true.
61  //! When enabled, pipeline processes tasks in dedicated time intervals between
62  //! sub-frame and between frames, trying to prevent time collisions between
63  //! task and frame processing.
65 
66  //! Minimum frame duration between processing tasks.
67  //! In-frame task processing does not happen until at least given number
68  //! of samples is processed.
69  //! Set to zero to allow task processing between frames of any size.
71 
72  //! Maximum frame duration between processing tasks.
73  //! If the frame is larger than this size, it is split into multiple subframes
74  //! to allow task processing between the sub-frames.
75  //! Set to zero to disable frame splitting.
77 
78  //! Mximum task processing duration happening immediatelly after processing a frame.
79  //! If this period expires and there are still pending tasks, asynchronous
80  //! task processing is scheduled.
81  //! At least one task is always processed after each frame, even if this
82  //! setting is too small.
84 
85  //! Time interval during which no task processing is allowed.
86  //! This setting is used to prohibit task processing during the time when
87  //! next read() or write() call is expected.
88  //! Since it can not be calculated abolutely precisely, and there is always
89  //! thread switch overhead, scheduler jitter clock drift, we use a wide interval.
91 
92  TaskConfig()
98  }
99 };
100 
101 //! Sender parameters.
102 struct SenderConfig {
103  //! Task processing parameters.
105 
106  //! To specify which resampling backend will be used.
108 
109  //! Resampler profile.
111 
112  //! FEC writer parameters.
114 
115  //! FEC encoder parameters.
117 
118  //! Input sample spec
120 
121  //! Packet length, in nanoseconds.
123 
124  //! RTP payload type for audio packets.
125  unsigned payload_type;
126 
127  //! Interleave packets.
129 
130  //! Constrain receiver speed using a CPU timer according to the sample rate.
132 
133  //! Automatically fill capture timestamps of input frames with invocation time.
135 
136  //! Profile moving average of frames being written.
138 
139  //! Profiler configuration.
141 
142  SenderConfig()
145  , input_sample_spec(DefaultSampleSpec)
148  , enable_interleaving(false)
149  , enable_timing(false)
150  , enable_auto_cts(false)
151  , enable_profiling(false) {
152  }
153 };
154 
155 //! Receiver session parameters.
156 //! @remarks
157 //! Defines per-session receiver parameters.
159  //! Target latency, nanoseconds.
161 
162  //! Packet payload type.
163  unsigned int payload_type;
164 
165  //! FEC reader parameters.
167 
168  //! FEC decoder parameters.
170 
171  //! RTP validator parameters.
173 
174  //! LatencyMonitor parameters.
176 
177  //! Watchdog parameters.
179 
180  //! To specify which resampling backend will be used.
182 
183  //! Resampler profile.
185 
188  , payload_type(0)
193  }
194 
195  //! Automatically deduce resampler backend from FreqEstimator config.
200  } else {
202  }
203  }
204 };
205 
206 //! Receiver common parameters.
207 //! @remarks
208 //! Defines receiver parameters common for all sessions.
210  //! Output sample spec
212 
213  //! Constrain receiver speed using a CPU timer according to the sample rate.
215 
216  //! Automatically invoke reclock before returning frames with invocation time.
218 
219  //! Profile moving average of frames being written.
221 
222  //! Profiler configuration.
224 
225  //! Insert weird beeps instead of silence on packet loss.
227 
229  : output_sample_spec(DefaultSampleSpec)
230  , enable_timing(false)
231  , enable_auto_reclock(false)
232  , enable_profiling(false)
233  , enable_beeping(false) {
234  }
235 };
236 
237 //! Receiver parameters.
239  //! Default parameters for receiver session.
241 
242  //! Parameters common for all sessions.
244 
245  //! Task processing parameters.
247 };
248 
249 //! Converter parameters.
251  //! To specify which resampling backend will be used.
253 
254  //! Resampler profile.
256 
257  //! Input sample spec
259 
260  //! Output sample spec
262 
263  //! Profile moving average of frames being written.
265 
266  //! Profiler configuration.
268 
272  , input_sample_spec(DefaultSampleSpec)
273  , output_sample_spec(DefaultSampleSpec)
274  , enable_profiling(false) {
275  }
276 };
277 
278 } // namespace pipeline
279 } // namespace roc
280 
281 #endif // ROC_PIPELINE_CONFIG_H_
Sample specification. Describes sample rate and channels.
Definition: sample_spec.h:26
FEC codec parameters.
Frequency estimator.
Latency monitor.
ResamplerBackend
Resampler backends.
@ ResamplerBackend_Builtin
Built-in resampler. High precision, high quality, slow.
@ ResamplerBackend_Default
Default backend. Resolved to one of other backends, depending on what is enabled at build time.
@ ChanLayout_Surround
Multi-channel mono / stereo / surround sound.
Definition: channel_defs.h:35
@ FreqEstimatorProfile_Responsive
Fast and responsive tuning. Good for lower network latency and jitter.
ResamplerProfile
Resampler parameters presets.
@ ResamplerProfile_Medium
Medium quality, medium speed.
@ ChanOrder_Smpte
ITU/SMPTE channel order. Order: FL, FR, FC, LFE, BL, BR, BC, SL, SR, TFL, TFR, TBL,...
Definition: channel_defs.h:66
const nanoseconds_t Millisecond
One millisecond represented in nanoseconds.
Definition: time.h:67
const nanoseconds_t Microsecond
One microsecond represented in nanoseconds.
Definition: time.h:64
int64_t nanoseconds_t
Nanoseconds.
Definition: time.h:58
const core::nanoseconds_t DefaultPacketLength
Default packet length.
Definition: config.h:49
const core::nanoseconds_t DefaultLatency
Default latency.
Definition: config.h:55
const size_t DefaultSampleRate
Default sample rate, number of samples per second.
Definition: config.h:37
@ PayloadType_L16_Stereo
Audio, 16-bit samples, 2 channels, 44100 Hz.
Definition: headers.h:30
Root namespace.
Profiler.
Protocol ID.
FEC reader.
Resampler backend.
Resampler map.
Resampler profile.
RTP headers.
Sample specifications.
Commonly used types and functions.
Parameters for latency monitor.
void deduce_latency_tolerance(core::nanoseconds_t target_latency)
Automatically deduce latency_tolerance from target_latency.
FreqEstimatorProfile fe_profile
FreqEstimator profile.
bool fe_enable
Enable FreqEstimator.
Profiler Configuration Parameters. Controls profiling interval and duration of each circular buffer c...
Definition: profiler.h:30
Watchdog parameters.
Definition: watchdog.h:28
void deduce_no_playback_timeout(core::nanoseconds_t target_latency)
Automatically deduce no_playback_timeout from target_latency.
Definition: watchdog.h:65
FEC codec parameters.
Definition: codec_config.h:22
FEC reader parameters.
Definition: reader.h:30
FEC writer parameters.
Definition: writer.h:30
Receiver common parameters.
Definition: config.h:209
bool enable_auto_reclock
Automatically invoke reclock before returning frames with invocation time.
Definition: config.h:217
bool enable_beeping
Insert weird beeps instead of silence on packet loss.
Definition: config.h:226
bool enable_profiling
Profile moving average of frames being written.
Definition: config.h:220
bool enable_timing
Constrain receiver speed using a CPU timer according to the sample rate.
Definition: config.h:214
audio::SampleSpec output_sample_spec
Output sample spec.
Definition: config.h:211
audio::ProfilerConfig profiler_config
Profiler configuration.
Definition: config.h:223
Receiver parameters.
Definition: config.h:238
TaskConfig tasks
Task processing parameters.
Definition: config.h:246
ReceiverCommonConfig common
Parameters common for all sessions.
Definition: config.h:243
ReceiverSessionConfig default_session
Default parameters for receiver session.
Definition: config.h:240
Receiver session parameters.
Definition: config.h:158
core::nanoseconds_t target_latency
Target latency, nanoseconds.
Definition: config.h:160
audio::LatencyMonitorConfig latency_monitor
LatencyMonitor parameters.
Definition: config.h:175
fec::ReaderConfig fec_reader
FEC reader parameters.
Definition: config.h:166
audio::ResamplerBackend resampler_backend
To specify which resampling backend will be used.
Definition: config.h:181
unsigned int payload_type
Packet payload type.
Definition: config.h:163
audio::ResamplerProfile resampler_profile
Resampler profile.
Definition: config.h:184
void deduce_resampler_backend()
Automatically deduce resampler backend from FreqEstimator config.
Definition: config.h:196
fec::CodecConfig fec_decoder
FEC decoder parameters.
Definition: config.h:169
rtp::ValidatorConfig rtp_validator
RTP validator parameters.
Definition: config.h:172
audio::WatchdogConfig watchdog
Watchdog parameters.
Definition: config.h:178
Sender parameters.
Definition: config.h:102
audio::SampleSpec input_sample_spec
Input sample spec.
Definition: config.h:119
bool enable_auto_cts
Automatically fill capture timestamps of input frames with invocation time.
Definition: config.h:134
TaskConfig tasks
Task processing parameters.
Definition: config.h:104
audio::ProfilerConfig profiler_config
Profiler configuration.
Definition: config.h:140
bool enable_interleaving
Interleave packets.
Definition: config.h:128
core::nanoseconds_t packet_length
Packet length, in nanoseconds.
Definition: config.h:122
bool enable_profiling
Profile moving average of frames being written.
Definition: config.h:137
audio::ResamplerProfile resampler_profile
Resampler profile.
Definition: config.h:110
audio::ResamplerBackend resampler_backend
To specify which resampling backend will be used.
Definition: config.h:107
fec::CodecConfig fec_encoder
FEC encoder parameters.
Definition: config.h:116
fec::WriterConfig fec_writer
FEC writer parameters.
Definition: config.h:113
unsigned payload_type
RTP payload type for audio packets.
Definition: config.h:125
bool enable_timing
Constrain receiver speed using a CPU timer according to the sample rate.
Definition: config.h:131
Task processing parameters.
Definition: config.h:58
core::nanoseconds_t task_processing_prohibited_interval
Time interval during which no task processing is allowed. This setting is used to prohibit task proce...
Definition: config.h:90
bool enable_precise_task_scheduling
Enable precise task scheduling mode (default). The other settings have effect only when this is set t...
Definition: config.h:64
core::nanoseconds_t max_inframe_task_processing
Mximum task processing duration happening immediatelly after processing a frame. If this period expir...
Definition: config.h:83
core::nanoseconds_t max_frame_length_between_tasks
Maximum frame duration between processing tasks. If the frame is larger than this size,...
Definition: config.h:76
core::nanoseconds_t min_frame_length_between_tasks
Minimum frame duration between processing tasks. In-frame task processing does not happen until at le...
Definition: config.h:70
Converter parameters.
Definition: config.h:250
audio::SampleSpec input_sample_spec
Input sample spec.
Definition: config.h:258
audio::SampleSpec output_sample_spec
Output sample spec.
Definition: config.h:261
audio::ResamplerBackend resampler_backend
To specify which resampling backend will be used.
Definition: config.h:252
bool enable_profiling
Profile moving average of frames being written.
Definition: config.h:264
audio::ProfilerConfig profiler_config
Profiler configuration.
Definition: config.h:267
audio::ResamplerProfile resampler_profile
Resampler profile.
Definition: config.h:255
Validator parameters.
Definition: validator.h:24
Time definitions.
Various units used in packets.
RTP validator.
Watchdog.
FEC writer.