diff --git a/api/video_codecs/video_encoder_factory_template.h b/api/video_codecs/video_encoder_factory_template.h index b167ccdcea..643096dbbb 100644 --- a/api/video_codecs/video_encoder_factory_template.h +++ b/api/video_codecs/video_encoder_factory_template.h @@ -46,9 +46,7 @@ template class VideoEncoderFactoryTemplate : public VideoEncoderFactory { public: std::vector GetSupportedFormats() const override { - std::vector formats; - GetSupportedFormatsInternal(formats); - return formats; + return GetSupportedFormatsInternal(); } std::unique_ptr CreateVideoEncoder( @@ -86,17 +84,20 @@ class VideoEncoderFactoryTemplate : public VideoEncoderFactory { } template - void GetSupportedFormatsInternal(std::vector& formats) const { + std::vector GetSupportedFormatsInternal() const { auto supported_formats = V::SupportedFormats(); - for (const auto& format : supported_formats) { - if (!IsFormatInList(format, formats)) { - formats.push_back(format); + + if constexpr (sizeof...(Vs) > 0) { + // Supported formats may overlap between implementations, so duplicates + // should be filtered out. + for (const auto& other_format : GetSupportedFormatsInternal()) { + if (!IsFormatInList(other_format, supported_formats)) { + supported_formats.push_back(other_format); + } } } - if constexpr (sizeof...(Vs) > 0) { - return GetSupportedFormatsInternal(formats); - } + return supported_formats; } template