Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: media/ffmpeg/ffmpeg_common.cc

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

Powered by Google App Engine
This is Rietveld 408576698