Chromium Code Reviews| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 &FFmpegVideoDecoder::DoRead, this, read_cb)); | 172 &FFmpegVideoDecoder::DoRead, this, read_cb)); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void FFmpegVideoDecoder::Reset(const base::Closure& closure) { | 175 void FFmpegVideoDecoder::Reset(const base::Closure& closure) { |
| 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 if (decryptor_) | |
| 183 decryptor_->Stop(); | |
|
xhwang
2012/09/22 01:00:49
Maybe rename Decryptor::Stop() to something like F
scherkus (not reviewing)
2012/09/23 20:01:16
Agreed as Stop() is implies there's a Start() -- F
xhwang
2012/09/24 17:27:01
Renamed Stop() to CancelDecrypt(). I know CancelDe
scherkus (not reviewing)
2012/09/24 20:22:33
SGTM
| |
| 184 | |
| 182 reset_cb_ = closure; | 185 reset_cb_ = closure; |
| 183 | 186 |
| 184 // Defer the reset if a read is pending. | 187 // Defer the reset if a read is pending. |
| 185 if (!read_cb_.is_null()) | 188 if (!read_cb_.is_null()) |
| 186 return; | 189 return; |
| 187 | 190 |
| 188 DoReset(); | 191 DoReset(); |
| 189 } | 192 } |
| 190 | 193 |
| 191 void FFmpegVideoDecoder::DoReset() { | 194 void FFmpegVideoDecoder::DoReset() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 // Return empty frames if decoding has finished. | 242 // Return empty frames if decoding has finished. |
| 240 if (state_ == kDecodeFinished) { | 243 if (state_ == kDecodeFinished) { |
| 241 read_cb.Run(kOk, VideoFrame::CreateEmptyFrame()); | 244 read_cb.Run(kOk, VideoFrame::CreateEmptyFrame()); |
| 242 return; | 245 return; |
| 243 } | 246 } |
| 244 | 247 |
| 245 read_cb_ = read_cb; | 248 read_cb_ = read_cb; |
| 246 ReadFromDemuxerStream(); | 249 ReadFromDemuxerStream(); |
| 247 } | 250 } |
| 248 | 251 |
| 249 | |
| 250 void FFmpegVideoDecoder::ReadFromDemuxerStream() { | 252 void FFmpegVideoDecoder::ReadFromDemuxerStream() { |
| 251 DCHECK_NE(state_, kUninitialized); | 253 DCHECK_NE(state_, kUninitialized); |
| 252 DCHECK_NE(state_, kDecodeFinished); | 254 DCHECK_NE(state_, kDecodeFinished); |
| 253 DCHECK(!read_cb_.is_null()); | 255 DCHECK(!read_cb_.is_null()); |
| 254 | 256 |
| 255 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecryptOrDecodeBuffer, | 257 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecryptOrDecodeBuffer, |
| 256 this)); | 258 this)); |
| 257 } | 259 } |
| 258 | 260 |
| 259 void FFmpegVideoDecoder::DecryptOrDecodeBuffer( | 261 void FFmpegVideoDecoder::DecryptOrDecodeBuffer( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 } | 322 } |
| 321 | 323 |
| 322 void FFmpegVideoDecoder::DoBufferDecrypted( | 324 void FFmpegVideoDecoder::DoBufferDecrypted( |
| 323 Decryptor::Status decrypt_status, | 325 Decryptor::Status decrypt_status, |
| 324 const scoped_refptr<DecoderBuffer>& buffer) { | 326 const scoped_refptr<DecoderBuffer>& buffer) { |
| 325 DCHECK(message_loop_->BelongsToCurrentThread()); | 327 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 326 DCHECK_NE(state_, kUninitialized); | 328 DCHECK_NE(state_, kUninitialized); |
| 327 DCHECK_NE(state_, kDecodeFinished); | 329 DCHECK_NE(state_, kDecodeFinished); |
| 328 DCHECK(!read_cb_.is_null()); | 330 DCHECK(!read_cb_.is_null()); |
| 329 | 331 |
| 332 if (!stop_cb_.is_null()) { | |
| 333 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); | |
| 334 DoStop(); | |
| 335 return; | |
| 336 } | |
| 337 | |
| 330 if (!reset_cb_.is_null()) { | 338 if (!reset_cb_.is_null()) { |
| 331 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); | 339 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); |
| 332 DoReset(); | 340 DoReset(); |
| 333 return; | 341 return; |
| 334 } | 342 } |
| 335 | 343 |
| 336 if (decrypt_status == Decryptor::kNoKey || | 344 if (decrypt_status == Decryptor::kNoKey || |
| 337 decrypt_status == Decryptor::kError) { | 345 decrypt_status == Decryptor::kError) { |
| 338 state_ = kDecodeFinished; | 346 state_ = kDecodeFinished; |
| 339 base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL); | 347 base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 return false; | 536 return false; |
| 529 | 537 |
| 530 if (avcodec_open2(codec_context_, codec, NULL) < 0) | 538 if (avcodec_open2(codec_context_, codec, NULL) < 0) |
| 531 return false; | 539 return false; |
| 532 | 540 |
| 533 av_frame_ = avcodec_alloc_frame(); | 541 av_frame_ = avcodec_alloc_frame(); |
| 534 return true; | 542 return true; |
| 535 } | 543 } |
| 536 | 544 |
| 537 } // namespace media | 545 } // namespace media |
| OLD | NEW |