| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 decode_threads = std::min(decode_threads, kMaxDecodeThreads); | 54 decode_threads = std::min(decode_threads, kMaxDecodeThreads); |
| 55 return decode_threads; | 55 return decode_threads; |
| 56 } | 56 } |
| 57 | 57 |
| 58 FFmpegVideoDecoder::FFmpegVideoDecoder( | 58 FFmpegVideoDecoder::FFmpegVideoDecoder( |
| 59 const scoped_refptr<base::MessageLoopProxy>& message_loop) | 59 const scoped_refptr<base::MessageLoopProxy>& message_loop) |
| 60 : message_loop_(message_loop), | 60 : message_loop_(message_loop), |
| 61 weak_factory_(this), | 61 weak_factory_(this), |
| 62 state_(kUninitialized), | 62 state_(kUninitialized), |
| 63 codec_context_(NULL), | 63 codec_context_(NULL), |
| 64 av_frame_(NULL) { | 64 av_frame_(NULL), |
| 65 demuxer_stream_(NULL) { |
| 65 } | 66 } |
| 66 | 67 |
| 67 int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, | 68 int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, |
| 68 AVFrame* frame) { | 69 AVFrame* frame) { |
| 69 // Don't use |codec_context_| here! With threaded decoding, | 70 // Don't use |codec_context_| here! With threaded decoding, |
| 70 // it will contain unsynchronized width/height/pix_fmt values, | 71 // it will contain unsynchronized width/height/pix_fmt values, |
| 71 // whereas |codec_context| contains the current threads's | 72 // whereas |codec_context| contains the current threads's |
| 72 // updated width/height/pix_fmt, which can change for adaptive | 73 // updated width/height/pix_fmt, which can change for adaptive |
| 73 // content. | 74 // content. |
| 74 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt); | 75 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 static void ReleaseVideoBufferImpl(AVCodecContext* s, AVFrame* frame) { | 124 static void ReleaseVideoBufferImpl(AVCodecContext* s, AVFrame* frame) { |
| 124 scoped_refptr<VideoFrame> video_frame; | 125 scoped_refptr<VideoFrame> video_frame; |
| 125 video_frame.swap(reinterpret_cast<VideoFrame**>(&frame->opaque)); | 126 video_frame.swap(reinterpret_cast<VideoFrame**>(&frame->opaque)); |
| 126 | 127 |
| 127 // The FFmpeg API expects us to zero the data pointers in | 128 // The FFmpeg API expects us to zero the data pointers in |
| 128 // this callback | 129 // this callback |
| 129 memset(frame->data, 0, sizeof(frame->data)); | 130 memset(frame->data, 0, sizeof(frame->data)); |
| 130 frame->opaque = NULL; | 131 frame->opaque = NULL; |
| 131 } | 132 } |
| 132 | 133 |
| 133 void FFmpegVideoDecoder::Initialize(const scoped_refptr<DemuxerStream>& stream, | 134 void FFmpegVideoDecoder::Initialize(DemuxerStream* stream, |
| 134 const PipelineStatusCB& status_cb, | 135 const PipelineStatusCB& status_cb, |
| 135 const StatisticsCB& statistics_cb) { | 136 const StatisticsCB& statistics_cb) { |
| 136 DCHECK(message_loop_->BelongsToCurrentThread()); | 137 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 137 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); | 138 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); |
| 138 weak_this_ = weak_factory_.GetWeakPtr(); | 139 weak_this_ = weak_factory_.GetWeakPtr(); |
| 139 | 140 |
| 140 FFmpegGlue::InitializeFFmpeg(); | 141 FFmpegGlue::InitializeFFmpeg(); |
| 141 DCHECK(!demuxer_stream_) << "Already initialized."; | 142 DCHECK(!demuxer_stream_) << "Already initialized."; |
| 142 | 143 |
| 143 if (!stream) { | 144 if (!stream) { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { | 488 if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { |
| 488 ReleaseFFmpegResources(); | 489 ReleaseFFmpegResources(); |
| 489 return false; | 490 return false; |
| 490 } | 491 } |
| 491 | 492 |
| 492 av_frame_ = avcodec_alloc_frame(); | 493 av_frame_ = avcodec_alloc_frame(); |
| 493 return true; | 494 return true; |
| 494 } | 495 } |
| 495 | 496 |
| 496 } // namespace media | 497 } // namespace media |
| OLD | NEW |