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

Unified Diff: media/base/test_helpers.h

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
Index: media/base/test_helpers.h
diff --git a/media/base/test_helpers.h b/media/base/test_helpers.h
index bc505d43a604f4368f2a29fe385f7eb2a0d4cc04..cdb86035714ef46c55b535ef0dc5eaa23b10146f 100644
--- a/media/base/test_helpers.h
+++ b/media/base/test_helpers.h
@@ -7,7 +7,11 @@
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/logging.h"
+#include "base/time.h"
+#include "media/base/audio_buffer.h"
#include "media/base/pipeline_status.h"
+#include "media/base/sample_format.h"
#include "media/base/video_decoder_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/gfx/size.h"
@@ -79,6 +83,75 @@ class TestVideoConfig {
DISALLOW_IMPLICIT_CONSTRUCTORS(TestVideoConfig);
};
+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 ||
scherkus (not reviewing) 2013/06/20 22:05:15 can you move the impl into the .cc and instantiate
jrummell 2013/06/20 23:28:58 Done.
+ 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);
+}
+
} // namespace media
#endif // MEDIA_BASE_TEST_HELPERS_H_

Powered by Google App Engine
This is Rietveld 408576698