[SCM] libav/experimental: better AC3 header error reporting

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 16:07:09 UTC 2013


The following commit has been merged in the experimental branch:
commit 3df880934e721d7e37e4feb1d4a3f226cfc1bf2d
Author: Justin Ruggles <justin.ruggles at gmail.com>
Date:   Sat Sep 15 02:41:24 2007 +0000

    better AC3 header error reporting
    
    Originally committed as revision 10496 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index e8b8b5b..d97c86e 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -44,21 +44,21 @@ int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr)
 
     hdr->sync_word = get_bits(&gbc, 16);
     if(hdr->sync_word != 0x0B77)
-        return -1;
+        return AC3_PARSE_ERROR_SYNC;
 
     /* read ahead to bsid to make sure this is AC-3, not E-AC-3 */
     hdr->bsid = show_bits_long(&gbc, 29) & 0x1F;
     if(hdr->bsid > 10)
-        return -2;
+        return AC3_PARSE_ERROR_BSID;
 
     hdr->crc1 = get_bits(&gbc, 16);
     hdr->fscod = get_bits(&gbc, 2);
     if(hdr->fscod == 3)
-        return -3;
+        return AC3_PARSE_ERROR_SAMPLE_RATE;
 
     hdr->frmsizecod = get_bits(&gbc, 6);
     if(hdr->frmsizecod > 37)
-        return -4;
+        return AC3_PARSE_ERROR_FRAME_SIZE;
 
     skip_bits(&gbc, 5); // skip bsid, already got it
 
diff --git a/libavcodec/ac3_parser.h b/libavcodec/ac3_parser.h
index fb35b97..c623034 100644
--- a/libavcodec/ac3_parser.h
+++ b/libavcodec/ac3_parser.h
@@ -25,6 +25,13 @@
 
 #include "ac3.h"
 
+typedef enum {
+    AC3_PARSE_ERROR_SYNC        = -1,
+    AC3_PARSE_ERROR_BSID        = -2,
+    AC3_PARSE_ERROR_SAMPLE_RATE = -3,
+    AC3_PARSE_ERROR_FRAME_SIZE  = -4,
+} AC3ParseError;
+
 /**
  * Parses AC-3 frame header.
  * Parses the header up to the lfeon element, which is the first 52 or 54 bits
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index e59b416..70c4d93 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1089,16 +1089,32 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
 {
     AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
     int16_t *out_samples = (int16_t *)data;
-    int i, blk, ch;
+    int i, blk, ch, err;
 
     /* initialize the GetBitContext with the start of valid AC-3 Frame */
     init_get_bits(&ctx->gb, buf, buf_size * 8);
 
     /* parse the syncinfo */
-    if (ac3_parse_header(ctx)) {
-        av_log(avctx, AV_LOG_ERROR, "\n");
-        *data_size = 0;
-        return buf_size;
+    err = ac3_parse_header(ctx);
+    if(err) {
+        switch(err) {
+            case AC3_PARSE_ERROR_SYNC:
+                av_log(avctx, AV_LOG_ERROR, "frame sync error\n");
+                break;
+            case AC3_PARSE_ERROR_BSID:
+                av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n");
+                break;
+            case AC3_PARSE_ERROR_SAMPLE_RATE:
+                av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n");
+                break;
+            case AC3_PARSE_ERROR_FRAME_SIZE:
+                av_log(avctx, AV_LOG_ERROR, "invalid frame size\n");
+                break;
+            default:
+                av_log(avctx, AV_LOG_ERROR, "invalid header\n");
+                break;
+        }
+        return -1;
     }
 
     avctx->sample_rate = ctx->sampling_rate;

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list