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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
151 default: | 155 default: |
| 156 if (codec_id == AV_CODEC_ID_VP9) { |
| 157 // TODO(tomfinegan): Remove this once FFmpeg rolls for M25, and |
| 158 // AV_CODEC_ID_VP9 is part of CodecID. |
| 159 return kCodecVP9; |
| 160 } |
152 DVLOG(1) << "Unknown video CodecID: " << codec_id; | 161 DVLOG(1) << "Unknown video CodecID: " << codec_id; |
153 } | 162 } |
154 return kUnknownVideoCodec; | 163 return kUnknownVideoCodec; |
155 } | 164 } |
156 | 165 |
157 static CodecID VideoCodecToCodecID(VideoCodec video_codec) { | 166 static CodecID VideoCodecToCodecID(VideoCodec video_codec) { |
158 switch (video_codec) { | 167 switch (video_codec) { |
159 case kCodecVC1: | 168 case kCodecVC1: |
160 return CODEC_ID_VC1; | 169 return CODEC_ID_VC1; |
161 case kCodecH264: | 170 case kCodecH264: |
162 return CODEC_ID_H264; | 171 return CODEC_ID_H264; |
163 case kCodecTheora: | 172 case kCodecTheora: |
164 return CODEC_ID_THEORA; | 173 return CODEC_ID_THEORA; |
165 case kCodecMPEG2: | 174 case kCodecMPEG2: |
166 return CODEC_ID_MPEG2VIDEO; | 175 return CODEC_ID_MPEG2VIDEO; |
167 case kCodecMPEG4: | 176 case kCodecMPEG4: |
168 return CODEC_ID_MPEG4; | 177 return CODEC_ID_MPEG4; |
169 case kCodecVP8: | 178 case kCodecVP8: |
170 return CODEC_ID_VP8; | 179 return CODEC_ID_VP8; |
| 180 case kCodecVP9: |
| 181 // TODO(tomfinegan): Remove this cast once FFmpeg rolls for M25, and the |
| 182 // local define for AV_CODEC_ID_VP9 is removed. |
| 183 return static_cast<CodecID>(AV_CODEC_ID_VP9); |
171 default: | 184 default: |
172 DVLOG(1) << "Unknown VideoCodec: " << video_codec; | 185 DVLOG(1) << "Unknown VideoCodec: " << video_codec; |
173 } | 186 } |
174 return CODEC_ID_NONE; | 187 return CODEC_ID_NONE; |
175 } | 188 } |
176 | 189 |
177 static VideoCodecProfile ProfileIDToVideoCodecProfile(int profile) { | 190 static VideoCodecProfile ProfileIDToVideoCodecProfile(int profile) { |
178 // Clear out the CONSTRAINED & INTRA flags which are strict subsets of the | 191 // Clear out the CONSTRAINED & INTRA flags which are strict subsets of the |
179 // corresponding profiles with which they're used. | 192 // corresponding profiles with which they're used. |
180 profile &= ~FF_PROFILE_H264_CONSTRAINED; | 193 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. | 317 // 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); | 318 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); |
306 | 319 |
307 AVRational aspect_ratio = { 1, 1 }; | 320 AVRational aspect_ratio = { 1, 1 }; |
308 if (stream->sample_aspect_ratio.num) | 321 if (stream->sample_aspect_ratio.num) |
309 aspect_ratio = stream->sample_aspect_ratio; | 322 aspect_ratio = stream->sample_aspect_ratio; |
310 else if (stream->codec->sample_aspect_ratio.num) | 323 else if (stream->codec->sample_aspect_ratio.num) |
311 aspect_ratio = stream->codec->sample_aspect_ratio; | 324 aspect_ratio = stream->codec->sample_aspect_ratio; |
312 | 325 |
313 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id); | 326 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id); |
314 VideoCodecProfile profile = (codec == kCodecVP8) ? VP8PROFILE_MAIN : | 327 |
315 ProfileIDToVideoCodecProfile(stream->codec->profile); | 328 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
| 329 if (codec == kCodecVP8) |
| 330 profile = VP8PROFILE_MAIN; |
| 331 else if (codec == kCodecVP9) |
| 332 profile = VP9PROFILE_MAIN; |
| 333 else |
| 334 profile = ProfileIDToVideoCodecProfile(stream->codec->profile); |
| 335 |
316 gfx::Size natural_size = GetNaturalSize( | 336 gfx::Size natural_size = GetNaturalSize( |
317 visible_rect.size(), aspect_ratio.num, aspect_ratio.den); | 337 visible_rect.size(), aspect_ratio.num, aspect_ratio.den); |
| 338 |
| 339 VideoFrame::Format format = PixelFormatToVideoFormat(stream->codec->pix_fmt); |
| 340 if (codec == kCodecVP9) { |
| 341 // TODO(tomfinegan): libavcodec doesn't know about VP9. |
| 342 format = VideoFrame::YV12; |
| 343 coded_size = natural_size; |
| 344 } |
| 345 |
318 config->Initialize(codec, | 346 config->Initialize(codec, |
319 profile, | 347 profile, |
320 PixelFormatToVideoFormat(stream->codec->pix_fmt), | 348 format, |
321 coded_size, visible_rect, natural_size, | 349 coded_size, visible_rect, natural_size, |
322 stream->codec->extradata, stream->codec->extradata_size, | 350 stream->codec->extradata, stream->codec->extradata_size, |
323 false, // Not encrypted. | 351 false, // Not encrypted. |
324 true); | 352 true); |
325 } | 353 } |
326 | 354 |
327 void VideoDecoderConfigToAVCodecContext( | 355 void VideoDecoderConfigToAVCodecContext( |
328 const VideoDecoderConfig& config, | 356 const VideoDecoderConfig& config, |
329 AVCodecContext* codec_context) { | 357 AVCodecContext* codec_context) { |
330 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 358 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; | 463 return PIX_FMT_YUV422P; |
436 case VideoFrame::YV12: | 464 case VideoFrame::YV12: |
437 return PIX_FMT_YUV420P; | 465 return PIX_FMT_YUV420P; |
438 default: | 466 default: |
439 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; | 467 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; |
440 } | 468 } |
441 return PIX_FMT_NONE; | 469 return PIX_FMT_NONE; |
442 } | 470 } |
443 | 471 |
444 } // namespace media | 472 } // namespace media |
OLD | NEW |