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:
parent
6e8224f4ab
commit
e725f7c73e
@ -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
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ TEST(DecisionLogic, CreateAndDestroy) {
|
||||
int fs_hz = 8000;
|
||||
int output_size_samples = fs_hz / 100; // Samples per 10 ms.
|
||||
DecoderDatabase decoder_database(
|
||||
std::unique_ptr<MockAudioDecoderFactory>(new MockAudioDecoderFactory));
|
||||
new rtc::RefCountedObject<MockAudioDecoderFactory>);
|
||||
TickTimer tick_timer;
|
||||
PacketBuffer packet_buffer(10, &tick_timer);
|
||||
DelayPeakDetector delay_peak_detector(&tick_timer);
|
||||
|
||||
@ -20,10 +20,10 @@
|
||||
namespace webrtc {
|
||||
|
||||
DecoderDatabase::DecoderDatabase(
|
||||
std::unique_ptr<AudioDecoderFactory> decoder_factory)
|
||||
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory)
|
||||
: active_decoder_type_(-1),
|
||||
active_cng_decoder_type_(-1),
|
||||
decoder_factory_(std::move(decoder_factory)) {}
|
||||
decoder_factory_(decoder_factory) {}
|
||||
|
||||
DecoderDatabase::~DecoderDatabase() = default;
|
||||
|
||||
|
||||
@ -69,7 +69,8 @@ class DecoderDatabase {
|
||||
// only 7 bits).
|
||||
static const uint8_t kRtpPayloadTypeError = 0xFF;
|
||||
|
||||
DecoderDatabase(std::unique_ptr<AudioDecoderFactory> decoder_factory);
|
||||
DecoderDatabase(
|
||||
const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory);
|
||||
|
||||
virtual ~DecoderDatabase();
|
||||
|
||||
@ -160,7 +161,7 @@ class DecoderDatabase {
|
||||
int active_decoder_type_;
|
||||
int active_cng_decoder_type_;
|
||||
std::unique_ptr<ComfortNoiseDecoder> active_cng_decoder_;
|
||||
const std::unique_ptr<AudioDecoderFactory> decoder_factory_;
|
||||
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase);
|
||||
};
|
||||
|
||||
@ -25,15 +25,13 @@
|
||||
namespace webrtc {
|
||||
|
||||
TEST(DecoderDatabase, CreateAndDestroy) {
|
||||
std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory);
|
||||
DecoderDatabase db(std::move(factory));
|
||||
DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
|
||||
EXPECT_EQ(0, db.Size());
|
||||
EXPECT_TRUE(db.Empty());
|
||||
}
|
||||
|
||||
TEST(DecoderDatabase, InsertAndRemove) {
|
||||
std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory);
|
||||
DecoderDatabase db(std::move(factory));
|
||||
DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
|
||||
const uint8_t kPayloadType = 0;
|
||||
const std::string kCodecName = "Robert\'); DROP TABLE Students;";
|
||||
EXPECT_EQ(
|
||||
@ -47,8 +45,7 @@ TEST(DecoderDatabase, InsertAndRemove) {
|
||||
}
|
||||
|
||||
TEST(DecoderDatabase, GetDecoderInfo) {
|
||||
std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory);
|
||||
DecoderDatabase db(std::move(factory));
|
||||
DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
|
||||
const uint8_t kPayloadType = 0;
|
||||
const std::string kCodecName = "Robert\'); DROP TABLE Students;";
|
||||
EXPECT_EQ(
|
||||
@ -66,8 +63,7 @@ TEST(DecoderDatabase, GetDecoderInfo) {
|
||||
}
|
||||
|
||||
TEST(DecoderDatabase, GetRtpPayloadType) {
|
||||
std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory);
|
||||
DecoderDatabase db(std::move(factory));
|
||||
DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
|
||||
const uint8_t kPayloadType = 0;
|
||||
const std::string kCodecName = "Robert\'); DROP TABLE Students;";
|
||||
EXPECT_EQ(
|
||||
@ -92,8 +88,7 @@ TEST(DecoderDatabase, GetDecoder) {
|
||||
}
|
||||
|
||||
TEST(DecoderDatabase, TypeTests) {
|
||||
std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory);
|
||||
DecoderDatabase db(std::move(factory));
|
||||
DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
|
||||
const uint8_t kPayloadTypePcmU = 0;
|
||||
const uint8_t kPayloadTypeCng = 13;
|
||||
const uint8_t kPayloadTypeDtmf = 100;
|
||||
@ -128,8 +123,7 @@ TEST(DecoderDatabase, TypeTests) {
|
||||
}
|
||||
|
||||
TEST(DecoderDatabase, ExternalDecoder) {
|
||||
std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory);
|
||||
DecoderDatabase db(std::move(factory));
|
||||
DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
|
||||
const uint8_t kPayloadType = 0;
|
||||
const std::string kCodecName = "Robert\'); DROP TABLE Students;";
|
||||
MockAudioDecoder decoder;
|
||||
@ -158,8 +152,7 @@ TEST(DecoderDatabase, ExternalDecoder) {
|
||||
}
|
||||
|
||||
TEST(DecoderDatabase, CheckPayloadTypes) {
|
||||
std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory);
|
||||
DecoderDatabase db(std::move(factory));
|
||||
DecoderDatabase db(new rtc::RefCountedObject<MockAudioDecoderFactory>);
|
||||
// Load a number of payloads into the database. Payload types are 0, 1, ...,
|
||||
// while the decoder type is the same for all payload types (this does not
|
||||
// matter for the test).
|
||||
|
||||
@ -311,8 +311,8 @@ TEST(RedPayloadSplitter, CheckRedPayloads) {
|
||||
// Use a real DecoderDatabase object here instead of a mock, since it is
|
||||
// easier to just register the payload types and let the actual implementation
|
||||
// do its job.
|
||||
std::unique_ptr<MockAudioDecoderFactory> factory(new MockAudioDecoderFactory);
|
||||
DecoderDatabase decoder_database(std::move(factory));
|
||||
DecoderDatabase decoder_database(
|
||||
new rtc::RefCountedObject<MockAudioDecoderFactory>);
|
||||
decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderCNGnb, "cng-nb");
|
||||
decoder_database.RegisterPayload(1, NetEqDecoder::kDecoderPCMu, "pcmu");
|
||||
decoder_database.RegisterPayload(2, NetEqDecoder::kDecoderAVT, "avt");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user