Skip to content

Commit

Permalink
roc-streaminggh-608 Improve --print-supported
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Nov 19, 2023
1 parent feb5af9 commit 5ed273f
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/internal_modules/roc_address/print_supported.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void print_interface_protos(core::Printer& prn,

size_t size = 0;

prn.writef(" %s:", interface_to_str(interface));
prn.writef(" %-12s ", interface_to_str(interface));

while (size < LineSize) {
size += prn.writef(" %s%s%s", "", str, "://");
Expand All @@ -45,24 +45,25 @@ void print_interface_protos(core::Printer& prn,

} // namespace

bool print_supported(ProtocolMap& protocol_map, core::IArena& arena) {
bool print_supported(core::IArena& arena) {
core::Printer prn;
core::Array<Interface> interface_array(arena);
core::StringList list(arena);

if (!protocol_map.get_supported_interfaces(interface_array)) {
if (!address::ProtocolMap::instance().get_supported_interfaces(interface_array)) {
roc_log(LogError, "can't retrieve interface array");
return false;
}

for (size_t n_interface = 0; n_interface < interface_array.size(); n_interface++) {
if (!protocol_map.get_supported_protocols(interface_array[n_interface], list)) {
if (!address::ProtocolMap::instance().get_supported_protocols(
interface_array[n_interface], list)) {
roc_log(LogError, "can't retrieve protocols list");
return false;
}

if (n_interface == 0) {
prn.writef("\nsupported network protocols:\n");
prn.writef("supported schemes for network endpoints:\n");
}

print_interface_protos(prn, interface_array[n_interface], list);
Expand Down
3 changes: 1 addition & 2 deletions src/internal_modules/roc_address/print_supported.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
#ifndef ROC_ADDRESS_PRINT_SUPPORTED_H_
#define ROC_ADDRESS_PRINT_SUPPORTED_H_

#include "roc_address/protocol_map.h"
#include "roc_core/attributes.h"
#include "roc_core/iarena.h"

namespace roc {
namespace address {

//! Print supported interfaces and protocols.
ROC_ATTR_NODISCARD bool print_supported(ProtocolMap&, core::IArena&);
ROC_ATTR_NODISCARD bool print_supported(core::IArena&);

} // namespace address
} // namespace roc
Expand Down
104 changes: 104 additions & 0 deletions src/internal_modules/roc_audio/print_supported.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2023 Roc Streaming authors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include "roc_audio/print_supported.h"
#include "roc_audio/channel_defs.h"
#include "roc_audio/channel_tables.h"
#include "roc_audio/pcm_format.h"
#include "roc_core/macro_helpers.h"
#include "roc_core/printer.h"

namespace roc {
namespace audio {

namespace {

void print_pcm_codes(core::Printer& prn) {
PcmTraits prev_traits, curr_traits;

for (int code = 0; code < PcmCode_Max; code++) {
for (int endian = 0; endian < PcmEndian_Max; endian++) {
PcmFormat fmt;
fmt.code = (PcmCode)code;
fmt.endian = (PcmEndian)endian;

curr_traits = pcm_format_traits(fmt);

if (prev_traits.bit_depth != curr_traits.bit_depth
|| prev_traits.bit_width != curr_traits.bit_width) {
if (curr_traits.bit_width % 8 == 0) {
prn.writef("\n %2d bit (%d byte) ", (int)curr_traits.bit_depth,
(int)curr_traits.bit_width / 8);
} else {
prn.writef("\n %d bit (%.2f byte) ", (int)curr_traits.bit_depth,
(double)curr_traits.bit_width / 8.);
}
}

prev_traits = curr_traits;

prn.writef(" %s", pcm_format_to_str(fmt));
}
}
}

void print_channel_names(core::Printer& prn) {
prn.writef(" front FL FR FC\n");
prn.writef(" side SL SR\n");
prn.writef(" back BL BR BC\n");
prn.writef(" top front TFL TFR\n");
prn.writef(" top mid TML TMR\n");
prn.writef(" top back TBL TBR\n");
prn.writef(" low freq LFE\n");
}

void print_channel_mask(core::Printer& prn, ChannelMask ch_mask) {
prn.writef(" %-13s (", channel_mask_to_str(ch_mask));

bool first = true;

for (int ch = 0; ch < ChanPos_Max; ch++) {
if (ch_mask & (1 << ch)) {
if (!first) {
prn.writef(" ");
}
first = false;
prn.writef("%s", channel_pos_to_str((ChannelPosition)ch));
}
}

prn.writef(")\n");
}

} // namespace

bool print_supported() {
core::Printer prn;

prn.writef("\nsupported formats for audio devices:\n");
prn.writef(" pcm\n");

prn.writef("\nsupported formats for network packets:\n");
prn.writef(" pcm\n");

prn.writef("\nsupported pcm codes:");
print_pcm_codes(prn);

prn.writef("\n\nsupported channel names:\n");
print_channel_names(prn);

prn.writef("\npre-defined channel masks:\n");
for (size_t i = 0; i < ROC_ARRAY_SIZE(ChanMaskNames); i++) {
print_channel_mask(prn, ChanMaskNames[i].mask);
}

return true;
}

} // namespace audio
} // namespace roc
26 changes: 26 additions & 0 deletions src/internal_modules/roc_audio/print_supported.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 Roc Streaming authors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

//! @file roc_audio/print_supported.h
//! @brief Print supported encodings.

#ifndef ROC_AUDIO_PRINT_SUPPORTED_H_
#define ROC_AUDIO_PRINT_SUPPORTED_H_

#include "roc_core/attributes.h"

namespace roc {
namespace audio {

//! Print supported encodings.
ROC_ATTR_NODISCARD bool print_supported();

} // namespace audio
} // namespace roc

#endif // ROC_AUDIO_PRINT_SUPPORTED_H_
2 changes: 1 addition & 1 deletion src/internal_modules/roc_sndio/print_supported.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool print_supported(BackendDispatcher& backend_dispatcher, core::IArena& arena)
return false;
}

prn.writef("supported schemes for audio devices and files:\n");
prn.writef("\nsupported schemes for audio devices and files:\n");
print_string_list(prn, list, "", "://");

if (!backend_dispatcher.get_supported_formats(list)) {
Expand Down
5 changes: 2 additions & 3 deletions src/tools/roc_recv/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ int main(int argc, char** argv) {
sndio::BackendDispatcher backend_dispatcher(context.arena());

if (args.list_supported_given) {
if (!sndio::print_supported(backend_dispatcher, context.arena())) {
if (!address::print_supported(context.arena())) {
return 1;
}

if (!address::print_supported(address::ProtocolMap::instance(),
context.arena())) {
if (!sndio::print_supported(backend_dispatcher, context.arena())) {
return 1;
}

Expand Down
3 changes: 1 addition & 2 deletions src/tools/roc_send/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ int main(int argc, char** argv) {
return 1;
}

if (!address::print_supported(address::ProtocolMap::instance(),
context.arena())) {
if (!address::print_supported(context.arena())) {
return 1;
}

Expand Down

0 comments on commit 5ed273f

Please sign in to comment.