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 // This test generate synthetic data. For audio it's a sinusoid waveform with | 5 // This test generate synthetic data. For audio it's a sinusoid waveform with |
6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern | 6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern |
7 // that is shifting by one pixel per frame, each pixels neighbors right and down | 7 // that is shifting by one pixel per frame, each pixels neighbors right and down |
8 // is this pixels value +1, since the pixel value is 8 bit it will wrap | 8 // is this pixels value +1, since the pixel value is 8 bit it will wrap |
9 // frequently within the image. Visually this will create diagonally color bands | 9 // frequently within the image. Visually this will create diagonally color bands |
10 // that moves across the screen | 10 // that moves across the screen |
11 | 11 |
12 #include <math.h> | 12 #include <math.h> |
13 #include <stdint.h> | 13 #include <stdint.h> |
14 | 14 |
15 #include <functional> | 15 #include <functional> |
16 #include <list> | 16 #include <list> |
17 #include <map> | 17 #include <map> |
18 | 18 |
19 #include "base/bind.h" | 19 #include "base/bind.h" |
20 #include "base/bind_helpers.h" | 20 #include "base/bind_helpers.h" |
21 #include "base/stl_util.h" | |
22 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
23 #include "base/sys_byteorder.h" | 22 #include "base/sys_byteorder.h" |
24 #include "base/test/simple_test_tick_clock.h" | 23 #include "base/test/simple_test_tick_clock.h" |
25 #include "base/time/tick_clock.h" | 24 #include "base/time/tick_clock.h" |
26 #include "media/base/audio_bus.h" | 25 #include "media/base/audio_bus.h" |
27 #include "media/base/video_frame.h" | 26 #include "media/base/video_frame.h" |
28 #include "media/cast/cast_config.h" | 27 #include "media/cast/cast_config.h" |
29 #include "media/cast/cast_environment.h" | 28 #include "media/cast/cast_environment.h" |
30 #include "media/cast/cast_receiver.h" | 29 #include "media/cast/cast_receiver.h" |
31 #include "media/cast/cast_sender.h" | 30 #include "media/cast/cast_sender.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 expected_audio_frame->record_time + | 297 expected_audio_frame->record_time + |
299 base::TimeDelta::FromMilliseconds(kDefaultRtpMaxDelayMs + | 298 base::TimeDelta::FromMilliseconds(kDefaultRtpMaxDelayMs + |
300 kTimerErrorMs); | 299 kTimerErrorMs); |
301 EXPECT_GE(upper_bound, playout_time) | 300 EXPECT_GE(upper_bound, playout_time) |
302 << "playout_time - upper_bound == " | 301 << "playout_time - upper_bound == " |
303 << (playout_time - upper_bound).InMicroseconds() << " usec"; | 302 << (playout_time - upper_bound).InMicroseconds() << " usec"; |
304 | 303 |
305 EXPECT_TRUE(is_continuous); | 304 EXPECT_TRUE(is_continuous); |
306 } | 305 } |
307 | 306 |
308 void CheckCodedAudioFrame( | 307 void CheckCodedAudioFrame(scoped_ptr<transport::EncodedFrame> audio_frame) { |
309 scoped_ptr<transport::EncodedAudioFrame> audio_frame, | |
310 const base::TimeTicks& playout_time) { | |
311 ASSERT_TRUE(!!audio_frame); | 308 ASSERT_TRUE(!!audio_frame); |
312 ASSERT_FALSE(expected_frames_.empty()); | 309 ASSERT_FALSE(expected_frames_.empty()); |
313 const ExpectedAudioFrame& expected_audio_frame = | 310 const ExpectedAudioFrame& expected_audio_frame = |
314 *(expected_frames_.front()); | 311 *(expected_frames_.front()); |
315 // Note: Just peeking here. Will delegate to CheckAudioFrame() to pop. | 312 // Note: Just peeking here. Will delegate to CheckAudioFrame() to pop. |
316 | 313 |
317 // We need to "decode" the encoded audio frame. The codec is simply to | 314 // We need to "decode" the encoded audio frame. The codec is simply to |
318 // swizzle the bytes of each int16 from host-->network-->host order to get | 315 // swizzle the bytes of each int16 from host-->network-->host order to get |
319 // interleaved int16 PCM. Then, make an AudioBus out of that. | 316 // interleaved int16 PCM. Then, make an AudioBus out of that. |
320 const int num_elements = audio_frame->data.size() / sizeof(int16); | 317 const int num_elements = audio_frame->data.size() / sizeof(int16); |
321 ASSERT_EQ(expected_audio_frame.audio_bus->channels() * | 318 ASSERT_EQ(expected_audio_frame.audio_bus->channels() * |
322 expected_audio_frame.audio_bus->frames(), | 319 expected_audio_frame.audio_bus->frames(), |
323 num_elements); | 320 num_elements); |
324 int16* const pcm_data = | 321 int16* const pcm_data = |
325 reinterpret_cast<int16*>(string_as_array(&audio_frame->data)); | 322 reinterpret_cast<int16*>(audio_frame->mutable_bytes()); |
hubbe
2014/05/16 17:13:20
Why not ->bytes() ?
miu
2014/05/16 21:28:46
Is your question:
1. Why did I choose to call mut
| |
326 for (int i = 0; i < num_elements; ++i) | 323 for (int i = 0; i < num_elements; ++i) |
327 pcm_data[i] = static_cast<int16>(base::NetToHost16(pcm_data[i])); | 324 pcm_data[i] = static_cast<int16>(base::NetToHost16(pcm_data[i])); |
328 scoped_ptr<AudioBus> audio_bus( | 325 scoped_ptr<AudioBus> audio_bus( |
329 AudioBus::Create(expected_audio_frame.audio_bus->channels(), | 326 AudioBus::Create(expected_audio_frame.audio_bus->channels(), |
330 expected_audio_frame.audio_bus->frames())); | 327 expected_audio_frame.audio_bus->frames())); |
331 audio_bus->FromInterleaved(pcm_data, audio_bus->frames(), sizeof(int16)); | 328 audio_bus->FromInterleaved(pcm_data, audio_bus->frames(), sizeof(int16)); |
332 | 329 |
333 // Delegate the checking from here... | 330 // Delegate the checking from here... |
334 CheckAudioFrame(audio_bus.Pass(), playout_time, true); | 331 CheckAudioFrame(audio_bus.Pass(), audio_frame->reference_time, true); |
335 } | 332 } |
336 | 333 |
337 int number_times_called() const { return num_called_; } | 334 int number_times_called() const { return num_called_; } |
338 | 335 |
339 protected: | 336 protected: |
340 virtual ~TestReceiverAudioCallback() { | 337 virtual ~TestReceiverAudioCallback() { |
341 STLDeleteElements(&expected_frames_); | 338 STLDeleteElements(&expected_frames_); |
342 } | 339 } |
343 | 340 |
344 private: | 341 private: |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1252 EXPECT_EQ(1000, received_counter); | 1249 EXPECT_EQ(1000, received_counter); |
1253 } | 1250 } |
1254 | 1251 |
1255 // TODO(pwestin): Add repeatable packet loss test. | 1252 // TODO(pwestin): Add repeatable packet loss test. |
1256 // TODO(pwestin): Add test for misaligned send get calls. | 1253 // TODO(pwestin): Add test for misaligned send get calls. |
1257 // TODO(pwestin): Add more tests that does not resample. | 1254 // TODO(pwestin): Add more tests that does not resample. |
1258 // TODO(pwestin): Add test when we have starvation for our RunTask. | 1255 // TODO(pwestin): Add test when we have starvation for our RunTask. |
1259 | 1256 |
1260 } // namespace cast | 1257 } // namespace cast |
1261 } // namespace media | 1258 } // namespace media |
OLD | NEW |