]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - libavcodec/xan.c
Use memcpy instead of the very inefficient bytecopy where both are correct
[frescor/ffmpeg.git] / libavcodec / xan.c
index 27fc16488a8d31e070e2e0bb7107f828b25b254c..36e944fdb1a4d54ced040f0b0f0aff5037acee4b 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 /**
- * @file xan.c
+ * @file libavcodec/xan.c
  * Xan video decoder for Wing Commander III computer game
  * by Mario Brito (mbrito@student.dei.uc.pt)
  * and Mike Melanson (melanson@pcisys.net)
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 
 typedef struct XanContext {
@@ -54,7 +55,7 @@ typedef struct XanContext {
 
 } XanContext;
 
-static int xan_decode_init(AVCodecContext *avctx)
+static av_cold int xan_decode_init(AVCodecContext *avctx)
 {
     XanContext *s = avctx->priv_data;
 
@@ -147,7 +148,7 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
             size = opcode & 3;
             if (dest + size > dest_end)
                 return;
-            bytecopy(dest, src, size);  dest += size;  src += size;
+            memcpy(dest, src, size);  dest += size;  src += size;
 
             size = ((opcode & 0x1c) >> 2) + 3;
             if (dest + size > dest_end)
@@ -163,7 +164,7 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
             size = byte1 >> 6;
             if (dest + size > dest_end)
                 return;
-            bytecopy (dest, src, size);  dest += size;  src += size;
+            memcpy(dest, src, size);  dest += size;  src += size;
 
             size = (opcode & 0x3f) + 4;
             if (dest + size > dest_end)
@@ -180,7 +181,7 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
             size = opcode & 3;
             if (dest + size > dest_end)
                 return;
-            bytecopy (dest, src, size);  dest += size;  src += size;
+            memcpy(dest, src, size);  dest += size;  src += size;
 
             size = byte3 + 5 + ((opcode & 0xc) << 6);
             if (dest + size > dest_end)
@@ -197,12 +198,12 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
 
             if (dest + size > dest_end)
                 return;
-            bytecopy (dest, src, size);  dest += size;  src += size;
+            memcpy(dest, src, size);  dest += size;  src += size;
         }
     }
 
     size = opcode & 3;
-    bytecopy(dest, src, size);  dest += size;  src += size;
+    memcpy(dest, src, size);  dest += size;  src += size;
 }
 
 static inline void xan_wc3_output_pixel_run(XanContext *s,
@@ -404,8 +405,10 @@ static void xan_wc4_decode_frame(XanContext *s) {
 
 static int xan_decode_frame(AVCodecContext *avctx,
                             void *data, int *data_size,
-                            const uint8_t *buf, int buf_size)
+                            AVPacket *avpkt)
 {
+    const uint8_t *buf = avpkt->data;
+    int buf_size = avpkt->size;
     XanContext *s = avctx->priv_data;
     AVPaletteControl *palette_control = avctx->palctrl;
 
@@ -435,23 +438,25 @@ static int xan_decode_frame(AVCodecContext *avctx,
     if (s->last_frame.data[0])
         avctx->release_buffer(avctx, &s->last_frame);
 
-    /* shuffle frames */
-    s->last_frame = s->current_frame;
-
     *data_size = sizeof(AVFrame);
     *(AVFrame*)data = s->current_frame;
 
+    /* shuffle frames */
+    FFSWAP(AVFrame, s->current_frame, s->last_frame);
+
     /* always report that the buffer was completely consumed */
     return buf_size;
 }
 
-static int xan_decode_end(AVCodecContext *avctx)
+static av_cold int xan_decode_end(AVCodecContext *avctx)
 {
     XanContext *s = avctx->priv_data;
 
-    /* release the last frame */
+    /* release the frames */
     if (s->last_frame.data[0])
         avctx->release_buffer(avctx, &s->last_frame);
+    if (s->current_frame.data[0])
+        avctx->release_buffer(avctx, &s->current_frame);
 
     av_free(s->buffer1);
     av_free(s->buffer2);
@@ -469,6 +474,7 @@ AVCodec xan_wc3_decoder = {
     xan_decode_end,
     xan_decode_frame,
     CODEC_CAP_DR1,
+    .long_name = NULL_IF_CONFIG_SMALL("Wing Commander III / Xan"),
 };
 
 /*