From b5fec7ca3ebd53196ebc94b98cc2cfec2eb5bdd9 Mon Sep 17 00:00:00 2001 From: Victor Gaydov Date: Sun, 12 May 2024 21:09:50 +0400 Subject: [PATCH] [sp] gh-614 Add status codes to IFrameReader Add status code to IFrameReader::read(), and update implementations of that interface. Sponsored-by: waspd --- .../roc_audio/channel_mapper_reader.cpp | 26 +++++++----- .../roc_audio/channel_mapper_reader.h | 10 ++--- .../roc_audio/depacketizer.cpp | 5 ++- src/internal_modules/roc_audio/depacketizer.h | 2 +- .../roc_audio/iframe_reader.h | 15 ++++--- .../roc_audio/latency_monitor.cpp | 11 ++--- .../roc_audio/latency_monitor.h | 2 +- src/internal_modules/roc_audio/mixer.cpp | 41 ++++++++---------- src/internal_modules/roc_audio/mixer.h | 10 ++--- .../roc_audio/pcm_mapper_reader.cpp | 10 +++-- .../roc_audio/pcm_mapper_reader.h | 2 +- .../roc_audio/profiling_reader.cpp | 18 +++----- .../roc_audio/profiling_reader.h | 2 +- .../roc_audio/resampler_reader.cpp | 18 ++++---- .../roc_audio/resampler_reader.h | 4 +- src/internal_modules/roc_audio/watchdog.cpp | 11 ++--- src/internal_modules/roc_audio/watchdog.h | 2 +- .../roc_pipeline/receiver_loop.cpp | 14 +++---- .../roc_pipeline/receiver_loop.h | 2 +- .../roc_pipeline/receiver_source.cpp | 2 +- .../roc_pipeline/receiver_source.h | 2 +- .../roc_pipeline/transcoder_source.cpp | 2 +- .../roc_pipeline/transcoder_source.h | 2 +- src/internal_modules/roc_sndio/pump.cpp | 31 ++++++++------ src/internal_modules/roc_sndio/pump.h | 2 +- .../roc_sndio/pulseaudio_device.cpp | 8 +++- .../roc_sndio/pulseaudio_device.h | 2 +- .../roc_sndio/sndfile_source.cpp | 13 ++++-- .../target_sndfile/roc_sndio/sndfile_source.h | 2 +- .../target_sox/roc_sndio/sox_source.cpp | 8 ++-- .../target_sox/roc_sndio/sox_source.h | 2 +- src/internal_modules/roc_sndio/wav_source.cpp | 8 ++-- src/internal_modules/roc_sndio/wav_source.h | 2 +- src/public_api/src/receiver.cpp | 6 ++- src/public_api/src/receiver_decoder.cpp | 6 ++- src/public_api/src/sender_encoder.cpp | 3 +- .../roc_audio/test_channel_mapper_reader.cpp | 12 +++--- src/tests/roc_audio/test_depacketizer.cpp | 8 ++-- .../roc_audio/test_helpers/mock_reader.h | 6 +-- src/tests/roc_audio/test_mixer.cpp | 2 +- .../roc_audio/test_pcm_mapper_reader.cpp | 42 +++++++++---------- src/tests/roc_audio/test_resampler.cpp | 20 ++++----- src/tests/roc_audio/test_watchdog.cpp | 8 ++-- .../roc_pipeline/test_helpers/frame_reader.h | 8 ++-- .../roc_pipeline/test_helpers/mock_source.h | 6 +-- .../roc_pipeline/test_receiver_source.cpp | 8 ++-- .../roc_pipeline/test_transcoder_source.cpp | 4 +- src/tests/roc_sndio/test_backend_source.cpp | 40 +++++++++--------- .../roc_sndio/test_helpers/mock_source.h | 4 +- src/tests/roc_sndio/test_pump.cpp | 10 ++--- 50 files changed, 253 insertions(+), 231 deletions(-) diff --git a/src/internal_modules/roc_audio/channel_mapper_reader.cpp b/src/internal_modules/roc_audio/channel_mapper_reader.cpp index 23ecd48bb..ec9cc1f26 100644 --- a/src/internal_modules/roc_audio/channel_mapper_reader.cpp +++ b/src/internal_modules/roc_audio/channel_mapper_reader.cpp @@ -56,7 +56,7 @@ status::StatusCode ChannelMapperReader::init_status() const { return init_status_; } -bool ChannelMapperReader::read(Frame& out_frame) { +status::StatusCode ChannelMapperReader::read(Frame& out_frame) { roc_panic_if(init_status_ != status::StatusOK); if (out_frame.num_raw_samples() % out_spec_.num_channels() != 0) { @@ -75,8 +75,10 @@ bool ChannelMapperReader::read(Frame& out_frame) { const size_t n_read = std::min(n_samples, max_batch); core::nanoseconds_t capt_ts = 0; - if (!read_(out_samples, n_read, flags, capt_ts)) { - return false; + + const status::StatusCode code = read_(out_samples, n_read, flags, capt_ts); + if (code != status::StatusOK) { + return code; } if (frames_counter == 0) { @@ -90,16 +92,18 @@ bool ChannelMapperReader::read(Frame& out_frame) { out_frame.set_flags(flags); out_frame.set_duration(out_frame.num_raw_samples() / out_spec_.num_channels()); - return true; + return status::StatusOK; } -bool ChannelMapperReader::read_(sample_t* out_samples, - size_t n_samples, - unsigned& flags, - core::nanoseconds_t& capt_ts) { +status::StatusCode ChannelMapperReader::read_(sample_t* out_samples, + size_t n_samples, + unsigned& flags, + core::nanoseconds_t& capt_ts) { Frame in_frame(input_buf_.data(), n_samples * in_spec_.num_channels()); - if (!input_reader_.read(in_frame)) { - return false; + + const status::StatusCode code = input_reader_.read(in_frame); + if (code != status::StatusOK) { + return code; } mapper_.map(in_frame.raw_samples(), in_frame.num_raw_samples(), out_samples, @@ -108,7 +112,7 @@ bool ChannelMapperReader::read_(sample_t* out_samples, capt_ts = in_frame.capture_timestamp(); flags |= in_frame.flags(); - return true; + return status::StatusOK; } } // namespace audio diff --git a/src/internal_modules/roc_audio/channel_mapper_reader.h b/src/internal_modules/roc_audio/channel_mapper_reader.h index 1a9cfdea9..e6f32d1db 100644 --- a/src/internal_modules/roc_audio/channel_mapper_reader.h +++ b/src/internal_modules/roc_audio/channel_mapper_reader.h @@ -38,13 +38,13 @@ class ChannelMapperReader : public IFrameReader, public core::NonCopyable<> { status::StatusCode init_status() const; //! Read audio frame. - virtual bool read(Frame& frame); + virtual ROC_ATTR_NODISCARD status::StatusCode read(Frame& frame); private: - bool read_(sample_t* out_samples, - size_t n_samples, - unsigned& flags, - core::nanoseconds_t& capt_ts); + status::StatusCode read_(sample_t* out_samples, + size_t n_samples, + unsigned& flags, + core::nanoseconds_t& capt_ts); IFrameReader& input_reader_; core::Slice input_buf_; diff --git a/src/internal_modules/roc_audio/depacketizer.cpp b/src/internal_modules/roc_audio/depacketizer.cpp index d20d5186e..577c80cd5 100644 --- a/src/internal_modules/roc_audio/depacketizer.cpp +++ b/src/internal_modules/roc_audio/depacketizer.cpp @@ -78,14 +78,15 @@ packet::stream_timestamp_t Depacketizer::next_timestamp() const { return stream_ts_; } -bool Depacketizer::read(Frame& frame) { +status::StatusCode Depacketizer::read(Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); read_frame_(frame); report_stats_(); - return true; + // TODO(gh-183): forward status + return status::StatusOK; } void Depacketizer::read_frame_(Frame& frame) { diff --git a/src/internal_modules/roc_audio/depacketizer.h b/src/internal_modules/roc_audio/depacketizer.h index f4d475d34..03d0f4ed5 100644 --- a/src/internal_modules/roc_audio/depacketizer.h +++ b/src/internal_modules/roc_audio/depacketizer.h @@ -48,7 +48,7 @@ class Depacketizer : public IFrameReader, public core::NonCopyable<> { bool is_started() const; //! Read audio frame. - virtual bool read(Frame& frame); + virtual ROC_ATTR_NODISCARD status::StatusCode read(Frame& frame); //! Get next timestamp to be rendered. //! @pre diff --git a/src/internal_modules/roc_audio/iframe_reader.h b/src/internal_modules/roc_audio/iframe_reader.h index f0620d51d..b882985c8 100644 --- a/src/internal_modules/roc_audio/iframe_reader.h +++ b/src/internal_modules/roc_audio/iframe_reader.h @@ -13,7 +13,9 @@ #define ROC_AUDIO_IFRAME_READER_H_ #include "roc_audio/frame.h" +#include "roc_core/attributes.h" #include "roc_core/list_node.h" +#include "roc_status/status_code.h" namespace roc { namespace audio { @@ -23,13 +25,14 @@ class IFrameReader : public core::ListNode<> { public: virtual ~IFrameReader(); - //! Read audio frame. - //! @remarks - //! Frame buffer and its size should be set by caller. The reader - //! should fill the entire buffer and should not resize it. + //! Read frame. + //! //! @returns - //! false if there is nothing to read anymore. - virtual bool read(Frame& frame) = 0; + //! If frame was successfully and completely read, returns status::StatusOK, + //! otherwise, returns an error. + //! + //! @see status::StatusCode. + virtual ROC_ATTR_NODISCARD status::StatusCode read(Frame& frame) = 0; }; } // namespace audio diff --git a/src/internal_modules/roc_audio/latency_monitor.cpp b/src/internal_modules/roc_audio/latency_monitor.cpp index ba3751a89..452b04bf7 100644 --- a/src/internal_modules/roc_audio/latency_monitor.cpp +++ b/src/internal_modules/roc_audio/latency_monitor.cpp @@ -69,7 +69,7 @@ const LatencyMetrics& LatencyMonitor::metrics() const { return latency_metrics_; } -bool LatencyMonitor::read(Frame& frame) { +status::StatusCode LatencyMonitor::read(Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); if (alive_) { @@ -82,16 +82,17 @@ bool LatencyMonitor::read(Frame& frame) { } if (!alive_) { - return false; + return status::StatusAbort; } - if (!frame_reader_.read(frame)) { - return false; + const status::StatusCode code = frame_reader_.read(frame); + if (code != status::StatusOK) { + return code; } post_process_(frame); - return true; + return status::StatusOK; } bool LatencyMonitor::reclock(const core::nanoseconds_t playback_timestamp) { diff --git a/src/internal_modules/roc_audio/latency_monitor.h b/src/internal_modules/roc_audio/latency_monitor.h index c44fc218d..bac245dd9 100644 --- a/src/internal_modules/roc_audio/latency_monitor.h +++ b/src/internal_modules/roc_audio/latency_monitor.h @@ -82,7 +82,7 @@ class LatencyMonitor : public IFrameReader, public core::NonCopyable<> { //! Read audio frame from a pipeline. //! @remarks //! Forwards frame from underlying reader as-is. - virtual bool read(Frame& frame); + virtual ROC_ATTR_NODISCARD status::StatusCode read(Frame& frame); //! Report playback timestamp of last frame returned by read. //! @remarks diff --git a/src/internal_modules/roc_audio/mixer.cpp b/src/internal_modules/roc_audio/mixer.cpp index bd732d777..4c66ab4a4 100644 --- a/src/internal_modules/roc_audio/mixer.cpp +++ b/src/internal_modules/roc_audio/mixer.cpp @@ -53,24 +53,9 @@ void Mixer::remove_input(IFrameReader& reader) { readers_.remove(reader); } -bool Mixer::read(Frame& frame) { +status::StatusCode Mixer::read(Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); - // Optimization for single reader case. - if (readers_.size() == 1) { - if (!readers_.front()->read(frame)) { - frame.set_duration(frame.num_raw_samples() / sample_spec_.num_channels()); - } - - if (!enable_timestamps_) { - // When timestamps are disabled, don't forget to zeroise - // them in the optimized path. - frame.set_capture_timestamp(0); - } - - return true; - } - const size_t max_read = temp_buf_.size(); sample_t* samples = frame.raw_samples(); @@ -88,7 +73,10 @@ bool Mixer::read(Frame& frame) { n_read = max_read; } - read_(samples, n_read, flags, capture_ts); + const status::StatusCode code = read_(samples, n_read, flags, capture_ts); + if (code != status::StatusOK) { + return code; + } samples += n_read; n_samples -= n_read; @@ -98,13 +86,13 @@ bool Mixer::read(Frame& frame) { frame.set_duration(frame.num_raw_samples() / sample_spec_.num_channels()); frame.set_capture_timestamp(capture_ts); - return true; + return status::StatusOK; } -void Mixer::read_(sample_t* out_data, - size_t out_size, - unsigned& out_flags, - core::nanoseconds_t& out_cts) { +status::StatusCode Mixer::read_(sample_t* out_data, + size_t out_size, + unsigned& out_flags, + core::nanoseconds_t& out_cts) { roc_panic_if(!out_data); roc_panic_if(out_size == 0); @@ -121,9 +109,14 @@ void Mixer::read_(sample_t* out_data, sample_t* temp_data = temp_buf_.data(); Frame temp_frame(temp_data, out_size); - if (!rp->read(temp_frame)) { + + const status::StatusCode code = rp->read(temp_frame); + if (code == status::StatusDrain) { continue; } + if (code != status::StatusOK) { + return code; + } for (size_t n = 0; n < out_size; n++) { out_data[n] += temp_data[n]; @@ -157,6 +150,8 @@ void Mixer::read_(sample_t* out_data, out_cts = core::nanoseconds_t(cts_base * ((double)cts_count / n_readers) + cts_sum / (double)n_readers); } + + return status::StatusOK; } } // namespace audio diff --git a/src/internal_modules/roc_audio/mixer.h b/src/internal_modules/roc_audio/mixer.h index ea692cccc..c52f7c03b 100644 --- a/src/internal_modules/roc_audio/mixer.h +++ b/src/internal_modules/roc_audio/mixer.h @@ -66,13 +66,13 @@ class Mixer : public IFrameReader, public core::NonCopyable<> { //! @remarks //! Reads samples from every input reader, mixes them, and fills @p frame //! with the result. - virtual bool read(Frame& frame); + virtual ROC_ATTR_NODISCARD status::StatusCode read(Frame& frame); private: - void read_(sample_t* out_data, - size_t out_size, - unsigned& out_flags, - core::nanoseconds_t& out_cts); + status::StatusCode read_(sample_t* out_data, + size_t out_size, + unsigned& out_flags, + core::nanoseconds_t& out_cts); core::List readers_; core::Slice temp_buf_; diff --git a/src/internal_modules/roc_audio/pcm_mapper_reader.cpp b/src/internal_modules/roc_audio/pcm_mapper_reader.cpp index 4c8bb0a38..3dd3317a7 100644 --- a/src/internal_modules/roc_audio/pcm_mapper_reader.cpp +++ b/src/internal_modules/roc_audio/pcm_mapper_reader.cpp @@ -64,7 +64,7 @@ status::StatusCode PcmMapperReader::init_status() const { return init_status_; } -bool PcmMapperReader::read(Frame& out_frame) { +status::StatusCode PcmMapperReader::read(Frame& out_frame) { roc_panic_if(init_status_ != status::StatusOK); const size_t max_sample_count = mapper_.input_sample_count(in_buf_.size()) / num_ch_; @@ -86,8 +86,10 @@ bool PcmMapperReader::read(Frame& out_frame) { size_t in_bit_offset = 0; Frame in_frame(in_buf_.data(), in_byte_count); - if (!in_reader_.read(in_frame)) { - return false; + + const status::StatusCode code = in_reader_.read(in_frame); + if (code != status::StatusOK) { + return code; } mapper_.map(in_buf_.data(), in_byte_count, in_bit_offset, out_frame.bytes(), @@ -110,7 +112,7 @@ bool PcmMapperReader::read(Frame& out_frame) { out_frame.set_flags(out_flags); out_frame.set_duration(out_sample_count); - return true; + return status::StatusOK; } } // namespace audio diff --git a/src/internal_modules/roc_audio/pcm_mapper_reader.h b/src/internal_modules/roc_audio/pcm_mapper_reader.h index 4b1b22171..1957b8de0 100644 --- a/src/internal_modules/roc_audio/pcm_mapper_reader.h +++ b/src/internal_modules/roc_audio/pcm_mapper_reader.h @@ -39,7 +39,7 @@ class PcmMapperReader : public IFrameReader, public core::NonCopyable<> { status::StatusCode init_status() const; //! Read audio frame. - virtual bool read(Frame& frame); + virtual ROC_ATTR_NODISCARD status::StatusCode read(Frame& frame); private: PcmMapper mapper_; diff --git a/src/internal_modules/roc_audio/profiling_reader.cpp b/src/internal_modules/roc_audio/profiling_reader.cpp index 088e20cc4..619e8ed20 100644 --- a/src/internal_modules/roc_audio/profiling_reader.cpp +++ b/src/internal_modules/roc_audio/profiling_reader.cpp @@ -26,22 +26,16 @@ status::StatusCode ProfilingReader::init_status() const { return profiler_.init_status(); } -bool ProfilingReader::read(Frame& frame) { - bool ret; - const core::nanoseconds_t elapsed = read_(frame, ret); +status::StatusCode ProfilingReader::read(Frame& frame) { + const core::nanoseconds_t started = core::timestamp(core::ClockMonotonic); + const status::StatusCode code = reader_.read(frame); + const core::nanoseconds_t elapsed = core::timestamp(core::ClockMonotonic) - started; - if (ret) { + if (code == status::StatusOK) { profiler_.add_frame(frame.duration(), elapsed); } - return ret; -} - -core::nanoseconds_t ProfilingReader::read_(Frame& frame, bool& ret) { - const core::nanoseconds_t start = core::timestamp(core::ClockMonotonic); - - ret = reader_.read(frame); - return core::timestamp(core::ClockMonotonic) - start; + return code; } } // namespace audio diff --git a/src/internal_modules/roc_audio/profiling_reader.h b/src/internal_modules/roc_audio/profiling_reader.h index d9feb887a..054288e07 100644 --- a/src/internal_modules/roc_audio/profiling_reader.h +++ b/src/internal_modules/roc_audio/profiling_reader.h @@ -35,7 +35,7 @@ class ProfilingReader : public IFrameReader, public core::NonCopyable<> { status::StatusCode init_status() const; //! Read audio frame. - virtual bool read(Frame& frame); + virtual ROC_ATTR_NODISCARD status::StatusCode read(Frame& frame); private: core::nanoseconds_t read_(Frame& frame, bool& ret); diff --git a/src/internal_modules/roc_audio/resampler_reader.cpp b/src/internal_modules/roc_audio/resampler_reader.cpp index 040f5ca64..89b596971 100644 --- a/src/internal_modules/roc_audio/resampler_reader.cpp +++ b/src/internal_modules/roc_audio/resampler_reader.cpp @@ -65,7 +65,7 @@ bool ResamplerReader::set_scaling(float multiplier) { out_sample_spec_.sample_rate(), multiplier); } -bool ResamplerReader::read(Frame& out_frame) { +status::StatusCode ResamplerReader::read(Frame& out_frame) { roc_panic_if(init_status_ != status::StatusOK); if (out_frame.num_raw_samples() % out_sample_spec_.num_channels() != 0) { @@ -81,8 +81,9 @@ bool ResamplerReader::read(Frame& out_frame) { resampler_.pop_output(out_frame.raw_samples() + out_pos, out_remain); if (num_popped < out_remain) { - if (!push_input_()) { - return false; + const status::StatusCode code = push_input_(); + if (code != status::StatusOK) { + return code; } } @@ -92,16 +93,17 @@ bool ResamplerReader::read(Frame& out_frame) { out_frame.set_duration(out_frame.num_raw_samples() / out_sample_spec_.num_channels()); out_frame.set_capture_timestamp(capture_ts_(out_frame)); - return true; + return status::StatusOK; } -bool ResamplerReader::push_input_() { +status::StatusCode ResamplerReader::push_input_() { const core::Slice& in_buff = resampler_.begin_push_input(); Frame in_frame(in_buff.data(), in_buff.size()); - if (!reader_.read(in_frame)) { - return false; + const status::StatusCode code = reader_.read(in_frame); + if (code != status::StatusOK) { + return code; } resampler_.end_push_input(); @@ -114,7 +116,7 @@ bool ResamplerReader::push_input_() { in_cts + in_sample_spec_.samples_overall_2_ns(in_frame.num_raw_samples()); } - return true; + return status::StatusOK; } // Compute timestamp of first sample of current output frame. diff --git a/src/internal_modules/roc_audio/resampler_reader.h b/src/internal_modules/roc_audio/resampler_reader.h index 39d0a8d3e..0dc66144c 100644 --- a/src/internal_modules/roc_audio/resampler_reader.h +++ b/src/internal_modules/roc_audio/resampler_reader.h @@ -42,10 +42,10 @@ class ResamplerReader : public IFrameReader, public core::NonCopyable<> { bool set_scaling(float multiplier); //! Read audio frame. - virtual bool read(Frame&); + virtual ROC_ATTR_NODISCARD status::StatusCode read(Frame&); private: - bool push_input_(); + status::StatusCode push_input_(); core::nanoseconds_t capture_ts_(Frame& out_frame); IResampler& resampler_; diff --git a/src/internal_modules/roc_audio/watchdog.cpp b/src/internal_modules/roc_audio/watchdog.cpp index ad50b65b4..629db97c1 100644 --- a/src/internal_modules/roc_audio/watchdog.cpp +++ b/src/internal_modules/roc_audio/watchdog.cpp @@ -122,15 +122,16 @@ bool Watchdog::is_alive() const { return alive_; } -bool Watchdog::read(Frame& frame) { +status::StatusCode Watchdog::read(Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); if (!alive_) { - return false; + return status::StatusAbort; } - if (!reader_.read(frame)) { - return false; + const status::StatusCode code = reader_.read(frame); + if (code != status::StatusOK) { + return code; } const packet::stream_timestamp_t next_read_pos = curr_read_pos_ + frame.duration(); @@ -153,7 +154,7 @@ bool Watchdog::read(Frame& frame) { update_warmup_(); - return true; + return status::StatusOK; } void Watchdog::update_blank_timeout_(const Frame& frame, diff --git a/src/internal_modules/roc_audio/watchdog.h b/src/internal_modules/roc_audio/watchdog.h index bc2cff8a2..2449ab44a 100644 --- a/src/internal_modules/roc_audio/watchdog.h +++ b/src/internal_modules/roc_audio/watchdog.h @@ -112,7 +112,7 @@ class Watchdog : public IFrameReader, public core::NonCopyable<> { //! Read audio frame. //! @remarks //! Updates stream state and reads frame from the input reader. - virtual bool read(Frame& frame); + virtual ROC_ATTR_NODISCARD status::StatusCode read(Frame& frame); private: void update_blank_timeout_(const Frame& frame, diff --git a/src/internal_modules/roc_pipeline/receiver_loop.cpp b/src/internal_modules/roc_pipeline/receiver_loop.cpp index 9a0e491a1..8e9981dbf 100644 --- a/src/internal_modules/roc_pipeline/receiver_loop.cpp +++ b/src/internal_modules/roc_pipeline/receiver_loop.cpp @@ -222,7 +222,7 @@ void ReceiverLoop::reclock(core::nanoseconds_t timestamp) { source_.reclock(timestamp); } -bool ReceiverLoop::read(audio::Frame& frame) { +status::StatusCode ReceiverLoop::read(audio::Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); core::Mutex::Lock lock(source_mutex_); @@ -232,9 +232,9 @@ bool ReceiverLoop::read(audio::Frame& frame) { } // invokes process_subframe_imp() and process_task_imp() - if (process_subframes_and_tasks(frame) != status::StatusOK) { - // TODO(gh-183): forward status - return false; + const status::StatusCode code = process_subframes_and_tasks(frame); + if (code != status::StatusOK) { + return code; } ticker_ts_ += frame.duration(); @@ -243,7 +243,7 @@ bool ReceiverLoop::read(audio::Frame& frame) { source_.reclock(core::timestamp(core::ClockUnix)); } - return true; + return status::StatusOK; } core::nanoseconds_t ReceiverLoop::timestamp_imp() const { @@ -255,11 +255,11 @@ uint64_t ReceiverLoop::tid_imp() const { } status::StatusCode ReceiverLoop::process_subframe_imp(audio::Frame& frame) { + // TODO(gh-183): forward status from refresh() // TODO: handle returned deadline and schedule refresh source_.refresh(core::timestamp(core::ClockUnix)); - // TOOD(gh-183): forward status - return source_.read(frame) ? status::StatusOK : status::StatusAbort; + return source_.read(frame); } bool ReceiverLoop::process_task_imp(PipelineTask& basic_task) { diff --git a/src/internal_modules/roc_pipeline/receiver_loop.h b/src/internal_modules/roc_pipeline/receiver_loop.h index 18c424661..f7f628092 100644 --- a/src/internal_modules/roc_pipeline/receiver_loop.h +++ b/src/internal_modules/roc_pipeline/receiver_loop.h @@ -152,7 +152,7 @@ class ReceiverLoop : public PipelineLoop, private sndio::ISource { virtual bool has_latency() const; virtual bool has_clock() const; virtual void reclock(core::nanoseconds_t timestamp); - virtual bool read(audio::Frame&); + virtual status::StatusCode read(audio::Frame&); // Methods of PipelineLoop virtual core::nanoseconds_t timestamp_imp() const; diff --git a/src/internal_modules/roc_pipeline/receiver_source.cpp b/src/internal_modules/roc_pipeline/receiver_source.cpp index 7c1b7d8a5..795f00cfa 100644 --- a/src/internal_modules/roc_pipeline/receiver_source.cpp +++ b/src/internal_modules/roc_pipeline/receiver_source.cpp @@ -187,7 +187,7 @@ void ReceiverSource::reclock(core::nanoseconds_t playback_time) { } } -bool ReceiverSource::read(audio::Frame& frame) { +status::StatusCode ReceiverSource::read(audio::Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); return frame_reader_->read(frame); diff --git a/src/internal_modules/roc_pipeline/receiver_source.h b/src/internal_modules/roc_pipeline/receiver_source.h index 1f483177d..1e3fbe639 100644 --- a/src/internal_modules/roc_pipeline/receiver_source.h +++ b/src/internal_modules/roc_pipeline/receiver_source.h @@ -112,7 +112,7 @@ class ReceiverSource : public sndio::ISource, public core::NonCopyable<> { virtual void reclock(core::nanoseconds_t playback_time); //! Read audio frame. - virtual bool read(audio::Frame&); + virtual ROC_ATTR_NODISCARD status::StatusCode read(audio::Frame&); private: ReceiverSourceConfig source_config_; diff --git a/src/internal_modules/roc_pipeline/transcoder_source.cpp b/src/internal_modules/roc_pipeline/transcoder_source.cpp index 79c5cadba..7ab4315d9 100644 --- a/src/internal_modules/roc_pipeline/transcoder_source.cpp +++ b/src/internal_modules/roc_pipeline/transcoder_source.cpp @@ -139,7 +139,7 @@ void TranscoderSource::reclock(core::nanoseconds_t timestamp) { input_source_.reclock(timestamp); } -bool TranscoderSource::read(audio::Frame& frame) { +status::StatusCode TranscoderSource::read(audio::Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); return frame_reader_->read(frame); diff --git a/src/internal_modules/roc_pipeline/transcoder_source.h b/src/internal_modules/roc_pipeline/transcoder_source.h index 178acf27e..9b1a5a276 100644 --- a/src/internal_modules/roc_pipeline/transcoder_source.h +++ b/src/internal_modules/roc_pipeline/transcoder_source.h @@ -78,7 +78,7 @@ class TranscoderSource : public sndio::ISource, public core::NonCopyable<> { virtual void reclock(core::nanoseconds_t timestamp); //! Read frame. - virtual bool read(audio::Frame&); + virtual ROC_ATTR_NODISCARD status::StatusCode read(audio::Frame&); private: audio::FrameFactory frame_factory_; diff --git a/src/internal_modules/roc_sndio/pump.cpp b/src/internal_modules/roc_sndio/pump.cpp index eea475211..a3d3e8cee 100644 --- a/src/internal_modules/roc_sndio/pump.cpp +++ b/src/internal_modules/roc_sndio/pump.cpp @@ -62,7 +62,12 @@ status::StatusCode Pump::init_status() const { status::StatusCode Pump::run() { roc_log(LogDebug, "pump: starting main loop"); - const status::StatusCode code = transfer_loop_(); + status::StatusCode code = transfer_loop_(); + + if (code == status::StatusEnd) { + // EOF is fine + code = status::StatusOK; + } roc_log(LogDebug, "pump: exiting main loop"); @@ -116,8 +121,8 @@ status::StatusCode Pump::transfer_loop_() { } } - // read frame - const status::StatusCode code = transfer_frame_(*current_source); + // copy one frame + const status::StatusCode code = transfer_frame_(*current_source, sink_); if (code == status::StatusEnd) { if (current_source == backup_source_) { roc_log(LogDebug, "pump: got eof from backup source"); @@ -139,12 +144,13 @@ status::StatusCode Pump::transfer_loop_() { } } -status::StatusCode Pump::transfer_frame_(ISource& current_source) { +status::StatusCode Pump::transfer_frame_(ISource& source, ISink& sink) { audio::Frame frame(frame_buffer_.data(), frame_buffer_.size()); + status::StatusCode frame_status = status::NoStatus; // if source has clock, here we block on it - if (!current_source.read(frame)) { - return status::StatusEnd; + if ((frame_status = source.read(frame)) != status::StatusOK) { + return frame_status; } if (!frame.has_duration()) { @@ -161,9 +167,9 @@ status::StatusCode Pump::transfer_frame_(ISource& current_source) { // recording buffer, and should take it into account too core::nanoseconds_t capture_latency = 0; - if (current_source.has_latency()) { - capture_latency = current_source.latency() - + sample_spec_.stream_timestamp_2_ns(frame.duration()); + if (source.has_latency()) { + capture_latency = + source.latency() + sample_spec_.stream_timestamp_2_ns(frame.duration()); } frame.set_capture_timestamp(core::timestamp(core::ClockUnix) - capture_latency); @@ -171,9 +177,8 @@ status::StatusCode Pump::transfer_frame_(ISource& current_source) { // if sink has clock, here we block on it // note that either source or sink has clock, but not both - const status::StatusCode code = sink_.write(frame); - if (code != status::StatusOK) { - return code; + if ((frame_status = sink.write(frame)) != status::StatusOK) { + return frame_status; } { @@ -188,7 +193,7 @@ status::StatusCode Pump::transfer_frame_(ISource& current_source) { sink_.latency() - sample_spec_.stream_timestamp_2_ns(frame.duration()); } - current_source.reclock(core::timestamp(core::ClockUnix) + playback_latency); + source.reclock(core::timestamp(core::ClockUnix) + playback_latency); } return status::StatusOK; diff --git a/src/internal_modules/roc_sndio/pump.h b/src/internal_modules/roc_sndio/pump.h index b39f5c918..d4a2631d7 100644 --- a/src/internal_modules/roc_sndio/pump.h +++ b/src/internal_modules/roc_sndio/pump.h @@ -67,7 +67,7 @@ class Pump : public core::NonCopyable<> { private: status::StatusCode transfer_loop_(); - status::StatusCode transfer_frame_(ISource& current_source); + status::StatusCode transfer_frame_(ISource& source, ISink& sink); audio::FrameFactory frame_factory_; diff --git a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.cpp b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.cpp index 7181532e3..eb70fb1e9 100644 --- a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.cpp +++ b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.cpp @@ -205,10 +205,14 @@ status::StatusCode PulseaudioDevice::write(audio::Frame& frame) { return status::StatusOK; } -bool PulseaudioDevice::read(audio::Frame& frame) { +status::StatusCode PulseaudioDevice::read(audio::Frame& frame) { roc_panic_if(device_type_ != DeviceType_Source); - return request_frame_(frame); + if (!request_frame_(frame)) { + return status::StatusErrDevice; + } + + return status::StatusOK; } bool PulseaudioDevice::request_frame_(audio::Frame& frame) { diff --git a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.h b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.h index a7777e96c..cfe8047af 100644 --- a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.h +++ b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.h @@ -78,7 +78,7 @@ class PulseaudioDevice : public ISink, public ISource, public core::NonCopyable< virtual ROC_ATTR_NODISCARD status::StatusCode write(audio::Frame& frame); //! Read audio frame. - virtual bool read(audio::Frame& frame); + virtual ROC_ATTR_NODISCARD status::StatusCode read(audio::Frame& frame); private: static void context_state_cb_(pa_context* context, void* userdata); diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.cpp b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.cpp index 2f2759d4f..b71f4e3b5 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.cpp +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.cpp @@ -140,7 +140,7 @@ void SndfileSource::reclock(core::nanoseconds_t) { // no-op } -bool SndfileSource::read(audio::Frame& frame) { +status::StatusCode SndfileSource::read(audio::Frame& frame) { roc_panic_if(!valid_); if (!file_) { @@ -152,8 +152,9 @@ bool SndfileSource::read(audio::Frame& frame) { sf_count_t n_samples = sf_read_float(file_, frame_data, frame_left); if (sf_error(file_) != 0) { - // TODO(gh-183): return error instead of panic - roc_panic("sndfile source: sf_read_float() failed: %s", sf_strerror(file_)); + roc_log(LogError, "sndfile source: sf_read_float() failed: %s", + sf_strerror(file_)); + return status::StatusErrFile; } if (n_samples < frame_left && n_samples != 0) { @@ -161,7 +162,11 @@ bool SndfileSource::read(audio::Frame& frame) { (size_t)(frame_left - n_samples) * sizeof(audio::sample_t)); } - return n_samples != 0; + if (n_samples == 0) { + return status::StatusEnd; + } + + return status::StatusOK; } bool SndfileSource::seek_(size_t offset) { diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.h b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.h index 7e0dfdfd1..2fd33e899 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.h +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.h @@ -88,7 +88,7 @@ class SndfileSource : public ISource, private core::NonCopyable<> { virtual void reclock(core::nanoseconds_t timestamp); //! Read frame. - virtual bool read(audio::Frame&); + virtual ROC_ATTR_NODISCARD status::StatusCode read(audio::Frame&); private: bool open_(); diff --git a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.cpp b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.cpp index 0cdd1db59..c70af4687 100644 --- a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.cpp +++ b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.cpp @@ -242,11 +242,11 @@ void SoxSource::reclock(core::nanoseconds_t) { // no-op } -bool SoxSource::read(audio::Frame& frame) { +status::StatusCode SoxSource::read(audio::Frame& frame) { roc_panic_if(!valid_); if (paused_ || eof_) { - return false; + return status::StatusEnd; } if (!input_) { @@ -285,14 +285,14 @@ bool SoxSource::read(audio::Frame& frame) { } if (frame_left == frame.num_raw_samples()) { - return false; + return status::StatusEnd; } if (frame_left != 0) { memset(frame_data, 0, frame_left * sizeof(audio::sample_t)); } - return true; + return status::StatusOK; } bool SoxSource::seek_(uint64_t offset) { diff --git a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.h b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.h index a943822e2..ebf180104 100644 --- a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.h +++ b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_source.h @@ -89,7 +89,7 @@ class SoxSource : public ISource, private core::NonCopyable<> { virtual void reclock(core::nanoseconds_t timestamp); //! Read frame. - virtual bool read(audio::Frame&); + virtual ROC_ATTR_NODISCARD status::StatusCode read(audio::Frame&); private: bool setup_names_(const char* driver, const char* path); diff --git a/src/internal_modules/roc_sndio/wav_source.cpp b/src/internal_modules/roc_sndio/wav_source.cpp index eefae037b..5e10976f5 100644 --- a/src/internal_modules/roc_sndio/wav_source.cpp +++ b/src/internal_modules/roc_sndio/wav_source.cpp @@ -119,13 +119,13 @@ void WavSource::reclock(core::nanoseconds_t timestamp) { // no-op } -bool WavSource::read(audio::Frame& frame) { +status::StatusCode WavSource::read(audio::Frame& frame) { if (!file_opened_) { roc_panic("wav source: not opened"); } if (eof_) { - return false; + return status::StatusEnd; } audio::sample_t* frame_data = frame.raw_samples(); @@ -149,14 +149,14 @@ bool WavSource::read(audio::Frame& frame) { } if (frame_left == frame.num_raw_samples()) { - return false; + return status::StatusEnd; } if (frame_left != 0) { memset(frame_data, 0, frame_left * sizeof(audio::sample_t)); } - return true; + return status::StatusOK; } bool WavSource::open_(const char* path) { diff --git a/src/internal_modules/roc_sndio/wav_source.h b/src/internal_modules/roc_sndio/wav_source.h index 4b3c629d9..3667cfddf 100644 --- a/src/internal_modules/roc_sndio/wav_source.h +++ b/src/internal_modules/roc_sndio/wav_source.h @@ -84,7 +84,7 @@ class WavSource : public ISource, private core::NonCopyable<> { virtual void reclock(core::nanoseconds_t timestamp); //! Read frame. - virtual bool read(audio::Frame& frame); + virtual ROC_ATTR_NODISCARD status::StatusCode read(audio::Frame& frame); private: bool open_(const char* path); diff --git a/src/public_api/src/receiver.cpp b/src/public_api/src/receiver.cpp index 40ce0bf9c..5919e4fa3 100644 --- a/src/public_api/src/receiver.cpp +++ b/src/public_api/src/receiver.cpp @@ -215,8 +215,10 @@ int roc_receiver_read(roc_receiver* receiver, roc_frame* frame) { audio::Frame imp_frame((float*)frame->samples, frame->samples_size / sizeof(float)); - if (!imp_source.read(imp_frame)) { - roc_log(LogError, "roc_receiver_read(): got unexpected eof from source"); + const status::StatusCode code = imp_source.read(imp_frame); + if (code != status::StatusOK) { + roc_log(LogError, "roc_receiver_read(): can't read frame from decoder: status=%s", + status::code_to_str(code)); return -1; } diff --git a/src/public_api/src/receiver_decoder.cpp b/src/public_api/src/receiver_decoder.cpp index cbb4ad342..06abdb8ef 100644 --- a/src/public_api/src/receiver_decoder.cpp +++ b/src/public_api/src/receiver_decoder.cpp @@ -330,10 +330,12 @@ int roc_receiver_decoder_pop_frame(roc_receiver_decoder* decoder, roc_frame* fra audio::Frame imp_frame((float*)frame->samples, frame->samples_size / sizeof(float)); - if (!imp_source.read(imp_frame)) { + const status::StatusCode code = imp_source.read(imp_frame); + if (code != status::StatusOK) { roc_log(LogError, "roc_receiver_decoder_pop_frame():" - " got unexpected eof from source"); + " can't read frame from decoder: status=%s", + status::code_to_str(code)); return -1; } diff --git a/src/public_api/src/sender_encoder.cpp b/src/public_api/src/sender_encoder.cpp index 271f50941..552387960 100644 --- a/src/public_api/src/sender_encoder.cpp +++ b/src/public_api/src/sender_encoder.cpp @@ -180,7 +180,8 @@ int roc_sender_encoder_push_frame(roc_sender_encoder* encoder, const roc_frame* const status::StatusCode code = imp_sink.write(imp_frame); if (code != status::StatusOK) { - roc_log(LogError, "roc_sender_encoder_write(): can't write frame: status=%s", + roc_log(LogError, + "roc_sender_encoder_write(): can't write frame to encoder: status=%s", status::code_to_str(code)); return -1; } diff --git a/src/tests/roc_audio/test_channel_mapper_reader.cpp b/src/tests/roc_audio/test_channel_mapper_reader.cpp index 32239e6f3..4f3eb2c6b 100644 --- a/src/tests/roc_audio/test_channel_mapper_reader.cpp +++ b/src/tests/roc_audio/test_channel_mapper_reader.cpp @@ -96,7 +96,7 @@ TEST(channel_mapper_reader, small_frame_upmix) { sample_t samples[FrameSz] = {}; Frame frame(samples, FrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); CHECK_EQUAL(1, mock_reader.total_reads()); CHECK_EQUAL(0, mock_reader.num_unread()); @@ -129,7 +129,7 @@ TEST(channel_mapper_reader, small_frame_downmix) { sample_t samples[FrameSz] = {}; Frame frame(samples, FrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); CHECK_EQUAL(1, mock_reader.total_reads()); CHECK_EQUAL(0, mock_reader.num_unread()); @@ -159,7 +159,7 @@ TEST(channel_mapper_reader, small_frame_nocts) { sample_t samples[FrameSz] = {}; Frame frame(samples, FrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); CHECK_EQUAL(1, mock_reader.total_reads()); CHECK_EQUAL(0, mock_reader.num_unread()); @@ -194,7 +194,7 @@ TEST(channel_mapper_reader, large_frame_upmix) { sample_t samples[FrameSz] = {}; Frame frame(samples, FrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); CHECK_EQUAL(2, mock_reader.total_reads()); CHECK_EQUAL(0, mock_reader.num_unread()); @@ -229,7 +229,7 @@ TEST(channel_mapper_reader, large_frame_downmix) { sample_t samples[FrameSz] = {}; Frame frame(samples, FrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); CHECK_EQUAL(2, mock_reader.total_reads()); CHECK_EQUAL(0, mock_reader.num_unread()); @@ -261,7 +261,7 @@ TEST(channel_mapper_reader, large_frame_nocts) { sample_t samples[FrameSz] = {}; Frame frame(samples, FrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); CHECK_EQUAL(2, mock_reader.total_reads()); CHECK_EQUAL(0, mock_reader.num_unread()); diff --git a/src/tests/roc_audio/test_depacketizer.cpp b/src/tests/roc_audio/test_depacketizer.cpp index 71542c7cb..ffbdaee88 100644 --- a/src/tests/roc_audio/test_depacketizer.cpp +++ b/src/tests/roc_audio/test_depacketizer.cpp @@ -106,7 +106,7 @@ void expect_output(Depacketizer& depacketizer, core::Slice buf = new_buffer(sz); Frame frame(buf.data(), buf.size()); - CHECK(depacketizer.read(frame)); + LONGS_EQUAL(status::StatusOK, depacketizer.read(frame)); CHECK(core::ns_equal_delta(frame.capture_timestamp(), capt_ts, core::Microsecond)); UNSIGNED_LONGS_EQUAL(sz * frame_spec.num_channels(), frame.num_raw_samples()); @@ -121,7 +121,7 @@ void expect_flags(Depacketizer& depacketizer, const core::nanoseconds_t epsilon = 100 * core::Microsecond; Frame frame(buf.data(), buf.size()); - CHECK(depacketizer.read(frame)); + LONGS_EQUAL(status::StatusOK, depacketizer.read(frame)); UNSIGNED_LONGS_EQUAL(flags, frame.flags()); if (capt_ts >= 0) { @@ -430,8 +430,8 @@ TEST(depacketizer, zeros_after_packet) { Frame f1(b1.data(), b1.size()); Frame f2(b2.data(), b2.size()); - dp.read(f1); - dp.read(f2); + LONGS_EQUAL(status::StatusOK, dp.read(f1)); + LONGS_EQUAL(status::StatusOK, dp.read(f2)); expect_values(f1.raw_samples(), SamplesPerPacket / 2 * frame_spec.num_channels(), 0.11f); diff --git a/src/tests/roc_audio/test_helpers/mock_reader.h b/src/tests/roc_audio/test_helpers/mock_reader.h index 79f8cd543..af520592a 100644 --- a/src/tests/roc_audio/test_helpers/mock_reader.h +++ b/src/tests/roc_audio/test_helpers/mock_reader.h @@ -28,13 +28,13 @@ class MockReader : public IFrameReader { , timestamp_(-1) { } - virtual bool read(Frame& frame) { + virtual status::StatusCode read(Frame& frame) { total_reads_++; if (fail_on_empty_) { CHECK(pos_ + frame.num_raw_samples() <= size_); } else if (pos_ + frame.num_raw_samples() > size_) { - return false; + return status::StatusEnd; } memcpy(frame.raw_samples(), samples_ + pos_, @@ -53,7 +53,7 @@ class MockReader : public IFrameReader { timestamp_ += sample_spec_.samples_overall_2_ns(frame.num_raw_samples()); } - return true; + return status::StatusOK; } void enable_timestamps(const core::nanoseconds_t base_timestamp, diff --git a/src/tests/roc_audio/test_mixer.cpp b/src/tests/roc_audio/test_mixer.cpp index 09c0d5ead..947e7352b 100644 --- a/src/tests/roc_audio/test_mixer.cpp +++ b/src/tests/roc_audio/test_mixer.cpp @@ -42,7 +42,7 @@ void expect_output(Mixer& mixer, core::Slice buf = new_buffer(sz); Frame frame(buf.data(), buf.size()); - CHECK(mixer.read(frame)); + LONGS_EQUAL(status::StatusOK, mixer.read(frame)); for (size_t n = 0; n < sz; n++) { DOUBLES_EQUAL((double)value, (double)frame.raw_samples()[n], 0.0001); diff --git a/src/tests/roc_audio/test_pcm_mapper_reader.cpp b/src/tests/roc_audio/test_pcm_mapper_reader.cpp index 2de227a24..414bb244a 100644 --- a/src/tests/roc_audio/test_pcm_mapper_reader.cpp +++ b/src/tests/roc_audio/test_pcm_mapper_reader.cpp @@ -46,7 +46,7 @@ template struct CountReader : IFrameReader { n_values = 0; } - virtual bool read(Frame& frame) { + virtual status::StatusCode read(Frame& frame) { size_t pos = 0; while (pos < frame.num_bytes()) { *reinterpret_cast(frame.bytes() + pos) = value; @@ -55,7 +55,7 @@ template struct CountReader : IFrameReader { n_values++; } n_calls++; - return true; + return status::StatusOK; } }; @@ -75,7 +75,7 @@ struct ByteReader : IFrameReader { , n_bytes(0) { } - virtual bool read(Frame& frame) { + virtual status::StatusCode read(Frame& frame) { size_t pos = 0; while (pos < frame.num_bytes()) { CHECK(buffer_pos < buffer_size); @@ -85,7 +85,7 @@ struct ByteReader : IFrameReader { n_bytes++; } n_calls++; - return true; + return status::StatusOK; } }; @@ -103,14 +103,14 @@ struct MetaReader : IFrameReader { n_calls = 0; } - virtual bool read(Frame& frame) { + virtual status::StatusCode read(Frame& frame) { CHECK(pos < ROC_ARRAY_SIZE(flags)); CHECK(pos < ROC_ARRAY_SIZE(cts)); frame.set_flags(flags[pos]); frame.set_capture_timestamp(cts[pos]); pos++; n_calls++; - return true; + return status::StatusOK; } }; @@ -131,7 +131,7 @@ TEST(pcm_mapper_reader, raw_to_raw) { sample_t samples[SmallFrameSz] = {}; Frame frame(samples, SmallFrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(1, count_reader.n_calls); LONGS_EQUAL(SmallFrameSz, count_reader.n_values); @@ -154,7 +154,7 @@ TEST(pcm_mapper_reader, s16_to_raw) { sample_t samples[SmallFrameSz] = {}; Frame frame(samples, SmallFrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(1, count_reader.n_calls); LONGS_EQUAL(SmallFrameSz, count_reader.n_values); @@ -177,7 +177,7 @@ TEST(pcm_mapper_reader, raw_to_s16) { int16_t samples[SmallFrameSz] = {}; Frame frame((uint8_t*)samples, sizeof(samples)); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(1, count_reader.n_calls); LONGS_EQUAL(SmallFrameSz, count_reader.n_values); @@ -200,7 +200,7 @@ TEST(pcm_mapper_reader, s16_to_s32) { int32_t samples[SmallFrameSz] = {}; Frame frame((uint8_t*)samples, sizeof(samples)); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(1, count_reader.n_calls); LONGS_EQUAL(SmallFrameSz, count_reader.n_values); @@ -223,7 +223,7 @@ TEST(pcm_mapper_reader, s32_to_s16) { int16_t samples[SmallFrameSz] = {}; Frame frame((uint8_t*)samples, sizeof(samples)); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(1, count_reader.n_calls); LONGS_EQUAL(SmallFrameSz, count_reader.n_values); @@ -250,7 +250,7 @@ TEST(pcm_mapper_reader, split_frame) { sample_t samples[LargeFrameSz] = {}; Frame frame(samples, LargeFrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(SplitCount, count_reader.n_calls); LONGS_EQUAL(LargeFrameSz, count_reader.n_values); @@ -282,7 +282,7 @@ TEST(pcm_mapper_reader, split_frame_loop) { Frame frame(samples, LargeFrameSz); count_reader.reset(); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(SplitCount, count_reader.n_calls); LONGS_EQUAL(LargeFrameSz, count_reader.n_values); @@ -306,7 +306,7 @@ TEST(pcm_mapper_reader, duration_mono) { sample_t samples[SmallFrameSz] = {}; Frame frame(samples, SmallFrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(1, count_reader.n_calls); LONGS_EQUAL(SmallFrameSz, count_reader.n_values); @@ -327,7 +327,7 @@ TEST(pcm_mapper_reader, duration_stereo) { sample_t samples[SmallFrameSz] = {}; Frame frame(samples, SmallFrameSz); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(1, count_reader.n_calls); LONGS_EQUAL(SmallFrameSz, count_reader.n_values); @@ -355,7 +355,7 @@ TEST(pcm_mapper_reader, flags_to_raw) { sample_t samples[MaxSamples * 3] = {}; Frame frame(samples, MaxSamples * 3); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(3, meta_reader.n_calls); @@ -371,7 +371,7 @@ TEST(pcm_mapper_reader, flags_to_raw) { sample_t samples[MaxSamples * 3] = {}; Frame frame(samples, MaxSamples * 3); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(6, meta_reader.n_calls); @@ -399,7 +399,7 @@ TEST(pcm_mapper_reader, flags_from_raw) { int16_t samples[MaxSamples * 3] = {}; Frame frame((uint8_t*)samples, sizeof(samples)); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(3, meta_reader.n_calls); @@ -416,7 +416,7 @@ TEST(pcm_mapper_reader, flags_from_raw) { int16_t samples[MaxSamples * 3] = {}; Frame frame((uint8_t*)samples, sizeof(samples)); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(6, meta_reader.n_calls); @@ -446,7 +446,7 @@ TEST(pcm_mapper_reader, capture_timestamp) { sample_t samples[MaxSamples * 3] = {}; Frame frame(samples, MaxSamples * 3); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(3, meta_reader.n_calls); @@ -461,7 +461,7 @@ TEST(pcm_mapper_reader, capture_timestamp) { sample_t samples[MaxSamples * 3] = {}; Frame frame(samples, MaxSamples * 3); - CHECK(mapper_reader.read(frame)); + LONGS_EQUAL(status::StatusOK, mapper_reader.read(frame)); LONGS_EQUAL(6, meta_reader.n_calls); diff --git a/src/tests/roc_audio/test_resampler.cpp b/src/tests/roc_audio/test_resampler.cpp index 02a5d2c96..1f27919c0 100644 --- a/src/tests/roc_audio/test_resampler.cpp +++ b/src/tests/roc_audio/test_resampler.cpp @@ -248,7 +248,7 @@ void resample_read(IResampler& resampler, Frame frame(out + pos, std::min(num_samples - pos, (size_t)OutFrameSize * sample_spec.num_channels())); - CHECK(rr.read(frame)); + LONGS_EQUAL(status::StatusOK, rr.read(frame)); pos += frame.num_raw_samples(); } } @@ -365,7 +365,7 @@ TEST(resampler, supported_scalings) { // smoke test sample_t samples[32]; Frame frame(samples, ROC_ARRAY_SIZE(samples)); - CHECK(rr.read(frame)); + LONGS_EQUAL(status::StatusOK, rr.read(frame)); } } } @@ -704,7 +704,7 @@ TEST(resampler, reader_timestamp_passthrough) { { { Frame frame(samples, ROC_ARRAY_SIZE(samples)); - CHECK(rreader.read(frame)); + LONGS_EQUAL(status::StatusOK, rreader.read(frame)); // Since CTS is estimated based scaling, it can happen // to be in past relative to the very first frame, but only // within allowed epsilon. @@ -713,7 +713,7 @@ TEST(resampler, reader_timestamp_passthrough) { } for (size_t i = 0; i < NumIterations; i++) { Frame frame(samples, ROC_ARRAY_SIZE(samples)); - CHECK(rreader.read(frame)); + LONGS_EQUAL(status::StatusOK, rreader.read(frame)); cur_ts += ts_step; expect_capture_timestamp(cur_ts, frame.capture_timestamp(), epsilon); @@ -726,7 +726,7 @@ TEST(resampler, reader_timestamp_passthrough) { { { Frame frame(samples, ROC_ARRAY_SIZE(samples)); - CHECK(rreader.read(frame)); + LONGS_EQUAL(status::StatusOK, rreader.read(frame)); cur_ts += ts_step; expect_capture_timestamp(cur_ts, frame.capture_timestamp(), epsilon); @@ -735,7 +735,7 @@ TEST(resampler, reader_timestamp_passthrough) { } for (size_t i = 0; i < NumIterations; i++) { Frame frame(samples, ROC_ARRAY_SIZE(samples)); - CHECK(rreader.read(frame)); + LONGS_EQUAL(status::StatusOK, rreader.read(frame)); cur_ts += ts_step; expect_capture_timestamp(cur_ts, frame.capture_timestamp(), epsilon); @@ -748,7 +748,7 @@ TEST(resampler, reader_timestamp_passthrough) { { { Frame frame(samples, ROC_ARRAY_SIZE(samples)); - CHECK(rreader.read(frame)); + LONGS_EQUAL(status::StatusOK, rreader.read(frame)); cur_ts += ts_step; expect_capture_timestamp(cur_ts, frame.capture_timestamp(), epsilon); @@ -757,7 +757,7 @@ TEST(resampler, reader_timestamp_passthrough) { } for (size_t i = 0; i < NumIterations; i++) { Frame frame(samples, ROC_ARRAY_SIZE(samples)); - CHECK(rreader.read(frame)); + LONGS_EQUAL(status::StatusOK, rreader.read(frame)); cur_ts += ts_step; expect_capture_timestamp(cur_ts, frame.capture_timestamp(), epsilon); @@ -936,7 +936,7 @@ TEST(resampler, reader_timestamp_zero_or_small) { for (size_t i = 0; i < NumIterations; i++) { sample_t samples[FrameLen] = {}; Frame frame(samples, ROC_ARRAY_SIZE(samples)); - CHECK(rreader.read(frame)); + LONGS_EQUAL(status::StatusOK, rreader.read(frame)); CHECK(frame.capture_timestamp() == 0); } @@ -955,7 +955,7 @@ TEST(resampler, reader_timestamp_zero_or_small) { for (size_t i = 0; i < NumIterations; i++) { sample_t samples[FrameLen] = {}; Frame frame(samples, ROC_ARRAY_SIZE(samples)); - CHECK(rreader.read(frame)); + LONGS_EQUAL(status::StatusOK, rreader.read(frame)); if (cur_ts == 0) { if (frame.capture_timestamp() != 0) { cur_ts = frame.capture_timestamp(); diff --git a/src/tests/roc_audio/test_watchdog.cpp b/src/tests/roc_audio/test_watchdog.cpp index 2ac546be6..b2befbb10 100644 --- a/src/tests/roc_audio/test_watchdog.cpp +++ b/src/tests/roc_audio/test_watchdog.cpp @@ -49,7 +49,7 @@ class MockReader : public IFrameReader, public core::NonCopyable<> { flags_ = flags; } - bool read(Frame& frame) { + virtual status::StatusCode read(Frame& frame) { if (flags_) { frame.set_flags(flags_); } @@ -57,7 +57,7 @@ class MockReader : public IFrameReader, public core::NonCopyable<> { frame.raw_samples()[n] = 42; } frame.set_duration(frame.num_raw_samples() / NumCh); - return true; + return status::StatusOK; } private: @@ -100,12 +100,12 @@ TEST_GROUP(watchdog) { Frame frame(buf.data(), buf.size()); if (is_read) { - CHECK(reader.read(frame)); + LONGS_EQUAL(status::StatusOK, reader.read(frame)); for (size_t n = 0; n < frame.num_raw_samples(); n++) { DOUBLES_EQUAL(42.0, (double)frame.raw_samples()[n], 0); } } else { - CHECK(!reader.read(frame)); + LONGS_EQUAL(status::StatusAbort, reader.read(frame)); } } diff --git a/src/tests/roc_pipeline/test_helpers/frame_reader.h b/src/tests/roc_pipeline/test_helpers/frame_reader.h index 827ac3623..8ff2721df 100644 --- a/src/tests/roc_pipeline/test_helpers/frame_reader.h +++ b/src/tests/roc_pipeline/test_helpers/frame_reader.h @@ -50,7 +50,7 @@ class FrameReader : public core::NonCopyable<> { core::nanoseconds_t base_capture_ts = -1) { core::Slice samples = alloc_samples_(num_samples, sample_spec); audio::Frame frame(samples.data(), samples.size()); - CHECK(source_.read(frame)); + LONGS_EQUAL(status::StatusOK, source_.read(frame)); check_duration_(frame, sample_spec); check_timestamp_(frame, sample_spec, base_capture_ts); @@ -81,7 +81,7 @@ class FrameReader : public core::NonCopyable<> { core::nanoseconds_t base_capture_ts = -1) { core::Slice samples = alloc_samples_(num_samples, sample_spec); audio::Frame frame(samples.data(), samples.size()); - CHECK(source_.read(frame)); + LONGS_EQUAL(status::StatusOK, source_.read(frame)); check_duration_(frame, sample_spec); check_timestamp_(frame, sample_spec, base_capture_ts); @@ -110,7 +110,7 @@ class FrameReader : public core::NonCopyable<> { core::nanoseconds_t base_capture_ts = -1) { core::Slice samples = alloc_samples_(num_samples, sample_spec); audio::Frame frame(samples.data(), samples.size()); - CHECK(source_.read(frame)); + LONGS_EQUAL(status::StatusOK, source_.read(frame)); check_duration_(frame, sample_spec); check_timestamp_(frame, sample_spec, base_capture_ts); @@ -135,7 +135,7 @@ class FrameReader : public core::NonCopyable<> { core::nanoseconds_t base_capture_ts = -1) { core::Slice samples = alloc_samples_(num_samples, sample_spec); audio::Frame frame(samples.data(), samples.size()); - CHECK(source_.read(frame)); + LONGS_EQUAL(status::StatusOK, source_.read(frame)); check_duration_(frame, sample_spec); check_timestamp_(frame, sample_spec, base_capture_ts); diff --git a/src/tests/roc_pipeline/test_helpers/mock_source.h b/src/tests/roc_pipeline/test_helpers/mock_source.h index 7fc77cee8..ce5934c1c 100644 --- a/src/tests/roc_pipeline/test_helpers/mock_source.h +++ b/src/tests/roc_pipeline/test_helpers/mock_source.h @@ -84,9 +84,9 @@ class MockSource : public sndio::ISource { // no-op } - virtual bool read(audio::Frame& frame) { + virtual status::StatusCode read(audio::Frame& frame) { if (pos_ == size_) { - return false; + return status::StatusEnd; } size_t ns = frame.num_raw_samples(); @@ -107,7 +107,7 @@ class MockSource : public sndio::ISource { CHECK(n_ch_ > 0); frame.set_duration(frame.num_raw_samples() / n_ch_); - return true; + return status::StatusOK; } void add(size_t num_samples, const audio::SampleSpec& sample_spec) { diff --git a/src/tests/roc_pipeline/test_receiver_source.cpp b/src/tests/roc_pipeline/test_receiver_source.cpp index ebc9f2e8b..c24848e75 100644 --- a/src/tests/roc_pipeline/test_receiver_source.cpp +++ b/src/tests/roc_pipeline/test_receiver_source.cpp @@ -2069,7 +2069,7 @@ TEST(receiver_source, timestamp_mapping_remixing) { cur_time += output_sample_spec.samples_overall_2_ns(frame_size); audio::Frame frame(frame_data, frame_size); - CHECK(receiver.read(frame)); + LONGS_EQUAL(status::StatusOK, receiver.read(frame)); if (!first_ts && frame.capture_timestamp()) { first_ts = frame.capture_timestamp(); @@ -2884,7 +2884,7 @@ TEST(receiver_source, pipeline_state) { cur_time += output_sample_spec.samples_overall_2_ns(samples.size()); audio::Frame frame(samples.data(), samples.size()); - receiver.read(frame); + LONGS_EQUAL(status::StatusOK, receiver.read(frame)); } packet_writer.write_packets(Latency / SamplesPerPacket, SamplesPerPacket, @@ -2897,7 +2897,7 @@ TEST(receiver_source, pipeline_state) { cur_time += output_sample_spec.samples_overall_2_ns(samples.size()); audio::Frame frame(samples.data(), samples.size()); - receiver.read(frame); + LONGS_EQUAL(status::StatusOK, receiver.read(frame)); } for (;;) { @@ -2905,7 +2905,7 @@ TEST(receiver_source, pipeline_state) { cur_time += output_sample_spec.samples_overall_2_ns(samples.size()); audio::Frame frame(samples.data(), samples.size()); - receiver.read(frame); + LONGS_EQUAL(status::StatusOK, receiver.read(frame)); if (receiver.state() == sndio::DeviceState_Idle) { break; diff --git a/src/tests/roc_pipeline/test_transcoder_source.cpp b/src/tests/roc_pipeline/test_transcoder_source.cpp index 348f05088..1b9ec9ca0 100644 --- a/src/tests/roc_pipeline/test_transcoder_source.cpp +++ b/src/tests/roc_pipeline/test_transcoder_source.cpp @@ -165,8 +165,8 @@ TEST(transcoder_source, eof) { audio::Frame frame(samples.data(), samples.size()); mock_source.add(SamplesPerFrame, input_sample_spec); - CHECK(transcoder.read(frame)); - CHECK(!transcoder.read(frame)); + LONGS_EQUAL(status::StatusOK, transcoder.read(frame)); + LONGS_EQUAL(status::StatusEnd, transcoder.read(frame)); } TEST(transcoder_source, frame_size_small) { diff --git a/src/tests/roc_sndio/test_backend_source.cpp b/src/tests/roc_sndio/test_backend_source.cpp index 7c8b954ba..e7746c1a8 100644 --- a/src/tests/roc_sndio/test_backend_source.cpp +++ b/src/tests/roc_sndio/test_backend_source.cpp @@ -94,7 +94,7 @@ TEST(backend_source, open) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); } IDevice* backend_device = backend.open_device( DeviceType_Source, DriverType_File, NULL, file.path(), source_config, arena); @@ -140,7 +140,7 @@ TEST(backend_source, has_clock) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); } IDevice* backend_device = backend.open_device( @@ -175,7 +175,7 @@ TEST(backend_source, sample_rate_auto) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); } source_config.sample_spec.set_sample_rate(0); source_config.frame_length = frame_duration; @@ -213,7 +213,7 @@ TEST(backend_source, sample_rate_mismatch) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); } source_config.sample_spec.set_sample_rate(SampleRate * 2); @@ -248,7 +248,7 @@ TEST(backend_source, pause_resume) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); } IDevice* backend_device = backend.open_device( @@ -262,7 +262,7 @@ TEST(backend_source, pause_resume) { // TODO(gh-706): check state - CHECK(backend_source->read(frame1)); + LONGS_EQUAL(status::StatusOK, backend_source->read(frame1)); audio::sample_t frame_data2[FrameSize * NumChans] = {}; audio::Frame frame2(frame_data2, FrameSize * NumChans); @@ -271,21 +271,21 @@ TEST(backend_source, pause_resume) { if (strcmp(backend.name(), "sox") == 0) { // TODO(gh-706): check state - CHECK(!backend_source->read(frame2)); + LONGS_EQUAL(status::StatusEnd, backend_source->read(frame2)); CHECK(backend_source->resume()); // TODO(gh-706): check state - CHECK(backend_source->read(frame2)); + LONGS_EQUAL(status::StatusOK, backend_source->read(frame2)); } else { // TODO(gh-706): check state - CHECK(backend_source->read(frame2)); + LONGS_EQUAL(status::StatusOK, backend_source->read(frame2)); CHECK(backend_source->resume()); // TODO(gh-706): check state - CHECK(!backend_source->read(frame2)); + LONGS_EQUAL(status::StatusEnd, backend_source->read(frame2)); } if (memcmp(frame_data1, frame_data2, sizeof(frame_data1)) == 0) { @@ -317,7 +317,7 @@ TEST(backend_source, pause_restart) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); } IDevice* backend_device = backend.open_device( @@ -331,7 +331,7 @@ TEST(backend_source, pause_restart) { // TODO(gh-706): check state - CHECK(backend_source->read(frame1)); + LONGS_EQUAL(status::StatusOK, backend_source->read(frame1)); backend_source->pause(); @@ -341,21 +341,21 @@ TEST(backend_source, pause_restart) { if (strcmp(backend.name(), "sox") == 0) { // TODO(gh-706): check state - CHECK(!backend_source->read(frame2)); + LONGS_EQUAL(status::StatusEnd, backend_source->read(frame2)); CHECK(backend_source->restart()); // TODO(gh-706): check state - CHECK(backend_source->read(frame2)); + LONGS_EQUAL(status::StatusOK, backend_source->read(frame2)); } else { // TODO(gh-706): check state - CHECK(backend_source->read(frame2)); + LONGS_EQUAL(status::StatusOK, backend_source->read(frame2)); CHECK(backend_source->restart()); // TODO(gh-706): check state - CHECK(backend_source->read(frame2)); + LONGS_EQUAL(status::StatusOK, backend_source->read(frame2)); } if (memcmp(frame_data1, frame_data2, sizeof(frame_data1)) != 0) { @@ -387,7 +387,7 @@ TEST(backend_source, eof_restart) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); } IDevice* backend_device = backend.open_device( @@ -400,9 +400,9 @@ TEST(backend_source, eof_restart) { audio::Frame frame(frame_data, FrameSize * NumChans); for (int i = 0; i < 3; i++) { - CHECK(backend_source->read(frame)); - CHECK(backend_source->read(frame)); - CHECK(!backend_source->read(frame)); + LONGS_EQUAL(status::StatusOK, backend_source->read(frame)); + LONGS_EQUAL(status::StatusOK, backend_source->read(frame)); + LONGS_EQUAL(status::StatusEnd, backend_source->read(frame)); CHECK(backend_source->restart()); } diff --git a/src/tests/roc_sndio/test_helpers/mock_source.h b/src/tests/roc_sndio/test_helpers/mock_source.h index 88a1a9393..7efcc764b 100644 --- a/src/tests/roc_sndio/test_helpers/mock_source.h +++ b/src/tests/roc_sndio/test_helpers/mock_source.h @@ -79,7 +79,7 @@ class MockSource : public ISource { // no-op } - virtual bool read(audio::Frame& frame) { + virtual status::StatusCode read(audio::Frame& frame) { size_t ns = frame.num_raw_samples(); if (ns > size_ - pos_) { ns = size_ - pos_; @@ -95,7 +95,7 @@ class MockSource : public ISource { (frame.num_raw_samples() - ns) * sizeof(audio::sample_t)); } - return true; + return status::StatusOK; } void add(size_t sz) { diff --git a/src/tests/roc_sndio/test_pump.cpp b/src/tests/roc_sndio/test_pump.cpp index 4d6dee8ad..5970d72d4 100644 --- a/src/tests/roc_sndio/test_pump.cpp +++ b/src/tests/roc_sndio/test_pump.cpp @@ -94,7 +94,7 @@ TEST(pump, write_read) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); CHECK(mock_source.num_returned() >= NumSamples - FrameSize); } @@ -110,7 +110,7 @@ TEST(pump, write_read) { Pump pump(buffer_pool, *backend_source, NULL, mock_writer, frame_duration, sample_spec, Pump::ModePermanent); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); mock_writer.check(0, mock_source.num_returned()); } @@ -140,7 +140,7 @@ TEST(pump, write_overwrite_read) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); } mock_source.add(NumSamples); @@ -157,7 +157,7 @@ TEST(pump, write_overwrite_read) { Pump pump(buffer_pool, mock_source, NULL, *backend_sink, frame_duration, sample_spec, Pump::ModeOneshot); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); } size_t num_returned2 = mock_source.num_returned() - num_returned1; @@ -174,7 +174,7 @@ TEST(pump, write_overwrite_read) { Pump pump(buffer_pool, *backend_source, NULL, mock_writer, frame_duration, sample_spec, Pump::ModePermanent); LONGS_EQUAL(status::StatusOK, pump.init_status()); - LONGS_EQUAL(status::StatusEnd, pump.run()); + LONGS_EQUAL(status::StatusOK, pump.run()); mock_writer.check(num_returned1, num_returned2); }