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/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" |
11 #include "media/base/video_util.h" | 11 #include "media/base/video_util.h" |
12 | 12 |
13 // TODO(tomfinegan): Remove this once FFmpeg rolls for M25. The VP9 patch is in | |
14 // tree, but this is required until the roll happens. | |
15 #define AV_CODEC_ID_VP9 170 | |
16 | |
13 namespace media { | 17 namespace media { |
14 | 18 |
15 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are | 19 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are |
16 // padded. Check here to ensure FFmpeg only receives data padded to its | 20 // padded. Check here to ensure FFmpeg only receives data padded to its |
17 // specifications. | 21 // specifications. |
18 COMPILE_ASSERT(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, | 22 COMPILE_ASSERT(DecoderBuffer::kPaddingSize >= FF_INPUT_BUFFER_PADDING_SIZE, |
19 decoder_buffer_padding_size_does_not_fit_ffmpeg_requirement); | 23 decoder_buffer_padding_size_does_not_fit_ffmpeg_requirement); |
20 | 24 |
21 // Alignment requirement by FFmpeg for input and output buffers. This need to | 25 // Alignment requirement by FFmpeg for input and output buffers. This need to |
22 // be updated to match FFmpeg when it changes. | 26 // be updated to match FFmpeg when it changes. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 case CODEC_ID_H264: | 145 case CODEC_ID_H264: |
142 return kCodecH264; | 146 return kCodecH264; |
143 case CODEC_ID_THEORA: | 147 case CODEC_ID_THEORA: |
144 return kCodecTheora; | 148 return kCodecTheora; |
145 case CODEC_ID_MPEG2VIDEO: | 149 case CODEC_ID_MPEG2VIDEO: |
146 return kCodecMPEG2; | 150 return kCodecMPEG2; |
147 case CODEC_ID_MPEG4: | 151 case CODEC_ID_MPEG4: |
148 return kCodecMPEG4; | 152 return kCodecMPEG4; |
149 case CODEC_ID_VP8: | 153 case CODEC_ID_VP8: |
150 return kCodecVP8; | 154 return kCodecVP8; |
155 case AV_CODEC_ID_VP9: | |
156 return kCodecVP9; | |
151 default: | 157 default: |
152 DVLOG(1) << "Unknown video CodecID: " << codec_id; | 158 DVLOG(1) << "Unknown video CodecID: " << codec_id; |
153 } | 159 } |
154 return kUnknownVideoCodec; | 160 return kUnknownVideoCodec; |
155 } | 161 } |
156 | 162 |
157 static CodecID VideoCodecToCodecID(VideoCodec video_codec) { | 163 static CodecID VideoCodecToCodecID(VideoCodec video_codec) { |
158 switch (video_codec) { | 164 switch (video_codec) { |
159 case kCodecVC1: | 165 case kCodecVC1: |
160 return CODEC_ID_VC1; | 166 return CODEC_ID_VC1; |
161 case kCodecH264: | 167 case kCodecH264: |
162 return CODEC_ID_H264; | 168 return CODEC_ID_H264; |
163 case kCodecTheora: | 169 case kCodecTheora: |
164 return CODEC_ID_THEORA; | 170 return CODEC_ID_THEORA; |
165 case kCodecMPEG2: | 171 case kCodecMPEG2: |
166 return CODEC_ID_MPEG2VIDEO; | 172 return CODEC_ID_MPEG2VIDEO; |
167 case kCodecMPEG4: | 173 case kCodecMPEG4: |
168 return CODEC_ID_MPEG4; | 174 return CODEC_ID_MPEG4; |
169 case kCodecVP8: | 175 case kCodecVP8: |
170 return CODEC_ID_VP8; | 176 return CODEC_ID_VP8; |
177 case kCodecVP9: | |
178 // TODO(tomfinegan): Remove this cast once FFmpeg rolls for M25, and the | |
179 // local define for AV_CODEC_ID_VP9 is removed. | |
180 return static_cast<CodecID>(AV_CODEC_ID_VP9); | |
171 default: | 181 default: |
172 DVLOG(1) << "Unknown VideoCodec: " << video_codec; | 182 DVLOG(1) << "Unknown VideoCodec: " << video_codec; |
173 } | 183 } |
174 return CODEC_ID_NONE; | 184 return CODEC_ID_NONE; |
175 } | 185 } |
176 | 186 |
177 static VideoCodecProfile ProfileIDToVideoCodecProfile(int profile) { | 187 static VideoCodecProfile ProfileIDToVideoCodecProfile(int profile) { |
178 // Clear out the CONSTRAINED & INTRA flags which are strict subsets of the | 188 // Clear out the CONSTRAINED & INTRA flags which are strict subsets of the |
179 // corresponding profiles with which they're used. | 189 // corresponding profiles with which they're used. |
180 profile &= ~FF_PROFILE_H264_CONSTRAINED; | 190 profile &= ~FF_PROFILE_H264_CONSTRAINED; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 // for now, but may not always be true forever. Fix this in the future. | 314 // for now, but may not always be true forever. Fix this in the future. |
305 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); | 315 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); |
306 | 316 |
307 AVRational aspect_ratio = { 1, 1 }; | 317 AVRational aspect_ratio = { 1, 1 }; |
308 if (stream->sample_aspect_ratio.num) | 318 if (stream->sample_aspect_ratio.num) |
309 aspect_ratio = stream->sample_aspect_ratio; | 319 aspect_ratio = stream->sample_aspect_ratio; |
310 else if (stream->codec->sample_aspect_ratio.num) | 320 else if (stream->codec->sample_aspect_ratio.num) |
311 aspect_ratio = stream->codec->sample_aspect_ratio; | 321 aspect_ratio = stream->codec->sample_aspect_ratio; |
312 | 322 |
313 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id); | 323 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id); |
314 VideoCodecProfile profile = (codec == kCodecVP8) ? VP8PROFILE_MAIN : | 324 VideoCodecProfile profile = (codec == kCodecVP8) ? VP8PROFILE_MAIN : |
scherkus (not reviewing)
2012/12/18 01:01:56
for clarity's sake let's unfold the nested ?: oper
Tom Finegan
2012/12/18 01:47:42
Done.
| |
315 ProfileIDToVideoCodecProfile(stream->codec->profile); | 325 (codec == kCodecVP9) ? VP9PROFILE_MAIN : |
326 ProfileIDToVideoCodecProfile(stream->codec->profile); | |
316 gfx::Size natural_size = GetNaturalSize( | 327 gfx::Size natural_size = GetNaturalSize( |
317 visible_rect.size(), aspect_ratio.num, aspect_ratio.den); | 328 visible_rect.size(), aspect_ratio.num, aspect_ratio.den); |
329 | |
330 VideoFrame::Format format = PixelFormatToVideoFormat(stream->codec->pix_fmt); | |
331 if (codec == kCodecVP9) { | |
332 // TODO(tomfinegan): libavcodec doesn't know about VP9. | |
333 format = VideoFrame::YV12; | |
scherkus (not reviewing)
2012/12/18 01:01:56
is this always true?
Tom Finegan
2012/12/18 01:47:42
Yes: libvpx outputs either YV12 or I420. The wrapp
| |
334 coded_size = natural_size; | |
335 } | |
336 | |
318 config->Initialize(codec, | 337 config->Initialize(codec, |
319 profile, | 338 profile, |
320 PixelFormatToVideoFormat(stream->codec->pix_fmt), | 339 format, |
321 coded_size, visible_rect, natural_size, | 340 coded_size, visible_rect, natural_size, |
322 stream->codec->extradata, stream->codec->extradata_size, | 341 stream->codec->extradata, stream->codec->extradata_size, |
323 false, // Not encrypted. | 342 false, // Not encrypted. |
324 true); | 343 true); |
325 } | 344 } |
326 | 345 |
327 void VideoDecoderConfigToAVCodecContext( | 346 void VideoDecoderConfigToAVCodecContext( |
328 const VideoDecoderConfig& config, | 347 const VideoDecoderConfig& config, |
329 AVCodecContext* codec_context) { | 348 AVCodecContext* codec_context) { |
330 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 349 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 return PIX_FMT_YUV422P; | 454 return PIX_FMT_YUV422P; |
436 case VideoFrame::YV12: | 455 case VideoFrame::YV12: |
437 return PIX_FMT_YUV420P; | 456 return PIX_FMT_YUV420P; |
438 default: | 457 default: |
439 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; | 458 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; |
440 } | 459 } |
441 return PIX_FMT_NONE; | 460 return PIX_FMT_NONE; |
442 } | 461 } |
443 | 462 |
444 } // namespace media | 463 } // namespace media |
OLD | NEW |