| 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_->CancelDecrypt(); |
| 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() { |
| 192 DCHECK(read_cb_.is_null()); | 195 DCHECK(read_cb_.is_null()); |
| 193 | 196 |
| 194 avcodec_flush_buffers(codec_context_); | 197 avcodec_flush_buffers(codec_context_); |
| 195 state_ = kNormal; | 198 state_ = kNormal; |
| 196 reset_cb_.Run(); | 199 reset_cb_.Run(); |
| 197 reset_cb_.Reset(); | 200 reset_cb_.Reset(); |
| 198 } | 201 } |
| 199 | 202 |
| 200 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { | 203 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { |
| 201 if (!message_loop_->BelongsToCurrentThread()) { | 204 if (!message_loop_->BelongsToCurrentThread()) { |
| 202 message_loop_->PostTask(FROM_HERE, base::Bind( | 205 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 203 &FFmpegVideoDecoder::Stop, this, closure)); | 206 &FFmpegVideoDecoder::Stop, this, closure)); |
| 204 return; | 207 return; |
| 205 } | 208 } |
| 206 | 209 |
| 207 if (decryptor_) | 210 if (decryptor_) |
| 208 decryptor_->Stop(); | 211 decryptor_->CancelDecrypt(); |
| 209 | 212 |
| 210 stop_cb_ = closure; | 213 stop_cb_ = closure; |
| 211 | 214 |
| 212 // Defer stopping if a read is pending. | 215 // Defer stopping if a read is pending. |
| 213 if (!read_cb_.is_null()) | 216 if (!read_cb_.is_null()) |
| 214 return; | 217 return; |
| 215 | 218 |
| 216 DoStop(); | 219 DoStop(); |
| 217 } | 220 } |
| 218 | 221 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 318 } |
| 316 | 319 |
| 317 void FFmpegVideoDecoder::DoBufferDecrypted( | 320 void FFmpegVideoDecoder::DoBufferDecrypted( |
| 318 Decryptor::Status decrypt_status, | 321 Decryptor::Status decrypt_status, |
| 319 const scoped_refptr<DecoderBuffer>& buffer) { | 322 const scoped_refptr<DecoderBuffer>& buffer) { |
| 320 DCHECK(message_loop_->BelongsToCurrentThread()); | 323 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 321 DCHECK_NE(state_, kUninitialized); | 324 DCHECK_NE(state_, kUninitialized); |
| 322 DCHECK_NE(state_, kDecodeFinished); | 325 DCHECK_NE(state_, kDecodeFinished); |
| 323 DCHECK(!read_cb_.is_null()); | 326 DCHECK(!read_cb_.is_null()); |
| 324 | 327 |
| 328 if (!stop_cb_.is_null()) { |
| 329 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); |
| 330 DoStop(); |
| 331 return; |
| 332 } |
| 333 |
| 325 if (!reset_cb_.is_null()) { | 334 if (!reset_cb_.is_null()) { |
| 326 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); | 335 base::ResetAndReturn(&read_cb_).Run(kOk, NULL); |
| 327 DoReset(); | 336 DoReset(); |
| 328 return; | 337 return; |
| 329 } | 338 } |
| 330 | 339 |
| 331 if (decrypt_status == Decryptor::kNoKey || | 340 if (decrypt_status == Decryptor::kNoKey || |
| 332 decrypt_status == Decryptor::kError) { | 341 decrypt_status == Decryptor::kError) { |
| 333 state_ = kDecodeFinished; | 342 state_ = kDecodeFinished; |
| 334 base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL); | 343 base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 return false; | 532 return false; |
| 524 | 533 |
| 525 if (avcodec_open2(codec_context_, codec, NULL) < 0) | 534 if (avcodec_open2(codec_context_, codec, NULL) < 0) |
| 526 return false; | 535 return false; |
| 527 | 536 |
| 528 av_frame_ = avcodec_alloc_frame(); | 537 av_frame_ = avcodec_alloc_frame(); |
| 529 return true; | 538 return true; |
| 530 } | 539 } |
| 531 | 540 |
| 532 } // namespace media | 541 } // namespace media |
| OLD | NEW |