Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: webrtc/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc

Issue 2935643002: Templated AudioEncoderFactory (Closed)
Patch Set: better docs Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/audio_codecs/test/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/api/audio_codecs/audio_encoder_factory_template.h"
12 #include "webrtc/base/ptr_util.h"
13 #include "webrtc/test/gmock.h"
14 #include "webrtc/test/gtest.h"
15 #include "webrtc/test/mock_audio_encoder.h"
16
17 namespace webrtc {
18
19 namespace {
20
21 struct BogusParams {
22 static SdpAudioFormat AudioFormat() { return {"bogus", 8000, 1}; }
23 static AudioCodecInfo CodecInfo() { return {8000, 1, 12345}; }
24 };
25
26 struct ShamParams {
27 static SdpAudioFormat AudioFormat() {
28 return {"sham", 16000, 2, {{"param", "value"}}};
29 }
30 static AudioCodecInfo CodecInfo() { return {16000, 2, 23456}; }
31 };
32
33 struct MyLittleConfig {
34 SdpAudioFormat audio_format;
35 };
36
37 template <typename Params>
38 struct AudioEncoderFakeApi {
39 static rtc::Optional<MyLittleConfig> SdpToConfig(
40 const SdpAudioFormat& audio_format) {
41 if (Params::AudioFormat() == audio_format) {
42 MyLittleConfig config = {audio_format};
43 return rtc::Optional<MyLittleConfig>(config);
44 } else {
45 return rtc::Optional<MyLittleConfig>();
46 }
47 }
48
49 static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs) {
50 specs->push_back({Params::AudioFormat(), Params::CodecInfo()});
51 }
52
53 static AudioCodecInfo QueryAudioEncoder(const MyLittleConfig&) {
54 return Params::CodecInfo();
55 }
56
57 static std::unique_ptr<AudioEncoder> MakeAudioEncoder(const MyLittleConfig&,
58 int payload_type) {
59 auto enc = rtc::MakeUnique<testing::StrictMock<MockAudioEncoder>>();
60 EXPECT_CALL(*enc, SampleRateHz())
61 .WillOnce(testing::Return(Params::CodecInfo().sample_rate_hz));
62 EXPECT_CALL(*enc, Die());
63 return std::move(enc);
64 }
65 };
66
67 } // namespace
68
69 TEST(AudioEncoderFactoryTemplateTest, NoEncoderTypes) {
70 rtc::scoped_refptr<AudioEncoderFactory> factory(
71 new rtc::RefCountedObject<
72 audio_encoder_factory_template_impl::AudioEncoderFactoryT<>>());
73 EXPECT_THAT(factory->GetSupportedEncoders(), testing::IsEmpty());
74 EXPECT_EQ(rtc::Optional<AudioCodecInfo>(),
75 factory->QueryAudioEncoder({"foo", 8000, 1}));
76 EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1}));
77 }
78
79 TEST(AudioEncoderFactoryTemplateTest, OneEncoderType) {
80 auto factory = CreateAudioEncoderFactory<AudioEncoderFakeApi<BogusParams>>();
81 EXPECT_THAT(factory->GetSupportedEncoders(),
82 testing::ElementsAre(
83 AudioCodecSpec{{"bogus", 8000, 1}, {8000, 1, 12345}}));
84 EXPECT_EQ(rtc::Optional<AudioCodecInfo>(),
85 factory->QueryAudioEncoder({"foo", 8000, 1}));
86 EXPECT_EQ(rtc::Optional<AudioCodecInfo>({8000, 1, 12345}),
87 factory->QueryAudioEncoder({"bogus", 8000, 1}));
88 EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1}));
89 auto enc = factory->MakeAudioEncoder(17, {"bogus", 8000, 1});
90 ASSERT_NE(nullptr, enc);
91 EXPECT_EQ(8000, enc->SampleRateHz());
92 }
93
94 TEST(AudioEncoderFactoryTemplateTest, TwoEncoderTypes) {
95 auto factory = CreateAudioEncoderFactory<AudioEncoderFakeApi<BogusParams>,
96 AudioEncoderFakeApi<ShamParams>>();
97 EXPECT_THAT(factory->GetSupportedEncoders(),
98 testing::ElementsAre(
99 AudioCodecSpec{{"bogus", 8000, 1}, {8000, 1, 12345}},
100 AudioCodecSpec{{"sham", 16000, 2, {{"param", "value"}}},
101 {16000, 2, 23456}}));
102 EXPECT_EQ(rtc::Optional<AudioCodecInfo>(),
103 factory->QueryAudioEncoder({"foo", 8000, 1}));
104 EXPECT_EQ(rtc::Optional<AudioCodecInfo>({8000, 1, 12345}),
105 factory->QueryAudioEncoder({"bogus", 8000, 1}));
106 EXPECT_EQ(
107 rtc::Optional<AudioCodecInfo>({16000, 2, 23456}),
108 factory->QueryAudioEncoder({"sham", 16000, 2, {{"param", "value"}}}));
109 EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1}));
110 auto enc1 = factory->MakeAudioEncoder(17, {"bogus", 8000, 1});
111 ASSERT_NE(nullptr, enc1);
112 EXPECT_EQ(8000, enc1->SampleRateHz());
113 EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"sham", 16000, 2}));
114 auto enc2 =
115 factory->MakeAudioEncoder(17, {"sham", 16000, 2, {{"param", "value"}}});
116 ASSERT_NE(nullptr, enc2);
117 EXPECT_EQ(16000, enc2->SampleRateHz());
118 }
119
120 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/audio_codecs/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698