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 21 matching lines...) Expand all Loading... |
32 key_added_while_decode_pending_(false), | 32 key_added_while_decode_pending_(false), |
33 trace_id_(0) { | 33 trace_id_(0) { |
34 } | 34 } |
35 | 35 |
36 void DecryptingVideoDecoder::Initialize( | 36 void DecryptingVideoDecoder::Initialize( |
37 DemuxerStream* stream, | 37 DemuxerStream* stream, |
38 const PipelineStatusCB& status_cb, | 38 const PipelineStatusCB& status_cb, |
39 const StatisticsCB& statistics_cb) { | 39 const StatisticsCB& statistics_cb) { |
40 DVLOG(2) << "Initialize()"; | 40 DVLOG(2) << "Initialize()"; |
41 DCHECK(message_loop_->BelongsToCurrentThread()); | 41 DCHECK(message_loop_->BelongsToCurrentThread()); |
42 DCHECK_EQ(state_, kUninitialized) << state_; | 42 DCHECK(state_ == kUninitialized || |
| 43 state_ == kIdle || |
| 44 state_ == kDecodeFinished) << state_; |
| 45 DCHECK(read_cb_.is_null()); |
| 46 DCHECK(reset_cb_.is_null()); |
43 DCHECK(stream); | 47 DCHECK(stream); |
| 48 |
44 init_cb_ = BindToCurrentLoop(status_cb); | 49 init_cb_ = BindToCurrentLoop(status_cb); |
45 weak_this_ = weak_factory_.GetWeakPtr(); | 50 weak_this_ = weak_factory_.GetWeakPtr(); |
| 51 demuxer_stream_ = stream; |
| 52 statistics_cb_ = statistics_cb; |
46 | 53 |
47 const VideoDecoderConfig& config = stream->video_decoder_config(); | 54 const VideoDecoderConfig& config = demuxer_stream_->video_decoder_config(); |
48 if (!config.IsValidConfig()) { | 55 DCHECK(config.IsValidConfig() && config.is_encrypted()); |
49 DLOG(ERROR) << "Invalid video stream config: " | 56 |
50 << config.AsHumanReadableString(); | 57 if (state_ == kUninitialized) { |
51 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_DECODE); | 58 state_ = kDecryptorRequested; |
| 59 set_decryptor_ready_cb_.Run(BindToCurrentLoop(base::Bind( |
| 60 &DecryptingVideoDecoder::SetDecryptor, weak_this_))); |
52 return; | 61 return; |
53 } | 62 } |
54 | 63 |
55 // DecryptingVideoDecoder only accepts potentially encrypted stream. | 64 // Reinitialization. |
56 if (!config.is_encrypted()) { | 65 decryptor_->DeinitializeDecoder(Decryptor::kVideo); |
57 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 66 state_ = kPendingDecoderInit; |
58 return; | 67 decryptor_->InitializeVideoDecoder(config, BindToCurrentLoop(base::Bind( |
59 } | 68 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); |
60 | |
61 DCHECK(!demuxer_stream_); | |
62 demuxer_stream_ = stream; | |
63 statistics_cb_ = statistics_cb; | |
64 | |
65 state_ = kDecryptorRequested; | |
66 set_decryptor_ready_cb_.Run(BindToCurrentLoop(base::Bind( | |
67 &DecryptingVideoDecoder::SetDecryptor, weak_this_))); | |
68 } | 69 } |
69 | 70 |
70 void DecryptingVideoDecoder::Read(const ReadCB& read_cb) { | 71 void DecryptingVideoDecoder::Read(const ReadCB& read_cb) { |
71 DVLOG(3) << "Read()"; | 72 DVLOG(3) << "Read()"; |
72 DCHECK(message_loop_->BelongsToCurrentThread()); | 73 DCHECK(message_loop_->BelongsToCurrentThread()); |
73 DCHECK(state_ == kIdle || | 74 DCHECK(state_ == kIdle || |
74 state_ == kDecodeFinished || | 75 state_ == kDecodeFinished || |
75 state_ == kError) << state_; | 76 state_ == kError) << state_; |
76 DCHECK(!read_cb.is_null()); | 77 DCHECK(!read_cb.is_null()); |
77 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; | 78 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 402 } |
402 | 403 |
403 void DecryptingVideoDecoder::DoReset() { | 404 void DecryptingVideoDecoder::DoReset() { |
404 DCHECK(init_cb_.is_null()); | 405 DCHECK(init_cb_.is_null()); |
405 DCHECK(read_cb_.is_null()); | 406 DCHECK(read_cb_.is_null()); |
406 state_ = kIdle; | 407 state_ = kIdle; |
407 base::ResetAndReturn(&reset_cb_).Run(); | 408 base::ResetAndReturn(&reset_cb_).Run(); |
408 } | 409 } |
409 | 410 |
410 } // namespace media | 411 } // namespace media |
OLD | NEW |