| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 reset_cb_.Reset(); | 200 reset_cb_.Reset(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { | 203 void FFmpegVideoDecoder::Stop(const base::Closure& closure) { |
| 204 if (!message_loop_->BelongsToCurrentThread()) { | 204 if (!message_loop_->BelongsToCurrentThread()) { |
| 205 message_loop_->PostTask(FROM_HERE, base::Bind( | 205 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 206 &FFmpegVideoDecoder::Stop, this, closure)); | 206 &FFmpegVideoDecoder::Stop, this, closure)); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 | 209 |
| 210 if (state_ == kUninitialized) { |
| 211 closure.Run(); |
| 212 return; |
| 213 } |
| 214 |
| 210 if (decryptor_) | 215 if (decryptor_) |
| 211 decryptor_->CancelDecrypt(); | 216 decryptor_->CancelDecrypt(); |
| 212 | 217 |
| 213 stop_cb_ = closure; | 218 stop_cb_ = closure; |
| 214 | 219 |
| 215 // Defer stopping if a read is pending. | 220 // Defer stopping if a read is pending. |
| 216 if (!read_cb_.is_null()) | 221 if (!read_cb_.is_null()) |
| 217 return; | 222 return; |
| 218 | 223 |
| 219 DoStop(); | 224 DoStop(); |
| 220 } | 225 } |
| 221 | 226 |
| 222 void FFmpegVideoDecoder::DoStop() { | 227 void FFmpegVideoDecoder::DoStop() { |
| 223 ReleaseFFmpegResources(); | 228 ReleaseFFmpegResources(); |
| 224 state_ = kUninitialized; | 229 state_ = kUninitialized; |
| 225 base::ResetAndReturn(&stop_cb_).Run(); | 230 base::ResetAndReturn(&stop_cb_).Run(); |
| 226 } | 231 } |
| 227 | 232 |
| 228 FFmpegVideoDecoder::~FFmpegVideoDecoder() { | 233 FFmpegVideoDecoder::~FFmpegVideoDecoder() { |
| 229 ReleaseFFmpegResources(); | 234 DCHECK_EQ(kUninitialized, state_); |
| 235 DCHECK(!codec_context_); |
| 236 DCHECK(!av_frame_); |
| 230 } | 237 } |
| 231 | 238 |
| 232 void FFmpegVideoDecoder::DoRead(const ReadCB& read_cb) { | 239 void FFmpegVideoDecoder::DoRead(const ReadCB& read_cb) { |
| 233 DCHECK(message_loop_->BelongsToCurrentThread()); | 240 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 234 DCHECK(!read_cb.is_null()); | 241 DCHECK(!read_cb.is_null()); |
| 235 CHECK_NE(state_, kUninitialized); | 242 CHECK_NE(state_, kUninitialized); |
| 236 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; | 243 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; |
| 237 | 244 |
| 238 // Return empty frames if decoding has finished. | 245 // Return empty frames if decoding has finished. |
| 239 if (state_ == kDecodeFinished) { | 246 if (state_ == kDecodeFinished) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 // for damaged macroblocks, and set our error detection sensitivity. | 528 // for damaged macroblocks, and set our error detection sensitivity. |
| 522 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; | 529 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; |
| 523 codec_context_->err_recognition = AV_EF_CAREFUL; | 530 codec_context_->err_recognition = AV_EF_CAREFUL; |
| 524 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); | 531 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); |
| 525 codec_context_->opaque = this; | 532 codec_context_->opaque = this; |
| 526 codec_context_->flags |= CODEC_FLAG_EMU_EDGE; | 533 codec_context_->flags |= CODEC_FLAG_EMU_EDGE; |
| 527 codec_context_->get_buffer = GetVideoBufferImpl; | 534 codec_context_->get_buffer = GetVideoBufferImpl; |
| 528 codec_context_->release_buffer = ReleaseVideoBufferImpl; | 535 codec_context_->release_buffer = ReleaseVideoBufferImpl; |
| 529 | 536 |
| 530 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); | 537 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
| 531 if (!codec) | 538 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { |
| 539 ReleaseFFmpegResources(); |
| 532 return false; | 540 return false; |
| 533 | 541 } |
| 534 if (avcodec_open2(codec_context_, codec, NULL) < 0) | |
| 535 return false; | |
| 536 | 542 |
| 537 av_frame_ = avcodec_alloc_frame(); | 543 av_frame_ = avcodec_alloc_frame(); |
| 538 return true; | 544 return true; |
| 539 } | 545 } |
| 540 | 546 |
| 541 } // namespace media | 547 } // namespace media |
| OLD | NEW |