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/ffmpeg_video_decoder.h" | 5 #include "media/filters/ffmpeg_video_decoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 if (!message_loop_->BelongsToCurrentThread()) { | 176 if (!message_loop_->BelongsToCurrentThread()) { |
177 message_loop_->PostTask(FROM_HERE, base::Bind( | 177 message_loop_->PostTask(FROM_HERE, base::Bind( |
178 &FFmpegVideoDecoder::Reset, this, closure)); | 178 &FFmpegVideoDecoder::Reset, this, closure)); |
179 return; | 179 return; |
180 } | 180 } |
181 | 181 |
182 DCHECK(reset_cb_.is_null()); | 182 DCHECK(reset_cb_.is_null()); |
183 reset_cb_ = closure; | 183 reset_cb_ = closure; |
184 | 184 |
185 if (decryptor_) | 185 if (decryptor_) |
186 decryptor_->CancelDecrypt(); | 186 decryptor_->CancelDecrypt(Decryptor::kVideo); |
187 | 187 |
188 // Defer the reset if a read is pending. | 188 // Defer the reset if a read is pending. |
189 if (!read_cb_.is_null()) | 189 if (!read_cb_.is_null()) |
190 return; | 190 return; |
191 | 191 |
192 DoReset(); | 192 DoReset(); |
193 } | 193 } |
194 | 194 |
195 void FFmpegVideoDecoder::DoReset() { | 195 void FFmpegVideoDecoder::DoReset() { |
196 DCHECK(read_cb_.is_null()); | 196 DCHECK(read_cb_.is_null()); |
(...skipping 10 matching lines...) Expand all Loading... |
207 &FFmpegVideoDecoder::Stop, this, closure)); | 207 &FFmpegVideoDecoder::Stop, this, closure)); |
208 return; | 208 return; |
209 } | 209 } |
210 | 210 |
211 if (state_ == kUninitialized) { | 211 if (state_ == kUninitialized) { |
212 closure.Run(); | 212 closure.Run(); |
213 return; | 213 return; |
214 } | 214 } |
215 | 215 |
216 if (decryptor_) | 216 if (decryptor_) |
217 decryptor_->CancelDecrypt(); | 217 decryptor_->CancelDecrypt(Decryptor::kVideo); |
218 | 218 |
219 if (!read_cb_.is_null()) | 219 if (!read_cb_.is_null()) |
220 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); | 220 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); |
221 | 221 |
222 ReleaseFFmpegResources(); | 222 ReleaseFFmpegResources(); |
223 state_ = kUninitialized; | 223 state_ = kUninitialized; |
224 closure.Run(); | 224 closure.Run(); |
225 } | 225 } |
226 | 226 |
227 FFmpegVideoDecoder::~FFmpegVideoDecoder() { | 227 FFmpegVideoDecoder::~FFmpegVideoDecoder() { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 return; | 293 return; |
294 } | 294 } |
295 | 295 |
296 ReadFromDemuxerStream(); | 296 ReadFromDemuxerStream(); |
297 return; | 297 return; |
298 } | 298 } |
299 | 299 |
300 DCHECK_EQ(status, DemuxerStream::kOk); | 300 DCHECK_EQ(status, DemuxerStream::kOk); |
301 | 301 |
302 if (buffer->GetDecryptConfig() && buffer->GetDataSize()) { | 302 if (buffer->GetDecryptConfig() && buffer->GetDataSize()) { |
303 decryptor_->Decrypt(buffer, | 303 decryptor_->Decrypt(Decryptor::kVideo, |
| 304 buffer, |
304 base::Bind(&FFmpegVideoDecoder::BufferDecrypted, this)); | 305 base::Bind(&FFmpegVideoDecoder::BufferDecrypted, this)); |
305 return; | 306 return; |
306 } | 307 } |
307 | 308 |
308 DecodeBuffer(buffer); | 309 DecodeBuffer(buffer); |
309 } | 310 } |
310 | 311 |
311 void FFmpegVideoDecoder::BufferDecrypted( | 312 void FFmpegVideoDecoder::BufferDecrypted( |
312 Decryptor::Status decrypt_status, | 313 Decryptor::Status decrypt_status, |
313 const scoped_refptr<DecoderBuffer>& buffer) { | 314 const scoped_refptr<DecoderBuffer>& buffer) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { | 527 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { |
527 ReleaseFFmpegResources(); | 528 ReleaseFFmpegResources(); |
528 return false; | 529 return false; |
529 } | 530 } |
530 | 531 |
531 av_frame_ = avcodec_alloc_frame(); | 532 av_frame_ = avcodec_alloc_frame(); |
532 return true; | 533 return true; |
533 } | 534 } |
534 | 535 |
535 } // namespace media | 536 } // namespace media |
OLD | NEW |