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