mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00

- Add `WebRTC-Audio-OpusDecodeStereoByDefault` field trial - Behind that field trial, `AudioDecoderOpus::SdpToConfig` uses 2 instead of 1 as default number of channels when the `stereo` codec param is unspecified - Instead of wiring up `FieldTrialsView` to `SdpToConfig`, which requires API changes that break downstream projects, a change in `AudioDecoderOpus::Config` is made to signal when the number of channels is forced via SDP config Bug: webrtc:379996136 Change-Id: If70eb19bc7e3bc74dd0423610cb04ae33ea602fe Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/368860 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43440}
109 lines
3.4 KiB
C++
109 lines
3.4 KiB
C++
/*
|
|
* Copyright (c) 2024 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "api/audio_codecs/opus/audio_decoder_opus.h"
|
|
|
|
#include <string>
|
|
|
|
#include "api/environment/environment.h"
|
|
#include "api/environment/environment_factory.h"
|
|
#include "test/explicit_key_value_config.h"
|
|
#include "test/gmock.h"
|
|
#include "test/gtest.h"
|
|
|
|
namespace webrtc {
|
|
namespace {
|
|
|
|
using test::ExplicitKeyValueConfig;
|
|
using ::testing::Field;
|
|
using ::testing::Optional;
|
|
using Config = AudioDecoderOpus::Config;
|
|
|
|
enum class StereoParam { kUnset, kMono, kStereo };
|
|
|
|
SdpAudioFormat GetSdpAudioFormat(StereoParam param) {
|
|
SdpAudioFormat format("opus", 48000, 2);
|
|
switch (param) {
|
|
case StereoParam::kUnset:
|
|
// Do nothing.
|
|
break;
|
|
case StereoParam::kMono:
|
|
format.parameters.emplace("stereo", "0");
|
|
break;
|
|
case StereoParam::kStereo:
|
|
format.parameters.emplace("stereo", "1");
|
|
break;
|
|
}
|
|
return format;
|
|
}
|
|
|
|
constexpr int kDefaultNumChannels = 1;
|
|
constexpr int kAlternativeNumChannels = 2;
|
|
|
|
TEST(AudioDecoderOpusTest, SdpToConfigDoesNotSetNumChannels) {
|
|
const std::optional<Config> config =
|
|
AudioDecoderOpus::SdpToConfig(GetSdpAudioFormat(StereoParam::kUnset));
|
|
|
|
EXPECT_THAT(config, Optional(Field(&Config::num_channels, std::nullopt)));
|
|
}
|
|
|
|
TEST(AudioDecoderOpusTest, SdpToConfigForcesMono) {
|
|
const std::optional<Config> config =
|
|
AudioDecoderOpus::SdpToConfig(GetSdpAudioFormat(StereoParam::kMono));
|
|
|
|
EXPECT_THAT(config, Optional(Field(&Config::num_channels, 1)));
|
|
}
|
|
|
|
TEST(AudioDecoderOpusTest, SdpToConfigForcesStereo) {
|
|
const std::optional<Config> config =
|
|
AudioDecoderOpus::SdpToConfig(GetSdpAudioFormat(StereoParam::kStereo));
|
|
|
|
EXPECT_THAT(config, Optional(Field(&Config::num_channels, 2)));
|
|
}
|
|
|
|
TEST(AudioDecoderOpusTest, MakeAudioDecoderForcesDefaultNumChannels) {
|
|
const Environment env = CreateEnvironment();
|
|
auto decoder = AudioDecoderOpus::MakeAudioDecoder(
|
|
env, /*config=*/{.num_channels = std::nullopt});
|
|
|
|
EXPECT_EQ(decoder->Channels(), static_cast<size_t>(kDefaultNumChannels));
|
|
}
|
|
|
|
TEST(AudioDecoderOpusTest, MakeAudioDecoderCannotForceDefaultNumChannels) {
|
|
const Environment env = CreateEnvironment();
|
|
auto decoder = AudioDecoderOpus::MakeAudioDecoder(
|
|
env, /*config=*/{.num_channels = kAlternativeNumChannels});
|
|
|
|
EXPECT_EQ(decoder->Channels(), static_cast<size_t>(kAlternativeNumChannels));
|
|
}
|
|
|
|
TEST(AudioDecoderOpusTest, MakeAudioDecoderForcesStereo) {
|
|
const Environment env =
|
|
CreateEnvironment(std::make_unique<ExplicitKeyValueConfig>(
|
|
"WebRTC-Audio-OpusDecodeStereoByDefault/Enabled/"));
|
|
auto decoder = AudioDecoderOpus::MakeAudioDecoder(
|
|
env,
|
|
/*config=*/{.num_channels = std::nullopt});
|
|
|
|
EXPECT_EQ(decoder->Channels(), 2u);
|
|
}
|
|
|
|
TEST(AudioDecoderOpusTest, MakeAudioDecoderCannotForceStereo) {
|
|
const Environment env =
|
|
CreateEnvironment(std::make_unique<ExplicitKeyValueConfig>(
|
|
"WebRTC-Audio-OpusDecodeStereoByDefault/Enabled/"));
|
|
auto decoder =
|
|
AudioDecoderOpus::MakeAudioDecoder(env, /*config=*/{.num_channels = 1});
|
|
|
|
EXPECT_EQ(decoder->Channels(), 1u);
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace webrtc
|