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

Side by Side Diff: media/cast/receiver/audio_decoder_unittest.cc

Issue 2962373002: [Opus] Update to v1.2.1 (Closed)
Patch Set: Pre-increment instead of post-increment Created 3 years, 5 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 | media/cast/test/utility/audio_utility.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 GetParam().sampling_rate, 51 GetParam().sampling_rate,
52 GetParam().codec)); 52 GetParam().codec));
53 CHECK_EQ(STATUS_INITIALIZED, audio_decoder_->InitializationResult()); 53 CHECK_EQ(STATUS_INITIALIZED, audio_decoder_->InitializationResult());
54 54
55 audio_bus_factory_.reset( 55 audio_bus_factory_.reset(
56 new TestAudioBusFactory(GetParam().num_channels, 56 new TestAudioBusFactory(GetParam().num_channels,
57 GetParam().sampling_rate, 57 GetParam().sampling_rate,
58 TestAudioBusFactory::kMiddleANoteFreq, 58 TestAudioBusFactory::kMiddleANoteFreq,
59 0.5f)); 59 0.5f));
60 last_frame_id_ = FrameId::first(); 60 last_frame_id_ = FrameId::first();
61 seen_a_decoded_frame_ = false; 61 decoded_frames_seen_ = 0;
62 62
63 if (GetParam().codec == CODEC_AUDIO_OPUS) { 63 if (GetParam().codec == CODEC_AUDIO_OPUS) {
64 opus_encoder_memory_.reset( 64 opus_encoder_memory_.reset(
65 new uint8_t[opus_encoder_get_size(GetParam().num_channels)]); 65 new uint8_t[opus_encoder_get_size(GetParam().num_channels)]);
66 OpusEncoder* const opus_encoder = 66 OpusEncoder* const opus_encoder =
67 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get()); 67 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get());
68 CHECK_EQ(OPUS_OK, opus_encoder_init(opus_encoder, 68 CHECK_EQ(OPUS_OK, opus_encoder_init(opus_encoder,
69 GetParam().sampling_rate, 69 GetParam().sampling_rate,
70 GetParam().num_channels, 70 GetParam().num_channels,
71 OPUS_APPLICATION_AUDIO)); 71 OPUS_APPLICATION_AUDIO));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 bool is_continuous) { 152 bool is_continuous) {
153 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 153 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
154 154
155 // A NULL |audio_bus| indicates a decode error, which we don't expect. 155 // A NULL |audio_bus| indicates a decode error, which we don't expect.
156 ASSERT_TRUE(audio_bus); 156 ASSERT_TRUE(audio_bus);
157 157
158 // Did the decoder detect whether frames were dropped? 158 // Did the decoder detect whether frames were dropped?
159 EXPECT_EQ(should_be_continuous, is_continuous); 159 EXPECT_EQ(should_be_continuous, is_continuous);
160 160
161 // Does the audio data seem to be intact? For Opus, we have to ignore the 161 // Does the audio data seem to be intact? For Opus, we have to ignore the
162 // first frame seen at the start (and immediately after dropped packet 162 // first two frames seen at the start (and immediately after dropped packet
163 // recovery) because it introduces a tiny, significant delay. 163 // recovery) because it introduces a tiny, significant delay.
164 bool examine_signal = true; 164 bool examine_signal = true;
165 if (GetParam().codec == CODEC_AUDIO_OPUS) { 165 if (GetParam().codec == CODEC_AUDIO_OPUS) {
166 examine_signal = seen_a_decoded_frame_ && should_be_continuous; 166 ++decoded_frames_seen_;
167 seen_a_decoded_frame_ = true; 167 examine_signal = (decoded_frames_seen_ > 2) && should_be_continuous;
168 } 168 }
169 if (examine_signal) { 169 if (examine_signal) {
170 for (int ch = 0; ch < audio_bus->channels(); ++ch) { 170 for (int ch = 0; ch < audio_bus->channels(); ++ch) {
171 EXPECT_NEAR( 171 EXPECT_NEAR(
172 TestAudioBusFactory::kMiddleANoteFreq * 2 * audio_bus->frames() / 172 TestAudioBusFactory::kMiddleANoteFreq * 2 * audio_bus->frames() /
173 GetParam().sampling_rate, 173 GetParam().sampling_rate,
174 CountZeroCrossings(audio_bus->channel(ch), audio_bus->frames()), 174 CountZeroCrossings(audio_bus->channel(ch), audio_bus->frames()),
175 1); 175 1);
176 } 176 }
177 } 177 }
178 178
179 // Signal the main test thread that more audio was decoded. 179 // Signal the main test thread that more audio was decoded.
180 base::AutoLock auto_lock(lock_); 180 base::AutoLock auto_lock(lock_);
181 total_audio_decoded_ += base::TimeDelta::FromSeconds(1) * 181 total_audio_decoded_ += base::TimeDelta::FromSeconds(1) *
182 audio_bus->frames() / GetParam().sampling_rate; 182 audio_bus->frames() / GetParam().sampling_rate;
183 cond_.Signal(); 183 cond_.Signal();
184 } 184 }
185 185
186 const scoped_refptr<StandaloneCastEnvironment> cast_environment_; 186 const scoped_refptr<StandaloneCastEnvironment> cast_environment_;
187 std::unique_ptr<AudioDecoder> audio_decoder_; 187 std::unique_ptr<AudioDecoder> audio_decoder_;
188 std::unique_ptr<TestAudioBusFactory> audio_bus_factory_; 188 std::unique_ptr<TestAudioBusFactory> audio_bus_factory_;
189 FrameId last_frame_id_; 189 FrameId last_frame_id_;
190 bool seen_a_decoded_frame_; 190 int decoded_frames_seen_;
191 std::unique_ptr<uint8_t[]> opus_encoder_memory_; 191 std::unique_ptr<uint8_t[]> opus_encoder_memory_;
192 192
193 base::Lock lock_; 193 base::Lock lock_;
194 base::ConditionVariable cond_; 194 base::ConditionVariable cond_;
195 base::TimeDelta total_audio_feed_in_; 195 base::TimeDelta total_audio_feed_in_;
196 base::TimeDelta total_audio_decoded_; 196 base::TimeDelta total_audio_decoded_;
197 197
198 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest); 198 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest);
199 }; 199 };
200 200
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 AudioDecoderTestScenarios, 241 AudioDecoderTestScenarios,
242 AudioDecoderTest, 242 AudioDecoderTest,
243 ::testing::Values( 243 ::testing::Values(
244 TestScenario(CODEC_AUDIO_PCM16, 1, 8000), 244 TestScenario(CODEC_AUDIO_PCM16, 1, 8000),
245 TestScenario(CODEC_AUDIO_PCM16, 2, 48000), 245 TestScenario(CODEC_AUDIO_PCM16, 2, 48000),
246 TestScenario(CODEC_AUDIO_OPUS, 1, 8000), 246 TestScenario(CODEC_AUDIO_OPUS, 1, 8000),
247 TestScenario(CODEC_AUDIO_OPUS, 2, 48000))); 247 TestScenario(CODEC_AUDIO_OPUS, 2, 48000)));
248 248
249 } // namespace cast 249 } // namespace cast
250 } // namespace media 250 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/cast/test/utility/audio_utility.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698