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

Unified Diff: media/base/test_helpers.cc

Issue 17112016: Add new class AudioBufferQueue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/test_helpers.h ('k') | media/media.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/test_helpers.cc
diff --git a/media/base/test_helpers.cc b/media/base/test_helpers.cc
index 2c71865e6ec5cff0679e99ef9aded1f513f861b5..368774b3925f88c6014724fea413a1fd6fb5fea2 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,100 @@ gfx::Size TestVideoConfig::LargeCodedSize() {
return kLargeSize;
}
+template <class T>
+scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer(
+ SampleFormat format,
+ int channels,
+ T start,
+ T increment,
+ int frames,
+ 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,
+ 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.
+
+#define DEFINE_INTERLEAVED_INSTANCE(type) \
+ template scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer<type>( \
+ SampleFormat format, \
+ int channels, \
+ type start, \
+ type increment, \
+ int frames, \
+ base::TimeDelta start_time)
+DEFINE_INTERLEAVED_INSTANCE(uint8);
+DEFINE_INTERLEAVED_INSTANCE(int16);
+DEFINE_INTERLEAVED_INSTANCE(int32);
+DEFINE_INTERLEAVED_INSTANCE(float);
+
+#define DEFINE_PLANAR_INSTANCE(type) \
+ template scoped_refptr<AudioBuffer> MakePlanarAudioBuffer<type>( \
+ SampleFormat format, \
+ int channels, \
+ type start, \
+ type increment, \
+ int frames, \
+ base::TimeDelta start_time);
+DEFINE_PLANAR_INSTANCE(int16);
+DEFINE_PLANAR_INSTANCE(float);
+
} // namespace media
« no previous file with comments | « media/base/test_helpers.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698