X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fcdg.c;h=36f25e7f66b68af489b8e7294e027efc645192c0;hb=bc70684e74a185d7b80c8b80bdedda659cb581b8;hp=05cac6e528dcb608289a2658ff0a6f30975a5c76;hpb=ee96ab2db507b95a694f10b152481cf71842de28;p=ffmpeg diff --git a/libavformat/cdg.c b/libavformat/cdg.c index 05cac6e528d..36f25e7f66b 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; @@ -49,42 +45,31 @@ static int read_header(AVFormatContext *s) if (ret < 0) { av_log(s, AV_LOG_WARNING, "Cannot calculate duration as file size cannot be determined\n"); } else - vst->duration = (ret * vst->time_base.den) / (CDG_PACKET_SIZE * 300); + vst->duration = (ret * (int64_t)vst->time_base.den) / (CDG_PACKET_SIZE * 300); return 0; } 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; } -AVInputFormat ff_cdg_demuxer = { +const 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,