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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef MEDIA_BASE_TEST_HELPERS_H_ 5 #ifndef MEDIA_BASE_TEST_HELPERS_H_
6 #define MEDIA_BASE_TEST_HELPERS_H_ 6 #define MEDIA_BASE_TEST_HELPERS_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h"
11 #include "base/time.h"
12 #include "media/base/audio_buffer.h"
10 #include "media/base/pipeline_status.h" 13 #include "media/base/pipeline_status.h"
14 #include "media/base/sample_format.h"
11 #include "media/base/video_decoder_config.h" 15 #include "media/base/video_decoder_config.h"
12 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
13 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
14 18
15 namespace base { 19 namespace base {
16 class MessageLoop; 20 class MessageLoop;
17 } 21 }
18 22
19 namespace media { 23 namespace media {
20 24
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 static VideoDecoderConfig LargeEncrypted(); 76 static VideoDecoderConfig LargeEncrypted();
73 77
74 // Returns coded size for Normal and Large config. 78 // Returns coded size for Normal and Large config.
75 static gfx::Size NormalCodedSize(); 79 static gfx::Size NormalCodedSize();
76 static gfx::Size LargeCodedSize(); 80 static gfx::Size LargeCodedSize();
77 81
78 private: 82 private:
79 DISALLOW_IMPLICIT_CONSTRUCTORS(TestVideoConfig); 83 DISALLOW_IMPLICIT_CONSTRUCTORS(TestVideoConfig);
80 }; 84 };
81 85
86 template <class T>
87 scoped_refptr<AudioBuffer> MakeInterleavedAudioBuffer(
88 SampleFormat format,
89 int channels,
90 T start,
91 T increment,
92 int frames,
93 const base::TimeDelta start_time) {
94 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.
95 format == kSampleFormatS32 || format == kSampleFormatF32);
96
97 // Create a block of memory with values:
98 // start
99 // start + increment
100 // start + 2 * increment, ...
101 // Since this is interleaved data, channel 0 data will be:
102 // start
103 // start + channels * increment
104 // start + 2 * channels * increment, ...
105 int buffer_size = frames * channels * sizeof(T);
106 scoped_ptr<uint8[]> memory(new uint8[buffer_size]);
107 uint8* data[] = { memory.get() };
108 T* buffer = reinterpret_cast<T*>(memory.get());
109 for (int i = 0; i < frames * channels; ++i) {
110 buffer[i] = start;
111 start += increment;
112 }
113 // Duration is 1 second per frame (for simplicity).
114 base::TimeDelta duration = base::TimeDelta::FromSeconds(frames);
115 return AudioBuffer::CopyFrom(
116 format, channels, frames, data, start_time, duration);
117 }
118
119 template <class T>
120 scoped_refptr<AudioBuffer> MakePlanarAudioBuffer(
121 SampleFormat format,
122 int channels,
123 T start,
124 T increment,
125 int frames,
126 const base::TimeDelta start_time) {
127 DCHECK(format == kSampleFormatPlanarF32 || format == kSampleFormatPlanarS16);
128
129 // Create multiple blocks of data, one for each channel.
130 // Values in channel 0 will be:
131 // start
132 // start + increment
133 // start + 2 * increment, ...
134 // Values in channel 1 will be:
135 // start + frames * increment
136 // start + (frames + 1) * increment
137 // start + (frames + 2) * increment, ...
138 int buffer_size = frames * sizeof(T);
139 scoped_ptr<uint8*[]> data(new uint8*[channels]);
140 scoped_ptr<uint8[]> memory(new uint8[channels * buffer_size]);
141 for (int i = 0; i < channels; ++i) {
142 data.get()[i] = memory.get() + i * buffer_size;
143 T* buffer = reinterpret_cast<T*>(data.get()[i]);
144 for (int j = 0; j < frames; ++j) {
145 buffer[j] = start;
146 start += increment;
147 }
148 }
149 // Duration is 1 second per frame (for simplicity).
150 base::TimeDelta duration = base::TimeDelta::FromSeconds(frames);
151 return AudioBuffer::CopyFrom(
152 format, channels, frames, data.get(), start_time, duration);
153 }
154
82 } // namespace media 155 } // namespace media
83 156
84 #endif // MEDIA_BASE_TEST_HELPERS_H_ 157 #endif // MEDIA_BASE_TEST_HELPERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698