Skip to content

Commit

Permalink
[cli] roc-streaminggh-608: Rework CLI options
Browse files Browse the repository at this point in the history
New options:

- Add --packet-encoding to roc-send and roc-recv.
- Add --fec-encoding to roc-send.
- Add --miface to roc-send.

Rename options:

- Rename --nbsrc/--nbrpr to --fec-block-src/--fec-block-rpr.
- Rename --frame-len to --io-frame-len.
- Rename --profile to --prof.

Improvements:

- Group options into sections.
- Update --help messages.

Refactoring:

- Split main() into smaller function.
- Hide sox frame size configuration inside sox backend.
  • Loading branch information
gavv committed Aug 22, 2024
1 parent c387bb0 commit b7fb866
Show file tree
Hide file tree
Showing 14 changed files with 1,002 additions and 683 deletions.
5 changes: 1 addition & 4 deletions src/internal_modules/roc_pipeline/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@
namespace roc {
namespace pipeline {

//! Default sample rate, number of samples per second.
const size_t DefaultSampleRate = 44100;

//! Default sample specification.
static const audio::SampleSpec DefaultSampleSpec(DefaultSampleRate,
static const audio::SampleSpec DefaultSampleSpec(44100,
audio::Sample_RawFormat,
audio::ChanLayout_Surround,
audio::ChanOrder_Smpte,
Expand Down
10 changes: 0 additions & 10 deletions src/internal_modules/roc_sndio/backend_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ const DriverInfo& BackendMap::nth_driver(size_t driver_index) const {
return drivers_[driver_index];
}

void BackendMap::set_frame_size(core::nanoseconds_t frame_length,
const audio::SampleSpec& sample_spec) {
#ifdef ROC_TARGET_SOX
sox_backend_->set_frame_size(frame_length, sample_spec);
#endif // ROC_TARGET_SOX

(void)frame_length;
(void)sample_spec;
}

void BackendMap::register_backends_() {
#ifdef ROC_TARGET_PULSEAUDIO
pulseaudio_backend_.reset(new (pulseaudio_backend_) PulseaudioBackend);
Expand Down
4 changes: 0 additions & 4 deletions src/internal_modules/roc_sndio/backend_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ class BackendMap : public core::NonCopyable<> {
//! Get driver by index.
const DriverInfo& nth_driver(size_t driver_index) const;

//! Set internal buffer size for all backends that need it.
void set_frame_size(core::nanoseconds_t frame_length,
const audio::SampleSpec& sample_spec);

private:
friend class core::Singleton<BackendMap>;

Expand Down
12 changes: 7 additions & 5 deletions src/internal_modules/roc_sndio/io_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace roc {
namespace sndio {

//! Default frame length.
//! @remarks
//! 10ms is rather high, but works well even on cheap sound cards and CPUs.
//! Usually you can use much lower values.
const core::nanoseconds_t DefaultFrameLength = 10 * core::Millisecond;
Expand All @@ -30,16 +31,17 @@ struct IoConfig {
//! Sample spec
audio::SampleSpec sample_spec;

//! Duration of the internal frames, in nanoseconds.
core::nanoseconds_t frame_length;

//! Requested input or output latency.
core::nanoseconds_t latency;

//! Duration of the internal frames, in nanoseconds.
core::nanoseconds_t frame_length;

//! Initialize.
IoConfig()
: frame_length(DefaultFrameLength)
, latency(0) {
: sample_spec()
, latency(0)
, frame_length(DefaultFrameLength) {
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,6 @@ SoxBackend::SoxBackend()
sox_get_globals()->output_message_handler = log_handler;
}

void SoxBackend::set_frame_size(core::nanoseconds_t frame_length,
const audio::SampleSpec& sample_spec) {
size_t size = sample_spec.ns_2_samples_overall(frame_length);

if (first_created_) {
roc_panic(
"sox backend:"
" set_frame_size() can be called only before creating first source or sink");
}

sox_get_globals()->bufsiz = size * sizeof(sox_sample_t);
}

const char* SoxBackend::name() const {
return "sox";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ class SoxBackend : public IBackend, core::NonCopyable<> {
public:
SoxBackend();

//! Set internal SoX frame size.
//! @remarks
//! Number of samples for all channels.
void set_frame_size(core::nanoseconds_t frame_length,
const audio::SampleSpec& sample_spec);

//! Returns name of backend.
virtual const char* name() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ SoxSink::SoxSink(audio::FrameFactory& frame_factory,
return;
}

{
audio::SampleSpec spec = sample_spec_;
spec.use_defaults(audio::Sample_RawFormat, audio::ChanLayout_Surround,
audio::ChanOrder_Smpte, audio::ChanMask_Surround_Stereo, 44100);

sox_get_globals()->bufsiz =
spec.ns_2_samples_overall(frame_length_) * sizeof(sox_sample_t);
}

memset(&out_signal_, 0, sizeof(out_signal_));
out_signal_.rate = (sox_rate_t)sample_spec_.sample_rate();
out_signal_.channels = (unsigned)sample_spec_.num_channels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ SoxSource::SoxSource(audio::FrameFactory& frame_factory,
return;
}

{
audio::SampleSpec spec = sample_spec_;
spec.use_defaults(audio::Sample_RawFormat, audio::ChanLayout_Surround,
audio::ChanOrder_Smpte, audio::ChanMask_Surround_Stereo, 44100);

sox_get_globals()->bufsiz =
spec.ns_2_samples_overall(frame_length_) * sizeof(sox_sample_t);
}

memset(&in_signal_, 0, sizeof(in_signal_));
in_signal_.rate = (sox_rate_t)sample_spec_.sample_rate();
in_signal_.channels = (unsigned)sample_spec_.num_channels();
Expand Down
36 changes: 20 additions & 16 deletions src/tools/roc_copy/cmdline.ggo
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
package "roc-copy"
usage "roc-copy OPTIONS"

section "Options"
section "General options"

option "verbose" v "Increase verbosity level (may be used multiple times)"
multiple optional
option "color" - "Set colored logging mode for stderr output"
values="auto","always","never" default="auto" enum optional

option "list-supported" L "list supported schemes and formats" optional
option "list-supported" L "List supported protocols, formats, etc." optional

option "input" i "Input file URI" typestr="FILE_URI" string required
option "output" o "Output file URI" typestr="FILE_URI" string optional
section "I/O options"

option "input" i "Input file URI" typestr="FILE_URI" string optional
option "input-format" - "Force input file format" typestr="FILE_FORMAT" string optional

option "output" o "Output file URI" typestr="FILE_URI" string optional
option "output-format" - "Force output file format" typestr="FILE_FORMAT" string optional
option "output-encoding" - "Output file encoding" typestr="IO_ENCODING" string optional

option "frame-len" - "Duration of the internal frames, TIME units"
typestr="TIME" string optional
option "io-frame-len" - "I/O frame length, TIME units" typestr="TIME" string optional

option "output-encoding" - "Output file encoding"
typestr="IO_ENCODING" string optional
section "Transcoding options"

option "resampler-backend" - "Resampler backend"
values="default","builtin","speex","speexdec" default="default" enum optional

option "resampler-profile" - "Resampler profile"
values="low","medium","high" default="medium" enum optional

option "profile" - "Enable self profiling" flag off
section "Debugging options"

option "color" - "Set colored logging mode for stderr output"
values="auto","always","never" default="auto" enum optional
option "prof" - "Enable self-profiling" flag off

text "
FILE_URI defines an absolute or relative file path, e.g.:
file:///home/user/test.wav; file:./test.wav; file:-
(use 'file://-' for stdout)

FILE_FORMAT is the output file format name, e.g.:
FILE_FORMAT is file format name:
wav; ogg; mp3
(useful when format can't be auto-detected)

IO_ENCODING is input or output format/rate/channels, e.g.:
s16/44100/mono; f32/48000/stereo
IO_ENCODING is input or output encoding in form <format>/<rate>/<channels>:
s16/44100/mono; f32/48000/stereo; -/-/mono
(any component may be '-' to use default value)

TIME is an integer or floating-point number with a suffix, e.g.:
TIME defines duration using a number with mandatory suffix:
123ns; 1.23us; 1.23ms; 1.23s; 1.23m; 1.23h;

Use --list-supported option to print the list of the supported
Expand Down
Loading

0 comments on commit b7fb866

Please sign in to comment.