| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 void FFmpegVideoDecoder::ReadFromDemuxerStream() { | 211 void FFmpegVideoDecoder::ReadFromDemuxerStream() { |
| 212 DCHECK_NE(state_, kUninitialized); | 212 DCHECK_NE(state_, kUninitialized); |
| 213 DCHECK_NE(state_, kDecodeFinished); | 213 DCHECK_NE(state_, kDecodeFinished); |
| 214 DCHECK(!read_cb_.is_null()); | 214 DCHECK(!read_cb_.is_null()); |
| 215 | 215 |
| 216 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this)); | 216 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this)); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void FFmpegVideoDecoder::DecodeBuffer( | 219 void FFmpegVideoDecoder::DecodeBuffer( |
| 220 const scoped_refptr<DecoderBuffer>& buffer) { | 220 DemuxerStream::Status status, const scoped_refptr<DecoderBuffer>& buffer) { |
| 221 DCHECK_EQ(status != DemuxerStream::kOk, !buffer); |
| 222 |
| 221 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read | 223 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read |
| 222 // callback on the same execution stack so we can get rid of forced task post. | 224 // callback on the same execution stack so we can get rid of forced task post. |
| 223 message_loop_->PostTask(FROM_HERE, base::Bind( | 225 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 224 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer)); | 226 &FFmpegVideoDecoder::DoDecodeBuffer, this, status, buffer)); |
| 225 } | 227 } |
| 226 | 228 |
| 227 void FFmpegVideoDecoder::DoDecodeBuffer( | 229 void FFmpegVideoDecoder::DoDecodeBuffer( |
| 228 const scoped_refptr<DecoderBuffer>& buffer) { | 230 DemuxerStream::Status status, const scoped_refptr<DecoderBuffer>& buffer) { |
| 229 DCHECK_EQ(MessageLoop::current(), message_loop_); | 231 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 230 DCHECK_NE(state_, kUninitialized); | 232 DCHECK_NE(state_, kUninitialized); |
| 231 DCHECK_NE(state_, kDecodeFinished); | 233 DCHECK_NE(state_, kDecodeFinished); |
| 232 DCHECK(!read_cb_.is_null()); | 234 DCHECK(!read_cb_.is_null()); |
| 233 | 235 |
| 234 if (!reset_cb_.is_null()) { | 236 if (!reset_cb_.is_null()) { |
| 235 DeliverFrame(NULL); | 237 DeliverFrame(NULL); |
| 236 DoReset(); | 238 DoReset(); |
| 237 return; | 239 return; |
| 238 } | 240 } |
| 239 | 241 |
| 240 if (!buffer) { | 242 if (status != DemuxerStream::kOk) { |
| 241 DeliverFrame(NULL); | 243 // TODO(acolwell): Add support for reinitializing the decoder when |
| 244 // |status| == kConfigChanged. For now we just trigger a decode error. |
| 245 DecoderStatus decoder_status = |
| 246 (status == DemuxerStream::kAborted) ? kOk : kDecodeError; |
| 247 base::ResetAndReturn(&read_cb_).Run(decoder_status, NULL); |
| 242 return; | 248 return; |
| 243 } | 249 } |
| 244 | 250 |
| 245 // During decode, because reads are issued asynchronously, it is possible to | 251 // During decode, because reads are issued asynchronously, it is possible to |
| 246 // receive multiple end of stream buffers since each read is acked. When the | 252 // receive multiple end of stream buffers since each read is acked. When the |
| 247 // first end of stream buffer is read, FFmpeg may still have frames queued | 253 // first end of stream buffer is read, FFmpeg may still have frames queued |
| 248 // up in the decoder so we need to go through the decode loop until it stops | 254 // up in the decoder so we need to go through the decode loop until it stops |
| 249 // giving sensible data. After that, the decoder should output empty | 255 // giving sensible data. After that, the decoder should output empty |
| 250 // frames. There are three states the decoder can be in: | 256 // frames. There are three states the decoder can be in: |
| 251 // | 257 // |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { | 439 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { |
| 434 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); | 440 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); |
| 435 size_t width = codec_context_->width; | 441 size_t width = codec_context_->width; |
| 436 size_t height = codec_context_->height; | 442 size_t height = codec_context_->height; |
| 437 | 443 |
| 438 return VideoFrame::CreateFrame(format, width, height, | 444 return VideoFrame::CreateFrame(format, width, height, |
| 439 kNoTimestamp(), kNoTimestamp()); | 445 kNoTimestamp(), kNoTimestamp()); |
| 440 } | 446 } |
| 441 | 447 |
| 442 } // namespace media | 448 } // namespace media |
| OLD | NEW |