From 39e29db9fe479367f45bd41e8697d428af70482f Mon Sep 17 00:00:00 2001 From: Victor Gaydov Date: Tue, 13 Aug 2024 15:07:09 +0400 Subject: [PATCH] bugfix: Rework allocation policy & fix crash There was a crash during ISource/ISink deallocation caused by virtual inheritance in IDevice (we were passing incorrect address to IArena). This commit reworks and simplifies allocation policies to avoid such problems: - to use object with ScopedPtr, object should be inherited from ArenaAllocation, PoolAllocation, or NoopAllocation - to use object with SharedPtr, object should be inherited from RefCounted, RefCounted, or RefCounted - FuncAllocation was removed; new class is introduced instead: ScopedRelease - object may override dispose() method of allocation policy; default implementation returns object to arena/pool - if virtual inheritance is used, dispose() should be overridden to pass correct object address to arena/pool, otherwise default implementation is fine - IDevice forces derived classes to override dispose() --- 3rdparty/SConscript | 2 +- SConstruct | 20 +- src/internal_modules/roc_audio/beep_plc.cpp | 9 +- src/internal_modules/roc_audio/beep_plc.h | 6 +- .../roc_audio/builtin_resampler.cpp | 8 +- .../roc_audio/builtin_resampler.h | 8 +- .../roc_audio/decimation_resampler.cpp | 6 +- .../roc_audio/decimation_resampler.h | 6 +- src/internal_modules/roc_audio/fanout.cpp | 6 +- src/internal_modules/roc_audio/fanout.h | 6 +- .../roc_audio/iframe_decoder.cpp | 4 + .../roc_audio/iframe_decoder.h | 6 +- .../roc_audio/iframe_encoder.cpp | 4 + .../roc_audio/iframe_encoder.h | 6 +- src/internal_modules/roc_audio/iplc.cpp | 4 + src/internal_modules/roc_audio/iplc.h | 7 +- src/internal_modules/roc_audio/mixer.cpp | 8 +- src/internal_modules/roc_audio/mixer.h | 8 +- .../roc_audio/pcm_decoder.cpp | 9 +- src/internal_modules/roc_audio/pcm_decoder.h | 4 +- .../roc_audio/pcm_encoder.cpp | 9 +- src/internal_modules/roc_audio/pcm_encoder.h | 4 +- .../roc_audio/processor_map.cpp | 58 ++--- .../roc_audio/processor_map.h | 32 +-- .../roc_audio/speex_resampler.cpp | 8 +- .../roc_audio/speex_resampler.h | 8 +- .../roc_core/allocation_policy.cpp | 24 ++ .../roc_core/allocation_policy.h | 77 +++---- src/internal_modules/roc_core/iarena.h | 2 +- src/internal_modules/roc_core/ipool.h | 2 +- src/internal_modules/roc_core/optional.h | 2 +- src/internal_modules/roc_core/ref_counted.h | 25 +- src/internal_modules/roc_core/scoped_ptr.h | 52 ++--- .../roc_core/scoped_release.h | 78 +++++++ src/internal_modules/roc_core/shared_ptr.h | 7 +- src/internal_modules/roc_fec/composer.h | 5 +- .../roc_fec/iblock_decoder.cpp | 4 + src/internal_modules/roc_fec/iblock_decoder.h | 6 +- .../roc_fec/iblock_encoder.cpp | 4 + src/internal_modules/roc_fec/iblock_encoder.h | 6 +- src/internal_modules/roc_fec/parser.h | 5 +- .../roc_fec/openfec_decoder.cpp | 3 +- .../roc_fec/openfec_encoder.cpp | 3 +- src/internal_modules/roc_node/node.cpp | 3 +- src/internal_modules/roc_node/node.h | 4 +- src/internal_modules/roc_packet/icomposer.cpp | 4 + src/internal_modules/roc_packet/icomposer.h | 6 +- src/internal_modules/roc_packet/iparser.cpp | 4 + src/internal_modules/roc_packet/iparser.h | 7 +- .../roc_pipeline/receiver_endpoint.cpp | 30 ++- .../roc_pipeline/receiver_loop.cpp | 23 +- .../roc_pipeline/receiver_loop.h | 4 +- .../roc_pipeline/receiver_session.cpp | 17 +- .../roc_pipeline/receiver_source.cpp | 34 +-- .../roc_pipeline/receiver_source.h | 9 +- .../roc_pipeline/sender_endpoint.cpp | 22 +- .../roc_pipeline/sender_loop.cpp | 23 +- .../roc_pipeline/sender_loop.h | 4 +- .../roc_pipeline/sender_session.cpp | 10 +- .../roc_pipeline/sender_sink.cpp | 34 +-- .../roc_pipeline/sender_sink.h | 10 +- .../roc_pipeline/transcoder_sink.cpp | 20 +- .../roc_pipeline/transcoder_sink.h | 9 +- .../roc_pipeline/transcoder_source.cpp | 20 +- .../roc_pipeline/transcoder_source.h | 9 +- src/internal_modules/roc_rtcp/composer.cpp | 3 +- src/internal_modules/roc_rtcp/composer.h | 2 +- src/internal_modules/roc_rtcp/parser.cpp | 3 +- src/internal_modules/roc_rtcp/parser.h | 2 +- src/internal_modules/roc_rtp/composer.cpp | 5 +- src/internal_modules/roc_rtp/composer.h | 2 +- src/internal_modules/roc_rtp/encoding.h | 8 +- src/internal_modules/roc_rtp/parser.cpp | 7 +- src/internal_modules/roc_rtp/parser.h | 4 +- .../roc_sndio/backend_dispatcher.cpp | 8 +- src/internal_modules/roc_sndio/idevice.cpp | 4 + src/internal_modules/roc_sndio/idevice.h | 13 +- src/internal_modules/roc_sndio/isink.cpp | 4 + src/internal_modules/roc_sndio/isink.h | 4 + src/internal_modules/roc_sndio/isource.cpp | 4 + src/internal_modules/roc_sndio/isource.h | 4 + .../roc_sndio/pulseaudio_backend.cpp | 5 +- .../roc_sndio/pulseaudio_device.cpp | 47 ++-- .../roc_sndio/pulseaudio_device.h | 9 +- .../roc_sndio/sndfile_backend.cpp | 8 +- .../target_sndfile/roc_sndio/sndfile_sink.cpp | 16 +- .../target_sndfile/roc_sndio/sndfile_sink.h | 9 +- .../roc_sndio/sndfile_source.cpp | 16 +- .../target_sndfile/roc_sndio/sndfile_source.h | 9 +- .../target_sox/roc_sndio/sox_backend.cpp | 8 +- .../target_sox/roc_sndio/sox_sink.cpp | 16 +- .../roc_sndio/target_sox/roc_sndio/sox_sink.h | 9 +- .../target_sox/roc_sndio/sox_source.cpp | 16 +- .../target_sox/roc_sndio/sox_source.h | 9 +- .../roc_sndio/wav_backend.cpp | 12 +- src/internal_modules/roc_sndio/wav_sink.cpp | 16 +- src/internal_modules/roc_sndio/wav_sink.h | 9 +- src/internal_modules/roc_sndio/wav_source.cpp | 16 +- src/internal_modules/roc_sndio/wav_source.h | 9 +- src/public_api/src/context.cpp | 7 +- src/public_api/src/endpoint.cpp | 2 +- src/public_api/src/plugin_plc.cpp | 17 +- src/public_api/src/plugin_plc.h | 12 +- src/public_api/src/receiver.cpp | 7 +- src/public_api/src/receiver_decoder.cpp | 7 +- src/public_api/src/sender.cpp | 7 +- src/public_api/src/sender_encoder.cpp | 7 +- src/tests/roc_audio/test_depacketizer.cpp | 102 ++++----- src/tests/roc_audio/test_fanout.cpp | 12 +- .../roc_audio/test_frame_encoder_decoder.cpp | 64 +++--- src/tests/roc_audio/test_mixer.cpp | 56 ++--- src/tests/roc_audio/test_packetizer.cpp | 32 +-- src/tests/roc_audio/test_plc_reader.cpp | 46 ++-- src/tests/roc_audio/test_resampler.cpp | 66 +++--- src/tests/roc_core/test_hashmap.cpp | 21 +- src/tests/roc_core/test_list.cpp | 7 +- src/tests/roc_core/test_mpsc_queue.cpp | 7 +- .../roc_fec/test_block_encoder_decoder.cpp | 6 +- .../roc_fec/test_block_writer_reader.cpp | 216 ++++++------------ .../test_block_writer_reader_duration.cpp | 18 +- .../test_block_writer_reader_errors.cpp | 45 ++-- .../roc_fec/test_block_writer_reader_peek.cpp | 18 +- src/tests/roc_fec/test_composer.cpp | 8 +- src/tests/roc_fec/test_composer_parser.cpp | 24 +- src/tests/roc_packet/test_shipper.cpp | 15 +- .../roc_pipeline/test_helpers/mock_sink.h | 18 +- .../roc_pipeline/test_helpers/mock_source.h | 20 +- .../roc_pipeline/test_helpers/packet_reader.h | 4 +- .../roc_pipeline/test_helpers/packet_writer.h | 43 ++-- .../roc_pipeline/test_receiver_endpoint.cpp | 6 +- .../roc_pipeline/test_transcoder_sink.cpp | 10 +- .../roc_pipeline/test_transcoder_source.cpp | 18 +- src/tests/roc_rtcp/test_communicator.cpp | 2 +- src/tests/roc_rtp/test_filter.cpp | 4 +- src/tests/roc_rtp/test_packet_formats.cpp | 8 +- src/tests/roc_sndio/test_backend_source.cpp | 4 +- src/tests/roc_sndio/test_helpers/mock_sink.h | 26 ++- .../roc_sndio/test_helpers/mock_source.h | 20 +- src/tests/roc_sndio/test_helpers/utils.h | 4 +- src/tests/roc_sndio/test_io_pump.cpp | 8 +- src/tools/roc_copy/main.cpp | 4 +- src/tools/roc_recv/main.cpp | 10 +- src/tools/roc_send/main.cpp | 4 +- 143 files changed, 1229 insertions(+), 996 deletions(-) create mode 100644 src/internal_modules/roc_core/allocation_policy.cpp create mode 100644 src/internal_modules/roc_core/scoped_release.h diff --git a/3rdparty/SConscript b/3rdparty/SConscript index 0d15d79bd..de7548964 100644 --- a/3rdparty/SConscript +++ b/3rdparty/SConscript @@ -28,7 +28,7 @@ thirdparty_versions = { 'sox': '14.4.2', 'speexdsp': '1.2.0', - # CLI tools + # cli tools 'gengetopt': '2.22.6', 'ragel': '6.10', diff --git a/SConstruct b/SConstruct index 44022af6b..3bb2d1369 100644 --- a/SConstruct +++ b/SConstruct @@ -1057,6 +1057,7 @@ if meta.compiler == 'gcc': ]) if meta.compiler_ver[:2] >= (10, 0): + # enable for var in ['CXXFLAGS', 'CFLAGS']: env.Append(**{var: [ '-Wdouble-promotion', @@ -1065,6 +1066,11 @@ if meta.compiler == 'gcc': '-Woverlength-strings', '-Wsign-conversion', ]}) + else: + # disable + env.Append(CXXFLAGS=[ + '-Wno-reorder', + ]) if meta.compiler == 'clang': for var in ['CXXFLAGS', 'CFLAGS']: @@ -1099,15 +1105,25 @@ if meta.compiler == 'clang': ]}) env.Append(CXXFLAGS=[ - '-Wno-invalid-offsetof', + # enable '-Wnon-virtual-dtor', + + # disable + '-Wno-invalid-offsetof', ]) - if meta.platform in ['darwin', 'android'] or meta.compiler_ver[:2] < (11, 0): + if meta.platform not in ['darwin', 'android'] and meta.compiler_ver[:2] >= (11, 0): + # enable + pass + else: + # disable for var in ['CXXFLAGS', 'CFLAGS']: env.Append(**{var: [ '-Wno-unknown-warning-option', ]}) + env.Append(CXXFLAGS=[ + '-Wno-reorder', + ]) if meta.compiler in ['gcc', 'clang']: for var in ['CXXFLAGS', 'CFLAGS']: diff --git a/src/internal_modules/roc_audio/beep_plc.cpp b/src/internal_modules/roc_audio/beep_plc.cpp index 7946c0f79..3a64b13d5 100644 --- a/src/internal_modules/roc_audio/beep_plc.cpp +++ b/src/internal_modules/roc_audio/beep_plc.cpp @@ -13,11 +13,12 @@ namespace roc { namespace audio { -BeepPlc::BeepPlc(core::IArena& arena, +BeepPlc::BeepPlc(const PlcConfig& config, + const SampleSpec& sample_spec, FrameFactory& frame_factory, - const PlcConfig& config, - const SampleSpec& sample_spec) - : sample_spec_(sample_spec) + core::IArena& arena) + : IPlc(arena) + , sample_spec_(sample_spec) , signal_pos_(0) { if (!sample_spec_.is_valid() || !sample_spec_.is_raw()) { roc_panic("beep plc: required valid sample specs with raw format: spec=%s", diff --git a/src/internal_modules/roc_audio/beep_plc.h b/src/internal_modules/roc_audio/beep_plc.h index 587db34ab..fc4e4830e 100644 --- a/src/internal_modules/roc_audio/beep_plc.h +++ b/src/internal_modules/roc_audio/beep_plc.h @@ -27,10 +27,10 @@ namespace audio { class BeepPlc : public IPlc { public: //! Initialize. - BeepPlc(core::IArena& arena, + BeepPlc(const PlcConfig& config, + const SampleSpec& sample_spec, FrameFactory& frame_factory, - const PlcConfig& config, - const SampleSpec& sample_spec); + core::IArena& arena); virtual ~BeepPlc(); diff --git a/src/internal_modules/roc_audio/builtin_resampler.cpp b/src/internal_modules/roc_audio/builtin_resampler.cpp index 1b950c780..4dadf4627 100644 --- a/src/internal_modules/roc_audio/builtin_resampler.cpp +++ b/src/internal_modules/roc_audio/builtin_resampler.cpp @@ -117,11 +117,11 @@ inline size_t get_frame_size(size_t window_size, } // namespace -BuiltinResampler::BuiltinResampler(core::IArena& arena, - FrameFactory& frame_factory, - const ResamplerConfig& config, +BuiltinResampler::BuiltinResampler(const ResamplerConfig& config, const SampleSpec& in_spec, - const SampleSpec& out_spec) + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena) : IResampler(arena) , in_spec_(in_spec) , out_spec_(out_spec) diff --git a/src/internal_modules/roc_audio/builtin_resampler.h b/src/internal_modules/roc_audio/builtin_resampler.h index fb61afbff..9edabb2fe 100644 --- a/src/internal_modules/roc_audio/builtin_resampler.h +++ b/src/internal_modules/roc_audio/builtin_resampler.h @@ -39,11 +39,11 @@ namespace audio { class BuiltinResampler : public IResampler, public core::NonCopyable<> { public: //! Initialize. - BuiltinResampler(core::IArena& arena, - FrameFactory& frame_factory, - const ResamplerConfig& config, + BuiltinResampler(const ResamplerConfig& config, const SampleSpec& in_spec, - const SampleSpec& out_spec); + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena); ~BuiltinResampler(); diff --git a/src/internal_modules/roc_audio/decimation_resampler.cpp b/src/internal_modules/roc_audio/decimation_resampler.cpp index 77febab87..cec39f90d 100644 --- a/src/internal_modules/roc_audio/decimation_resampler.cpp +++ b/src/internal_modules/roc_audio/decimation_resampler.cpp @@ -27,10 +27,10 @@ const size_t InputFrameSize = 16; DecimationResampler::DecimationResampler( const core::SharedPtr& inner_resampler, - core::IArena& arena, - FrameFactory& frame_factory, const SampleSpec& in_spec, - const SampleSpec& out_spec) + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena) : IResampler(arena) , inner_resampler_(inner_resampler) , use_inner_resampler_(in_spec.sample_rate() != out_spec.sample_rate()) diff --git a/src/internal_modules/roc_audio/decimation_resampler.h b/src/internal_modules/roc_audio/decimation_resampler.h index 5ef0b77a4..0192e16ae 100644 --- a/src/internal_modules/roc_audio/decimation_resampler.h +++ b/src/internal_modules/roc_audio/decimation_resampler.h @@ -51,10 +51,10 @@ class DecimationResampler : public IResampler, public core::NonCopyable<> { public: //! Initialize. DecimationResampler(const core::SharedPtr& inner_resampler, - core::IArena& arena, - FrameFactory& frame_factory, const SampleSpec& in_spec, - const SampleSpec& out_spec); + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena); ~DecimationResampler(); diff --git a/src/internal_modules/roc_audio/fanout.cpp b/src/internal_modules/roc_audio/fanout.cpp index 39c2f0740..0c67a02dd 100644 --- a/src/internal_modules/roc_audio/fanout.cpp +++ b/src/internal_modules/roc_audio/fanout.cpp @@ -14,9 +14,9 @@ namespace roc { namespace audio { -Fanout::Fanout(FrameFactory& frame_factory, - core::IArena& arena, - const SampleSpec& sample_spec) +Fanout::Fanout(const SampleSpec& sample_spec, + FrameFactory& frame_factory, + core::IArena& arena) : outputs_(arena) , sample_spec_(sample_spec) , init_status_(status::NoStatus) { diff --git a/src/internal_modules/roc_audio/fanout.h b/src/internal_modules/roc_audio/fanout.h index 71c341c60..041a13200 100644 --- a/src/internal_modules/roc_audio/fanout.h +++ b/src/internal_modules/roc_audio/fanout.h @@ -35,9 +35,9 @@ namespace audio { class Fanout : public IFrameWriter, public core::NonCopyable<> { public: //! Initialize. - Fanout(FrameFactory& frame_factory, - core::IArena& arena, - const SampleSpec& sample_spec); + Fanout(const SampleSpec& sample_spec, + FrameFactory& frame_factory, + core::IArena& arena); //! Check if the object was successfully constructed. status::StatusCode init_status() const; diff --git a/src/internal_modules/roc_audio/iframe_decoder.cpp b/src/internal_modules/roc_audio/iframe_decoder.cpp index 8288c394e..a24bb9634 100644 --- a/src/internal_modules/roc_audio/iframe_decoder.cpp +++ b/src/internal_modules/roc_audio/iframe_decoder.cpp @@ -11,6 +11,10 @@ namespace roc { namespace audio { +IFrameDecoder::IFrameDecoder(core::IArena& arena) + : core::ArenaAllocation(arena) { +} + IFrameDecoder::~IFrameDecoder() { } diff --git a/src/internal_modules/roc_audio/iframe_decoder.h b/src/internal_modules/roc_audio/iframe_decoder.h index 7592a01e0..cd7b0f6de 100644 --- a/src/internal_modules/roc_audio/iframe_decoder.h +++ b/src/internal_modules/roc_audio/iframe_decoder.h @@ -22,8 +22,12 @@ namespace roc { namespace audio { //! Audio frame decoder interface. -class IFrameDecoder { +class IFrameDecoder : public core::ArenaAllocation { public: + //! Initialize. + explicit IFrameDecoder(core::IArena& arena); + + //! Deinitialize. virtual ~IFrameDecoder(); //! Check if the object was successfully constructed. diff --git a/src/internal_modules/roc_audio/iframe_encoder.cpp b/src/internal_modules/roc_audio/iframe_encoder.cpp index b3c3e042d..0a1936325 100644 --- a/src/internal_modules/roc_audio/iframe_encoder.cpp +++ b/src/internal_modules/roc_audio/iframe_encoder.cpp @@ -11,6 +11,10 @@ namespace roc { namespace audio { +IFrameEncoder::IFrameEncoder(core::IArena& arena) + : core::ArenaAllocation(arena) { +} + IFrameEncoder::~IFrameEncoder() { } diff --git a/src/internal_modules/roc_audio/iframe_encoder.h b/src/internal_modules/roc_audio/iframe_encoder.h index 0a888a671..bc9e6eeda 100644 --- a/src/internal_modules/roc_audio/iframe_encoder.h +++ b/src/internal_modules/roc_audio/iframe_encoder.h @@ -22,8 +22,12 @@ namespace roc { namespace audio { //! Audio frame encoder interface. -class IFrameEncoder { +class IFrameEncoder : public core::ArenaAllocation { public: + //! Initialize. + explicit IFrameEncoder(core::IArena& arena); + + //! Deinitialize. virtual ~IFrameEncoder(); //! Check if the object was successfully constructed. diff --git a/src/internal_modules/roc_audio/iplc.cpp b/src/internal_modules/roc_audio/iplc.cpp index c6f108c6e..89bd60385 100644 --- a/src/internal_modules/roc_audio/iplc.cpp +++ b/src/internal_modules/roc_audio/iplc.cpp @@ -11,6 +11,10 @@ namespace roc { namespace audio { +IPlc::IPlc(core::IArena& arena) + : core::ArenaAllocation(arena) { +} + IPlc::~IPlc() { } diff --git a/src/internal_modules/roc_audio/iplc.h b/src/internal_modules/roc_audio/iplc.h index 2bda0a621..66e3078d2 100644 --- a/src/internal_modules/roc_audio/iplc.h +++ b/src/internal_modules/roc_audio/iplc.h @@ -37,9 +37,12 @@ namespace audio { //! //! PLC implementation is allowed to use arbitrary PCM format, specified //! by its sample_spec() method. -class IPlc { +class IPlc : public core::ArenaAllocation { public: - //! Deinitialization. + //! Initialize. + explicit IPlc(core::IArena& arena); + + //! Deinitialize. virtual ~IPlc(); //! Check if the object was successfully constructed. diff --git a/src/internal_modules/roc_audio/mixer.cpp b/src/internal_modules/roc_audio/mixer.cpp index c9a846447..b86506f26 100644 --- a/src/internal_modules/roc_audio/mixer.cpp +++ b/src/internal_modules/roc_audio/mixer.cpp @@ -14,10 +14,10 @@ namespace roc { namespace audio { -Mixer::Mixer(FrameFactory& frame_factory, - core::IArena& arena, - const SampleSpec& sample_spec, - bool enable_timestamps) +Mixer::Mixer(const SampleSpec& sample_spec, + bool enable_timestamps, + FrameFactory& frame_factory, + core::IArena& arena) : frame_factory_(frame_factory) , inputs_(arena) , sample_spec_(sample_spec) diff --git a/src/internal_modules/roc_audio/mixer.h b/src/internal_modules/roc_audio/mixer.h index d78033420..8e5692054 100644 --- a/src/internal_modules/roc_audio/mixer.h +++ b/src/internal_modules/roc_audio/mixer.h @@ -51,10 +51,10 @@ class Mixer : public IFrameReader, public core::NonCopyable<> { public: //! Initialize. //! @p enable_timestamps defines whether to enable calculation of capture timestamps. - Mixer(FrameFactory& frame_factory, - core::IArena& arena, - const SampleSpec& sample_spec, - bool enable_timestamps); + Mixer(const SampleSpec& sample_spec, + bool enable_timestamps, + FrameFactory& frame_factory, + core::IArena& arena); //! Check if the object was successfully constructed. status::StatusCode init_status() const; diff --git a/src/internal_modules/roc_audio/pcm_decoder.cpp b/src/internal_modules/roc_audio/pcm_decoder.cpp index 6811d995f..96f1c732d 100644 --- a/src/internal_modules/roc_audio/pcm_decoder.cpp +++ b/src/internal_modules/roc_audio/pcm_decoder.cpp @@ -13,12 +13,13 @@ namespace roc { namespace audio { -IFrameDecoder* PcmDecoder::construct(core::IArena& arena, const SampleSpec& sample_spec) { - return new (arena) PcmDecoder(sample_spec); +IFrameDecoder* PcmDecoder::construct(const SampleSpec& sample_spec, core::IArena& arena) { + return new (arena) PcmDecoder(sample_spec, arena); } -PcmDecoder::PcmDecoder(const SampleSpec& sample_spec) - : pcm_mapper_(sample_spec.pcm_format(), Sample_RawFormat) +PcmDecoder::PcmDecoder(const SampleSpec& sample_spec, core::IArena& arena) + : IFrameDecoder(arena) + , pcm_mapper_(sample_spec.pcm_format(), Sample_RawFormat) , n_chans_(sample_spec.num_channels()) , stream_pos_(0) , stream_avail_(0) diff --git a/src/internal_modules/roc_audio/pcm_decoder.h b/src/internal_modules/roc_audio/pcm_decoder.h index d7826ddf3..5da76007e 100644 --- a/src/internal_modules/roc_audio/pcm_decoder.h +++ b/src/internal_modules/roc_audio/pcm_decoder.h @@ -24,10 +24,10 @@ namespace audio { class PcmDecoder : public IFrameDecoder, public core::NonCopyable<> { public: //! Construction function. - static IFrameDecoder* construct(core::IArena& arena, const SampleSpec& sample_spec); + static IFrameDecoder* construct(const SampleSpec& sample_spec, core::IArena& arena); //! Initialize. - PcmDecoder(const SampleSpec& sample_spec); + PcmDecoder(const SampleSpec& sample_spec, core::IArena& arena); //! Check if the object was successfully constructed. virtual status::StatusCode init_status() const; diff --git a/src/internal_modules/roc_audio/pcm_encoder.cpp b/src/internal_modules/roc_audio/pcm_encoder.cpp index 53dc3d089..49ef31433 100644 --- a/src/internal_modules/roc_audio/pcm_encoder.cpp +++ b/src/internal_modules/roc_audio/pcm_encoder.cpp @@ -12,12 +12,13 @@ namespace roc { namespace audio { -IFrameEncoder* PcmEncoder::construct(core::IArena& arena, const SampleSpec& sample_spec) { - return new (arena) PcmEncoder(sample_spec); +IFrameEncoder* PcmEncoder::construct(const SampleSpec& sample_spec, core::IArena& arena) { + return new (arena) PcmEncoder(sample_spec, arena); } -PcmEncoder::PcmEncoder(const SampleSpec& sample_spec) - : pcm_mapper_(Sample_RawFormat, sample_spec.pcm_format()) +PcmEncoder::PcmEncoder(const SampleSpec& sample_spec, core::IArena& arena) + : IFrameEncoder(arena) + , pcm_mapper_(Sample_RawFormat, sample_spec.pcm_format()) , n_chans_(sample_spec.num_channels()) , frame_data_(NULL) , frame_byte_size_(0) diff --git a/src/internal_modules/roc_audio/pcm_encoder.h b/src/internal_modules/roc_audio/pcm_encoder.h index 9cbc4037c..775b7a1c9 100644 --- a/src/internal_modules/roc_audio/pcm_encoder.h +++ b/src/internal_modules/roc_audio/pcm_encoder.h @@ -24,10 +24,10 @@ namespace audio { class PcmEncoder : public IFrameEncoder, public core::NonCopyable<> { public: //! Construction function. - static IFrameEncoder* construct(core::IArena& arena, const SampleSpec& sample_spec); + static IFrameEncoder* construct(const SampleSpec& sample_spec, core::IArena& arena); //! Initialize. - PcmEncoder(const SampleSpec& sample_spec); + PcmEncoder(const SampleSpec& sample_spec, core::IArena& arena); //! Check if the object was successfully constructed. virtual status::StatusCode init_status() const; diff --git a/src/internal_modules/roc_audio/processor_map.cpp b/src/internal_modules/roc_audio/processor_map.cpp index 9f62295dd..87bac9b11 100644 --- a/src/internal_modules/roc_audio/processor_map.cpp +++ b/src/internal_modules/roc_audio/processor_map.cpp @@ -23,36 +23,36 @@ namespace audio { namespace { template -IResampler* resampler_ctor_fn(void* backend_owner, - core::IArena& arena, - FrameFactory& frame_factory, - const ResamplerConfig& config, +IResampler* resampler_ctor_fn(const ResamplerConfig& config, const SampleSpec& in_spec, - const SampleSpec& out_spec) { - return new (arena) T(arena, frame_factory, config, in_spec, out_spec); + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena, + void* backend_owner) { + return new (arena) T(config, in_spec, out_spec, frame_factory, arena); } template -IResampler* decim_resampler_ctor_fn(void* backend_owner, - core::IArena& arena, - FrameFactory& frame_factory, - const ResamplerConfig& config, +IResampler* decim_resampler_ctor_fn(const ResamplerConfig& config, const SampleSpec& in_spec, - const SampleSpec& out_spec) { + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena, + void* backend_owner) { core::SharedPtr inner_resampler = - new (arena) T(arena, frame_factory, config, in_spec, out_spec); + new (arena) T(config, in_spec, out_spec, frame_factory, arena); return new (arena) - DecimationResampler(inner_resampler, arena, frame_factory, in_spec, out_spec); + DecimationResampler(inner_resampler, in_spec, out_spec, frame_factory, arena); } template -IPlc* plc_ctor_fn(void* backend_owner, - core::IArena& arena, +IPlc* plc_ctor_fn(const PlcConfig& config, + const SampleSpec& sample_spec, FrameFactory& frame_factory, - const PlcConfig& config, - const SampleSpec& sample_spec) { - return new (arena) T(arena, frame_factory, config, sample_spec); + core::IArena& arena, + void* backend_owner) { + return new (arena) T(config, sample_spec, frame_factory, arena); } } // namespace @@ -101,11 +101,11 @@ bool ProcessorMap::has_resampler_backend(ResamplerBackend backend_id) const { return find_node_(NodeType_Resampler, backend_id) != NULL; } -IResampler* ProcessorMap::new_resampler(core::IArena& arena, - FrameFactory& frame_factory, - const ResamplerConfig& config, +IResampler* ProcessorMap::new_resampler(const ResamplerConfig& config, const SampleSpec& in_spec, - const SampleSpec& out_spec) { + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena) { core::SharedPtr node; { @@ -119,8 +119,8 @@ IResampler* ProcessorMap::new_resampler(core::IArena& arena, } roc_panic_if(!node->ctor_fn); - return ((ResamplerFunc)node->ctor_fn)(node->owner, arena, frame_factory, config, - in_spec, out_spec); + return ((ResamplerFunc)node->ctor_fn)(config, in_spec, out_spec, frame_factory, arena, + node->owner); } bool ProcessorMap::has_plc_backend(PlcBackend backend_id) const { @@ -189,10 +189,10 @@ ProcessorMap::register_plc(int backend_id, void* backend_owner, PlcFunc ctor_fn) return status::StatusOK; } -IPlc* ProcessorMap::new_plc(core::IArena& arena, +IPlc* ProcessorMap::new_plc(const PlcConfig& config, + const SampleSpec& sample_spec, FrameFactory& frame_factory, - const PlcConfig& config, - const SampleSpec& sample_spec) { + core::IArena& arena) { core::SharedPtr node; { @@ -206,8 +206,8 @@ IPlc* ProcessorMap::new_plc(core::IArena& arena, } roc_panic_if(!node->ctor_fn); - return ((PlcFunc)node->ctor_fn)(node->owner, arena, frame_factory, config, - sample_spec); + return ((PlcFunc)node->ctor_fn)(config, sample_spec, frame_factory, arena, + node->owner); } core::SharedPtr ProcessorMap::find_node_(NodeType type, diff --git a/src/internal_modules/roc_audio/processor_map.h b/src/internal_modules/roc_audio/processor_map.h index 63bb2a80d..b63e7202e 100644 --- a/src/internal_modules/roc_audio/processor_map.h +++ b/src/internal_modules/roc_audio/processor_map.h @@ -42,30 +42,30 @@ class ProcessorMap : public core::NonCopyable<> { explicit ProcessorMap(core::IArena& arena); //! Resampler factory function. - typedef IResampler* (*ResamplerFunc)(void* backend_owner, - core::IArena& arena, - FrameFactory& frame_factory, - const ResamplerConfig& config, + typedef IResampler* (*ResamplerFunc)(const ResamplerConfig& config, const SampleSpec& in_spec, - const SampleSpec& out_spec); + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena, + void* backend_owner); //! Check if given backend is supported. bool has_resampler_backend(ResamplerBackend backend_id) const; //! Instantiate IResampler for given configuration. //! The type depends on backend specified in @p config. - IResampler* new_resampler(core::IArena& arena, - FrameFactory& frame_factory, - const ResamplerConfig& config, + IResampler* new_resampler(const ResamplerConfig& config, const SampleSpec& in_spec, - const SampleSpec& out_spec); + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena); //! PLC factory function. - typedef IPlc* (*PlcFunc)(void* backend_owner, - core::IArena& arena, + typedef IPlc* (*PlcFunc)(const PlcConfig& config, + const SampleSpec& sample_spec, FrameFactory& frame_factory, - const PlcConfig& config, - const SampleSpec& sample_spec); + core::IArena& arena, + void* backend_owner); //! Register custom PLC backend. ROC_ATTR_NODISCARD status::StatusCode @@ -76,10 +76,10 @@ class ProcessorMap : public core::NonCopyable<> { //! Instantiate IPlc for given configuration. //! The type depends on backend specified in @p config. - IPlc* new_plc(core::IArena& arena, + IPlc* new_plc(const PlcConfig& config, + const SampleSpec& sample_spec, FrameFactory& frame_factory, - const PlcConfig& config, - const SampleSpec& sample_spec); + core::IArena& arena); private: friend class core::Singleton; diff --git a/src/internal_modules/roc_audio/target_speexdsp/roc_audio/speex_resampler.cpp b/src/internal_modules/roc_audio/target_speexdsp/roc_audio/speex_resampler.cpp index 581391f46..b62b7e8df 100644 --- a/src/internal_modules/roc_audio/target_speexdsp/roc_audio/speex_resampler.cpp +++ b/src/internal_modules/roc_audio/target_speexdsp/roc_audio/speex_resampler.cpp @@ -45,11 +45,11 @@ inline int get_quality(ResamplerProfile profile) { } // namespace -SpeexResampler::SpeexResampler(core::IArena& arena, - FrameFactory& frame_factory, - const ResamplerConfig& config, +SpeexResampler::SpeexResampler(const ResamplerConfig& config, const SampleSpec& in_spec, - const SampleSpec& out_spec) + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena) : IResampler(arena) , speex_state_(NULL) , num_ch_((spx_uint32_t)in_spec.num_channels()) diff --git a/src/internal_modules/roc_audio/target_speexdsp/roc_audio/speex_resampler.h b/src/internal_modules/roc_audio/target_speexdsp/roc_audio/speex_resampler.h index 371b3cd1f..d28d1c14e 100644 --- a/src/internal_modules/roc_audio/target_speexdsp/roc_audio/speex_resampler.h +++ b/src/internal_modules/roc_audio/target_speexdsp/roc_audio/speex_resampler.h @@ -40,11 +40,11 @@ namespace audio { class SpeexResampler : public IResampler, public core::NonCopyable<> { public: //! Initialize. - SpeexResampler(core::IArena& arena, - FrameFactory& frame_factory, - const ResamplerConfig& config, + SpeexResampler(const ResamplerConfig& config, const SampleSpec& in_spec, - const SampleSpec& out_spec); + const SampleSpec& out_spec, + FrameFactory& frame_factory, + core::IArena& arena); ~SpeexResampler(); diff --git a/src/internal_modules/roc_core/allocation_policy.cpp b/src/internal_modules/roc_core/allocation_policy.cpp new file mode 100644 index 000000000..b12b6fc29 --- /dev/null +++ b/src/internal_modules/roc_core/allocation_policy.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 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_core/allocation_policy.h" + +namespace roc { +namespace core { + +ArenaAllocation::~ArenaAllocation() { +} + +PoolAllocation::~PoolAllocation() { +} + +NoopAllocation::~NoopAllocation() { +} + +} // namespace core +} // namespace roc diff --git a/src/internal_modules/roc_core/allocation_policy.h b/src/internal_modules/roc_core/allocation_policy.h index fc0fc896a..ae52c0308 100644 --- a/src/internal_modules/roc_core/allocation_policy.h +++ b/src/internal_modules/roc_core/allocation_policy.h @@ -19,82 +19,81 @@ namespace roc { namespace core { -//! Allocation policy for objects allocated using IArena. +//! Base class for objects allocated using IArena. +//! @remarks +//! Objects allocated on arena should inherit either ArenaAllocation (to use with +//! ScopedPtr) or RefCounted (to use with SharedPtr). class ArenaAllocation { public: //! Initialize. - ArenaAllocation(IArena& arena) - : arena_(&arena) { + explicit ArenaAllocation(IArena& arena) + : arena_(arena) { } + virtual ~ArenaAllocation(); + //! Destroy object and return memory to arena. - template void destroy(T& object) { - arena_->destroy_object(object); + //! @remarks + //! Usually default implementation is fine, but you may need to override + //! it if you're using multiple inheritance. + virtual void dispose() { + arena_.dispose_object(*this); } protected: //! Get arena. IArena& arena() const { - return *arena_; + return arena_; } private: - IArena* arena_; + IArena& arena_; }; -//! Allocation policy for objects allocated using IPool. +//! Base class for objects allocated using IPool. +//! @remarks +//! Objects allocated on arena should inherit either PoolAllocation (to use with +//! ScopedPtr) or RefCounted (to use with SharedPtr). class PoolAllocation { public: //! Initialize. - PoolAllocation(IPool& pool) - : pool_(&pool) { + explicit PoolAllocation(IPool& pool) + : pool_(pool) { } + virtual ~PoolAllocation(); + //! Destroy object and return memory to pool. - template void destroy(T& object) { - pool_->destroy_object(object); + //! @remarks + //! Usually default implementation is fine, but you may need to override + //! it if you're using multiple inheritance. + virtual void dispose() { + pool_.dispose_object(*this); } protected: //! Get pool. IPool& pool() const { - return *pool_; + return pool_; } private: - IPool* pool_; + IPool& pool_; }; -//! Allocation policy for objects with custom deallocation function. -class FuncAllocation { - typedef void (*DestroyFunc)(void*); - -public: - //! Initialize. - template - FuncAllocation(void (*destroy_func)(T*)) - : destroy_func_((DestroyFunc)destroy_func) { - if (!destroy_func_) { - roc_panic("allocation policy: null function"); - } - } - - //! Invoke custom destruction function. - template void destroy(T& object) { - destroy_func_(&object); - } - -private: - DestroyFunc destroy_func_; -}; - -//! Allocation policy for objects that don't have automatic deallocation. +//! Base class for objects which allocation is not managed by smart pointer. +//! @remarks +//! Useful when you want to use RefCounted for an object to enable it's safety +//! checks (e.g. it panic in destructor if there are active references), but +//! don't want smart pointer to manage allocation and deallocation. class NoopAllocation { public: + virtual ~NoopAllocation(); + //! No-op. //! When SharedPtr or ScopedPtr "destroys" object, nothing happens. //! The user is responsible for destroying object. - template void destroy(T&) { + virtual void dispose() { } }; diff --git a/src/internal_modules/roc_core/iarena.h b/src/internal_modules/roc_core/iarena.h index 6a466906a..63f9087cd 100644 --- a/src/internal_modules/roc_core/iarena.h +++ b/src/internal_modules/roc_core/iarena.h @@ -43,7 +43,7 @@ class IArena { virtual size_t allocated_size(void* ptr) const = 0; //! Destroy object and deallocate its memory. - template void destroy_object(T& object) { + template void dispose_object(T& object) { object.~T(); deallocate(&object); } diff --git a/src/internal_modules/roc_core/ipool.h b/src/internal_modules/roc_core/ipool.h index 14f08c220..74799d5fd 100644 --- a/src/internal_modules/roc_core/ipool.h +++ b/src/internal_modules/roc_core/ipool.h @@ -46,7 +46,7 @@ class IPool { virtual void deallocate(void* memory) = 0; //! Destroy object and deallocate its memory. - template void destroy_object(T& object) { + template void dispose_object(T& object) { object.~T(); deallocate(&object); } diff --git a/src/internal_modules/roc_core/optional.h b/src/internal_modules/roc_core/optional.h index 347104a78..12bc1eef7 100644 --- a/src/internal_modules/roc_core/optional.h +++ b/src/internal_modules/roc_core/optional.h @@ -42,7 +42,7 @@ template class Optional : public NonCopyable< ptr_->~T(); } if (ptr && (void*)ptr != storage_.memory()) { - roc_panic("optional: attempt to set incorrect object"); + roc_panic("optional: attempt to initialize with invalid pointer"); } ptr_ = ptr; } diff --git a/src/internal_modules/roc_core/ref_counted.h b/src/internal_modules/roc_core/ref_counted.h index df4ac40ca..b66ac2d47 100644 --- a/src/internal_modules/roc_core/ref_counted.h +++ b/src/internal_modules/roc_core/ref_counted.h @@ -22,22 +22,19 @@ namespace core { //! Base class for object with reference counter. //! //! Allows to increment and decrement reference counter. When the counter -//! reaches zero, the object is automatically destroyed. +//! reaches zero, the object is automatically disposed. //! //! @tparam T defines the derived class. -//! @tparam AllocationPolicy defines destroy policy. +//! @tparam AllocationPolicy defines allocation policy to be inherited +//! (ArenaAllocation, PoolAllocation, etc.) //! -//! When reference counter becomes zero, AllocationPolicy::destroy() is invoked -//! by RefCounted to destroy itself. -//! -//! Inherits AllocationPolicy to make its methods and state available in the -//! derived class. E.g., PoolAllocation policy holds a reference to the pool -//! and uses it to release the object. +//! When reference counter becomes zero, RefCounted invokes dispose() method +//! implemented by allocation policy. //! //! Thread-safe. template -class RefCounted : public NonCopyable >, - protected AllocationPolicy { +class RefCounted : public AllocationPolicy, + public NonCopyable > { public: //! Initialize. RefCounted() @@ -45,8 +42,9 @@ class RefCounted : public NonCopyable >, } //! Initialize. - explicit RefCounted(const AllocationPolicy& alloc) - : AllocationPolicy(alloc) { + template + explicit RefCounted(Arg& arg) + : AllocationPolicy(arg) { } //! Get reference counter. @@ -66,8 +64,7 @@ class RefCounted : public NonCopyable >, const int current_counter = impl_.decref(); if (current_counter == 0) { - const_cast(*this).destroy( - static_cast(const_cast(*this))); + const_cast(*this).dispose(); } } diff --git a/src/internal_modules/roc_core/scoped_ptr.h b/src/internal_modules/roc_core/scoped_ptr.h index abad477cb..252c58dd9 100644 --- a/src/internal_modules/roc_core/scoped_ptr.h +++ b/src/internal_modules/roc_core/scoped_ptr.h @@ -7,7 +7,7 @@ */ //! @file roc_core/scoped_ptr.h -//! @brief Unique ownrship pointer. +//! @brief Lexical scoped ownership pointer. #ifndef ROC_CORE_SCOPED_PTR_H_ #define ROC_CORE_SCOPED_PTR_H_ @@ -24,23 +24,17 @@ namespace core { //! Lexical scoped ownership pointer. //! -//! @tparam T defines pointee type. It may be const. -//! @tparam AllocationPolicy defies (de)allocation policy. +//! @tparam T defines pointee type. +//! Pointee type should inherit one of the allocation policies (ArenaAllocation, +//! PoolAllocation, etc). //! -//! ScopedPtr holds an instance of AllocationPolicy. When ScopedPtr is -//! destroyed or reset, it invokes AllocationPolicy::destroy(). -template -class ScopedPtr : public NonCopyable<> { +//! ScopedPtr holds a pointer to an object and calls its dispose() method +//! (implemented by allocation policy) in destructor. +template class ScopedPtr : public NonCopyable<> { public: - //! Initialize null pointer. - ScopedPtr() - : ptr_(NULL) { - } - - //! Initialize from a raw pointer. - ScopedPtr(T* ptr, const AllocationPolicy& alloc) + //! Initialize. + ScopedPtr(T* ptr = NULL) : ptr_(ptr) { - policy_.reset(new (policy_) AllocationPolicy(alloc)); } //! Destroy object. @@ -49,35 +43,22 @@ class ScopedPtr : public NonCopyable<> { } //! Reset pointer to null. - void reset() { - if (ptr_ != NULL) { - policy_->destroy(*ptr_); - policy_.reset(); + void reset(T* new_ptr = NULL) { + if (ptr_ != NULL && ptr_ != new_ptr) { + ptr_->dispose(); ptr_ = NULL; } - } - - //! Reset pointer to a new value. - //! @p alloc defines an argument for AllocationPolicy constructor. - void reset(T* new_ptr, const AllocationPolicy& new_alloc) { - if (new_ptr != ptr_) { - reset(); - - ptr_ = new_ptr; - policy_.reset(new (policy_) AllocationPolicy(new_alloc)); - } + ptr_ = new_ptr; } //! Get underlying pointer and pass ownership to the caller. - T* release() { + T* hijack() { T* ret = ptr_; if (ret == NULL) { roc_panic("scoped ptr: attempting to release a null pointer"); } ptr_ = NULL; - policy_.reset(); - return ret; } @@ -106,18 +87,17 @@ class ScopedPtr : public NonCopyable<> { private: T* ptr_; - Optional policy_; }; //! Equality check. template -inline bool operator==(const ScopedPtr& a, const ScopedPtr& b) { +inline bool operator==(const ScopedPtr& a, const ScopedPtr& b) { return a.get() == b.get(); } //! Equality check. template -inline bool operator!=(const ScopedPtr& a, const ScopedPtr& b) { +inline bool operator!=(const ScopedPtr& a, const ScopedPtr& b) { return a.get() != b.get(); } diff --git a/src/internal_modules/roc_core/scoped_release.h b/src/internal_modules/roc_core/scoped_release.h new file mode 100644 index 000000000..dafe9e019 --- /dev/null +++ b/src/internal_modules/roc_core/scoped_release.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 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_core/scoped_release.h +//! @brief Lexical scoped releaser. + +#ifndef ROC_CORE_SCOPED_RELEASE_H_ +#define ROC_CORE_SCOPED_RELEASE_H_ + +#include "roc_core/allocation_policy.h" +#include "roc_core/iarena.h" +#include "roc_core/noncopyable.h" +#include "roc_core/optional.h" +#include "roc_core/panic.h" +#include "roc_core/stddefs.h" + +namespace roc { +namespace core { + +//! Lexical scoped releaser. +//! +//! @tparam T defines pointee type. +//! +//! ScopedRelease holds a pointer to an object and calls custom releaser +//! function for the object in destructor. +template class ScopedRelease : public NonCopyable<> { +public: + //! Initialize. + template + ScopedRelease(T* ptr, void (*release_func)(Arg*)) + : ptr_(ptr) + , del_fn_((ReleaseFunc)release_func) { + if (!del_fn_) { + roc_panic("scoped release: null function"); + } + } + + //! Destroy object. + ~ScopedRelease() { + reset(); + } + + //! Reset pointer to a new value. + void reset(T* new_ptr = NULL) { + if (ptr_ != NULL && ptr_ != new_ptr) { + del_fn_(ptr_); + ptr_ = NULL; + } + ptr_ = new_ptr; + } + + //! Get underlying pointer and pass ownership to the caller. + T* hijack() { + T* ret = ptr_; + if (ret == NULL) { + roc_panic("scoped release: attempt to release a null pointer"); + } + + ptr_ = NULL; + return ret; + } + +private: + typedef void (*ReleaseFunc)(void*); + + T* ptr_; + ReleaseFunc del_fn_; +}; + +} // namespace core +} // namespace roc + +#endif // ROC_CORE_SCOPED_RELEASE_H_ diff --git a/src/internal_modules/roc_core/shared_ptr.h b/src/internal_modules/roc_core/shared_ptr.h index 791fac7ef..857ece60b 100644 --- a/src/internal_modules/roc_core/shared_ptr.h +++ b/src/internal_modules/roc_core/shared_ptr.h @@ -21,14 +21,15 @@ namespace core { //! Shared ownership intrusive pointer. //! -//! @tparam T defines pointee type. It may be const. +//! @tparam T defines pointee type. //! //! @tparam OwnershipPolicy defines ownership policy. It provides methods to //! increase and decrease the reference counter embedded into object. //! //! If RefCountedOwnership is used, T should inherit RefCounted. RefCounted //! has a template parameter AllocationPolicy, and inherits from it. -//! When reference counter reaches zero, it invokes AllocationPolicy::destroy(). +//! When reference counter reaches zero, it invokes dispose() method provided +//! by the allocation policy. template class OwnershipPolicy = RefCountedOwnership> class SharedPtr { public: @@ -91,7 +92,7 @@ class SharedPtr { } //! Get underlying pointer and pass ownership to the caller. - T* release() { + T* hijack() { T* ret = ptr_; if (ret == NULL) { roc_panic("shared ptr: attempting to release a null pointer"); diff --git a/src/internal_modules/roc_fec/composer.h b/src/internal_modules/roc_fec/composer.h index ebfa759b6..78b9ff107 100644 --- a/src/internal_modules/roc_fec/composer.h +++ b/src/internal_modules/roc_fec/composer.h @@ -30,8 +30,9 @@ class Composer : public packet::IComposer, public core::NonCopyable<> { //! @remarks //! Composes FECFRAME header or footer and passes the rest to //! @p inner_composer if it's not null. - Composer(packet::IComposer* inner_composer) - : inner_composer_(inner_composer) { + Composer(packet::IComposer* inner_composer, core::IArena& arena) + : IComposer(arena) + , inner_composer_(inner_composer) { } //! Check if the object was successfully constructed. diff --git a/src/internal_modules/roc_fec/iblock_decoder.cpp b/src/internal_modules/roc_fec/iblock_decoder.cpp index 288ab776c..55e067d4b 100644 --- a/src/internal_modules/roc_fec/iblock_decoder.cpp +++ b/src/internal_modules/roc_fec/iblock_decoder.cpp @@ -11,6 +11,10 @@ namespace roc { namespace fec { +IBlockDecoder::IBlockDecoder(core::IArena& arena) + : core::ArenaAllocation(arena) { +} + IBlockDecoder::~IBlockDecoder() { } diff --git a/src/internal_modules/roc_fec/iblock_decoder.h b/src/internal_modules/roc_fec/iblock_decoder.h index 82d466e69..6c71e7536 100644 --- a/src/internal_modules/roc_fec/iblock_decoder.h +++ b/src/internal_modules/roc_fec/iblock_decoder.h @@ -20,8 +20,12 @@ namespace roc { namespace fec { //! FEC block decoder interface. -class IBlockDecoder { +class IBlockDecoder : public core::ArenaAllocation { public: + //! Initialize. + explicit IBlockDecoder(core::IArena& arena); + + //! Deinitialize. virtual ~IBlockDecoder(); //! Check if the object was successfully constructed. diff --git a/src/internal_modules/roc_fec/iblock_encoder.cpp b/src/internal_modules/roc_fec/iblock_encoder.cpp index 6f4fa763b..7914c578c 100644 --- a/src/internal_modules/roc_fec/iblock_encoder.cpp +++ b/src/internal_modules/roc_fec/iblock_encoder.cpp @@ -11,6 +11,10 @@ namespace roc { namespace fec { +IBlockEncoder::IBlockEncoder(core::IArena& arena) + : core::ArenaAllocation(arena) { +} + IBlockEncoder::~IBlockEncoder() { } diff --git a/src/internal_modules/roc_fec/iblock_encoder.h b/src/internal_modules/roc_fec/iblock_encoder.h index f0269c9a1..46cb538fc 100644 --- a/src/internal_modules/roc_fec/iblock_encoder.h +++ b/src/internal_modules/roc_fec/iblock_encoder.h @@ -20,8 +20,12 @@ namespace roc { namespace fec { //! FEC block encoder interface. -class IBlockEncoder { +class IBlockEncoder : public core::ArenaAllocation { public: + //! Initialize. + explicit IBlockEncoder(core::IArena& arena); + + //! Deinitialize. virtual ~IBlockEncoder(); //! Check if the object was successfully constructed. diff --git a/src/internal_modules/roc_fec/parser.h b/src/internal_modules/roc_fec/parser.h index c6fc2ee04..571b67d8e 100644 --- a/src/internal_modules/roc_fec/parser.h +++ b/src/internal_modules/roc_fec/parser.h @@ -28,8 +28,9 @@ class Parser : public packet::IParser, public core::NonCopyable<> { //! @remarks //! Parses FECFRAME header or footer and passes the rest to @p inner_parser //! if it's not null. - explicit Parser(packet::IParser* inner_parser) - : inner_parser_(inner_parser) { + Parser(packet::IParser* inner_parser, core::IArena& arena) + : IParser(arena) + , inner_parser_(inner_parser) { } //! Check if the object was successfully constructed. diff --git a/src/internal_modules/roc_fec/target_openfec/roc_fec/openfec_decoder.cpp b/src/internal_modules/roc_fec/target_openfec/roc_fec/openfec_decoder.cpp index f07b8eee2..9bc85b878 100644 --- a/src/internal_modules/roc_fec/target_openfec/roc_fec/openfec_decoder.cpp +++ b/src/internal_modules/roc_fec/target_openfec/roc_fec/openfec_decoder.cpp @@ -22,7 +22,8 @@ namespace fec { OpenfecDecoder::OpenfecDecoder(const CodecConfig& config, packet::PacketFactory& packet_factory, core::IArena& arena) - : sblen_(0) + : IBlockDecoder(arena) + , sblen_(0) , rblen_(0) , payload_size_(0) , max_index_(0) diff --git a/src/internal_modules/roc_fec/target_openfec/roc_fec/openfec_encoder.cpp b/src/internal_modules/roc_fec/target_openfec/roc_fec/openfec_encoder.cpp index 743f7e393..8c624232d 100644 --- a/src/internal_modules/roc_fec/target_openfec/roc_fec/openfec_encoder.cpp +++ b/src/internal_modules/roc_fec/target_openfec/roc_fec/openfec_encoder.cpp @@ -17,7 +17,8 @@ namespace fec { OpenfecEncoder::OpenfecEncoder(const CodecConfig& config, packet::PacketFactory& packet_factory, core::IArena& arena) - : sblen_(0) + : IBlockEncoder(arena) + , sblen_(0) , rblen_(0) , payload_size_(0) , of_sess_(NULL) diff --git a/src/internal_modules/roc_node/node.cpp b/src/internal_modules/roc_node/node.cpp index 889a3fd8f..cda40cbff 100644 --- a/src/internal_modules/roc_node/node.cpp +++ b/src/internal_modules/roc_node/node.cpp @@ -12,7 +12,8 @@ namespace roc { namespace node { Node::Node(Context& context) - : context_(&context) { + : core::ArenaAllocation(context.arena()) + , context_(&context) { } Node::~Node() { diff --git a/src/internal_modules/roc_node/node.h b/src/internal_modules/roc_node/node.h index 61fe5cdb7..4076143ca 100644 --- a/src/internal_modules/roc_node/node.h +++ b/src/internal_modules/roc_node/node.h @@ -20,10 +20,10 @@ namespace roc { namespace node { //! Base class for nodes. -class Node : public core::NonCopyable<> { +class Node : public core::ArenaAllocation, core::NonCopyable<> { public: //! Initialize. - Node(Context& context); + explicit Node(Context& context); //! Deinitialize. virtual ~Node(); diff --git a/src/internal_modules/roc_packet/icomposer.cpp b/src/internal_modules/roc_packet/icomposer.cpp index 96ced512d..5158f7679 100644 --- a/src/internal_modules/roc_packet/icomposer.cpp +++ b/src/internal_modules/roc_packet/icomposer.cpp @@ -11,6 +11,10 @@ namespace roc { namespace packet { +IComposer::IComposer(core::IArena& arena) + : core::ArenaAllocation(arena) { +} + IComposer::~IComposer() { } diff --git a/src/internal_modules/roc_packet/icomposer.h b/src/internal_modules/roc_packet/icomposer.h index b05562f6e..311b1ccf3 100644 --- a/src/internal_modules/roc_packet/icomposer.h +++ b/src/internal_modules/roc_packet/icomposer.h @@ -20,8 +20,12 @@ namespace roc { namespace packet { //! Packet composer interface. -class IComposer { +class IComposer : public core::ArenaAllocation { public: + //! Initialize. + explicit IComposer(core::IArena& arena); + + //! Deinitialize. virtual ~IComposer(); //! Check if the object was successfully constructed. diff --git a/src/internal_modules/roc_packet/iparser.cpp b/src/internal_modules/roc_packet/iparser.cpp index df32a1742..61ea2f49a 100644 --- a/src/internal_modules/roc_packet/iparser.cpp +++ b/src/internal_modules/roc_packet/iparser.cpp @@ -11,6 +11,10 @@ namespace roc { namespace packet { +IParser::IParser(core::IArena& arena) + : core::ArenaAllocation(arena) { +} + IParser::~IParser() { } diff --git a/src/internal_modules/roc_packet/iparser.h b/src/internal_modules/roc_packet/iparser.h index 10be78539..9f5d55a32 100644 --- a/src/internal_modules/roc_packet/iparser.h +++ b/src/internal_modules/roc_packet/iparser.h @@ -12,6 +12,7 @@ #ifndef ROC_PACKET_IPARSER_H_ #define ROC_PACKET_IPARSER_H_ +#include "roc_core/allocation_policy.h" #include "roc_core/slice.h" #include "roc_packet/packet.h" #include "roc_status/status_code.h" @@ -20,8 +21,12 @@ namespace roc { namespace packet { //! Packet parser interface. -class IParser { +class IParser : public core::ArenaAllocation { public: + //! Initialize. + explicit IParser(core::IArena& arena); + + //! Deinitialize. virtual ~IParser(); //! Check if the object was successfully constructed. diff --git a/src/internal_modules/roc_pipeline/receiver_endpoint.cpp b/src/internal_modules/roc_pipeline/receiver_endpoint.cpp index e812b8179..210eabf5f 100644 --- a/src/internal_modules/roc_pipeline/receiver_endpoint.cpp +++ b/src/internal_modules/roc_pipeline/receiver_endpoint.cpp @@ -40,7 +40,7 @@ ReceiverEndpoint::ReceiverEndpoint(address::Protocol proto, case address::Proto_RTP: case address::Proto_RTP_LDPC_Source: case address::Proto_RTP_RS8M_Source: - rtp_parser_.reset(new (rtp_parser_) rtp::Parser(encoding_map, NULL)); + rtp_parser_.reset(new (rtp_parser_) rtp::Parser(NULL, encoding_map, arena)); if ((init_status_ = rtp_parser_->init_status()) != status::StatusOK) { return; } @@ -53,9 +53,8 @@ ReceiverEndpoint::ReceiverEndpoint(address::Protocol proto, switch (proto) { case address::Proto_RTP_LDPC_Source: fec_parser_.reset( - new (arena) - fec::Parser(parser), - arena); + new (arena) fec::Parser( + parser, arena)); if (!fec_parser_) { init_status_ = status::StatusNoMem; return; @@ -67,9 +66,8 @@ ReceiverEndpoint::ReceiverEndpoint(address::Protocol proto, break; case address::Proto_LDPC_Repair: fec_parser_.reset( - new (arena) - fec::Parser(parser), - arena); + new (arena) fec::Parser( + parser, arena)); if (!fec_parser_) { init_status_ = status::StatusNoMem; return; @@ -80,10 +78,9 @@ ReceiverEndpoint::ReceiverEndpoint(address::Protocol proto, parser = fec_parser_.get(); break; case address::Proto_RTP_RS8M_Source: - fec_parser_.reset( - new (arena) - fec::Parser(parser), - arena); + fec_parser_.reset(new (arena) + fec::Parser( + parser, arena)); if (!fec_parser_) { init_status_ = status::StatusNoMem; return; @@ -94,10 +91,9 @@ ReceiverEndpoint::ReceiverEndpoint(address::Protocol proto, parser = fec_parser_.get(); break; case address::Proto_RS8M_Repair: - fec_parser_.reset( - new (arena) - fec::Parser(parser), - arena); + fec_parser_.reset(new (arena) + fec::Parser( + parser, arena)); if (!fec_parser_) { init_status_ = status::StatusNoMem; return; @@ -113,13 +109,13 @@ ReceiverEndpoint::ReceiverEndpoint(address::Protocol proto, switch (proto) { case address::Proto_RTCP: - rtcp_composer_.reset(new (rtcp_composer_) rtcp::Composer()); + rtcp_composer_.reset(new (rtcp_composer_) rtcp::Composer(arena)); if ((init_status_ = rtcp_composer_->init_status()) != status::StatusOK) { return; } composer = rtcp_composer_.get(); - rtcp_parser_.reset(new (rtcp_parser_) rtcp::Parser()); + rtcp_parser_.reset(new (rtcp_parser_) rtcp::Parser(arena)); if ((init_status_ = rtcp_parser_->init_status()) != status::StatusOK) { return; } diff --git a/src/internal_modules/roc_pipeline/receiver_loop.cpp b/src/internal_modules/roc_pipeline/receiver_loop.cpp index ad6d1d2fa..f26db4955 100644 --- a/src/internal_modules/roc_pipeline/receiver_loop.cpp +++ b/src/internal_modules/roc_pipeline/receiver_loop.cpp @@ -95,12 +95,14 @@ ReceiverLoop::ReceiverLoop(IPipelineTaskScheduler& scheduler, core::IPool& frame_pool, core::IPool& frame_buffer_pool, core::IArena& arena) - : PipelineLoop(scheduler, + : IDevice(arena) + , PipelineLoop(scheduler, source_config.pipeline_loop, source_config.common.output_sample_spec, frame_pool, frame_buffer_pool, Dir_ReadFrames) + , ISource(arena) , source_(source_config, processor_map, encoding_map, @@ -124,6 +126,9 @@ ReceiverLoop::ReceiverLoop(IPipelineTaskScheduler& scheduler, init_status_ = status::StatusOK; } +ReceiverLoop::~ReceiverLoop() { +} + status::StatusCode ReceiverLoop::init_status() const { return init_status_; } @@ -194,12 +199,6 @@ bool ReceiverLoop::has_clock() const { return source_.has_clock(); } -status::StatusCode ReceiverLoop::close() { - core::Mutex::Lock lock(source_mutex_); - - return source_.close(); -} - status::StatusCode ReceiverLoop::rewind() { core::Mutex::Lock lock(source_mutex_); @@ -251,6 +250,16 @@ status::StatusCode ReceiverLoop::read(audio::Frame& frame, return code; } +status::StatusCode ReceiverLoop::close() { + core::Mutex::Lock lock(source_mutex_); + + return source_.close(); +} + +void ReceiverLoop::dispose() { + arena().dispose_object(*this); +} + core::nanoseconds_t ReceiverLoop::timestamp_imp() const { return core::timestamp(core::ClockMonotonic); } diff --git a/src/internal_modules/roc_pipeline/receiver_loop.h b/src/internal_modules/roc_pipeline/receiver_loop.h index ca66fd84b..5faeef0f9 100644 --- a/src/internal_modules/roc_pipeline/receiver_loop.h +++ b/src/internal_modules/roc_pipeline/receiver_loop.h @@ -131,6 +131,7 @@ class ReceiverLoop : public PipelineLoop, private sndio::ISource { core::IPool& frame_pool, core::IPool& frame_buffer_pool, core::IArena& arena); + ~ReceiverLoop(); //! Check if the pipeline was successfully constructed. status::StatusCode init_status() const; @@ -153,12 +154,13 @@ class ReceiverLoop : public PipelineLoop, private sndio::ISource { virtual bool has_latency() const; virtual core::nanoseconds_t latency() const; virtual bool has_clock() const; - virtual status::StatusCode close(); virtual status::StatusCode rewind(); virtual void reclock(core::nanoseconds_t timestamp); virtual status::StatusCode read(audio::Frame& frame, packet::stream_timestamp_t duration, audio::FrameReadMode mode); + virtual status::StatusCode close(); + virtual void dispose(); // Methods of PipelineLoop virtual core::nanoseconds_t timestamp_imp() const; diff --git a/src/internal_modules/roc_pipeline/receiver_session.cpp b/src/internal_modules/roc_pipeline/receiver_session.cpp index 3c887f9c7..e45a80d61 100644 --- a/src/internal_modules/roc_pipeline/receiver_session.cpp +++ b/src/internal_modules/roc_pipeline/receiver_session.cpp @@ -70,8 +70,7 @@ ReceiverSession::ReceiverSession(const ReceiverSessionConfig& session_config, // packets stored in the queues. packet::IReader* pkt_reader = source_queue_.get(); - payload_decoder_.reset(pkt_encoding->new_decoder(arena, pkt_encoding->sample_spec), - arena); + payload_decoder_.reset(pkt_encoding->new_decoder(pkt_encoding->sample_spec, arena)); if (!payload_decoder_) { init_status_ = status::StatusNoMem; return; @@ -124,8 +123,7 @@ ReceiverSession::ReceiverSession(const ReceiverSessionConfig& session_config, // Sub-pipeline with chained readers for packets after repairing losses. fec_decoder_.reset(fec::CodecMap::instance().new_block_decoder( - session_config.fec_decoder, packet_factory, arena), - arena); + session_config.fec_decoder, packet_factory, arena)); if (!fec_decoder_) { init_status_ = status::StatusNoMem; return; @@ -134,7 +132,7 @@ ReceiverSession::ReceiverSession(const ReceiverSessionConfig& session_config, return; } - fec_parser_.reset(new (fec_parser_) rtp::Parser(encoding_map, NULL)); + fec_parser_.reset(new (fec_parser_) rtp::Parser(NULL, encoding_map, arena)); if ((init_status_ = fec_parser_->init_status()) != status::StatusOK) { return; } @@ -181,9 +179,8 @@ ReceiverSession::ReceiverSession(const ReceiverSessionConfig& session_config, frm_reader = depacketizer_.get(); if (session_config.plc.backend != audio::PlcBackend_None) { - plc_.reset( - processor_map.new_plc(arena, frame_factory, session_config.plc, out_spec), - arena); + plc_.reset(processor_map.new_plc(session_config.plc, out_spec, frame_factory, + arena)); if (!plc_) { init_status_ = status::StatusNoMem; return; @@ -241,8 +238,8 @@ ReceiverSession::ReceiverSession(const ReceiverSessionConfig& session_config, audio::Sample_RawFormat, common_config.output_sample_spec.channel_set()); - resampler_.reset(processor_map.new_resampler( - arena, frame_factory, session_config.resampler, in_spec, out_spec)); + resampler_.reset(processor_map.new_resampler(session_config.resampler, in_spec, + out_spec, frame_factory, arena)); if (!resampler_) { init_status_ = status::StatusNoMem; return; diff --git a/src/internal_modules/roc_pipeline/receiver_source.cpp b/src/internal_modules/roc_pipeline/receiver_source.cpp index f02f321a0..eba1253c3 100644 --- a/src/internal_modules/roc_pipeline/receiver_source.cpp +++ b/src/internal_modules/roc_pipeline/receiver_source.cpp @@ -22,7 +22,9 @@ ReceiverSource::ReceiverSource(const ReceiverSourceConfig& source_config, core::IPool& frame_pool, core::IPool& frame_buffer_pool, core::IArena& arena) - : source_config_(source_config) + : IDevice(arena) + , ISource(arena) + , source_config_(source_config) , processor_map_(processor_map) , encoding_map_(encoding_map) , packet_factory_(packet_pool, packet_buffer_pool) @@ -50,7 +52,7 @@ ReceiverSource::ReceiverSource(const ReceiverSourceConfig& source_config, audio::Sample_RawFormat, source_config_.common.output_sample_spec.channel_set()); - mixer_.reset(new (mixer_) audio::Mixer(frame_factory_, arena, inout_spec, true)); + mixer_.reset(new (mixer_) audio::Mixer(inout_spec, true, frame_factory_, arena)); if ((init_status_ = mixer_->init_status()) != status::StatusOK) { return; } @@ -231,18 +233,6 @@ bool ReceiverSource::has_clock() const { return source_config_.common.enable_cpu_clock; } -status::StatusCode ReceiverSource::close() { - roc_panic_if(init_status_ != status::StatusOK); - - if (state_tracker_.is_closed()) { - return status::StatusBadState; - } - - state_tracker_.set_closed(); - - return status::StatusOK; -} - status::StatusCode ReceiverSource::rewind() { roc_panic_if(init_status_ != status::StatusOK); @@ -288,5 +278,21 @@ status::StatusCode ReceiverSource::read(audio::Frame& frame, return code; } +status::StatusCode ReceiverSource::close() { + roc_panic_if(init_status_ != status::StatusOK); + + if (state_tracker_.is_closed()) { + return status::StatusBadState; + } + + state_tracker_.set_closed(); + + return status::StatusOK; +} + +void ReceiverSource::dispose() { + arena_.dispose_object(*this); +} + } // namespace pipeline } // namespace roc diff --git a/src/internal_modules/roc_pipeline/receiver_source.h b/src/internal_modules/roc_pipeline/receiver_source.h index 012d70490..5d6d7b1df 100644 --- a/src/internal_modules/roc_pipeline/receiver_source.h +++ b/src/internal_modules/roc_pipeline/receiver_source.h @@ -109,9 +109,6 @@ class ReceiverSource : public sndio::ISource, public core::NonCopyable<> { //! Check if the source has own clock. virtual bool has_clock() const; - //! Explicitly close the source. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Restart reading from beginning. virtual ROC_ATTR_NODISCARD status::StatusCode rewind(); @@ -126,6 +123,12 @@ class ReceiverSource : public sndio::ISource, public core::NonCopyable<> { packet::stream_timestamp_t duration, audio::FrameReadMode mode); + //! Explicitly close the source. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: ReceiverSourceConfig source_config_; diff --git a/src/internal_modules/roc_pipeline/sender_endpoint.cpp b/src/internal_modules/roc_pipeline/sender_endpoint.cpp index 820abd1e6..cf8748a69 100644 --- a/src/internal_modules/roc_pipeline/sender_endpoint.cpp +++ b/src/internal_modules/roc_pipeline/sender_endpoint.cpp @@ -37,7 +37,7 @@ SenderEndpoint::SenderEndpoint(address::Protocol proto, case address::Proto_RTP: case address::Proto_RTP_LDPC_Source: case address::Proto_RTP_RS8M_Source: - rtp_composer_.reset(new (rtp_composer_) rtp::Composer(NULL)); + rtp_composer_.reset(new (rtp_composer_) rtp::Composer(NULL, arena)); if ((init_status_ = rtp_composer_->init_status()) != status::StatusOK) { return; } @@ -52,8 +52,7 @@ SenderEndpoint::SenderEndpoint(address::Protocol proto, fec_composer_.reset( new (arena) fec::Composer( - composer), - arena); + composer, arena)); if (!fec_composer_) { init_status_ = status::StatusNoMem; return; @@ -67,8 +66,7 @@ SenderEndpoint::SenderEndpoint(address::Protocol proto, fec_composer_.reset( new (arena) fec::Composer( - composer), - arena); + composer, arena)); if (!fec_composer_) { init_status_ = status::StatusNoMem; return; @@ -80,9 +78,8 @@ SenderEndpoint::SenderEndpoint(address::Protocol proto, break; case address::Proto_RTP_RS8M_Source: fec_composer_.reset( - new (arena) - fec::Composer(composer), - arena); + new (arena) fec::Composer( + composer, arena)); if (!fec_composer_) { init_status_ = status::StatusNoMem; return; @@ -94,9 +91,8 @@ SenderEndpoint::SenderEndpoint(address::Protocol proto, break; case address::Proto_RS8M_Repair: fec_composer_.reset( - new (arena) - fec::Composer(composer), - arena); + new (arena) fec::Composer( + composer, arena)); if (!fec_composer_) { init_status_ = status::StatusNoMem; return; @@ -112,13 +108,13 @@ SenderEndpoint::SenderEndpoint(address::Protocol proto, switch (proto) { case address::Proto_RTCP: - rtcp_composer_.reset(new (rtcp_composer_) rtcp::Composer()); + rtcp_composer_.reset(new (rtcp_composer_) rtcp::Composer(arena)); if ((init_status_ = rtcp_composer_->init_status()) != status::StatusOK) { return; } composer = rtcp_composer_.get(); - rtcp_parser_.reset(new (rtcp_parser_) rtcp::Parser()); + rtcp_parser_.reset(new (rtcp_parser_) rtcp::Parser(arena)); if ((init_status_ = rtcp_parser_->init_status()) != status::StatusOK) { return; } diff --git a/src/internal_modules/roc_pipeline/sender_loop.cpp b/src/internal_modules/roc_pipeline/sender_loop.cpp index 3cccb12a4..eaefb1a35 100644 --- a/src/internal_modules/roc_pipeline/sender_loop.cpp +++ b/src/internal_modules/roc_pipeline/sender_loop.cpp @@ -94,12 +94,14 @@ SenderLoop::SenderLoop(IPipelineTaskScheduler& scheduler, core::IPool& frame_pool, core::IPool& frame_buffer_pool, core::IArena& arena) - : PipelineLoop(scheduler, + : IDevice(arena) + , PipelineLoop(scheduler, sink_config.pipeline_loop, sink_config.input_sample_spec, frame_pool, frame_buffer_pool, Dir_WriteFrames) + , ISink(arena) , sink_(sink_config, processor_map, encoding_map, @@ -124,6 +126,9 @@ SenderLoop::SenderLoop(IPipelineTaskScheduler& scheduler, init_status_ = status::StatusOK; } +SenderLoop::~SenderLoop() { +} + status::StatusCode SenderLoop::init_status() const { return init_status_; } @@ -194,12 +199,6 @@ bool SenderLoop::has_clock() const { return sink_.has_clock(); } -status::StatusCode SenderLoop::close() { - core::Mutex::Lock lock(sink_mutex_); - - return sink_.close(); -} - status::StatusCode SenderLoop::write(audio::Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); @@ -238,6 +237,16 @@ status::StatusCode SenderLoop::flush() { return sink_.flush(); } +status::StatusCode SenderLoop::close() { + core::Mutex::Lock lock(sink_mutex_); + + return sink_.close(); +} + +void SenderLoop::dispose() { + arena().dispose_object(*this); +} + core::nanoseconds_t SenderLoop::timestamp_imp() const { return core::timestamp(core::ClockMonotonic); } diff --git a/src/internal_modules/roc_pipeline/sender_loop.h b/src/internal_modules/roc_pipeline/sender_loop.h index e82033004..681c1b9ad 100644 --- a/src/internal_modules/roc_pipeline/sender_loop.h +++ b/src/internal_modules/roc_pipeline/sender_loop.h @@ -129,6 +129,7 @@ class SenderLoop : public PipelineLoop, private sndio::ISink { core::IPool& frame_pool, core::IPool& frame_buffer_pool, core::IArena& arena); + ~SenderLoop(); //! Check if the pipeline was successfully constructed. status::StatusCode init_status() const; @@ -151,9 +152,10 @@ class SenderLoop : public PipelineLoop, private sndio::ISink { virtual bool has_latency() const; virtual core::nanoseconds_t latency() const; virtual bool has_clock() const; - virtual status::StatusCode close(); virtual status::StatusCode write(audio::Frame& frame); virtual ROC_ATTR_NODISCARD status::StatusCode flush(); + virtual status::StatusCode close(); + virtual void dispose(); // Methods of PipelineLoop virtual core::nanoseconds_t timestamp_imp() const; diff --git a/src/internal_modules/roc_pipeline/sender_session.cpp b/src/internal_modules/roc_pipeline/sender_session.cpp index d59589b4f..1063083df 100644 --- a/src/internal_modules/roc_pipeline/sender_session.cpp +++ b/src/internal_modules/roc_pipeline/sender_session.cpp @@ -98,8 +98,7 @@ SenderSession::create_transport_pipeline(SenderEndpoint* source_endpoint, } fec_encoder_.reset(fec::CodecMap::instance().new_block_encoder( - sink_config_.fec_encoder, packet_factory_, arena_), - arena_); + sink_config_.fec_encoder, packet_factory_, arena_)); if (!fec_encoder_) { return status::StatusNoMem; } @@ -124,8 +123,7 @@ SenderSession::create_transport_pipeline(SenderEndpoint* source_endpoint, } pkt_writer = timestamp_extractor_.get(); - payload_encoder_.reset(pkt_encoding->new_encoder(arena_, pkt_encoding->sample_spec), - arena_); + payload_encoder_.reset(pkt_encoding->new_encoder(pkt_encoding->sample_spec, arena_)); if (!payload_encoder_) { return status::StatusNoMem; } @@ -188,8 +186,8 @@ SenderSession::create_transport_pipeline(SenderEndpoint* source_endpoint, audio::Sample_RawFormat, sink_config_.input_sample_spec.channel_set()); - resampler_.reset(processor_map_.new_resampler( - arena_, frame_factory_, sink_config_.resampler, in_spec, out_spec)); + resampler_.reset(processor_map_.new_resampler(sink_config_.resampler, in_spec, + out_spec, frame_factory_, arena_)); if (!resampler_) { return status::StatusNoMem; } diff --git a/src/internal_modules/roc_pipeline/sender_sink.cpp b/src/internal_modules/roc_pipeline/sender_sink.cpp index 0498431e7..419a65f7d 100644 --- a/src/internal_modules/roc_pipeline/sender_sink.cpp +++ b/src/internal_modules/roc_pipeline/sender_sink.cpp @@ -22,7 +22,9 @@ SenderSink::SenderSink(const SenderSinkConfig& sink_config, core::IPool& frame_pool, core::IPool& frame_buffer_pool, core::IArena& arena) - : sink_config_(sink_config) + : IDevice(arena) + , ISink(arena) + , sink_config_(sink_config) , processor_map_(processor_map) , encoding_map_(encoding_map) , packet_factory_(packet_pool, packet_buffer_pool) @@ -49,7 +51,7 @@ SenderSink::SenderSink(const SenderSinkConfig& sink_config, audio::Sample_RawFormat, sink_config_.input_sample_spec.channel_set()); - fanout_.reset(new (fanout_) audio::Fanout(frame_factory_, arena_, inout_spec)); + fanout_.reset(new (fanout_) audio::Fanout(inout_spec, frame_factory_, arena_)); if ((init_status_ = fanout_->init_status()) != status::StatusOK) { return; } @@ -230,18 +232,6 @@ bool SenderSink::has_clock() const { return sink_config_.enable_cpu_clock; } -status::StatusCode SenderSink::close() { - roc_panic_if(init_status_ != status::StatusOK); - - if (state_tracker_.is_closed()) { - return status::StatusBadState; - } - - state_tracker_.set_closed(); - - return status::StatusOK; -} - status::StatusCode SenderSink::write(audio::Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); @@ -264,5 +254,21 @@ status::StatusCode SenderSink::flush() { return status::StatusOK; } +status::StatusCode SenderSink::close() { + roc_panic_if(init_status_ != status::StatusOK); + + if (state_tracker_.is_closed()) { + return status::StatusBadState; + } + + state_tracker_.set_closed(); + + return status::StatusOK; +} + +void SenderSink::dispose() { + arena_.dispose_object(*this); +} + } // namespace pipeline } // namespace roc diff --git a/src/internal_modules/roc_pipeline/sender_sink.h b/src/internal_modules/roc_pipeline/sender_sink.h index 532068bec..6bef71e97 100644 --- a/src/internal_modules/roc_pipeline/sender_sink.h +++ b/src/internal_modules/roc_pipeline/sender_sink.h @@ -53,7 +53,6 @@ class SenderSink : public sndio::ISink, public core::NonCopyable<> { core::IPool& frame_pool, core::IPool& frame_buffer_pool, core::IArena& arena); - ~SenderSink(); //! Check if the pipeline was successfully constructed. @@ -109,15 +108,18 @@ class SenderSink : public sndio::ISink, public core::NonCopyable<> { //! Check if the sink has own clock. virtual bool has_clock() const; - //! Explicitly close the sink. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Write frame. virtual ROC_ATTR_NODISCARD status::StatusCode write(audio::Frame& frame); //! Flush buffered data, if any. virtual ROC_ATTR_NODISCARD status::StatusCode flush(); + //! Explicitly close the sink. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: SenderSinkConfig sink_config_; diff --git a/src/internal_modules/roc_pipeline/transcoder_sink.cpp b/src/internal_modules/roc_pipeline/transcoder_sink.cpp index af2b2efd1..4109f6257 100644 --- a/src/internal_modules/roc_pipeline/transcoder_sink.cpp +++ b/src/internal_modules/roc_pipeline/transcoder_sink.cpp @@ -20,7 +20,9 @@ TranscoderSink::TranscoderSink(const TranscoderConfig& config, core::IPool& frame_pool, core::IPool& frame_buffer_pool, core::IArena& arena) - : frame_factory_(frame_pool, frame_buffer_pool) + : IDevice(arena) + , ISink(arena) + , frame_factory_(frame_pool, frame_buffer_pool) , frame_writer_(NULL) , config_(config) , init_status_(status::NoStatus) { @@ -63,8 +65,8 @@ TranscoderSink::TranscoderSink(const TranscoderConfig& config, audio::Sample_RawFormat, config_.input_sample_spec.channel_set()); - resampler_.reset(processor_map.new_resampler( - arena, frame_factory_, config_.resampler, from_spec, to_spec)); + resampler_.reset(processor_map.new_resampler(config_.resampler, from_spec, + to_spec, frame_factory_, arena)); if (!resampler_) { init_status_ = status::StatusNoMem; return; @@ -126,10 +128,6 @@ bool TranscoderSink::has_clock() const { return false; } -status::StatusCode TranscoderSink::close() { - return status::StatusOK; -} - status::StatusCode TranscoderSink::write(audio::Frame& frame) { roc_panic_if(init_status_ != status::StatusOK); @@ -140,5 +138,13 @@ status::StatusCode TranscoderSink::flush() { return status::StatusOK; } +status::StatusCode TranscoderSink::close() { + return status::StatusOK; +} + +void TranscoderSink::dispose() { + arena().dispose_object(*this); +} + } // namespace pipeline } // namespace roc diff --git a/src/internal_modules/roc_pipeline/transcoder_sink.h b/src/internal_modules/roc_pipeline/transcoder_sink.h index 85677896d..6a4388207 100644 --- a/src/internal_modules/roc_pipeline/transcoder_sink.h +++ b/src/internal_modules/roc_pipeline/transcoder_sink.h @@ -66,15 +66,18 @@ class TranscoderSink : public sndio::ISink, public core::NonCopyable<> { //! Check if the sink has own clock. virtual bool has_clock() const; - //! Explicitly close the sink. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Write frame. virtual ROC_ATTR_NODISCARD status::StatusCode write(audio::Frame& frame); //! Flush buffered data, if any. virtual ROC_ATTR_NODISCARD status::StatusCode flush(); + //! Explicitly close the sink. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: audio::FrameFactory frame_factory_; diff --git a/src/internal_modules/roc_pipeline/transcoder_source.cpp b/src/internal_modules/roc_pipeline/transcoder_source.cpp index 1c135edc1..6ee9f6e73 100644 --- a/src/internal_modules/roc_pipeline/transcoder_source.cpp +++ b/src/internal_modules/roc_pipeline/transcoder_source.cpp @@ -20,7 +20,9 @@ TranscoderSource::TranscoderSource(const TranscoderConfig& config, core::IPool& frame_pool, core::IPool& frame_buffer_pool, core::IArena& arena) - : frame_factory_(frame_pool, frame_buffer_pool) + : IDevice(arena) + , ISource(arena) + , frame_factory_(frame_pool, frame_buffer_pool) , input_source_(input_source) , frame_reader_(NULL) , config_(config) @@ -61,8 +63,8 @@ TranscoderSource::TranscoderSource(const TranscoderConfig& config, audio::Sample_RawFormat, config_.output_sample_spec.channel_set()); - resampler_.reset(processor_map.new_resampler( - arena, frame_factory_, config_.resampler, from_spec, to_spec)); + resampler_.reset(processor_map.new_resampler(config_.resampler, from_spec, + to_spec, frame_factory_, arena)); if (!resampler_) { init_status_ = status::StatusNoMem; return; @@ -140,10 +142,6 @@ bool TranscoderSource::has_clock() const { return input_source_.has_clock(); } -status::StatusCode TranscoderSource::close() { - return input_source_.close(); -} - status::StatusCode TranscoderSource::rewind() { return input_source_.rewind(); } @@ -160,5 +158,13 @@ status::StatusCode TranscoderSource::read(audio::Frame& frame, return frame_reader_->read(frame, duration, mode); } +status::StatusCode TranscoderSource::close() { + return input_source_.close(); +} + +void TranscoderSource::dispose() { + arena().dispose_object(*this); +} + } // namespace pipeline } // namespace roc diff --git a/src/internal_modules/roc_pipeline/transcoder_source.h b/src/internal_modules/roc_pipeline/transcoder_source.h index 829cab600..a34d82f27 100644 --- a/src/internal_modules/roc_pipeline/transcoder_source.h +++ b/src/internal_modules/roc_pipeline/transcoder_source.h @@ -77,9 +77,6 @@ class TranscoderSource : public sndio::ISource, public core::NonCopyable<> { //! Check if the source has own clock. virtual bool has_clock() const; - //! Explicitly close the source. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Restart reading from beginning. virtual ROC_ATTR_NODISCARD status::StatusCode rewind(); @@ -92,6 +89,12 @@ class TranscoderSource : public sndio::ISource, public core::NonCopyable<> { packet::stream_timestamp_t duration, audio::FrameReadMode mode); + //! Explicitly close the source. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: audio::FrameFactory frame_factory_; diff --git a/src/internal_modules/roc_rtcp/composer.cpp b/src/internal_modules/roc_rtcp/composer.cpp index e2b9eabd9..eb53c0d85 100644 --- a/src/internal_modules/roc_rtcp/composer.cpp +++ b/src/internal_modules/roc_rtcp/composer.cpp @@ -14,7 +14,8 @@ namespace roc { namespace rtcp { -Composer::Composer() { +Composer::Composer(core::IArena& arena) + : IComposer(arena) { } status::StatusCode Composer::init_status() const { diff --git a/src/internal_modules/roc_rtcp/composer.h b/src/internal_modules/roc_rtcp/composer.h index 72763ba22..8af74e5e7 100644 --- a/src/internal_modules/roc_rtcp/composer.h +++ b/src/internal_modules/roc_rtcp/composer.h @@ -27,7 +27,7 @@ namespace rtcp { class Composer : public packet::IComposer, public core::NonCopyable<> { public: //! Initialization. - Composer(); + explicit Composer(core::IArena& arena); //! Check if the object was successfully constructed. virtual status::StatusCode init_status() const; diff --git a/src/internal_modules/roc_rtcp/parser.cpp b/src/internal_modules/roc_rtcp/parser.cpp index 5887a273b..94c0e4cdb 100644 --- a/src/internal_modules/roc_rtcp/parser.cpp +++ b/src/internal_modules/roc_rtcp/parser.cpp @@ -12,7 +12,8 @@ namespace roc { namespace rtcp { -Parser::Parser() { +Parser::Parser(core::IArena& arena) + : IParser(arena) { } status::StatusCode Parser::init_status() const { diff --git a/src/internal_modules/roc_rtcp/parser.h b/src/internal_modules/roc_rtcp/parser.h index 9d4e322e0..81e4f9da8 100644 --- a/src/internal_modules/roc_rtcp/parser.h +++ b/src/internal_modules/roc_rtcp/parser.h @@ -27,7 +27,7 @@ namespace rtcp { class Parser : public packet::IParser, public core::NonCopyable<> { public: //! Initialization. - Parser(); + explicit Parser(core::IArena& arena); //! Check if the object was successfully constructed. virtual status::StatusCode init_status() const; diff --git a/src/internal_modules/roc_rtp/composer.cpp b/src/internal_modules/roc_rtp/composer.cpp index ccc18a480..4ab52cc96 100644 --- a/src/internal_modules/roc_rtp/composer.cpp +++ b/src/internal_modules/roc_rtp/composer.cpp @@ -15,8 +15,9 @@ namespace roc { namespace rtp { -Composer::Composer(packet::IComposer* inner_composer) - : inner_composer_(inner_composer) { +Composer::Composer(packet::IComposer* inner_composer, core::IArena& arena) + : IComposer(arena) + , inner_composer_(inner_composer) { } status::StatusCode Composer::init_status() const { diff --git a/src/internal_modules/roc_rtp/composer.h b/src/internal_modules/roc_rtp/composer.h index f4c906c7c..cce2a04dd 100644 --- a/src/internal_modules/roc_rtp/composer.h +++ b/src/internal_modules/roc_rtp/composer.h @@ -25,7 +25,7 @@ class Composer : public packet::IComposer, public core::NonCopyable<> { //! Initialization. //! @remarks //! If @p inner_composer is not NULL, it is used to compose the packet payload. - Composer(packet::IComposer* inner_composer); + Composer(packet::IComposer* inner_composer, core::IArena& arena); //! Check if the object was successfully constructed. virtual status::StatusCode init_status() const; diff --git a/src/internal_modules/roc_rtp/encoding.h b/src/internal_modules/roc_rtp/encoding.h index 51575cbef..373ffeb81 100644 --- a/src/internal_modules/roc_rtp/encoding.h +++ b/src/internal_modules/roc_rtp/encoding.h @@ -35,12 +35,12 @@ struct Encoding { unsigned packet_flags; //! Create frame encoder. - audio::IFrameEncoder* (*new_encoder)(core::IArena& arena, - const audio::SampleSpec& sample_spec); + audio::IFrameEncoder* (*new_encoder)(const audio::SampleSpec& sample_spec, + core::IArena& arena); //! Create frame decoder. - audio::IFrameDecoder* (*new_decoder)(core::IArena& arena, - const audio::SampleSpec& sample_spec); + audio::IFrameDecoder* (*new_decoder)(const audio::SampleSpec& sample_spec, + core::IArena& arena); //! Initialize. Encoding() diff --git a/src/internal_modules/roc_rtp/parser.cpp b/src/internal_modules/roc_rtp/parser.cpp index 868d0af8a..ea7b1d88b 100644 --- a/src/internal_modules/roc_rtp/parser.cpp +++ b/src/internal_modules/roc_rtp/parser.cpp @@ -13,8 +13,11 @@ namespace roc { namespace rtp { -Parser::Parser(const EncodingMap& encoding_map, packet::IParser* inner_parser) - : encoding_map_(encoding_map) +Parser::Parser(packet::IParser* inner_parser, + const EncodingMap& encoding_map, + core::IArena& arena) + : IParser(arena) + , encoding_map_(encoding_map) , inner_parser_(inner_parser) { } diff --git a/src/internal_modules/roc_rtp/parser.h b/src/internal_modules/roc_rtp/parser.h index b99669f23..7b5894379 100644 --- a/src/internal_modules/roc_rtp/parser.h +++ b/src/internal_modules/roc_rtp/parser.h @@ -29,7 +29,9 @@ class Parser : public packet::IParser, public core::NonCopyable<> { //! payload type //! - if @p inner_parser is not NULL, it is used to parse the //! packet payload - Parser(const EncodingMap& encoding_map, packet::IParser* inner_parser); + Parser(packet::IParser* inner_parser, + const EncodingMap& encoding_map, + core::IArena& arena); //! Check if the object was successfully constructed. virtual status::StatusCode init_status() const; diff --git a/src/internal_modules/roc_sndio/backend_dispatcher.cpp b/src/internal_modules/roc_sndio/backend_dispatcher.cpp index 612366de2..d0d2026d2 100644 --- a/src/internal_modules/roc_sndio/backend_dispatcher.cpp +++ b/src/internal_modules/roc_sndio/backend_dispatcher.cpp @@ -80,7 +80,7 @@ status::StatusCode BackendDispatcher::open_default_sink(const IoConfig& io_confi roc_panic_if_msg(!device || device->type() != DeviceType_Sink || !device->to_sink(), "backend dispatcher: unexpected device"); - result.reset(device->to_sink(), arena_); + result.reset(device->to_sink()); return status::StatusOK; } @@ -99,7 +99,7 @@ BackendDispatcher::open_default_source(const IoConfig& io_config, || !device->to_source(), "backend dispatcher: unexpected device"); - result.reset(device->to_source(), arena_); + result.reset(device->to_source()); return status::StatusOK; } @@ -125,7 +125,7 @@ status::StatusCode BackendDispatcher::open_sink(const address::IoUri& uri, roc_panic_if_msg(!device || device->type() != DeviceType_Sink || !device->to_sink(), "backend dispatcher: unexpected device"); - result.reset(device->to_sink(), arena_); + result.reset(device->to_sink()); return status::StatusOK; } @@ -152,7 +152,7 @@ status::StatusCode BackendDispatcher::open_source(const address::IoUri& uri, || !device->to_source(), "backend dispatcher: unexpected device"); - result.reset(device->to_source(), arena_); + result.reset(device->to_source()); return status::StatusOK; } diff --git a/src/internal_modules/roc_sndio/idevice.cpp b/src/internal_modules/roc_sndio/idevice.cpp index a5c2e6cf7..3f5ace875 100644 --- a/src/internal_modules/roc_sndio/idevice.cpp +++ b/src/internal_modules/roc_sndio/idevice.cpp @@ -12,6 +12,10 @@ namespace roc { namespace sndio { +IDevice::IDevice(core::IArena& arena) + : core::ArenaAllocation(arena) { +} + IDevice::~IDevice() { } diff --git a/src/internal_modules/roc_sndio/idevice.h b/src/internal_modules/roc_sndio/idevice.h index c9a0ebf2f..98ba2e80f 100644 --- a/src/internal_modules/roc_sndio/idevice.h +++ b/src/internal_modules/roc_sndio/idevice.h @@ -39,8 +39,12 @@ class ISource; //! sndio::IoPump is a class that copies stream from ISource to ISink //! regardless of the device kind, e.g. from file to network sender, //! or from network receiver to speakers. -class IDevice { +class IDevice : public core::ArenaAllocation { public: + //! Initialize. + explicit IDevice(core::IArena& arena); + + //! Deinitialize. virtual ~IDevice(); //! Get device type (sink or source). @@ -124,6 +128,13 @@ class IDevice { //! If this method is not called before the destructor, it's called //! automatically, but you won't know if error happened. virtual ROC_ATTR_NODISCARD status::StatusCode close() = 0; + + //! Destroy object and return memory to arena. + //! @remarks + //! Since IDevice uses virtual inheritance, we force all derived classes + //! to override ArenaAllocation::dispose() to ensure they pass correct + //! pointer to this to IArena::dispose_object(). + virtual void dispose() = 0; }; } // namespace sndio diff --git a/src/internal_modules/roc_sndio/isink.cpp b/src/internal_modules/roc_sndio/isink.cpp index b3925f101..52e0f255e 100644 --- a/src/internal_modules/roc_sndio/isink.cpp +++ b/src/internal_modules/roc_sndio/isink.cpp @@ -11,6 +11,10 @@ namespace roc { namespace sndio { +ISink::ISink(core::IArena& arena) + : IDevice(arena) { +} + ISink::~ISink() { } diff --git a/src/internal_modules/roc_sndio/isink.h b/src/internal_modules/roc_sndio/isink.h index 14406bc7f..9e48b9f6e 100644 --- a/src/internal_modules/roc_sndio/isink.h +++ b/src/internal_modules/roc_sndio/isink.h @@ -22,6 +22,10 @@ namespace sndio { //! Sink interface. class ISink : virtual public IDevice, public audio::IFrameWriter { public: + //! Initialize. + explicit ISink(core::IArena& arena); + + //! Deinitialize. virtual ~ISink(); //! Flush buffered data, if any. diff --git a/src/internal_modules/roc_sndio/isource.cpp b/src/internal_modules/roc_sndio/isource.cpp index 60af4a7fd..9b55ea764 100644 --- a/src/internal_modules/roc_sndio/isource.cpp +++ b/src/internal_modules/roc_sndio/isource.cpp @@ -12,6 +12,10 @@ namespace roc { namespace sndio { +ISource::ISource(core::IArena& arena) + : IDevice(arena) { +} + ISource::~ISource() { } diff --git a/src/internal_modules/roc_sndio/isource.h b/src/internal_modules/roc_sndio/isource.h index 9724161b1..17c0c88cd 100644 --- a/src/internal_modules/roc_sndio/isource.h +++ b/src/internal_modules/roc_sndio/isource.h @@ -22,6 +22,10 @@ namespace sndio { //! Source interface. class ISource : virtual public IDevice, public audio::IFrameReader { public: + //! Initialize. + explicit ISource(core::IArena& arena); + + //! Deinitialize. virtual ~ISource(); //! Restart reading from beginning. diff --git a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_backend.cpp b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_backend.cpp index 3dcd406fc..7bb528c78 100644 --- a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_backend.cpp +++ b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_backend.cpp @@ -51,8 +51,7 @@ status::StatusCode PulseaudioBackend::open_device(DeviceType device_type, } core::ScopedPtr device( - new (arena) PulseaudioDevice(frame_factory, arena, io_config, device_type), - arena); + new (arena) PulseaudioDevice(frame_factory, arena, io_config, device_type)); if (!device) { roc_log(LogDebug, "pulseaudio backend: can't allocate device: path=%s", path); @@ -73,7 +72,7 @@ status::StatusCode PulseaudioBackend::open_device(DeviceType device_type, return code; } - *result = device.release(); + *result = device.hijack(); return status::StatusOK; } 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 9ebf501c8..5cb1e9367 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 @@ -122,7 +122,10 @@ PulseaudioDevice::PulseaudioDevice(audio::FrameFactory& frame_factory, core::IArena& arena, const IoConfig& io_config, DeviceType device_type) - : device_type_(device_type) + : IDevice(arena) + , ISink(arena) + , ISource(arena) + , device_type_(device_type) , device_(NULL) , frame_factory_(frame_factory) , sample_spec_(io_config.sample_spec) @@ -214,15 +217,6 @@ status::StatusCode PulseaudioDevice::open(const char* device) { return status::StatusOK; } -status::StatusCode PulseaudioDevice::close() { - roc_log(LogDebug, "pulseaudio %s: closing device", device_type_to_str(device_type_)); - - close_(); - stop_mainloop_(); - - return status::StatusOK; -} - DeviceType PulseaudioDevice::type() const { return device_type_; } @@ -330,16 +324,6 @@ void PulseaudioDevice::reclock(core::nanoseconds_t timestamp) { // no-op } -status::StatusCode PulseaudioDevice::write(audio::Frame& frame) { - roc_panic_if(device_type_ != DeviceType_Sink); - - return handle_request_(frame.bytes(), frame.num_bytes()); -} - -status::StatusCode PulseaudioDevice::flush() { - return status::StatusOK; -} - status::StatusCode PulseaudioDevice::read(audio::Frame& frame, packet::stream_timestamp_t duration, audio::FrameReadMode mode) { @@ -356,6 +340,29 @@ status::StatusCode PulseaudioDevice::read(audio::Frame& frame, return handle_request_(frame.bytes(), frame.num_bytes()); } +status::StatusCode PulseaudioDevice::write(audio::Frame& frame) { + roc_panic_if(device_type_ != DeviceType_Sink); + + return handle_request_(frame.bytes(), frame.num_bytes()); +} + +status::StatusCode PulseaudioDevice::flush() { + return status::StatusOK; +} + +status::StatusCode PulseaudioDevice::close() { + roc_log(LogDebug, "pulseaudio %s: closing device", device_type_to_str(device_type_)); + + close_(); + stop_mainloop_(); + + return status::StatusOK; +} + +void PulseaudioDevice::dispose() { + arena().dispose_object(*this); +} + status::StatusCode PulseaudioDevice::handle_request_(uint8_t* data, size_t size) { want_mainloop_(); 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 212204eb3..c3f352c6f 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 @@ -79,9 +79,6 @@ class PulseaudioDevice : public ISink, public ISource, public core::NonCopyable< //! Check if the device has own clock. virtual bool has_clock() const; - //! Explicitly close the device. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Restart reading from beginning. virtual ROC_ATTR_NODISCARD status::StatusCode rewind(); @@ -104,6 +101,12 @@ class PulseaudioDevice : public ISink, public ISource, public core::NonCopyable< //! Flush buffered data, if any. virtual ROC_ATTR_NODISCARD status::StatusCode flush(); + //! Explicitly close the device. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: static void context_state_cb_(pa_context* context, void* userdata); diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_backend.cpp b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_backend.cpp index 2f7b4cda6..223c0e262 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_backend.cpp +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_backend.cpp @@ -76,7 +76,7 @@ status::StatusCode SndfileBackend::open_device(DeviceType device_type, switch (device_type) { case DeviceType_Sink: { core::ScopedPtr sink( - new (arena) SndfileSink(frame_factory, arena, io_config), arena); + new (arena) SndfileSink(frame_factory, arena, io_config)); if (!sink) { roc_log(LogDebug, "sndfile backend: can't allocate sink: driver=%s path=%s", @@ -99,13 +99,13 @@ status::StatusCode SndfileBackend::open_device(DeviceType device_type, return code; } - *result = sink.release(); + *result = sink.hijack(); return status::StatusOK; } break; case DeviceType_Source: { core::ScopedPtr source( - new (arena) SndfileSource(frame_factory, arena, io_config), arena); + new (arena) SndfileSource(frame_factory, arena, io_config)); if (!source) { roc_log(LogDebug, "sndfile backend: can't allocate source: driver=%s path=%s", @@ -129,7 +129,7 @@ status::StatusCode SndfileBackend::open_device(DeviceType device_type, return code; } - *result = source.release(); + *result = source.hijack(); return status::StatusOK; } break; 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 9f538c3a3..edf0ab868 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 @@ -212,7 +212,9 @@ bool select_sub_format(SF_INFO& file_info, SndfileSink::SndfileSink(audio::FrameFactory& frame_factory, core::IArena& arena, const IoConfig& io_config) - : file_(NULL) + : IDevice(arena) + , ISink(arena) + , file_(NULL) , requested_subformat_(0) , init_status_(status::NoStatus) { if (io_config.latency != 0) { @@ -284,10 +286,6 @@ status::StatusCode SndfileSink::open(const char* driver, const char* path) { return open_(driver, path); } -status::StatusCode SndfileSink::close() { - return close_(); -} - DeviceType SndfileSink::type() const { return DeviceType_Sink; } @@ -349,6 +347,14 @@ status::StatusCode SndfileSink::flush() { return status::StatusOK; } +status::StatusCode SndfileSink::close() { + return close_(); +} + +void SndfileSink::dispose() { + arena().dispose_object(*this); +} + status::StatusCode SndfileSink::open_(const char* driver, const char* path) { file_info_.channels = (int)sample_spec_.num_channels(); file_info_.samplerate = (int)sample_spec_.sample_rate(); diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.h b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.h index 9f453594e..46efdefb9 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.h +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.h @@ -63,15 +63,18 @@ class SndfileSink : public ISink, public core::NonCopyable<> { //! Check if the sink has own clock. virtual bool has_clock() const; - //! Explicitly close the sink. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Write frame. virtual ROC_ATTR_NODISCARD status::StatusCode write(audio::Frame& frame); //! Flush buffered data, if any. virtual ROC_ATTR_NODISCARD status::StatusCode flush(); + //! Explicitly close the sink. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: status::StatusCode open_(const char* driver, const char* path); status::StatusCode close_(); 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 aa2f1606e..99166300b 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 @@ -19,7 +19,9 @@ namespace sndio { SndfileSource::SndfileSource(audio::FrameFactory& frame_factory, core::IArena& arena, const IoConfig& io_config) - : frame_factory_(frame_factory) + : IDevice(arena) + , ISource(arena) + , frame_factory_(frame_factory) , file_(NULL) , path_(arena) , init_status_(status::NoStatus) { @@ -71,10 +73,6 @@ status::StatusCode SndfileSource::open(const char* driver, const char* path) { return open_(); } -status::StatusCode SndfileSource::close() { - return close_(); -} - DeviceType SndfileSource::type() const { return DeviceType_Source; } @@ -166,6 +164,14 @@ status::StatusCode SndfileSource::read(audio::Frame& frame, return status::StatusOK; } +status::StatusCode SndfileSource::close() { + return close_(); +} + +void SndfileSource::dispose() { + arena().dispose_object(*this); +} + status::StatusCode SndfileSource::seek_(size_t offset) { if (!file_) { roc_panic("sndfile source: can't seek: not opened"); 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 6a68ee0ac..e84aa9b61 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 @@ -64,9 +64,6 @@ class SndfileSource : public ISource, private core::NonCopyable<> { //! Check if the source has own clock. virtual bool has_clock() const; - //! Explicitly close the source. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Restart reading from beginning. virtual ROC_ATTR_NODISCARD status::StatusCode rewind(); @@ -79,6 +76,12 @@ class SndfileSource : public ISource, private core::NonCopyable<> { packet::stream_timestamp_t duration, audio::FrameReadMode mode); + //! Explicitly close the source. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: status::StatusCode open_(); status::StatusCode close_(); diff --git a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_backend.cpp b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_backend.cpp index 2ff3b2d2a..9dc326572 100644 --- a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_backend.cpp +++ b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_backend.cpp @@ -274,7 +274,7 @@ status::StatusCode SoxBackend::open_device(DeviceType device_type, switch (device_type) { case DeviceType_Sink: { core::ScopedPtr sink( - new (arena) SoxSink(frame_factory, arena, io_config, driver_type), arena); + new (arena) SoxSink(frame_factory, arena, io_config, driver_type)); if (!sink) { roc_log(LogDebug, "sox backend: can't allocate sink: path=%s", path); @@ -294,13 +294,13 @@ status::StatusCode SoxBackend::open_device(DeviceType device_type, return code; } - *result = sink.release(); + *result = sink.hijack(); return status::StatusOK; } break; case DeviceType_Source: { core::ScopedPtr source( - new (arena) SoxSource(frame_factory, arena, io_config, driver_type), arena); + new (arena) SoxSource(frame_factory, arena, io_config, driver_type)); if (!source) { roc_log(LogDebug, "sox backend: can't allocate source: path=%s", path); @@ -320,7 +320,7 @@ status::StatusCode SoxBackend::open_device(DeviceType device_type, return code; } - *result = source.release(); + *result = source.hijack(); return status::StatusOK; } break; diff --git a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_sink.cpp b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_sink.cpp index ee0427607..880556ba0 100644 --- a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_sink.cpp +++ b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_sink.cpp @@ -19,7 +19,9 @@ SoxSink::SoxSink(audio::FrameFactory& frame_factory, core::IArena& arena, const IoConfig& io_config, DriverType driver_type) - : driver_type_(driver_type) + : IDevice(arena) + , ISink(arena) + , driver_type_(driver_type) , driver_name_(arena) , output_name_(arena) , output_(NULL) @@ -105,10 +107,6 @@ status::StatusCode SoxSink::open(const char* driver, const char* path) { return status::StatusOK; } -status::StatusCode SoxSink::close() { - return close_(); -} - DeviceType SoxSink::type() const { return DeviceType_Sink; } @@ -240,6 +238,14 @@ status::StatusCode SoxSink::flush() { return status::StatusOK; } +status::StatusCode SoxSink::close() { + return close_(); +} + +void SoxSink::dispose() { + arena().dispose_object(*this); +} + status::StatusCode SoxSink::init_names_(const char* driver, const char* path) { if (driver) { if (!driver_name_.assign(driver)) { diff --git a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_sink.h b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_sink.h index a473ab2dc..be4215ca9 100644 --- a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_sink.h +++ b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_sink.h @@ -75,15 +75,18 @@ class SoxSink : public ISink, public core::NonCopyable<> { //! Check if the sink has own clock. virtual bool has_clock() const; - //! Explicitly close the sink. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Write frame. virtual ROC_ATTR_NODISCARD status::StatusCode write(audio::Frame& frame); //! Flush buffered data, if any. virtual ROC_ATTR_NODISCARD status::StatusCode flush(); + //! Explicitly close the sink. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: status::StatusCode init_names_(const char* driver, const char* path); status::StatusCode init_buffer_(); 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 948a1143c..7b025e2ff 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 @@ -19,7 +19,9 @@ SoxSource::SoxSource(audio::FrameFactory& frame_factory, core::IArena& arena, const IoConfig& io_config, DriverType driver_type) - : frame_factory_(frame_factory) + : IDevice(arena) + , ISource(arena) + , frame_factory_(frame_factory) , driver_type_(driver_type) , driver_name_(arena) , input_name_(arena) @@ -110,10 +112,6 @@ status::StatusCode SoxSource::open(const char* driver, const char* path) { return status::StatusOK; } -status::StatusCode SoxSource::close() { - return close_(); -} - DeviceType SoxSource::type() const { return DeviceType_Source; } @@ -298,6 +296,14 @@ status::StatusCode SoxSource::read(audio::Frame& frame, return status::StatusOK; } +status::StatusCode SoxSource::close() { + return close_(); +} + +void SoxSource::dispose() { + arena().dispose_object(*this); +} + status::StatusCode SoxSource::init_names_(const char* driver, const char* path) { if (driver) { if (!driver_name_.assign(driver)) { 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 590027e55..c183beb73 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 @@ -76,9 +76,6 @@ class SoxSource : public ISource, private core::NonCopyable<> { //! Check if the source has own clock. virtual bool has_clock() const; - //! Explicitly close the source. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Restart reading from beginning. virtual ROC_ATTR_NODISCARD status::StatusCode rewind(); @@ -91,6 +88,12 @@ class SoxSource : public ISource, private core::NonCopyable<> { packet::stream_timestamp_t duration, audio::FrameReadMode mode); + //! Explicitly close the source. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: status::StatusCode init_names_(const char* driver, const char* path); status::StatusCode init_buffer_(); diff --git a/src/internal_modules/roc_sndio/wav_backend.cpp b/src/internal_modules/roc_sndio/wav_backend.cpp index e5a8e7cff..d33ef3340 100644 --- a/src/internal_modules/roc_sndio/wav_backend.cpp +++ b/src/internal_modules/roc_sndio/wav_backend.cpp @@ -71,8 +71,8 @@ status::StatusCode WavBackend::open_device(DeviceType device_type, switch (device_type) { case DeviceType_Sink: { - core::ScopedPtr sink( - new (arena) WavSink(frame_factory, arena, io_config), arena); + core::ScopedPtr sink(new (arena) + WavSink(frame_factory, arena, io_config)); if (!sink) { roc_log(LogDebug, "wav backend: can't allocate sink: path=%s", path); @@ -92,13 +92,13 @@ status::StatusCode WavBackend::open_device(DeviceType device_type, return code; } - *result = sink.release(); + *result = sink.hijack(); return status::StatusOK; } break; case DeviceType_Source: { - core::ScopedPtr source( - new (arena) WavSource(frame_factory, arena, io_config), arena); + core::ScopedPtr source(new (arena) + WavSource(frame_factory, arena, io_config)); if (!source) { roc_log(LogDebug, "wav backend: can't allocate source: path=%s", path); @@ -118,7 +118,7 @@ status::StatusCode WavBackend::open_device(DeviceType device_type, return code; } - *result = source.release(); + *result = source.hijack(); return status::StatusOK; } break; diff --git a/src/internal_modules/roc_sndio/wav_sink.cpp b/src/internal_modules/roc_sndio/wav_sink.cpp index 10dc447c7..f3a027ff2 100644 --- a/src/internal_modules/roc_sndio/wav_sink.cpp +++ b/src/internal_modules/roc_sndio/wav_sink.cpp @@ -20,7 +20,9 @@ namespace sndio { WavSink::WavSink(audio::FrameFactory& frame_factory, core::IArena& arena, const IoConfig& io_config) - : output_file_(NULL) + : IDevice(arena) + , ISink(arena) + , output_file_(NULL) , init_status_(status::NoStatus) { if (io_config.latency != 0) { roc_log(LogError, "wav sink: setting io latency not supported by backend"); @@ -63,10 +65,6 @@ status::StatusCode WavSink::open(const char* path) { return open_(path); } -status::StatusCode WavSink::close() { - return close_(); -} - DeviceType WavSink::type() const { return DeviceType_Sink; } @@ -154,6 +152,14 @@ status::StatusCode WavSink::flush() { return status::StatusOK; } +status::StatusCode WavSink::close() { + return close_(); +} + +void WavSink::dispose() { + arena().dispose_object(*this); +} + status::StatusCode WavSink::open_(const char* path) { if (output_file_) { roc_panic("wav sink: already opened"); diff --git a/src/internal_modules/roc_sndio/wav_sink.h b/src/internal_modules/roc_sndio/wav_sink.h index afbd68f1b..2e1596b45 100644 --- a/src/internal_modules/roc_sndio/wav_sink.h +++ b/src/internal_modules/roc_sndio/wav_sink.h @@ -60,15 +60,18 @@ class WavSink : public ISink, public core::NonCopyable<> { //! Check if the sink has own clock. virtual bool has_clock() const; - //! Explicitly close the sink. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Write frame. virtual ROC_ATTR_NODISCARD status::StatusCode write(audio::Frame& frame); //! Flush buffered data, if any. virtual ROC_ATTR_NODISCARD status::StatusCode flush(); + //! Explicitly close the sink. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: status::StatusCode open_(const char* path); status::StatusCode close_(); diff --git a/src/internal_modules/roc_sndio/wav_source.cpp b/src/internal_modules/roc_sndio/wav_source.cpp index 93d41a5eb..f4dba94f4 100644 --- a/src/internal_modules/roc_sndio/wav_source.cpp +++ b/src/internal_modules/roc_sndio/wav_source.cpp @@ -17,7 +17,9 @@ namespace sndio { WavSource::WavSource(audio::FrameFactory& frame_factory, core::IArena& arena, const IoConfig& io_config) - : frame_factory_(frame_factory) + : IDevice(arena) + , ISource(arena) + , frame_factory_(frame_factory) , file_opened_(false) , eof_(false) , init_status_(status::NoStatus) { @@ -52,10 +54,6 @@ status::StatusCode WavSource::open(const char* path) { return open_(path); } -status::StatusCode WavSource::close() { - return close_(); -} - DeviceType WavSource::type() const { return DeviceType_Source; } @@ -163,6 +161,14 @@ status::StatusCode WavSource::read(audio::Frame& frame, return status::StatusOK; } +status::StatusCode WavSource::close() { + return close_(); +} + +void WavSource::dispose() { + arena().dispose_object(*this); +} + status::StatusCode WavSource::open_(const char* path) { if (file_opened_) { roc_panic("wav source: already opened"); diff --git a/src/internal_modules/roc_sndio/wav_source.h b/src/internal_modules/roc_sndio/wav_source.h index e6756b7cf..10f957dcb 100644 --- a/src/internal_modules/roc_sndio/wav_source.h +++ b/src/internal_modules/roc_sndio/wav_source.h @@ -61,9 +61,6 @@ class WavSource : public ISource, private core::NonCopyable<> { //! Check if the source has own clock. virtual bool has_clock() const; - //! Explicitly close the source. - virtual ROC_ATTR_NODISCARD status::StatusCode close(); - //! Restart reading from beginning. virtual ROC_ATTR_NODISCARD status::StatusCode rewind(); @@ -76,6 +73,12 @@ class WavSource : public ISource, private core::NonCopyable<> { packet::stream_timestamp_t duration, audio::FrameReadMode mode); + //! Explicitly close the source. + virtual ROC_ATTR_NODISCARD status::StatusCode close(); + + //! Destroy object and return memory to arena. + virtual void dispose(); + private: status::StatusCode open_(const char* path); status::StatusCode close_(); diff --git a/src/public_api/src/context.cpp b/src/public_api/src/context.cpp index 2c5b8b7de..b83d3b4ec 100644 --- a/src/public_api/src/context.cpp +++ b/src/public_api/src/context.cpp @@ -40,8 +40,7 @@ int roc_context_open(const roc_context_config* config, roc_context** result) { } core::ScopedPtr imp_context( - new (api::default_arena) node::Context(imp_config, api::default_arena), - api::default_arena); + new (api::default_arena) node::Context(imp_config, api::default_arena)); if (!imp_context) { roc_log(LogError, "roc_context_open(): can't allocate context"); @@ -54,7 +53,7 @@ int roc_context_open(const roc_context_config* config, roc_context** result) { return -1; } - *result = (roc_context*)imp_context.release(); + *result = (roc_context*)imp_context.hijack(); return 0; } @@ -165,7 +164,7 @@ int roc_context_close(roc_context* context) { return -1; } - api::default_arena.destroy_object(*imp_context); + api::default_arena.dispose_object(*imp_context); roc_log(LogInfo, "roc_context_close(): closed context"); diff --git a/src/public_api/src/endpoint.cpp b/src/public_api/src/endpoint.cpp index bdadfbaaa..31bb3789f 100644 --- a/src/public_api/src/endpoint.cpp +++ b/src/public_api/src/endpoint.cpp @@ -289,7 +289,7 @@ int roc_endpoint_deallocate(roc_endpoint* endpoint) { } address::EndpointUri& imp_endpoint = *(address::EndpointUri*)endpoint; - api::default_arena.destroy_object(imp_endpoint); + api::default_arena.dispose_object(imp_endpoint); return 0; } diff --git a/src/public_api/src/plugin_plc.cpp b/src/public_api/src/plugin_plc.cpp index 2f4f2e6cb..361804a43 100644 --- a/src/public_api/src/plugin_plc.cpp +++ b/src/public_api/src/plugin_plc.cpp @@ -49,16 +49,19 @@ bool PluginPlc::validate(roc_plugin_plc* plugin) { return true; } -audio::IPlc* PluginPlc::construct(void* plugin, - core::IArena& arena, +audio::IPlc* PluginPlc::construct(const audio::PlcConfig& config, + const audio::SampleSpec& sample_spec, audio::FrameFactory& frame_factory, - const audio::PlcConfig& config, - const audio::SampleSpec& sample_spec) { - return new (arena) PluginPlc((roc_plugin_plc*)plugin, sample_spec); + core::IArena& arena, + void* plugin) { + return new (arena) PluginPlc(sample_spec, arena, (roc_plugin_plc*)plugin); } -PluginPlc::PluginPlc(roc_plugin_plc* plugin, const audio::SampleSpec& sample_spec) - : plugin_(plugin) +PluginPlc::PluginPlc(const audio::SampleSpec& sample_spec, + core::IArena& arena, + roc_plugin_plc* plugin) + : IPlc(arena) + , plugin_(plugin) , plugin_instance_(NULL) , sample_spec_(sample_spec) { roc_panic_if(!plugin_); diff --git a/src/public_api/src/plugin_plc.h b/src/public_api/src/plugin_plc.h index 57f95c1d9..e47a0543d 100644 --- a/src/public_api/src/plugin_plc.h +++ b/src/public_api/src/plugin_plc.h @@ -25,14 +25,16 @@ class PluginPlc : public audio::IPlc { //! Construction function. //! @p plugin is roc_plugin_plc. - static IPlc* construct(void* plugin, - core::IArena& arena, + static IPlc* construct(const audio::PlcConfig& config, + const audio::SampleSpec& sample_spec, audio::FrameFactory& frame_factory, - const audio::PlcConfig& config, - const audio::SampleSpec& sample_spec); + core::IArena& arena, + void* plugin); //! Initialize. - PluginPlc(roc_plugin_plc* plugin, const audio::SampleSpec& sample_spec); + PluginPlc(const audio::SampleSpec& sample_spec, + core::IArena& arena, + roc_plugin_plc* plugin); virtual ~PluginPlc(); diff --git a/src/public_api/src/receiver.cpp b/src/public_api/src/receiver.cpp index f3a3315e5..4a046ba8d 100644 --- a/src/public_api/src/receiver.cpp +++ b/src/public_api/src/receiver.cpp @@ -46,8 +46,7 @@ int roc_receiver_open(roc_context* context, } core::ScopedPtr imp_receiver( - new (imp_context->arena()) node::Receiver(*imp_context, imp_config), - imp_context->arena()); + new (imp_context->arena()) node::Receiver(*imp_context, imp_config)); if (!imp_receiver) { roc_log(LogError, "roc_receiver_open(): can't allocate receiver"); @@ -60,7 +59,7 @@ int roc_receiver_open(roc_context* context, return -1; } - *result = (roc_receiver*)imp_receiver.release(); + *result = (roc_receiver*)imp_receiver.hijack(); return 0; } @@ -220,7 +219,7 @@ int roc_receiver_close(roc_receiver* receiver) { } node::Receiver* imp_receiver = (node::Receiver*)receiver; - imp_receiver->context().arena().destroy_object(*imp_receiver); + imp_receiver->context().arena().dispose_object(*imp_receiver); roc_log(LogInfo, "roc_receiver_close(): closed receiver"); diff --git a/src/public_api/src/receiver_decoder.cpp b/src/public_api/src/receiver_decoder.cpp index 66ba81107..983cac4f5 100644 --- a/src/public_api/src/receiver_decoder.cpp +++ b/src/public_api/src/receiver_decoder.cpp @@ -52,8 +52,7 @@ int roc_receiver_decoder_open(roc_context* context, } core::ScopedPtr imp_decoder( - new (imp_context->arena()) node::ReceiverDecoder(*imp_context, imp_config), - imp_context->arena()); + new (imp_context->arena()) node::ReceiverDecoder(*imp_context, imp_config)); if (!imp_decoder) { roc_log(LogError, "roc_receiver_decoder_open(): can't allocate decoder"); @@ -67,7 +66,7 @@ int roc_receiver_decoder_open(roc_context* context, return -1; } - *result = (roc_receiver_decoder*)imp_decoder.release(); + *result = (roc_receiver_decoder*)imp_decoder.hijack(); return 0; } @@ -297,7 +296,7 @@ int roc_receiver_decoder_close(roc_receiver_decoder* decoder) { } node::ReceiverDecoder* imp_decoder = (node::ReceiverDecoder*)decoder; - imp_decoder->context().arena().destroy_object(*imp_decoder); + imp_decoder->context().arena().dispose_object(*imp_decoder); roc_log(LogInfo, "roc_receiver_decoder_close(): closed decoder"); diff --git a/src/public_api/src/sender.cpp b/src/public_api/src/sender.cpp index 1af5de2e5..ec3c4b233 100644 --- a/src/public_api/src/sender.cpp +++ b/src/public_api/src/sender.cpp @@ -46,8 +46,7 @@ int roc_sender_open(roc_context* context, } core::ScopedPtr imp_sender(new (imp_context->arena()) - node::Sender(*imp_context, imp_config), - imp_context->arena()); + node::Sender(*imp_context, imp_config)); if (!imp_sender) { roc_log(LogError, "roc_sender_open(): can't allocate sender"); @@ -60,7 +59,7 @@ int roc_sender_open(roc_context* context, return -1; } - *result = (roc_sender*)imp_sender.release(); + *result = (roc_sender*)imp_sender.hijack(); return 0; } @@ -219,7 +218,7 @@ int roc_sender_close(roc_sender* sender) { } node::Sender* imp_sender = (node::Sender*)sender; - imp_sender->context().arena().destroy_object(*imp_sender); + imp_sender->context().arena().dispose_object(*imp_sender); roc_log(LogInfo, "roc_sender_close(): closed sender"); diff --git a/src/public_api/src/sender_encoder.cpp b/src/public_api/src/sender_encoder.cpp index b153acec2..61ae75362 100644 --- a/src/public_api/src/sender_encoder.cpp +++ b/src/public_api/src/sender_encoder.cpp @@ -49,8 +49,7 @@ int roc_sender_encoder_open(roc_context* context, } core::ScopedPtr imp_encoder( - new (imp_context->arena()) node::SenderEncoder(*imp_context, imp_config), - imp_context->arena()); + new (imp_context->arena()) node::SenderEncoder(*imp_context, imp_config)); if (!imp_encoder) { roc_log(LogError, "roc_sender_encoder_open(): can't allocate encoder"); @@ -64,7 +63,7 @@ int roc_sender_encoder_open(roc_context* context, return -1; } - *result = (roc_sender_encoder*)imp_encoder.release(); + *result = (roc_sender_encoder*)imp_encoder.hijack(); return 0; } @@ -293,7 +292,7 @@ int roc_sender_encoder_close(roc_sender_encoder* encoder) { } node::SenderEncoder* imp_encoder = (node::SenderEncoder*)encoder; - imp_encoder->context().arena().destroy_object(*imp_encoder); + imp_encoder->context().arena().dispose_object(*imp_encoder); roc_log(LogInfo, "roc_sender_encoder_close(): closed encoder"); diff --git a/src/tests/roc_audio/test_depacketizer.cpp b/src/tests/roc_audio/test_depacketizer.cpp index c92b385a9..14f0f8a22 100644 --- a/src/tests/roc_audio/test_depacketizer.cpp +++ b/src/tests/roc_audio/test_depacketizer.cpp @@ -50,7 +50,7 @@ core::HeapArena arena; packet::PacketFactory packet_factory(arena, MaxBufSize); FrameFactory frame_factory(arena, MaxBufSize); -rtp::Composer rtp_composer(NULL); +rtp::Composer rtp_composer(NULL, arena); packet::PacketPtr new_packet(IFrameEncoder& encoder, packet::stream_timestamp_t ts, @@ -225,8 +225,8 @@ TEST_GROUP(depacketizer) {}; // Frame size same as packet size. TEST(depacketizer, one_packet_one_read) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -242,8 +242,8 @@ TEST(depacketizer, one_packet_one_read) { // Small frame, big packet. TEST(depacketizer, one_packet_multiple_reads) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -269,8 +269,8 @@ TEST(depacketizer, one_packet_multiple_reads) { TEST(depacketizer, multiple_packets_one_read) { enum { NumPackets = 10 }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -298,8 +298,8 @@ TEST(depacketizer, multiple_packets_multiple_reads) { CHECK(SamplesPerPacket % FramesPerPacket == 0); - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -350,8 +350,8 @@ TEST(depacketizer, multiple_packets_multiple_reads) { // Wrapping of 32-bit packet stream timestamp (STS). TEST(depacketizer, timestamp_wrap) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -381,8 +381,8 @@ TEST(depacketizer, timestamp_wrap) { } TEST(depacketizer, drop_late_packets) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -412,8 +412,8 @@ TEST(depacketizer, drop_late_packets) { } TEST(depacketizer, drop_late_packets_timestamp_wrap) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -443,8 +443,8 @@ TEST(depacketizer, drop_late_packets_timestamp_wrap) { } TEST(depacketizer, zeros_no_first_packet) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -454,8 +454,8 @@ TEST(depacketizer, zeros_no_first_packet) { } TEST(depacketizer, zeros_no_next_packet) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -471,8 +471,8 @@ TEST(depacketizer, zeros_no_next_packet) { } TEST(depacketizer, zeros_between_packets) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -494,8 +494,8 @@ TEST(depacketizer, zeros_between_packets) { } TEST(depacketizer, zeros_between_packets_timestamp_wrap) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -522,8 +522,8 @@ TEST(depacketizer, zeros_between_packets_timestamp_wrap) { } TEST(depacketizer, zeros_after_packet) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); CHECK(SamplesPerPacket % 2 == 0); @@ -544,8 +544,8 @@ TEST(depacketizer, zeros_after_packet) { } TEST(depacketizer, packet_after_zeros) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -565,8 +565,8 @@ TEST(depacketizer, packet_after_zeros) { TEST(depacketizer, overlapping_packets) { CHECK(SamplesPerPacket % 2 == 0); - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -597,8 +597,8 @@ TEST(depacketizer, overlapping_packets) { // Depacketizer should check what is next packet using ModePeek and don't fetch // packet if it's not needed yet. TEST(depacketizer, late_reordered) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); CHECK(SamplesPerPacket % 2 == 0); @@ -643,8 +643,8 @@ TEST(depacketizer, late_reordered) { // In hard read mode, depacketizer should fill packet losses with zeros and generate // partial reads to avoid mixing losses and normal samples in a same frame. TEST(depacketizer, frequent_losses_hard_read) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -763,8 +763,8 @@ TEST(depacketizer, frequent_losses_hard_read) { // In soft read mode, depacketizer should stop reading on packet loss and // generate partial read or drain. TEST(depacketizer, frequent_losses_soft_read) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -895,8 +895,8 @@ TEST(depacketizer, frequent_losses_soft_read) { TEST(depacketizer, frame_flags_signal_gaps) { enum { PacketsPerFrame = 3 }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -1016,8 +1016,8 @@ TEST(depacketizer, frame_flags_signal_gaps) { } TEST(depacketizer, frame_flags_drops) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -1067,8 +1067,8 @@ TEST(depacketizer, capture_timestamp) { CHECK(SamplesPerPacket % FramesPerPacket == 0); - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -1124,8 +1124,8 @@ TEST(depacketizer, capture_timestamp_fract_frame_per_packet) { SamplesPerFrame = SamplesPerPacket + 50 }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -1148,8 +1148,8 @@ TEST(depacketizer, capture_timestamp_small_non_zero) { PacketsPerFrame = 10 }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -1202,8 +1202,8 @@ TEST(depacketizer, partial_on_big_read) { NumPackets = (MaxFrameSamples / SamplesPerPacket) * NumFrames }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; Depacketizer dp(queue, decoder, frame_factory, frame_spec, NULL); @@ -1225,8 +1225,8 @@ TEST(depacketizer, partial_on_big_read) { // Forward error from packet reader. TEST(depacketizer, forward_error) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue queue; StatusReader reader(queue); @@ -1264,8 +1264,8 @@ TEST(depacketizer, preallocated_buffer) { 0, // no buffer (depacketizer should allocate buffer) }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); for (size_t bn = 0; bn < ROC_ARRAY_SIZE(buffer_list); bn++) { const size_t orig_buf_sz = buffer_list[bn]; diff --git a/src/tests/roc_audio/test_fanout.cpp b/src/tests/roc_audio/test_fanout.cpp index 19724f4d3..6f494d5c3 100644 --- a/src/tests/roc_audio/test_fanout.cpp +++ b/src/tests/roc_audio/test_fanout.cpp @@ -62,7 +62,7 @@ void expect_written(test::MockWriter& mock_writer, size_t sz, sample_t value) { TEST_GROUP(fanout) {}; TEST(fanout, no_writers) { - Fanout fanout(frame_factory, arena, sample_spec); + Fanout fanout(sample_spec, frame_factory, arena); LONGS_EQUAL(status::StatusOK, fanout.init_status()); write_frame(fanout, BufSz, 0.11f); @@ -71,7 +71,7 @@ TEST(fanout, no_writers) { TEST(fanout, one_output) { test::MockWriter writer; - Fanout fanout(frame_factory, arena, sample_spec); + Fanout fanout(sample_spec, frame_factory, arena); LONGS_EQUAL(status::StatusOK, fanout.init_status()); LONGS_EQUAL(status::StatusOK, fanout.add_output(writer)); @@ -88,7 +88,7 @@ TEST(fanout, two_outputs) { test::MockWriter writer1; test::MockWriter writer2; - Fanout fanout(frame_factory, arena, sample_spec); + Fanout fanout(sample_spec, frame_factory, arena); LONGS_EQUAL(status::StatusOK, fanout.init_status()); LONGS_EQUAL(status::StatusOK, fanout.add_output(writer1)); @@ -111,7 +111,7 @@ TEST(fanout, remove_output) { test::MockWriter writer2; test::MockWriter writer3; - Fanout fanout(frame_factory, arena, sample_spec); + Fanout fanout(sample_spec, frame_factory, arena); LONGS_EQUAL(status::StatusOK, fanout.init_status()); LONGS_EQUAL(status::StatusOK, fanout.add_output(writer1)); @@ -137,7 +137,7 @@ TEST(fanout, has_output) { test::MockWriter writer1; test::MockWriter writer2; - Fanout fanout(frame_factory, arena, sample_spec); + Fanout fanout(sample_spec, frame_factory, arena); LONGS_EQUAL(status::StatusOK, fanout.init_status()); CHECK(!fanout.has_output(writer1)); @@ -164,7 +164,7 @@ TEST(fanout, forward_error) { test::MockWriter writer1; test::MockWriter writer2; - Fanout fanout(frame_factory, arena, sample_spec); + Fanout fanout(sample_spec, frame_factory, arena); LONGS_EQUAL(status::StatusOK, fanout.init_status()); LONGS_EQUAL(status::StatusOK, fanout.add_output(writer1)); diff --git a/src/tests/roc_audio/test_frame_encoder_decoder.cpp b/src/tests/roc_audio/test_frame_encoder_decoder.cpp index 8109ab01b..8ceca9173 100644 --- a/src/tests/roc_audio/test_frame_encoder_decoder.cpp +++ b/src/tests/roc_audio/test_frame_encoder_decoder.cpp @@ -52,22 +52,26 @@ IFrameEncoder* new_encoder(size_t id) { case Codec_PCM_SInt16_1ch: return new (arena) PcmEncoder(SampleSpec(SampleRate, PcmFormat_SInt16_Be, ChanLayout_Surround, - ChanOrder_Smpte, ChanMask_Surround_Mono)); + ChanOrder_Smpte, ChanMask_Surround_Mono), + arena); case Codec_PCM_SInt16_2ch: return new (arena) PcmEncoder(SampleSpec(SampleRate, PcmFormat_SInt16_Be, ChanLayout_Surround, - ChanOrder_Smpte, ChanMask_Surround_Stereo)); + ChanOrder_Smpte, ChanMask_Surround_Stereo), + arena); case Codec_PCM_SInt24_1ch: return new (arena) PcmEncoder(SampleSpec(SampleRate, PcmFormat_SInt24_Be, ChanLayout_Surround, - ChanOrder_Smpte, ChanMask_Surround_Mono)); + ChanOrder_Smpte, ChanMask_Surround_Mono), + arena); case Codec_PCM_SInt24_2ch: return new (arena) PcmEncoder(SampleSpec(SampleRate, PcmFormat_SInt24_Be, ChanLayout_Surround, - ChanOrder_Smpte, ChanMask_Surround_Stereo)); + ChanOrder_Smpte, ChanMask_Surround_Stereo), + arena); default: FAIL("bad codec id"); @@ -81,22 +85,26 @@ IFrameDecoder* new_decoder(size_t id) { case Codec_PCM_SInt16_1ch: return new (arena) PcmDecoder(SampleSpec(SampleRate, PcmFormat_SInt16_Be, ChanLayout_Surround, - ChanOrder_Smpte, ChanMask_Surround_Mono)); + ChanOrder_Smpte, ChanMask_Surround_Mono), + arena); case Codec_PCM_SInt16_2ch: return new (arena) PcmDecoder(SampleSpec(SampleRate, PcmFormat_SInt16_Be, ChanLayout_Surround, - ChanOrder_Smpte, ChanMask_Surround_Stereo)); + ChanOrder_Smpte, ChanMask_Surround_Stereo), + arena); case Codec_PCM_SInt24_1ch: return new (arena) PcmDecoder(SampleSpec(SampleRate, PcmFormat_SInt24_Be, ChanLayout_Surround, - ChanOrder_Smpte, ChanMask_Surround_Mono)); + ChanOrder_Smpte, ChanMask_Surround_Mono), + arena); case Codec_PCM_SInt24_2ch: return new (arena) PcmDecoder(SampleSpec(SampleRate, PcmFormat_SInt24_Be, ChanLayout_Surround, - ChanOrder_Smpte, ChanMask_Surround_Stereo)); + ChanOrder_Smpte, ChanMask_Surround_Stereo), + arena); default: FAIL("bad codec id"); @@ -163,10 +171,10 @@ TEST(encoder_decoder, one_frame) { enum { Timestamp = 100500, SamplesPerFrame = 177 }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); core::Slice bp = @@ -208,10 +216,10 @@ TEST(encoder_decoder, multiple_frames) { enum { NumFrames = 20, SamplesPerFrame = 177 }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); packet::stream_timestamp_t ts = 100500; @@ -264,10 +272,10 @@ TEST(encoder_decoder, incomplete_frames) { enum { NumFrames = 20, ExpectedSamplesPerFrame = 211, ActualSamplesPerFrame = 177 }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); packet::stream_timestamp_t ts = 100500; @@ -323,10 +331,10 @@ TEST(encoder_decoder, shifted_frames) { enum { NumFrames = 20, SamplesPerFrame = 177, Shift = 55 }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); packet::stream_timestamp_t ts = 100500; @@ -386,10 +394,10 @@ TEST(encoder_decoder, skipped_frames) { enum { NumFrames = 20, SkipEvery = 3, SamplesPerFrame = 177 }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); packet::stream_timestamp_t ts = 100500; @@ -453,10 +461,10 @@ TEST(encoder_decoder, write_incrementally) { }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); core::Slice bp = @@ -498,10 +506,10 @@ TEST(encoder_decoder, write_too_much) { enum { Timestamp = 100500, SamplesPerFrame = 177 }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); core::Slice bp = @@ -543,10 +551,10 @@ TEST(encoder_decoder, read_incrementally) { }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); core::Slice bp = @@ -606,10 +614,10 @@ TEST(encoder_decoder, read_too_much) { enum { Timestamp = 100500, SamplesPerFrame = 177 }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); core::Slice bp = @@ -655,10 +663,10 @@ TEST(encoder_decoder, shift_incrementally) { }; for (size_t n_codec = 0; n_codec < NumCodecs; n_codec++) { - core::ScopedPtr encoder(new_encoder(n_codec), arena); + core::ScopedPtr encoder(new_encoder(n_codec)); CHECK(encoder); - core::ScopedPtr decoder(new_decoder(n_codec), arena); + core::ScopedPtr decoder(new_decoder(n_codec)); CHECK(decoder); core::Slice bp = diff --git a/src/tests/roc_audio/test_mixer.cpp b/src/tests/roc_audio/test_mixer.cpp index 1c6ca6f65..61b05a7df 100644 --- a/src/tests/roc_audio/test_mixer.cpp +++ b/src/tests/roc_audio/test_mixer.cpp @@ -82,7 +82,7 @@ void expect_error(status::StatusCode expected_code, TEST_GROUP(mixer) {}; TEST(mixer, no_readers) { - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); expect_output(status::StatusOK, mixer, BufSz, BufSz, 0); @@ -91,7 +91,7 @@ TEST(mixer, no_readers) { TEST(mixer, one_input) { test::MockReader reader(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader)); @@ -108,7 +108,7 @@ TEST(mixer, one_input_big_frame) { test::MockReader reader(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader)); @@ -124,7 +124,7 @@ TEST(mixer, two_inputs) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -146,7 +146,7 @@ TEST(mixer, remove_input) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -176,7 +176,7 @@ TEST(mixer, has_input) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); CHECK(!mixer.has_input(reader1)); @@ -204,7 +204,7 @@ TEST(mixer, finish) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -238,7 +238,7 @@ TEST(mixer, partial) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -275,7 +275,7 @@ TEST(mixer, partial_end) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -306,7 +306,7 @@ TEST(mixer, clamp) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -339,7 +339,7 @@ TEST(mixer, cts_one_reader) { test::MockReader reader(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader)); @@ -370,7 +370,7 @@ TEST(mixer, cts_two_readers) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -409,7 +409,7 @@ TEST(mixer, cts_partial) { test::MockReader reader2(frame_factory, sample_spec); test::MockReader reader3(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -457,7 +457,7 @@ TEST(mixer, cts_prevent_overflow) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -494,7 +494,7 @@ TEST(mixer, cts_disabled) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, false); + Mixer mixer(sample_spec, false, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); reader1.enable_timestamps(start_ts); @@ -522,7 +522,7 @@ TEST(mixer, soft_read_drain) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -560,7 +560,7 @@ TEST(mixer, soft_read_partial) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -597,7 +597,7 @@ TEST(mixer, soft_read_partial) { TEST(mixer, soft_read_partial_drain) { test::MockReader reader(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader)); @@ -634,7 +634,7 @@ TEST(mixer, soft_read_partial_drain_two_readers) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -703,7 +703,7 @@ TEST(mixer, soft_read_partial_end_two_readers) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -741,7 +741,7 @@ TEST(mixer, soft_read_cts) { test::MockReader reader(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader)); @@ -772,7 +772,7 @@ TEST(mixer, soft_read_cts_partial) { test::MockReader reader(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader)); @@ -806,7 +806,7 @@ TEST(mixer, soft_read_cts_two_readers) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -849,7 +849,7 @@ TEST(mixer, soft_read_add_reader) { test::MockReader reader2(frame_factory, sample_spec); test::MockReader reader3(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -892,7 +892,7 @@ TEST(mixer, soft_read_remove_reader) { test::MockReader reader2(frame_factory, sample_spec); test::MockReader reader3(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -973,7 +973,7 @@ TEST(mixer, soft_read_remove_reader) { TEST(mixer, forward_mode) { test::MockReader reader(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader)); @@ -998,7 +998,7 @@ TEST(mixer, forward_error) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); LONGS_EQUAL(status::StatusOK, mixer.add_input(reader1)); @@ -1050,7 +1050,7 @@ TEST(mixer, preallocated_buffer) { test::MockReader reader1(frame_factory, sample_spec); test::MockReader reader2(frame_factory, sample_spec); - Mixer mixer(frame_factory, arena, sample_spec, true); + Mixer mixer(sample_spec, true, frame_factory, arena); LONGS_EQUAL(status::StatusOK, mixer.init_status()); reader1.add_zero_samples(); diff --git a/src/tests/roc_audio/test_packetizer.cpp b/src/tests/roc_audio/test_packetizer.cpp index 3ad9d57d4..af4dd03d0 100644 --- a/src/tests/roc_audio/test_packetizer.cpp +++ b/src/tests/roc_audio/test_packetizer.cpp @@ -53,7 +53,7 @@ core::HeapArena arena; packet::PacketFactory packet_factory(arena, MaxBufSize); FrameFactory frame_factory(arena, MaxBufSize * sizeof(sample_t)); -rtp::Composer rtp_composer(NULL); +rtp::Composer rtp_composer(NULL, arena); sample_t nth_sample(uint8_t n) { return sample_t(n) / sample_t(1 << 8); @@ -200,8 +200,8 @@ TEST_GROUP(packetizer) {}; TEST(packetizer, one_buffer_one_packet) { enum { NumFrames = 10 }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue packet_queue; @@ -228,8 +228,8 @@ TEST(packetizer, one_buffer_one_packet) { TEST(packetizer, one_buffer_multiple_packets) { enum { NumPackets = 10 }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue packet_queue; @@ -256,8 +256,8 @@ TEST(packetizer, multiple_buffers_one_packet) { CHECK(SamplesPerPacket % FramesPerPacket == 0); - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue packet_queue; @@ -290,8 +290,8 @@ TEST(packetizer, multiple_buffers_multiple_packets) { NumPackets = (NumSamples * NumFrames / SamplesPerPacket) }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue packet_queue; @@ -318,8 +318,8 @@ TEST(packetizer, multiple_buffers_multiple_packets) { TEST(packetizer, flush) { enum { NumIterations = 5, Missing = 10 }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue packet_queue; @@ -357,8 +357,8 @@ TEST(packetizer, timestamp_zero_cts) { NumPackets = (NumSamples * NumFrames / SamplesPerPacket) }; - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); packet::FifoQueue packet_queue; @@ -387,7 +387,7 @@ TEST(packetizer, timestamp_zero_cts) { TEST(packetizer, metrics) { enum { NumPackets = 10 }; - PcmEncoder encoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); packet::FifoQueue packet_queue; rtp::Identity identity; @@ -410,8 +410,8 @@ TEST(packetizer, metrics) { } TEST(packetizer, forward_error) { - PcmEncoder encoder(packet_spec); - PcmDecoder decoder(packet_spec); + PcmEncoder encoder(packet_spec, arena); + PcmDecoder decoder(packet_spec, arena); StatusWriter packet_writer(status::StatusAbort); diff --git a/src/tests/roc_audio/test_plc_reader.cpp b/src/tests/roc_audio/test_plc_reader.cpp index d26f18b93..42fef37a6 100644 --- a/src/tests/roc_audio/test_plc_reader.cpp +++ b/src/tests/roc_audio/test_plc_reader.cpp @@ -128,8 +128,9 @@ void expect_int_samples(const Frame& frame, size_t n_samples, T value) { class MockPlc : public IPlc { public: - MockPlc(const SampleSpec& sample_spec) - : sample_spec_(sample_spec) + MockPlc(const SampleSpec& sample_spec, core::IArena& arena) + : IPlc(arena) + , sample_spec_(sample_spec) , lookbehind_len_(0) , lookahead_len_(0) , fill_value_(0) @@ -258,8 +259,11 @@ class MockPlc : public IPlc { template class IntPlc : public IPlc { public: - IntPlc(const SampleSpec& sample_spec, packet::stream_timestamp_t window_len) - : sample_spec_(sample_spec) + IntPlc(const SampleSpec& sample_spec, + packet::stream_timestamp_t window_len, + core::IArena& arena) + : IPlc(arena) + , sample_spec_(sample_spec) , window_len_(window_len) , fill_value_(0) { } @@ -385,7 +389,7 @@ TEST(plc_reader, small_read) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.11f, Frame::HasSignal); @@ -414,7 +418,7 @@ TEST(plc_reader, big_read) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.11f, Frame::HasSignal); @@ -443,7 +447,7 @@ TEST(plc_reader, initial_gap) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasGaps); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasGaps); @@ -496,7 +500,7 @@ TEST(plc_reader, readahead_disabled) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.11f, Frame::HasSignal); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasGaps); @@ -568,7 +572,7 @@ TEST(plc_reader, readahead_enabled) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.11f, Frame::HasSignal); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasGaps); @@ -675,7 +679,7 @@ TEST(plc_reader, readahead_drained) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.11f, Frame::HasSignal); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasGaps); @@ -749,7 +753,7 @@ TEST(plc_reader, readahead_partial) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.11f, Frame::HasSignal); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasGaps); @@ -826,7 +830,7 @@ TEST(plc_reader, soft_reads) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasGaps); add_samples(mock_reader, FrameSz, 0.22f, Frame::HasSignal); @@ -967,7 +971,7 @@ TEST(plc_reader, variable_frame_sizes) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); mock_plc.set_lookbehind(LookbehindSz); mock_plc.set_lookahead(LookaheadSz); @@ -1130,7 +1134,7 @@ TEST(plc_reader, without_cts) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.11f, Frame::HasSignal); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasGaps); @@ -1198,7 +1202,7 @@ TEST(plc_reader, with_cts) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz, 0.11f, Frame::HasSignal); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasGaps); @@ -1272,7 +1276,7 @@ TEST(plc_reader, non_raw_format) { ChanOrder_Smpte, ChanMask_Surround_Mono); IntReader int_reader(int_spec); - IntPlc int_plc(int_spec, FrameSz); + IntPlc int_plc(int_spec, FrameSz, arena); PlcReader plc_reader(int_reader, frame_factory, int_plc, int_spec); LONGS_EQUAL(status::StatusOK, plc_reader.init_status()); @@ -1360,7 +1364,7 @@ TEST(plc_reader, supported_backends) { plc_config.backend = supported_backends[n_back]; core::ScopedPtr plc( - processor_map.new_plc(arena, frame_factory, plc_config, sample_spec), arena); + processor_map.new_plc(plc_config, sample_spec, frame_factory, arena)); CHECK(plc); LONGS_EQUAL(status::StatusOK, plc->init_status()); @@ -1401,7 +1405,7 @@ TEST(plc_reader, forward_mode) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz * 10, 0.00f, Frame::HasSignal); @@ -1429,7 +1433,7 @@ TEST(plc_reader, forward_error) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz * 10, 0.00f, Frame::HasSignal); @@ -1457,7 +1461,7 @@ TEST(plc_reader, forward_partial) { ChanOrder_Smpte, ChanMask_Surround_Mono); test::MockReader mock_reader(frame_factory, sample_spec); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); add_samples(mock_reader, FrameSz / 2, 0.00f, Frame::HasSignal); @@ -1493,7 +1497,7 @@ TEST(plc_reader, preallocated_buffer) { test::MockReader mock_reader(frame_factory, sample_spec); add_samples(mock_reader, FrameSz, 0.00f, Frame::HasSignal); - MockPlc mock_plc(sample_spec); + MockPlc mock_plc(sample_spec, arena); PlcReader plc_reader(mock_reader, frame_factory, mock_plc, sample_spec); LONGS_EQUAL(status::StatusOK, plc_reader.init_status()); diff --git a/src/tests/roc_audio/test_resampler.cpp b/src/tests/roc_audio/test_resampler.cpp index 767a527c2..a48f11dee 100644 --- a/src/tests/roc_audio/test_resampler.cpp +++ b/src/tests/roc_audio/test_resampler.cpp @@ -353,7 +353,7 @@ void resample(ResamplerBackend backend, const SampleSpec& sample_spec, float scaling) { core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, profile), sample_spec, sample_spec); + make_config(backend, profile), sample_spec, sample_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -411,9 +411,8 @@ TEST(resampler, supported_scalings) { core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, supported_profiles[n_prof]), in_spec, - out_spec); + out_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -468,9 +467,8 @@ TEST(resampler, invalid_scalings) { ChanLayout_Surround, ChanOrder_Smpte, ChMask); core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, supported_profiles[n_prof]), in_spec, - out_spec); + out_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -520,8 +518,8 @@ TEST(resampler, scaling_trend) { const float scaling = supported_scalings[n_scale]; core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, ResamplerProfile_Low), - in_spec, out_spec); + make_config(backend, ResamplerProfile_Low), in_spec, out_spec, + frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -742,9 +740,8 @@ TEST(resampler, reader_timestamp_passthrough) { ChanLayout_Surround, ChanOrder_Smpte, ChMask); core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, supported_profiles[n_prof]), in_spec, - out_spec); + out_spec, frame_factory, arena); const core::nanoseconds_t start_ts = 1691499037871419405; core::nanoseconds_t cur_ts = start_ts; @@ -855,9 +852,8 @@ TEST(resampler, writer_timestamp_passthrough) { ChanLayout_Surround, ChanOrder_Smpte, ChMask); core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, supported_profiles[n_prof]), in_spec, - out_spec); + out_spec, frame_factory, arena); const core::nanoseconds_t start_ts = 1691499037871419405; core::nanoseconds_t cur_ts = start_ts; @@ -966,9 +962,8 @@ TEST(resampler, reader_timestamp_zero_or_small) { ChanLayout_Surround, ChanOrder_Smpte, ChMask); core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, supported_profiles[n_prof]), in_spec, - out_spec); + out_spec, frame_factory, arena); test::MockReader input_reader(frame_factory, in_spec); input_reader.add_zero_samples(); @@ -1045,9 +1040,8 @@ TEST(resampler, writer_timestamp_zero_or_small) { ChanLayout_Surround, ChanOrder_Smpte, ChMask); core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, supported_profiles[n_prof]), in_spec, - out_spec); + out_spec, frame_factory, arena); const core::nanoseconds_t epsilon = core::nanoseconds_t(1. / in_spec.sample_rate() * core::Second @@ -1110,9 +1104,9 @@ TEST(resampler, reader_big_frame) { test::MockReader input_reader(frame_factory, sample_spec); input_reader.add_zero_samples(); - core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, profile), sample_spec, - sample_spec); + core::SharedPtr resampler = + processor_map.new_resampler(make_config(backend, profile), sample_spec, + sample_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -1148,9 +1142,9 @@ TEST(resampler, writer_big_frame) { test::MockWriter output_writer; - core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, profile), sample_spec, - sample_spec); + core::SharedPtr resampler = + processor_map.new_resampler(make_config(backend, profile), sample_spec, + sample_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -1191,9 +1185,9 @@ TEST(resampler, reader_forward_mode) { test::MockReader input_reader(frame_factory, sample_spec); input_reader.add_zero_samples(); - core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, profile), sample_spec, - sample_spec); + core::SharedPtr resampler = + processor_map.new_resampler(make_config(backend, profile), sample_spec, + sample_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -1235,9 +1229,9 @@ TEST(resampler, reader_forward_error) { test::MockReader input_reader(frame_factory, sample_spec); - core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, profile), sample_spec, - sample_spec); + core::SharedPtr resampler = + processor_map.new_resampler(make_config(backend, profile), sample_spec, + sample_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -1279,9 +1273,9 @@ TEST(resampler, writer_forward_error) { test::MockWriter output_writer; - core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, profile), sample_spec, - sample_spec); + core::SharedPtr resampler = + processor_map.new_resampler(make_config(backend, profile), sample_spec, + sample_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -1322,9 +1316,9 @@ TEST(resampler, reader_process_partial) { test::MockReader input_reader(frame_factory, sample_spec); - core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, profile), sample_spec, - sample_spec); + core::SharedPtr resampler = + processor_map.new_resampler(make_config(backend, profile), sample_spec, + sample_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); @@ -1370,9 +1364,9 @@ TEST(resampler, reader_preallocated_buffer) { test::MockReader input_reader(frame_factory, sample_spec); input_reader.add_zero_samples(); - core::SharedPtr resampler = processor_map.new_resampler( - arena, frame_factory, make_config(backend, profile), sample_spec, - sample_spec); + core::SharedPtr resampler = + processor_map.new_resampler(make_config(backend, profile), sample_spec, + sample_spec, frame_factory, arena); CHECK(resampler); LONGS_EQUAL(status::StatusOK, resampler->init_status()); diff --git a/src/tests/roc_core/test_hashmap.cpp b/src/tests/roc_core/test_hashmap.cpp index 51125237d..175e474cd 100644 --- a/src/tests/roc_core/test_hashmap.cpp +++ b/src/tests/roc_core/test_hashmap.cpp @@ -21,17 +21,19 @@ namespace core { namespace { -struct HeapAllocation { - template void destroy(T& object) { - delete &object; +struct TestAllocation { + virtual ~TestAllocation() { + } + + void dispose() { + delete this; } }; -class Object : public HashmapNode<>, public RefCounted { +class Object : public HashmapNode<>, public RefCounted { public: Object(const char* k) { strcpy(key_, k); - visited_ = false; } static hashsum_t key_hash(const char* key) { @@ -46,17 +48,8 @@ class Object : public HashmapNode<>, public RefCounted { return key_; } - bool is_visited() { - return visited_; - } - - void set_visited() { - visited_ = true; - } - private: char key_[64]; - bool visited_; }; void format_key(char* key, size_t keysz, size_t n) { diff --git a/src/tests/roc_core/test_list.cpp b/src/tests/roc_core/test_list.cpp index 970a2bd1a..b5ee2efb8 100644 --- a/src/tests/roc_core/test_list.cpp +++ b/src/tests/roc_core/test_list.cpp @@ -19,14 +19,9 @@ namespace { enum { NumObjects = 5 }; -struct NoAllocation { - template void destroy(T&) { - } -}; - struct Object : ListNode<> {}; -struct RefObject : RefCounted, ListNode<> {}; +struct RefObject : RefCounted, ListNode<> {}; } // namespace diff --git a/src/tests/roc_core/test_mpsc_queue.cpp b/src/tests/roc_core/test_mpsc_queue.cpp index c24953dd0..4349f0673 100644 --- a/src/tests/roc_core/test_mpsc_queue.cpp +++ b/src/tests/roc_core/test_mpsc_queue.cpp @@ -17,12 +17,7 @@ namespace core { namespace { -struct NoAllocation { - template void destroy(T&) { - } -}; - -struct Object : RefCounted, MpscQueueNode<> {}; +struct Object : RefCounted, MpscQueueNode<> {}; } // namespace diff --git a/src/tests/roc_fec/test_block_encoder_decoder.cpp b/src/tests/roc_fec/test_block_encoder_decoder.cpp index c0121cbdf..26f8d2d7a 100644 --- a/src/tests/roc_fec/test_block_encoder_decoder.cpp +++ b/src/tests/roc_fec/test_block_encoder_decoder.cpp @@ -31,11 +31,9 @@ class Codec { : arena_() , packet_factory_(arena_, MaxPayloadSize) , encoder_( - CodecMap::instance().new_block_encoder(config, packet_factory_, arena_), - arena_) + CodecMap::instance().new_block_encoder(config, packet_factory_, arena_)) , decoder_( - CodecMap::instance().new_block_decoder(config, packet_factory_, arena_), - arena_) + CodecMap::instance().new_block_decoder(config, packet_factory_, arena_)) , buffers_(arena_) { set_fail(false); diff --git a/src/tests/roc_fec/test_block_writer_reader.cpp b/src/tests/roc_fec/test_block_writer_reader.cpp index 49c8f3e73..73c134f4e 100644 --- a/src/tests/roc_fec/test_block_writer_reader.cpp +++ b/src/tests/roc_fec/test_block_writer_reader.cpp @@ -46,18 +46,19 @@ core::HeapArena arena; packet::PacketFactory packet_factory(arena, MaxBuffSize); rtp::EncodingMap encoding_map(arena); -rtp::Parser rtp_parser(encoding_map, NULL); +rtp::Parser rtp_parser(NULL, encoding_map, arena); -Parser rs8m_source_parser(&rtp_parser); -Parser rs8m_repair_parser(NULL); -Parser ldpc_source_parser(&rtp_parser); -Parser ldpc_repair_parser(NULL); +Parser rs8m_source_parser(&rtp_parser, arena); +Parser rs8m_repair_parser(NULL, arena); +Parser ldpc_source_parser(&rtp_parser, arena); +Parser ldpc_repair_parser(NULL, arena); -rtp::Composer rtp_composer(NULL); -Composer rs8m_source_composer(&rtp_composer); -Composer rs8m_repair_composer(NULL); -Composer ldpc_source_composer(&rtp_composer); -Composer ldpc_repair_composer(NULL); +rtp::Composer rtp_composer(NULL, arena); +Composer rs8m_source_composer(&rtp_composer, arena); +Composer rs8m_repair_composer(NULL, arena); +Composer ldpc_source_composer(&rtp_composer, + arena); +Composer ldpc_repair_composer(NULL, arena); } // namespace @@ -210,12 +211,10 @@ TEST(block_writer_reader, no_losses) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -259,12 +258,10 @@ TEST(block_writer_reader, 1_loss) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -310,12 +307,10 @@ TEST(block_writer_reader, lost_first_packet_in_first_block) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -370,12 +365,10 @@ TEST(block_writer_reader, lost_one_source_and_all_repair_packets) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -444,12 +437,10 @@ TEST(block_writer_reader, multiple_blocks_1_loss) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -520,12 +511,10 @@ TEST(block_writer_reader, multiple_blocks_in_queue) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -577,12 +566,10 @@ TEST(block_writer_reader, interleaved_packets) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -634,12 +621,10 @@ TEST(block_writer_reader, delayed_packets) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -710,12 +695,10 @@ TEST(block_writer_reader, late_out_of_order_packets) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -792,12 +775,10 @@ TEST(block_writer_reader, repair_packets_before_source_packets) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -881,12 +862,10 @@ TEST(block_writer_reader, repair_packets_mixed_with_source_packets) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -984,12 +963,10 @@ TEST(block_writer_reader, multiple_repair_attempts) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1067,12 +1044,10 @@ TEST(block_writer_reader, drop_outdated_block) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1142,12 +1117,10 @@ TEST(block_writer_reader, repaired_block_numbering) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1232,12 +1205,10 @@ TEST(block_writer_reader, invalid_esi) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1315,12 +1286,10 @@ TEST(block_writer_reader, invalid_sbl) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1393,12 +1362,10 @@ TEST(block_writer_reader, invalid_nes) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1470,12 +1437,10 @@ TEST(block_writer_reader, invalid_payload_size) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1557,12 +1522,10 @@ TEST(block_writer_reader, zero_source_packets) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1644,12 +1607,10 @@ TEST(block_writer_reader, zero_repair_packets) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1729,12 +1690,10 @@ TEST(block_writer_reader, zero_payload_size) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1818,12 +1777,10 @@ TEST(block_writer_reader, sbn_jump) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -1933,10 +1890,8 @@ TEST(block_writer_reader, writer_encode_blocks) { packet::stream_source_t data_source = 555; for (size_t n = 0; n < 5; n++) { - core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, - arena), - arena); + core::ScopedPtr encoder(CodecMap::instance().new_block_encoder( + codec_config, packet_factory, arena)); CHECK(encoder); @@ -2028,8 +1983,7 @@ TEST(block_writer_reader, writer_resize_blocks) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); CHECK(encoder); test::PacketDispatcher dispatcher(source_parser(), repair_parser(), @@ -2092,12 +2046,10 @@ TEST(block_writer_reader, resize_block_begin) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(decoder); CHECK(encoder); @@ -2168,12 +2120,10 @@ TEST(block_writer_reader, resize_block_middle) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(decoder); CHECK(encoder); @@ -2267,12 +2217,10 @@ TEST(block_writer_reader, resize_block_losses) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(decoder); CHECK(encoder); @@ -2345,12 +2293,10 @@ TEST(block_writer_reader, resize_block_repair_first) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -2440,12 +2386,10 @@ TEST(block_writer_reader, writer_oversized_block) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -2509,12 +2453,10 @@ TEST(block_writer_reader, reader_oversized_source_block) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -2582,12 +2524,10 @@ TEST(block_writer_reader, reader_oversized_repair_block) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -2659,12 +2599,10 @@ TEST(block_writer_reader, reader_invalid_fec_scheme_source_packet) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -2734,12 +2672,10 @@ TEST(block_writer_reader, reader_invalid_fec_scheme_repair_packet) { codec_config.scheme = CodecMap::instance().nth_scheme(n_scheme); core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); diff --git a/src/tests/roc_fec/test_block_writer_reader_duration.cpp b/src/tests/roc_fec/test_block_writer_reader_duration.cpp index 1f093152b..7682e1e4f 100644 --- a/src/tests/roc_fec/test_block_writer_reader_duration.cpp +++ b/src/tests/roc_fec/test_block_writer_reader_duration.cpp @@ -43,14 +43,14 @@ core::HeapArena arena; packet::PacketFactory packet_factory(arena, MaxBuffSize); rtp::EncodingMap encoding_map(arena); -rtp::Parser rtp_parser(encoding_map, NULL); +rtp::Parser rtp_parser(NULL, encoding_map, arena); -Parser source_parser(&rtp_parser); -Parser repair_parser(NULL); +Parser source_parser(&rtp_parser, arena); +Parser repair_parser(NULL, arena); -rtp::Composer rtp_composer(NULL); -Composer source_composer(&rtp_composer); -Composer repair_composer(NULL); +rtp::Composer rtp_composer(NULL, arena); +Composer source_composer(&rtp_composer, arena); +Composer repair_composer(NULL, arena); } // namespace @@ -72,11 +72,9 @@ TEST_GROUP(block_writer_reader_duration) { if (fec_supported()) { encoder.reset(CodecMap::instance().new_block_encoder(codec_config, - packet_factory, arena), - arena); + packet_factory, arena)); decoder.reset(CodecMap::instance().new_block_decoder(codec_config, - packet_factory, arena), - arena); + packet_factory, arena)); CHECK(encoder); CHECK(decoder); } diff --git a/src/tests/roc_fec/test_block_writer_reader_errors.cpp b/src/tests/roc_fec/test_block_writer_reader_errors.cpp index be610dc29..2e3876fa3 100644 --- a/src/tests/roc_fec/test_block_writer_reader_errors.cpp +++ b/src/tests/roc_fec/test_block_writer_reader_errors.cpp @@ -46,14 +46,14 @@ core::HeapArena arena; packet::PacketFactory packet_factory(arena, MaxBuffSize); rtp::EncodingMap encoding_map(arena); -rtp::Parser rtp_parser(encoding_map, NULL); +rtp::Parser rtp_parser(NULL, encoding_map, arena); -Parser source_parser(&rtp_parser); -Parser repair_parser(NULL); +Parser source_parser(&rtp_parser, arena); +Parser repair_parser(NULL, arena); -rtp::Composer rtp_composer(NULL); -Composer source_composer(&rtp_composer); -Composer repair_composer(NULL); +rtp::Composer rtp_composer(NULL, arena); +Composer source_composer(&rtp_composer, arena); +Composer repair_composer(NULL, arena); } // namespace @@ -141,8 +141,7 @@ TEST(block_writer_reader_errors, writer_cant_resize_block) { } core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); CHECK(encoder); test::PacketDispatcher dispatcher(source_parser, repair_parser, packet_factory, @@ -188,8 +187,7 @@ TEST(block_writer_reader_errors, writer_cant_encode_packet) { test::MockArena mock_arena; core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, mock_arena), - mock_arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, mock_arena)); CHECK(encoder); test::PacketDispatcher dispatcher(source_parser, repair_parser, packet_factory, @@ -227,12 +225,10 @@ TEST(block_writer_reader_errors, reader_cant_resize_block) { } core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -299,15 +295,13 @@ TEST(block_writer_reader_errors, reader_cant_decode_packet) { } core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); CHECK(encoder); test::MockArena mock_arena; core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, mock_arena), - mock_arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, mock_arena)); CHECK(decoder); test::PacketDispatcher dispatcher(source_parser, repair_parser, packet_factory, @@ -381,12 +375,10 @@ TEST(block_writer_reader_errors, reader_cant_read_source_packet) { } core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -430,12 +422,10 @@ TEST(block_writer_reader_errors, reader_cant_read_repair_packet) { } core::ScopedPtr encoder( - CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_encoder(codec_config, packet_factory, arena)); core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(encoder); CHECK(decoder); @@ -479,8 +469,7 @@ TEST(block_writer_reader_errors, reader_cant_read_source_and_repair_packets) { } core::ScopedPtr decoder( - CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena), - arena); + CodecMap::instance().new_block_decoder(codec_config, packet_factory, arena)); CHECK(decoder); diff --git a/src/tests/roc_fec/test_block_writer_reader_peek.cpp b/src/tests/roc_fec/test_block_writer_reader_peek.cpp index 2f66a8269..4f35e8eb7 100644 --- a/src/tests/roc_fec/test_block_writer_reader_peek.cpp +++ b/src/tests/roc_fec/test_block_writer_reader_peek.cpp @@ -43,14 +43,14 @@ core::HeapArena arena; packet::PacketFactory packet_factory(arena, MaxBuffSize); rtp::EncodingMap encoding_map(arena); -rtp::Parser rtp_parser(encoding_map, NULL); +rtp::Parser rtp_parser(NULL, encoding_map, arena); -Parser source_parser(&rtp_parser); -Parser repair_parser(NULL); +Parser source_parser(&rtp_parser, arena); +Parser repair_parser(NULL, arena); -rtp::Composer rtp_composer(NULL); -Composer source_composer(&rtp_composer); -Composer repair_composer(NULL); +rtp::Composer rtp_composer(NULL, arena); +Composer source_composer(&rtp_composer, arena); +Composer repair_composer(NULL, arena); } // namespace @@ -72,11 +72,9 @@ TEST_GROUP(block_writer_reader_peek) { if (fec_supported()) { encoder.reset(CodecMap::instance().new_block_encoder(codec_config, - packet_factory, arena), - arena); + packet_factory, arena)); decoder.reset(CodecMap::instance().new_block_decoder(codec_config, - packet_factory, arena), - arena); + packet_factory, arena)); CHECK(encoder); CHECK(decoder); } diff --git a/src/tests/roc_fec/test_composer.cpp b/src/tests/roc_fec/test_composer.cpp index 783192f01..f4735e6c5 100644 --- a/src/tests/roc_fec/test_composer.cpp +++ b/src/tests/roc_fec/test_composer.cpp @@ -41,7 +41,7 @@ TEST(composer, align_footer) { UNSIGNED_LONGS_EQUAL(BufferSize, slice.capacity()); UNSIGNED_LONGS_EQUAL((unsigned long)buffer->data(), slice.data()); - Composer composer(NULL); + Composer composer(NULL, arena); CHECK(composer.align(slice, 0, Alignment)); UNSIGNED_LONGS_EQUAL(0, slice.size()); @@ -64,7 +64,7 @@ TEST(composer, align_header) { UNSIGNED_LONGS_EQUAL((unsigned long)buffer->data(), slice.data()); CHECK(((unsigned long)slice.data() + sizeof(RS8M_PayloadID)) % Alignment != 0); - Composer composer(NULL); + Composer composer(NULL, arena); CHECK(composer.align(slice, 0, Alignment)); UNSIGNED_LONGS_EQUAL(0, slice.size()); @@ -92,7 +92,7 @@ TEST(composer, align_outer_header) { CHECK(((unsigned long)slice.data() + sizeof(RS8M_PayloadID) + OuterHeader) % Alignment != 0); - Composer composer(NULL); + Composer composer(NULL, arena); CHECK(composer.align(slice, OuterHeader, Alignment)); UNSIGNED_LONGS_EQUAL(0, slice.size()); @@ -115,7 +115,7 @@ TEST(composer, packet_size) { packet::PacketPtr packet = packet_factory.new_packet(); CHECK(packet); - Composer composer(NULL); + Composer composer(NULL, arena); CHECK(composer.align(buffer, 0, Alignment)); CHECK(composer.prepare(*packet, buffer, PayloadSize)); diff --git a/src/tests/roc_fec/test_composer_parser.cpp b/src/tests/roc_fec/test_composer_parser.cpp index e43281b70..48e9393fa 100644 --- a/src/tests/roc_fec/test_composer_parser.cpp +++ b/src/tests/roc_fec/test_composer_parser.cpp @@ -236,12 +236,12 @@ void test_all(const PacketTest& test) { TEST_GROUP(composer_parser) {}; TEST(composer_parser, rtp_ldpc_source) { - rtp::Composer rtp_composer(NULL); - Composer ldpc_composer(&rtp_composer); + rtp::Composer rtp_composer(NULL, arena); + Composer ldpc_composer(&rtp_composer, arena); rtp::EncodingMap rtp_encoding_map(arena); - rtp::Parser rtp_parser(rtp_encoding_map, NULL); - Parser ldpc_parser(&rtp_parser); + rtp::Parser rtp_parser(NULL, rtp_encoding_map, arena); + Parser ldpc_parser(&rtp_parser, arena); PacketTest test; test.composer = &ldpc_composer; @@ -256,8 +256,8 @@ TEST(composer_parser, rtp_ldpc_source) { } TEST(composer_parser, ldpc_repair) { - Composer ldpc_composer(NULL); - Parser ldpc_parser(NULL); + Composer ldpc_composer(NULL, arena); + Parser ldpc_parser(NULL, arena); PacketTest test; test.composer = &ldpc_composer; @@ -272,12 +272,12 @@ TEST(composer_parser, ldpc_repair) { } TEST(composer_parser, rtp_rs8m_source) { - rtp::Composer rtp_composer(NULL); - Composer rs8m_composer(&rtp_composer); + rtp::Composer rtp_composer(NULL, arena); + Composer rs8m_composer(&rtp_composer, arena); rtp::EncodingMap rtp_encoding_map(arena); - rtp::Parser rtp_parser(rtp_encoding_map, NULL); - Parser rs8m_parser(&rtp_parser); + rtp::Parser rtp_parser(NULL, rtp_encoding_map, arena); + Parser rs8m_parser(&rtp_parser, arena); PacketTest test; test.composer = &rs8m_composer; @@ -292,8 +292,8 @@ TEST(composer_parser, rtp_rs8m_source) { } TEST(composer_parser, rs8m_repair) { - Composer rs8m_composer(NULL); - Parser rs8m_parser(NULL); + Composer rs8m_composer(NULL, arena); + Parser rs8m_parser(NULL, arena); PacketTest test; test.composer = &rs8m_composer; diff --git a/src/tests/roc_packet/test_shipper.cpp b/src/tests/roc_packet/test_shipper.cpp index 7d9dabbb4..1901fb30f 100644 --- a/src/tests/roc_packet/test_shipper.cpp +++ b/src/tests/roc_packet/test_shipper.cpp @@ -53,8 +53,9 @@ class MockWriter : public IWriter, public core::NonCopyable<> { }; struct MockComposer : public IComposer, public core::NonCopyable<> { - MockComposer() - : compose_call_count(0) { + MockComposer(core::IArena& arena) + : IComposer(arena) + , compose_call_count(0) { } virtual status::StatusCode init_status() const { @@ -86,7 +87,7 @@ struct MockComposer : public IComposer, public core::NonCopyable<> { TEST_GROUP(shipper) {}; TEST(shipper, without_address) { - MockComposer composer; + MockComposer composer(arena); FifoQueue queue; Shipper shipper(composer, queue, NULL); @@ -110,7 +111,7 @@ TEST(shipper, with_address) { address::SocketAddr address; CHECK(address.set_host_port_auto("127.0.0.1", 123)); - MockComposer composer; + MockComposer composer(arena); FifoQueue queue; Shipper shipper(composer, queue, &address); @@ -132,7 +133,7 @@ TEST(shipper, with_address) { TEST(shipper, packet_already_composed) { address::SocketAddr address; - MockComposer composer; + MockComposer composer(arena); FifoQueue queue; Shipper shipper(composer, queue, &address); @@ -155,7 +156,7 @@ TEST(shipper, packet_already_composed) { TEST(shipper, packet_not_composed) { address::SocketAddr address; - MockComposer composer; + MockComposer composer(arena); FifoQueue queue; Shipper shipper(composer, queue, &address); @@ -183,7 +184,7 @@ TEST(shipper, forward_error) { for (size_t st_n = 0; st_n < ROC_ARRAY_SIZE(status_codes); ++st_n) { address::SocketAddr address; - MockComposer composer; + MockComposer composer(arena); MockWriter writer(status_codes[st_n]); Shipper shipper(composer, writer, &address); diff --git a/src/tests/roc_pipeline/test_helpers/mock_sink.h b/src/tests/roc_pipeline/test_helpers/mock_sink.h index 3ef3408a8..f7206cd91 100644 --- a/src/tests/roc_pipeline/test_helpers/mock_sink.h +++ b/src/tests/roc_pipeline/test_helpers/mock_sink.h @@ -22,8 +22,10 @@ namespace test { class MockSink : public sndio::ISink, public core::NonCopyable<> { public: - MockSink(const audio::SampleSpec& sample_spec) - : off_(0) + MockSink(const audio::SampleSpec& sample_spec, core::IArena& arena) + : sndio::IDevice(arena) + , sndio::ISink(arena) + , off_(0) , n_frames_(0) , n_samples_(0) , n_chans_(sample_spec.num_channels()) { @@ -57,10 +59,6 @@ class MockSink : public sndio::ISink, public core::NonCopyable<> { return false; } - virtual status::StatusCode close() { - return status::StatusOK; - } - virtual status::StatusCode write(audio::Frame& frame) { CHECK(frame.num_raw_samples() % n_chans_ == 0); @@ -83,6 +81,14 @@ class MockSink : public sndio::ISink, public core::NonCopyable<> { return status::StatusOK; } + virtual status::StatusCode close() { + return status::StatusOK; + } + + virtual void dispose() { + arena().dispose_object(*this); + } + void expect_frames(size_t total) { UNSIGNED_LONGS_EQUAL(total, n_frames_); } diff --git a/src/tests/roc_pipeline/test_helpers/mock_source.h b/src/tests/roc_pipeline/test_helpers/mock_source.h index ae662d468..c145faef8 100644 --- a/src/tests/roc_pipeline/test_helpers/mock_source.h +++ b/src/tests/roc_pipeline/test_helpers/mock_source.h @@ -23,8 +23,12 @@ namespace test { class MockSource : public sndio::ISource { public: - MockSource(audio::FrameFactory& frame_factory, const audio::SampleSpec& sample_spec) - : frame_factory_(frame_factory) + MockSource(audio::FrameFactory& frame_factory, + const audio::SampleSpec& sample_spec, + core::IArena& arena) + : sndio::IDevice(arena) + , sndio::ISource(arena) + , frame_factory_(frame_factory) , sample_spec_(sample_spec) , state_(sndio::DeviceState_Active) , pos_(0) @@ -79,10 +83,6 @@ class MockSource : public sndio::ISource { return false; } - virtual status::StatusCode close() { - return status::StatusOK; - } - virtual status::StatusCode rewind() { state_ = sndio::DeviceState_Active; return status::StatusOK; @@ -128,6 +128,14 @@ class MockSource : public sndio::ISource { return status::StatusOK; } + virtual status::StatusCode close() { + return status::StatusOK; + } + + virtual void dispose() { + arena().dispose_object(*this); + } + void add(size_t num_samples, const audio::SampleSpec& sample_spec) { CHECK(size_ + num_samples * sample_spec.num_channels() <= MaxSz); diff --git a/src/tests/roc_pipeline/test_helpers/packet_reader.h b/src/tests/roc_pipeline/test_helpers/packet_reader.h index adcbce3c6..c2c92ec43 100644 --- a/src/tests/roc_pipeline/test_helpers/packet_reader.h +++ b/src/tests/roc_pipeline/test_helpers/packet_reader.h @@ -117,11 +117,11 @@ class PacketReader : public core::NonCopyable<> { // payload decoder const rtp::Encoding* enc = encoding_map.find_by_pt(pt); CHECK(enc); - payload_decoder_.reset(enc->new_decoder(arena, enc->sample_spec), arena); + payload_decoder_.reset(enc->new_decoder(enc->sample_spec, arena)); CHECK(payload_decoder_); // rtp parser - parser_.reset(new (arena) rtp::Parser(encoding_map, NULL), arena); + parser_.reset(new (arena) rtp::Parser(NULL, encoding_map, arena)); } packet::PacketPtr read_packet_() { diff --git a/src/tests/roc_pipeline/test_helpers/packet_writer.h b/src/tests/roc_pipeline/test_helpers/packet_writer.h index efcb902ec..c291bf74c 100644 --- a/src/tests/roc_pipeline/test_helpers/packet_writer.h +++ b/src/tests/roc_pipeline/test_helpers/packet_writer.h @@ -178,58 +178,51 @@ class PacketWriter : public core::NonCopyable<> { // payload encoder const rtp::Encoding* enc = encoding_map.find_by_pt(pt); CHECK(enc); - payload_encoder_.reset(enc->new_encoder(arena, enc->sample_spec), arena); + payload_encoder_.reset(enc->new_encoder(enc->sample_spec, arena)); CHECK(payload_encoder_); if (fec_scheme == packet::FEC_None) { // rtp composer - source_composer_.reset(new (arena) rtp::Composer(NULL), arena); + source_composer_.reset(new (arena) rtp::Composer(NULL, arena)); } else { if (fec_scheme == packet::FEC_ReedSolomon_M8) { // rs8m composers - payload_composer_.reset(new (arena) rtp::Composer(NULL), arena); + payload_composer_.reset(new (arena) rtp::Composer(NULL, arena)); source_composer_.reset( new (arena) fec::Composer( - payload_composer_.get()), - arena); + payload_composer_.get(), arena)); repair_composer_.reset( new (arena) fec::Composer( - NULL), - arena); + NULL, arena)); } else if (fec_scheme == packet::FEC_LDPC_Staircase) { // ldpc composers - payload_composer_.reset(new (arena) rtp::Composer(NULL), arena); + payload_composer_.reset(new (arena) rtp::Composer(NULL, arena)); - source_composer_.reset( - new (arena) fec::Composer(payload_composer_.get()), - arena); - - repair_composer_.reset(new (arena) - fec::Composer(NULL), - arena); + source_composer_.reset(new ( + arena) fec::Composer(payload_composer_.get(), arena)); + + repair_composer_.reset( + new (arena) fec::Composer(NULL, arena)); } // fec encoder fec::CodecConfig codec_config; codec_config.scheme = fec_scheme; fec_encoder_.reset(fec::CodecMap::instance().new_block_encoder( - codec_config, packet_factory, arena), - arena); + codec_config, packet_factory, arena)); CHECK(fec_encoder_); LONGS_EQUAL(status::StatusOK, fec_encoder_->init_status()); // fec writer - fec_writer_.reset( - new (arena) fec::BlockWriter(fec_config, fec_scheme, *fec_encoder_, - fec_queue_, *source_composer_, - *repair_composer_, packet_factory, arena), - arena); + fec_writer_.reset(new (fec_writer_) fec::BlockWriter( + fec_config, fec_scheme, *fec_encoder_, fec_queue_, *source_composer_, + *repair_composer_, packet_factory, arena)); CHECK(fec_writer_); LONGS_EQUAL(status::StatusOK, fec_writer_->init_status()); } @@ -356,7 +349,7 @@ class PacketWriter : public core::NonCopyable<> { core::ScopedPtr repair_composer_; core::ScopedPtr fec_encoder_; - core::ScopedPtr fec_writer_; + core::Optional fec_writer_; packet::FifoQueue fec_queue_; core::ScopedPtr payload_encoder_; diff --git a/src/tests/roc_pipeline/test_receiver_endpoint.cpp b/src/tests/roc_pipeline/test_receiver_endpoint.cpp index 19c836f61..736ed6d87 100644 --- a/src/tests/roc_pipeline/test_receiver_endpoint.cpp +++ b/src/tests/roc_pipeline/test_receiver_endpoint.cpp @@ -37,7 +37,7 @@ rtp::EncodingMap encoding_map(arena); TEST_GROUP(receiver_endpoint) {}; TEST(receiver_endpoint, valid) { - audio::Mixer mixer(frame_factory, arena, DefaultSampleSpec, false); + audio::Mixer mixer(DefaultSampleSpec, false, frame_factory, arena); StateTracker state_tracker; ReceiverSourceConfig source_config; @@ -52,7 +52,7 @@ TEST(receiver_endpoint, valid) { } TEST(receiver_endpoint, invalid_proto) { - audio::Mixer mixer(frame_factory, arena, DefaultSampleSpec, false); + audio::Mixer mixer(DefaultSampleSpec, false, frame_factory, arena); StateTracker state_tracker; ReceiverSourceConfig source_config; @@ -75,7 +75,7 @@ TEST(receiver_endpoint, no_memory) { }; for (size_t n = 0; n < ROC_ARRAY_SIZE(protos); ++n) { - audio::Mixer mixer(frame_factory, arena, DefaultSampleSpec, false); + audio::Mixer mixer(DefaultSampleSpec, false, frame_factory, arena); StateTracker state_tracker; ReceiverSourceConfig source_config; diff --git a/src/tests/roc_pipeline/test_transcoder_sink.cpp b/src/tests/roc_pipeline/test_transcoder_sink.cpp index b36046a5f..cf7b8b5a8 100644 --- a/src/tests/roc_pipeline/test_transcoder_sink.cpp +++ b/src/tests/roc_pipeline/test_transcoder_sink.cpp @@ -100,7 +100,7 @@ TEST(transcoder_sink, write) { init(Rate, Chans, Rate, Chans); - test::MockSink mock_sink(output_sample_spec); + test::MockSink mock_sink(output_sample_spec, arena); TranscoderSink transcoder(make_config(), &mock_sink, processor_map, frame_pool, frame_buffer_pool, arena); @@ -125,7 +125,7 @@ TEST(transcoder_sink, frame_size_small) { init(Rate, Chans, Rate, Chans); - test::MockSink mock_sink(output_sample_spec); + test::MockSink mock_sink(output_sample_spec, arena); TranscoderSink transcoder(make_config(), &mock_sink, processor_map, frame_pool, frame_buffer_pool, arena); @@ -150,7 +150,7 @@ TEST(transcoder_sink, frame_size_large) { init(Rate, Chans, Rate, Chans); - test::MockSink mock_sink(output_sample_spec); + test::MockSink mock_sink(output_sample_spec, arena); TranscoderSink transcoder(make_config(), &mock_sink, processor_map, frame_pool, frame_buffer_pool, arena); @@ -171,7 +171,7 @@ TEST(transcoder_sink, channel_mapping_stereo_to_mono) { init(Rate, InputChans, Rate, OutputChans); - test::MockSink mock_sink(output_sample_spec); + test::MockSink mock_sink(output_sample_spec, arena); TranscoderSink transcoder(make_config(), &mock_sink, processor_map, frame_pool, frame_buffer_pool, arena); @@ -192,7 +192,7 @@ TEST(transcoder_sink, channel_mapping_mono_to_stereo) { init(Rate, InputChans, Rate, OutputChans); - test::MockSink mock_sink(output_sample_spec); + test::MockSink mock_sink(output_sample_spec, arena); TranscoderSink transcoder(make_config(), &mock_sink, processor_map, frame_pool, frame_buffer_pool, arena); diff --git a/src/tests/roc_pipeline/test_transcoder_source.cpp b/src/tests/roc_pipeline/test_transcoder_source.cpp index 75f6a477a..6013503e7 100644 --- a/src/tests/roc_pipeline/test_transcoder_source.cpp +++ b/src/tests/roc_pipeline/test_transcoder_source.cpp @@ -95,7 +95,7 @@ TEST(transcoder_source, state) { init(Chans, Chans); - test::MockSource mock_source(frame_factory, input_sample_spec); + test::MockSource mock_source(frame_factory, input_sample_spec, arena); TranscoderSource transcoder(make_config(), mock_source, processor_map, frame_pool, frame_buffer_pool, arena); @@ -113,7 +113,7 @@ TEST(transcoder_source, pause_resume) { init(Chans, Chans); - test::MockSource mock_source(frame_factory, input_sample_spec); + test::MockSource mock_source(frame_factory, input_sample_spec, arena); TranscoderSource transcoder(make_config(), mock_source, processor_map, frame_pool, frame_buffer_pool, arena); @@ -133,7 +133,7 @@ TEST(transcoder_source, pause_restart) { init(Chans, Chans); - test::MockSource mock_source(frame_factory, input_sample_spec); + test::MockSource mock_source(frame_factory, input_sample_spec, arena); TranscoderSource transcoder(make_config(), mock_source, processor_map, frame_pool, frame_buffer_pool, arena); @@ -153,7 +153,7 @@ TEST(transcoder_source, read) { init(Chans, Chans); - test::MockSource mock_source(frame_factory, input_sample_spec); + test::MockSource mock_source(frame_factory, input_sample_spec, arena); mock_source.add(ManyFrames * SamplesPerFrame, input_sample_spec); TranscoderSource transcoder(make_config(), mock_source, processor_map, frame_pool, @@ -174,7 +174,7 @@ TEST(transcoder_source, eof) { init(Chans, Chans); - test::MockSource mock_source(frame_factory, input_sample_spec); + test::MockSource mock_source(frame_factory, input_sample_spec, arena); TranscoderSource transcoder(make_config(), mock_source, processor_map, frame_pool, frame_buffer_pool, arena); @@ -191,7 +191,7 @@ TEST(transcoder_source, frame_size_small) { init(Chans, Chans); - test::MockSource mock_source(frame_factory, input_sample_spec); + test::MockSource mock_source(frame_factory, input_sample_spec, arena); mock_source.add(ManyFrames * SamplesPerSmallFrame, input_sample_spec); TranscoderSource transcoder(make_config(), mock_source, processor_map, frame_pool, @@ -212,7 +212,7 @@ TEST(transcoder_source, frame_size_large) { init(Chans, Chans); - test::MockSource mock_source(frame_factory, input_sample_spec); + test::MockSource mock_source(frame_factory, input_sample_spec, arena); mock_source.add(ManyFrames * SamplesPerLargeFrame, input_sample_spec); TranscoderSource transcoder(make_config(), mock_source, processor_map, frame_pool, @@ -233,7 +233,7 @@ TEST(transcoder_source, channel_mapping_stereo_to_mono) { init(InputChans, OutputChans); - test::MockSource mock_source(frame_factory, input_sample_spec); + test::MockSource mock_source(frame_factory, input_sample_spec, arena); mock_source.add(ManyFrames * SamplesPerFrame, input_sample_spec); TranscoderSource transcoder(make_config(), mock_source, processor_map, frame_pool, @@ -254,7 +254,7 @@ TEST(transcoder_source, channel_mapping_mono_to_stereo) { init(InputChans, OutputChans); - test::MockSource mock_source(frame_factory, input_sample_spec); + test::MockSource mock_source(frame_factory, input_sample_spec, arena); mock_source.add(ManyFrames * SamplesPerFrame, input_sample_spec); TranscoderSource transcoder(make_config(), mock_source, processor_map, frame_pool, diff --git a/src/tests/roc_rtcp/test_communicator.cpp b/src/tests/roc_rtcp/test_communicator.cpp index 002ac9247..76fd24a92 100644 --- a/src/tests/roc_rtcp/test_communicator.cpp +++ b/src/tests/roc_rtcp/test_communicator.cpp @@ -69,7 +69,7 @@ packet::PacketFactory packet_factory(arena, MaxPacketSz); packet::PacketFactory small_packet_factory(arena, SmallPacketSz); packet::PacketFactory tiny_packet_factory(arena, TinyPacketSz); -Composer composer; +Composer composer(arena); // Mock implementation of IParticipant struct MockParticipant : public IParticipant, public core::NonCopyable<> { diff --git a/src/tests/roc_rtp/test_filter.cpp b/src/tests/roc_rtp/test_filter.cpp index a8a3cacf4..822bbd32c 100644 --- a/src/tests/roc_rtp/test_filter.cpp +++ b/src/tests/roc_rtp/test_filter.cpp @@ -42,11 +42,11 @@ const audio::SampleSpec payload_spec(SampleRate, audio::ChanOrder_Smpte, ChMask); -audio::PcmDecoder decoder(payload_spec); - core::HeapArena arena; packet::PacketFactory packet_factory(arena, PacketSz); +audio::PcmDecoder decoder(payload_spec, arena); + packet::PacketPtr new_packet(PayloadType pt, packet::stream_source_t src, packet::seqnum_t sn, diff --git a/src/tests/roc_rtp/test_packet_formats.cpp b/src/tests/roc_rtp/test_packet_formats.cpp index f466c2f8e..4d28343ce 100644 --- a/src/tests/roc_rtp/test_packet_formats.cpp +++ b/src/tests/roc_rtp/test_packet_formats.cpp @@ -165,14 +165,14 @@ void check_parse_decode(const test::PacketInfo& pi) { packet->set_buffer(buffer); - Parser parser(encoding_map, NULL); + Parser parser(NULL, encoding_map, arena); CHECK(parser.parse(*packet, packet->buffer())); const Encoding* encoding = encoding_map.find_by_pt(packet->rtp()->payload_type); CHECK(encoding); core::ScopedPtr decoder( - encoding->new_decoder(arena, encoding->sample_spec), arena); + encoding->new_decoder(encoding->sample_spec, arena)); CHECK(decoder); check_format_info(*encoding, pi); @@ -197,10 +197,10 @@ void check_compose_encode(const test::PacketInfo& pi) { CHECK(encoding); core::ScopedPtr encoder( - encoding->new_encoder(arena, encoding->sample_spec), arena); + encoding->new_encoder(encoding->sample_spec, arena)); CHECK(encoder); - Composer composer(NULL); + Composer composer(NULL, arena); CHECK(composer.prepare(*packet, buffer, pi.payload_size + pi.padding_size)); packet->set_buffer(buffer); diff --git a/src/tests/roc_sndio/test_backend_source.cpp b/src/tests/roc_sndio/test_backend_source.cpp index 53000ff38..c133ccd6c 100644 --- a/src/tests/roc_sndio/test_backend_source.cpp +++ b/src/tests/roc_sndio/test_backend_source.cpp @@ -48,7 +48,7 @@ void write_wav(IBackend& backend, const IoConfig& config, const char* path, size_t num_samples) { - test::MockSource mock_source(frame_factory, config.sample_spec); + test::MockSource mock_source(frame_factory, config.sample_spec, arena); mock_source.add(num_samples * sample_spec.num_channels()); IDevice* backend_device = NULL; @@ -56,7 +56,7 @@ void write_wav(IBackend& backend, backend.open_device(DeviceType_Sink, DriverType_File, NULL, path, config, frame_factory, arena, &backend_device)); CHECK(backend_device != NULL); - core::ScopedPtr backend_sink(backend_device->to_sink(), arena); + core::ScopedPtr backend_sink(backend_device->to_sink()); CHECK(backend_sink != NULL); IoPump pump(frame_pool, frame_buffer_pool, mock_source, NULL, *backend_sink, config, diff --git a/src/tests/roc_sndio/test_helpers/mock_sink.h b/src/tests/roc_sndio/test_helpers/mock_sink.h index 1877ba57f..5ad9b4f67 100644 --- a/src/tests/roc_sndio/test_helpers/mock_sink.h +++ b/src/tests/roc_sndio/test_helpers/mock_sink.h @@ -19,8 +19,10 @@ namespace test { class MockSink : public ISink { public: - MockSink() - : pos_(0) { + MockSink(core::IArena& arena) + : IDevice(arena) + , ISink(arena) + , pos_(0) { } virtual DeviceType type() const { @@ -65,10 +67,6 @@ class MockSink : public ISink { return false; } - virtual status::StatusCode close() { - return status::StatusOK; - } - virtual status::StatusCode write(audio::Frame& frame) { CHECK(pos_ + frame.num_raw_samples() <= MaxSz); @@ -78,6 +76,18 @@ class MockSink : public ISink { return status::StatusOK; } + virtual ROC_ATTR_NODISCARD status::StatusCode flush() { + return status::StatusOK; + } + + virtual status::StatusCode close() { + return status::StatusOK; + } + + virtual void dispose() { + arena().dispose_object(*this); + } + void check(size_t offset, size_t size) { UNSIGNED_LONGS_EQUAL(pos_, size); @@ -86,10 +96,6 @@ class MockSink : public ISink { } } - virtual ROC_ATTR_NODISCARD status::StatusCode flush() { - return status::StatusOK; - } - private: enum { MaxSz = 256 * 1024 }; diff --git a/src/tests/roc_sndio/test_helpers/mock_source.h b/src/tests/roc_sndio/test_helpers/mock_source.h index 68c1ecdf4..2c127753f 100644 --- a/src/tests/roc_sndio/test_helpers/mock_source.h +++ b/src/tests/roc_sndio/test_helpers/mock_source.h @@ -22,8 +22,12 @@ namespace test { class MockSource : public ISource { public: - MockSource(audio::FrameFactory& frame_factory, const audio::SampleSpec& sample_spec) - : frame_factory_(frame_factory) + MockSource(audio::FrameFactory& frame_factory, + const audio::SampleSpec& sample_spec, + core::IArena& arena) + : IDevice(arena) + , ISource(arena) + , frame_factory_(frame_factory) , sample_spec_(sample_spec) , pos_(0) , size_(0) { @@ -75,10 +79,6 @@ class MockSource : public ISource { return false; } - virtual status::StatusCode close() { - return status::StatusOK; - } - virtual status::StatusCode rewind() { FAIL("not implemented"); return status::StatusAbort; @@ -117,6 +117,14 @@ class MockSource : public ISource { return status::StatusOK; } + virtual status::StatusCode close() { + return status::StatusOK; + } + + virtual void dispose() { + arena().dispose_object(*this); + } + void add(size_t sz) { CHECK(size_ + sz <= MaxSz); diff --git a/src/tests/roc_sndio/test_helpers/utils.h b/src/tests/roc_sndio/test_helpers/utils.h index 8e65a6624..bd5f71a63 100644 --- a/src/tests/roc_sndio/test_helpers/utils.h +++ b/src/tests/roc_sndio/test_helpers/utils.h @@ -60,7 +60,7 @@ void expect_open_sink(status::StatusCode expected_code, if (code == status::StatusOK) { CHECK(device); CHECK(device->to_sink()); - result.reset(device->to_sink(), arena); + result.reset(device->to_sink()); } else { CHECK(!device); } @@ -94,7 +94,7 @@ void expect_open_source(status::StatusCode expected_code, if (code == status::StatusOK) { CHECK(device); CHECK(device->to_source()); - result.reset(device->to_source(), arena); + result.reset(device->to_source()); } else { CHECK(!device); } diff --git a/src/tests/roc_sndio/test_io_pump.cpp b/src/tests/roc_sndio/test_io_pump.cpp index 2faf27e53..c539a1427 100644 --- a/src/tests/roc_sndio/test_io_pump.cpp +++ b/src/tests/roc_sndio/test_io_pump.cpp @@ -73,7 +73,7 @@ TEST(io_pump, write_read) { dbgio::TempFile file("test.wav"); - test::MockSource mock_source(frame_factory, sink_config.sample_spec); + test::MockSource mock_source(frame_factory, sink_config.sample_spec, arena); mock_source.add(NumSamples); { @@ -99,7 +99,7 @@ TEST(io_pump, write_read) { backend_source); // copy from source to mock sink - test::MockSink mock_sink; + test::MockSink mock_sink(arena); IoPump pump(frame_pool, frame_buffer_pool, *backend_source, NULL, mock_sink, sink_config, IoPump::ModePermanent); LONGS_EQUAL(status::StatusOK, pump.init_status()); @@ -122,7 +122,7 @@ TEST(io_pump, write_overwrite_read) { dbgio::TempFile file("test.wav"); - test::MockSource mock_source(frame_factory, sink_config.sample_spec); + test::MockSource mock_source(frame_factory, sink_config.sample_spec, arena); mock_source.add(NumSamples); { @@ -169,7 +169,7 @@ TEST(io_pump, write_overwrite_read) { backend_source); // copy from source to mock sink - test::MockSink mock_sink; + test::MockSink mock_sink(arena); IoPump pump(frame_pool, frame_buffer_pool, *backend_source, NULL, mock_sink, sink_config, IoPump::ModePermanent); LONGS_EQUAL(status::StatusOK, pump.init_status()); diff --git a/src/tools/roc_copy/main.cpp b/src/tools/roc_copy/main.cpp index 0831cbc23..c8c69292c 100644 --- a/src/tools/roc_copy/main.cpp +++ b/src/tools/roc_copy/main.cpp @@ -12,6 +12,7 @@ #include "roc_core/log.h" #include "roc_core/parse_units.h" #include "roc_core/scoped_ptr.h" +#include "roc_core/scoped_release.h" #include "roc_pipeline/transcoder_sink.h" #include "roc_sndio/backend_dispatcher.h" #include "roc_sndio/backend_map.h" @@ -37,8 +38,7 @@ int main(int argc, char** argv) { return code; } - core::ScopedPtr args_holder( - &args, &cmdline_parser_free); + core::ScopedRelease args_holder(&args, &cmdline_parser_free); core::Logger::instance().set_verbosity(args.verbose_given); diff --git a/src/tools/roc_recv/main.cpp b/src/tools/roc_recv/main.cpp index af4fb9740..49abc30dc 100644 --- a/src/tools/roc_recv/main.cpp +++ b/src/tools/roc_recv/main.cpp @@ -15,6 +15,7 @@ #include "roc_core/log.h" #include "roc_core/parse_units.h" #include "roc_core/scoped_ptr.h" +#include "roc_core/scoped_release.h" #include "roc_core/time.h" #include "roc_netio/network_loop.h" #include "roc_node/context.h" @@ -46,8 +47,7 @@ int main(int argc, char** argv) { return code; } - core::ScopedPtr args_holder( - &args, &cmdline_parser_free); + core::ScopedRelease args_holder(&args, &cmdline_parser_free); core::Logger::instance().set_verbosity(args.verbose_given); @@ -459,10 +459,8 @@ int main(int argc, char** argv) { receiver_config.common.output_sample_spec.channel_set()); backup_pipeline.reset(new (context.arena()) pipeline::TranscoderSource( - transcoder_config, *backup_source, - context.processor_map(), context.frame_pool(), - context.frame_buffer_pool(), context.arena()), - context.arena()); + transcoder_config, *backup_source, context.processor_map(), + context.frame_pool(), context.frame_buffer_pool(), context.arena())); if (!backup_pipeline) { roc_log(LogError, "can't allocate backup pipeline"); return 1; diff --git a/src/tools/roc_send/main.cpp b/src/tools/roc_send/main.cpp index 36bd32b6f..369965b9b 100644 --- a/src/tools/roc_send/main.cpp +++ b/src/tools/roc_send/main.cpp @@ -15,6 +15,7 @@ #include "roc_core/log.h" #include "roc_core/parse_units.h" #include "roc_core/scoped_ptr.h" +#include "roc_core/scoped_release.h" #include "roc_core/time.h" #include "roc_netio/network_loop.h" #include "roc_node/context.h" @@ -45,8 +46,7 @@ int main(int argc, char** argv) { return code; } - core::ScopedPtr args_holder( - &args, &cmdline_parser_free); + core::ScopedRelease args_holder(&args, &cmdline_parser_free); core::Logger::instance().set_verbosity(args.verbose_given);