diff mbox series

[FFmpeg-devel] avcodec/cdgraphics: fix decoded output when seeking to start of file

Message ID 20200909224257.22775-1-onemda@gmail.com
State Accepted
Commit e1da139a331de753867dc3af2da0d8341f9d2ed5
Headers show
Series [FFmpeg-devel] avcodec/cdgraphics: fix decoded output when seeking to start of file
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Paul B Mahol Sept. 9, 2020, 10:42 p.m. UTC
Also in cdg demuxer do not skip packets data, and remove
private context which is not really needed.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/cdgraphics.c | 10 ++++++++++
 libavformat/cdg.c       | 23 ++++-------------------
 2 files changed, 14 insertions(+), 19 deletions(-)

Comments

Paul B Mahol Sept. 13, 2020, 9:09 a.m. UTC | #1
On Thu, Sep 10, 2020 at 12:42:57AM +0200, Paul B Mahol wrote:
> Also in cdg demuxer do not skip packets data, and remove
> private context which is not really needed.
> 
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavcodec/cdgraphics.c | 10 ++++++++++
>  libavformat/cdg.c       | 23 ++++-------------------
>  2 files changed, 14 insertions(+), 19 deletions(-)
> 

will apply.
diff mbox series

Patch

diff --git a/libavcodec/cdgraphics.c b/libavcodec/cdgraphics.c
index 469128964c..965f43684a 100644
--- a/libavcodec/cdgraphics.c
+++ b/libavcodec/cdgraphics.c
@@ -365,6 +365,15 @@  static int cdg_decode_frame(AVCodecContext *avctx,
     return avpkt->size;
 }
 
+static void cdg_decode_flush(AVCodecContext *avctx)
+{
+    CDGraphicsContext *cc = avctx->priv_data;
+
+    memset(cc->frame->data[0], 0, cc->frame->linesize[0] * avctx->height);
+    if (!avctx->frame_number)
+        memset(cc->frame->data[1], 0, AVPALETTE_SIZE);
+}
+
 static av_cold int cdg_decode_end(AVCodecContext *avctx)
 {
     CDGraphicsContext *cc = avctx->priv_data;
@@ -383,5 +392,6 @@  AVCodec ff_cdgraphics_decoder = {
     .init           = cdg_decode_init,
     .close          = cdg_decode_end,
     .decode         = cdg_decode_frame,
+    .flush          = cdg_decode_flush,
     .capabilities   = AV_CODEC_CAP_DR1,
 };
diff --git a/libavformat/cdg.c b/libavformat/cdg.c
index 05cac6e528..ed30c3c0f6 100644
--- a/libavformat/cdg.c
+++ b/libavformat/cdg.c
@@ -26,10 +26,6 @@ 
 #define CDG_COMMAND        0x09
 #define CDG_MASK           0x3F
 
-typedef struct CDGContext {
-    int got_first_packet;
-} CDGContext;
-
 static int read_header(AVFormatContext *s)
 {
     AVStream *vst;
@@ -56,26 +52,16 @@  static int read_header(AVFormatContext *s)
 
 static int read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-    CDGContext *priv = s->priv_data;
     int ret;
 
-    while (1) {
-        ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
-        if (ret < 1 || (pkt->data[0] & CDG_MASK) == CDG_COMMAND)
-            break;
-        av_packet_unref(pkt);
-    }
-
-    if (!priv->got_first_packet) {
-        pkt->flags |= AV_PKT_FLAG_KEY;
-        priv->got_first_packet = 1;
-    }
-
+    ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
     pkt->stream_index = 0;
     pkt->dts=
     pkt->pts= pkt->pos / CDG_PACKET_SIZE;
 
-    if(ret>5 && (pkt->data[0]&0x3F) == 9 && (pkt->data[1]&0x3F)==1 && !(pkt->data[2+2+1] & 0x0F)){
+    if (!pkt->pos || (ret > 5 &&
+         (pkt->data[0] & CDG_MASK) == CDG_COMMAND &&
+         (pkt->data[1] & CDG_MASK) == 1 && !(pkt->data[2+2+1] & 0x0F))) {
         pkt->flags = AV_PKT_FLAG_KEY;
     }
     return ret;
@@ -84,7 +70,6 @@  static int read_packet(AVFormatContext *s, AVPacket *pkt)
 AVInputFormat ff_cdg_demuxer = {
     .name           = "cdg",
     .long_name      = NULL_IF_CONFIG_SMALL("CD Graphics"),
-    .priv_data_size = sizeof(CDGContext),
     .read_header    = read_header,
     .read_packet    = read_packet,
     .flags          = AVFMT_GENERIC_INDEX,