OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromecast/media/cma/pipeline/av_pipeline_impl.h" | 5 #include "chromecast/media/cma/pipeline/av_pipeline_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 : bytes_decoded_since_last_update_(0), | 40 : bytes_decoded_since_last_update_(0), |
41 decoder_(decoder), | 41 decoder_(decoder), |
42 client_(client), | 42 client_(client), |
43 state_(kUninitialized), | 43 state_(kUninitialized), |
44 buffered_time_(::media::kNoTimestamp), | 44 buffered_time_(::media::kNoTimestamp), |
45 playable_buffered_time_(::media::kNoTimestamp), | 45 playable_buffered_time_(::media::kNoTimestamp), |
46 enable_feeding_(false), | 46 enable_feeding_(false), |
47 pending_read_(false), | 47 pending_read_(false), |
48 cast_cdm_context_(NULL), | 48 cast_cdm_context_(NULL), |
49 player_tracker_callback_id_(kNoCallbackId), | 49 player_tracker_callback_id_(kNoCallbackId), |
50 weak_factory_(this) { | 50 weak_factory_(this), |
| 51 decrypt_weak_factory_(this) { |
51 DCHECK(decoder_); | 52 DCHECK(decoder_); |
52 decoder_->SetDelegate(this); | 53 decoder_->SetDelegate(this); |
53 weak_this_ = weak_factory_.GetWeakPtr(); | 54 weak_this_ = weak_factory_.GetWeakPtr(); |
54 thread_checker_.DetachFromThread(); | 55 thread_checker_.DetachFromThread(); |
55 } | 56 } |
56 | 57 |
57 AvPipelineImpl::~AvPipelineImpl() { | 58 AvPipelineImpl::~AvPipelineImpl() { |
58 DCHECK(thread_checker_.CalledOnValidThread()); | 59 DCHECK(thread_checker_.CalledOnValidThread()); |
59 | 60 |
60 if (cast_cdm_context_ && player_tracker_callback_id_ != kNoCallbackId) | 61 if (cast_cdm_context_ && player_tracker_callback_id_ != kNoCallbackId) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 DCHECK_EQ(state_, kFlushing); | 141 DCHECK_EQ(state_, kFlushing); |
141 set_state(kFlushed); | 142 set_state(kFlushed); |
142 base::ResetAndReturn(&flush_cb_).Run(); | 143 base::ResetAndReturn(&flush_cb_).Run(); |
143 } | 144 } |
144 | 145 |
145 void AvPipelineImpl::Stop() { | 146 void AvPipelineImpl::Stop() { |
146 DCHECK(thread_checker_.CalledOnValidThread()); | 147 DCHECK(thread_checker_.CalledOnValidThread()); |
147 CMALOG(kLogControl) << __FUNCTION__; | 148 CMALOG(kLogControl) << __FUNCTION__; |
148 // Stop feeding the pipeline. | 149 // Stop feeding the pipeline. |
149 enable_feeding_ = false; | 150 enable_feeding_ = false; |
| 151 // Drop any pending asynchronous decryption, so any pending |
| 152 // OnBufferDecrypted() callback will not be called. StartPlayingFrom() sets |
| 153 // enable_feeding_ back to true, so if a pending decryption callback from |
| 154 // before Stop() is allowed to complete after StartPlayingFrom() is called |
| 155 // again, it will think everything is fine and try to push a buffer, resulting |
| 156 // in a double push. |
| 157 decrypt_weak_factory_.InvalidateWeakPtrs(); |
150 set_state(kStopped); | 158 set_state(kStopped); |
151 } | 159 } |
152 | 160 |
153 void AvPipelineImpl::SetCdm(CastCdmContext* cast_cdm_context) { | 161 void AvPipelineImpl::SetCdm(CastCdmContext* cast_cdm_context) { |
154 DCHECK(thread_checker_.CalledOnValidThread()); | 162 DCHECK(thread_checker_.CalledOnValidThread()); |
155 DCHECK(cast_cdm_context); | 163 DCHECK(cast_cdm_context); |
156 | 164 |
157 if (cast_cdm_context_ && player_tracker_callback_id_ != kNoCallbackId) | 165 if (cast_cdm_context_ && player_tracker_callback_id_ != kNoCallbackId) |
158 cast_cdm_context_->UnregisterPlayer(player_tracker_callback_id_); | 166 cast_cdm_context_->UnregisterPlayer(player_tracker_callback_id_); |
159 | 167 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 client_.wait_for_key_cb.Run(); | 236 client_.wait_for_key_cb.Run(); |
229 return; | 237 return; |
230 } | 238 } |
231 | 239 |
232 DCHECK_NE(decrypt_context->GetKeySystem(), KEY_SYSTEM_NONE); | 240 DCHECK_NE(decrypt_context->GetKeySystem(), KEY_SYSTEM_NONE); |
233 | 241 |
234 // If we can get the clear content, decrypt the pending buffer | 242 // If we can get the clear content, decrypt the pending buffer |
235 if (decrypt_context->CanDecryptToBuffer()) { | 243 if (decrypt_context->CanDecryptToBuffer()) { |
236 auto buffer = pending_buffer_; | 244 auto buffer = pending_buffer_; |
237 pending_buffer_ = nullptr; | 245 pending_buffer_ = nullptr; |
238 DecryptDecoderBuffer( | 246 DecryptDecoderBuffer(buffer, decrypt_context.get(), |
239 buffer, decrypt_context.get(), | 247 base::Bind(&AvPipelineImpl::OnBufferDecrypted, |
240 base::Bind(&AvPipelineImpl::OnBufferDecrypted, weak_this_, | 248 decrypt_weak_factory_.GetWeakPtr(), |
241 base::Passed(&decrypt_context))); | 249 base::Passed(&decrypt_context))); |
242 | 250 |
243 return; | 251 return; |
244 } | 252 } |
245 | 253 |
246 pending_buffer_->set_decrypt_context(std::move(decrypt_context)); | 254 pending_buffer_->set_decrypt_context(std::move(decrypt_context)); |
247 } | 255 } |
248 | 256 |
249 PushPendingBuffer(); | 257 PushPendingBuffer(); |
250 } | 258 } |
251 | 259 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 } | 405 } |
398 } | 406 } |
399 | 407 |
400 // The frame is playable: remove it from the list of non playable frames. | 408 // The frame is playable: remove it from the list of non playable frames. |
401 non_playable_frames_.pop_front(); | 409 non_playable_frames_.pop_front(); |
402 } | 410 } |
403 } | 411 } |
404 | 412 |
405 } // namespace media | 413 } // namespace media |
406 } // namespace chromecast | 414 } // namespace chromecast |
OLD | NEW |