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_demuxer_stream.h" | 5 #include "media/filters/decrypting_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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 const SetDecryptorReadyCB& set_decryptor_ready_cb) | 36 const SetDecryptorReadyCB& set_decryptor_ready_cb) |
37 : message_loop_(message_loop), | 37 : message_loop_(message_loop), |
38 weak_factory_(this), | 38 weak_factory_(this), |
39 state_(kUninitialized), | 39 state_(kUninitialized), |
40 demuxer_stream_(NULL), | 40 demuxer_stream_(NULL), |
41 set_decryptor_ready_cb_(set_decryptor_ready_cb), | 41 set_decryptor_ready_cb_(set_decryptor_ready_cb), |
42 decryptor_(NULL), | 42 decryptor_(NULL), |
43 key_added_while_decrypt_pending_(false) { | 43 key_added_while_decrypt_pending_(false) { |
44 } | 44 } |
45 | 45 |
46 void DecryptingDemuxerStream::Initialize( | 46 void DecryptingDemuxerStream::Initialize(DemuxerStream* stream, |
47 DemuxerStream* stream, | 47 const PipelineStatusCB& status_cb) { |
48 const PipelineStatusCB& status_cb) { | 48 DVLOG(2) << __FUNCTION__; |
49 DVLOG(2) << "Initialize()"; | |
50 DCHECK(message_loop_->BelongsToCurrentThread()); | 49 DCHECK(message_loop_->BelongsToCurrentThread()); |
51 DCHECK_EQ(state_, kUninitialized) << state_; | 50 DCHECK_EQ(state_, kUninitialized) << state_; |
52 | 51 |
53 DCHECK(!demuxer_stream_); | 52 DCHECK(!demuxer_stream_); |
54 weak_this_ = weak_factory_.GetWeakPtr(); | 53 weak_this_ = weak_factory_.GetWeakPtr(); |
55 demuxer_stream_ = stream; | 54 demuxer_stream_ = stream; |
56 init_cb_ = status_cb; | 55 init_cb_ = BindToCurrentLoop(status_cb); |
57 | 56 |
58 InitializeDecoderConfig(); | 57 InitializeDecoderConfig(); |
59 | 58 |
60 state_ = kDecryptorRequested; | 59 state_ = kDecryptorRequested; |
61 set_decryptor_ready_cb_.Run( | 60 set_decryptor_ready_cb_.Run( |
62 BIND_TO_LOOP(&DecryptingDemuxerStream::SetDecryptor)); | 61 BIND_TO_LOOP(&DecryptingDemuxerStream::SetDecryptor)); |
63 } | 62 } |
64 | 63 |
65 void DecryptingDemuxerStream::Read(const ReadCB& read_cb) { | 64 void DecryptingDemuxerStream::Read(const ReadCB& read_cb) { |
66 DVLOG(3) << "Read()"; | 65 DVLOG(3) << __FUNCTION__; |
67 DCHECK(message_loop_->BelongsToCurrentThread()); | 66 DCHECK(message_loop_->BelongsToCurrentThread()); |
68 DCHECK_EQ(state_, kIdle) << state_; | 67 DCHECK_EQ(state_, kIdle) << state_; |
69 DCHECK(!read_cb.is_null()); | 68 DCHECK(!read_cb.is_null()); |
70 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported."; | 69 CHECK(read_cb_.is_null()) << "Overlapping reads are not supported."; |
71 | 70 |
72 read_cb_ = read_cb; | 71 read_cb_ = BindToCurrentLoop(read_cb); |
73 state_ = kPendingDemuxerRead; | 72 state_ = kPendingDemuxerRead; |
74 demuxer_stream_->Read( | 73 demuxer_stream_->Read( |
75 base::Bind(&DecryptingDemuxerStream::DecryptBuffer, weak_this_)); | 74 base::Bind(&DecryptingDemuxerStream::DecryptBuffer, weak_this_)); |
76 } | 75 } |
77 | 76 |
78 void DecryptingDemuxerStream::Reset(const base::Closure& closure) { | 77 void DecryptingDemuxerStream::Reset(const base::Closure& closure) { |
79 DVLOG(2) << "Reset() - state: " << state_; | 78 DVLOG(2) << __FUNCTION__ << " - state: " << state_; |
80 DCHECK(message_loop_->BelongsToCurrentThread()); | 79 DCHECK(message_loop_->BelongsToCurrentThread()); |
81 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; | 80 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; |
82 DCHECK(init_cb_.is_null()); // No Reset() during pending initialization. | 81 DCHECK(init_cb_.is_null()); // No Reset() during pending initialization. |
83 DCHECK(reset_cb_.is_null()); | 82 DCHECK(reset_cb_.is_null()); |
84 | 83 |
85 reset_cb_ = BindToCurrentLoop(closure); | 84 reset_cb_ = BindToCurrentLoop(closure); |
86 | 85 |
87 decryptor_->CancelDecrypt(GetDecryptorStreamType()); | 86 decryptor_->CancelDecrypt(GetDecryptorStreamType()); |
88 | 87 |
89 // Reset() cannot complete if the read callback is still pending. | 88 // Reset() cannot complete if the read callback is still pending. |
(...skipping 29 matching lines...) Expand all Loading... |
119 | 118 |
120 DemuxerStream::Type DecryptingDemuxerStream::type() { | 119 DemuxerStream::Type DecryptingDemuxerStream::type() { |
121 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; | 120 DCHECK(state_ != kUninitialized && state_ != kDecryptorRequested) << state_; |
122 return demuxer_stream_->type(); | 121 return demuxer_stream_->type(); |
123 } | 122 } |
124 | 123 |
125 void DecryptingDemuxerStream::EnableBitstreamConverter() { | 124 void DecryptingDemuxerStream::EnableBitstreamConverter() { |
126 demuxer_stream_->EnableBitstreamConverter(); | 125 demuxer_stream_->EnableBitstreamConverter(); |
127 } | 126 } |
128 | 127 |
129 DecryptingDemuxerStream::~DecryptingDemuxerStream() {} | 128 DecryptingDemuxerStream::~DecryptingDemuxerStream() { |
| 129 DVLOG(2) << __FUNCTION__; |
| 130 if (!set_decryptor_ready_cb_.is_null()) |
| 131 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); |
| 132 } |
130 | 133 |
131 void DecryptingDemuxerStream::SetDecryptor(Decryptor* decryptor) { | 134 void DecryptingDemuxerStream::SetDecryptor(Decryptor* decryptor) { |
132 DVLOG(2) << "SetDecryptor()"; | 135 DVLOG(2) << __FUNCTION__; |
133 DCHECK(message_loop_->BelongsToCurrentThread()); | 136 DCHECK(message_loop_->BelongsToCurrentThread()); |
134 DCHECK_EQ(state_, kDecryptorRequested) << state_; | 137 DCHECK_EQ(state_, kDecryptorRequested) << state_; |
135 DCHECK(!init_cb_.is_null()); | 138 DCHECK(!init_cb_.is_null()); |
136 DCHECK(!set_decryptor_ready_cb_.is_null()); | 139 DCHECK(!set_decryptor_ready_cb_.is_null()); |
137 | 140 |
138 set_decryptor_ready_cb_.Reset(); | 141 set_decryptor_ready_cb_.Reset(); |
139 | 142 |
140 if (!decryptor) { | 143 if (!decryptor) { |
| 144 state_ = kUninitialized; |
141 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); | 145 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); |
142 state_ = kUninitialized; | |
143 return; | 146 return; |
144 } | 147 } |
145 | 148 |
146 decryptor_ = decryptor; | 149 decryptor_ = decryptor; |
147 | 150 |
148 decryptor_->RegisterNewKeyCB( | 151 decryptor_->RegisterNewKeyCB( |
149 GetDecryptorStreamType(), | 152 GetDecryptorStreamType(), |
150 BIND_TO_LOOP(&DecryptingDemuxerStream::OnKeyAdded)); | 153 BIND_TO_LOOP(&DecryptingDemuxerStream::OnKeyAdded)); |
151 | 154 |
152 state_ = kIdle; | 155 state_ = kIdle; |
153 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 156 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
154 } | 157 } |
155 | 158 |
156 void DecryptingDemuxerStream::DecryptBuffer( | 159 void DecryptingDemuxerStream::DecryptBuffer( |
157 DemuxerStream::Status status, | 160 DemuxerStream::Status status, |
158 const scoped_refptr<DecoderBuffer>& buffer) { | 161 const scoped_refptr<DecoderBuffer>& buffer) { |
159 DVLOG(3) << "DecryptBuffer()"; | 162 DVLOG(3) << __FUNCTION__; |
160 DCHECK(message_loop_->BelongsToCurrentThread()); | 163 DCHECK(message_loop_->BelongsToCurrentThread()); |
161 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; | 164 DCHECK_EQ(state_, kPendingDemuxerRead) << state_; |
162 DCHECK(!read_cb_.is_null()); | 165 DCHECK(!read_cb_.is_null()); |
163 DCHECK_EQ(buffer.get() != NULL, status == kOk) << status; | 166 DCHECK_EQ(buffer.get() != NULL, status == kOk) << status; |
164 | 167 |
165 if (!reset_cb_.is_null()) { | 168 if (!reset_cb_.is_null()) { |
166 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); | 169 base::ResetAndReturn(&read_cb_).Run(kAborted, NULL); |
167 DoReset(); | 170 DoReset(); |
168 return; | 171 return; |
169 } | 172 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 DCHECK_EQ(state_, kPendingDecrypt) << state_; | 208 DCHECK_EQ(state_, kPendingDecrypt) << state_; |
206 decryptor_->Decrypt( | 209 decryptor_->Decrypt( |
207 GetDecryptorStreamType(), | 210 GetDecryptorStreamType(), |
208 pending_buffer_to_decrypt_, | 211 pending_buffer_to_decrypt_, |
209 BIND_TO_LOOP(&DecryptingDemuxerStream::DeliverBuffer)); | 212 BIND_TO_LOOP(&DecryptingDemuxerStream::DeliverBuffer)); |
210 } | 213 } |
211 | 214 |
212 void DecryptingDemuxerStream::DeliverBuffer( | 215 void DecryptingDemuxerStream::DeliverBuffer( |
213 Decryptor::Status status, | 216 Decryptor::Status status, |
214 const scoped_refptr<DecoderBuffer>& decrypted_buffer) { | 217 const scoped_refptr<DecoderBuffer>& decrypted_buffer) { |
215 DVLOG(3) << "DeliverBuffer() - status: " << status; | 218 DVLOG(3) << __FUNCTION__ << " - status: " << status; |
216 DCHECK(message_loop_->BelongsToCurrentThread()); | 219 DCHECK(message_loop_->BelongsToCurrentThread()); |
217 DCHECK_EQ(state_, kPendingDecrypt) << state_; | 220 DCHECK_EQ(state_, kPendingDecrypt) << state_; |
218 DCHECK_NE(status, Decryptor::kNeedMoreData); | 221 DCHECK_NE(status, Decryptor::kNeedMoreData); |
219 DCHECK(!read_cb_.is_null()); | 222 DCHECK(!read_cb_.is_null()); |
220 DCHECK(pending_buffer_to_decrypt_.get()); | 223 DCHECK(pending_buffer_to_decrypt_.get()); |
221 | 224 |
222 bool need_to_try_again_if_nokey = key_added_while_decrypt_pending_; | 225 bool need_to_try_again_if_nokey = key_added_while_decrypt_pending_; |
223 key_added_while_decrypt_pending_ = false; | 226 key_added_while_decrypt_pending_ = false; |
224 | 227 |
225 if (!reset_cb_.is_null()) { | 228 if (!reset_cb_.is_null()) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 break; | 327 break; |
325 } | 328 } |
326 | 329 |
327 default: | 330 default: |
328 NOTREACHED(); | 331 NOTREACHED(); |
329 return; | 332 return; |
330 } | 333 } |
331 } | 334 } |
332 | 335 |
333 } // namespace media | 336 } // namespace media |
OLD | NEW |