]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/cdg.c
avdevice: Add missing header for NULL_IF_CONFIG_SMALL
[ffmpeg] / libavformat / cdg.c
index 974880a63039d36352edcc33ca220a2dc217b6ee..e6996919252f6e8cdc94f38626abe4d1651b1cf8 100644 (file)
 #define CDG_COMMAND        0x09
 #define CDG_MASK           0x3F
 
+typedef struct CDGContext {
+    int got_first_packet;
+} CDGContext;
+
 static int read_header(AVFormatContext *s)
 {
     AVStream *vst;
@@ -42,14 +46,16 @@ static int read_header(AVFormatContext *s)
     avpriv_set_pts_info(vst, 32, 1, 300);
 
     ret = avio_size(s->pb);
-    if (ret > 0)
-        vst->duration = (ret * vst->time_base.den) / (CDG_PACKET_SIZE * 300);
+    if (ret < 0)
+        return ret;
 
+    vst->duration = (ret * 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) {
@@ -59,6 +65,11 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
         av_free_packet(pkt);
     }
 
+    if (!priv->got_first_packet) {
+        pkt->flags |= AV_PKT_FLAG_KEY;
+        priv->got_first_packet = 1;
+    }
+
     pkt->stream_index = 0;
     return ret;
 }
@@ -66,6 +77,7 @@ 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,
     .extensions     = "cdg",