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

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/codec_owner_unittest.cc

Issue 1331853002: ACM CodecOwner: Test that we reset speech encoder when enabling CNG or RED (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@mark
Patch Set: Created 5 years, 3 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 | « no previous file | 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
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 EXPECT_TRUE(encoded_info.redundant.empty()); 49 EXPECT_TRUE(encoded_info.redundant.empty());
50 EXPECT_EQ(expected_out_length, encoded_info.encoded_bytes); 50 EXPECT_EQ(expected_out_length, encoded_info.encoded_bytes);
51 EXPECT_EQ(expected_timestamp, encoded_info.encoded_timestamp); 51 EXPECT_EQ(expected_timestamp, encoded_info.encoded_timestamp);
52 if (expected_payload_type >= 0) 52 if (expected_payload_type >= 0)
53 EXPECT_EQ(expected_payload_type, encoded_info.payload_type); 53 EXPECT_EQ(expected_payload_type, encoded_info.payload_type);
54 if (expected_send_even_if_empty >= 0) 54 if (expected_send_even_if_empty >= 0)
55 EXPECT_EQ(static_cast<bool>(expected_send_even_if_empty), 55 EXPECT_EQ(static_cast<bool>(expected_send_even_if_empty),
56 encoded_info.send_even_if_empty); 56 encoded_info.send_even_if_empty);
57 } 57 }
58 58
59 // Verify that the speech encoder's Reset method is called when CNG or RED
60 // (or both) are switched on, but not when they're switched off.
61 void TestCngAndRedResetSpeechEncoder(bool use_cng, bool use_red) {
62 MockAudioEncoder speech_encoder;
63 EXPECT_CALL(speech_encoder, NumChannels())
64 .WillRepeatedly(Return(1));
65 EXPECT_CALL(speech_encoder, Max10MsFramesInAPacket())
66 .WillRepeatedly(Return(2));
67 EXPECT_CALL(speech_encoder, SampleRateHz())
68 .WillRepeatedly(Return(8000));
69 {
70 InSequence s;
71 EXPECT_CALL(speech_encoder, Mark("start off"));
72 EXPECT_CALL(speech_encoder, Mark("switch on"));
73 if (use_cng || use_red)
74 EXPECT_CALL(speech_encoder, Reset());
75 EXPECT_CALL(speech_encoder, Mark("start on"));
76 if (use_cng || use_red)
77 EXPECT_CALL(speech_encoder, Reset());
78 EXPECT_CALL(speech_encoder, Mark("switch off"));
79 EXPECT_CALL(speech_encoder, Die());
80 }
81
82 int cng_pt = use_cng ? 17 : -1;
83 int red_pt = use_red ? 19 : -1;
84 speech_encoder.Mark("start off");
85 codec_owner_.SetEncoders(&speech_encoder, -1, VADNormal, -1);
86 speech_encoder.Mark("switch on");
87 codec_owner_.ChangeCngAndRed(cng_pt, VADNormal, red_pt);
88 speech_encoder.Mark("start on");
89 codec_owner_.SetEncoders(&speech_encoder, cng_pt, VADNormal, red_pt);
90 speech_encoder.Mark("switch off");
91 codec_owner_.ChangeCngAndRed(-1, VADNormal, -1);
92 }
93
59 CodecOwner codec_owner_; 94 CodecOwner codec_owner_;
60 uint32_t timestamp_; 95 uint32_t timestamp_;
61 }; 96 };
62 97
63 // This test verifies that CNG frames are delivered as expected. Since the frame 98 // This test verifies that CNG frames are delivered as expected. Since the frame
64 // size is set to 20 ms, we expect the first encode call to produce no output 99 // size is set to 20 ms, we expect the first encode call to produce no output
65 // (which is signaled as 0 bytes output of type kNoEncoding). The next encode 100 // (which is signaled as 0 bytes output of type kNoEncoding). The next encode
66 // call should produce one SID frame of 9 bytes. The third call should not 101 // call should produce one SID frame of 9 bytes. The third call should not
67 // result in any output (just like the first one). The fourth and final encode 102 // result in any output (just like the first one). The fourth and final encode
68 // call should produce an "empty frame", which is like no output, but with 103 // call should produce an "empty frame", which is like no output, but with
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 arraysize(encoded), encoded); 173 arraysize(encoded), encoded);
139 external_encoder.Mark("B"); 174 external_encoder.Mark("B");
140 175
141 // Change back to external encoder again. 176 // Change back to external encoder again.
142 codec_owner_.SetEncoders(&external_encoder, -1, VADNormal, -1); 177 codec_owner_.SetEncoders(&external_encoder, -1, VADNormal, -1);
143 info = codec_owner_.Encoder()->Encode(2, audio, arraysize(audio), 178 info = codec_owner_.Encoder()->Encode(2, audio, arraysize(audio),
144 arraysize(encoded), encoded); 179 arraysize(encoded), encoded);
145 EXPECT_EQ(2u, info.encoded_timestamp); 180 EXPECT_EQ(2u, info.encoded_timestamp);
146 } 181 }
147 182
183 TEST_F(CodecOwnerTest, CngResetsSpeechEncoder) {
184 TestCngAndRedResetSpeechEncoder(true, false);
185 }
186
187 TEST_F(CodecOwnerTest, RedResetsSpeechEncoder) {
188 TestCngAndRedResetSpeechEncoder(false, true);
189 }
190
191 TEST_F(CodecOwnerTest, CngAndRedResetsSpeechEncoder) {
192 TestCngAndRedResetSpeechEncoder(true, true);
193 }
194
195 TEST_F(CodecOwnerTest, NoCngAndRedNoSpeechEncoderReset) {
196 TestCngAndRedResetSpeechEncoder(false, false);
197 }
198
148 } // namespace acm2 199 } // namespace acm2
149 } // namespace webrtc 200 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698