| 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 PipelineStatusCB& callback, | 67 const base::Closure& 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 callback.Run(PIPELINE_ERROR_DECODE); | 79 host()->SetError(PIPELINE_ERROR_DECODE); |
| 80 callback.Run(); |
| 80 return; | 81 return; |
| 81 } | 82 } |
| 82 | 83 |
| 83 demuxer_stream_ = demuxer_stream; | 84 demuxer_stream_ = demuxer_stream; |
| 84 statistics_callback_ = stats_callback; | 85 statistics_callback_ = stats_callback; |
| 85 | 86 |
| 86 const VideoDecoderConfig& config = demuxer_stream->video_decoder_config(); | 87 const VideoDecoderConfig& config = demuxer_stream->video_decoder_config(); |
| 87 | 88 |
| 88 // TODO(scherkus): this check should go in PipelineImpl prior to creating | 89 // TODO(scherkus): this check should go in PipelineImpl prior to creating |
| 89 // decoder objects. | 90 // decoder objects. |
| 90 if (!config.IsValidConfig()) { | 91 if (!config.IsValidConfig()) { |
| 91 DLOG(ERROR) << "Invalid video stream - " << config.AsHumanReadableString(); | 92 DLOG(ERROR) << "Invalid video stream -" |
| 92 callback.Run(PIPELINE_ERROR_DECODE); | 93 << " codec: " << config.codec() |
| 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(); |
| 93 return; | 110 return; |
| 94 } | 111 } |
| 95 | 112 |
| 96 // Initialize AVCodecContext structure. | 113 // Initialize AVCodecContext structure. |
| 97 codec_context_ = avcodec_alloc_context(); | 114 codec_context_ = avcodec_alloc_context(); |
| 98 VideoDecoderConfigToAVCodecContext(config, codec_context_); | 115 VideoDecoderConfigToAVCodecContext(config, codec_context_); |
| 99 | 116 |
| 100 // Enable motion vector search (potentially slow), strong deblocking filter | 117 // Enable motion vector search (potentially slow), strong deblocking filter |
| 101 // for damaged macroblocks, and set our error detection sensitivity. | 118 // for damaged macroblocks, and set our error detection sensitivity. |
| 102 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; | 119 codec_context_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; |
| 103 codec_context_->error_recognition = FF_ER_CAREFUL; | 120 codec_context_->error_recognition = FF_ER_CAREFUL; |
| 104 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); | 121 codec_context_->thread_count = GetThreadCount(codec_context_->codec_id); |
| 105 | 122 |
| 106 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); | 123 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
| 107 if (!codec) { | 124 if (!codec) { |
| 108 callback.Run(PIPELINE_ERROR_DECODE); | 125 host()->SetError(PIPELINE_ERROR_DECODE); |
| 126 callback.Run(); |
| 109 return; | 127 return; |
| 110 } | 128 } |
| 111 | 129 |
| 112 if (avcodec_open(codec_context_, codec) < 0) { | 130 if (avcodec_open(codec_context_, codec) < 0) { |
| 113 callback.Run(PIPELINE_ERROR_DECODE); | 131 host()->SetError(PIPELINE_ERROR_DECODE); |
| 132 callback.Run(); |
| 114 return; | 133 return; |
| 115 } | 134 } |
| 116 | 135 |
| 117 // Success! | 136 // Success! |
| 118 state_ = kNormal; | 137 state_ = kNormal; |
| 119 av_frame_ = avcodec_alloc_frame(); | 138 av_frame_ = avcodec_alloc_frame(); |
| 120 pts_stream_.Initialize(GetFrameDuration(config)); | 139 pts_stream_.Initialize(GetFrameDuration(config)); |
| 121 natural_size_ = config.natural_size(); | 140 natural_size_ = config.natural_size(); |
| 122 frame_rate_numerator_ = config.frame_rate_numerator(); | 141 frame_rate_numerator_ = config.frame_rate_numerator(); |
| 123 frame_rate_denominator_ = config.frame_rate_denominator(); | 142 frame_rate_denominator_ = config.frame_rate_denominator(); |
| 124 callback.Run(PIPELINE_OK); | 143 callback.Run(); |
| 125 } | 144 } |
| 126 | 145 |
| 127 void FFmpegVideoDecoder::Stop(const base::Closure& callback) { | 146 void FFmpegVideoDecoder::Stop(const base::Closure& callback) { |
| 128 if (MessageLoop::current() != message_loop_) { | 147 if (MessageLoop::current() != message_loop_) { |
| 129 message_loop_->PostTask(FROM_HERE, base::Bind( | 148 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 130 &FFmpegVideoDecoder::Stop, this, callback)); | 149 &FFmpegVideoDecoder::Stop, this, callback)); |
| 131 return; | 150 return; |
| 132 } | 151 } |
| 133 | 152 |
| 134 ReleaseFFmpegResources(); | 153 ReleaseFFmpegResources(); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { | 434 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { |
| 416 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); | 435 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); |
| 417 size_t width = codec_context_->width; | 436 size_t width = codec_context_->width; |
| 418 size_t height = codec_context_->height; | 437 size_t height = codec_context_->height; |
| 419 | 438 |
| 420 return VideoFrame::CreateFrame(format, width, height, | 439 return VideoFrame::CreateFrame(format, width, height, |
| 421 kNoTimestamp, kNoTimestamp); | 440 kNoTimestamp, kNoTimestamp); |
| 422 } | 441 } |
| 423 | 442 |
| 424 } // namespace media | 443 } // namespace media |
| OLD | NEW |