Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_video_decoder.h" | 5 #include "media/filters/fake_video_decoder.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/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| 11 #include "media/base/bind_to_current_loop.h" | 11 #include "media/base/bind_to_current_loop.h" |
| 12 #include "media/base/test_helpers.h" | 12 #include "media/base/test_helpers.h" |
| 13 | 13 |
| 14 namespace media { | 14 namespace media { |
| 15 | 15 |
| 16 FakeVideoDecoder::FakeVideoDecoder(int decoding_delay) | 16 FakeVideoDecoder::FakeVideoDecoder(int decoding_delay) |
| 17 : task_runner_(base::MessageLoopProxy::current()), | 17 : task_runner_(base::MessageLoopProxy::current()), |
| 18 weak_factory_(this), | 18 weak_factory_(this), |
| 19 decoding_delay_(decoding_delay), | 19 decoding_delay_(decoding_delay), |
| 20 state_(UNINITIALIZED), | 20 state_(UNINITIALIZED), |
| 21 total_bytes_decoded_(0) { | 21 total_bytes_decoded_(0), |
| 22 reads_queued_(0) { | |
| 22 DCHECK_GE(decoding_delay, 0); | 23 DCHECK_GE(decoding_delay, 0); |
| 23 } | 24 } |
| 24 | 25 |
| 25 FakeVideoDecoder::~FakeVideoDecoder() { | 26 FakeVideoDecoder::~FakeVideoDecoder() { |
| 26 DCHECK_EQ(state_, UNINITIALIZED); | 27 DCHECK_EQ(state_, UNINITIALIZED); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config, | 30 void FakeVideoDecoder::Initialize(const VideoDecoderConfig& config, |
| 30 const PipelineStatusCB& status_cb) { | 31 const PipelineStatusCB& status_cb) { |
| 31 DCHECK(task_runner_->BelongsToCurrentThread()); | 32 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 DCHECK(task_runner_->BelongsToCurrentThread()); | 97 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 97 stop_cb_.SetCallback(BindToCurrentLoop(closure)); | 98 stop_cb_.SetCallback(BindToCurrentLoop(closure)); |
| 98 | 99 |
| 99 // Defer the stop if an init, a decode or a reset is pending. | 100 // Defer the stop if an init, a decode or a reset is pending. |
| 100 if (!init_cb_.IsNull() || !decode_cb_.IsNull() || !reset_cb_.IsNull()) | 101 if (!init_cb_.IsNull() || !decode_cb_.IsNull() || !reset_cb_.IsNull()) |
| 101 return; | 102 return; |
| 102 | 103 |
| 103 DoStop(); | 104 DoStop(); |
| 104 } | 105 } |
| 105 | 106 |
| 107 scoped_refptr<VideoFrame> FakeVideoDecoder::GetDecodeOutput() { | |
| 108 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 109 if (!reads_queued_) { | |
| 110 return NULL; | |
| 111 } | |
|
xhwang
2014/03/06 23:32:40
nit: no need for braces.
| |
| 112 --reads_queued_; | |
| 113 return VideoFrame::CreateEOSFrame(); | |
|
xhwang
2014/03/06 23:32:40
This isn't quite right. Even though this decoder i
| |
| 114 } | |
| 115 | |
| 116 void FakeVideoDecoder::QueueRead() { | |
| 117 ++reads_queued_; | |
| 118 } | |
| 119 | |
| 106 void FakeVideoDecoder::HoldNextInit() { | 120 void FakeVideoDecoder::HoldNextInit() { |
| 107 DCHECK(task_runner_->BelongsToCurrentThread()); | 121 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 108 init_cb_.HoldCallback(); | 122 init_cb_.HoldCallback(); |
| 109 } | 123 } |
| 110 | 124 |
| 111 void FakeVideoDecoder::HoldNextRead() { | 125 void FakeVideoDecoder::HoldNextRead() { |
| 112 DCHECK(task_runner_->BelongsToCurrentThread()); | 126 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 113 decode_cb_.HoldCallback(); | 127 decode_cb_.HoldCallback(); |
| 114 } | 128 } |
| 115 | 129 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 int buffer_size, | 199 int buffer_size, |
| 186 const DecodeCB& decode_cb, | 200 const DecodeCB& decode_cb, |
| 187 Status status, | 201 Status status, |
| 188 const scoped_refptr<VideoFrame>& video_frame) { | 202 const scoped_refptr<VideoFrame>& video_frame) { |
| 189 if (status == kOk || status == kNotEnoughData) | 203 if (status == kOk || status == kNotEnoughData) |
| 190 total_bytes_decoded_ += buffer_size; | 204 total_bytes_decoded_ += buffer_size; |
| 191 decode_cb.Run(status, video_frame); | 205 decode_cb.Run(status, video_frame); |
| 192 } | 206 } |
| 193 | 207 |
| 194 } // namespace media | 208 } // namespace media |
| OLD | NEW |