Turned AudioDecoderFactory into a RefCounted thing to use with scoped_refptr.
First step of AudioDecoderFactory injection CLs. AudioDecoderFactories will be shared, and shared_ptr is currently off the table, so this CL changes the current uses of AudioDecoderFactory from std::unique_ptr to rtc::scoped_refptr. BUG=webrtc:5805 Review-Url: https://codereview.webrtc.org/1990803004 Cr-Commit-Position: refs/heads/master@{#12815}
This commit is contained in:
@ -14,6 +14,8 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "webrtc/base/atomicops.h"
|
||||
#include "webrtc/base/refcount.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_decoder.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_format.h"
|
||||
|
||||
@ -21,10 +23,8 @@ namespace webrtc {
|
||||
|
||||
// A factory that creates AudioDecoders.
|
||||
// NOTE: This class is still under development and may change without notice.
|
||||
class AudioDecoderFactory {
|
||||
class AudioDecoderFactory : public rtc::RefCountInterface {
|
||||
public:
|
||||
virtual ~AudioDecoderFactory() = default;
|
||||
|
||||
virtual std::vector<SdpAudioFormat> GetSupportedFormats() = 0;
|
||||
|
||||
virtual std::unique_ptr<AudioDecoder> MakeAudioDecoder(
|
||||
|
||||
@ -16,13 +16,15 @@
|
||||
namespace webrtc {
|
||||
|
||||
TEST(AudioDecoderFactoryTest, CreateUnknownDecoder) {
|
||||
std::unique_ptr<AudioDecoderFactory> adf = CreateBuiltinAudioDecoderFactory();
|
||||
rtc::scoped_refptr<AudioDecoderFactory> adf =
|
||||
CreateBuiltinAudioDecoderFactory();
|
||||
ASSERT_TRUE(adf);
|
||||
EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("rey", 8000, 1)));
|
||||
}
|
||||
|
||||
TEST(AudioDecoderFactoryTest, CreatePcmu) {
|
||||
std::unique_ptr<AudioDecoderFactory> adf = CreateBuiltinAudioDecoderFactory();
|
||||
rtc::scoped_refptr<AudioDecoderFactory> adf =
|
||||
CreateBuiltinAudioDecoderFactory();
|
||||
ASSERT_TRUE(adf);
|
||||
// PCMu supports 8 kHz, and any number of channels.
|
||||
EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("pcmu", 8000, 0)));
|
||||
@ -33,7 +35,8 @@ TEST(AudioDecoderFactoryTest, CreatePcmu) {
|
||||
}
|
||||
|
||||
TEST(AudioDecoderFactoryTest, CreatePcma) {
|
||||
std::unique_ptr<AudioDecoderFactory> adf = CreateBuiltinAudioDecoderFactory();
|
||||
rtc::scoped_refptr<AudioDecoderFactory> adf =
|
||||
CreateBuiltinAudioDecoderFactory();
|
||||
ASSERT_TRUE(adf);
|
||||
// PCMa supports 8 kHz, and any number of channels.
|
||||
EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("pcma", 8000, 0)));
|
||||
@ -44,7 +47,8 @@ TEST(AudioDecoderFactoryTest, CreatePcma) {
|
||||
}
|
||||
|
||||
TEST(AudioDecoderFactoryTest, CreateIlbc) {
|
||||
std::unique_ptr<AudioDecoderFactory> adf = CreateBuiltinAudioDecoderFactory();
|
||||
rtc::scoped_refptr<AudioDecoderFactory> adf =
|
||||
CreateBuiltinAudioDecoderFactory();
|
||||
ASSERT_TRUE(adf);
|
||||
// iLBC supports 8 kHz, 1 channel.
|
||||
EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("ilbc", 8000, 0)));
|
||||
@ -60,7 +64,8 @@ TEST(AudioDecoderFactoryTest, CreateIlbc) {
|
||||
}
|
||||
|
||||
TEST(AudioDecoderFactoryTest, CreateIsac) {
|
||||
std::unique_ptr<AudioDecoderFactory> adf = CreateBuiltinAudioDecoderFactory();
|
||||
rtc::scoped_refptr<AudioDecoderFactory> adf =
|
||||
CreateBuiltinAudioDecoderFactory();
|
||||
ASSERT_TRUE(adf);
|
||||
// iSAC supports 16 kHz, 1 channel. The float implementation additionally
|
||||
// supports 32 kHz, 1 channel.
|
||||
@ -77,7 +82,8 @@ TEST(AudioDecoderFactoryTest, CreateIsac) {
|
||||
}
|
||||
|
||||
TEST(AudioDecoderFactoryTest, CreateL16) {
|
||||
std::unique_ptr<AudioDecoderFactory> adf = CreateBuiltinAudioDecoderFactory();
|
||||
rtc::scoped_refptr<AudioDecoderFactory> adf =
|
||||
CreateBuiltinAudioDecoderFactory();
|
||||
ASSERT_TRUE(adf);
|
||||
// L16 supports any clock rate, any number of channels.
|
||||
const int clockrates[] = {8000, 16000, 32000, 48000};
|
||||
@ -92,7 +98,8 @@ TEST(AudioDecoderFactoryTest, CreateL16) {
|
||||
}
|
||||
|
||||
TEST(AudioDecoderFactoryTest, CreateG722) {
|
||||
std::unique_ptr<AudioDecoderFactory> adf = CreateBuiltinAudioDecoderFactory();
|
||||
rtc::scoped_refptr<AudioDecoderFactory> adf =
|
||||
CreateBuiltinAudioDecoderFactory();
|
||||
ASSERT_TRUE(adf);
|
||||
// g722 supports 8 kHz, 1-2 channels.
|
||||
EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("g722", 8000, 0)));
|
||||
@ -104,7 +111,8 @@ TEST(AudioDecoderFactoryTest, CreateG722) {
|
||||
}
|
||||
|
||||
TEST(AudioDecoderFactoryTest, CreateOpus) {
|
||||
std::unique_ptr<AudioDecoderFactory> adf = CreateBuiltinAudioDecoderFactory();
|
||||
rtc::scoped_refptr<AudioDecoderFactory> adf =
|
||||
CreateBuiltinAudioDecoderFactory();
|
||||
ASSERT_TRUE(adf);
|
||||
// Opus supports 48 kHz, 2 channels, and wants a "stereo" parameter whose
|
||||
// value is either "0" or "1".
|
||||
|
||||
@ -145,8 +145,9 @@ class BuiltinAudioDecoderFactory : public AudioDecoderFactory {
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory() {
|
||||
return std::unique_ptr<AudioDecoderFactory>(new BuiltinAudioDecoderFactory);
|
||||
rtc::scoped_refptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory() {
|
||||
return rtc::scoped_refptr<AudioDecoderFactory>(
|
||||
new rtc::RefCountedObject<BuiltinAudioDecoderFactory>);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -13,13 +13,14 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "webrtc/base/scoped_ref_ptr.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_decoder_factory.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Creates a new factory that can create the built-in types of audio decoders.
|
||||
// NOTE: This function is still under development and may change without notice.
|
||||
std::unique_ptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory();
|
||||
rtc::scoped_refptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory();
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user