Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: media/filters/decrypting_video_decoder.cc

Issue 20136002: Reland r212023 "Rename VideoDecoder::ReadCB to VideoDecoder::DecodeCB." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix content_browsertests failure. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 20 matching lines...) Expand all
31 trace_id_(0) { 31 trace_id_(0) {
32 } 32 }
33 33
34 void DecryptingVideoDecoder::Initialize(const VideoDecoderConfig& config, 34 void DecryptingVideoDecoder::Initialize(const VideoDecoderConfig& config,
35 const PipelineStatusCB& status_cb) { 35 const PipelineStatusCB& status_cb) {
36 DVLOG(2) << "Initialize()"; 36 DVLOG(2) << "Initialize()";
37 DCHECK(message_loop_->BelongsToCurrentThread()); 37 DCHECK(message_loop_->BelongsToCurrentThread());
38 DCHECK(state_ == kUninitialized || 38 DCHECK(state_ == kUninitialized ||
39 state_ == kIdle || 39 state_ == kIdle ||
40 state_ == kDecodeFinished) << state_; 40 state_ == kDecodeFinished) << state_;
41 DCHECK(read_cb_.is_null()); 41 DCHECK(decode_cb_.is_null());
42 DCHECK(reset_cb_.is_null()); 42 DCHECK(reset_cb_.is_null());
43 DCHECK(config.IsValidConfig()); 43 DCHECK(config.IsValidConfig());
44 DCHECK(config.is_encrypted()); 44 DCHECK(config.is_encrypted());
45 45
46 init_cb_ = BindToCurrentLoop(status_cb); 46 init_cb_ = BindToCurrentLoop(status_cb);
47 weak_this_ = weak_factory_.GetWeakPtr(); 47 weak_this_ = weak_factory_.GetWeakPtr();
48 config_ = config; 48 config_ = config;
49 49
50 if (state_ == kUninitialized) { 50 if (state_ == kUninitialized) {
51 state_ = kDecryptorRequested; 51 state_ = kDecryptorRequested;
52 set_decryptor_ready_cb_.Run(BindToCurrentLoop(base::Bind( 52 set_decryptor_ready_cb_.Run(BindToCurrentLoop(base::Bind(
53 &DecryptingVideoDecoder::SetDecryptor, weak_this_))); 53 &DecryptingVideoDecoder::SetDecryptor, weak_this_)));
54 return; 54 return;
55 } 55 }
56 56
57 // Reinitialization. 57 // Reinitialization.
58 decryptor_->DeinitializeDecoder(Decryptor::kVideo); 58 decryptor_->DeinitializeDecoder(Decryptor::kVideo);
59 state_ = kPendingDecoderInit; 59 state_ = kPendingDecoderInit;
60 decryptor_->InitializeVideoDecoder(config, BindToCurrentLoop(base::Bind( 60 decryptor_->InitializeVideoDecoder(config, BindToCurrentLoop(base::Bind(
61 &DecryptingVideoDecoder::FinishInitialization, weak_this_))); 61 &DecryptingVideoDecoder::FinishInitialization, weak_this_)));
62 } 62 }
63 63
64 void DecryptingVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 64 void DecryptingVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
65 const ReadCB& read_cb) { 65 const DecodeCB& decode_cb) {
66 DVLOG(3) << "Decode()"; 66 DVLOG(3) << "Decode()";
67 DCHECK(message_loop_->BelongsToCurrentThread()); 67 DCHECK(message_loop_->BelongsToCurrentThread());
68 DCHECK(state_ == kIdle || 68 DCHECK(state_ == kIdle ||
69 state_ == kDecodeFinished || 69 state_ == kDecodeFinished ||
70 state_ == kError) << state_; 70 state_ == kError) << state_;
71 DCHECK(!read_cb.is_null()); 71 DCHECK(!decode_cb.is_null());
72 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; 72 CHECK(decode_cb_.is_null()) << "Overlapping decodes are not supported.";
73 73
74 read_cb_ = BindToCurrentLoop(read_cb); 74 decode_cb_ = BindToCurrentLoop(decode_cb);
75 75
76 if (state_ == kError) { 76 if (state_ == kError) {
77 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); 77 base::ResetAndReturn(&decode_cb_).Run(kDecodeError, NULL);
78 return; 78 return;
79 } 79 }
80 80
81 // Return empty frames if decoding has finished. 81 // Return empty frames if decoding has finished.
82 if (state_ == kDecodeFinished) { 82 if (state_ == kDecodeFinished) {
83 base::ResetAndReturn(&read_cb_).Run(kOk, VideoFrame::CreateEmptyFrame()); 83 base::ResetAndReturn(&decode_cb_).Run(kOk, VideoFrame::CreateEmptyFrame());
84 return; 84 return;
85 } 85 }
86 86
87 pending_buffer_to_decode_ = buffer; 87 pending_buffer_to_decode_ = buffer;
88 state_ = kPendingDecode; 88 state_ = kPendingDecode;
89 DecodePendingBuffer(); 89 DecodePendingBuffer();
90 } 90 }
91 91
92 void DecryptingVideoDecoder::Reset(const base::Closure& closure) { 92 void DecryptingVideoDecoder::Reset(const base::Closure& closure) {
93 DVLOG(2) << "Reset() - state: " << state_; 93 DVLOG(2) << "Reset() - state: " << state_;
94 DCHECK(message_loop_->BelongsToCurrentThread()); 94 DCHECK(message_loop_->BelongsToCurrentThread());
95 DCHECK(state_ == kIdle || 95 DCHECK(state_ == kIdle ||
96 state_ == kPendingDecode || 96 state_ == kPendingDecode ||
97 state_ == kWaitingForKey || 97 state_ == kWaitingForKey ||
98 state_ == kDecodeFinished || 98 state_ == kDecodeFinished ||
99 state_ == kError) << state_; 99 state_ == kError) << state_;
100 DCHECK(init_cb_.is_null()); // No Reset() during pending initialization. 100 DCHECK(init_cb_.is_null()); // No Reset() during pending initialization.
101 DCHECK(reset_cb_.is_null()); 101 DCHECK(reset_cb_.is_null());
102 102
103 reset_cb_ = BindToCurrentLoop(closure); 103 reset_cb_ = BindToCurrentLoop(closure);
104 104
105 decryptor_->ResetDecoder(Decryptor::kVideo); 105 decryptor_->ResetDecoder(Decryptor::kVideo);
106 106
107 // Reset() cannot complete if the read callback is still pending. 107 // Reset() cannot complete if the decode callback is still pending.
108 // Defer the resetting process in this case. The |reset_cb_| will be fired 108 // Defer the resetting process in this case. The |reset_cb_| will be fired
109 // after the read callback is fired - see DecryptAndDecodeBuffer() and 109 // after the decode callback is fired - see DecryptAndDecodeBuffer() and
110 // DeliverFrame(). 110 // DeliverFrame().
111 if (state_ == kPendingDecode) { 111 if (state_ == kPendingDecode) {
112 DCHECK(!read_cb_.is_null()); 112 DCHECK(!decode_cb_.is_null());
113 return; 113 return;
114 } 114 }
115 115
116 if (state_ == kWaitingForKey) { 116 if (state_ == kWaitingForKey) {
117 DCHECK(!read_cb_.is_null()); 117 DCHECK(!decode_cb_.is_null());
118 pending_buffer_to_decode_ = NULL; 118 pending_buffer_to_decode_ = NULL;
119 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); 119 base::ResetAndReturn(&decode_cb_).Run(kOk, NULL);
120 } 120 }
121 121
122 DCHECK(read_cb_.is_null()); 122 DCHECK(decode_cb_.is_null());
123 DoReset(); 123 DoReset();
124 } 124 }
125 125
126 void DecryptingVideoDecoder::Stop(const base::Closure& closure) { 126 void DecryptingVideoDecoder::Stop(const base::Closure& closure) {
127 DCHECK(message_loop_->BelongsToCurrentThread()); 127 DCHECK(message_loop_->BelongsToCurrentThread());
128 DVLOG(2) << "Stop() - state: " << state_; 128 DVLOG(2) << "Stop() - state: " << state_;
129 129
130 // At this point the render thread is likely paused (in WebMediaPlayerImpl's 130 // At this point the render thread is likely paused (in WebMediaPlayerImpl's
131 // Destroy()), so running |closure| can't wait for anything that requires the 131 // Destroy()), so running |closure| can't wait for anything that requires the
132 // render thread to be processing messages to complete (such as PPAPI 132 // render thread to be processing messages to complete (such as PPAPI
133 // callbacks). 133 // callbacks).
134 if (decryptor_) { 134 if (decryptor_) {
135 decryptor_->RegisterNewKeyCB(Decryptor::kVideo, Decryptor::NewKeyCB()); 135 decryptor_->RegisterNewKeyCB(Decryptor::kVideo, Decryptor::NewKeyCB());
136 decryptor_->DeinitializeDecoder(Decryptor::kVideo); 136 decryptor_->DeinitializeDecoder(Decryptor::kVideo);
137 decryptor_ = NULL; 137 decryptor_ = NULL;
138 } 138 }
139 if (!set_decryptor_ready_cb_.is_null()) 139 if (!set_decryptor_ready_cb_.is_null())
140 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB()); 140 base::ResetAndReturn(&set_decryptor_ready_cb_).Run(DecryptorReadyCB());
141 pending_buffer_to_decode_ = NULL; 141 pending_buffer_to_decode_ = NULL;
142 if (!init_cb_.is_null()) 142 if (!init_cb_.is_null())
143 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 143 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
144 if (!read_cb_.is_null()) 144 if (!decode_cb_.is_null())
145 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); 145 base::ResetAndReturn(&decode_cb_).Run(kOk, NULL);
146 if (!reset_cb_.is_null()) 146 if (!reset_cb_.is_null())
147 base::ResetAndReturn(&reset_cb_).Run(); 147 base::ResetAndReturn(&reset_cb_).Run();
148 state_ = kStopped; 148 state_ = kStopped;
149 BindToCurrentLoop(closure).Run(); 149 BindToCurrentLoop(closure).Run();
150 } 150 }
151 151
152 DecryptingVideoDecoder::~DecryptingVideoDecoder() { 152 DecryptingVideoDecoder::~DecryptingVideoDecoder() {
153 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_; 153 DCHECK(state_ == kUninitialized || state_ == kStopped) << state_;
154 } 154 }
155 155
(...skipping 27 matching lines...) Expand all
183 void DecryptingVideoDecoder::FinishInitialization(bool success) { 183 void DecryptingVideoDecoder::FinishInitialization(bool success) {
184 DVLOG(2) << "FinishInitialization()"; 184 DVLOG(2) << "FinishInitialization()";
185 DCHECK(message_loop_->BelongsToCurrentThread()); 185 DCHECK(message_loop_->BelongsToCurrentThread());
186 186
187 if (state_ == kStopped) 187 if (state_ == kStopped)
188 return; 188 return;
189 189
190 DCHECK_EQ(state_, kPendingDecoderInit) << state_; 190 DCHECK_EQ(state_, kPendingDecoderInit) << state_;
191 DCHECK(!init_cb_.is_null()); 191 DCHECK(!init_cb_.is_null());
192 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished. 192 DCHECK(reset_cb_.is_null()); // No Reset() before initialization finished.
193 DCHECK(read_cb_.is_null()); // No Read() before initialization finished. 193 DCHECK(decode_cb_.is_null()); // No Decode() before initialization finished.
194 194
195 if (!success) { 195 if (!success) {
196 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED); 196 base::ResetAndReturn(&init_cb_).Run(DECODER_ERROR_NOT_SUPPORTED);
197 state_ = kStopped; 197 state_ = kStopped;
198 return; 198 return;
199 } 199 }
200 200
201 decryptor_->RegisterNewKeyCB(Decryptor::kVideo, BindToCurrentLoop( 201 decryptor_->RegisterNewKeyCB(Decryptor::kVideo, BindToCurrentLoop(
202 base::Bind(&DecryptingVideoDecoder::OnKeyAdded, weak_this_))); 202 base::Bind(&DecryptingVideoDecoder::OnKeyAdded, weak_this_)));
203 203
(...skipping 25 matching lines...) Expand all
229 const scoped_refptr<VideoFrame>& frame) { 229 const scoped_refptr<VideoFrame>& frame) {
230 DVLOG(3) << "DeliverFrame() - status: " << status; 230 DVLOG(3) << "DeliverFrame() - status: " << status;
231 DCHECK(message_loop_->BelongsToCurrentThread()); 231 DCHECK(message_loop_->BelongsToCurrentThread());
232 TRACE_EVENT_ASYNC_END0( 232 TRACE_EVENT_ASYNC_END0(
233 "eme", "DecryptingVideoDecoder::DecodePendingBuffer", trace_id_); 233 "eme", "DecryptingVideoDecoder::DecodePendingBuffer", trace_id_);
234 234
235 if (state_ == kStopped) 235 if (state_ == kStopped)
236 return; 236 return;
237 237
238 DCHECK_EQ(state_, kPendingDecode) << state_; 238 DCHECK_EQ(state_, kPendingDecode) << state_;
239 DCHECK(!read_cb_.is_null()); 239 DCHECK(!decode_cb_.is_null());
240 DCHECK(pending_buffer_to_decode_.get()); 240 DCHECK(pending_buffer_to_decode_.get());
241 241
242 bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_; 242 bool need_to_try_again_if_nokey_is_returned = key_added_while_decode_pending_;
243 key_added_while_decode_pending_ = false; 243 key_added_while_decode_pending_ = false;
244 244
245 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode = 245 scoped_refptr<DecoderBuffer> scoped_pending_buffer_to_decode =
246 pending_buffer_to_decode_; 246 pending_buffer_to_decode_;
247 pending_buffer_to_decode_ = NULL; 247 pending_buffer_to_decode_ = NULL;
248 248
249 if (!reset_cb_.is_null()) { 249 if (!reset_cb_.is_null()) {
250 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); 250 base::ResetAndReturn(&decode_cb_).Run(kOk, NULL);
251 DoReset(); 251 DoReset();
252 return; 252 return;
253 } 253 }
254 254
255 DCHECK_EQ(status == Decryptor::kSuccess, frame.get() != NULL); 255 DCHECK_EQ(status == Decryptor::kSuccess, frame.get() != NULL);
256 256
257 if (status == Decryptor::kError) { 257 if (status == Decryptor::kError) {
258 DVLOG(2) << "DeliverFrame() - kError"; 258 DVLOG(2) << "DeliverFrame() - kError";
259 state_ = kError; 259 state_ = kError;
260 base::ResetAndReturn(&read_cb_).Run(kDecodeError, NULL); 260 base::ResetAndReturn(&decode_cb_).Run(kDecodeError, NULL);
261 return; 261 return;
262 } 262 }
263 263
264 if (status == Decryptor::kNoKey) { 264 if (status == Decryptor::kNoKey) {
265 DVLOG(2) << "DeliverFrame() - kNoKey"; 265 DVLOG(2) << "DeliverFrame() - kNoKey";
266 // Set |pending_buffer_to_decode_| back as we need to try decoding the 266 // Set |pending_buffer_to_decode_| back as we need to try decoding the
267 // pending buffer again when new key is added to the decryptor. 267 // pending buffer again when new key is added to the decryptor.
268 pending_buffer_to_decode_ = scoped_pending_buffer_to_decode; 268 pending_buffer_to_decode_ = scoped_pending_buffer_to_decode;
269 269
270 if (need_to_try_again_if_nokey_is_returned) { 270 if (need_to_try_again_if_nokey_is_returned) {
271 // The |state_| is still kPendingDecode. 271 // The |state_| is still kPendingDecode.
272 DecodePendingBuffer(); 272 DecodePendingBuffer();
273 return; 273 return;
274 } 274 }
275 275
276 state_ = kWaitingForKey; 276 state_ = kWaitingForKey;
277 return; 277 return;
278 } 278 }
279 279
280 if (status == Decryptor::kNeedMoreData) { 280 if (status == Decryptor::kNeedMoreData) {
281 DVLOG(2) << "DeliverFrame() - kNeedMoreData"; 281 DVLOG(2) << "DeliverFrame() - kNeedMoreData";
282 if (scoped_pending_buffer_to_decode->end_of_stream()) { 282 if (scoped_pending_buffer_to_decode->end_of_stream()) {
283 state_ = kDecodeFinished; 283 state_ = kDecodeFinished;
284 base::ResetAndReturn(&read_cb_).Run( 284 base::ResetAndReturn(&decode_cb_).Run(
285 kOk, media::VideoFrame::CreateEmptyFrame()); 285 kOk, media::VideoFrame::CreateEmptyFrame());
286 return; 286 return;
287 } 287 }
288 288
289 state_ = kIdle; 289 state_ = kIdle;
290 base::ResetAndReturn(&read_cb_).Run(kNotEnoughData, NULL); 290 base::ResetAndReturn(&decode_cb_).Run(kNotEnoughData, NULL);
291 return; 291 return;
292 } 292 }
293 293
294 DCHECK_EQ(status, Decryptor::kSuccess); 294 DCHECK_EQ(status, Decryptor::kSuccess);
295 // No frame returned with kSuccess should be end-of-stream frame. 295 // No frame returned with kSuccess should be end-of-stream frame.
296 DCHECK(!frame->IsEndOfStream()); 296 DCHECK(!frame->IsEndOfStream());
297 state_ = kIdle; 297 state_ = kIdle;
298 base::ResetAndReturn(&read_cb_).Run(kOk, frame); 298 base::ResetAndReturn(&decode_cb_).Run(kOk, frame);
299 } 299 }
300 300
301 void DecryptingVideoDecoder::OnKeyAdded() { 301 void DecryptingVideoDecoder::OnKeyAdded() {
302 DVLOG(2) << "OnKeyAdded()"; 302 DVLOG(2) << "OnKeyAdded()";
303 DCHECK(message_loop_->BelongsToCurrentThread()); 303 DCHECK(message_loop_->BelongsToCurrentThread());
304 304
305 if (state_ == kPendingDecode) { 305 if (state_ == kPendingDecode) {
306 key_added_while_decode_pending_ = true; 306 key_added_while_decode_pending_ = true;
307 return; 307 return;
308 } 308 }
309 309
310 if (state_ == kWaitingForKey) { 310 if (state_ == kWaitingForKey) {
311 state_ = kPendingDecode; 311 state_ = kPendingDecode;
312 DecodePendingBuffer(); 312 DecodePendingBuffer();
313 } 313 }
314 } 314 }
315 315
316 void DecryptingVideoDecoder::DoReset() { 316 void DecryptingVideoDecoder::DoReset() {
317 DCHECK(init_cb_.is_null()); 317 DCHECK(init_cb_.is_null());
318 DCHECK(read_cb_.is_null()); 318 DCHECK(decode_cb_.is_null());
319 state_ = kIdle; 319 state_ = kIdle;
320 base::ResetAndReturn(&reset_cb_).Run(); 320 base::ResetAndReturn(&reset_cb_).Run();
321 } 321 }
322 322
323 } // namespace media 323 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decrypting_video_decoder.h ('k') | media/filters/decrypting_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698