---
 libavcodec/dxa.c |   44 ++++++++++++++++++++++++++------------------
 1 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/libavcodec/dxa.c b/libavcodec/dxa.c
index 97b912a..baeb067 100644
--- a/libavcodec/dxa.c
+++ b/libavcodec/dxa.c
@@ -29,6 +29,7 @@
 
 #include "libavutil/intreadwrite.h"
 #include "avcodec.h"
+#include "bytestream.h"
 
 #include <zlib.h>
 
@@ -42,12 +43,14 @@ typedef struct DxaDecContext {
     int dsize;
     uint8_t *decomp_buf;
     uint32_t pal[256];
+    GetByteContext g;
 } DxaDecContext;
 
 static const int shift1[6] = { 0, 8, 8, 8, 4, 4 };
 static const int shift2[6] = { 0, 0, 8, 4, 0, 4 };
 
-static int decode_13(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst, 
uint8_t *src, uint8_t *ref)
+static int decode_13(AVCodecContext *avctx, DxaDecContext *c,
+                     uint8_t* dst, uint8_t *src, uint8_t *ref)
 {
     uint8_t *code, *data, *mv, *msk, *tmp, *tmp2;
     int i, j, k;
@@ -188,31 +191,30 @@ static int decode_13(AVCodecContext *avctx, DxaDecContext 
*c, uint8_t* dst, uint
     return 0;
 }
 
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, 
AVPacket *avpkt)
+static int decode_frame(AVCodecContext *avctx,
+                        void *data, int *data_size, AVPacket *avpkt)
 {
-    const uint8_t *buf = avpkt->data;
-    int buf_size = avpkt->size;
     DxaDecContext * const c = avctx->priv_data;
     uint8_t *outptr, *srcptr, *tmpptr;
     unsigned long dsize;
     int i, j, compr;
     int stride;
-    int orig_buf_size = buf_size;
     int pc = 0;
 
+    bytestream2_init(&c->g, avpkt->data, avpkt->size);
+
     /* make the palette available on the way out */
-    if(buf[0]=='C' && buf[1]=='M' && buf[2]=='A' && buf[3]=='P'){
+    if(bytestream2_peek_be32(&c->g) == MKTAG('C','M','A','P')) {
         int r, g, b;
 
-        buf += 4;
+        bytestream2_skip(&c->g, 4);
         for(i = 0; i < 256; i++){
-            r = *buf++;
-            g = *buf++;
-            b = *buf++;
+            r = bytestream2_get_byte(&c->g);
+            g = bytestream2_get_byte(&c->g);
+            b = bytestream2_get_byte(&c->g);
             c->pal[i] = (r << 16) | (g << 8) | b;
         }
         pc = 1;
-        buf_size -= 768+4;
     }
 
     if(avctx->get_buffer(avctx, &c->pic) < 0){
@@ -227,13 +229,15 @@ static int decode_frame(AVCodecContext *avctx, void 
*data, int *data_size, AVPac
     tmpptr = c->prev.data[0];
     stride = c->pic.linesize[0];
 
-    if(buf[0]=='N' && buf[1]=='U' && buf[2]=='L' && buf[3]=='L')
+    if(bytestream2_get_be32(&c->g) == MKTAG('N','U','L','L'))
         compr = -1;
-    else
-        compr = buf[4];
+    else {
+        compr = bytestream2_get_byte(&c->g);
+    }
 
     dsize = c->dsize;
-    if((compr != 4 && compr != -1) && uncompress(c->decomp_buf, &dsize, buf + 
9, buf_size - 9) != Z_OK){
+    if((compr != 4 && compr != -1) &&
+        uncompress(c->decomp_buf, &dsize, avpkt->data + 
bytestream2_tell(&c->g) + 9, avpkt->size - 9) != Z_OK) {
         av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n");
         return -1;
     }
@@ -242,7 +246,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *data_size, AVPac
         c->pic.key_frame = 0;
         c->pic.pict_type = AV_PICTURE_TYPE_P;
         if(c->prev.data[0])
-            memcpy(c->pic.data[0], c->prev.data[0], c->pic.linesize[0] * 
avctx->height);
+            memcpy(c->pic.data[0],
+                   c->prev.data[0],
+                   c->pic.linesize[0] * avctx->height);
         else{ // Should happen only when first frame is 'NULL'
             memset(c->pic.data[0], 0, c->pic.linesize[0] * avctx->height);
             c->pic.key_frame = 1;
@@ -273,7 +279,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *data_size, AVPac
         decode_13(avctx, c, c->pic.data[0], srcptr, c->prev.data[0]);
         break;
     default:
-        av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type 
%d\n", buf[4]);
+        av_log(avctx, AV_LOG_ERROR,
+               "Unknown/unsupported compression type %d\n",
+               compr);
         return -1;
     }
 
@@ -285,7 +293,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *data_size, AVPac
     *(AVFrame*)data = c->prev;
 
     /* always report that the buffer was completely consumed */
-    return orig_buf_size;
+    return avpkt->size;
 }
 
 static av_cold int decode_init(AVCodecContext *avctx)
-- 
1.7.5.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to