Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / media / filters / decrypting_video_decoder.cc
index bae5ab1..e5bf393 100644 (file)
@@ -127,12 +127,15 @@ void DecryptingVideoDecoder::Stop(const base::Closure& closure) {
   DCHECK(task_runner_->BelongsToCurrentThread());
   DVLOG(2) << "Stop() - state: " << state_;
 
+  // Invalidate all weak pointers so that pending callbacks won't be fired into
+  // this object.
+  weak_factory_.InvalidateWeakPtrs();
+
   // At this point the render thread is likely paused (in WebMediaPlayerImpl's
   // Destroy()), so running |closure| can't wait for anything that requires the
   // render thread to be processing messages to complete (such as PPAPI
   // callbacks).
   if (decryptor_) {
-    decryptor_->RegisterNewKeyCB(Decryptor::kVideo, Decryptor::NewKeyCB());
     decryptor_->DeinitializeDecoder(Decryptor::kVideo);
     decryptor_ = NULL;
   }
@@ -145,6 +148,7 @@ void DecryptingVideoDecoder::Stop(const base::Closure& closure) {
     base::ResetAndReturn(&decode_cb_).Run(kAborted, NULL);
   if (!reset_cb_.is_null())
     base::ResetAndReturn(&reset_cb_).Run();
+
   state_ = kStopped;
   BindToCurrentLoop(closure).Run();
 }
@@ -156,10 +160,6 @@ DecryptingVideoDecoder::~DecryptingVideoDecoder() {
 void DecryptingVideoDecoder::SetDecryptor(Decryptor* decryptor) {
   DVLOG(2) << "SetDecryptor()";
   DCHECK(task_runner_->BelongsToCurrentThread());
-
-  if (state_ == kStopped)
-    return;
-
   DCHECK_EQ(state_, kDecryptorRequested) << state_;
   DCHECK(!init_cb_.is_null());
   DCHECK(!set_decryptor_ready_cb_.is_null());
@@ -183,10 +183,6 @@ void DecryptingVideoDecoder::SetDecryptor(Decryptor* decryptor) {
 void DecryptingVideoDecoder::FinishInitialization(bool success) {
   DVLOG(2) << "FinishInitialization()";
   DCHECK(task_runner_->BelongsToCurrentThread());
-
-  if (state_ == kStopped)
-    return;
-
   DCHECK_EQ(state_, kPendingDecoderInit) << state_;
   DCHECK(!init_cb_.is_null());
   DCHECK(reset_cb_.is_null());  // No Reset() before initialization finished.
@@ -198,8 +194,10 @@ void DecryptingVideoDecoder::FinishInitialization(bool success) {
     return;
   }
 
-  decryptor_->RegisterNewKeyCB(Decryptor::kVideo, BindToCurrentLoop(
-      base::Bind(&DecryptingVideoDecoder::OnKeyAdded, weak_this_)));
+  decryptor_->RegisterNewKeyCB(
+      Decryptor::kVideo,
+      BindToCurrentLoop(
+          base::Bind(&DecryptingVideoDecoder::OnKeyAdded, weak_this_)));
 
   // Success!
   state_ = kIdle;
@@ -229,16 +227,13 @@ void DecryptingVideoDecoder::DeliverFrame(
     const scoped_refptr<VideoFrame>& frame) {
   DVLOG(3) << "DeliverFrame() - status: " << status;
   DCHECK(task_runner_->BelongsToCurrentThread());
-  TRACE_EVENT_ASYNC_END0(
-      "media", "DecryptingVideoDecoder::DecodePendingBuffer", trace_id_);
-
-  if (state_ == kStopped)
-    return;
-
   DCHECK_EQ(state_, kPendingDecode) << state_;
   DCHECK(!decode_cb_.is_null());
   DCHECK(pending_buffer_to_decode_.get());
 
+  TRACE_EVENT_ASYNC_END0(
+      "media", "DecryptingVideoDecoder::DecodePendingBuffer", trace_id_);
+
   bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_;
   key_added_while_decode_pending_ = false;