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

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

Issue 265943002: Revert of Remove AudioBuffer::set_duration(), instead base on frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 size_t channel_count, 154 int channel_count,
155 int sample_rate, 155 int sample_rate,
156 T start, 156 T start,
157 T increment, 157 T increment,
158 size_t frames, 158 int frames,
159 base::TimeDelta timestamp) { 159 base::TimeDelta timestamp,
160 const size_t channels = ChannelLayoutToChannelCount(channel_layout); 160 base::TimeDelta duration) {
161 scoped_refptr<AudioBuffer> output = 161 int channels = ChannelLayoutToChannelCount(channel_layout);
162 AudioBuffer::CreateBuffer(format, 162 scoped_refptr<AudioBuffer> output = AudioBuffer::CreateBuffer(
163 channel_layout, 163 format, channel_layout, channel_count, sample_rate, frames);
164 static_cast<int>(channel_count),
165 sample_rate,
166 static_cast<int>(frames));
167 output->set_timestamp(timestamp); 164 output->set_timestamp(timestamp);
165 output->set_duration(duration);
168 166
169 const bool is_planar = 167 // Create a block of memory with values:
170 format == kSampleFormatPlanarS16 || format == kSampleFormatPlanarF32;
171
172 // Values in channel 0 will be:
173 // start 168 // start
174 // start + increment 169 // start + increment
175 // start + 2 * increment, ... 170 // 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, ...
176 // While, values in channel 1 will be: 180 // While, values in channel 1 will be:
177 // start + frames * increment 181 // start + frames * increment
178 // start + (frames + 1) * increment 182 // start + (frames + 1) * increment
179 // start + (frames + 2) * increment, ... 183 // start + (frames + 2) * increment, ...
180 for (size_t ch = 0; ch < channels; ++ch) { 184 const size_t output_size =
181 T* buffer = 185 output->channel_data().size() == 1 ? frames * channels : frames;
182 reinterpret_cast<T*>(output->channel_data()[is_planar ? ch : 0]); 186 for (size_t ch = 0; ch < output->channel_data().size(); ++ch) {
183 const T v = static_cast<T>(start + ch * frames * increment); 187 T* buffer = reinterpret_cast<T*>(output->channel_data()[ch]);
184 for (size_t i = 0; i < frames; ++i) { 188 const T v = static_cast<T>(start + ch * output_size * increment);
185 buffer[is_planar ? i : ch + i * channels] = 189 for (size_t i = 0; i < output_size; ++i) {
186 static_cast<T>(v + i * increment); 190 buffer[i] = static_cast<T>(v + i * increment);
187 } 191 }
188 } 192 }
189 return output; 193 return output;
190 } 194 }
191 195
192 // Instantiate all the types of MakeAudioBuffer() and 196 // Instantiate all the types of MakeAudioBuffer() and
193 // MakeAudioBuffer() needed. 197 // MakeAudioBuffer() needed.
194 #define DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(type) \ 198 #define DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(type) \
195 template scoped_refptr<AudioBuffer> MakeAudioBuffer<type>( \ 199 template scoped_refptr<AudioBuffer> MakeAudioBuffer<type>( \
196 SampleFormat format, \ 200 SampleFormat format, \
197 ChannelLayout channel_layout, \ 201 ChannelLayout channel_layout, \
198 size_t channel_count, \ 202 int channel_count, \
199 int sample_rate, \ 203 int sample_rate, \
200 type start, \ 204 type start, \
201 type increment, \ 205 type increment, \
202 size_t frames, \ 206 int frames, \
203 base::TimeDelta start_time) 207 base::TimeDelta start_time, \
208 base::TimeDelta duration)
204 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(uint8); 209 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(uint8);
205 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int16); 210 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int16);
206 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int32); 211 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(int32);
207 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(float); 212 DEFINE_MAKE_AUDIO_BUFFER_INSTANCE(float);
208 213
209 static const char kFakeVideoBufferHeader[] = "FakeVideoBufferForTest"; 214 static const char kFakeVideoBufferHeader[] = "FakeVideoBufferForTest";
210 215
211 scoped_refptr<DecoderBuffer> CreateFakeVideoBufferForTest( 216 scoped_refptr<DecoderBuffer> CreateFakeVideoBufferForTest(
212 const VideoDecoderConfig& config, 217 const VideoDecoderConfig& config,
213 base::TimeDelta timestamp, base::TimeDelta duration) { 218 base::TimeDelta timestamp, base::TimeDelta duration) {
(...skipping 22 matching lines...) Expand all
236 int width = 0; 241 int width = 0;
237 int height = 0; 242 int height = 0;
238 bool success = pickle.ReadString(&header) && pickle.ReadInt(&width) && 243 bool success = pickle.ReadString(&header) && pickle.ReadInt(&width) &&
239 pickle.ReadInt(&height); 244 pickle.ReadInt(&height);
240 return (success && header == kFakeVideoBufferHeader && 245 return (success && header == kFakeVideoBufferHeader &&
241 width == config.coded_size().width() && 246 width == config.coded_size().width() &&
242 height == config.coded_size().height()); 247 height == config.coded_size().height());
243 } 248 }
244 249
245 } // namespace media 250 } // 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