[FFmpeg-devel] [PATCH] aac: fix alignment

Nicolás Dato ndato at 3way.com.ar
Thu Mar 21 03:16:03 CET 2013


Hello,
I was having the problem described in ticket #1694. The ticket is
fixed, but the problem decoding certain frames is still there (channel
element #.# is not allocated...)
So I found the problem, and made a patch, now it can decode all the
audio frames. The problem was when the decode_pce() needed to align
the bits, it was calculating the alignment from a wrong position; and
a second problem was that it was changing always the configuration
when decoding the PCE but it only has to do it when the chan_config is
0.

I wish I was in time to include this patch on the next 1.0.6 release

--

diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 37c7de5..133d6fb 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -2506,6 +2506,7 @@ static int aac_decode_frame_int(AVCodecContext
*avctx, void *data,
         goto fail;
     }

+    set_alignment_get_bits(gb);
     ac->tags_mapped = 0;
     // parse
     while ((elem_type = get_bits(gb, 3)) != TYPE_END) {
@@ -2550,7 +2551,9 @@ static int aac_decode_frame_int(AVCodecContext
*avctx, void *data,
         case TYPE_PCE: {
             uint8_t layout_map[MAX_ELEM_ID*4][3];
             int tags;
-            push_output_configuration(ac);
+            err = 0;
+            if(ac->oc[1].m4ac.chan_config == 0)
+                push_output_configuration(ac);
             tags = decode_pce(avctx, &ac->oc[1].m4ac, layout_map, gb);
             if (tags < 0) {
                 err = tags;
@@ -2559,7 +2562,7 @@ static int aac_decode_frame_int(AVCodecContext
*avctx, void *data,
             if (pce_found) {
                 av_log(avctx, AV_LOG_ERROR,
                        "Not evaluating a further
program_config_element as this construct is dubious at best.\n");
-            } else {
+            } else if(ac->oc[1].m4ac.chan_config == 0) {
                 err = output_configure(ac, layout_map, tags, OC_TRIAL_PCE, 1);
                 if (!err)
                     ac->oc[1].m4ac.chan_config = 0;
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index f16a508..a83a240 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -56,6 +56,7 @@ typedef struct GetBitContext {
     int index;
     int size_in_bits;
     int size_in_bits_plus8;
+    int index_to_align;
 } GetBitContext;

 #define VLC_TYPE int16_t
@@ -395,6 +396,7 @@ static inline int init_get_bits(GetBitContext *s,
const uint8_t *buffer,
     s->size_in_bits_plus8 = bit_size + 8;
     s->buffer_end         = buffer + buffer_size;
     s->index              = 0;
+    s->index_to_align     = 0;

     return ret;
 }
@@ -417,12 +419,17 @@ static inline int init_get_bits8(GetBitContext
*s, const uint8_t *buffer,

 static inline const uint8_t *align_get_bits(GetBitContext *s)
 {
-    int n = -get_bits_count(s) & 7;
+    int n = -(get_bits_count(s) - s->index_to_align) & 7;
     if (n)
         skip_bits(s, n);
     return s->buffer + (s->index >> 3);
 }

+static inline void set_alignment_get_bits(GetBitContext *s)
+{
+       s->index_to_align = s->index;
+}
+
 #define init_vlc(vlc, nb_bits, nb_codes,                \
                  bits, bits_wrap, bits_size,            \
                  codes, codes_wrap, codes_size,         \


More information about the ffmpeg-devel mailing list