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/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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 return FF_PROFILE_UNKNOWN; | 172 return FF_PROFILE_UNKNOWN; |
173 } | 173 } |
174 | 174 |
175 void AVCodecContextToAudioDecoderConfig( | 175 void AVCodecContextToAudioDecoderConfig( |
176 const AVCodecContext* codec_context, | 176 const AVCodecContext* codec_context, |
177 AudioDecoderConfig* config) { | 177 AudioDecoderConfig* config) { |
178 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 178 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
179 | 179 |
180 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 180 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
181 int bits_per_channel = av_get_bits_per_sample_fmt(codec_context->sample_fmt); | 181 int bytes_per_channel = av_get_bytes_per_sample(codec_context->sample_fmt); |
182 ChannelLayout channel_layout = | 182 ChannelLayout channel_layout = |
183 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, | 183 ChannelLayoutToChromeChannelLayout(codec_context->channel_layout, |
184 codec_context->channels); | 184 codec_context->channels); |
185 int samples_per_second = codec_context->sample_rate; | 185 int samples_per_second = codec_context->sample_rate; |
186 | 186 |
187 config->Initialize(codec, | 187 config->Initialize(codec, |
188 bits_per_channel, | 188 bytes_per_channel << 3, |
189 channel_layout, | 189 channel_layout, |
190 samples_per_second, | 190 samples_per_second, |
191 codec_context->extradata, | 191 codec_context->extradata, |
192 codec_context->extradata_size, | 192 codec_context->extradata_size, |
193 true); | 193 true); |
194 } | 194 } |
195 | 195 |
196 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config, | 196 void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config, |
197 AVCodecContext* codec_context) { | 197 AVCodecContext* codec_context) { |
198 codec_context->codec_type = AVMEDIA_TYPE_AUDIO; | 198 codec_context->codec_type = AVMEDIA_TYPE_AUDIO; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 FF_INPUT_BUFFER_PADDING_SIZE); | 282 FF_INPUT_BUFFER_PADDING_SIZE); |
283 } else { | 283 } else { |
284 codec_context->extradata = NULL; | 284 codec_context->extradata = NULL; |
285 codec_context->extradata_size = 0; | 285 codec_context->extradata_size = 0; |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout, | 289 ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout, |
290 int channels) { | 290 int channels) { |
291 switch (layout) { | 291 switch (layout) { |
292 case CH_LAYOUT_MONO: | 292 case AV_CH_LAYOUT_MONO: |
293 return CHANNEL_LAYOUT_MONO; | 293 return CHANNEL_LAYOUT_MONO; |
294 case CH_LAYOUT_STEREO: | 294 case AV_CH_LAYOUT_STEREO: |
295 return CHANNEL_LAYOUT_STEREO; | 295 return CHANNEL_LAYOUT_STEREO; |
296 case CH_LAYOUT_2_1: | 296 case AV_CH_LAYOUT_2_1: |
297 return CHANNEL_LAYOUT_2_1; | 297 return CHANNEL_LAYOUT_2_1; |
298 case CH_LAYOUT_SURROUND: | 298 case AV_CH_LAYOUT_SURROUND: |
299 return CHANNEL_LAYOUT_SURROUND; | 299 return CHANNEL_LAYOUT_SURROUND; |
300 case CH_LAYOUT_4POINT0: | 300 case AV_CH_LAYOUT_4POINT0: |
301 return CHANNEL_LAYOUT_4POINT0; | 301 return CHANNEL_LAYOUT_4POINT0; |
302 case CH_LAYOUT_2_2: | 302 case AV_CH_LAYOUT_2_2: |
303 return CHANNEL_LAYOUT_2_2; | 303 return CHANNEL_LAYOUT_2_2; |
304 case CH_LAYOUT_QUAD: | 304 case AV_CH_LAYOUT_QUAD: |
305 return CHANNEL_LAYOUT_QUAD; | 305 return CHANNEL_LAYOUT_QUAD; |
306 case CH_LAYOUT_5POINT0: | 306 case AV_CH_LAYOUT_5POINT0: |
307 return CHANNEL_LAYOUT_5POINT0; | 307 return CHANNEL_LAYOUT_5POINT0; |
308 case CH_LAYOUT_5POINT1: | 308 case AV_CH_LAYOUT_5POINT1: |
309 return CHANNEL_LAYOUT_5POINT1; | 309 return CHANNEL_LAYOUT_5POINT1; |
310 case CH_LAYOUT_5POINT0_BACK: | 310 case AV_CH_LAYOUT_5POINT0_BACK: |
311 return CHANNEL_LAYOUT_5POINT0_BACK; | 311 return CHANNEL_LAYOUT_5POINT0_BACK; |
312 case CH_LAYOUT_5POINT1_BACK: | 312 case AV_CH_LAYOUT_5POINT1_BACK: |
313 return CHANNEL_LAYOUT_5POINT1_BACK; | 313 return CHANNEL_LAYOUT_5POINT1_BACK; |
314 case CH_LAYOUT_7POINT0: | 314 case AV_CH_LAYOUT_7POINT0: |
315 return CHANNEL_LAYOUT_7POINT0; | 315 return CHANNEL_LAYOUT_7POINT0; |
316 case CH_LAYOUT_7POINT1: | 316 case AV_CH_LAYOUT_7POINT1: |
317 return CHANNEL_LAYOUT_7POINT1; | 317 return CHANNEL_LAYOUT_7POINT1; |
318 case CH_LAYOUT_7POINT1_WIDE: | 318 case AV_CH_LAYOUT_7POINT1_WIDE: |
319 return CHANNEL_LAYOUT_7POINT1_WIDE; | 319 return CHANNEL_LAYOUT_7POINT1_WIDE; |
320 case CH_LAYOUT_STEREO_DOWNMIX: | 320 case AV_CH_LAYOUT_STEREO_DOWNMIX: |
321 return CHANNEL_LAYOUT_STEREO_DOWNMIX; | 321 return CHANNEL_LAYOUT_STEREO_DOWNMIX; |
322 default: | 322 default: |
323 // FFmpeg channel_layout is 0 for .wav and .mp3. We know mono and stereo | 323 // FFmpeg channel_layout is 0 for .wav and .mp3. We know mono and stereo |
324 // from the number of channels, otherwise report errors. | 324 // from the number of channels, otherwise report errors. |
325 if (channels == 1) | 325 if (channels == 1) |
326 return CHANNEL_LAYOUT_MONO; | 326 return CHANNEL_LAYOUT_MONO; |
327 if (channels == 2) | 327 if (channels == 2) |
328 return CHANNEL_LAYOUT_STEREO; | 328 return CHANNEL_LAYOUT_STEREO; |
329 DVLOG(1) << "Unsupported channel layout: " << layout; | 329 DVLOG(1) << "Unsupported channel layout: " << layout; |
330 } | 330 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 // Iterate each stream and destroy each one of them. | 369 // Iterate each stream and destroy each one of them. |
370 if (format_context->streams) { | 370 if (format_context->streams) { |
371 int streams = format_context->nb_streams; | 371 int streams = format_context->nb_streams; |
372 for (int i = 0; i < streams; ++i) { | 372 for (int i = 0; i < streams; ++i) { |
373 AVStream* stream = format_context->streams[i]; | 373 AVStream* stream = format_context->streams[i]; |
374 | 374 |
375 // The conditions for calling avcodec_close(): | 375 // The conditions for calling avcodec_close(): |
376 // 1. AVStream is alive. | 376 // 1. AVStream is alive. |
377 // 2. AVCodecContext in AVStream is alive. | 377 // 2. AVCodecContext in AVStream is alive. |
378 // 3. AVCodec in AVCodecContext is alive. | 378 // 3. AVCodec in AVCodecContext is alive. |
379 // Notice that closing a codec context without prior avcodec_open() will | 379 // Notice that closing a codec context without prior avcodec_open2() will |
380 // result in a crash in FFmpeg. | 380 // result in a crash in FFmpeg. |
381 if (stream && stream->codec && stream->codec->codec) { | 381 if (stream && stream->codec && stream->codec->codec) { |
382 stream->discard = AVDISCARD_ALL; | 382 stream->discard = AVDISCARD_ALL; |
383 avcodec_close(stream->codec); | 383 avcodec_close(stream->codec); |
384 } | 384 } |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 // Then finally cleanup the format context. | 388 // Then finally cleanup the format context. |
389 av_close_input_file(format_context); | 389 avformat_close_input(&format_context); |
390 } | 390 } |
391 | 391 |
392 } // namespace media | 392 } // namespace media |
OLD | NEW |