1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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.
This commit is contained in:
Paul B Mahol 2020-09-10 00:39:47 +02:00
parent 55af1807f7
commit e1da139a33
2 changed files with 14 additions and 19 deletions

View File

@ -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,
};

View File

@ -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,