| OLD | NEW |
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 total_audio_feed_in_ = base::TimeDelta(); | 76 total_audio_feed_in_ = base::TimeDelta(); |
| 77 total_audio_decoded_ = base::TimeDelta(); | 77 total_audio_decoded_ = base::TimeDelta(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Called from the unit test thread to create another EncodedFrame and push it | 80 // Called from the unit test thread to create another EncodedFrame and push it |
| 81 // into the decoding pipeline. | 81 // into the decoding pipeline. |
| 82 void FeedMoreAudio(const base::TimeDelta& duration, | 82 void FeedMoreAudio(const base::TimeDelta& duration, |
| 83 int num_dropped_frames) { | 83 int num_dropped_frames) { |
| 84 // Prepare a simulated EncodedFrame to feed into the AudioDecoder. | 84 // Prepare a simulated EncodedFrame to feed into the AudioDecoder. |
| 85 scoped_ptr<EncodedFrame> encoded_frame( | 85 std::unique_ptr<EncodedFrame> encoded_frame(new EncodedFrame()); |
| 86 new EncodedFrame()); | |
| 87 encoded_frame->dependency = EncodedFrame::KEY; | 86 encoded_frame->dependency = EncodedFrame::KEY; |
| 88 encoded_frame->frame_id = last_frame_id_ + 1 + num_dropped_frames; | 87 encoded_frame->frame_id = last_frame_id_ + 1 + num_dropped_frames; |
| 89 encoded_frame->referenced_frame_id = encoded_frame->frame_id; | 88 encoded_frame->referenced_frame_id = encoded_frame->frame_id; |
| 90 last_frame_id_ = encoded_frame->frame_id; | 89 last_frame_id_ = encoded_frame->frame_id; |
| 91 | 90 |
| 92 const scoped_ptr<AudioBus> audio_bus( | 91 const std::unique_ptr<AudioBus> audio_bus( |
| 93 audio_bus_factory_->NextAudioBus(duration)); | 92 audio_bus_factory_->NextAudioBus(duration)); |
| 94 | 93 |
| 95 // Encode |audio_bus| into |encoded_frame->data|. | 94 // Encode |audio_bus| into |encoded_frame->data|. |
| 96 const int num_elements = audio_bus->channels() * audio_bus->frames(); | 95 const int num_elements = audio_bus->channels() * audio_bus->frames(); |
| 97 std::vector<int16_t> interleaved(num_elements); | 96 std::vector<int16_t> interleaved(num_elements); |
| 98 audio_bus->ToInterleaved(audio_bus->frames(), sizeof(int16_t), | 97 audio_bus->ToInterleaved(audio_bus->frames(), sizeof(int16_t), |
| 99 &interleaved.front()); | 98 &interleaved.front()); |
| 100 if (GetParam().codec == CODEC_AUDIO_PCM16) { | 99 if (GetParam().codec == CODEC_AUDIO_PCM16) { |
| 101 encoded_frame->data.resize(num_elements * sizeof(int16_t)); | 100 encoded_frame->data.resize(num_elements * sizeof(int16_t)); |
| 102 int16_t* const pcm_data = | 101 int16_t* const pcm_data = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 base::AutoLock auto_lock(lock_); | 141 base::AutoLock auto_lock(lock_); |
| 143 while (total_audio_decoded_ < total_audio_feed_in_) | 142 while (total_audio_decoded_ < total_audio_feed_in_) |
| 144 cond_.Wait(); | 143 cond_.Wait(); |
| 145 EXPECT_EQ(total_audio_feed_in_.InMicroseconds(), | 144 EXPECT_EQ(total_audio_feed_in_.InMicroseconds(), |
| 146 total_audio_decoded_.InMicroseconds()); | 145 total_audio_decoded_.InMicroseconds()); |
| 147 } | 146 } |
| 148 | 147 |
| 149 private: | 148 private: |
| 150 // Called by |audio_decoder_| to deliver each frame of decoded audio. | 149 // Called by |audio_decoder_| to deliver each frame of decoded audio. |
| 151 void OnDecodedFrame(bool should_be_continuous, | 150 void OnDecodedFrame(bool should_be_continuous, |
| 152 scoped_ptr<AudioBus> audio_bus, | 151 std::unique_ptr<AudioBus> audio_bus, |
| 153 bool is_continuous) { | 152 bool is_continuous) { |
| 154 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 153 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 155 | 154 |
| 156 // 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. |
| 157 ASSERT_TRUE(audio_bus); | 156 ASSERT_TRUE(audio_bus); |
| 158 | 157 |
| 159 // Did the decoder detect whether frames were dropped? | 158 // Did the decoder detect whether frames were dropped? |
| 160 EXPECT_EQ(should_be_continuous, is_continuous); | 159 EXPECT_EQ(should_be_continuous, is_continuous); |
| 161 | 160 |
| 162 // 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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 178 } | 177 } |
| 179 | 178 |
| 180 // Signal the main test thread that more audio was decoded. | 179 // Signal the main test thread that more audio was decoded. |
| 181 base::AutoLock auto_lock(lock_); | 180 base::AutoLock auto_lock(lock_); |
| 182 total_audio_decoded_ += base::TimeDelta::FromSeconds(1) * | 181 total_audio_decoded_ += base::TimeDelta::FromSeconds(1) * |
| 183 audio_bus->frames() / GetParam().sampling_rate; | 182 audio_bus->frames() / GetParam().sampling_rate; |
| 184 cond_.Signal(); | 183 cond_.Signal(); |
| 185 } | 184 } |
| 186 | 185 |
| 187 const scoped_refptr<StandaloneCastEnvironment> cast_environment_; | 186 const scoped_refptr<StandaloneCastEnvironment> cast_environment_; |
| 188 scoped_ptr<AudioDecoder> audio_decoder_; | 187 std::unique_ptr<AudioDecoder> audio_decoder_; |
| 189 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; | 188 std::unique_ptr<TestAudioBusFactory> audio_bus_factory_; |
| 190 uint32_t last_frame_id_; | 189 uint32_t last_frame_id_; |
| 191 bool seen_a_decoded_frame_; | 190 bool seen_a_decoded_frame_; |
| 192 scoped_ptr<uint8_t[]> opus_encoder_memory_; | 191 std::unique_ptr<uint8_t[]> opus_encoder_memory_; |
| 193 | 192 |
| 194 base::Lock lock_; | 193 base::Lock lock_; |
| 195 base::ConditionVariable cond_; | 194 base::ConditionVariable cond_; |
| 196 base::TimeDelta total_audio_feed_in_; | 195 base::TimeDelta total_audio_feed_in_; |
| 197 base::TimeDelta total_audio_decoded_; | 196 base::TimeDelta total_audio_decoded_; |
| 198 | 197 |
| 199 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest); | 198 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest); |
| 200 }; | 199 }; |
| 201 | 200 |
| 202 TEST_P(AudioDecoderTest, DecodesFramesWithSameDuration) { | 201 TEST_P(AudioDecoderTest, DecodesFramesWithSameDuration) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 AudioDecoderTestScenarios, | 241 AudioDecoderTestScenarios, |
| 243 AudioDecoderTest, | 242 AudioDecoderTest, |
| 244 ::testing::Values( | 243 ::testing::Values( |
| 245 TestScenario(CODEC_AUDIO_PCM16, 1, 8000), | 244 TestScenario(CODEC_AUDIO_PCM16, 1, 8000), |
| 246 TestScenario(CODEC_AUDIO_PCM16, 2, 48000), | 245 TestScenario(CODEC_AUDIO_PCM16, 2, 48000), |
| 247 TestScenario(CODEC_AUDIO_OPUS, 1, 8000), | 246 TestScenario(CODEC_AUDIO_OPUS, 1, 8000), |
| 248 TestScenario(CODEC_AUDIO_OPUS, 2, 48000))); | 247 TestScenario(CODEC_AUDIO_OPUS, 2, 48000))); |
| 249 | 248 |
| 250 } // namespace cast | 249 } // namespace cast |
| 251 } // namespace media | 250 } // namespace media |
| OLD | NEW |