]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/idroq.c
nut prefers extradata style global headers
[ffmpeg] / libavformat / idroq.c
index 15c6d55131f17603bf316a4659648b01bacca82d..add882eef3ddf7bf700726ecbadf15ab77f61b84 100644 (file)
 
 #include "avformat.h"
 
-#define LE_16(x)  ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
-#define LE_32(x)  ((((uint8_t*)(x))[3] << 24) | \
-                   (((uint8_t*)(x))[2] << 16) | \
-                   (((uint8_t*)(x))[1] << 8) | \
-                    ((uint8_t*)(x))[0])
-
 #define RoQ_MAGIC_NUMBER 0x1084
 #define RoQ_CHUNK_PREAMBLE_SIZE 8
 #define RoQ_AUDIO_SAMPLE_RATE 22050
@@ -62,6 +56,9 @@ typedef struct RoqDemuxContext {
 
 static int roq_probe(AVProbeData *p)
 {
+    if (p->buf_size < 6)
+        return 0;
+
     if ((LE_16(&p->buf[0]) != RoQ_MAGIC_NUMBER) ||
         (LE_32(&p->buf[2]) != 0xFFFFFFFF))
         return 0;
@@ -87,10 +84,6 @@ static int roq_read_header(AVFormatContext *s,
     roq->framerate = LE_16(&preamble[6]);
     roq->frame_pts_inc = 90000 / roq->framerate;
 
-    /* set the pts reference (1 pts = 1/90000) */
-    s->pts_num = 1;
-    s->pts_den = 90000;
-
     /* init private context parameters */
     roq->width = roq->height = roq->audio_channels = roq->video_pts = 
     roq->audio_frame_count = 0;
@@ -132,7 +125,7 @@ static int roq_read_header(AVFormatContext *s,
             break;
 
         default:
-            printf (" unknown RoQ chunk type (%04X)\n", LE_16(&preamble[0]));
+            av_log(s, AV_LOG_ERROR, " unknown RoQ chunk type (%04X)\n", LE_16(&preamble[0]));
             return AVERROR_INVALIDDATA;
             break;
         }
@@ -149,6 +142,8 @@ static int roq_read_header(AVFormatContext *s,
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
+    /* set the pts reference (1 pts = 1/90000) */
+    av_set_pts_info(st, 33, 1, 90000);
     roq->video_stream_index = st->index;
     st->codec.codec_type = CODEC_TYPE_VIDEO;
     st->codec.codec_id = CODEC_ID_ROQ;
@@ -160,6 +155,7 @@ static int roq_read_header(AVFormatContext *s,
         st = av_new_stream(s, 0);
         if (!st)
             return AVERROR_NOMEM;
+        av_set_pts_info(st, 33, 1, 90000);
         roq->audio_stream_index = st->index;
         st->codec.codec_type = CODEC_TYPE_AUDIO;
         st->codec.codec_id = CODEC_ID_ROQ_DPCM;
@@ -171,8 +167,6 @@ static int roq_read_header(AVFormatContext *s,
             st->codec.bits_per_sample;
         st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
     }
-printf (" video is %d x %d, audio is %d channels\n",
-  roq->width, roq->height, roq->audio_channels);
 
     return 0;
 }
@@ -193,15 +187,17 @@ static int roq_read_packet(AVFormatContext *s,
     while (!packet_read) {
 
         if (url_feof(&s->pb))
-            return -EIO;
+            return AVERROR_IO;
 
         /* get the next chunk preamble */
         if ((ret = get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) != 
             RoQ_CHUNK_PREAMBLE_SIZE)
-            return -EIO;
+            return AVERROR_IO;
 
         chunk_type = LE_16(&preamble[0]);
         chunk_size = LE_32(&preamble[2]);
+        if(chunk_size > INT_MAX)
+            return AVERROR_INVALIDDATA;
 
         switch (chunk_type) {
 
@@ -217,7 +213,7 @@ static int roq_read_packet(AVFormatContext *s,
             url_fseek(pb, codebook_size, SEEK_CUR);
             if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != 
                 RoQ_CHUNK_PREAMBLE_SIZE)
-                return -EIO;
+                return AVERROR_IO;
             chunk_size = LE_32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 + 
                 codebook_size;
 
@@ -225,13 +221,11 @@ static int roq_read_packet(AVFormatContext *s,
             url_fseek(pb, codebook_offset, SEEK_SET);
 
             /* load up the packet */
-            if (av_new_packet(pkt, chunk_size))
-                return -EIO;
+            ret= av_get_packet(pb, pkt, chunk_size);
+            if (ret != chunk_size)
+                return AVERROR_IO;
             pkt->stream_index = roq->video_stream_index;
             pkt->pts = roq->video_pts;
-            ret = get_buffer(pb, pkt->data, chunk_size);
-            if (ret != chunk_size)
-                ret = -EIO;
 
             roq->video_pts += roq->frame_pts_inc;
             packet_read = 1;
@@ -242,7 +236,7 @@ static int roq_read_packet(AVFormatContext *s,
         case RoQ_QUAD_VQ:
             /* load up the packet */
             if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE))
-                return -EIO;
+                return AVERROR_IO;
             /* copy over preamble */
             memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE);
 
@@ -258,15 +252,17 @@ static int roq_read_packet(AVFormatContext *s,
                 roq->audio_frame_count += (chunk_size / roq->audio_channels);
             }
 
-            ret = get_buffer(pb, pkt->data, chunk_size);
+            pkt->pos= url_ftell(pb);
+            ret = get_buffer(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE,
+                chunk_size);
             if (ret != chunk_size)
-                ret = -EIO;
+                ret = AVERROR_IO;
 
             packet_read = 1;
             break;
 
         default:
-            printf ("  unknown RoQ chunk (%04X)\n", chunk_type);
+            av_log(s, AV_LOG_ERROR, "  unknown RoQ chunk (%04X)\n", chunk_type);
             return AVERROR_INVALIDDATA;
             break;
         }