]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cdgraphics.c
xsubdec: Convert to the new bitstream reader
[ffmpeg] / libavcodec / cdgraphics.c
index b8a6fb845b094fc658b31c758dd25393270c9ab8..3b68f452f4151b5dac969a84d7b7e518a816e9c5 100644 (file)
@@ -261,7 +261,7 @@ static void cdg_scroll(CDGraphicsContext *cc, uint8_t *data,
 static int cdg_decode_frame(AVCodecContext *avctx,
                             void *data, int *got_frame, AVPacket *avpkt)
 {
-    const uint8_t *buf = avpkt->data;
+    GetByteContext gb;
     int buf_size       = avpkt->size;
     int ret;
     uint8_t command, inst;
@@ -269,10 +269,8 @@ static int cdg_decode_frame(AVCodecContext *avctx,
     AVFrame *frame = data;
     CDGraphicsContext *cc = avctx->priv_data;
 
-    if (buf_size < CDG_MINIMUM_PKT_SIZE) {
-        av_log(avctx, AV_LOG_ERROR, "buffer too small for decoder\n");
-        return AVERROR(EINVAL);
-    }
+    bytestream2_init(&gb, avpkt->data, avpkt->size);
+
 
     ret = ff_reget_buffer(avctx, cc->frame);
     if (ret) {
@@ -282,11 +280,11 @@ static int cdg_decode_frame(AVCodecContext *avctx,
     if (!avctx->frame_number)
         memset(cc->frame->data[0], 0, cc->frame->linesize[0] * avctx->height);
 
-    command = bytestream_get_byte(&buf);
-    inst    = bytestream_get_byte(&buf);
+    command = bytestream2_get_byte(&gb);
+    inst    = bytestream2_get_byte(&gb);
     inst    &= CDG_MASK;
-    buf += 2;  /// skipping 2 unneeded bytes
-    bytestream_get_buffer(&buf, cdg_data, buf_size - CDG_HEADER_SIZE);
+    bytestream2_skip(&gb, 2);
+    bytestream2_get_buffer(&gb, cdg_data, sizeof(cdg_data));
 
     if ((command & CDG_MASK) == CDG_COMMAND) {
         switch (inst) {
@@ -351,10 +349,9 @@ static int cdg_decode_frame(AVCodecContext *avctx,
         *got_frame = 1;
     } else {
         *got_frame = 0;
-        buf_size   = 0;
     }
 
-    return buf_size;
+    return avpkt->size;
 }
 
 static av_cold int cdg_decode_end(AVCodecContext *avctx)
@@ -375,5 +372,5 @@ AVCodec ff_cdgraphics_decoder = {
     .init           = cdg_decode_init,
     .close          = cdg_decode_end,
     .decode         = cdg_decode_frame,
-    .capabilities   = CODEC_CAP_DR1,
+    .capabilities   = AV_CODEC_CAP_DR1,
 };