From dd1151f7bc74538954720f60ca53cb04fb368292 Mon Sep 17 00:00:00 2001 From: Victor Gaydov Date: Wed, 7 Aug 2024 20:07:03 +0400 Subject: [PATCH] chore: Cosmetic fixes in roc_sndio --- src/internal_modules/roc_sndio/pump.cpp | 31 +++++++++++++------ src/internal_modules/roc_sndio/pump.h | 1 + .../target_sndfile/roc_sndio/sndfile_sink.cpp | 4 +++ src/internal_modules/roc_sndio/wav_sink.cpp | 4 +++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/internal_modules/roc_sndio/pump.cpp b/src/internal_modules/roc_sndio/pump.cpp index f7b754f71..9f857c385 100644 --- a/src/internal_modules/roc_sndio/pump.cpp +++ b/src/internal_modules/roc_sndio/pump.cpp @@ -65,25 +65,25 @@ status::StatusCode Pump::run() { } } - roc_panic_if_msg(code <= status::NoStatus || code >= status::MaxStatus, - "pump: invalid status code %d", code); - if (code == status::StatusFinish) { code = status::StatusOK; // EOF is fine } + if (code == status::StatusOK) { - code = sink_.flush(); - if (code != status::StatusOK) { - roc_log(LogError, "pump: got error when flushing sink: status=%s", - status::code_to_str(code)); - } + code = flush_sink_(); } - status::StatusCode close_code = close_all_devices_(); + const status::StatusCode close_code = close_all_devices_(); + if (code == status::StatusOK) { + code = close_code; + } roc_log(LogDebug, "pump: exiting main loop"); - return (code != status::StatusOK) ? code : close_code; + roc_panic_if_msg(code <= status::NoStatus || code >= status::MaxStatus, + "pump: invalid status code %d", code); + + return code; } void Pump::stop() { @@ -282,6 +282,17 @@ status::StatusCode Pump::transfer_frame_(ISource& source, ISink& sink) { return status::StatusOK; } +status::StatusCode Pump::flush_sink_() { + const status::StatusCode code = sink_.flush(); + + if (code != status::StatusOK) { + roc_log(LogError, "pump: got error when flushing sink: status=%s", + status::code_to_str(code)); + } + + return code; +} + status::StatusCode Pump::close_all_devices_() { IDevice* devices[] = { &main_source_, &sink_, backup_source_ }; status::StatusCode first_error = status::StatusOK; diff --git a/src/internal_modules/roc_sndio/pump.h b/src/internal_modules/roc_sndio/pump.h index bfb9593a2..15a67fdc2 100644 --- a/src/internal_modules/roc_sndio/pump.h +++ b/src/internal_modules/roc_sndio/pump.h @@ -70,6 +70,7 @@ class Pump : public core::NonCopyable<> { status::StatusCode next_(); status::StatusCode switch_source_(ISource* new_source); status::StatusCode transfer_frame_(ISource& source, ISink& sink); + status::StatusCode flush_sink_(); status::StatusCode close_all_devices_(); audio::FrameFactory frame_factory_; diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.cpp b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.cpp index 25115e349..b9f8b023c 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.cpp +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.cpp @@ -251,6 +251,10 @@ status::StatusCode SndfileSink::write(audio::Frame& frame) { } status::StatusCode SndfileSink::flush() { + if (!file_) { + roc_panic("sndfile sink: not opened"); + } + return status::StatusOK; } diff --git a/src/internal_modules/roc_sndio/wav_sink.cpp b/src/internal_modules/roc_sndio/wav_sink.cpp index ded8855bd..c78ca74c6 100644 --- a/src/internal_modules/roc_sndio/wav_sink.cpp +++ b/src/internal_modules/roc_sndio/wav_sink.cpp @@ -145,6 +145,10 @@ status::StatusCode WavSink::write(audio::Frame& frame) { } status::StatusCode WavSink::flush() { + if (!output_file_) { + roc_panic("wav sink: not opened"); + } + return status::StatusOK; }