]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/roqaudioenc.c
eacdata: fix a memleak, return partial packets and use proper return values.
[ffmpeg] / libavcodec / roqaudioenc.c
index 5e5dde73fe1a17ea1ea6029546155f87cb3654dc..b44d5d382a0f1e8925a604fde14a04da53d35f7b 100644 (file)
@@ -21,6 +21,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/intmath.h"
 #include "avcodec.h"
 #include "bytestream.h"
 
@@ -29,7 +30,6 @@
 
 
 #define MAX_DPCM (127*127)
-static unsigned char dpcmValues[MAX_DPCM];
 
 
 typedef struct
@@ -37,18 +37,6 @@ typedef struct
     short lastSample[2];
 } ROQDPCMContext;
 
-static av_cold void roq_dpcm_table_init(void)
-{
-    int i;
-
-    /* Create a table of quick DPCM values */
-    for (i=0; i<MAX_DPCM; i++) {
-        int s= ff_sqrt(i);
-        int mid= s*s + s;
-        dpcmValues[i]= s + (i>mid);
-    }
-}
-
 static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx)
 {
     ROQDPCMContext *context = avctx->priv_data;
@@ -66,8 +54,6 @@ static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx)
         return -1;
     }
 
-    roq_dpcm_table_init();
-
     avctx->frame_size = ROQ_FIRST_FRAME_SIZE;
 
     context->lastSample[0] = context->lastSample[1] = 0;
@@ -92,8 +78,10 @@ static unsigned char dpcm_predict(short *previous, short current)
 
     if (diff >= MAX_DPCM)
         result = 127;
-    else
-        result = dpcmValues[diff];
+    else {
+        result = ff_sqrt(diff);
+        result += diff > result*result+result;
+    }
 
     /* See if this overflows */
  retry:
@@ -174,6 +162,6 @@ AVCodec roq_dpcm_encoder = {
     roq_dpcm_encode_frame,
     roq_dpcm_encode_close,
     NULL,
-    .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
+    .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
     .long_name = NULL_IF_CONFIG_SMALL("id RoQ DPCM"),
 };