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/filters/decrypting_video_decoder.h" | 5 #include "media/filters/decrypting_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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 const SetDecryptorReadyCB& set_decryptor_ready_cb) | 24 const SetDecryptorReadyCB& set_decryptor_ready_cb) |
25 : task_runner_(task_runner), | 25 : task_runner_(task_runner), |
26 state_(kUninitialized), | 26 state_(kUninitialized), |
27 set_decryptor_ready_cb_(set_decryptor_ready_cb), | 27 set_decryptor_ready_cb_(set_decryptor_ready_cb), |
28 decryptor_(NULL), | 28 decryptor_(NULL), |
29 key_added_while_decode_pending_(false), | 29 key_added_while_decode_pending_(false), |
30 trace_id_(0), | 30 trace_id_(0), |
31 weak_factory_(this) {} | 31 weak_factory_(this) {} |
32 | 32 |
33 void DecryptingVideoDecoder::Initialize(const VideoDecoderConfig& config, | 33 void DecryptingVideoDecoder::Initialize(const VideoDecoderConfig& config, |
34 bool /* live_mode */, | 34 bool /* low_delay */, |
35 const PipelineStatusCB& status_cb, | 35 const PipelineStatusCB& status_cb, |
36 const OutputCB& output_cb) { | 36 const OutputCB& output_cb) { |
37 DVLOG(2) << "Initialize()"; | 37 DVLOG(2) << "Initialize()"; |
38 DCHECK(task_runner_->BelongsToCurrentThread()); | 38 DCHECK(task_runner_->BelongsToCurrentThread()); |
39 DCHECK(state_ == kUninitialized || | 39 DCHECK(state_ == kUninitialized || |
40 state_ == kIdle || | 40 state_ == kIdle || |
41 state_ == kDecodeFinished) << state_; | 41 state_ == kDecodeFinished) << state_; |
42 DCHECK(decode_cb_.is_null()); | 42 DCHECK(decode_cb_.is_null()); |
43 DCHECK(reset_cb_.is_null()); | 43 DCHECK(reset_cb_.is_null()); |
44 DCHECK(config.IsValidConfig()); | 44 DCHECK(config.IsValidConfig()); |
(...skipping 30 matching lines...) Expand all Loading... |
75 | 75 |
76 decode_cb_ = BindToCurrentLoop(decode_cb); | 76 decode_cb_ = BindToCurrentLoop(decode_cb); |
77 | 77 |
78 if (state_ == kError) { | 78 if (state_ == kError) { |
79 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); | 79 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); |
80 return; | 80 return; |
81 } | 81 } |
82 | 82 |
83 // Return empty frames if decoding has finished. | 83 // Return empty frames if decoding has finished. |
84 if (state_ == kDecodeFinished) { | 84 if (state_ == kDecodeFinished) { |
85 output_cb_.Run(VideoFrame::CreateEOSFrame()); | |
86 base::ResetAndReturn(&decode_cb_).Run(kOk); | 85 base::ResetAndReturn(&decode_cb_).Run(kOk); |
87 return; | 86 return; |
88 } | 87 } |
89 | 88 |
90 pending_buffer_to_decode_ = buffer; | 89 pending_buffer_to_decode_ = buffer; |
91 state_ = kPendingDecode; | 90 state_ = kPendingDecode; |
92 DecodePendingBuffer(); | 91 DecodePendingBuffer(); |
93 } | 92 } |
94 | 93 |
95 void DecryptingVideoDecoder::Reset(const base::Closure& closure) { | 94 void DecryptingVideoDecoder::Reset(const base::Closure& closure) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 DecodePendingBuffer(); | 269 DecodePendingBuffer(); |
271 return; | 270 return; |
272 } | 271 } |
273 | 272 |
274 state_ = kWaitingForKey; | 273 state_ = kWaitingForKey; |
275 return; | 274 return; |
276 } | 275 } |
277 | 276 |
278 if (status == Decryptor::kNeedMoreData) { | 277 if (status == Decryptor::kNeedMoreData) { |
279 DVLOG(2) << "DeliverFrame() - kNeedMoreData"; | 278 DVLOG(2) << "DeliverFrame() - kNeedMoreData"; |
280 if (scoped_pending_buffer_to_decode->end_of_stream()) { | 279 state_ = scoped_pending_buffer_to_decode->end_of_stream() ? kDecodeFinished |
281 state_ = kDecodeFinished; | 280 : kIdle; |
282 output_cb_.Run(media::VideoFrame::CreateEOSFrame()); | |
283 } else { | |
284 state_ = kIdle; | |
285 } | |
286 base::ResetAndReturn(&decode_cb_).Run(kOk); | 281 base::ResetAndReturn(&decode_cb_).Run(kOk); |
287 return; | 282 return; |
288 } | 283 } |
289 | 284 |
290 DCHECK_EQ(status, Decryptor::kSuccess); | 285 DCHECK_EQ(status, Decryptor::kSuccess); |
291 // No frame returned with kSuccess should be end-of-stream frame. | 286 // No frame returned with kSuccess should be end-of-stream frame. |
292 DCHECK(!frame->end_of_stream()); | 287 DCHECK(!frame->end_of_stream()); |
293 output_cb_.Run(frame); | 288 output_cb_.Run(frame); |
294 | 289 |
295 if (scoped_pending_buffer_to_decode->end_of_stream()) { | 290 if (scoped_pending_buffer_to_decode->end_of_stream()) { |
(...skipping 24 matching lines...) Expand all Loading... |
320 } | 315 } |
321 | 316 |
322 void DecryptingVideoDecoder::DoReset() { | 317 void DecryptingVideoDecoder::DoReset() { |
323 DCHECK(init_cb_.is_null()); | 318 DCHECK(init_cb_.is_null()); |
324 DCHECK(decode_cb_.is_null()); | 319 DCHECK(decode_cb_.is_null()); |
325 state_ = kIdle; | 320 state_ = kIdle; |
326 base::ResetAndReturn(&reset_cb_).Run(); | 321 base::ResetAndReturn(&reset_cb_).Run(); |
327 } | 322 } |
328 | 323 |
329 } // namespace media | 324 } // namespace media |
OLD | NEW |