filter/AutoConvert: use std::unique_ptr
This commit is contained in:
parent
12091fcfb1
commit
28c6975732
@ -26,28 +26,26 @@
|
|||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
#include "util/ConstBuffer.hxx"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
class AutoConvertFilter final : public Filter {
|
class AutoConvertFilter final : public Filter {
|
||||||
/**
|
/**
|
||||||
* The underlying filter.
|
* The underlying filter.
|
||||||
*/
|
*/
|
||||||
Filter *const filter;
|
std::unique_ptr<Filter> filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convert_filter, just in case conversion is needed. nullptr
|
* A convert_filter, just in case conversion is needed. nullptr
|
||||||
* if unused.
|
* if unused.
|
||||||
*/
|
*/
|
||||||
Filter *const convert;
|
std::unique_ptr<Filter> convert;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AutoConvertFilter(Filter *_filter, Filter *_convert)
|
AutoConvertFilter(std::unique_ptr<Filter> &&_filter,
|
||||||
:filter(_filter), convert(_convert) {}
|
std::unique_ptr<Filter> &&_convert)
|
||||||
|
:filter(std::move(_filter)), convert(std::move(_convert)) {}
|
||||||
~AutoConvertFilter() {
|
|
||||||
delete convert;
|
|
||||||
delete filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ConstBuffer<void> FilterPCM(ConstBuffer<void> src,
|
virtual ConstBuffer<void> FilterPCM(ConstBuffer<void> src,
|
||||||
Error &error) override;
|
Error &error) override;
|
||||||
@ -76,26 +74,25 @@ PreparedAutoConvertFilter::Open(AudioFormat &in_audio_format, Error &error)
|
|||||||
/* open the "real" filter */
|
/* open the "real" filter */
|
||||||
|
|
||||||
AudioFormat child_audio_format = in_audio_format;
|
AudioFormat child_audio_format = in_audio_format;
|
||||||
auto *new_filter = filter->Open(child_audio_format, error);
|
std::unique_ptr<Filter> new_filter(filter->Open(child_audio_format, error));
|
||||||
if (new_filter == nullptr)
|
if (!new_filter)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
/* need to convert? */
|
/* need to convert? */
|
||||||
|
|
||||||
Filter *convert = nullptr;
|
std::unique_ptr<Filter> convert;
|
||||||
if (in_audio_format != child_audio_format) {
|
if (in_audio_format != child_audio_format) {
|
||||||
/* yes - create a convert_filter */
|
/* yes - create a convert_filter */
|
||||||
|
|
||||||
convert = convert_filter_new(in_audio_format,
|
convert.reset(convert_filter_new(in_audio_format,
|
||||||
child_audio_format,
|
child_audio_format,
|
||||||
error);
|
error));
|
||||||
if (convert == nullptr) {
|
if (!convert)
|
||||||
delete new_filter;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AutoConvertFilter(new_filter, convert);
|
return new AutoConvertFilter(std::move(new_filter),
|
||||||
|
std::move(convert));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstBuffer<void>
|
ConstBuffer<void>
|
||||||
|
Loading…
Reference in New Issue
Block a user