filter/Internal: return std::unique_ptr<Filter>

This commit is contained in:
Max Kellermann
2017-12-27 11:42:14 +01:00
parent e2621d5e44
commit edef62df86
12 changed files with 64 additions and 70 deletions

View File

@@ -29,6 +29,9 @@
#include <string.h>
AudioOutputSource::AudioOutputSource() noexcept {}
AudioOutputSource::~AudioOutputSource() noexcept = default;
AudioFormat
AudioOutputSource::Open(const AudioFormat audio_format, const MusicPipe &_pipe,
PreparedFilter *prepared_replay_gain_filter,
@@ -116,14 +119,9 @@ try {
void
AudioOutputSource::CloseFilter() noexcept
{
delete replay_gain_filter_instance;
replay_gain_filter_instance = nullptr;
delete other_replay_gain_filter_instance;
other_replay_gain_filter_instance = nullptr;
delete filter_instance;
filter_instance = nullptr;
replay_gain_filter_instance.reset();
other_replay_gain_filter_instance.reset();
filter_instance.reset();
}
ConstBuffer<void>
@@ -160,7 +158,7 @@ AudioOutputSource::GetChunkData(const MusicChunk &chunk,
ConstBuffer<void>
AudioOutputSource::FilterChunk(const MusicChunk &chunk)
{
auto data = GetChunkData(chunk, replay_gain_filter_instance,
auto data = GetChunkData(chunk, replay_gain_filter_instance.get(),
&replay_gain_serial);
if (data.empty())
return data;
@@ -169,7 +167,7 @@ AudioOutputSource::FilterChunk(const MusicChunk &chunk)
if (chunk.other != nullptr) {
auto other_data = GetChunkData(*chunk.other,
other_replay_gain_filter_instance,
other_replay_gain_filter_instance.get(),
&other_replay_gain_serial);
if (other_data.empty())
return data;

View File

@@ -30,6 +30,7 @@
#include "util/ConstBuffer.hxx"
#include <utility>
#include <memory>
#include <assert.h>
#include <stdint.h>
@@ -76,14 +77,14 @@ class AudioOutputSource {
* The replay_gain_filter_plugin instance of this audio
* output.
*/
Filter *replay_gain_filter_instance = nullptr;
std::unique_ptr<Filter> replay_gain_filter_instance;
/**
* The replay_gain_filter_plugin instance of this audio
* output, to be applied to the second chunk during
* cross-fading.
*/
Filter *other_replay_gain_filter_instance = nullptr;
std::unique_ptr<Filter> other_replay_gain_filter_instance;
/**
* The buffer used to allocate the cross-fading result.
@@ -99,7 +100,7 @@ class AudioOutputSource {
* The filter object of this audio output. This is an
* instance of chain_filter_plugin.
*/
Filter *filter_instance = nullptr;
std::unique_ptr<Filter> filter_instance;
/**
* The #MusicChunk currently being processed (see
@@ -119,6 +120,9 @@ class AudioOutputSource {
ConstBuffer<uint8_t> pending_data;
public:
AudioOutputSource() noexcept;
~AudioOutputSource() noexcept;
void SetReplayGainMode(ReplayGainMode _mode) noexcept {
replay_gain_mode = _mode;
}