Skip to content

Commit

Permalink
chore: Cosmetic fixes in roc_sndio
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Aug 7, 2024
1 parent bb07c4d commit dd1151f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/internal_modules/roc_sndio/pump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/internal_modules/roc_sndio/pump.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/internal_modules/roc_sndio/wav_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit dd1151f

Please sign in to comment.