| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/stl_util.h" | |
| 8 #include "base/synchronization/condition_variable.h" | 7 #include "base/synchronization/condition_variable.h" |
| 9 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 10 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
| 11 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 12 #include "media/cast/audio_receiver/audio_decoder.h" | 11 #include "media/cast/audio_receiver/audio_decoder.h" |
| 13 #include "media/cast/cast_config.h" | 12 #include "media/cast/cast_config.h" |
| 14 #include "media/cast/test/utility/audio_utility.h" | 13 #include "media/cast/test/utility/audio_utility.h" |
| 15 #include "media/cast/test/utility/standalone_cast_environment.h" | 14 #include "media/cast/test/utility/standalone_cast_environment.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/opus/src/include/opus.h" | 16 #include "third_party/opus/src/include/opus.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 GetParam().num_channels, | 63 GetParam().num_channels, |
| 65 OPUS_APPLICATION_AUDIO)); | 64 OPUS_APPLICATION_AUDIO)); |
| 66 CHECK_EQ(OPUS_OK, | 65 CHECK_EQ(OPUS_OK, |
| 67 opus_encoder_ctl(opus_encoder, OPUS_SET_BITRATE(OPUS_AUTO))); | 66 opus_encoder_ctl(opus_encoder, OPUS_SET_BITRATE(OPUS_AUTO))); |
| 68 } | 67 } |
| 69 | 68 |
| 70 total_audio_feed_in_ = base::TimeDelta(); | 69 total_audio_feed_in_ = base::TimeDelta(); |
| 71 total_audio_decoded_ = base::TimeDelta(); | 70 total_audio_decoded_ = base::TimeDelta(); |
| 72 } | 71 } |
| 73 | 72 |
| 74 // Called from the unit test thread to create another EncodedAudioFrame and | 73 // Called from the unit test thread to create another EncodedFrame and push it |
| 75 // push it into the decoding pipeline. | 74 // into the decoding pipeline. |
| 76 void FeedMoreAudio(const base::TimeDelta& duration, | 75 void FeedMoreAudio(const base::TimeDelta& duration, |
| 77 int num_dropped_frames) { | 76 int num_dropped_frames) { |
| 78 // Prepare a simulated EncodedAudioFrame to feed into the AudioDecoder. | 77 // Prepare a simulated EncodedFrame to feed into the AudioDecoder. |
| 79 scoped_ptr<transport::EncodedAudioFrame> encoded_frame( | 78 scoped_ptr<transport::EncodedFrame> encoded_frame( |
| 80 new transport::EncodedAudioFrame()); | 79 new transport::EncodedFrame()); |
| 81 encoded_frame->codec = GetParam().codec; | |
| 82 encoded_frame->frame_id = last_frame_id_ + 1 + num_dropped_frames; | 80 encoded_frame->frame_id = last_frame_id_ + 1 + num_dropped_frames; |
| 81 encoded_frame->base_frame_id = encoded_frame->frame_id; |
| 83 last_frame_id_ = encoded_frame->frame_id; | 82 last_frame_id_ = encoded_frame->frame_id; |
| 84 | 83 |
| 85 const scoped_ptr<AudioBus> audio_bus( | 84 const scoped_ptr<AudioBus> audio_bus( |
| 86 audio_bus_factory_->NextAudioBus(duration).Pass()); | 85 audio_bus_factory_->NextAudioBus(duration).Pass()); |
| 87 | 86 |
| 88 // Encode |audio_bus| into |encoded_frame->data|. | 87 // Encode |audio_bus| into |encoded_frame->data|. |
| 89 const int num_elements = audio_bus->channels() * audio_bus->frames(); | 88 const int num_elements = audio_bus->channels() * audio_bus->frames(); |
| 90 std::vector<int16> interleaved(num_elements); | 89 std::vector<int16> interleaved(num_elements); |
| 91 audio_bus->ToInterleaved( | 90 audio_bus->ToInterleaved( |
| 92 audio_bus->frames(), sizeof(int16), &interleaved.front()); | 91 audio_bus->frames(), sizeof(int16), &interleaved.front()); |
| 93 if (GetParam().codec == transport::kPcm16) { | 92 if (GetParam().codec == transport::kPcm16) { |
| 94 encoded_frame->data.resize(num_elements * sizeof(int16)); | 93 encoded_frame->data.resize(num_elements * sizeof(int16)); |
| 95 int16* const pcm_data = | 94 int16* const pcm_data = |
| 96 reinterpret_cast<int16*>(string_as_array(&encoded_frame->data)); | 95 reinterpret_cast<int16*>(encoded_frame->mutable_bytes()); |
| 97 for (size_t i = 0; i < interleaved.size(); ++i) | 96 for (size_t i = 0; i < interleaved.size(); ++i) |
| 98 pcm_data[i] = static_cast<int16>(base::HostToNet16(interleaved[i])); | 97 pcm_data[i] = static_cast<int16>(base::HostToNet16(interleaved[i])); |
| 99 } else if (GetParam().codec == transport::kOpus) { | 98 } else if (GetParam().codec == transport::kOpus) { |
| 100 OpusEncoder* const opus_encoder = | 99 OpusEncoder* const opus_encoder = |
| 101 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get()); | 100 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get()); |
| 102 const int kOpusEncodeBufferSize = 4000; | 101 const int kOpusEncodeBufferSize = 4000; |
| 103 encoded_frame->data.resize(kOpusEncodeBufferSize); | 102 encoded_frame->data.resize(kOpusEncodeBufferSize); |
| 104 const int payload_size = | 103 const int payload_size = |
| 105 opus_encode(opus_encoder, | 104 opus_encode(opus_encoder, |
| 106 &interleaved.front(), | 105 &interleaved.front(), |
| 107 audio_bus->frames(), | 106 audio_bus->frames(), |
| 108 reinterpret_cast<unsigned char*>( | 107 encoded_frame->mutable_bytes(), |
| 109 string_as_array(&encoded_frame->data)), | |
| 110 encoded_frame->data.size()); | 108 encoded_frame->data.size()); |
| 111 CHECK_GT(payload_size, 1); | 109 CHECK_GT(payload_size, 1); |
| 112 encoded_frame->data.resize(payload_size); | 110 encoded_frame->data.resize(payload_size); |
| 113 } else { | 111 } else { |
| 114 ASSERT_TRUE(false); // Not reached. | 112 ASSERT_TRUE(false); // Not reached. |
| 115 } | 113 } |
| 116 | 114 |
| 117 { | 115 { |
| 118 base::AutoLock auto_lock(lock_); | 116 base::AutoLock auto_lock(lock_); |
| 119 total_audio_feed_in_ += duration; | 117 total_audio_feed_in_ += duration; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 INSTANTIATE_TEST_CASE_P(AudioDecoderTestScenarios, | 233 INSTANTIATE_TEST_CASE_P(AudioDecoderTestScenarios, |
| 236 AudioDecoderTest, | 234 AudioDecoderTest, |
| 237 ::testing::Values( | 235 ::testing::Values( |
| 238 TestScenario(transport::kPcm16, 1, 8000), | 236 TestScenario(transport::kPcm16, 1, 8000), |
| 239 TestScenario(transport::kPcm16, 2, 48000), | 237 TestScenario(transport::kPcm16, 2, 48000), |
| 240 TestScenario(transport::kOpus, 1, 8000), | 238 TestScenario(transport::kOpus, 1, 8000), |
| 241 TestScenario(transport::kOpus, 2, 48000))); | 239 TestScenario(transport::kOpus, 2, 48000))); |
| 242 | 240 |
| 243 } // namespace cast | 241 } // namespace cast |
| 244 } // namespace media | 242 } // namespace media |
| OLD | NEW |