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

Side by Side Diff: media/ffmpeg/ffmpeg_common.cc

Issue 12025030: Add wrapper class to media for support of VP9 video, and add a command line flag to enable the supp… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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) 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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/base/decoder_buffer.h" 9 #include "media/base/decoder_buffer.h"
10 #include "media/base/video_frame.h" 10 #include "media/base/video_frame.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 VideoCodec CodecIDToVideoCodec(CodecID codec_id) { 140 VideoCodec CodecIDToVideoCodec(CodecID codec_id) {
141 switch (codec_id) { 141 switch (codec_id) {
142 case CODEC_ID_H264: 142 case CODEC_ID_H264:
143 return kCodecH264; 143 return kCodecH264;
144 case CODEC_ID_THEORA: 144 case CODEC_ID_THEORA:
145 return kCodecTheora; 145 return kCodecTheora;
146 case CODEC_ID_MPEG4: 146 case CODEC_ID_MPEG4:
147 return kCodecMPEG4; 147 return kCodecMPEG4;
148 case CODEC_ID_VP8: 148 case CODEC_ID_VP8:
149 return kCodecVP8; 149 return kCodecVP8;
150 case AV_CODEC_ID_VP9:
151 return kCodecVP9;
150 default: 152 default:
151 DVLOG(1) << "Unknown video CodecID: " << codec_id; 153 DVLOG(1) << "Unknown video CodecID: " << codec_id;
152 } 154 }
153 return kUnknownVideoCodec; 155 return kUnknownVideoCodec;
154 } 156 }
155 157
156 static CodecID VideoCodecToCodecID(VideoCodec video_codec) { 158 static CodecID VideoCodecToCodecID(VideoCodec video_codec) {
157 switch (video_codec) { 159 switch (video_codec) {
158 case kCodecH264: 160 case kCodecH264:
159 return CODEC_ID_H264; 161 return CODEC_ID_H264;
160 case kCodecTheora: 162 case kCodecTheora:
161 return CODEC_ID_THEORA; 163 return CODEC_ID_THEORA;
162 case kCodecMPEG4: 164 case kCodecMPEG4:
163 return CODEC_ID_MPEG4; 165 return CODEC_ID_MPEG4;
164 case kCodecVP8: 166 case kCodecVP8:
165 return CODEC_ID_VP8; 167 return CODEC_ID_VP8;
168 case kCodecVP9:
169 return AV_CODEC_ID_VP9;
166 default: 170 default:
167 DVLOG(1) << "Unknown VideoCodec: " << video_codec; 171 DVLOG(1) << "Unknown VideoCodec: " << video_codec;
168 } 172 }
169 return CODEC_ID_NONE; 173 return CODEC_ID_NONE;
170 } 174 }
171 175
172 static VideoCodecProfile ProfileIDToVideoCodecProfile(int profile) { 176 static VideoCodecProfile ProfileIDToVideoCodecProfile(int profile) {
173 // Clear out the CONSTRAINED & INTRA flags which are strict subsets of the 177 // Clear out the CONSTRAINED & INTRA flags which are strict subsets of the
174 // corresponding profiles with which they're used. 178 // corresponding profiles with which they're used.
175 profile &= ~FF_PROFILE_H264_CONSTRAINED; 179 profile &= ~FF_PROFILE_H264_CONSTRAINED;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // for now, but may not always be true forever. Fix this in the future. 332 // for now, but may not always be true forever. Fix this in the future.
329 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); 333 gfx::Rect visible_rect(stream->codec->width, stream->codec->height);
330 334
331 AVRational aspect_ratio = { 1, 1 }; 335 AVRational aspect_ratio = { 1, 1 };
332 if (stream->sample_aspect_ratio.num) 336 if (stream->sample_aspect_ratio.num)
333 aspect_ratio = stream->sample_aspect_ratio; 337 aspect_ratio = stream->sample_aspect_ratio;
334 else if (stream->codec->sample_aspect_ratio.num) 338 else if (stream->codec->sample_aspect_ratio.num)
335 aspect_ratio = stream->codec->sample_aspect_ratio; 339 aspect_ratio = stream->codec->sample_aspect_ratio;
336 340
337 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id); 341 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id);
338 VideoCodecProfile profile = (codec == kCodecVP8) ? VP8PROFILE_MAIN : 342
339 ProfileIDToVideoCodecProfile(stream->codec->profile); 343 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
344 if (codec == kCodecVP8)
345 profile = VP8PROFILE_MAIN;
346 else if (codec == kCodecVP9)
347 profile = VP9PROFILE_MAIN;
348 else
349 profile = ProfileIDToVideoCodecProfile(stream->codec->profile);
350
340 gfx::Size natural_size = GetNaturalSize( 351 gfx::Size natural_size = GetNaturalSize(
341 visible_rect.size(), aspect_ratio.num, aspect_ratio.den); 352 visible_rect.size(), aspect_ratio.num, aspect_ratio.den);
353
354 VideoFrame::Format format = PixelFormatToVideoFormat(stream->codec->pix_fmt);
355 if (codec == kCodecVP9) {
356 // TODO(tomfinegan): libavcodec doesn't know about VP9.
357 format = VideoFrame::YV12;
358 coded_size = natural_size;
359 }
360
342 config->Initialize(codec, 361 config->Initialize(codec,
343 profile, 362 profile,
344 PixelFormatToVideoFormat(stream->codec->pix_fmt), 363 format,
345 coded_size, visible_rect, natural_size, 364 coded_size, visible_rect, natural_size,
346 stream->codec->extradata, stream->codec->extradata_size, 365 stream->codec->extradata, stream->codec->extradata_size,
347 false, // Not encrypted. 366 false, // Not encrypted.
348 true); 367 true);
349 } 368 }
350 369
351 void VideoDecoderConfigToAVCodecContext( 370 void VideoDecoderConfigToAVCodecContext(
352 const VideoDecoderConfig& config, 371 const VideoDecoderConfig& config,
353 AVCodecContext* codec_context) { 372 AVCodecContext* codec_context) {
354 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; 373 codec_context->codec_type = AVMEDIA_TYPE_VIDEO;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 return PIX_FMT_YUV422P; 478 return PIX_FMT_YUV422P;
460 case VideoFrame::YV12: 479 case VideoFrame::YV12:
461 return PIX_FMT_YUV420P; 480 return PIX_FMT_YUV420P;
462 default: 481 default:
463 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; 482 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format;
464 } 483 }
465 return PIX_FMT_NONE; 484 return PIX_FMT_NONE;
466 } 485 }
467 486
468 } // namespace media 487 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698