Skip to content

Commit

Permalink
Add new options to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed May 2, 2024
1 parent ec53e84 commit b2f3ac8
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 73 deletions.
1 change: 1 addition & 0 deletions tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_executable(${TOOL_NAME}
cmd_uninstall.cpp
connector.cpp
format.cpp
help_formatter.cpp
main.cpp
parse.cpp
print.cpp
Expand Down
208 changes: 178 additions & 30 deletions tool/cmd_device_add_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,86 @@ CmdDeviceAddReceiver::CmdDeviceAddReceiver(CLI::App& parent)
{
auto command = parent.add_subcommand("receiver", "Add receiver virtual device");

command->add_option("-u,--uid", uid_, "Device UID (omit to auto-generate)");
command->add_option("-u,--uid", device_uid_, "Device UID (omit to auto-generate)");
command->add_option(
"-n,--name", name_, "Human-readable device name (omit to auto-generate)");
"-n,--name", device_name_, "Human-readable device name (omit to auto-generate)");

command->add_option(
"-r,--rate", rate_, "Sample rate for virtual device, in hertz (e.g. 44100)");
command->add_option("-c,--chans",
chans_,
// device_encoding
auto device_encoding_opts = command->add_option_group("Device encoding");

device_encoding_opts->add_option("-r,--device-rate",
device_encoding_rate_,
"Sample rate for virtual device, in hertz (e.g. 44100)");
device_encoding_opts->add_option("-c,--device-chans",
device_encoding_chans_,
fmt::format("Channel set for virtual device (supported values: {})",
supported_enum_values(channel_layout_map)));

command->add_option("--target-latency",
target_latency_,
fmt::format("Receiver target latency (number with one of the suffixes: {})",
supported_duration_suffixes()));
// packet_encoding
auto packet_encoding_opts = command->add_option_group("Packet encoding");

command->add_option("--resampler-backend",
packet_encoding_opts->add_option("--packet-encoding-id",
packet_encoding_id_,
"Unique identifier to use for packet encoding");
packet_encoding_opts->add_option("--packet-encoding-rate",
packet_encoding_rate_,
"Sample rate to use for packet encoding");
packet_encoding_opts->add_option("--packet-encoding-format",
packet_encoding_format_,
fmt::format("Sample format to use for packet encoding (supported values: {})",
supported_enum_values(sample_format_map)));
packet_encoding_opts->add_option("--packet-encoding-chans",
packet_encoding_chans_,
fmt::format("Channel layout to use for packet encoding (supported values: {})",
supported_enum_values(channel_layout_map)));

// resampler
auto resampler_opts = command->add_option_group("Resampler");

resampler_opts->add_option("--resampler-backend",
resampler_backend_,
fmt::format("Receiver resampler backend (supported values: {})",
fmt::format("Resampler backend (supported values: {})",
supported_enum_values(resampler_backend_map)));
command->add_option("--resampler-profile",
resampler_opts->add_option("--resampler-profile",
resampler_profile_,
fmt::format("Receiver resampler profile (supported values: {})",
fmt::format("Resampler profile (supported values: {})",
supported_enum_values(resampler_profile_map)));

// latency_tuner
auto latency_tuner_opts = command->add_option_group("Latency tuner");

latency_tuner_opts->add_option("--latency-backend",
latency_tuner_backend_,
fmt::format("Latency tuner backend (supported values: {})",
supported_enum_values(latency_tuner_backend_map)));
latency_tuner_opts->add_option("--latency-profile",
latency_tuner_profile_,
fmt::format("Latency tuner profile (supported values: {})",
supported_enum_values(latency_tuner_profile_map)));

// latency
auto latency_opts = command->add_option_group("Latency");

latency_opts->add_option("--target-latency",
target_latency_,
fmt::format("Target latency (number with one of the suffixes: {})",
supported_duration_suffixes()));
latency_opts->add_option(
"--min-latency", min_latency_, "Minimum latency (same format)");
latency_opts->add_option(
"--max-latency", max_latency_, "Maximum latency (same format)");

// timeouts
auto timeouts_opts = command->add_option_group("Timeouts");

timeouts_opts->add_option("--no-play-timeout",
no_playback_timeout_,
fmt::format("No playback timeout (number with one of the suffixes: {})",
supported_duration_suffixes()));
timeouts_opts->add_option("--choppy-play-timeout",
choppy_playback_timeout_,
"Choppy playback timeout (same format)");

register_command(command);
}

Expand All @@ -63,36 +118,67 @@ bool CmdDeviceAddReceiver::execute(const Environment& env)
rvpb::RvDeviceInfo request;
rvpb::RvDeviceInfo response;

// device
request.set_type(rvpb::RV_DEVICE_TYPE_RECEIVER);

if (uid_) {
request.set_uid(*uid_);
if (device_uid_) {
request.set_uid(*device_uid_);
}

if (name_) {
request.set_name(*name_);
if (device_name_) {
request.set_name(*device_name_);
}

if (rate_) {
request.mutable_device_encoding()->set_sample_rate(*rate_);
// device_encoding
if (device_encoding_rate_) {
request.mutable_device_encoding()->set_sample_rate(*device_encoding_rate_);
}

if (chans_) {
if (device_encoding_chans_) {
rvpb::RvChannelLayout channel_layout;
if (!parse_enum("--chans", channel_layout_map, *chans_, channel_layout)) {
if (!parse_enum("--device-chans",
channel_layout_map,
*device_encoding_chans_,
channel_layout)) {
return false;
}
request.mutable_device_encoding()->set_channel_layout(channel_layout);
}

if (target_latency_) {
if (!parse_duration("--target-latency",
*target_latency_,
*request.mutable_receiver_config()->mutable_target_latency())) {
return false;
// packet_encoding
if (packet_encoding_id_ || packet_encoding_rate_ || packet_encoding_format_ ||
packet_encoding_chans_) {
rvpb::RvPacketEncoding packet_encoding;

if (packet_encoding_id_) {
packet_encoding.set_encoding_id(*packet_encoding_id_);
}
if (packet_encoding_rate_) {
packet_encoding.set_sample_rate(*packet_encoding_rate_);
}
if (packet_encoding_format_) {
rvpb::RvSampleFormat sample_format;
if (!parse_enum("--packet-encoding-format",
sample_format_map,
*packet_encoding_format_,
sample_format)) {
return false;
}
packet_encoding.set_sample_format(sample_format);
}
if (packet_encoding_chans_) {
rvpb::RvChannelLayout channel_layout;
if (!parse_enum("--packet-encoding-chans",
channel_layout_map,
*packet_encoding_chans_,
channel_layout)) {
return false;
}
packet_encoding.set_channel_layout(channel_layout);
}

*request.mutable_receiver_config()->add_packet_encodings() = packet_encoding;
}

// resampler
if (resampler_backend_) {
rvpb::RvResamplerBackend resampler_backend;
if (!parse_enum("--resampler-backend",
Expand All @@ -103,7 +189,6 @@ bool CmdDeviceAddReceiver::execute(const Environment& env)
}
request.mutable_receiver_config()->set_resampler_backend(resampler_backend);
}

if (resampler_profile_) {
rvpb::RvResamplerProfile resampler_profile;
if (!parse_enum("--resampler-profile",
Expand All @@ -115,6 +200,69 @@ bool CmdDeviceAddReceiver::execute(const Environment& env)
request.mutable_receiver_config()->set_resampler_profile(resampler_profile);
}

// latency_tuner
if (latency_tuner_backend_) {
rvpb::RvLatencyTunerBackend latency_tuner_backend;
if (!parse_enum("--latency-backend",
latency_tuner_backend_map,
*latency_tuner_backend_,
latency_tuner_backend)) {
return false;
}
request.mutable_receiver_config()->set_latency_tuner_backend(
latency_tuner_backend);
}
if (latency_tuner_profile_) {
rvpb::RvLatencyTunerProfile latency_tuner_profile;
if (!parse_enum("--latency-profile",
latency_tuner_profile_map,
*latency_tuner_profile_,
latency_tuner_profile)) {
return false;
}
request.mutable_receiver_config()->set_latency_tuner_profile(
latency_tuner_profile);
}

// latency
if (target_latency_) {
if (!parse_duration("--target-latency",
*target_latency_,
*request.mutable_receiver_config()->mutable_target_latency())) {
return false;
}
}
if (min_latency_) {
if (!parse_duration("--min-latency",
*min_latency_,
*request.mutable_receiver_config()->mutable_min_latency())) {
return false;
}
}
if (max_latency_) {
if (!parse_duration("--max-latency",
*max_latency_,
*request.mutable_receiver_config()->mutable_max_latency())) {
return false;
}
}

// timeouts
if (no_playback_timeout_) {
if (!parse_duration("--no-play-timeout",
*no_playback_timeout_,
*request.mutable_receiver_config()->mutable_no_playback_timeout())) {
return false;
}
}
if (choppy_playback_timeout_) {
if (!parse_duration("--choppy-play-timeout",
*choppy_playback_timeout_,
*request.mutable_receiver_config()->mutable_choppy_playback_timeout())) {
return false;
}
}

const grpc::Status status = stub->add_device(&context, request, &response);

if (!status.ok()) {
Expand Down
23 changes: 18 additions & 5 deletions tool/cmd_device_add_receiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,29 @@ class CmdDeviceAddReceiver : public CmdBase
bool execute(const Environment& env) override;

private:
std::optional<std::string> uid_;
std::optional<std::string> name_;
std::optional<std::string> device_uid_;
std::optional<std::string> device_name_;

std::optional<uint32_t> rate_;
std::optional<std::string> chans_;
std::optional<uint32_t> device_encoding_rate_;
std::optional<std::string> device_encoding_chans_;

std::optional<std::string> target_latency_;
std::optional<uint8_t> packet_encoding_id_;
std::optional<uint32_t> packet_encoding_rate_;
std::optional<std::string> packet_encoding_format_;
std::optional<std::string> packet_encoding_chans_;

std::optional<std::string> resampler_backend_;
std::optional<std::string> resampler_profile_;

std::optional<std::string> latency_tuner_backend_;
std::optional<std::string> latency_tuner_profile_;

std::optional<std::string> target_latency_;
std::optional<std::string> min_latency_;
std::optional<std::string> max_latency_;

std::optional<std::string> no_playback_timeout_;
std::optional<std::string> choppy_playback_timeout_;
};

} // namespace rocvad
Loading

0 comments on commit b2f3ac8

Please sign in to comment.