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

Side by Side Diff: media/base/test_helpers.cc

Issue 261533002: Remove AudioBuffer::set_duration(), instead base on frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix divide by zero case. Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « media/base/test_helpers.h ('k') | media/filters/audio_renderer_algorithm_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "media/base/test_helpers.h" 5 #include "media/base/test_helpers.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return kNormalSize; 144 return kNormalSize;
145 } 145 }
146 146
147 gfx::Size TestVideoConfig::LargeCodedSize() { 147 gfx::Size TestVideoConfig::LargeCodedSize() {
148 return kLargeSize; 148 return kLargeSize;
149 } 149 }
150 150
151 template <class T> 151 template <class T>
152 scoped_refptr<AudioBuffer> MakeAudioBuffer(SampleFormat format, 152 scoped_refptr<AudioBuffer> MakeAudioBuffer(SampleFormat format,
153 ChannelLayout channel_layout, 153 ChannelLayout channel_layout,
154 int channel_count, 154 size_t channel_count,
155 int sample_rate, 155 int sample_rate,
156 T start, 156 T start,
157 T increment, 157 T increment,
158 int frames, 158 size_t frames,
159 base::TimeDelta timestamp, 159 base::TimeDelta timestamp) {
160 base::TimeDelta duration) { 160 const size_t channels = ChannelLayoutToChannelCount(channel_layout);
161 int channels = ChannelLayoutToChannelCount(channel_layout); 161 scoped_refptr<AudioBuffer> output =
162 scoped_refptr<AudioBuffer> output = AudioBuffer::CreateBuffer( 162 AudioBuffer::CreateBuffer(format,
163 format, channel_layout, channel_count, sample_rate, frames); 163 channel_layout,
164 static_cast<int>(channel_count),
165 sample_rate,
166 static_cast<int>(frames));
164 output->set_timestamp(timestamp); 167 output->set_timestamp(timestamp);
165 output->set_duration(duration);
166 168
167 // Create a block of memory with values: 169 const bool is_planar =
170 format == kSampleFormatPlanarS16 || format == kSampleFormatPlanarF32;
171
172 // Values in channel 0 will be:
168 // start 173 // start
169 // start + increment 174 // start + increment
170 // start + 2 * increment, ... 175 // start + 2 * increment, ...
171 // For interleaved data, raw data will be:
172 // start
173 // start + channels * increment
174 // start + 2 * channels * increment, ...
175 //
176 // For planar data, values in channel 0 will be:
177 // start
178 // start + increment
179 // start + 2 * increment, ...
180 // While, values in channel 1 will be: 176 // While, values in channel 1 will be:
181 // start + frames * increment 177 // start + frames * increment
182 // start + (frames + 1) * increment 178 // start + (frames + 1) * increment
183 // start + (frames + 2) * increment, ... 179 // start + (frames + 2) * increment, ...
184 const size_t output_size = 180 for (size_t ch = 0; ch < channels; ++ch) {
185 output->channel_data().size() == 1 ? frames * channels : frames; 181 T* buffer =
186 for (size_t ch = 0; ch < output->channel_data().size(); ++ch) { 182 reinterpret_cast<T*>(output->channel_data()[is_planar ? ch : 0]);
187 T* buffer = reinterpret_cast<T*>(output->channel_data()[ch]); 183 const T v = static_cast<T>(start + ch * frames * increment);
188 const T v = static_cast<T>(start + ch * output_size * increment); 184 for (size_t i = 0; i < frames; ++i) {
189 for (size_t i = 0; i < output_size; ++i) { 185 buffer[is_planar ? i : ch + i * channels] =
190 buffer[i] = static_cast<T>(v + i * increment); 186 static_cast<T>(v + i * increment);
191 } 187 }
192 } 188 }
193 return output; 189 return output;
194 } 190 }
195 191
196 // Instantiate all the types of MakeAudioBuffer() and 192 // Instantiate all the types of MakeAudioBuffer() and
197 // MakeAudioBuffer() needed. 193 // MakeAudioBuffer() needed.
198 #define DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(type) \ 194 #define DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(type) \
199 template scoped_refptr<AudioBuffer> MakeAudioBuffer<type>( \ 195 template scoped_refptr<AudioBuffer> MakeAudioBuffer<type>( \
200 SampleFormat format, \ 196 SampleFormat format, \
201 ChannelLayout channel_layout, \ 197 ChannelLayout channel_layout, \
202 int channel_count, \ 198 size_t channel_count, \
203 int sample_rate, \ 199 int sample_rate, \
204 type start, \ 200 type start, \
205 type increment, \ 201 type increment, \
206 int frames, \ 202 size_t frames, \
207 base::TimeDelta start_time, \ 203 base::TimeDelta start_time)
208 base::TimeDelta duration)
209 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(uint8); 204 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(uint8);
210 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int16); 205 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int16);
211 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int32); 206 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int32);
212 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(float); 207 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(float);
213 208
214 static const char kFakeVideoBufferHeader[] = "FakeVideoBufferForTest"; 209 static const char kFakeVideoBufferHeader[] = "FakeVideoBufferForTest";
215 210
216 scoped_refptr<DecoderBuffer> CreateFakeVideoBufferForTest( 211 scoped_refptr<DecoderBuffer> CreateFakeVideoBufferForTest(
217 const VideoDecoderConfig& config, 212 const VideoDecoderConfig& config,
218 base::TimeDelta timestamp, base::TimeDelta duration) { 213 base::TimeDelta timestamp, base::TimeDelta duration) {
(...skipping 22 matching lines...) Expand all
241 int width = 0; 236 int width = 0;
242 int height = 0; 237 int height = 0;
243 bool success = pickle.ReadString(&header) && pickle.ReadInt(&width) && 238 bool success = pickle.ReadString(&header) && pickle.ReadInt(&width) &&
244 pickle.ReadInt(&height); 239 pickle.ReadInt(&height);
245 return (success && header == kFakeVideoBufferHeader && 240 return (success && header == kFakeVideoBufferHeader &&
246 width == config.coded_size().width() && 241 width == config.coded_size().width() &&
247 height == config.coded_size().height()); 242 height == config.coded_size().height());
248 } 243 }
249 244
250 } // namespace media 245 } // namespace media
OLDNEW
« no previous file with comments | « media/base/test_helpers.h ('k') | media/filters/audio_renderer_algorithm_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698