Add AudioDecoderOpus::MakeAudioDecoder overload taking Environment
Mark old overload deprecated. This allows to migrate both calls through AudioDecoderFactory and direct calls to AudioDecpderOpus trait. Bug: webrtc:356878416 Change-Id: I1502aee5b18aac43a8258e77b770c8e73a056f92 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/359741 Commit-Queue: Jakob Ivarsson <jakobi@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Auto-Submit: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42793}
This commit is contained in:
parent
e0fe4200eb
commit
24823c502b
@ -58,11 +58,16 @@ struct Helper<T, Ts...> {
|
||||
"absl::optional<T::Config>");
|
||||
return opt_config ? true : Helper<Ts...>::IsSupportedDecoder(format);
|
||||
}
|
||||
// TODO: bugs.webrtc.org/356878416 - Migrate to `Create`
|
||||
static std::unique_ptr<AudioDecoder> MakeAudioDecoder(
|
||||
const SdpAudioFormat& format,
|
||||
absl::optional<AudioCodecPairId> codec_pair_id) {
|
||||
auto opt_config = T::SdpToConfig(format);
|
||||
return opt_config ? T::MakeAudioDecoder(*opt_config, codec_pair_id)
|
||||
return opt_config ?
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
T::MakeAudioDecoder(*opt_config, codec_pair_id)
|
||||
#pragma clang diagnostic pop
|
||||
: Helper<Ts...>::MakeAudioDecoder(format, codec_pair_id);
|
||||
}
|
||||
};
|
||||
|
||||
@ -67,6 +67,8 @@ rtc_library("audio_decoder_opus") {
|
||||
"../../../modules/audio_coding:webrtc_opus",
|
||||
"../../../rtc_base:checks",
|
||||
"../../../rtc_base/system:rtc_export",
|
||||
"../../environment",
|
||||
"../../transport:field_trial_based_config",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//third_party/abseil-cpp/absl/types:optional",
|
||||
]
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#include "api/audio_codecs/audio_decoder.h"
|
||||
#include "api/audio_codecs/audio_format.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "api/transport/field_trial_based_config.h"
|
||||
#include "modules/audio_coding/codecs/opus/audio_decoder_opus.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
@ -79,6 +80,17 @@ void AudioDecoderOpus::AppendSupportedDecoders(
|
||||
specs->push_back({std::move(opus_format), opus_info});
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioDecoder> AudioDecoderOpus::MakeAudioDecoder(
|
||||
const Environment& env,
|
||||
Config config) {
|
||||
if (!config.IsOk()) {
|
||||
RTC_DCHECK_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<AudioDecoderOpusImpl>(
|
||||
env.field_trials(), config.num_channels, config.sample_rate_hz);
|
||||
}
|
||||
|
||||
std::unique_ptr<AudioDecoder> AudioDecoderOpus::MakeAudioDecoder(
|
||||
Config config,
|
||||
absl::optional<AudioCodecPairId> /*codec_pair_id*/,
|
||||
@ -87,8 +99,13 @@ std::unique_ptr<AudioDecoder> AudioDecoderOpus::MakeAudioDecoder(
|
||||
RTC_DCHECK_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<AudioDecoderOpusImpl>(config.num_channels,
|
||||
config.sample_rate_hz);
|
||||
if (field_trials == nullptr) {
|
||||
return std::make_unique<AudioDecoderOpusImpl>(
|
||||
FieldTrialBasedConfig(), config.num_channels, config.sample_rate_hz);
|
||||
} else {
|
||||
return std::make_unique<AudioDecoderOpusImpl>(
|
||||
*field_trials, config.num_channels, config.sample_rate_hz);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#include "api/audio_codecs/audio_codec_pair_id.h"
|
||||
#include "api/audio_codecs/audio_decoder.h"
|
||||
#include "api/audio_codecs/audio_format.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "rtc_base/system/rtc_export.h"
|
||||
|
||||
@ -33,10 +34,16 @@ struct RTC_EXPORT AudioDecoderOpus {
|
||||
};
|
||||
static absl::optional<Config> SdpToConfig(const SdpAudioFormat& audio_format);
|
||||
static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs);
|
||||
static std::unique_ptr<AudioDecoder> MakeAudioDecoder(
|
||||
|
||||
[[deprecated("bugs.webrtc.org/356878416")]] //
|
||||
static std::unique_ptr<AudioDecoder>
|
||||
MakeAudioDecoder(
|
||||
Config config,
|
||||
absl::optional<AudioCodecPairId> codec_pair_id = absl::nullopt,
|
||||
const FieldTrialsView* field_trials = nullptr);
|
||||
|
||||
static std::unique_ptr<AudioDecoder> MakeAudioDecoder(const Environment& env,
|
||||
Config config);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -485,7 +485,6 @@ rtc_library("webrtc_opus") {
|
||||
"../../rtc_base:safe_minmax",
|
||||
"../../rtc_base:stringutils",
|
||||
"../../rtc_base:timeutils",
|
||||
"../../system_wrappers:field_trial",
|
||||
"//third_party/abseil-cpp/absl/memory",
|
||||
"//third_party/abseil-cpp/absl/strings",
|
||||
"//third_party/abseil-cpp/absl/strings:string_view",
|
||||
@ -1207,6 +1206,7 @@ if (rtc_include_tests) {
|
||||
"../../api/environment:environment_factory",
|
||||
"../../common_audio",
|
||||
"../../rtc_base/system:arch",
|
||||
"../../test:explicit_key_value_config",
|
||||
"../../test:fileutils",
|
||||
"../../test:test_main",
|
||||
"../../test:test_support",
|
||||
|
||||
@ -15,17 +15,18 @@
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "modules/audio_coding/codecs/opus/audio_coder_opus_common.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "system_wrappers/include/field_trial.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
AudioDecoderOpusImpl::AudioDecoderOpusImpl(size_t num_channels,
|
||||
AudioDecoderOpusImpl::AudioDecoderOpusImpl(const FieldTrialsView& field_trials,
|
||||
size_t num_channels,
|
||||
int sample_rate_hz)
|
||||
: channels_(num_channels),
|
||||
sample_rate_hz_(sample_rate_hz),
|
||||
generate_plc_(field_trial::IsEnabled("WebRTC-Audio-OpusGeneratePlc")) {
|
||||
generate_plc_(field_trials.IsEnabled("WebRTC-Audio-OpusGeneratePlc")) {
|
||||
RTC_DCHECK(num_channels == 1 || num_channels == 2);
|
||||
RTC_DCHECK(sample_rate_hz == 16000 || sample_rate_hz == 48000);
|
||||
const int error =
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio_codecs/audio_decoder.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "modules/audio_coding/codecs/opus/opus_interface.h"
|
||||
#include "rtc_base/buffer.h"
|
||||
|
||||
@ -24,8 +25,10 @@ namespace webrtc {
|
||||
|
||||
class AudioDecoderOpusImpl final : public AudioDecoder {
|
||||
public:
|
||||
explicit AudioDecoderOpusImpl(size_t num_channels,
|
||||
int sample_rate_hz = 48000);
|
||||
explicit AudioDecoderOpusImpl(const FieldTrialsView& field_trails,
|
||||
size_t num_channels,
|
||||
int sample_rate_hz);
|
||||
|
||||
~AudioDecoderOpusImpl() override;
|
||||
|
||||
AudioDecoderOpusImpl(const AudioDecoderOpusImpl&) = delete;
|
||||
|
||||
@ -122,7 +122,7 @@ TEST(BandwidthAdaptationTest, BandwidthAdaptationTest) {
|
||||
// Create decoder.
|
||||
AudioDecoderOpus::Config dec_config;
|
||||
dec_config.num_channels = kNumChannels;
|
||||
auto decoder = AudioDecoderOpus::MakeAudioDecoder(dec_config);
|
||||
auto decoder = AudioDecoderOpus::MakeAudioDecoder(env, dec_config);
|
||||
|
||||
// Open speech file.
|
||||
const std::string kInputFileName =
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
#include "modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h"
|
||||
#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
|
||||
#include "rtc_base/system/arch.h"
|
||||
#include "test/explicit_key_value_config.h"
|
||||
#include "test/gtest.h"
|
||||
#include "test/testsupport/file_utils.h"
|
||||
|
||||
@ -35,6 +36,8 @@ namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
using test::ExplicitKeyValueConfig;
|
||||
|
||||
constexpr int kOverheadBytesPerPacket = 50;
|
||||
|
||||
// The absolute difference between the input and output (the first channel) is
|
||||
@ -384,8 +387,8 @@ class AudioDecoderOpusTest
|
||||
codec_input_rate_hz_ = opus_sample_rate_hz_;
|
||||
frame_size_ = rtc::CheckedDivExact(opus_sample_rate_hz_, 100);
|
||||
data_length_ = 10 * frame_size_;
|
||||
decoder_ =
|
||||
new AudioDecoderOpusImpl(opus_num_channels_, opus_sample_rate_hz_);
|
||||
decoder_ = new AudioDecoderOpusImpl(
|
||||
ExplicitKeyValueConfig(""), opus_num_channels_, opus_sample_rate_hz_);
|
||||
AudioEncoderOpusConfig config;
|
||||
config.frame_size_ms = 10;
|
||||
config.sample_rate_hz = opus_sample_rate_hz_;
|
||||
|
||||
@ -330,6 +330,7 @@ webrtc_fuzzer_test("audio_decoder_opus_fuzzer") {
|
||||
sources = [ "audio_decoder_opus_fuzzer.cc" ]
|
||||
deps = [
|
||||
":audio_decoder_fuzzer",
|
||||
"..:explicit_key_value_config",
|
||||
"../../modules/audio_coding:webrtc_opus",
|
||||
]
|
||||
}
|
||||
@ -338,6 +339,7 @@ webrtc_fuzzer_test("audio_decoder_opus_redundant_fuzzer") {
|
||||
sources = [ "audio_decoder_opus_redundant_fuzzer.cc" ]
|
||||
deps = [
|
||||
":audio_decoder_fuzzer",
|
||||
"..:explicit_key_value_config",
|
||||
"../../modules/audio_coding:webrtc_opus",
|
||||
]
|
||||
}
|
||||
|
||||
@ -9,13 +9,15 @@
|
||||
*/
|
||||
|
||||
#include "modules/audio_coding/codecs/opus/audio_decoder_opus.h"
|
||||
#include "test/explicit_key_value_config.h"
|
||||
#include "test/fuzzers/audio_decoder_fuzzer.h"
|
||||
|
||||
namespace webrtc {
|
||||
void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
const size_t channels = (size % 2) + 1; // 1 or 2 channels.
|
||||
AudioDecoderOpusImpl dec(channels);
|
||||
const int kSampleRateHz = 48000;
|
||||
const int kSampleRateHz = 48'000;
|
||||
AudioDecoderOpusImpl dec(test::ExplicitKeyValueConfig(""), channels,
|
||||
kSampleRateHz);
|
||||
const size_t kAllocatedOuputSizeSamples = kSampleRateHz / 10; // 100 ms.
|
||||
int16_t output[kAllocatedOuputSizeSamples];
|
||||
FuzzAudioDecoder(DecoderFunctionType::kNormalDecode, data, size, &dec,
|
||||
|
||||
@ -9,13 +9,15 @@
|
||||
*/
|
||||
|
||||
#include "modules/audio_coding/codecs/opus/audio_decoder_opus.h"
|
||||
#include "test/explicit_key_value_config.h"
|
||||
#include "test/fuzzers/audio_decoder_fuzzer.h"
|
||||
|
||||
namespace webrtc {
|
||||
void FuzzOneInput(const uint8_t* data, size_t size) {
|
||||
const size_t channels = (size % 2) + 1; // 1 or 2 channels.
|
||||
AudioDecoderOpusImpl dec(channels);
|
||||
const int kSampleRateHz = 48000;
|
||||
const int kSampleRateHz = 48'000;
|
||||
AudioDecoderOpusImpl dec(test::ExplicitKeyValueConfig(""), channels,
|
||||
kSampleRateHz);
|
||||
const size_t kAllocatedOuputSizeSamples = kSampleRateHz / 10; // 100 ms.
|
||||
int16_t output[kAllocatedOuputSizeSamples];
|
||||
FuzzAudioDecoder(DecoderFunctionType::kRedundantDecode, data, size, &dec,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user