[FFmpeg-devel] [PATCH] Correct header parsing for CDATA files

Michael Niedermayer michaelni
Mon Nov 5 09:49:14 CET 2007


On Mon, Nov 05, 2007 at 12:27:23PM +0900, Jonathan Wilson wrote:
> This patch fixes up the header parsing for command & conquer 3 .cdata files 
> based on information discovered (and added to the multimedia wiki) by 
> myself.
>
> The PCM format is not used by the files that come with the game as far as I 
> can tell but can be created by the MOD SDK.
>

> Index: libavformat/eacdata.c
> ===================================================================
> --- libavformat/eacdata.c	(revision 10927)
> +++ libavformat/eacdata.c	(working copy)
> @@ -39,7 +39,7 @@
>  {
>      const uint8_t *b = p->buf;
>  
> -    if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C))
> +    if ((b[0] == 0x02 || b[0] == 0x04 || b[0] == 0x05) && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C))
>          return AVPROBE_SCORE_MAX/8;
>      return 0;
>  }

seperate patch and please check a few more bytes, this is too easily true
in random data


> @@ -48,28 +48,39 @@
>  {
>      CdataDemuxContext *cdata = s->priv_data;
>      ByteIOContext *pb = &s->pb;
> -    unsigned int sample_rate, header;
> +    unsigned int sample_rate, codec, channels;
>      AVStream *st;
>  
> -    header = get_be16(pb);
> +    codec = get_byte(pb);
> +    channels = get_byte(pb);

spliting a variable -> seperate patch


> -    switch (header) {
> -        case 0x0400: cdata->channels = 1; break;
> -        case 0x0404: cdata->channels = 2; break;
> -        case 0x040C: cdata->channels = 4; break;
> +    st = av_new_stream(s, 0);
> +    if (!st)
> +        return AVERROR(ENOMEM);
> +
> +    switch (codec) {
> +        case 0x02: //PCM
> +            st->codec->codec_id = CODEC_ID_PCM_S16BE;
> +            break;
> +        case 0x04: //EA XAS ADPCM
> +            st->codec->codec_id = CODEC_ID_ADPCM_EA_XAS;
> +            break;
> +        case 0x05: //EALayer3
> +            av_log(s, AV_LOG_INFO, "EALayer3 MPEG audio not supported\n");
> +            return -1;
> +		case 0: //streamed audio
> +            av_log(s, AV_LOG_INFO, "Streaming audio not supported\n");
> +            return -1;
>          default:
> -            av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
> +            av_log(s, AV_LOG_INFO, "unknown codec 0x%02x\n", codec);
>              return -1;
>      };

tabs are forbidden in svn
and the list of codec_tag <-> codec_id mappings should be exported in
AVInputFormat.codec_tag and av_codec_get_id() (or another function)
could then be used to map tag->id

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20071105/2e000a08/attachment.pgp>



More information about the ffmpeg-devel mailing list