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_audio_decoder.h" | 5 #include "media/filters/decrypting_audio_decoder.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstdlib> | 9 #include <cstdlib> |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 DCHECK(task_runner_->BelongsToCurrentThread()); | 101 DCHECK(task_runner_->BelongsToCurrentThread()); |
102 DCHECK(state_ == kIdle || state_ == kDecodeFinished) << state_; | 102 DCHECK(state_ == kIdle || state_ == kDecodeFinished) << state_; |
103 DCHECK(!decode_cb.is_null()); | 103 DCHECK(!decode_cb.is_null()); |
104 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; | 104 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported."; |
105 | 105 |
106 decode_cb_ = BindToCurrentLoop(decode_cb); | 106 decode_cb_ = BindToCurrentLoop(decode_cb); |
107 | 107 |
108 // Return empty (end-of-stream) frames if decoding has finished. | 108 // Return empty (end-of-stream) frames if decoding has finished. |
109 if (state_ == kDecodeFinished) { | 109 if (state_ == kDecodeFinished) { |
110 output_cb_.Run(AudioBuffer::CreateEOSBuffer()); | 110 output_cb_.Run(AudioBuffer::CreateEOSBuffer()); |
111 base::ResetAndReturn(&decode_cb_).Run(kOk); | 111 base::ResetAndReturn(&decode_cb_).Run(DecodeStatus::OK); |
112 return; | 112 return; |
113 } | 113 } |
114 | 114 |
115 // Initialize the |next_output_timestamp_| to be the timestamp of the first | 115 // Initialize the |next_output_timestamp_| to be the timestamp of the first |
116 // non-EOS buffer. | 116 // non-EOS buffer. |
117 if (timestamp_helper_->base_timestamp() == kNoTimestamp() && | 117 if (timestamp_helper_->base_timestamp() == kNoTimestamp() && |
118 !buffer->end_of_stream()) { | 118 !buffer->end_of_stream()) { |
119 timestamp_helper_->SetBaseTimestamp(buffer->timestamp()); | 119 timestamp_helper_->SetBaseTimestamp(buffer->timestamp()); |
120 } | 120 } |
121 | 121 |
(...skipping 21 matching lines...) Expand all Loading... |
143 // after the read callback is fired - see DecryptAndDecodeBuffer() and | 143 // after the read callback is fired - see DecryptAndDecodeBuffer() and |
144 // DeliverFrame(). | 144 // DeliverFrame(). |
145 if (state_ == kPendingDecode) { | 145 if (state_ == kPendingDecode) { |
146 DCHECK(!decode_cb_.is_null()); | 146 DCHECK(!decode_cb_.is_null()); |
147 return; | 147 return; |
148 } | 148 } |
149 | 149 |
150 if (state_ == kWaitingForKey) { | 150 if (state_ == kWaitingForKey) { |
151 DCHECK(!decode_cb_.is_null()); | 151 DCHECK(!decode_cb_.is_null()); |
152 pending_buffer_to_decode_ = NULL; | 152 pending_buffer_to_decode_ = NULL; |
153 base::ResetAndReturn(&decode_cb_).Run(kAborted); | 153 base::ResetAndReturn(&decode_cb_).Run(DecodeStatus::ABORTED); |
154 } | 154 } |
155 | 155 |
156 DCHECK(decode_cb_.is_null()); | 156 DCHECK(decode_cb_.is_null()); |
157 DoReset(); | 157 DoReset(); |
158 } | 158 } |
159 | 159 |
160 DecryptingAudioDecoder::~DecryptingAudioDecoder() { | 160 DecryptingAudioDecoder::~DecryptingAudioDecoder() { |
161 DVLOG(2) << __FUNCTION__; | 161 DVLOG(2) << __FUNCTION__; |
162 DCHECK(task_runner_->BelongsToCurrentThread()); | 162 DCHECK(task_runner_->BelongsToCurrentThread()); |
163 | 163 |
164 if (state_ == kUninitialized) | 164 if (state_ == kUninitialized) |
165 return; | 165 return; |
166 | 166 |
167 if (decryptor_) { | 167 if (decryptor_) { |
168 decryptor_->DeinitializeDecoder(Decryptor::kAudio); | 168 decryptor_->DeinitializeDecoder(Decryptor::kAudio); |
169 decryptor_ = NULL; | 169 decryptor_ = NULL; |
170 } | 170 } |
171 pending_buffer_to_decode_ = NULL; | 171 pending_buffer_to_decode_ = NULL; |
172 if (!init_cb_.is_null()) | 172 if (!init_cb_.is_null()) |
173 base::ResetAndReturn(&init_cb_).Run(false); | 173 base::ResetAndReturn(&init_cb_).Run(false); |
174 if (!decode_cb_.is_null()) | 174 if (!decode_cb_.is_null()) |
175 base::ResetAndReturn(&decode_cb_).Run(kAborted); | 175 base::ResetAndReturn(&decode_cb_).Run(DecodeStatus::ABORTED); |
176 if (!reset_cb_.is_null()) | 176 if (!reset_cb_.is_null()) |
177 base::ResetAndReturn(&reset_cb_).Run(); | 177 base::ResetAndReturn(&reset_cb_).Run(); |
178 } | 178 } |
179 | 179 |
180 void DecryptingAudioDecoder::InitializeDecoder() { | 180 void DecryptingAudioDecoder::InitializeDecoder() { |
181 state_ = kPendingDecoderInit; | 181 state_ = kPendingDecoderInit; |
182 decryptor_->InitializeAudioDecoder( | 182 decryptor_->InitializeAudioDecoder( |
183 config_, | 183 config_, |
184 BindToCurrentLoop(base::Bind( | 184 BindToCurrentLoop(base::Bind( |
185 &DecryptingAudioDecoder::FinishInitialization, weak_this_))); | 185 &DecryptingAudioDecoder::FinishInitialization, weak_this_))); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 DCHECK(pending_buffer_to_decode_.get()); | 241 DCHECK(pending_buffer_to_decode_.get()); |
242 | 242 |
243 bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_; | 243 bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_; |
244 key_added_while_decode_pending_ = false; | 244 key_added_while_decode_pending_ = false; |
245 | 245 |
246 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode = | 246 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode = |
247 pending_buffer_to_decode_; | 247 pending_buffer_to_decode_; |
248 pending_buffer_to_decode_ = NULL; | 248 pending_buffer_to_decode_ = NULL; |
249 | 249 |
250 if (!reset_cb_.is_null()) { | 250 if (!reset_cb_.is_null()) { |
251 base::ResetAndReturn(&decode_cb_).Run(kAborted); | 251 base::ResetAndReturn(&decode_cb_).Run(DecodeStatus::ABORTED); |
252 DoReset(); | 252 DoReset(); |
253 return; | 253 return; |
254 } | 254 } |
255 | 255 |
256 DCHECK_EQ(status == Decryptor::kSuccess, !frames.empty()); | 256 DCHECK_EQ(status == Decryptor::kSuccess, !frames.empty()); |
257 | 257 |
258 if (status == Decryptor::kError) { | 258 if (status == Decryptor::kError) { |
259 DVLOG(2) << "DeliverFrame() - kError"; | 259 DVLOG(2) << "DeliverFrame() - kError"; |
260 MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": decode error"; | 260 MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": decode error"; |
261 state_ = kDecodeFinished; // TODO add kError state | 261 state_ = kDecodeFinished; // TODO add kError state |
262 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); | 262 base::ResetAndReturn(&decode_cb_).Run(DecodeStatus::DECODE_ERROR); |
263 return; | 263 return; |
264 } | 264 } |
265 | 265 |
266 if (status == Decryptor::kNoKey) { | 266 if (status == Decryptor::kNoKey) { |
267 DVLOG(2) << "DeliverFrame() - kNoKey"; | 267 DVLOG(2) << "DeliverFrame() - kNoKey"; |
268 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no key"; | 268 MEDIA_LOG(DEBUG, media_log_) << GetDisplayName() << ": no key"; |
269 | 269 |
270 // Set |pending_buffer_to_decode_| back as we need to try decoding the | 270 // Set |pending_buffer_to_decode_| back as we need to try decoding the |
271 // pending buffer again when new key is added to the decryptor. | 271 // pending buffer again when new key is added to the decryptor. |
272 pending_buffer_to_decode_ = scoped_pending_buffer_to_decode; | 272 pending_buffer_to_decode_ = scoped_pending_buffer_to_decode; |
273 | 273 |
274 if (need_to_try_again_if_nokey_is_returned) { | 274 if (need_to_try_again_if_nokey_is_returned) { |
275 // The |state_| is still kPendingDecode. | 275 // The |state_| is still kPendingDecode. |
276 DecodePendingBuffer(); | 276 DecodePendingBuffer(); |
277 return; | 277 return; |
278 } | 278 } |
279 | 279 |
280 state_ = kWaitingForKey; | 280 state_ = kWaitingForKey; |
281 waiting_for_decryption_key_cb_.Run(); | 281 waiting_for_decryption_key_cb_.Run(); |
282 return; | 282 return; |
283 } | 283 } |
284 | 284 |
285 if (status == Decryptor::kNeedMoreData) { | 285 if (status == Decryptor::kNeedMoreData) { |
286 DVLOG(2) << "DeliverFrame() - kNeedMoreData"; | 286 DVLOG(2) << "DeliverFrame() - kNeedMoreData"; |
287 state_ = scoped_pending_buffer_to_decode->end_of_stream() ? kDecodeFinished | 287 state_ = scoped_pending_buffer_to_decode->end_of_stream() ? kDecodeFinished |
288 : kIdle; | 288 : kIdle; |
289 base::ResetAndReturn(&decode_cb_).Run(kOk); | 289 base::ResetAndReturn(&decode_cb_).Run(DecodeStatus::OK); |
290 return; | 290 return; |
291 } | 291 } |
292 | 292 |
293 DCHECK_EQ(status, Decryptor::kSuccess); | 293 DCHECK_EQ(status, Decryptor::kSuccess); |
294 DCHECK(!frames.empty()); | 294 DCHECK(!frames.empty()); |
295 ProcessDecodedFrames(frames); | 295 ProcessDecodedFrames(frames); |
296 | 296 |
297 if (scoped_pending_buffer_to_decode->end_of_stream()) { | 297 if (scoped_pending_buffer_to_decode->end_of_stream()) { |
298 // Set |pending_buffer_to_decode_| back as we need to keep flushing the | 298 // Set |pending_buffer_to_decode_| back as we need to keep flushing the |
299 // decryptor until kNeedMoreData is returned. | 299 // decryptor until kNeedMoreData is returned. |
300 pending_buffer_to_decode_ = scoped_pending_buffer_to_decode; | 300 pending_buffer_to_decode_ = scoped_pending_buffer_to_decode; |
301 DecodePendingBuffer(); | 301 DecodePendingBuffer(); |
302 return; | 302 return; |
303 } | 303 } |
304 | 304 |
305 state_ = kIdle; | 305 state_ = kIdle; |
306 base::ResetAndReturn(&decode_cb_).Run(kOk); | 306 base::ResetAndReturn(&decode_cb_).Run(DecodeStatus::OK); |
307 } | 307 } |
308 | 308 |
309 void DecryptingAudioDecoder::OnKeyAdded() { | 309 void DecryptingAudioDecoder::OnKeyAdded() { |
310 DCHECK(task_runner_->BelongsToCurrentThread()); | 310 DCHECK(task_runner_->BelongsToCurrentThread()); |
311 | 311 |
312 if (state_ == kPendingDecode) { | 312 if (state_ == kPendingDecode) { |
313 key_added_while_decode_pending_ = true; | 313 key_added_while_decode_pending_ = true; |
314 return; | 314 return; |
315 } | 315 } |
316 | 316 |
(...skipping 30 matching lines...) Expand all Loading... |
347 } | 347 } |
348 | 348 |
349 frame->set_timestamp(current_time); | 349 frame->set_timestamp(current_time); |
350 timestamp_helper_->AddFrames(frame->frame_count()); | 350 timestamp_helper_->AddFrames(frame->frame_count()); |
351 | 351 |
352 output_cb_.Run(frame); | 352 output_cb_.Run(frame); |
353 } | 353 } |
354 } | 354 } |
355 | 355 |
356 } // namespace media | 356 } // namespace media |
OLD | NEW |