Chromium Code Reviews| Index: media/base/test_helpers.cc |
| diff --git a/media/base/test_helpers.cc b/media/base/test_helpers.cc |
| index 2c71865e6ec5cff0679e99ef9aded1f513f861b5..9430cca969bfa3dfd73ad27770cf7065a4124a0a 100644 |
| --- a/media/base/test_helpers.cc |
| +++ b/media/base/test_helpers.cc |
| @@ -5,9 +5,12 @@ |
| #include "media/base/test_helpers.h" |
| #include "base/bind.h" |
| +#include "base/logging.h" |
| #include "base/message_loop.h" |
| #include "base/test/test_timeouts.h" |
| +#include "base/time.h" |
| #include "base/timer.h" |
| +#include "media/base/audio_buffer.h" |
| #include "media/base/bind_to_loop.h" |
| #include "ui/gfx/rect.h" |
| @@ -143,4 +146,123 @@ gfx::Size TestVideoConfig::LargeCodedSize() { |
| return kLargeSize; |
| } |
| +template <class T> |
| +scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer( |
| + SampleFormat format, |
| + int channels, |
| + T start, |
| + T increment, |
| + int frames, |
| + const base::TimeDelta start_time) { |
| + DCHECK(format == kSampleFormatU8 || format == kSampleFormatS16 || |
| + format == kSampleFormatS32 || format == kSampleFormatF32); |
| + |
| + // Create a block of memory with values: |
| + // start |
| + // start + increment |
| + // start + 2 * increment, ... |
| + // Since this is interleaved data, channel 0 data will be: |
| + // start |
| + // start + channels * increment |
| + // start + 2 * channels * increment, ... |
| + int buffer_size = frames * channels * sizeof(T); |
| + scoped_ptr<uint8[]> memory(new uint8[buffer_size]); |
| + uint8* data[] = { memory.get() }; |
| + T* buffer = reinterpret_cast<T*>(memory.get()); |
| + for (int i = 0; i < frames * channels; ++i) { |
| + buffer[i] = start; |
| + start += increment; |
| + } |
| + // Duration is 1 second per frame (for simplicity). |
| + base::TimeDelta duration = base::TimeDelta::FromSeconds(frames); |
| + return AudioBuffer::CopyFrom( |
| + format, channels, frames, data, start_time, duration); |
| +} |
| + |
| +template <class T> |
| +scoped_refptr<AudioBuffer> MakePlanarAudioBuffer( |
| + SampleFormat format, |
| + int channels, |
| + T start, |
| + T increment, |
| + int frames, |
| + const base::TimeDelta start_time) { |
| + DCHECK(format == kSampleFormatPlanarF32 || format == kSampleFormatPlanarS16); |
| + |
| + // Create multiple blocks of data, one for each channel. |
| + // Values in channel 0 will be: |
| + // start |
| + // start + increment |
| + // start + 2 * increment, ... |
| + // Values in channel 1 will be: |
| + // start + frames * increment |
| + // start + (frames + 1) * increment |
| + // start + (frames + 2) * increment, ... |
| + int buffer_size = frames * sizeof(T); |
| + scoped_ptr<uint8*[]> data(new uint8*[channels]); |
| + scoped_ptr<uint8[]> memory(new uint8[channels * buffer_size]); |
| + for (int i = 0; i < channels; ++i) { |
| + data.get()[i] = memory.get() + i * buffer_size; |
| + T* buffer = reinterpret_cast<T*>(data.get()[i]); |
| + for (int j = 0; j < frames; ++j) { |
| + buffer[j] = start; |
| + start += increment; |
| + } |
| + } |
| + // Duration is 1 second per frame (for simplicity). |
| + base::TimeDelta duration = base::TimeDelta::FromSeconds(frames); |
| + return AudioBuffer::CopyFrom( |
| + format, channels, frames, data.get(), start_time, duration); |
| +} |
| + |
| +// Instantiate all the types of MakeInterleavedAudioBuffer() and |
| +// MakePlanarAudioBuffer() needed. |
| +template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<uint8>( |
|
scherkus (not reviewing)
2013/06/20 23:36:24
if you want you can create a macro to cut down on
jrummell
2013/06/21 01:17:22
Done.
|
| + SampleFormat format, |
| + int channels, |
| + uint8 start, |
| + uint8 increment, |
| + int frames, |
| + const base::TimeDelta start_time); |
| + |
| +template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<int16>( |
| + SampleFormat format, |
| + int channels, |
| + int16 start, |
| + int16 increment, |
| + int frames, |
| + const base::TimeDelta start_time); |
| + |
| +template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<int32>( |
| + SampleFormat format, |
| + int channels, |
| + int32 start, |
| + int32 increment, |
| + int frames, |
| + const base::TimeDelta start_time); |
| + |
| +template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<float>( |
| + SampleFormat format, |
| + int channels, |
| + float start, |
| + float increment, |
| + int frames, |
| + const base::TimeDelta start_time); |
| + |
| +template scoped_refptr<AudioBuffer> MakePlanarAudioBuffer<int16>( |
| + SampleFormat format, |
| + int channels, |
| + int16 start, |
| + int16 increment, |
| + int frames, |
| + const base::TimeDelta start_time); |
| + |
| +template scoped_refptr<AudioBuffer> MakePlanarAudioBuffer<float>( |
| + SampleFormat format, |
| + int channels, |
| + float start, |
| + float increment, |
| + int frames, |
| + const base::TimeDelta start_time); |
| + |
| } // namespace media |