]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/adpcm.c
Merge remote branch 'qatar/master'
[ffmpeg] / libavcodec / adpcm.c
index 6a6c77b5741857562df23daaffd0758e1a53f5d9..c1ceca918a5681789dd156625d97e891e0693050 100644 (file)
@@ -382,6 +382,12 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
                     dec_sample = av_clip_int16(dec_sample);\
                     d = sample - dec_sample;\
                     ssd = nodes[j]->ssd + d*d;\
+                    /* Check for wraparound, skip such samples completely. \
+                     * Note, changing ssd to a 64 bit variable would be \
+                     * simpler, avoiding this check, but it's slower on \
+                     * x86 32 bit at the moment. */\
+                    if (ssd < nodes[j]->ssd)\
+                        goto next_##NAME;\
                     /* Collapse any two states with the same previous sample value. \
                      * One could also distinguish states by step and by 2nd to last
                      * sample, but the effects of that are negligible.
@@ -401,9 +407,10 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
                     } else {\
                         /* Try to replace one of the leaf nodes with the new \
                          * one, but try a different slot each time. */\
-                        pos = (frontier >> 1) + (heap_pos++ & ((frontier >> 1) - 1));\
+                        pos = (frontier >> 1) + (heap_pos & ((frontier >> 1) - 1));\
                         if (ssd > nodes_next[pos]->ssd)\
                             goto next_##NAME;\
+                        heap_pos++;\
                     }\
                     *h = generation;\
                     u = nodes_next[pos];\
@@ -419,7 +426,7 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
                     u->sample1 = dec_sample;\
                     paths[u->path].nibble = nibble;\
                     paths[u->path].prev = nodes[j]->path;\
-                    /* Sift the newly inserted node down in the heap to \
+                    /* Sift the newly inserted node up in the heap to \
                      * restore the heap property. */\
                     while (pos > 0) {\
                         int parent = (pos - 1) >> 1;\
@@ -743,6 +750,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
     case CODEC_ID_ADPCM_EA_R1:
     case CODEC_ID_ADPCM_EA_R2:
     case CODEC_ID_ADPCM_EA_R3:
+    case CODEC_ID_ADPCM_EA_XAS:
         max_channels = 6;
         break;
     }
@@ -1284,7 +1292,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
         }
         break;
     case CODEC_ID_ADPCM_EA:
-        if (buf_size < 4 || AV_RL32(src) >= ((buf_size - 12) * 2)) {
+        if (buf_size < 12 || AV_RL32(src) > (buf_size - 12)/30*28) {
             src += buf_size;
             break;
         }
@@ -1701,7 +1709,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
 
 #if CONFIG_ENCODERS
 #define ADPCM_ENCODER(id,name,long_name_)       \
-AVCodec name ## _encoder = {                    \
+AVCodec ff_ ## name ## _encoder = {             \
     #name,                                      \
     AVMEDIA_TYPE_AUDIO,                         \
     id,                                         \
@@ -1712,14 +1720,14 @@ AVCodec name ## _encoder = {                    \
     NULL,                                       \
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, \
     .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
-};
+}
 #else
 #define ADPCM_ENCODER(id,name,long_name_)
 #endif
 
 #if CONFIG_DECODERS
 #define ADPCM_DECODER(id,name,long_name_)       \
-AVCodec name ## _decoder = {                    \
+AVCodec ff_ ## name ## _decoder = {             \
     #name,                                      \
     AVMEDIA_TYPE_AUDIO,                         \
     id,                                         \
@@ -1729,13 +1737,13 @@ AVCodec name ## _decoder = {                    \
     NULL,                                       \
     adpcm_decode_frame,                         \
     .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
-};
+}
 #else
 #define ADPCM_DECODER(id,name,long_name_)
 #endif
 
 #define ADPCM_CODEC(id,name,long_name_)         \
-    ADPCM_ENCODER(id,name,long_name_) ADPCM_DECODER(id,name,long_name_)
+    ADPCM_ENCODER(id,name,long_name_); ADPCM_DECODER(id,name,long_name_)
 
 /* Note: Do not forget to add new entries to the Makefile as well. */
 ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm, "ADPCM 4X Movie");