comparison utils.c @ 6034:bf6169d77dbd libavformat

Store in a dedicated array the format name - codec id - codec type mapping. Simplify.
author stefano
date Sat, 22 May 2010 21:52:02 +0000
parents 44d635df3f26
children 746b2040c34e
comparison
equal deleted inserted replaced
6033:c7b98381ec2d 6034:bf6169d77dbd
342 return av_probe_input_format2(pd, is_opened, &score); 342 return av_probe_input_format2(pd, is_opened, &score);
343 } 343 }
344 344
345 static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd, int score) 345 static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd, int score)
346 { 346 {
347 AVInputFormat *fmt; 347 static const struct {
348 fmt = av_probe_input_format2(pd, 1, &score); 348 const char *name; enum CodecID id; enum AVMediaType type;
349 } fmt_id_type[] = {
350 { "aac" , CODEC_ID_AAC , AVMEDIA_TYPE_AUDIO },
351 { "ac3" , CODEC_ID_AC3 , AVMEDIA_TYPE_AUDIO },
352 { "dts" , CODEC_ID_DTS , AVMEDIA_TYPE_AUDIO },
353 { "eac3" , CODEC_ID_EAC3 , AVMEDIA_TYPE_AUDIO },
354 { "h264" , CODEC_ID_H264 , AVMEDIA_TYPE_VIDEO },
355 { "m4v" , CODEC_ID_MPEG4 , AVMEDIA_TYPE_VIDEO },
356 { "mp3" , CODEC_ID_MP3 , AVMEDIA_TYPE_AUDIO },
357 { "mpegvideo", CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
358 { 0 }
359 };
360 AVInputFormat *fmt = av_probe_input_format2(pd, 1, &score);
349 361
350 if (fmt) { 362 if (fmt) {
363 int i;
351 av_log(s, AV_LOG_DEBUG, "Probe with size=%d, packets=%d detected %s with score=%d\n", 364 av_log(s, AV_LOG_DEBUG, "Probe with size=%d, packets=%d detected %s with score=%d\n",
352 pd->buf_size, MAX_PROBE_PACKETS - st->probe_packets, fmt->name, score); 365 pd->buf_size, MAX_PROBE_PACKETS - st->probe_packets, fmt->name, score);
353 if (!strcmp(fmt->name, "mp3")) { 366 for (i = 0; fmt_id_type[i].name; i++) {
354 st->codec->codec_id = CODEC_ID_MP3; 367 if (!strcmp(fmt->name, fmt_id_type[i].name)) {
355 st->codec->codec_type = AVMEDIA_TYPE_AUDIO; 368 st->codec->codec_id = fmt_id_type[i].id;
356 } else if (!strcmp(fmt->name, "ac3")) { 369 st->codec->codec_type = fmt_id_type[i].type;
357 st->codec->codec_id = CODEC_ID_AC3; 370 break;
358 st->codec->codec_type = AVMEDIA_TYPE_AUDIO; 371 }
359 } else if (!strcmp(fmt->name, "eac3")) {
360 st->codec->codec_id = CODEC_ID_EAC3;
361 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
362 } else if (!strcmp(fmt->name, "mpegvideo")) {
363 st->codec->codec_id = CODEC_ID_MPEG2VIDEO;
364 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
365 } else if (!strcmp(fmt->name, "m4v")) {
366 st->codec->codec_id = CODEC_ID_MPEG4;
367 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
368 } else if (!strcmp(fmt->name, "h264")) {
369 st->codec->codec_id = CODEC_ID_H264;
370 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
371 } else if (!strcmp(fmt->name, "dts")) {
372 st->codec->codec_id = CODEC_ID_DTS;
373 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
374 } else if (!strcmp(fmt->name, "aac")) {
375 st->codec->codec_id = CODEC_ID_AAC;
376 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
377 } 372 }
378 } 373 }
379 return !!fmt; 374 return !!fmt;
380 } 375 }
381 376