[FFmpeg-cvslog] avcodec/cdgraphics: fix decoded output when seeking to start of file
Paul B Mahol
git at videolan.org
Sun Sep 13 17:11:40 EEST 2020
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Thu Sep 10 00:39:47 2020 +0200| [e1da139a331de753867dc3af2da0d8341f9d2ed5] | committer: Paul B Mahol
avcodec/cdgraphics: fix decoded output when seeking to start of file
Also in cdg demuxer do not skip packets data, and remove
private context which is not really needed.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e1da139a331de753867dc3af2da0d8341f9d2ed5
---
libavcodec/cdgraphics.c | 10 ++++++++++
libavformat/cdg.c | 23 ++++-------------------
2 files changed, 14 insertions(+), 19 deletions(-)
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 f933819d57..8fb287a998 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,
More information about the ffmpeg-cvslog
mailing list