| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 av_frame_(NULL), | 57 av_frame_(NULL), |
| 58 frame_rate_numerator_(0), | 58 frame_rate_numerator_(0), |
| 59 frame_rate_denominator_(0) { | 59 frame_rate_denominator_(0) { |
| 60 } | 60 } |
| 61 | 61 |
| 62 FFmpegVideoDecoder::~FFmpegVideoDecoder() { | 62 FFmpegVideoDecoder::~FFmpegVideoDecoder() { |
| 63 ReleaseFFmpegResources(); | 63 ReleaseFFmpegResources(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream, | 66 void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream, |
| 67 const base::Closure& callback, | 67 const PipelineStatusCB& callback, |
| 68 const StatisticsCallback& stats_callback) { | 68 const StatisticsCallback& stats_callback) { |
| 69 if (MessageLoop::current() != message_loop_) { | 69 if (MessageLoop::current() != message_loop_) { |
| 70 message_loop_->PostTask(FROM_HERE, base::Bind( | 70 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 71 &FFmpegVideoDecoder::Initialize, this, | 71 &FFmpegVideoDecoder::Initialize, this, |
| 72 make_scoped_refptr(demuxer_stream), callback, stats_callback)); | 72 make_scoped_refptr(demuxer_stream), callback, stats_callback)); |
| 73 return; | 73 return; |
| 74 } | 74 } |
| 75 | 75 |
| 76 DCHECK(!demuxer_stream_); | 76 DCHECK(!demuxer_stream_); |
| 77 | 77 |
| 78 if (!demuxer_stream) { | 78 if (!demuxer_stream) { |
| 79 host()->SetError(PIPELINE_ERROR_DECODE); | 79 callback.Run(PIPELINE_ERROR_DECODE); |
| 80 callback.Run(); | |
| 81 return; | 80 return; |
| 82 } | 81 } |
| 83 | 82 |
| 84 demuxer_stream_ = demuxer_stream; | 83 demuxer_stream_ = demuxer_stream; |
| 85 statistics_callback_ = stats_callback; | 84 statistics_callback_ = stats_callback; |
| 86 | 85 |
| 87 const VideoDecoderConfig& config = demuxer_stream->video_decoder_config(); | 86 const VideoDecoderConfig& config = demuxer_stream->video_decoder_config(); |
| 88 | 87 |
| 89 // TODO(scherkus): this check should go in PipelineImpl prior to creating | 88 // TODO(scherkus): this check should go in PipelineImpl prior to creating |
| 90 // decoder objects. | 89 // decoder objects. |
| 91 if (!config.IsValidConfig()) { | 90 if (!config.IsValidConfig()) { |
| 92 DLOG(ERROR) << "Invalid video stream -" | 91 DLOG(ERROR) << "Invalid video stream - " << config.AsHumanReadableString(); |
| 93 << " codec: " << config.codec() | 92 callback.Run(PIPELINE_ERROR_DECODE); |
| 94 << " format: " << config.format() | |
| 95 << " coded size: [" << config.coded_size().width() | |
| 96 << "," << config.coded_size().height() << "]" | |
| 97 << " visible rect: [" << config.visible_rect().x() | |
| 98 << "," << config.visible_rect().y() | |
| 99 << "," << config.visible_rect().width() | |
| 100 << "," << config.visible_rect().height() << "]" | |
| 101 << " natural size: [" << config.natural_size().width() | |
| 102 << "," << config.natural_size().height() << "]" | |
| 103 << " frame rate: " << config.frame_rate_numerator() | |
| 104 << "/" << config.frame_rate_denominator() | |
| 105 << " aspect ratio: " << config.aspect_ratio_numerator() | |
| 106 << "/" << config.aspect_ratio_denominator(); | |
| 107 | |
| 108 host()->SetError(PIPELINE_ERROR_DECODE); | |
| 109 callback.Run(); | |
| 110 return; | 93 return; |
| 111 } | 94 } |
| 112 | 95 |
| 113 // Initialize AVCodecContext structure. | 96 // Initialize AVCodecContext structure. |
| 114 codec_context_ = avcodec_alloc_context(); | 97 codec_context_ = avcodec_alloc_context(); |
| 115 VideoDecoderConfigToAVCodecContext(config, codec_context_); | 98 VideoDecoderConfigToAVCodecContext(config, codec_context_); |
| 116 | 99 |
| 117 // Enable motion vector search (potentially slow), strong deblocking filter | 100 // Enable motion vector search (potentially slow), strong deblocking filter |
| 118 // for damaged macroblocks, and set our error detection sensitivity. | 101 // for damaged macroblocks, and set our error detection sensitivity. |
| 119 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; | 102 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; |
| 120 codec_context_->error_recognition = FF_ER_CAREFUL; | 103 codec_context_->error_recognition = FF_ER_CAREFUL; |
| 121 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); | 104 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); |
| 122 | 105 |
| 123 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); | 106 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
| 124 if (!codec) { | 107 if (!codec) { |
| 125 host()->SetError(PIPELINE_ERROR_DECODE); | 108 callback.Run(PIPELINE_ERROR_DECODE); |
| 126 callback.Run(); | |
| 127 return; | 109 return; |
| 128 } | 110 } |
| 129 | 111 |
| 130 if (avcodec_open(codec_context_, codec) < 0) { | 112 if (avcodec_open(codec_context_, codec) < 0) { |
| 131 host()->SetError(PIPELINE_ERROR_DECODE); | 113 callback.Run(PIPELINE_ERROR_DECODE); |
| 132 callback.Run(); | |
| 133 return; | 114 return; |
| 134 } | 115 } |
| 135 | 116 |
| 136 // Success! | 117 // Success! |
| 137 state_ = kNormal; | 118 state_ = kNormal; |
| 138 av_frame_ = avcodec_alloc_frame(); | 119 av_frame_ = avcodec_alloc_frame(); |
| 139 pts_stream_.Initialize(GetFrameDuration(config)); | 120 pts_stream_.Initialize(GetFrameDuration(config)); |
| 140 natural_size_ = config.natural_size(); | 121 natural_size_ = config.natural_size(); |
| 141 frame_rate_numerator_ = config.frame_rate_numerator(); | 122 frame_rate_numerator_ = config.frame_rate_numerator(); |
| 142 frame_rate_denominator_ = config.frame_rate_denominator(); | 123 frame_rate_denominator_ = config.frame_rate_denominator(); |
| 143 callback.Run(); | 124 callback.Run(PIPELINE_OK); |
| 144 } | 125 } |
| 145 | 126 |
| 146 void FFmpegVideoDecoder::Stop(const base::Closure& callback) { | 127 void FFmpegVideoDecoder::Stop(const base::Closure& callback) { |
| 147 if (MessageLoop::current() != message_loop_) { | 128 if (MessageLoop::current() != message_loop_) { |
| 148 message_loop_->PostTask(FROM_HERE, base::Bind( | 129 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 149 &FFmpegVideoDecoder::Stop, this, callback)); | 130 &FFmpegVideoDecoder::Stop, this, callback)); |
| 150 return; | 131 return; |
| 151 } | 132 } |
| 152 | 133 |
| 153 ReleaseFFmpegResources(); | 134 ReleaseFFmpegResources(); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { | 415 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { |
| 435 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); | 416 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); |
| 436 size_t width = codec_context_->width; | 417 size_t width = codec_context_->width; |
| 437 size_t height = codec_context_->height; | 418 size_t height = codec_context_->height; |
| 438 | 419 |
| 439 return VideoFrame::CreateFrame(format, width, height, | 420 return VideoFrame::CreateFrame(format, width, height, |
| 440 kNoTimestamp, kNoTimestamp); | 421 kNoTimestamp, kNoTimestamp); |
| 441 } | 422 } |
| 442 | 423 |
| 443 } // namespace media | 424 } // namespace media |
| OLD | NEW |