| 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 | |
| 172 void AVCodecContextToAudioDecoderConfig( | 130 void AVCodecContextToAudioDecoderConfig( |
| 173 const AVCodecContext* codec_context, | 131 const AVCodecContext* codec_context, |
| 174 AudioDecoderConfig* config) { | 132 AudioDecoderConfig* config) { |
| 175 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 133 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
| 176 | 134 |
| 177 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 135 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
| 178 int bits_per_channel = av_get_bits_per_sample_fmt(codec_context->sample_fmt); | 136 int bits_per_channel = av_get_bits_per_sample_fmt(codec_context->sample_fmt); |
| 179 ChannelLayout channel_layout = | 137 ChannelLayout channel_layout = |
| 180 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, | 138 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, |
| 181 codec_context->channels); | 139 codec_context->channels); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // for now, but may not always be true forever. Fix this in the future. | 197 // for now, but may not always be true forever. Fix this in the future. |
| 240 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); | 198 gfx::Rect visible_rect(stream->codec->width, stream->codec->height); |
| 241 | 199 |
| 242 AVRational aspect_ratio = { 1, 1 }; | 200 AVRational aspect_ratio = { 1, 1 }; |
| 243 if (stream->sample_aspect_ratio.num) | 201 if (stream->sample_aspect_ratio.num) |
| 244 aspect_ratio = stream->sample_aspect_ratio; | 202 aspect_ratio = stream->sample_aspect_ratio; |
| 245 else if (stream->codec->sample_aspect_ratio.num) | 203 else if (stream->codec->sample_aspect_ratio.num) |
| 246 aspect_ratio = stream->codec->sample_aspect_ratio; | 204 aspect_ratio = stream->codec->sample_aspect_ratio; |
| 247 | 205 |
| 248 config->Initialize(CodecIDToVideoCodec(stream->codec->codec_id), | 206 config->Initialize(CodecIDToVideoCodec(stream->codec->codec_id), |
| 249 ProfileIDToVideoCodecProfile(stream->codec->profile), | |
| 250 PixelFormatToVideoFormat(stream->codec->pix_fmt), | 207 PixelFormatToVideoFormat(stream->codec->pix_fmt), |
| 251 coded_size, visible_rect, | 208 coded_size, visible_rect, |
| 252 stream->r_frame_rate.num, | 209 stream->r_frame_rate.num, |
| 253 stream->r_frame_rate.den, | 210 stream->r_frame_rate.den, |
| 254 aspect_ratio.num, | 211 aspect_ratio.num, |
| 255 aspect_ratio.den, | 212 aspect_ratio.den, |
| 256 stream->codec->extradata, | 213 stream->codec->extradata, |
| 257 stream->codec->extradata_size); | 214 stream->codec->extradata_size); |
| 258 } | 215 } |
| 259 | 216 |
| 260 void VideoDecoderConfigToAVCodecContext( | 217 void VideoDecoderConfigToAVCodecContext( |
| 261 const VideoDecoderConfig& config, | 218 const VideoDecoderConfig& config, |
| 262 AVCodecContext* codec_context) { | 219 AVCodecContext* codec_context) { |
| 263 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; | 220 codec_context->codec_type = AVMEDIA_TYPE_VIDEO; |
| 264 codec_context->codec_id = VideoCodecToCodecID(config.codec()); | 221 codec_context->codec_id = VideoCodecToCodecID(config.codec()); |
| 265 codec_context->profile = VideoCodecProfileToProfileID(config.profile()); | |
| 266 codec_context->coded_width = config.coded_size().width(); | 222 codec_context->coded_width = config.coded_size().width(); |
| 267 codec_context->coded_height = config.coded_size().height(); | 223 codec_context->coded_height = config.coded_size().height(); |
| 268 codec_context->pix_fmt = VideoFormatToPixelFormat(config.format()); | 224 codec_context->pix_fmt = VideoFormatToPixelFormat(config.format()); |
| 269 | 225 |
| 270 if (config.extra_data()) { | 226 if (config.extra_data()) { |
| 271 codec_context->extradata_size = config.extra_data_size(); | 227 codec_context->extradata_size = config.extra_data_size(); |
| 272 codec_context->extradata = reinterpret_cast<uint8_t*>( | 228 codec_context->extradata = reinterpret_cast<uint8_t*>( |
| 273 av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE)); | 229 av_malloc(config.extra_data_size() + FF_INPUT_BUFFER_PADDING_SIZE)); |
| 274 memcpy(codec_context->extradata, config.extra_data(), | 230 memcpy(codec_context->extradata, config.extra_data(), |
| 275 config.extra_data_size()); | 231 config.extra_data_size()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 avcodec_close(stream->codec); | 334 avcodec_close(stream->codec); |
| 379 } | 335 } |
| 380 } | 336 } |
| 381 } | 337 } |
| 382 | 338 |
| 383 // Then finally cleanup the format context. | 339 // Then finally cleanup the format context. |
| 384 av_close_input_file(format_context); | 340 av_close_input_file(format_context); |
| 385 } | 341 } |
| 386 | 342 |
| 387 } // namespace media | 343 } // namespace media |
| OLD | NEW |