| 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 switch (profile) { |
| 132 case FF_PROFILE_H264_BASELINE: |
| 133 return H264PROFILE_BASELINE; |
| 134 case FF_PROFILE_H264_MAIN: |
| 135 return H264PROFILE_MAIN; |
| 136 case FF_PROFILE_H264_EXTENDED: |
| 137 return H264PROFILE_EXTENDED; |
| 138 case FF_PROFILE_H264_HIGH: |
| 139 return H264PROFILE_HIGH; |
| 140 case FF_PROFILE_H264_HIGH_10: |
| 141 return H264PROFILE_HIGH10PROFILE; |
| 142 case FF_PROFILE_H264_HIGH_422: |
| 143 return H264PROFILE_HIGH422PROFILE; |
| 144 case FF_PROFILE_H264_HIGH_444_PREDICTIVE: |
| 145 return H264PROFILE_HIGH444PREDICTIVEPROFILE; |
| 146 default: |
| 147 return VIDEO_CODEC_PROFILE_UNKNOWN; |
| 148 } |
| 149 } |
| 150 |
| 151 static int VideoCodecProfileToProfileID(VideoCodecProfile profile) { |
| 152 switch (profile) { |
| 153 case H264PROFILE_BASELINE: |
| 154 return FF_PROFILE_H264_BASELINE; |
| 155 case H264PROFILE_MAIN: |
| 156 return FF_PROFILE_H264_MAIN; |
| 157 case H264PROFILE_EXTENDED: |
| 158 return FF_PROFILE_H264_EXTENDED; |
| 159 case H264PROFILE_HIGH: |
| 160 return FF_PROFILE_H264_HIGH; |
| 161 case H264PROFILE_HIGH10PROFILE: |
| 162 return FF_PROFILE_H264_HIGH_10; |
| 163 case H264PROFILE_HIGH422PROFILE: |
| 164 return FF_PROFILE_H264_HIGH_422; |
| 165 case H264PROFILE_HIGH444PREDICTIVEPROFILE: |
| 166 return FF_PROFILE_H264_HIGH_444_PREDICTIVE; |
| 167 default: |
| 168 return FF_PROFILE_UNKNOWN; |
| 169 } |
| 170 } |
| 171 |
| 130 void AVCodecContextToAudioDecoderConfig( | 172 void AVCodecContextToAudioDecoderConfig( |
| 131 const AVCodecContext* codec_context, | 173 const AVCodecContext* codec_context, |
| 132 AudioDecoderConfig* config) { | 174 AudioDecoderConfig* config) { |
| 133 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 175 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
| 134 | 176 |
| 135 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 177 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
| 136 int bits_per_channel = av_get_bits_per_sample_fmt(codec_context->sample_fmt); | 178 int bits_per_channel = av_get_bits_per_sample_fmt(codec_context->sample_fmt); |
| 137 ChannelLayout channel_layout = | 179 ChannelLayout channel_layout = |
| 138 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, | 180 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, |
| 139 codec_context->channels); | 181 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. | 239 // 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); | 240 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); |
| 199 | 241 |
| 200 AVRational aspect_ratio = { 1, 1 }; | 242 AVRational aspect_ratio = { 1, 1 }; |
| 201 if (stream->sample_aspect_ratio.num) | 243 if (stream->sample_aspect_ratio.num) |
| 202 aspect_ratio = stream->sample_aspect_ratio; | 244 aspect_ratio = stream->sample_aspect_ratio; |
| 203 else if (stream->codec->sample_aspect_ratio.num) | 245 else if (stream->codec->sample_aspect_ratio.num) |
| 204 aspect_ratio = stream->codec->sample_aspect_ratio; | 246 aspect_ratio = stream->codec->sample_aspect_ratio; |
| 205 | 247 |
| 206 config->Initialize(CodecIDToVideoCodec(stream->codec->codec_id), | 248 config->Initialize(CodecIDToVideoCodec(stream->codec->codec_id), |
| 249 ProfileIDToVideoCodecProfile(stream->codec->profile), |
| 207 PixelFormatToVideoFormat(stream->codec->pix_fmt), | 250 PixelFormatToVideoFormat(stream->codec->pix_fmt), |
| 208 coded_size, visible_rect, | 251 coded_size, visible_rect, |
| 209 stream->r_frame_rate.num, | 252 stream->r_frame_rate.num, |
| 210 stream->r_frame_rate.den, | 253 stream->r_frame_rate.den, |
| 211 aspect_ratio.num, | 254 aspect_ratio.num, |
| 212 aspect_ratio.den, | 255 aspect_ratio.den, |
| 213 stream->codec->extradata, | 256 stream->codec->extradata, |
| 214 stream->codec->extradata_size); | 257 stream->codec->extradata_size); |
| 215 } | 258 } |
| 216 | 259 |
| 217 void VideoDecoderConfigToAVCodecContext( | 260 void VideoDecoderConfigToAVCodecContext( |
| 218 const VideoDecoderConfig& config, | 261 const VideoDecoderConfig& config, |
| 219 AVCodecContext* codec_context) { | 262 AVCodecContext* codec_context) { |
| 220 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 263 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
| 221 codec_context->codec_id = VideoCodecToCodecID(config.codec()); | 264 codec_context->codec_id = VideoCodecToCodecID(config.codec()); |
| 265 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); |
| 222 codec_context->coded_width = config.coded_size().width(); | 266 codec_context->coded_width = config.coded_size().width(); |
| 223 codec_context->coded_height = config.coded_size().height(); | 267 codec_context->coded_height = config.coded_size().height(); |
| 224 codec_context->pix_fmt = VideoFormatToPixelFormat(config.format()); | 268 codec_context->pix_fmt = VideoFormatToPixelFormat(config.format()); |
| 225 | 269 |
| 226 if (config.extra_data()) { | 270 if (config.extra_data()) { |
| 227 codec_context->extradata_size = config.extra_data_size(); | 271 codec_context->extradata_size = config.extra_data_size(); |
| 228 codec_context->extradata = reinterpret_cast<uint8_t*>( | 272 codec_context->extradata = reinterpret_cast<uint8_t*>( |
| 229 av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE)); | 273 av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE)); |
| 230 memcpy(codec_context->extradata, config.extra_data(), | 274 memcpy(codec_context->extradata, config.extra_data(), |
| 231 config.extra_data_size()); | 275 config.extra_data_size()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 avcodec_close(stream->codec); | 378 avcodec_close(stream->codec); |
| 335 } | 379 } |
| 336 } | 380 } |
| 337 } | 381 } |
| 338 | 382 |
| 339 // Then finally cleanup the format context. | 383 // Then finally cleanup the format context. |
| 340 av_close_input_file(format_context); | 384 av_close_input_file(format_context); |
| 341 } | 385 } |
| 342 | 386 |
| 343 } // namespace media | 387 } // namespace media |
| OLD | NEW |