Skip to content

Commit

Permalink
roc-streaminggh-608: Rename pcm_format to pcm_subformat
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Sep 11, 2024
1 parent bfbf13f commit 1db4d30
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 93 deletions.
6 changes: 3 additions & 3 deletions src/internal_modules/roc_sndio/io_pump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ IoPump::IoPump(core::IPool& frame_pool,
, stop_(0)
, transferred_bytes_(0)
, init_status_(status::NoStatus) {
if (!io_config.sample_spec.is_complete()) {
roc_panic("io pump: expected complete sample spec: spec=%s",
if (!io_config.sample_spec.is_complete() || !io_config.sample_spec.is_pcm()) {
roc_panic("io pump: required complete sample spec with pcm format: spec=%s",
audio::sample_spec_to_str(io_config.sample_spec).c_str());
}

Expand Down Expand Up @@ -83,7 +83,7 @@ status::StatusCode IoPump::run() {
// EOF is fine
code = status::StatusOK;
roc_log(LogDebug, "io pump: transferred %.3f MB",
(double)transferred_bytes_ / 1024 * 1024);
(double)transferred_bytes_ / 1024 / 1024);
}

if (code == status::StatusOK) {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/roc_sndio/test_helpers/mock_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace test {

class MockSource : public ISource {
public:
MockSource(audio::FrameFactory& frame_factory,
const audio::SampleSpec& sample_spec,
MockSource(const audio::SampleSpec& sample_spec,
audio::FrameFactory& frame_factory,
core::IArena& arena)
: IDevice(arena)
, ISource(arena)
Expand Down
70 changes: 38 additions & 32 deletions src/tests/roc_sndio/test_io_pump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ namespace sndio {

namespace {

enum { FrameSize = 512, SampleRate = 48000 };
enum { FrameSize = 512, ManySamples = FrameSize * 10 };

const audio::SampleSpec sample_spec(SampleRate,
audio::PcmSubformat_Raw,
audio::ChanLayout_Surround,
audio::ChanOrder_Smpte,
audio::ChanMask_Surround_Stereo);
const audio::SampleSpec frame_spec(48000,
audio::PcmSubformat_Raw,
audio::ChanLayout_Surround,
audio::ChanOrder_Smpte,
audio::ChanMask_Surround_Stereo);

const core::nanoseconds_t frame_duration = FrameSize * core::Second
/ core::nanoseconds_t(sample_spec.sample_rate() * sample_spec.num_channels());
/ core::nanoseconds_t(frame_spec.sample_rate() * frame_spec.num_channels());

core::HeapArena arena;

Expand All @@ -51,19 +51,27 @@ audio::FrameFactory frame_factory(frame_pool, frame_buffer_pool);
TEST_GROUP(io_pump) {
IoConfig source_config;
IoConfig sink_config;
IoConfig pump_config;

void setup() {
audio::SampleSpec file_spec;
file_spec.set_format(audio::Format_Wav);
file_spec.set_pcm_subformat(audio::PcmSubformat_Raw);
file_spec.set_sample_rate(frame_spec.sample_rate());
file_spec.set_channel_set(frame_spec.channel_set());

source_config.sample_spec = audio::SampleSpec();
source_config.frame_length = frame_duration;

sink_config.sample_spec = sample_spec;
sink_config.sample_spec = file_spec;
sink_config.frame_length = frame_duration;

pump_config.sample_spec = frame_spec;
pump_config.frame_length = frame_duration;
}
};

IGNORE_TEST(io_pump, write_read) {
enum { NumSamples = FrameSize * 10 };

TEST(io_pump, write_read) {
for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends();
n_backend++) {
IBackend& backend = BackendMap::instance().nth_backend(n_backend);
Expand All @@ -73,8 +81,8 @@ IGNORE_TEST(io_pump, write_read) {

dbgio::TempFile file("test.wav");

test::MockSource mock_source(frame_factory, sink_config.sample_spec, arena);
mock_source.add(NumSamples);
test::MockSource mock_source(pump_config.sample_spec, frame_factory, arena);
mock_source.add(ManySamples);

{
// open file sink
Expand All @@ -84,11 +92,11 @@ IGNORE_TEST(io_pump, write_read) {

// copy from mock source to file sink
IoPump pump(frame_pool, frame_buffer_pool, mock_source, NULL, *file_sink,
sink_config, IoPump::ModeOneshot);
pump_config, IoPump::ModeOneshot);
LONGS_EQUAL(status::StatusOK, pump.init_status());
LONGS_EQUAL(status::StatusOK, pump.run());

CHECK(mock_source.num_returned() >= NumSamples - FrameSize);
CHECK(mock_source.num_returned() >= ManySamples - FrameSize);
}

// open file source
Expand All @@ -99,7 +107,7 @@ IGNORE_TEST(io_pump, write_read) {
// copy from file source to mock sink
test::MockSink mock_sink(arena);
IoPump pump(frame_pool, frame_buffer_pool, *file_source, NULL, mock_sink,
sink_config, IoPump::ModePermanent);
pump_config, IoPump::ModePermanent);
LONGS_EQUAL(status::StatusOK, pump.init_status());
LONGS_EQUAL(status::StatusOK, pump.run());

Expand All @@ -108,9 +116,7 @@ IGNORE_TEST(io_pump, write_read) {
}
}

IGNORE_TEST(io_pump, write_overwrite_read) {
enum { NumSamples = FrameSize * 10 };

TEST(io_pump, write_overwrite_read) {
for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends();
n_backend++) {
IBackend& backend = BackendMap::instance().nth_backend(n_backend);
Expand All @@ -120,53 +126,53 @@ IGNORE_TEST(io_pump, write_overwrite_read) {

dbgio::TempFile file("test.wav");

test::MockSource mock_source(frame_factory, sink_config.sample_spec, arena);
mock_source.add(NumSamples);
test::MockSource mock_source(pump_config.sample_spec, frame_factory, arena);
mock_source.add(ManySamples);

{
// open file sink
core::ScopedPtr<ISink> file_sink;
test::expect_open_sink(status::StatusOK, backend, frame_factory, arena, "wav",
file.path(), sink_config, file_sink);
test::expect_open_sink(status::StatusOK, backend, frame_factory, arena,
"file", file.path(), sink_config, file_sink);

// copy from mock source to file sink
IoPump pump(frame_pool, frame_buffer_pool, mock_source, NULL, *file_sink,
sink_config, IoPump::ModeOneshot);
pump_config, IoPump::ModeOneshot);
LONGS_EQUAL(status::StatusOK, pump.init_status());
LONGS_EQUAL(status::StatusOK, pump.run());
}

// add more samples to mock source
mock_source.add(NumSamples);
mock_source.add(ManySamples);

size_t num_returned1 = mock_source.num_returned();
CHECK(num_returned1 >= NumSamples - FrameSize);
CHECK(num_returned1 >= ManySamples - FrameSize);

{
// open file sink
core::ScopedPtr<ISink> file_sink;
test::expect_open_sink(status::StatusOK, backend, frame_factory, arena, "wav",
file.path(), sink_config, file_sink);
test::expect_open_sink(status::StatusOK, backend, frame_factory, arena,
"file", file.path(), sink_config, file_sink);

// copy next samples from mock source to file sink, overwriting file
IoPump pump(frame_pool, frame_buffer_pool, mock_source, NULL, *file_sink,
sink_config, IoPump::ModeOneshot);
pump_config, IoPump::ModeOneshot);
LONGS_EQUAL(status::StatusOK, pump.init_status());
LONGS_EQUAL(status::StatusOK, pump.run());
}

size_t num_returned2 = mock_source.num_returned() - num_returned1;
CHECK(num_returned1 >= NumSamples - FrameSize);
CHECK(num_returned1 >= ManySamples - FrameSize);

// open file source
core::ScopedPtr<ISource> file_source;
test::expect_open_source(status::StatusOK, backend, frame_factory, arena, "wav",
test::expect_open_source(status::StatusOK, backend, frame_factory, arena, "file",
file.path(), source_config, file_source);

// copy from file source to mock sink
test::MockSink mock_sink(arena);
IoPump pump(frame_pool, frame_buffer_pool, *file_source, NULL, mock_sink,
sink_config, IoPump::ModePermanent);
pump_config, IoPump::ModePermanent);
LONGS_EQUAL(status::StatusOK, pump.init_status());
LONGS_EQUAL(status::StatusOK, pump.run());

Expand Down
Loading

0 comments on commit 1db4d30

Please sign in to comment.