]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/flashsv.c
gain code, gain pitch and pitch delay decoding for ACELP based codecs
[ffmpeg] / libavcodec / flashsv.c
index 3214d18605e7fbe917b220aa173ccddd1a2266b8..3842594ad264300cc9e00fb5c640fc0c995edc03 100644 (file)
@@ -3,18 +3,20 @@
  * Copyright (C) 2004 Alex Beregszaszi
  * Copyright (C) 2006 Benjamin Larsson
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "common.h"
 #include "avcodec.h"
 #include "bitstream.h"
 
-#ifdef CONFIG_ZLIB
 #include <zlib.h>
-#endif
 
 typedef struct FlashSVContext {
     AVCodecContext *avctx;
@@ -63,9 +62,7 @@ typedef struct FlashSVContext {
     int block_width, block_height;
     uint8_t* tmpblock;
     int block_size;
-#ifdef CONFIG_ZLIB
     z_stream zstream;
-#endif
 } FlashSVContext;
 
 
@@ -82,13 +79,12 @@ static void copy_region(uint8_t *sptr, uint8_t *dptr,
 }
 
 
-static int flashsv_decode_init(AVCodecContext *avctx)
+static av_cold int flashsv_decode_init(AVCodecContext *avctx)
 {
-    FlashSVContext *s = (FlashSVContext *)avctx->priv_data;
+    FlashSVContext *s = avctx->priv_data;
     int zret; // Zlib return code
 
     s->avctx = avctx;
-#ifdef CONFIG_ZLIB
     s->zstream.zalloc = Z_NULL;
     s->zstream.zfree = Z_NULL;
     s->zstream.opaque = Z_NULL;
@@ -97,12 +93,7 @@ static int flashsv_decode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
         return 1;
     }
-#else
-    av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled. Needed for the decoder.\n");
-    return 1;
-#endif
     avctx->pix_fmt = PIX_FMT_BGR24;
-    avctx->has_b_frames = 0;
     s->frame.data[0] = NULL;
 
     return 0;
@@ -111,9 +102,9 @@ static int flashsv_decode_init(AVCodecContext *avctx)
 
 static int flashsv_decode_frame(AVCodecContext *avctx,
                                     void *data, int *data_size,
-                                    uint8_t *buf, int buf_size)
+                                    const uint8_t *buf, int buf_size)
 {
-    FlashSVContext *s = (FlashSVContext *)avctx->priv_data;
+    FlashSVContext *s = avctx->priv_data;
     int h_blocks, v_blocks, h_part, v_part, i, j;
     GetBitContext gb;
 
@@ -143,12 +134,12 @@ static int flashsv_decode_frame(AVCodecContext *avctx,
     if(s->block_size < s->block_width*s->block_height) {
         if (s->tmpblock != NULL)
             av_free(s->tmpblock);
-        s->block_size = s->block_width*s->block_height;
-        if ((s->tmpblock = av_malloc(3*s->block_size)) == NULL) {
+        if ((s->tmpblock = av_malloc(3*s->block_width*s->block_height)) == NULL) {
             av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
             return -1;
         }
     }
+    s->block_size = s->block_width*s->block_height;
 
     /* init the image size once */
     if((avctx->width==0) && (avctx->height==0)){
@@ -196,7 +187,6 @@ static int flashsv_decode_frame(AVCodecContext *avctx,
                 /* no change, don't do anything */
             } else {
                 /* decompress block */
-#ifdef CONFIG_ZLIB
                 int ret = inflateReset(&(s->zstream));
                 if (ret != Z_OK)
                 {
@@ -210,7 +200,7 @@ static int flashsv_decode_frame(AVCodecContext *avctx,
                 ret = inflate(&(s->zstream), Z_FINISH);
                 if (ret == Z_DATA_ERROR)
                 {
-                    av_log(avctx, AV_LOG_ERROR, "Zlib resync occured\n");
+                    av_log(avctx, AV_LOG_ERROR, "Zlib resync occurred\n");
                     inflateSync(&(s->zstream));
                     ret = inflate(&(s->zstream), Z_FINISH);
                 }
@@ -220,10 +210,6 @@ static int flashsv_decode_frame(AVCodecContext *avctx,
                     av_log(avctx, AV_LOG_ERROR, "error in decompression of block %dx%d: %d\n", i, j, ret);
                     /* return -1; */
                 }
-#else
-                av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled in.\n");
-                return -1;
-#endif
                 copy_region(s->tmpblock, s->frame.data[0], s->image_height-(hp+hs+1), wp, hs, ws, s->frame.linesize[0]);
                 skip_bits(&gb, 8*size);   /* skip the consumed bits */
             }
@@ -242,12 +228,10 @@ static int flashsv_decode_frame(AVCodecContext *avctx,
 }
 
 
-static int flashsv_decode_end(AVCodecContext *avctx)
+static av_cold int flashsv_decode_end(AVCodecContext *avctx)
 {
-    FlashSVContext *s = (FlashSVContext *)avctx->priv_data;
-#ifdef CONFIG_ZLIB
+    FlashSVContext *s = avctx->priv_data;
     inflateEnd(&(s->zstream));
-#endif
     /* release the frame if needed */
     if (s->frame.data[0])
         avctx->release_buffer(avctx, &s->frame);
@@ -270,5 +254,6 @@ AVCodec flashsv_decoder = {
     flashsv_decode_end,
     flashsv_decode_frame,
     CODEC_CAP_DR1,
-    .pix_fmts = (enum PixelFormat[]){PIX_FMT_BGR24, -1},
+    .pix_fmts = (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE},
+    .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video v1"),
 };