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