]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/cdg.c
avpacket: Deprecate av_dup_packet
[ffmpeg] / libavformat / cdg.c
index 150496762bfec8e1c70a4a1587d873de3f9f308c..285bfaf35b271a1958d7e9df7558752b7eb0484b 100644 (file)
  */
 
 #include "avformat.h"
+#include "internal.h"
 
 #define CDG_PACKET_SIZE    24
+#define CDG_COMMAND        0x09
+#define CDG_MASK           0x3F
 
-static int read_header(AVFormatContext *s, AVFormatParameters *ap)
+typedef struct CDGContext {
+    int got_first_packet;
+} CDGContext;
+
+static int read_header(AVFormatContext *s)
 {
     AVStream *vst;
     int ret;
 
-    vst = av_new_stream(s, 0);
+    vst = avformat_new_stream(s, NULL);
     if (!vst)
         return AVERROR(ENOMEM);
 
     vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
-    vst->codec->codec_id   = CODEC_ID_CDGRAPHICS;
+    vst->codec->codec_id   = AV_CODEC_ID_CDGRAPHICS;
 
     /// 75 sectors/sec * 4 packets/sector = 300 packets/sec
-    av_set_pts_info(vst, 32, 1, 300);
+    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;
 
-    ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
+    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;
+    }
 
     pkt->stream_index = 0;
     return ret;
@@ -57,8 +76,9 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
 
 AVInputFormat ff_cdg_demuxer = {
     .name           = "cdg",
-    .long_name      = NULL_IF_CONFIG_SMALL("CD Graphics Format"),
+    .long_name      = NULL_IF_CONFIG_SMALL("CD Graphics"),
+    .priv_data_size = sizeof(CDGContext),
     .read_header    = read_header,
     .read_packet    = read_packet,
-    .extensions = "cdg"
+    .extensions     = "cdg",
 };