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

Side by Side Diff: media/filters/fake_video_decoder.cc

Issue 1834303005: Refactor audio and video decoder status into common file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Created 4 years, 8 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
« no previous file with comments | « media/filters/fake_video_decoder.h ('k') | media/filters/fake_video_decoder_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 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/location.h" 7 #include "base/location.h"
8 #include "media/base/bind_to_current_loop.h" 8 #include "media/base/bind_to_current_loop.h"
9 #include "media/base/test_helpers.h" 9 #include "media/base/test_helpers.h"
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 max_parallel_decoding_requests_); 86 max_parallel_decoding_requests_);
87 DCHECK_NE(state_, STATE_END_OF_STREAM); 87 DCHECK_NE(state_, STATE_END_OF_STREAM);
88 88
89 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size(); 89 int buffer_size = buffer->end_of_stream() ? 0 : buffer->data_size();
90 DecodeCB wrapped_decode_cb = base::Bind(&FakeVideoDecoder::OnFrameDecoded, 90 DecodeCB wrapped_decode_cb = base::Bind(&FakeVideoDecoder::OnFrameDecoded,
91 weak_factory_.GetWeakPtr(), 91 weak_factory_.GetWeakPtr(),
92 buffer_size, 92 buffer_size,
93 BindToCurrentLoop(decode_cb)); 93 BindToCurrentLoop(decode_cb));
94 94
95 if (state_ == STATE_ERROR) { 95 if (state_ == STATE_ERROR) {
96 wrapped_decode_cb.Run(kDecodeError); 96 wrapped_decode_cb.Run(DecodeStatus::DECODE_ERROR);
97 return; 97 return;
98 } 98 }
99 99
100 if (buffer->end_of_stream()) { 100 if (buffer->end_of_stream()) {
101 state_ = STATE_END_OF_STREAM; 101 state_ = STATE_END_OF_STREAM;
102 } else { 102 } else {
103 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_)); 103 DCHECK(VerifyFakeVideoBufferForTest(buffer, current_config_));
104 scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateColorFrame( 104 scoped_refptr<VideoFrame> video_frame = VideoFrame::CreateColorFrame(
105 current_config_.coded_size(), 0, 0, 0, buffer->timestamp()); 105 current_config_.coded_size(), 0, 0, 0, buffer->timestamp());
106 decoded_frames_.push_back(video_frame); 106 decoded_frames_.push_back(video_frame);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 DCHECK(thread_checker_.CalledOnValidThread()); 173 DCHECK(thread_checker_.CalledOnValidThread());
174 DCHECK(held_decode_callbacks_.empty()); 174 DCHECK(held_decode_callbacks_.empty());
175 reset_cb_.RunHeldCallback(); 175 reset_cb_.RunHeldCallback();
176 } 176 }
177 177
178 void FakeVideoDecoder::SimulateError() { 178 void FakeVideoDecoder::SimulateError() {
179 DCHECK(thread_checker_.CalledOnValidThread()); 179 DCHECK(thread_checker_.CalledOnValidThread());
180 180
181 state_ = STATE_ERROR; 181 state_ = STATE_ERROR;
182 while (!held_decode_callbacks_.empty()) { 182 while (!held_decode_callbacks_.empty()) {
183 held_decode_callbacks_.front().Run(kDecodeError); 183 held_decode_callbacks_.front().Run(DecodeStatus::DECODE_ERROR);
184 held_decode_callbacks_.pop_front(); 184 held_decode_callbacks_.pop_front();
185 } 185 }
186 decoded_frames_.clear(); 186 decoded_frames_.clear();
187 } 187 }
188 188
189 void FakeVideoDecoder::SimulateFailureToInit() { 189 void FakeVideoDecoder::SimulateFailureToInit() {
190 fail_to_initialize_ = true; 190 fail_to_initialize_ = true;
191 } 191 }
192 192
193 int FakeVideoDecoder::GetMaxDecodeRequests() const { 193 int FakeVideoDecoder::GetMaxDecodeRequests() const {
194 return max_parallel_decoding_requests_; 194 return max_parallel_decoding_requests_;
195 } 195 }
196 196
197 void FakeVideoDecoder::OnFrameDecoded(int buffer_size, 197 void FakeVideoDecoder::OnFrameDecoded(int buffer_size,
198 const DecodeCB& decode_cb, 198 const DecodeCB& decode_cb,
199 Status status) { 199 DecodeStatus status) {
200 DCHECK(thread_checker_.CalledOnValidThread()); 200 DCHECK(thread_checker_.CalledOnValidThread());
201 201
202 if (status == kOk) { 202 if (status == DecodeStatus::OK) {
203 total_bytes_decoded_ += buffer_size; 203 total_bytes_decoded_ += buffer_size;
204 bytes_decoded_cb_.Run(buffer_size); 204 bytes_decoded_cb_.Run(buffer_size);
205 } 205 }
206 decode_cb.Run(status); 206 decode_cb.Run(status);
207 } 207 }
208 208
209 void FakeVideoDecoder::RunOrHoldDecode(const DecodeCB& decode_cb) { 209 void FakeVideoDecoder::RunOrHoldDecode(const DecodeCB& decode_cb) {
210 DCHECK(thread_checker_.CalledOnValidThread()); 210 DCHECK(thread_checker_.CalledOnValidThread());
211 211
212 if (hold_decode_) { 212 if (hold_decode_) {
213 held_decode_callbacks_.push_back(decode_cb); 213 held_decode_callbacks_.push_back(decode_cb);
214 } else { 214 } else {
215 DCHECK(held_decode_callbacks_.empty()); 215 DCHECK(held_decode_callbacks_.empty());
216 RunDecodeCallback(decode_cb); 216 RunDecodeCallback(decode_cb);
217 } 217 }
218 } 218 }
219 219
220 void FakeVideoDecoder::RunDecodeCallback(const DecodeCB& decode_cb) { 220 void FakeVideoDecoder::RunDecodeCallback(const DecodeCB& decode_cb) {
221 DCHECK(thread_checker_.CalledOnValidThread()); 221 DCHECK(thread_checker_.CalledOnValidThread());
222 222
223 if (!reset_cb_.IsNull()) { 223 if (!reset_cb_.IsNull()) {
224 DCHECK(decoded_frames_.empty()); 224 DCHECK(decoded_frames_.empty());
225 decode_cb.Run(kAborted); 225 decode_cb.Run(DecodeStatus::ABORTED);
226 return; 226 return;
227 } 227 }
228 228
229 // Make sure we leave decoding_delay_ frames in the queue and also frames for 229 // Make sure we leave decoding_delay_ frames in the queue and also frames for
230 // all pending decode callbacks, except the current one. 230 // all pending decode callbacks, except the current one.
231 if (decoded_frames_.size() > 231 if (decoded_frames_.size() >
232 decoding_delay_ + held_decode_callbacks_.size()) { 232 decoding_delay_ + held_decode_callbacks_.size()) {
233 output_cb_.Run(decoded_frames_.front()); 233 output_cb_.Run(decoded_frames_.front());
234 decoded_frames_.pop_front(); 234 decoded_frames_.pop_front();
235 } else if (state_ == STATE_END_OF_STREAM) { 235 } else if (state_ == STATE_END_OF_STREAM) {
236 // Drain the queue if this was the last request in the stream, otherwise 236 // Drain the queue if this was the last request in the stream, otherwise
237 // just pop the last frame from the queue. 237 // just pop the last frame from the queue.
238 if (held_decode_callbacks_.empty()) { 238 if (held_decode_callbacks_.empty()) {
239 while (!decoded_frames_.empty()) { 239 while (!decoded_frames_.empty()) {
240 output_cb_.Run(decoded_frames_.front()); 240 output_cb_.Run(decoded_frames_.front());
241 decoded_frames_.pop_front(); 241 decoded_frames_.pop_front();
242 } 242 }
243 state_ = STATE_NORMAL; 243 state_ = STATE_NORMAL;
244 } else if (!decoded_frames_.empty()) { 244 } else if (!decoded_frames_.empty()) {
245 output_cb_.Run(decoded_frames_.front()); 245 output_cb_.Run(decoded_frames_.front());
246 decoded_frames_.pop_front(); 246 decoded_frames_.pop_front();
247 } 247 }
248 } 248 }
249 249
250 decode_cb.Run(kOk); 250 decode_cb.Run(DecodeStatus::OK);
251 } 251 }
252 252
253 void FakeVideoDecoder::DoReset() { 253 void FakeVideoDecoder::DoReset() {
254 DCHECK(thread_checker_.CalledOnValidThread()); 254 DCHECK(thread_checker_.CalledOnValidThread());
255 DCHECK(held_decode_callbacks_.empty()); 255 DCHECK(held_decode_callbacks_.empty());
256 DCHECK(!reset_cb_.IsNull()); 256 DCHECK(!reset_cb_.IsNull());
257 257
258 reset_cb_.RunOrHold(); 258 reset_cb_.RunOrHold();
259 } 259 }
260 260
261 } // namespace media 261 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/fake_video_decoder.h ('k') | media/filters/fake_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698