Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / ffmpeg / libavformat / cdg.c
index 2d40d3d..baf37d4 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,7 +46,9 @@ static int read_header(AVFormatContext *s)
     avpriv_set_pts_info(vst, 32, 1, 300);
 
     ret = avio_size(s->pb);
-    if (ret > 0)
+    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);
 
     return 0;
@@ -50,6 +56,7 @@ static int read_header(AVFormatContext *s)
 
 static int read_packet(AVFormatContext *s, AVPacket *pkt)
 {
+    CDGContext *priv = s->priv_data;
     int ret;
 
     while (1) {
@@ -59,6 +66,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;
     pkt->dts=
     pkt->pts= pkt->pos / CDG_PACKET_SIZE;
@@ -72,6 +84,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,
     .flags          = AVFMT_GENERIC_INDEX,