Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: media/video/ffmpeg_video_decode_engine.cc

Issue 7932005: Reland r101418: Fix aspect ratio and clarify video frame dimensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/video/ffmpeg_video_decode_engine.h" 5 #include "media/video/ffmpeg_video_decode_engine.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/task.h" 9 #include "base/task.h"
10 #include "media/base/buffers.h" 10 #include "media/base/buffers.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 static const int kDecodeThreads = 2; 54 static const int kDecodeThreads = 2;
55 static const int kMaxDecodeThreads = 16; 55 static const int kMaxDecodeThreads = 16;
56 56
57 // Initialize AVCodecContext structure. 57 // Initialize AVCodecContext structure.
58 codec_context_ = avcodec_alloc_context(); 58 codec_context_ = avcodec_alloc_context();
59 59
60 // TODO(scherkus): should video format get passed in via VideoDecoderConfig? 60 // TODO(scherkus): should video format get passed in via VideoDecoderConfig?
61 codec_context_->pix_fmt = PIX_FMT_YUV420P; 61 codec_context_->pix_fmt = PIX_FMT_YUV420P;
62 codec_context_->codec_type = AVMEDIA_TYPE_VIDEO; 62 codec_context_->codec_type = AVMEDIA_TYPE_VIDEO;
63 codec_context_->codec_id = VideoCodecToCodecID(config.codec()); 63 codec_context_->codec_id = VideoCodecToCodecID(config.codec());
64 codec_context_->coded_width = config.width(); 64 codec_context_->coded_width = config.coded_size().width();
65 codec_context_->coded_height = config.height(); 65 codec_context_->coded_height = config.coded_size().height();
66 66
67 frame_rate_numerator_ = config.frame_rate_numerator(); 67 frame_rate_numerator_ = config.frame_rate_numerator();
68 frame_rate_denominator_ = config.frame_rate_denominator(); 68 frame_rate_denominator_ = config.frame_rate_denominator();
69 69
70 if (config.extra_data() != NULL) { 70 if (config.extra_data() != NULL) {
71 codec_context_->extradata_size = config.extra_data_size(); 71 codec_context_->extradata_size = config.extra_data_size();
72 codec_context_->extradata = reinterpret_cast<uint8_t*>( 72 codec_context_->extradata = reinterpret_cast<uint8_t*>(
73 av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE)); 73 av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE));
74 memcpy(codec_context_->extradata, config.extra_data(), 74 memcpy(codec_context_->extradata, config.extra_data(),
75 config.extra_data_size()); 75 config.extra_data_size());
(...skipping 21 matching lines...) Expand all
97 decode_threads < 0 || decode_threads > kMaxDecodeThreads) { 97 decode_threads < 0 || decode_threads > kMaxDecodeThreads) {
98 decode_threads = kDecodeThreads; 98 decode_threads = kDecodeThreads;
99 } 99 }
100 100
101 // We don't allocate AVFrame on the stack since different versions of FFmpeg 101 // We don't allocate AVFrame on the stack since different versions of FFmpeg
102 // may change the size of AVFrame, causing stack corruption. The solution is 102 // may change the size of AVFrame, causing stack corruption. The solution is
103 // to let FFmpeg allocate the structure via avcodec_alloc_frame(). 103 // to let FFmpeg allocate the structure via avcodec_alloc_frame().
104 av_frame_.reset(avcodec_alloc_frame()); 104 av_frame_.reset(avcodec_alloc_frame());
105 VideoCodecInfo info; 105 VideoCodecInfo info;
106 info.success = false; 106 info.success = false;
107 info.surface_width = config.surface_width(); 107 info.natural_size = config.natural_size();
108 info.surface_height = config.surface_height();
109 108
110 // If we do not have enough buffers, we will report error too. 109 // If we do not have enough buffers, we will report error too.
111 frame_queue_available_.clear(); 110 frame_queue_available_.clear();
112 111
113 // Create output buffer pool when direct rendering is not used. 112 // Create output buffer pool when direct rendering is not used.
114 for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) { 113 for (size_t i = 0; i < Limits::kMaxVideoFrames; ++i) {
115 scoped_refptr<VideoFrame> video_frame = 114 scoped_refptr<VideoFrame> video_frame =
116 VideoFrame::CreateFrame(VideoFrame::YV12, 115 VideoFrame::CreateFrame(VideoFrame::YV12,
117 config.surface_width(), 116 config.visible_rect().width(),
118 config.surface_height(), 117 config.visible_rect().height(),
119 kNoTimestamp, 118 kNoTimestamp,
120 kNoTimestamp); 119 kNoTimestamp);
121 frame_queue_available_.push_back(video_frame); 120 frame_queue_available_.push_back(video_frame);
122 } 121 }
123 122
124 codec_context_->thread_count = decode_threads; 123 codec_context_->thread_count = decode_threads;
125 if (codec && 124 if (codec &&
126 avcodec_open(codec_context_, codec) >= 0 && 125 avcodec_open(codec_context_, codec) >= 0 &&
127 av_frame_.get()) { 126 av_frame_.get()) {
128 info.success = true; 127 info.success = true;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 DCHECK_EQ(output_eos_reached_, false); 300 DCHECK_EQ(output_eos_reached_, false);
302 pending_input_buffers_++; 301 pending_input_buffers_++;
303 event_handler_->ProduceVideoSample(NULL); 302 event_handler_->ProduceVideoSample(NULL);
304 } 303 }
305 304
306 } // namespace media 305 } // namespace media
307 306
308 // Disable refcounting for this object because this object only lives 307 // Disable refcounting for this object because this object only lives
309 // on the video decoder thread and there's no need to refcount it. 308 // on the video decoder thread and there's no need to refcount it.
310 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::FFmpegVideoDecodeEngine); 309 DISABLE_RUNNABLE_METHOD_REFCOUNT(media::FFmpegVideoDecodeEngine);
OLDNEW
« no previous file with comments | « media/tools/player_x11/x11_video_renderer.cc ('k') | media/video/ffmpeg_video_decode_engine_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698