| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/audio_decoder_config.h" | 8 #include "media/base/audio_decoder_config.h" |
| 9 #include "media/base/video_decoder_config.h" | 9 #include "media/base/video_decoder_config.h" |
| 10 | 10 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 case kCodecMPEG4: | 120 case kCodecMPEG4: |
| 121 return CODEC_ID_MPEG4; | 121 return CODEC_ID_MPEG4; |
| 122 case kCodecVP8: | 122 case kCodecVP8: |
| 123 return CODEC_ID_VP8; | 123 return CODEC_ID_VP8; |
| 124 default: | 124 default: |
| 125 NOTREACHED(); | 125 NOTREACHED(); |
| 126 } | 126 } |
| 127 return CODEC_ID_NONE; | 127 return CODEC_ID_NONE; |
| 128 } | 128 } |
| 129 | 129 |
| 130 static VideoCodecProfile ProfileIDToVideoCodecProfile(int profile) { |
| 131 // Clear out the CONSTRAINED & INTRA flags which are strict subsets of the |
| 132 // corresponding profiles with which they're used. |
| 133 profile &= ~FF_PROFILE_H264_CONSTRAINED; |
| 134 profile &= ~FF_PROFILE_H264_INTRA; |
| 135 switch (profile) { |
| 136 case FF_PROFILE_H264_BASELINE: |
| 137 return H264PROFILE_BASELINE; |
| 138 case FF_PROFILE_H264_MAIN: |
| 139 return H264PROFILE_MAIN; |
| 140 case FF_PROFILE_H264_EXTENDED: |
| 141 return H264PROFILE_EXTENDED; |
| 142 case FF_PROFILE_H264_HIGH: |
| 143 return H264PROFILE_HIGH; |
| 144 case FF_PROFILE_H264_HIGH_10: |
| 145 return H264PROFILE_HIGH10PROFILE; |
| 146 case FF_PROFILE_H264_HIGH_422: |
| 147 return H264PROFILE_HIGH422PROFILE; |
| 148 case FF_PROFILE_H264_HIGH_444_PREDICTIVE: |
| 149 return H264PROFILE_HIGH444PREDICTIVEPROFILE; |
| 150 default: |
| 151 return VIDEO_CODEC_PROFILE_UNKNOWN; |
| 152 } |
| 153 } |
| 154 |
| 155 static int VideoCodecProfileToProfileID(VideoCodecProfile profile) { |
| 156 switch (profile) { |
| 157 case H264PROFILE_BASELINE: |
| 158 return FF_PROFILE_H264_BASELINE; |
| 159 case H264PROFILE_MAIN: |
| 160 return FF_PROFILE_H264_MAIN; |
| 161 case H264PROFILE_EXTENDED: |
| 162 return FF_PROFILE_H264_EXTENDED; |
| 163 case H264PROFILE_HIGH: |
| 164 return FF_PROFILE_H264_HIGH; |
| 165 case H264PROFILE_HIGH10PROFILE: |
| 166 return FF_PROFILE_H264_HIGH_10; |
| 167 case H264PROFILE_HIGH422PROFILE: |
| 168 return FF_PROFILE_H264_HIGH_422; |
| 169 case H264PROFILE_HIGH444PREDICTIVEPROFILE: |
| 170 return FF_PROFILE_H264_HIGH_444_PREDICTIVE; |
| 171 default: |
| 172 return FF_PROFILE_UNKNOWN; |
| 173 } |
| 174 } |
| 175 |
| 130 void AVCodecContextToAudioDecoderConfig( | 176 void AVCodecContextToAudioDecoderConfig( |
| 131 const AVCodecContext* codec_context, | 177 const AVCodecContext* codec_context, |
| 132 AudioDecoderConfig* config) { | 178 AudioDecoderConfig* config) { |
| 133 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 179 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
| 134 | 180 |
| 135 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 181 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
| 136 int bits_per_channel = av_get_bits_per_sample_fmt(codec_context->sample_fmt); | 182 int bits_per_channel = av_get_bits_per_sample_fmt(codec_context->sample_fmt); |
| 137 ChannelLayout channel_layout = | 183 ChannelLayout channel_layout = |
| 138 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, | 184 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, |
| 139 codec_context->channels); | 185 codec_context->channels); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // for now, but may not always be true forever. Fix this in the future. | 243 // for now, but may not always be true forever. Fix this in the future. |
| 198 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); | 244 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); |
| 199 | 245 |
| 200 AVRational aspect_ratio = { 1, 1 }; | 246 AVRational aspect_ratio = { 1, 1 }; |
| 201 if (stream->sample_aspect_ratio.num) | 247 if (stream->sample_aspect_ratio.num) |
| 202 aspect_ratio = stream->sample_aspect_ratio; | 248 aspect_ratio = stream->sample_aspect_ratio; |
| 203 else if (stream->codec->sample_aspect_ratio.num) | 249 else if (stream->codec->sample_aspect_ratio.num) |
| 204 aspect_ratio = stream->codec->sample_aspect_ratio; | 250 aspect_ratio = stream->codec->sample_aspect_ratio; |
| 205 | 251 |
| 206 config->Initialize(CodecIDToVideoCodec(stream->codec->codec_id), | 252 config->Initialize(CodecIDToVideoCodec(stream->codec->codec_id), |
| 253 ProfileIDToVideoCodecProfile(stream->codec->profile), |
| 207 PixelFormatToVideoFormat(stream->codec->pix_fmt), | 254 PixelFormatToVideoFormat(stream->codec->pix_fmt), |
| 208 coded_size, visible_rect, | 255 coded_size, visible_rect, |
| 209 stream->r_frame_rate.num, | 256 stream->r_frame_rate.num, |
| 210 stream->r_frame_rate.den, | 257 stream->r_frame_rate.den, |
| 211 aspect_ratio.num, | 258 aspect_ratio.num, |
| 212 aspect_ratio.den, | 259 aspect_ratio.den, |
| 213 stream->codec->extradata, | 260 stream->codec->extradata, |
| 214 stream->codec->extradata_size); | 261 stream->codec->extradata_size); |
| 215 } | 262 } |
| 216 | 263 |
| 217 void VideoDecoderConfigToAVCodecContext( | 264 void VideoDecoderConfigToAVCodecContext( |
| 218 const VideoDecoderConfig& config, | 265 const VideoDecoderConfig& config, |
| 219 AVCodecContext* codec_context) { | 266 AVCodecContext* codec_context) { |
| 220 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 267 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
| 221 codec_context->codec_id = VideoCodecToCodecID(config.codec()); | 268 codec_context->codec_id = VideoCodecToCodecID(config.codec()); |
| 269 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); |
| 222 codec_context->coded_width = config.coded_size().width(); | 270 codec_context->coded_width = config.coded_size().width(); |
| 223 codec_context->coded_height = config.coded_size().height(); | 271 codec_context->coded_height = config.coded_size().height(); |
| 224 codec_context->pix_fmt = VideoFormatToPixelFormat(config.format()); | 272 codec_context->pix_fmt = VideoFormatToPixelFormat(config.format()); |
| 225 | 273 |
| 226 if (config.extra_data()) { | 274 if (config.extra_data()) { |
| 227 codec_context->extradata_size = config.extra_data_size(); | 275 codec_context->extradata_size = config.extra_data_size(); |
| 228 codec_context->extradata = reinterpret_cast<uint8_t*>( | 276 codec_context->extradata = reinterpret_cast<uint8_t*>( |
| 229 av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE)); | 277 av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE)); |
| 230 memcpy(codec_context->extradata, config.extra_data(), | 278 memcpy(codec_context->extradata, config.extra_data(), |
| 231 config.extra_data_size()); | 279 config.extra_data_size()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 avcodec_close(stream->codec); | 382 avcodec_close(stream->codec); |
| 335 } | 383 } |
| 336 } | 384 } |
| 337 } | 385 } |
| 338 | 386 |
| 339 // Then finally cleanup the format context. | 387 // Then finally cleanup the format context. |
| 340 av_close_input_file(format_context); | 388 av_close_input_file(format_context); |
| 341 } | 389 } |
| 342 | 390 |
| 343 } // namespace media | 391 } // namespace media |
| OLD | NEW |