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/location.h" | 9 #include "base/location.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 state_ == kPendingDemuxerRead || | 61 state_ == kPendingDemuxerRead || |
62 state_ == kPendingDecode || | 62 state_ == kPendingDecode || |
63 state_ == kWaitingForKey || | 63 state_ == kWaitingForKey || |
64 state_ == kDecodeFinished) << state_; | 64 state_ == kDecodeFinished) << state_; |
65 DCHECK(init_cb_.is_null()); // No Reset() during pending initialization. | 65 DCHECK(init_cb_.is_null()); // No Reset() during pending initialization. |
66 DCHECK(stop_cb_.is_null()); // No Reset() during pending Stop(). | 66 DCHECK(stop_cb_.is_null()); // No Reset() during pending Stop(). |
67 DCHECK(reset_cb_.is_null()); | 67 DCHECK(reset_cb_.is_null()); |
68 | 68 |
69 reset_cb_ = closure; | 69 reset_cb_ = closure; |
70 | 70 |
71 decryptor_->CancelDecryptAndDecodeVideo(); | 71 decryptor_->ResetDecoder(Decryptor::kVideo); |
72 | 72 |
73 // Reset() cannot complete if the read callback is still pending. | 73 // Reset() cannot complete if the read callback is still pending. |
74 // Defer the resetting process in this case. The |reset_cb_| will be fired | 74 // Defer the resetting process in this case. The |reset_cb_| will be fired |
75 // after the read callback is fired - see DoDecryptAndDecodeBuffer() and | 75 // after the read callback is fired - see DoDecryptAndDecodeBuffer() and |
76 // DoDeliverFrame(). | 76 // DoDeliverFrame(). |
77 if (state_ == kPendingDemuxerRead || state_ == kPendingDecode) { | 77 if (state_ == kPendingDemuxerRead || state_ == kPendingDecode) { |
78 DCHECK(!read_cb_.is_null()); | 78 DCHECK(!read_cb_.is_null()); |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
(...skipping 11 matching lines...) Expand all Loading... | |
93 if (!message_loop_->BelongsToCurrentThread()) { | 93 if (!message_loop_->BelongsToCurrentThread()) { |
94 message_loop_->PostTask(FROM_HERE, base::Bind( | 94 message_loop_->PostTask(FROM_HERE, base::Bind( |
95 &DecryptingVideoDecoder::Stop, this, closure)); | 95 &DecryptingVideoDecoder::Stop, this, closure)); |
96 return; | 96 return; |
97 } | 97 } |
98 | 98 |
99 DVLOG(2) << "Stop() - state: " << state_; | 99 DVLOG(2) << "Stop() - state: " << state_; |
100 DCHECK(stop_cb_.is_null()); | 100 DCHECK(stop_cb_.is_null()); |
101 stop_cb_ = closure; | 101 stop_cb_ = closure; |
102 | 102 |
103 // We need to call Decryptor::StopVideoDecoder() if we ever called | 103 // We need to call Decryptor::DeinitializeDecoder(Decryptor::kVideo) if we |
104 // Decryptor::InitializeVideoDecoder() to cancel the pending initialization if | 104 // ever called Decryptor::InitializeVideoDecoder() to cancel the pending |
105 // the initialization is still pending, or to stop the video decoder if | 105 // initialization if the initialization is still pending, or to stop the video |
106 // the initialization has completed. | 106 // decoder if the initialization has completed. |
107 // When the state is kUninitialized and kDecryptorRequested, | 107 // When the state is kUninitialized and kDecryptorRequested, |
108 // InitializeVideoDecoder() has not been called, so we are okay. | 108 // InitializeVideoDecoder() has not been called, so we are okay. |
109 // When the state is kStopped, the video decoder should have already been | 109 // When the state is kStopped, the video decoder should have already been |
110 // stopped, so no need to call StopVideoDecoder() either. | 110 // stopped, so no need to call DeinitializeDecoder(Decryptor::kVideo) either. |
111 // In all other cases, we need to call StopVideoDecoder()! | 111 // In all other cases, we need to call DeinitializeDecoder(Decryptor::kVideo)! |
112 switch (state_) { | 112 switch (state_) { |
113 case kUninitialized: | 113 case kUninitialized: |
114 case kStopped: | 114 case kStopped: |
115 DoStop(); | 115 DoStop(); |
116 break; | 116 break; |
117 case kDecryptorRequested: | 117 case kDecryptorRequested: |
118 // Stop() cannot complete if the decryptor request is still pending. | 118 // Stop() cannot complete if the decryptor request is still pending. |
119 // Defer the stopping process in this case. The |stop_cb_| will be fired | 119 // Defer the stopping process in this case. The |stop_cb_| will be fired |
120 // after the request decryptor callback is fired - see SetDecryptor(). | 120 // after the request decryptor callback is fired - see SetDecryptor(). |
121 request_decryptor_notification_cb_.Run(DecryptorNotificationCB()); | 121 request_decryptor_notification_cb_.Run(DecryptorNotificationCB()); |
122 break; | 122 break; |
123 case kIdle: | 123 case kIdle: |
124 case kDecodeFinished: | 124 case kDecodeFinished: |
125 decryptor_->StopVideoDecoder(); | 125 decryptor_->DeinitializeDecoder(Decryptor::kVideo); |
ddorwin
2012/10/17 02:52:33
nit: Might be less bug-prone to have a private hel
xhwang
2012/10/17 22:29:06
I'll hold here as fischman is trying to remove thi
| |
126 DoStop(); | 126 DoStop(); |
127 break; | 127 break; |
128 case kWaitingForKey: | 128 case kWaitingForKey: |
129 decryptor_->StopVideoDecoder(); | 129 decryptor_->DeinitializeDecoder(Decryptor::kVideo); |
130 DCHECK(!read_cb_.is_null()); | 130 DCHECK(!read_cb_.is_null()); |
131 pending_buffer_to_decode_ = NULL; | 131 pending_buffer_to_decode_ = NULL; |
132 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); | 132 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); |
133 DoStop(); | 133 DoStop(); |
134 break; | 134 break; |
135 case kPendingDecoderInit: | 135 case kPendingDecoderInit: |
136 case kPendingDemuxerRead: | 136 case kPendingDemuxerRead: |
137 case kPendingDecode: | 137 case kPendingDecode: |
138 // Stop() cannot complete if the init or read callback is still pending. | 138 // Stop() cannot complete if the init or read callback is still pending. |
139 // Defer the stopping process in these cases. The |stop_cb_| will be | 139 // Defer the stopping process in these cases. The |stop_cb_| will be |
140 // fired after the init or read callback is fired - see | 140 // fired after the init or read callback is fired - see |
141 // FinishInitialization(), DoDecryptAndDecodeBuffer() and | 141 // FinishInitialization(), DoDecryptAndDecodeBuffer() and |
142 // DoDeliverFrame(), respectively. | 142 // DoDeliverFrame(), respectively. |
143 decryptor_->StopVideoDecoder(); | 143 decryptor_->DeinitializeDecoder(Decryptor::kVideo); |
144 DCHECK(!init_cb_.is_null() || !read_cb_.is_null()); | 144 DCHECK(!init_cb_.is_null() || !read_cb_.is_null()); |
145 break; | 145 break; |
146 default: | 146 default: |
147 NOTREACHED(); | 147 NOTREACHED(); |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 DecryptingVideoDecoder::~DecryptingVideoDecoder() { | 151 DecryptingVideoDecoder::~DecryptingVideoDecoder() { |
152 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; | 152 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; |
153 } | 153 } |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 } | 421 } |
422 | 422 |
423 void DecryptingVideoDecoder::DoStop() { | 423 void DecryptingVideoDecoder::DoStop() { |
424 DCHECK(init_cb_.is_null()); | 424 DCHECK(init_cb_.is_null()); |
425 DCHECK(read_cb_.is_null()); | 425 DCHECK(read_cb_.is_null()); |
426 state_ = kStopped; | 426 state_ = kStopped; |
427 base::ResetAndReturn(&stop_cb_).Run(); | 427 base::ResetAndReturn(&stop_cb_).Run(); |
428 } | 428 } |
429 | 429 |
430 } // namespace media | 430 } // namespace media |
OLD | NEW |