filter/AutoConvert: eliminate AutoConvertFilter if possible
If no conversion is necessary, return the child Filter as-is. This allows removing all nullptr checks from AutoConvertFilter.
This commit is contained in:
parent
226eb26300
commit
77c14692c9
@ -47,9 +47,7 @@ public:
|
|||||||
|
|
||||||
void Reset() noexcept override {
|
void Reset() noexcept override {
|
||||||
filter->Reset();
|
filter->Reset();
|
||||||
|
convert->Reset();
|
||||||
if (convert)
|
|
||||||
convert->Reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstBuffer<void> FilterPCM(ConstBuffer<void> src) override;
|
ConstBuffer<void> FilterPCM(ConstBuffer<void> src) override;
|
||||||
@ -81,13 +79,14 @@ PreparedAutoConvertFilter::Open(AudioFormat &in_audio_format)
|
|||||||
|
|
||||||
/* need to convert? */
|
/* need to convert? */
|
||||||
|
|
||||||
std::unique_ptr<Filter> convert;
|
if (in_audio_format == child_audio_format)
|
||||||
if (in_audio_format != child_audio_format) {
|
/* no */
|
||||||
/* yes - create a convert_filter */
|
return new_filter;
|
||||||
|
|
||||||
convert = convert_filter_new(in_audio_format,
|
/* yes - create a convert_filter */
|
||||||
child_audio_format);
|
|
||||||
}
|
auto convert = convert_filter_new(in_audio_format,
|
||||||
|
child_audio_format);
|
||||||
|
|
||||||
return std::make_unique<AutoConvertFilter>(std::move(new_filter),
|
return std::make_unique<AutoConvertFilter>(std::move(new_filter),
|
||||||
std::move(convert));
|
std::move(convert));
|
||||||
@ -96,20 +95,16 @@ PreparedAutoConvertFilter::Open(AudioFormat &in_audio_format)
|
|||||||
ConstBuffer<void>
|
ConstBuffer<void>
|
||||||
AutoConvertFilter::FilterPCM(ConstBuffer<void> src)
|
AutoConvertFilter::FilterPCM(ConstBuffer<void> src)
|
||||||
{
|
{
|
||||||
if (convert != nullptr)
|
src = convert->FilterPCM(src);
|
||||||
src = convert->FilterPCM(src);
|
|
||||||
|
|
||||||
return filter->FilterPCM(src);
|
return filter->FilterPCM(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstBuffer<void>
|
ConstBuffer<void>
|
||||||
AutoConvertFilter::Flush()
|
AutoConvertFilter::Flush()
|
||||||
{
|
{
|
||||||
if (convert != nullptr) {
|
auto result = convert->Flush();
|
||||||
auto result = convert->Flush();
|
if (!result.IsNull())
|
||||||
if (!result.IsNull())
|
return filter->FilterPCM(result);
|
||||||
return filter->FilterPCM(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return filter->Flush();
|
return filter->Flush();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user