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

Side by Side Diff: media/filters/ffmpeg_video_decoder.cc

Issue 10824141: Remove VideoDecoder::natural_size() & added VideoFrame::natural_size(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copyright year. Created 8 years, 4 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
« no previous file with comments | « media/filters/ffmpeg_video_decoder.h ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // Don't use |codec_context_| here! With threaded decoding, 68 // Don't use |codec_context_| here! With threaded decoding,
69 // it will contain unsynchronized width/height/pix_fmt values, 69 // it will contain unsynchronized width/height/pix_fmt values,
70 // whereas |codec_context| contains the current threads's 70 // whereas |codec_context| contains the current threads's
71 // updated width/height/pix_fmt, which can change for adaptive 71 // updated width/height/pix_fmt, which can change for adaptive
72 // content. 72 // content.
73 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt); 73 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt);
74 if (format == VideoFrame::INVALID) 74 if (format == VideoFrame::INVALID)
75 return AVERROR(EINVAL); 75 return AVERROR(EINVAL);
76 DCHECK(format == VideoFrame::YV12 || format == VideoFrame::YV16); 76 DCHECK(format == VideoFrame::YV12 || format == VideoFrame::YV16);
77 77
78 int width = codec_context->width; 78 gfx::Size size(codec_context->width, codec_context->height);
79 int height = codec_context->height;
80 int ret; 79 int ret;
81 if ((ret = av_image_check_size(width, height, 0, NULL)) < 0) 80 if ((ret = av_image_check_size(size.width(), size.height(), 0, NULL)) < 0)
82 return ret; 81 return ret;
83 82
83 gfx::Size natural_size;
84 if (codec_context->sample_aspect_ratio.num > 0) {
85 natural_size = GetNaturalSize(size,
86 codec_context->sample_aspect_ratio.num,
87 codec_context->sample_aspect_ratio.den);
88 } else {
89 natural_size = demuxer_stream_->video_decoder_config().natural_size();
90 }
91
84 scoped_refptr<VideoFrame> video_frame = 92 scoped_refptr<VideoFrame> video_frame =
85 VideoFrame::CreateFrame(format, width, height, kNoTimestamp()); 93 VideoFrame::CreateFrame(format, size, natural_size, kNoTimestamp());
86 94
87 for (int i = 0; i < 3; i++) { 95 for (int i = 0; i < 3; i++) {
88 frame->base[i] = video_frame->data(i); 96 frame->base[i] = video_frame->data(i);
89 frame->data[i] = video_frame->data(i); 97 frame->data[i] = video_frame->data(i);
90 frame->linesize[i] = video_frame->stride(i); 98 frame->linesize[i] = video_frame->stride(i);
91 } 99 }
92 100
93 frame->opaque = video_frame.release(); 101 frame->opaque = video_frame.release();
94 frame->type = FF_BUFFER_TYPE_USER; 102 frame->type = FF_BUFFER_TYPE_USER;
95 frame->pkt_pts = codec_context->pkt ? codec_context->pkt->pts : 103 frame->pkt_pts = codec_context->pkt ? codec_context->pkt->pts :
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 186 }
179 187
180 if (avcodec_open2(codec_context_, codec, NULL) < 0) { 188 if (avcodec_open2(codec_context_, codec, NULL) < 0) {
181 status_cb.Run(PIPELINE_ERROR_DECODE); 189 status_cb.Run(PIPELINE_ERROR_DECODE);
182 return; 190 return;
183 } 191 }
184 192
185 // Success! 193 // Success!
186 state_ = kNormal; 194 state_ = kNormal;
187 av_frame_ = avcodec_alloc_frame(); 195 av_frame_ = avcodec_alloc_frame();
188 natural_size_ = config.natural_size();
189 status_cb.Run(PIPELINE_OK); 196 status_cb.Run(PIPELINE_OK);
190 } 197 }
191 198
192 void FFmpegVideoDecoder::Read(const ReadCB& read_cb) { 199 void FFmpegVideoDecoder::Read(const ReadCB& read_cb) {
193 // Complete operation asynchronously on different stack of execution as per 200 // Complete operation asynchronously on different stack of execution as per
194 // the API contract of VideoDecoder::Read() 201 // the API contract of VideoDecoder::Read()
195 message_loop_->PostTask(FROM_HERE, base::Bind( 202 message_loop_->PostTask(FROM_HERE, base::Bind(
196 &FFmpegVideoDecoder::DoRead, this, read_cb)); 203 &FFmpegVideoDecoder::DoRead, this, read_cb));
197 } 204 }
198 205
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 243
237 DoStop(); 244 DoStop();
238 } 245 }
239 246
240 void FFmpegVideoDecoder::DoStop() { 247 void FFmpegVideoDecoder::DoStop() {
241 ReleaseFFmpegResources(); 248 ReleaseFFmpegResources();
242 state_ = kUninitialized; 249 state_ = kUninitialized;
243 base::ResetAndReturn(&stop_cb_).Run(); 250 base::ResetAndReturn(&stop_cb_).Run();
244 } 251 }
245 252
246 const gfx::Size& FFmpegVideoDecoder::natural_size() {
247 return natural_size_;
248 }
249
250 void FFmpegVideoDecoder::set_decryptor(Decryptor* decryptor) { 253 void FFmpegVideoDecoder::set_decryptor(Decryptor* decryptor) {
251 DCHECK_EQ(state_, kUninitialized); 254 DCHECK_EQ(state_, kUninitialized);
252 decryptor_ = decryptor; 255 decryptor_ = decryptor;
253 } 256 }
254 257
255 FFmpegVideoDecoder::~FFmpegVideoDecoder() { 258 FFmpegVideoDecoder::~FFmpegVideoDecoder() {
256 ReleaseFFmpegResources(); 259 ReleaseFFmpegResources();
257 } 260 }
258 261
259 void FFmpegVideoDecoder::DoRead(const ReadCB& read_cb) { 262 void FFmpegVideoDecoder::DoRead(const ReadCB& read_cb) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 av_free(codec_context_); 516 av_free(codec_context_);
514 codec_context_ = NULL; 517 codec_context_ = NULL;
515 } 518 }
516 if (av_frame_) { 519 if (av_frame_) {
517 av_free(av_frame_); 520 av_free(av_frame_);
518 av_frame_ = NULL; 521 av_frame_ = NULL;
519 } 522 }
520 } 523 }
521 524
522 } // namespace media 525 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_video_decoder.h ('k') | media/filters/ffmpeg_video_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698