Add Opus-only audio codec factories
Many WebRTC users need only Opus, and no other audio codecs. This makes it convenient for them to do the right thing. To prove that the new factories work, use them in PeerConnectionEndToEndTest. Bug: webrtc:11130 Change-Id: I2c2450ba0fb33ef3b50da8f6cd325cad6b1e59a6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160648 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29921}
This commit is contained in:
parent
3967389d34
commit
44d7ec0683
@ -110,3 +110,35 @@ rtc_library("builtin_audio_encoder_factory") {
|
||||
defines += [ "WEBRTC_USE_BUILTIN_OPUS=0" ]
|
||||
}
|
||||
}
|
||||
|
||||
rtc_library("opus_audio_decoder_factory") {
|
||||
visibility = [ "*" ]
|
||||
allow_poison = [ "audio_codecs" ]
|
||||
sources = [
|
||||
"opus_audio_decoder_factory.cc",
|
||||
"opus_audio_decoder_factory.h",
|
||||
]
|
||||
deps = [
|
||||
":audio_codecs_api",
|
||||
"..:scoped_refptr",
|
||||
"../../rtc_base:rtc_base_approved",
|
||||
"opus:audio_decoder_multiopus",
|
||||
"opus:audio_decoder_opus",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_library("opus_audio_encoder_factory") {
|
||||
visibility = [ "*" ]
|
||||
allow_poison = [ "audio_codecs" ]
|
||||
sources = [
|
||||
"opus_audio_encoder_factory.cc",
|
||||
"opus_audio_encoder_factory.h",
|
||||
]
|
||||
deps = [
|
||||
":audio_codecs_api",
|
||||
"..:scoped_refptr",
|
||||
"../../rtc_base:rtc_base_approved",
|
||||
"opus:audio_encoder_multiopus",
|
||||
"opus:audio_encoder_opus",
|
||||
]
|
||||
}
|
||||
|
||||
@ -17,6 +17,10 @@
|
||||
namespace webrtc {
|
||||
|
||||
// Creates a new factory that can create the built-in types of audio decoders.
|
||||
// Note: This will link with all the code implementing those codecs, so if you
|
||||
// only need a subset of the codecs, consider using
|
||||
// CreateAudioDecoderFactory<...codecs listed here...>() or
|
||||
// CreateOpusAudioDecoderFactory() instead.
|
||||
rtc::scoped_refptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory();
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -17,6 +17,10 @@
|
||||
namespace webrtc {
|
||||
|
||||
// Creates a new factory that can create the built-in types of audio encoders.
|
||||
// Note: This will link with all the code implementing those codecs, so if you
|
||||
// only need a subset of the codecs, consider using
|
||||
// CreateAudioEncoderFactory<...codecs listed here...>() or
|
||||
// CreateOpusAudioEncoderFactory() instead.
|
||||
rtc::scoped_refptr<AudioEncoderFactory> CreateBuiltinAudioEncoderFactory();
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
49
api/audio_codecs/opus_audio_decoder_factory.cc
Normal file
49
api/audio_codecs/opus_audio_decoder_factory.cc
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2019 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_factory.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio_codecs/audio_decoder_factory_template.h"
|
||||
#include "api/audio_codecs/opus/audio_decoder_multi_channel_opus.h"
|
||||
#include "api/audio_codecs/opus/audio_decoder_opus.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
// Modify an audio decoder to not advertise support for anything.
|
||||
template <typename T>
|
||||
struct NotAdvertised {
|
||||
using Config = typename T::Config;
|
||||
static absl::optional<Config> SdpToConfig(
|
||||
const SdpAudioFormat& audio_format) {
|
||||
return T::SdpToConfig(audio_format);
|
||||
}
|
||||
static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs) {
|
||||
// Don't advertise support for anything.
|
||||
}
|
||||
static std::unique_ptr<AudioDecoder> MakeAudioDecoder(
|
||||
const Config& config,
|
||||
absl::optional<AudioCodecPairId> codec_pair_id = absl::nullopt) {
|
||||
return T::MakeAudioDecoder(config, codec_pair_id);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
rtc::scoped_refptr<AudioDecoderFactory> CreateOpusAudioDecoderFactory() {
|
||||
return CreateAudioDecoderFactory<
|
||||
AudioDecoderOpus, NotAdvertised<AudioDecoderMultiChannelOpus>>();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
26
api/audio_codecs/opus_audio_decoder_factory.h
Normal file
26
api/audio_codecs/opus_audio_decoder_factory.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2019 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.
|
||||
*/
|
||||
|
||||
#ifndef API_AUDIO_CODECS_OPUS_AUDIO_DECODER_FACTORY_H_
|
||||
#define API_AUDIO_CODECS_OPUS_AUDIO_DECODER_FACTORY_H_
|
||||
|
||||
#include "api/audio_codecs/audio_decoder_factory.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Creates a new factory that can create only Opus audio decoders. Works like
|
||||
// CreateAudioDecoderFactory<AudioDecoderOpus>(), but is easier to use and is
|
||||
// not inline because it isn't a template.
|
||||
rtc::scoped_refptr<AudioDecoderFactory> CreateOpusAudioDecoderFactory();
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // API_AUDIO_CODECS_OPUS_AUDIO_DECODER_FACTORY_H_
|
||||
52
api/audio_codecs/opus_audio_encoder_factory.cc
Normal file
52
api/audio_codecs/opus_audio_encoder_factory.cc
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2019 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_encoder_factory.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "api/audio_codecs/audio_encoder_factory_template.h"
|
||||
#include "api/audio_codecs/opus/audio_encoder_multi_channel_opus.h"
|
||||
#include "api/audio_codecs/opus/audio_encoder_opus.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
// Modify an audio encoder to not advertise support for anything.
|
||||
template <typename T>
|
||||
struct NotAdvertised {
|
||||
using Config = typename T::Config;
|
||||
static absl::optional<Config> SdpToConfig(
|
||||
const SdpAudioFormat& audio_format) {
|
||||
return T::SdpToConfig(audio_format);
|
||||
}
|
||||
static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs) {
|
||||
// Don't advertise support for anything.
|
||||
}
|
||||
static AudioCodecInfo QueryAudioEncoder(const Config& config) {
|
||||
return T::QueryAudioEncoder(config);
|
||||
}
|
||||
static std::unique_ptr<AudioEncoder> MakeAudioEncoder(
|
||||
const Config& config,
|
||||
int payload_type,
|
||||
absl::optional<AudioCodecPairId> codec_pair_id = absl::nullopt) {
|
||||
return T::MakeAudioEncoder(config, payload_type, codec_pair_id);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
rtc::scoped_refptr<AudioEncoderFactory> CreateOpusAudioEncoderFactory() {
|
||||
return CreateAudioEncoderFactory<
|
||||
AudioEncoderOpus, NotAdvertised<AudioEncoderMultiChannelOpus>>();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
26
api/audio_codecs/opus_audio_encoder_factory.h
Normal file
26
api/audio_codecs/opus_audio_encoder_factory.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2019 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.
|
||||
*/
|
||||
|
||||
#ifndef API_AUDIO_CODECS_OPUS_AUDIO_ENCODER_FACTORY_H_
|
||||
#define API_AUDIO_CODECS_OPUS_AUDIO_ENCODER_FACTORY_H_
|
||||
|
||||
#include "api/audio_codecs/audio_encoder_factory.h"
|
||||
#include "api/scoped_refptr.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Creates a new factory that can create only Opus audio encoders. Works like
|
||||
// CreateAudioEncoderFactory<AudioEncoderOpus>(), but is easier to use and is
|
||||
// not inline because it isn't a template.
|
||||
rtc::scoped_refptr<AudioEncoderFactory> CreateOpusAudioEncoderFactory();
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // API_AUDIO_CODECS_OPUS_AUDIO_ENCODER_FACTORY_H_
|
||||
@ -613,6 +613,8 @@ if (rtc_include_tests) {
|
||||
"../api/audio_codecs:audio_codecs_api",
|
||||
"../api/audio_codecs:builtin_audio_decoder_factory",
|
||||
"../api/audio_codecs:builtin_audio_encoder_factory",
|
||||
"../api/audio_codecs:opus_audio_decoder_factory",
|
||||
"../api/audio_codecs:opus_audio_encoder_factory",
|
||||
"../api/audio_codecs/L16:audio_decoder_L16",
|
||||
"../api/audio_codecs/L16:audio_encoder_L16",
|
||||
"../api/video_codecs:builtin_video_decoder_factory",
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
#include "api/audio_codecs/audio_codec_pair_id.h"
|
||||
#include "api/audio_codecs/audio_decoder_factory_template.h"
|
||||
#include "api/audio_codecs/audio_encoder_factory_template.h"
|
||||
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
|
||||
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
|
||||
#include "api/audio_codecs/opus_audio_decoder_factory.h"
|
||||
#include "api/audio_codecs/opus_audio_encoder_factory.h"
|
||||
#include "media/sctp/sctp_transport_internal.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "rtc_base/logging.h"
|
||||
@ -358,8 +358,8 @@ struct AudioDecoderUnicornSparklesRainbow {
|
||||
|
||||
TEST_P(PeerConnectionEndToEndTest, Call) {
|
||||
rtc::scoped_refptr<webrtc::AudioDecoderFactory> real_decoder_factory =
|
||||
webrtc::CreateBuiltinAudioDecoderFactory();
|
||||
CreatePcs(webrtc::CreateBuiltinAudioEncoderFactory(),
|
||||
webrtc::CreateOpusAudioDecoderFactory();
|
||||
CreatePcs(webrtc::CreateOpusAudioEncoderFactory(),
|
||||
CreateForwardingMockDecoderFactory(real_decoder_factory.get()));
|
||||
GetAndAddUserMedia();
|
||||
Negotiate();
|
||||
@ -368,8 +368,8 @@ TEST_P(PeerConnectionEndToEndTest, Call) {
|
||||
|
||||
TEST_P(PeerConnectionEndToEndTest, CallWithSdesKeyNegotiation) {
|
||||
config_.enable_dtls_srtp = false;
|
||||
CreatePcs(webrtc::CreateBuiltinAudioEncoderFactory(),
|
||||
webrtc::CreateBuiltinAudioDecoderFactory());
|
||||
CreatePcs(webrtc::CreateOpusAudioEncoderFactory(),
|
||||
webrtc::CreateOpusAudioDecoderFactory());
|
||||
GetAndAddUserMedia();
|
||||
Negotiate();
|
||||
WaitForCallEstablished();
|
||||
@ -739,8 +739,8 @@ TEST_P(PeerConnectionEndToEndTest, TooManyDataChannelsOpenedBeforeConnecting) {
|
||||
|
||||
TEST_P(PeerConnectionEndToEndTest, CanRestartIce) {
|
||||
rtc::scoped_refptr<webrtc::AudioDecoderFactory> real_decoder_factory =
|
||||
webrtc::CreateBuiltinAudioDecoderFactory();
|
||||
CreatePcs(webrtc::CreateBuiltinAudioEncoderFactory(),
|
||||
webrtc::CreateOpusAudioDecoderFactory();
|
||||
CreatePcs(webrtc::CreateOpusAudioEncoderFactory(),
|
||||
CreateForwardingMockDecoderFactory(real_decoder_factory.get()));
|
||||
GetAndAddUserMedia();
|
||||
Negotiate();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user