[FFmpeg-devel] [PATCH] wavdec: refactor wav_read_header() to make it more readable and display an error message in case an invalid header is detected (the current version just returns AVERROR_INVALIDDATA)

wm4 nfxjfg at googlemail.com
Thu Dec 18 14:17:20 CET 2014


On Thu, 18 Dec 2014 12:50:25 +0100
Thomas Volkert <silvo at gmx.net> wrote:

> From: Thomas Volkert <thomas at homer-conferencing.com>
> 

The commit message subject line should be at most 72 (or was it 60?)
characters long. The rest should go into the body of the commit message
(in raw git, the first line of the commit message is the subject, then
comes an empty line, and the rest is the body of the commit message).
Makes it more readable in "git log" and other tools.

> ---
>  libavformat/wavdec.c | 32 ++++++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 10 deletions(-)
> 
> diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
> index 8a7f84b..8651372 100644
> --- a/libavformat/wavdec.c
> +++ b/libavformat/wavdec.c
> @@ -248,7 +248,7 @@ static int wav_read_header(AVFormatContext *s)
>  {
>      int64_t size, av_uninit(data_size);
>      int64_t sample_count = 0;
> -    int rf64;
> +    int rf64 = 0;
>      uint32_t tag;
>      AVIOContext *pb      = s->pb;
>      AVStream *st         = NULL;
> @@ -260,17 +260,29 @@ static int wav_read_header(AVFormatContext *s)
>  
>      wav->smv_data_ofs = -1;
>  
> -    /* check RIFF header */
> -    tag = avio_rl32(pb);
> -
> -    rf64 = tag == MKTAG('R', 'F', '6', '4');
> -    wav->rifx = tag == MKTAG('R', 'I', 'F', 'X');
> -    if (!rf64 && !wav->rifx && tag != MKTAG('R', 'I', 'F', 'F'))
> +    /* read chunk ID */
> +    switch (avio_rl32(pb)) {
> +    case MKTAG('R', 'I', 'F', 'F'):
> +        break;
> +    case MKTAG('R', 'I', 'F', 'X'):
> +        wav->rifx = 1;
> +        break;
> +    case MKTAG('R', 'F', '6', '4'):
> +        rf64 = 1;
> +        break;
> +    default:
> +        av_log(s, AV_LOG_ERROR, "invalid start code in RIFF header\n");
>          return AVERROR_INVALIDDATA;

Seems like a good idea... could it print the chunk ID too, or would
that not be interesting?

> -    avio_rl32(pb); /* file size */
> -    tag = avio_rl32(pb);
> -    if (tag != MKTAG('W', 'A', 'V', 'E'))
> +    }
> +
> +    /* read chunk size */
> +    avio_rl32(pb);
> +
> +    /* read format */
> +    if (avio_rl32(pb) != MKTAG('W', 'A', 'V', 'E')) {
> +        av_log(s, AV_LOG_ERROR, "invalid format in RIFF header\n");
>          return AVERROR_INVALIDDATA;
> +    }
>  
>      if (rf64) {
>          if (avio_rl32(pb) != MKTAG('d', 's', '6', '4'))



More information about the ffmpeg-devel mailing list