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/ffmpeg/ffmpeg_common.h" | 5 #include "media/ffmpeg/ffmpeg_common.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/base/video_util.h" |
8 | 9 |
9 namespace media { | 10 namespace media { |
10 | 11 |
11 static const AVRational kMicrosBase = { 1, base::Time::kMicrosecondsPerSecond }; | 12 static const AVRational kMicrosBase = { 1, base::Time::kMicrosecondsPerSecond }; |
12 | 13 |
13 base::TimeDelta ConvertFromTimeBase(const AVRational& time_base, | 14 base::TimeDelta ConvertFromTimeBase(const AVRational& time_base, |
14 int64 timestamp) { | 15 int64 timestamp) { |
15 int64 microseconds = av_rescale_q(timestamp, time_base, kMicrosBase); | 16 int64 microseconds = av_rescale_q(timestamp, time_base, kMicrosBase); |
16 return base::TimeDelta::FromMicroseconds(microseconds); | 17 return base::TimeDelta::FromMicroseconds(microseconds); |
17 } | 18 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 244 |
244 AVRational aspect_ratio = { 1, 1 }; | 245 AVRational aspect_ratio = { 1, 1 }; |
245 if (stream->sample_aspect_ratio.num) | 246 if (stream->sample_aspect_ratio.num) |
246 aspect_ratio = stream->sample_aspect_ratio; | 247 aspect_ratio = stream->sample_aspect_ratio; |
247 else if (stream->codec->sample_aspect_ratio.num) | 248 else if (stream->codec->sample_aspect_ratio.num) |
248 aspect_ratio = stream->codec->sample_aspect_ratio; | 249 aspect_ratio = stream->codec->sample_aspect_ratio; |
249 | 250 |
250 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id); | 251 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id); |
251 VideoCodecProfile profile = (codec == kCodecVP8) ? VP8PROFILE_MAIN : | 252 VideoCodecProfile profile = (codec == kCodecVP8) ? VP8PROFILE_MAIN : |
252 ProfileIDToVideoCodecProfile(stream->codec->profile); | 253 ProfileIDToVideoCodecProfile(stream->codec->profile); |
| 254 gfx::Size natural_size = GetNaturalSize( |
| 255 visible_rect.size(), aspect_ratio.num, aspect_ratio.den); |
253 config->Initialize(codec, | 256 config->Initialize(codec, |
254 profile, | 257 profile, |
255 PixelFormatToVideoFormat(stream->codec->pix_fmt), | 258 PixelFormatToVideoFormat(stream->codec->pix_fmt), |
256 coded_size, visible_rect, | 259 coded_size, visible_rect, natural_size, |
257 aspect_ratio.num, | |
258 aspect_ratio.den, | |
259 stream->codec->extradata, | 260 stream->codec->extradata, |
260 stream->codec->extradata_size, | 261 stream->codec->extradata_size, |
261 true); | 262 true); |
262 } | 263 } |
263 | 264 |
264 void VideoDecoderConfigToAVCodecContext( | 265 void VideoDecoderConfigToAVCodecContext( |
265 const VideoDecoderConfig& config, | 266 const VideoDecoderConfig& config, |
266 AVCodecContext* codec_context) { | 267 AVCodecContext* codec_context) { |
267 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 268 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
268 codec_context->codec_id = VideoCodecToCodecID(config.codec()); | 269 codec_context->codec_id = VideoCodecToCodecID(config.codec()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 avcodec_close(stream->codec); | 375 avcodec_close(stream->codec); |
375 } | 376 } |
376 } | 377 } |
377 } | 378 } |
378 | 379 |
379 // Then finally cleanup the format context. | 380 // Then finally cleanup the format context. |
380 avformat_close_input(&format_context); | 381 avformat_close_input(&format_context); |
381 } | 382 } |
382 | 383 |
383 } // namespace media | 384 } // namespace media |
OLD | NEW |