]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - libavformat/ipmovie.c
frsh: Export information about the last RTP contract and VRES
[frescor/ffmpeg.git] / libavformat / ipmovie.c
index 731b0396bc7a31e8dd91efe3a7a29f7d4b382df1..f992b68782e138c7ce8b51a4975c801969e8f5a1 100644 (file)
@@ -2,23 +2,25 @@
  * Interplay MVE File Demuxer
  * Copyright (c) 2003 The ffmpeg Project
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /**
- * @file ipmovie.c
+ * @file libavformat/ipmovie.c
  * Interplay MVE file demuxer
  * by Mike Melanson (melanson@pcisys.net)
  * For more information regarding the Interplay MVE file format, visit:
@@ -30,6 +32,7 @@
  * up and sending out the chunks.
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 /* debugging support: #define DEBUG_IPMOVIE as non-zero to see extremely
@@ -37,6 +40,7 @@
 #define DEBUG_IPMOVIE 0
 
 #if DEBUG_IPMOVIE
+#undef printf
 #define debug_ipmovie printf
 #else
 static inline void debug_ipmovie(const char *format, ...) { }
@@ -89,8 +93,7 @@ typedef struct IPMVEContext {
     unsigned char *buf;
     int buf_size;
 
-    float fps;
-    int frame_pts_inc;
+    uint64_t frame_pts_inc;
 
     unsigned int video_width;
     unsigned int video_height;
@@ -99,20 +102,20 @@ typedef struct IPMVEContext {
     unsigned int audio_bits;
     unsigned int audio_channels;
     unsigned int audio_sample_rate;
-    unsigned int audio_type;
+    enum CodecID audio_type;
     unsigned int audio_frame_count;
 
     int video_stream_index;
     int audio_stream_index;
 
-    offset_t audio_chunk_offset;
+    int64_t audio_chunk_offset;
     int audio_chunk_size;
-    offset_t video_chunk_offset;
+    int64_t video_chunk_offset;
     int video_chunk_size;
-    offset_t decode_map_chunk_offset;
+    int64_t decode_map_chunk_offset;
     int decode_map_chunk_size;
 
-    offset_t next_chunk_offset;
+    int64_t next_chunk_offset;
 
     AVPaletteControl palette_control;
 
@@ -122,7 +125,6 @@ static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb,
     AVPacket *pkt) {
 
     int chunk_type;
-    int64_t audio_pts = 0;
 
     if (s->audio_chunk_offset) {
 
@@ -135,16 +137,11 @@ static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb,
         url_fseek(pb, s->audio_chunk_offset, SEEK_SET);
         s->audio_chunk_offset = 0;
 
-        /* figure out the audio pts */
-        audio_pts = 90000;
-        audio_pts *= s->audio_frame_count;
-        audio_pts /= s->audio_sample_rate;
-
         if (s->audio_chunk_size != av_get_packet(pb, pkt, s->audio_chunk_size))
             return CHUNK_EOF;
 
         pkt->stream_index = s->audio_stream_index;
-        pkt->pts = audio_pts;
+        pkt->pts = s->audio_frame_count;
 
         /* audio frame maintenance */
         if (s->audio_type != CODEC_ID_INTERPLAY_DPCM)
@@ -154,8 +151,8 @@ static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb,
             s->audio_frame_count +=
                 (s->audio_chunk_size - 6) / s->audio_channels;
 
-        debug_ipmovie("sending audio frame with pts %lld (%d audio frames)\n",
-            audio_pts, s->audio_frame_count);
+        debug_ipmovie("sending audio frame with pts %"PRId64" (%d audio frames)\n",
+            pkt->pts, s->audio_frame_count);
 
         chunk_type = CHUNK_VIDEO;
 
@@ -188,7 +185,7 @@ static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb,
         pkt->stream_index = s->video_stream_index;
         pkt->pts = s->video_pts;
 
-        debug_ipmovie("sending video frame with pts %lld\n",
+        debug_ipmovie("sending video frame with pts %"PRId64"\n",
             pkt->pts);
 
         s->video_pts += s->frame_pts_inc;
@@ -225,7 +222,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
 
     /* see if there are any pending packets */
     chunk_type = load_ipmovie_packet(s, pb, pkt);
-    if ((chunk_type == CHUNK_VIDEO) && (chunk_type != CHUNK_DONE))
+    if (chunk_type != CHUNK_DONE)
         return chunk_type;
 
     /* read the next chunk, wherever the file happens to be pointing */
@@ -234,8 +231,8 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
     if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
         CHUNK_PREAMBLE_SIZE)
         return CHUNK_BAD;
-    chunk_size = LE_16(&chunk_preamble[0]);
-    chunk_type = LE_16(&chunk_preamble[2]);
+    chunk_size = AV_RL16(&chunk_preamble[0]);
+    chunk_type = AV_RL16(&chunk_preamble[2]);
 
     debug_ipmovie("chunk type 0x%04X, 0x%04X bytes: ", chunk_type, chunk_size);
 
@@ -285,7 +282,7 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
             break;
         }
 
-        opcode_size = LE_16(&opcode_preamble[0]);
+        opcode_size = AV_RL16(&opcode_preamble[0]);
         opcode_type = opcode_preamble[2];
         opcode_version = opcode_preamble[3];
 
@@ -323,10 +320,9 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
                 chunk_type = CHUNK_BAD;
                 break;
             }
-            s->fps = 1000000.0 / (LE_32(&scratch[0]) * LE_16(&scratch[4]));
-            s->frame_pts_inc = 90000 / s->fps;
+            s->frame_pts_inc = ((uint64_t)AV_RL32(&scratch[0])) * AV_RL16(&scratch[4]);
             debug_ipmovie("  %.2f frames/second (timer div = %d, subdiv = %d)\n",
-                s->fps, LE_32(&scratch[0]), LE_16(&scratch[4]));
+                1000000.0/s->frame_pts_inc, AV_RL32(&scratch[0]), AV_RL16(&scratch[4]));
             break;
 
         case OPCODE_INIT_AUDIO_BUFFERS:
@@ -341,8 +337,8 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
                 chunk_type = CHUNK_BAD;
                 break;
             }
-            s->audio_sample_rate = LE_16(&scratch[4]);
-            audio_flags = LE_16(&scratch[2]);
+            s->audio_sample_rate = AV_RL16(&scratch[4]);
+            audio_flags = AV_RL16(&scratch[2]);
             /* bit 0 of the flags: 0 = mono, 1 = stereo */
             s->audio_channels = (audio_flags & 1) + 1;
             /* bit 1 of the flags: 0 = 8 bit, 1 = 16 bit */
@@ -379,8 +375,8 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
                 chunk_type = CHUNK_BAD;
                 break;
             }
-            s->video_width = LE_16(&scratch[0]) * 8;
-            s->video_height = LE_16(&scratch[2]) * 8;
+            s->video_width = AV_RL16(&scratch[0]) * 8;
+            s->video_height = AV_RL16(&scratch[2]) * 8;
             debug_ipmovie("video resolution: %d x %d\n",
                 s->video_width, s->video_height);
             break;
@@ -440,11 +436,11 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
             }
 
             /* load the palette into internal data structure */
-            first_color = LE_16(&scratch[0]);
-            last_color = first_color + LE_16(&scratch[2]) - 1;
+            first_color = AV_RL16(&scratch[0]);
+            last_color = first_color + AV_RL16(&scratch[2]) - 1;
             /* sanity check (since they are 16 bit values) */
             if ((first_color > 0xFF) || (last_color > 0xFF)) {
-                debug_ipmovie("demux_ipmovie: set_palette indices out of range (%d -> %d)\n",
+                debug_ipmovie("demux_ipmovie: set_palette indexes out of range (%d -> %d)\n",
                     first_color, last_color);
                 chunk_type = CHUNK_BAD;
                 break;
@@ -505,8 +501,6 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
 
 static int ipmovie_probe(AVProbeData *p)
 {
-    if (p->buf_size < IPMOVIE_SIGNATURE_SIZE)
-        return 0;
     if (strncmp(p->buf, IPMOVIE_SIGNATURE, IPMOVIE_SIGNATURE_SIZE) != 0)
         return 0;
 
@@ -516,8 +510,8 @@ static int ipmovie_probe(AVProbeData *p)
 static int ipmovie_read_header(AVFormatContext *s,
                                AVFormatParameters *ap)
 {
-    IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
-    ByteIOContext *pb = &s->pb;
+    IPMVEContext *ipmovie = s->priv_data;
+    ByteIOContext *pb = s->pb;
     AVPacket pkt;
     AVStream *st;
     unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
@@ -539,20 +533,20 @@ static int ipmovie_read_header(AVFormatContext *s,
      * it; if it is the first video chunk, this is a silent file */
     if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
         CHUNK_PREAMBLE_SIZE)
-        return AVERROR_IO;
-    chunk_type = LE_16(&chunk_preamble[2]);
+        return AVERROR(EIO);
+    chunk_type = AV_RL16(&chunk_preamble[2]);
     url_fseek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR);
 
     if (chunk_type == CHUNK_VIDEO)
-        ipmovie->audio_type = 0;  /* no audio */
+        ipmovie->audio_type = CODEC_ID_NONE;  /* no audio */
     else if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
         return AVERROR_INVALIDDATA;
 
     /* initialize the stream decoders */
     st = av_new_stream(s, 0);
     if (!st)
-        return AVERROR_NOMEM;
-    av_set_pts_info(st, 33, 1, 90000);
+        return AVERROR(ENOMEM);
+    av_set_pts_info(st, 63, 1, 1000000);
     ipmovie->video_stream_index = st->index;
     st->codec->codec_type = CODEC_TYPE_VIDEO;
     st->codec->codec_id = CODEC_ID_INTERPLAY_VIDEO;
@@ -566,20 +560,20 @@ static int ipmovie_read_header(AVFormatContext *s,
     if (ipmovie->audio_type) {
         st = av_new_stream(s, 0);
         if (!st)
-            return AVERROR_NOMEM;
-        av_set_pts_info(st, 33, 1, 90000);
+            return AVERROR(ENOMEM);
+        av_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate);
         ipmovie->audio_stream_index = st->index;
         st->codec->codec_type = CODEC_TYPE_AUDIO;
         st->codec->codec_id = ipmovie->audio_type;
         st->codec->codec_tag = 0;  /* no tag */
         st->codec->channels = ipmovie->audio_channels;
         st->codec->sample_rate = ipmovie->audio_sample_rate;
-        st->codec->bits_per_sample = ipmovie->audio_bits;
+        st->codec->bits_per_coded_sample = ipmovie->audio_bits;
         st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
-            st->codec->bits_per_sample;
+            st->codec->bits_per_coded_sample;
         if (st->codec->codec_id == CODEC_ID_INTERPLAY_DPCM)
             st->codec->bit_rate /= 2;
-        st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+        st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
     }
 
     return 0;
@@ -588,43 +582,30 @@ static int ipmovie_read_header(AVFormatContext *s,
 static int ipmovie_read_packet(AVFormatContext *s,
                                AVPacket *pkt)
 {
-    IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
-    ByteIOContext *pb = &s->pb;
+    IPMVEContext *ipmovie = s->priv_data;
+    ByteIOContext *pb = s->pb;
     int ret;
 
     ret = process_ipmovie_chunk(ipmovie, pb, pkt);
     if (ret == CHUNK_BAD)
         ret = AVERROR_INVALIDDATA;
     else if (ret == CHUNK_EOF)
-        ret = AVERROR_IO;
+        ret = AVERROR(EIO);
     else if (ret == CHUNK_NOMEM)
-        ret = AVERROR_NOMEM;
-    else
+        ret = AVERROR(ENOMEM);
+    else if (ret == CHUNK_VIDEO)
         ret = 0;
+    else
+        ret = -1;
 
     return ret;
 }
 
-static int ipmovie_read_close(AVFormatContext *s)
-{
-//    IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
-
-    return 0;
-}
-
-static AVInputFormat ipmovie_iformat = {
+AVInputFormat ipmovie_demuxer = {
     "ipmovie",
-    "Interplay MVE format",
+    NULL_IF_CONFIG_SMALL("Interplay MVE format"),
     sizeof(IPMVEContext),
     ipmovie_probe,
     ipmovie_read_header,
     ipmovie_read_packet,
-    ipmovie_read_close,
 };
-
-int ipmovie_init(void)
-{
-    av_register_input_format(&ipmovie_iformat);
-    return 0;
-}
-