| 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" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; | |
| 152 default: | 150 default: |
| 153 DVLOG(1) << "Unknown video CodecID: " << codec_id; | 151 DVLOG(1) << "Unknown video CodecID: " << codec_id; |
| 154 } | 152 } |
| 155 return kUnknownVideoCodec; | 153 return kUnknownVideoCodec; |
| 156 } | 154 } |
| 157 | 155 |
| 158 static CodecID VideoCodecToCodecID(VideoCodec video_codec) { | 156 static CodecID VideoCodecToCodecID(VideoCodec video_codec) { |
| 159 switch (video_codec) { | 157 switch (video_codec) { |
| 160 case kCodecH264: | 158 case kCodecH264: |
| 161 return CODEC_ID_H264; | 159 return CODEC_ID_H264; |
| 162 case kCodecTheora: | 160 case kCodecTheora: |
| 163 return CODEC_ID_THEORA; | 161 return CODEC_ID_THEORA; |
| 164 case kCodecMPEG4: | 162 case kCodecMPEG4: |
| 165 return CODEC_ID_MPEG4; | 163 return CODEC_ID_MPEG4; |
| 166 case kCodecVP8: | 164 case kCodecVP8: |
| 167 return CODEC_ID_VP8; | 165 return CODEC_ID_VP8; |
| 168 case kCodecVP9: | |
| 169 return AV_CODEC_ID_VP9; | |
| 170 default: | 166 default: |
| 171 DVLOG(1) << "Unknown VideoCodec: " << video_codec; | 167 DVLOG(1) << "Unknown VideoCodec: " << video_codec; |
| 172 } | 168 } |
| 173 return CODEC_ID_NONE; | 169 return CODEC_ID_NONE; |
| 174 } | 170 } |
| 175 | 171 |
| 176 static VideoCodecProfile ProfileIDToVideoCodecProfile(int profile) { | 172 static VideoCodecProfile ProfileIDToVideoCodecProfile(int profile) { |
| 177 // Clear out the CONSTRAINED & INTRA flags which are strict subsets of the | 173 // Clear out the CONSTRAINED & INTRA flags which are strict subsets of the |
| 178 // corresponding profiles with which they're used. | 174 // corresponding profiles with which they're used. |
| 179 profile &= ~FF_PROFILE_H264_CONSTRAINED; | 175 profile &= ~FF_PROFILE_H264_CONSTRAINED; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // for now, but may not always be true forever. Fix this in the future. | 328 // for now, but may not always be true forever. Fix this in the future. |
| 333 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); | 329 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); |
| 334 | 330 |
| 335 AVRational aspect_ratio = { 1, 1 }; | 331 AVRational aspect_ratio = { 1, 1 }; |
| 336 if (stream->sample_aspect_ratio.num) | 332 if (stream->sample_aspect_ratio.num) |
| 337 aspect_ratio = stream->sample_aspect_ratio; | 333 aspect_ratio = stream->sample_aspect_ratio; |
| 338 else if (stream->codec->sample_aspect_ratio.num) | 334 else if (stream->codec->sample_aspect_ratio.num) |
| 339 aspect_ratio = stream->codec->sample_aspect_ratio; | 335 aspect_ratio = stream->codec->sample_aspect_ratio; |
| 340 | 336 |
| 341 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id); | 337 VideoCodec codec = CodecIDToVideoCodec(stream->codec->codec_id); |
| 342 | 338 VideoCodecProfile profile = (codec == kCodecVP8) ? VP8PROFILE_MAIN : |
| 343 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; | 339 ProfileIDToVideoCodecProfile(stream->codec->profile); |
| 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 | |
| 351 gfx::Size natural_size = GetNaturalSize( | 340 gfx::Size natural_size = GetNaturalSize( |
| 352 visible_rect.size(), aspect_ratio.num, aspect_ratio.den); | 341 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 | |
| 361 config->Initialize(codec, | 342 config->Initialize(codec, |
| 362 profile, | 343 profile, |
| 363 format, | 344 PixelFormatToVideoFormat(stream->codec->pix_fmt), |
| 364 coded_size, visible_rect, natural_size, | 345 coded_size, visible_rect, natural_size, |
| 365 stream->codec->extradata, stream->codec->extradata_size, | 346 stream->codec->extradata, stream->codec->extradata_size, |
| 366 false, // Not encrypted. | 347 false, // Not encrypted. |
| 367 true); | 348 true); |
| 368 } | 349 } |
| 369 | 350 |
| 370 void VideoDecoderConfigToAVCodecContext( | 351 void VideoDecoderConfigToAVCodecContext( |
| 371 const VideoDecoderConfig& config, | 352 const VideoDecoderConfig& config, |
| 372 AVCodecContext* codec_context) { | 353 AVCodecContext* codec_context) { |
| 373 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 354 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 return PIX_FMT_YUV422P; | 459 return PIX_FMT_YUV422P; |
| 479 case VideoFrame::YV12: | 460 case VideoFrame::YV12: |
| 480 return PIX_FMT_YUV420P; | 461 return PIX_FMT_YUV420P; |
| 481 default: | 462 default: |
| 482 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; | 463 DVLOG(1) << "Unsupported VideoFrame::Format: " << video_format; |
| 483 } | 464 } |
| 484 return PIX_FMT_NONE; | 465 return PIX_FMT_NONE; |
| 485 } | 466 } |
| 486 | 467 |
| 487 } // namespace media | 468 } // namespace media |
| OLD | NEW |