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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/pickle.h" |
10 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
13 #include "media/base/audio_buffer.h" | 14 #include "media/base/audio_buffer.h" |
14 #include "media/base/bind_to_loop.h" | 15 #include "media/base/bind_to_loop.h" |
| 16 #include "media/base/decoder_buffer.h" |
15 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
16 | 18 |
17 using ::testing::_; | 19 using ::testing::_; |
18 using ::testing::StrictMock; | 20 using ::testing::StrictMock; |
19 | 21 |
20 namespace media { | 22 namespace media { |
21 | 23 |
22 // Utility mock for testing methods expecting Closures and PipelineStatusCBs. | 24 // Utility mock for testing methods expecting Closures and PipelineStatusCBs. |
23 class MockCallback : public base::RefCountedThreadSafe<MockCallback> { | 25 class MockCallback : public base::RefCountedThreadSafe<MockCallback> { |
24 public: | 26 public: |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 template scoped_refptr<AudioBuffer> MakePlanarAudioBuffer<type>( \ | 237 template scoped_refptr<AudioBuffer> MakePlanarAudioBuffer<type>( \ |
236 SampleFormat format, \ | 238 SampleFormat format, \ |
237 int channels, \ | 239 int channels, \ |
238 type start, \ | 240 type start, \ |
239 type increment, \ | 241 type increment, \ |
240 int frames, \ | 242 int frames, \ |
241 base::TimeDelta start_time); | 243 base::TimeDelta start_time); |
242 DEFINE_PLANAR_INSTANCE(int16); | 244 DEFINE_PLANAR_INSTANCE(int16); |
243 DEFINE_PLANAR_INSTANCE(float); | 245 DEFINE_PLANAR_INSTANCE(float); |
244 | 246 |
| 247 static const char kFakeVideoBufferHeader[] = "FakeVideoBufferForTest"; |
| 248 |
| 249 scoped_refptr<DecoderBuffer> CreateFakeVideoBufferForTest( |
| 250 const VideoDecoderConfig& config, |
| 251 base::TimeDelta timestamp, base::TimeDelta duration) { |
| 252 Pickle pickle; |
| 253 pickle.WriteString(kFakeVideoBufferHeader); |
| 254 pickle.WriteInt(config.coded_size().width()); |
| 255 pickle.WriteInt(config.coded_size().height()); |
| 256 pickle.WriteInt64(timestamp.InMilliseconds()); |
| 257 |
| 258 scoped_refptr<DecoderBuffer> buffer = DecoderBuffer::CopyFrom( |
| 259 static_cast<const uint8*>(pickle.data()), |
| 260 static_cast<int>(pickle.size())); |
| 261 buffer->SetTimestamp(timestamp); |
| 262 buffer->SetDuration(duration); |
| 263 |
| 264 return buffer; |
| 265 } |
| 266 |
| 267 bool VerifyFakeVideoBufferForTest( |
| 268 const scoped_refptr<DecoderBuffer>& buffer, |
| 269 const VideoDecoderConfig& config) { |
| 270 // Check if the input |buffer| matches the |config|. |
| 271 PickleIterator pickle(Pickle(reinterpret_cast<const char*>(buffer->GetData()), |
| 272 buffer->GetDataSize())); |
| 273 std::string header; |
| 274 int width = 0; |
| 275 int height = 0; |
| 276 bool success = pickle.ReadString(&header) && pickle.ReadInt(&width) && |
| 277 pickle.ReadInt(&height); |
| 278 return (success && header == kFakeVideoBufferHeader && |
| 279 width == config.coded_size().width() && |
| 280 height == config.coded_size().height()); |
| 281 } |
| 282 |
245 } // namespace media | 283 } // namespace media |
OLD | NEW |