| 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" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "media/base/decoder_buffer.h" |
| 12 #include "media/base/demuxer_stream.h" | 13 #include "media/base/demuxer_stream.h" |
| 13 #include "media/base/limits.h" | 14 #include "media/base/limits.h" |
| 14 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
| 15 #include "media/base/pipeline.h" | 16 #include "media/base/pipeline.h" |
| 16 #include "media/base/video_decoder_config.h" | 17 #include "media/base/video_decoder_config.h" |
| 17 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
| 18 #include "media/base/video_util.h" | 19 #include "media/base/video_util.h" |
| 19 #include "media/ffmpeg/ffmpeg_common.h" | 20 #include "media/ffmpeg/ffmpeg_common.h" |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 202 |
| 202 | 203 |
| 203 void FFmpegVideoDecoder::ReadFromDemuxerStream() { | 204 void FFmpegVideoDecoder::ReadFromDemuxerStream() { |
| 204 DCHECK_NE(state_, kUninitialized); | 205 DCHECK_NE(state_, kUninitialized); |
| 205 DCHECK_NE(state_, kDecodeFinished); | 206 DCHECK_NE(state_, kDecodeFinished); |
| 206 DCHECK(!read_cb_.is_null()); | 207 DCHECK(!read_cb_.is_null()); |
| 207 | 208 |
| 208 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this)); | 209 demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::DecodeBuffer, this)); |
| 209 } | 210 } |
| 210 | 211 |
| 211 void FFmpegVideoDecoder::DecodeBuffer(const scoped_refptr<Buffer>& buffer) { | 212 void FFmpegVideoDecoder::DecodeBuffer( |
| 213 const scoped_refptr<DecoderBuffer>& buffer) { |
| 212 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read | 214 // TODO(scherkus): fix FFmpegDemuxerStream::Read() to not execute our read |
| 213 // callback on the same execution stack so we can get rid of forced task post. | 215 // callback on the same execution stack so we can get rid of forced task post. |
| 214 message_loop_->PostTask(FROM_HERE, base::Bind( | 216 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 215 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer)); | 217 &FFmpegVideoDecoder::DoDecodeBuffer, this, buffer)); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void FFmpegVideoDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& buffer) { | 220 void FFmpegVideoDecoder::DoDecodeBuffer( |
| 221 const scoped_refptr<DecoderBuffer>& buffer) { |
| 219 DCHECK_EQ(MessageLoop::current(), message_loop_); | 222 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 220 DCHECK_NE(state_, kUninitialized); | 223 DCHECK_NE(state_, kUninitialized); |
| 221 DCHECK_NE(state_, kDecodeFinished); | 224 DCHECK_NE(state_, kDecodeFinished); |
| 222 DCHECK(!read_cb_.is_null()); | 225 DCHECK(!read_cb_.is_null()); |
| 223 | 226 |
| 224 if (!reset_cb_.is_null()) { | 227 if (!reset_cb_.is_null()) { |
| 225 DeliverFrame(NULL); | 228 DeliverFrame(NULL); |
| 226 DoReset(); | 229 DoReset(); |
| 227 return; | 230 return; |
| 228 } | 231 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 255 // kFlushCodec -> kDecodeFinished: | 258 // kFlushCodec -> kDecodeFinished: |
| 256 // When avcodec_decode_video2() returns 0 data or errors out. | 259 // When avcodec_decode_video2() returns 0 data or errors out. |
| 257 // (any state) -> kNormal: | 260 // (any state) -> kNormal: |
| 258 // Any time Reset() is called. | 261 // Any time Reset() is called. |
| 259 | 262 |
| 260 // Transition to kFlushCodec on the first end of stream buffer. | 263 // Transition to kFlushCodec on the first end of stream buffer. |
| 261 if (state_ == kNormal && buffer->IsEndOfStream()) { | 264 if (state_ == kNormal && buffer->IsEndOfStream()) { |
| 262 state_ = kFlushCodec; | 265 state_ = kFlushCodec; |
| 263 } | 266 } |
| 264 | 267 |
| 265 scoped_refptr<Buffer> unencrypted_buffer = buffer; | 268 scoped_refptr<DecoderBuffer> unencrypted_buffer = buffer; |
| 266 if (buffer->GetDecryptConfig() && buffer->GetDataSize()) { | 269 if (buffer->GetDecryptConfig() && buffer->GetDataSize()) { |
| 267 unencrypted_buffer = decryptor_.Decrypt(buffer); | 270 unencrypted_buffer = decryptor_.Decrypt(buffer); |
| 268 if (!unencrypted_buffer || !unencrypted_buffer->GetDataSize()) { | 271 if (!unencrypted_buffer || !unencrypted_buffer->GetDataSize()) { |
| 269 state_ = kDecodeFinished; | 272 state_ = kDecodeFinished; |
| 270 base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL); | 273 base::ResetAndReturn(&read_cb_).Run(kDecryptError, NULL); |
| 271 return; | 274 return; |
| 272 } | 275 } |
| 273 } | 276 } |
| 274 | 277 |
| 275 scoped_refptr<VideoFrame> video_frame; | 278 scoped_refptr<VideoFrame> video_frame; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 296 } | 299 } |
| 297 | 300 |
| 298 ReadFromDemuxerStream(); | 301 ReadFromDemuxerStream(); |
| 299 return; | 302 return; |
| 300 } | 303 } |
| 301 | 304 |
| 302 DeliverFrame(video_frame); | 305 DeliverFrame(video_frame); |
| 303 } | 306 } |
| 304 | 307 |
| 305 bool FFmpegVideoDecoder::Decode( | 308 bool FFmpegVideoDecoder::Decode( |
| 306 const scoped_refptr<Buffer>& buffer, | 309 const scoped_refptr<DecoderBuffer>& buffer, |
| 307 scoped_refptr<VideoFrame>* video_frame) { | 310 scoped_refptr<VideoFrame>* video_frame) { |
| 308 DCHECK(video_frame); | 311 DCHECK(video_frame); |
| 309 | 312 |
| 310 // Create a packet for input data. | 313 // Create a packet for input data. |
| 311 // Due to FFmpeg API changes we no longer have const read-only pointers. | 314 // Due to FFmpeg API changes we no longer have const read-only pointers. |
| 312 AVPacket packet; | 315 AVPacket packet; |
| 313 av_init_packet(&packet); | 316 av_init_packet(&packet); |
| 314 packet.data = const_cast<uint8*>(buffer->GetData()); | 317 packet.data = const_cast<uint8*>(buffer->GetData()); |
| 315 packet.size = buffer->GetDataSize(); | 318 packet.size = buffer->GetDataSize(); |
| 316 | 319 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { | 422 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { |
| 420 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); | 423 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); |
| 421 size_t width = codec_context_->width; | 424 size_t width = codec_context_->width; |
| 422 size_t height = codec_context_->height; | 425 size_t height = codec_context_->height; |
| 423 | 426 |
| 424 return VideoFrame::CreateFrame(format, width, height, | 427 return VideoFrame::CreateFrame(format, width, height, |
| 425 kNoTimestamp(), kNoTimestamp()); | 428 kNoTimestamp(), kNoTimestamp()); |
| 426 } | 429 } |
| 427 | 430 |
| 428 } // namespace media | 431 } // namespace media |
| OLD | NEW |