]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/lscrdec.c
avformat/dashenc: Remove deprecated min_seg_duration option
[ffmpeg] / libavcodec / lscrdec.c
index 5ad043153486d74c8d15c789164385e33a8d873d..042da84bf9030eb46f07ebf606e43c8d5a5a6625 100644 (file)
@@ -1,4 +1,6 @@
 /*
+ * Copyright (c) 2019 Paul B Mahol
+ *
  * This file is part of FFmpeg.
  *
  * FFmpeg is free software; you can redistribute it and/or
@@ -74,6 +76,10 @@ static int decode_idat(LSCRContext *s, int length)
     int ret;
     s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb));
     s->zstream.next_in  = s->gb.buffer;
+
+    if (length <= 0)
+        return AVERROR_INVALIDDATA;
+
     bytestream2_skip(&s->gb, length);
 
     /* decode one line if possible */
@@ -105,7 +111,7 @@ static int decode_frame_lscr(AVCodecContext *avctx,
 {
     LSCRContext *const s = avctx->priv_data;
     GetByteContext *gb = &s->gb;
-    AVFrame *frame = data;
+    AVFrame *frame = s->last_picture;
     int ret, nb_blocks, offset = 0;
 
     if (avpkt->size < 2)
@@ -115,18 +121,14 @@ static int decode_frame_lscr(AVCodecContext *avctx,
 
     bytestream2_init(gb, avpkt->data, avpkt->size);
 
-    if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
-        return ret;
-
     nb_blocks = bytestream2_get_le16(gb);
     if (bytestream2_get_bytes_left(gb) < 2 + nb_blocks * (12 + 8))
         return AVERROR_INVALIDDATA;
 
-    if (s->last_picture->data[0]) {
-        ret = av_frame_copy(frame, s->last_picture);
-        if (ret < 0)
-            return ret;
-    }
+    ret = ff_reget_buffer(avctx, frame,
+                          nb_blocks ? 0 : FF_REGET_BUFFER_FLAG_READONLY);
+    if (ret < 0)
+        return ret;
 
     for (int b = 0; b < nb_blocks; b++) {
         int x, y, x2, y2, w, h, left;
@@ -216,8 +218,7 @@ static int decode_frame_lscr(AVCodecContext *avctx,
 
     frame->pict_type = frame->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
-    av_frame_unref(s->last_picture);
-    if ((ret = av_frame_ref(s->last_picture, frame)) < 0)
+    if ((ret = av_frame_ref(data, frame)) < 0)
         return ret;
 
     *got_frame = 1;
@@ -274,6 +275,5 @@ AVCodec ff_lscr_decoder = {
     .decode         = decode_frame_lscr,
     .flush          = lscr_decode_flush,
     .capabilities   = AV_CODEC_CAP_DR1,
-    .caps_internal  = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE |
-                      FF_CODEC_CAP_ALLOCATE_PROGRESS,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };