]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/c93.c
rtsp: make ff_sdp_parse return value forwarded
[ffmpeg] / libavformat / c93.c
index 369ae8e01ee1377619cb2d8fcde3188f9076cb16..dbb2bf389ec8f6b2d24bee73216576b333a6c8ab 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "avformat.h"
 #include "voc.h"
+#include "libavutil/intreadwrite.h"
 
 typedef struct {
     uint16_t index;
@@ -29,7 +30,7 @@ typedef struct {
 } C93BlockRecord;
 
 typedef struct {
-    voc_dec_context_t voc;
+    VocDecContext voc;
 
     C93BlockRecord block_records[512];
     int current_block;
@@ -43,20 +44,23 @@ typedef struct {
 
 static int probe(AVProbeData *p)
 {
-    if (p->buf[0] == 0x01 && p->buf[1] == 0x00 &&
-        p->buf[4] == 0x01 + p->buf[2] &&
-        p->buf[8] == p->buf[4] + p->buf[6] &&
-        p->buf[12] == p->buf[8] + p->buf[10])
-        return AVPROBE_SCORE_MAX;
-
-    return 0;
+    int i;
+    int index = 1;
+    if (p->buf_size < 16)
+        return 0;
+    for (i = 0; i < 16; i += 4) {
+        if (AV_RL16(p->buf + i) != index || !p->buf[i + 2] || !p->buf[i + 3])
+            return 0;
+        index += p->buf[i + 2];
+    }
+    return AVPROBE_SCORE_MAX;
 }
 
 static int read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
 {
     AVStream *video;
-    ByteIOContext *pb = &s->pb;
+    ByteIOContext *pb = s->pb;
     C93DemuxContext *c93 = s->priv_data;
     int i;
     int framecount = 0;
@@ -77,14 +81,14 @@ static int read_header(AVFormatContext *s,
 
     video = av_new_stream(s, 0);
     if (!video)
-        return AVERROR_NOMEM;
+        return AVERROR(ENOMEM);
 
-    video->codec->codec_type = CODEC_TYPE_VIDEO;
+    video->codec->codec_type = AVMEDIA_TYPE_VIDEO;
     video->codec->codec_id = CODEC_ID_C93;
     video->codec->width = 320;
     video->codec->height = 192;
     /* 4:3 320x200 with 8 empty lines */
-    video->codec->sample_aspect_ratio = (AVRational) { 5, 6 };
+    video->sample_aspect_ratio = (AVRational) { 5, 6 };
     video->time_base = (AVRational) { 2, 25 };
     video->nb_frames = framecount;
     video->duration = framecount;
@@ -101,7 +105,7 @@ static int read_header(AVFormatContext *s,
 
 static int read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-    ByteIOContext *pb = &s->pb;
+    ByteIOContext *pb = s->pb;
     C93DemuxContext *c93 = s->priv_data;
     C93BlockRecord *br = &c93->block_records[c93->current_block];
     int datasize;
@@ -115,21 +119,21 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
             if (!c93->audio) {
                 c93->audio = av_new_stream(s, 1);
                 if (!c93->audio)
-                    return AVERROR_NOMEM;
-                c93->audio->codec->codec_type = CODEC_TYPE_AUDIO;
+                    return AVERROR(ENOMEM);
+                c93->audio->codec->codec_type = AVMEDIA_TYPE_AUDIO;
             }
             url_fskip(pb, 26); /* VOC header */
             ret = voc_get_packet(s, pkt, c93->audio, datasize - 26);
             if (ret > 0) {
                 pkt->stream_index = 1;
-                pkt->flags |= PKT_FLAG_KEY;
+                pkt->flags |= AV_PKT_FLAG_KEY;
                 return ret;
             }
         }
     }
     if (c93->current_frame >= br->frames) {
         if (c93->current_block >= 511 || !br[1].length)
-            return AVERROR_IO;
+            return AVERROR(EIO);
         br++;
         c93->current_block++;
         c93->current_frame = 0;
@@ -154,7 +158,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
 
     ret = get_buffer(pb, pkt->data + 1, datasize);
     if (ret < datasize) {
-        ret = AVERROR_IO;
+        ret = AVERROR(EIO);
         goto fail;
     }
 
@@ -168,7 +172,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
         pkt->data[0] |= C93_HAS_PALETTE;
         ret = get_buffer(pb, pkt->data + pkt->size, datasize);
         if (ret < datasize) {
-            ret = AVERROR_IO;
+            ret = AVERROR(EIO);
             goto fail;
         }
         pkt->size += 768;
@@ -178,7 +182,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
 
     /* only the first frame is guaranteed to not reference previous frames */
     if (c93->current_block == 0 && c93->current_frame == 0) {
-        pkt->flags |= PKT_FLAG_KEY;
+        pkt->flags |= AV_PKT_FLAG_KEY;
         pkt->data[0] |= C93_FIRST_FRAME;
     }
     return 0;
@@ -188,9 +192,9 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
     return ret;
 }
 
-AVInputFormat c93_demuxer = {
+AVInputFormat ff_c93_demuxer = {
     "c93",
-    "Interplay C93",
+    NULL_IF_CONFIG_SMALL("Interplay C93"),
     sizeof(C93DemuxContext),
     probe,
     read_header,