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

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

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/synchronization/condition_variable.h" 7 #include "base/synchronization/condition_variable.h"
8 #include "base/synchronization/lock.h" 8 #include "base/synchronization/lock.h"
9 #include "base/sys_byteorder.h" 9 #include "base/sys_byteorder.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 audio_bus_factory_.reset( 51 audio_bus_factory_.reset(
52 new TestAudioBusFactory(GetParam().num_channels, 52 new TestAudioBusFactory(GetParam().num_channels,
53 GetParam().sampling_rate, 53 GetParam().sampling_rate,
54 TestAudioBusFactory::kMiddleANoteFreq, 54 TestAudioBusFactory::kMiddleANoteFreq,
55 0.5f)); 55 0.5f));
56 last_frame_id_ = 0; 56 last_frame_id_ = 0;
57 seen_a_decoded_frame_ = false; 57 seen_a_decoded_frame_ = false;
58 58
59 if (GetParam().codec == CODEC_AUDIO_OPUS) { 59 if (GetParam().codec == CODEC_AUDIO_OPUS) {
60 opus_encoder_memory_.reset( 60 opus_encoder_memory_.reset(
61 new uint8[opus_encoder_get_size(GetParam().num_channels)]); 61 new uint8_t[opus_encoder_get_size(GetParam().num_channels)]);
62 OpusEncoder* const opus_encoder = 62 OpusEncoder* const opus_encoder =
63 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get()); 63 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get());
64 CHECK_EQ(OPUS_OK, opus_encoder_init(opus_encoder, 64 CHECK_EQ(OPUS_OK, opus_encoder_init(opus_encoder,
65 GetParam().sampling_rate, 65 GetParam().sampling_rate,
66 GetParam().num_channels, 66 GetParam().num_channels,
67 OPUS_APPLICATION_AUDIO)); 67 OPUS_APPLICATION_AUDIO));
68 CHECK_EQ(OPUS_OK, 68 CHECK_EQ(OPUS_OK,
69 opus_encoder_ctl(opus_encoder, OPUS_SET_BITRATE(OPUS_AUTO))); 69 opus_encoder_ctl(opus_encoder, OPUS_SET_BITRATE(OPUS_AUTO)));
70 } 70 }
71 71
(...skipping 11 matching lines...) Expand all
83 encoded_frame->dependency = EncodedFrame::KEY; 83 encoded_frame->dependency = EncodedFrame::KEY;
84 encoded_frame->frame_id = last_frame_id_ + 1 + num_dropped_frames; 84 encoded_frame->frame_id = last_frame_id_ + 1 + num_dropped_frames;
85 encoded_frame->referenced_frame_id = encoded_frame->frame_id; 85 encoded_frame->referenced_frame_id = encoded_frame->frame_id;
86 last_frame_id_ = encoded_frame->frame_id; 86 last_frame_id_ = encoded_frame->frame_id;
87 87
88 const scoped_ptr<AudioBus> audio_bus( 88 const scoped_ptr<AudioBus> audio_bus(
89 audio_bus_factory_->NextAudioBus(duration).Pass()); 89 audio_bus_factory_->NextAudioBus(duration).Pass());
90 90
91 // Encode |audio_bus| into |encoded_frame->data|. 91 // Encode |audio_bus| into |encoded_frame->data|.
92 const int num_elements = audio_bus->channels() * audio_bus->frames(); 92 const int num_elements = audio_bus->channels() * audio_bus->frames();
93 std::vector<int16> interleaved(num_elements); 93 std::vector<int16_t> interleaved(num_elements);
94 audio_bus->ToInterleaved( 94 audio_bus->ToInterleaved(audio_bus->frames(), sizeof(int16_t),
95 audio_bus->frames(), sizeof(int16), &interleaved.front()); 95 &interleaved.front());
96 if (GetParam().codec == CODEC_AUDIO_PCM16) { 96 if (GetParam().codec == CODEC_AUDIO_PCM16) {
97 encoded_frame->data.resize(num_elements * sizeof(int16)); 97 encoded_frame->data.resize(num_elements * sizeof(int16_t));
98 int16* const pcm_data = 98 int16_t* const pcm_data =
99 reinterpret_cast<int16*>(encoded_frame->mutable_bytes()); 99 reinterpret_cast<int16_t*>(encoded_frame->mutable_bytes());
100 for (size_t i = 0; i < interleaved.size(); ++i) 100 for (size_t i = 0; i < interleaved.size(); ++i)
101 pcm_data[i] = static_cast<int16>(base::HostToNet16(interleaved[i])); 101 pcm_data[i] = static_cast<int16_t>(base::HostToNet16(interleaved[i]));
102 } else if (GetParam().codec == CODEC_AUDIO_OPUS) { 102 } else if (GetParam().codec == CODEC_AUDIO_OPUS) {
103 OpusEncoder* const opus_encoder = 103 OpusEncoder* const opus_encoder =
104 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get()); 104 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get());
105 const int kOpusEncodeBufferSize = 4000; 105 const int kOpusEncodeBufferSize = 4000;
106 encoded_frame->data.resize(kOpusEncodeBufferSize); 106 encoded_frame->data.resize(kOpusEncodeBufferSize);
107 const int payload_size = 107 const int payload_size =
108 opus_encode(opus_encoder, 108 opus_encode(opus_encoder,
109 &interleaved.front(), 109 &interleaved.front(),
110 audio_bus->frames(), 110 audio_bus->frames(),
111 encoded_frame->mutable_bytes(), 111 encoded_frame->mutable_bytes(),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // Signal the main test thread that more audio was decoded. 176 // Signal the main test thread that more audio was decoded.
177 base::AutoLock auto_lock(lock_); 177 base::AutoLock auto_lock(lock_);
178 total_audio_decoded_ += base::TimeDelta::FromSeconds(1) * 178 total_audio_decoded_ += base::TimeDelta::FromSeconds(1) *
179 audio_bus->frames() / GetParam().sampling_rate; 179 audio_bus->frames() / GetParam().sampling_rate;
180 cond_.Signal(); 180 cond_.Signal();
181 } 181 }
182 182
183 const scoped_refptr<StandaloneCastEnvironment> cast_environment_; 183 const scoped_refptr<StandaloneCastEnvironment> cast_environment_;
184 scoped_ptr<AudioDecoder> audio_decoder_; 184 scoped_ptr<AudioDecoder> audio_decoder_;
185 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; 185 scoped_ptr<TestAudioBusFactory> audio_bus_factory_;
186 uint32 last_frame_id_; 186 uint32_t last_frame_id_;
187 bool seen_a_decoded_frame_; 187 bool seen_a_decoded_frame_;
188 scoped_ptr<uint8[]> opus_encoder_memory_; 188 scoped_ptr<uint8_t[]> opus_encoder_memory_;
189 189
190 base::Lock lock_; 190 base::Lock lock_;
191 base::ConditionVariable cond_; 191 base::ConditionVariable cond_;
192 base::TimeDelta total_audio_feed_in_; 192 base::TimeDelta total_audio_feed_in_;
193 base::TimeDelta total_audio_decoded_; 193 base::TimeDelta total_audio_decoded_;
194 194
195 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest); 195 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest);
196 }; 196 };
197 197
198 TEST_P(AudioDecoderTest, DecodesFramesWithSameDuration) { 198 TEST_P(AudioDecoderTest, DecodesFramesWithSameDuration) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 AudioDecoderTestScenarios, 238 AudioDecoderTestScenarios,
239 AudioDecoderTest, 239 AudioDecoderTest,
240 ::testing::Values( 240 ::testing::Values(
241 TestScenario(CODEC_AUDIO_PCM16, 1, 8000), 241 TestScenario(CODEC_AUDIO_PCM16, 1, 8000),
242 TestScenario(CODEC_AUDIO_PCM16, 2, 48000), 242 TestScenario(CODEC_AUDIO_PCM16, 2, 48000),
243 TestScenario(CODEC_AUDIO_OPUS, 1, 8000), 243 TestScenario(CODEC_AUDIO_OPUS, 1, 8000),
244 TestScenario(CODEC_AUDIO_OPUS, 2, 48000))); 244 TestScenario(CODEC_AUDIO_OPUS, 2, 48000)));
245 245
246 } // namespace cast 246 } // namespace cast
247 } // namespace media 247 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698