]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blobdiff - libavformat/iff.c
frsh: Export information about the last RTP contract and VRES
[frescor/ffmpeg.git] / libavformat / iff.c
index db46b082c56a7fab6a2fa077d8b4feb6a147310d..812ed23404e4d4bc4c52855fb4de49e387353219 100644 (file)
  */
 
 /**
- * @file iff.c
+ * @file libavformat/iff.c
  * IFF file demuxer
  * by Jaikrishnan Menon
  * for more information on the .iff file format, visit:
  * http://wiki.multimedia.cx/index.php?title=IFF
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define ID_8SVX       MKTAG('8','S','V','X')
@@ -52,7 +53,7 @@
 
 #define PACKET_SIZE 1024
 
-typedef enum {COMP_NONE, COMP_FIB, COMP_EXP} svx8_compression_t;
+typedef enum {COMP_NONE, COMP_FIB, COMP_EXP} svx8_compression_type;
 
 typedef struct {
     uint32_t  body_size;
@@ -60,6 +61,19 @@ typedef struct {
     uint32_t  audio_frame_count;
 } IffDemuxContext;
 
+
+static void interleave_stereo(const uint8_t *src, uint8_t *dest, int size)
+{
+    uint8_t *end = dest + size;
+    size = size>>1;
+
+    while(dest < end) {
+        *dest++ = *src;
+        *dest++ = *(src+size);
+        src++;
+    }
+}
+
 static int iff_probe(AVProbeData *p)
 {
     const uint8_t *d = p->buf;
@@ -77,7 +91,7 @@ static int iff_read_header(AVFormatContext *s,
     ByteIOContext *pb = s->pb;
     AVStream *st;
     uint32_t chunk_id, data_size;
-    int padding, ret, done = 0;
+    int padding, done = 0;
 
     st = av_new_stream(s, 0);
     if (!st)
@@ -136,9 +150,9 @@ static int iff_read_header(AVFormatContext *s,
         return -1;
     }
 
-    st->codec->bits_per_sample = 8;
-    st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_sample;
-    st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
+    st->codec->bits_per_coded_sample = 8;
+    st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample;
+    st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
 
     return 0;
 }
@@ -152,7 +166,20 @@ static int iff_read_packet(AVFormatContext *s,
 
     if(iff->sent_bytes > iff->body_size)
         return AVERROR(EIO);
-    ret = av_get_packet(pb, pkt, PACKET_SIZE);
+
+    if(s->streams[0]->codec->channels == 2) {
+        uint8_t sample_buffer[PACKET_SIZE];
+
+        ret = get_buffer(pb, sample_buffer, PACKET_SIZE);
+        if(av_new_packet(pkt, PACKET_SIZE) < 0) {
+            av_log(s, AV_LOG_ERROR, "iff: cannot allocate packet \n");
+            return AVERROR(ENOMEM);
+        }
+        interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE);
+    }
+    else {
+        ret = av_get_packet(pb, pkt, PACKET_SIZE);
+    }
 
     if(iff->sent_bytes == 0)
         pkt->flags |= PKT_FLAG_KEY;
@@ -166,7 +193,7 @@ static int iff_read_packet(AVFormatContext *s,
 
 AVInputFormat iff_demuxer = {
     "IFF",
-    "IFF format",
+    NULL_IF_CONFIG_SMALL("IFF format"),
     sizeof(IffDemuxContext),
     iff_probe,
     iff_read_header,