| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/filters/fake_demuxer_stream.h" | 5 #include "media/filters/fake_demuxer_stream.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/pickle.h" | |
| 13 #include "media/base/bind_to_loop.h" | 12 #include "media/base/bind_to_loop.h" |
| 14 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
| 14 #include "media/base/test_helpers.h" |
| 15 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
| 16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 | 20 |
| 21 static const int kStartTimestampMs = 0; | 21 static const int kStartTimestampMs = 0; |
| 22 static const int kDurationMs = 30; | 22 static const int kDurationMs = 30; |
| 23 static const int kStartWidth = 320; | 23 static const int kStartWidth = 320; |
| 24 static const int kStartHeight = 240; | 24 static const int kStartHeight = 240; |
| 25 static const int kWidthDelta = 4; | 25 static const int kWidthDelta = 4; |
| 26 static const int kHeightDelta = 3; | 26 static const int kHeightDelta = 3; |
| 27 static const char kFakeBufferHeader[] = "Fake Buffer"; | |
| 28 | 27 |
| 29 FakeDemuxerStream::FakeDemuxerStream(int num_configs, | 28 FakeDemuxerStream::FakeDemuxerStream(int num_configs, |
| 30 int num_buffers_in_one_config, | 29 int num_buffers_in_one_config, |
| 31 bool is_encrypted) | 30 bool is_encrypted) |
| 32 : message_loop_(base::MessageLoopProxy::current()), | 31 : message_loop_(base::MessageLoopProxy::current()), |
| 33 num_configs_left_(num_configs), | 32 num_configs_left_(num_configs), |
| 34 num_buffers_in_one_config_(num_buffers_in_one_config), | 33 num_buffers_in_one_config_(num_buffers_in_one_config), |
| 35 is_encrypted_(is_encrypted), | 34 is_encrypted_(is_encrypted), |
| 36 num_buffers_left_in_current_config_(num_buffers_in_one_config), | 35 num_buffers_left_in_current_config_(num_buffers_in_one_config), |
| 37 num_buffers_returned_(0), | 36 num_buffers_returned_(0), |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 return; | 131 return; |
| 133 } | 132 } |
| 134 | 133 |
| 135 // Config change. | 134 // Config change. |
| 136 num_buffers_left_in_current_config_ = num_buffers_in_one_config_; | 135 num_buffers_left_in_current_config_ = num_buffers_in_one_config_; |
| 137 UpdateVideoDecoderConfig(); | 136 UpdateVideoDecoderConfig(); |
| 138 base::ResetAndReturn(&read_cb_).Run(kConfigChanged, NULL); | 137 base::ResetAndReturn(&read_cb_).Run(kConfigChanged, NULL); |
| 139 return; | 138 return; |
| 140 } | 139 } |
| 141 | 140 |
| 142 // Prepare the next buffer. | 141 scoped_refptr<DecoderBuffer> buffer = CreateFakeVideoBufferForTest( |
| 143 Pickle pickle; | 142 video_decoder_config_, current_timestamp_, duration_); |
| 144 pickle.WriteString(kFakeBufferHeader); | |
| 145 pickle.WriteInt(video_decoder_config_.coded_size().width()); | |
| 146 pickle.WriteInt(video_decoder_config_.coded_size().height()); | |
| 147 pickle.WriteInt64(current_timestamp_.InMilliseconds()); | |
| 148 | |
| 149 scoped_refptr<DecoderBuffer> buffer = DecoderBuffer::CopyFrom( | |
| 150 static_cast<const uint8*>(pickle.data()), pickle.size()); | |
| 151 | 143 |
| 152 // TODO(xhwang): Output out-of-order buffers if needed. | 144 // TODO(xhwang): Output out-of-order buffers if needed. |
| 153 buffer->SetTimestamp(current_timestamp_); | |
| 154 buffer->SetDuration(duration_); | |
| 155 current_timestamp_ += duration_; | 145 current_timestamp_ += duration_; |
| 156 | 146 |
| 157 num_buffers_left_in_current_config_--; | 147 num_buffers_left_in_current_config_--; |
| 158 if (num_buffers_left_in_current_config_ == 0) | 148 if (num_buffers_left_in_current_config_ == 0) |
| 159 num_configs_left_--; | 149 num_configs_left_--; |
| 160 | 150 |
| 161 num_buffers_returned_++; | 151 num_buffers_returned_++; |
| 162 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); | 152 base::ResetAndReturn(&read_cb_).Run(kOk, buffer); |
| 163 } | 153 } |
| 164 | 154 |
| 165 } // namespace media | 155 } // namespace media |
| OLD | NEW |