| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 234 } |
| 235 | 235 |
| 236 void FFmpegVideoDecoder::Reset(const base::Closure& closure) { | 236 void FFmpegVideoDecoder::Reset(const base::Closure& closure) { |
| 237 DCHECK(task_runner_->BelongsToCurrentThread()); | 237 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 238 | 238 |
| 239 avcodec_flush_buffers(codec_context_.get()); | 239 avcodec_flush_buffers(codec_context_.get()); |
| 240 state_ = kNormal; | 240 state_ = kNormal; |
| 241 task_runner_->PostTask(FROM_HERE, closure); | 241 task_runner_->PostTask(FROM_HERE, closure); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void FFmpegVideoDecoder::Stop() { | 244 FFmpegVideoDecoder::~FFmpegVideoDecoder() { |
| 245 DCHECK(task_runner_->BelongsToCurrentThread()); | 245 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 246 | 246 |
| 247 if (state_ == kUninitialized) | 247 if (state_ != kUninitialized) { |
| 248 return; | 248 ReleaseFFmpegResources(); |
| 249 | 249 state_ = kUninitialized; |
| 250 ReleaseFFmpegResources(); | 250 } |
| 251 state_ = kUninitialized; | |
| 252 } | |
| 253 | |
| 254 FFmpegVideoDecoder::~FFmpegVideoDecoder() { | |
| 255 DCHECK_EQ(kUninitialized, state_); | |
| 256 DCHECK(!codec_context_); | |
| 257 DCHECK(!av_frame_); | |
| 258 } | 251 } |
| 259 | 252 |
| 260 bool FFmpegVideoDecoder::FFmpegDecode( | 253 bool FFmpegVideoDecoder::FFmpegDecode( |
| 261 const scoped_refptr<DecoderBuffer>& buffer, | 254 const scoped_refptr<DecoderBuffer>& buffer, |
| 262 bool* has_produced_frame) { | 255 bool* has_produced_frame) { |
| 263 DCHECK(!*has_produced_frame); | 256 DCHECK(!*has_produced_frame); |
| 264 | 257 |
| 265 // Create a packet for input data. | 258 // Create a packet for input data. |
| 266 // Due to FFmpeg API changes we no longer have const read-only pointers. | 259 // Due to FFmpeg API changes we no longer have const read-only pointers. |
| 267 AVPacket packet; | 260 AVPacket packet; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { | 343 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { |
| 351 ReleaseFFmpegResources(); | 344 ReleaseFFmpegResources(); |
| 352 return false; | 345 return false; |
| 353 } | 346 } |
| 354 | 347 |
| 355 av_frame_.reset(av_frame_alloc()); | 348 av_frame_.reset(av_frame_alloc()); |
| 356 return true; | 349 return true; |
| 357 } | 350 } |
| 358 | 351 |
| 359 } // namespace media | 352 } // namespace media |
| OLD | NEW |