]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/aiffdec.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavformat / aiffdec.c
index 70ce01748830625df71e11002cb97fec7df33aac..c94863c285326b57860e385046c7084c30f53f7a 100644 (file)
@@ -2,20 +2,20 @@
  * AIFF/AIFF-C demuxer
  * Copyright (c) 2006  Patrick Guimond
  *
- * This file is part of Libav.
+ * This file is part of FFmpeg.
  *
- * Libav is free software; you can redistribute it and/or
+ * 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.1 of the License, or (at your option) any later version.
  *
- * Libav 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 Libav; 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
  */
 
@@ -25,6 +25,7 @@
 #include "internal.h"
 #include "pcm.h"
 #include "aiff.h"
+#include "isom.h"
 
 #define AIFF                    0
 #define AIFF_C_VERSION1         0xA2805140
@@ -54,7 +55,7 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
 {
     int size;
 
-    if (pb->eof_reached)
+    if (url_feof(pb))
         return AVERROR(EIO);
 
     *tag = avio_rl32(pb);
@@ -70,19 +71,20 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
 static void get_meta(AVFormatContext *s, const char *key, int size)
 {
     uint8_t *str = av_malloc(size+1);
-    int res;
 
-    if (!str) {
-        avio_skip(s->pb, size);
-        return;
-    }
-
-    res = avio_read(s->pb, str, size);
-    if (res < 0)
-        return;
+    if (str) {
+        int res = avio_read(s->pb, str, size);
+        if (res < 0){
+            av_free(str);
+            return;
+        }
+        size += (size&1)-res;
+        str[res] = 0;
+        av_dict_set(&s->metadata, key, str, AV_DICT_DONT_STRDUP_VAL);
+    }else
+        size+= size&1;
 
-    str[res] = 0;
-    av_dict_set(&s->metadata, key, str, AV_DICT_DONT_STRDUP_VAL);
+    avio_skip(s->pb, size);
 }
 
 /* Returns the number of sound data frames or negative on error */
@@ -123,6 +125,13 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size,
         aiff->block_duration = 1;
     } else {
         switch (codec->codec_id) {
+        case CODEC_ID_PCM_F32BE:
+        case CODEC_ID_PCM_F64BE:
+        case CODEC_ID_PCM_S16LE:
+        case CODEC_ID_PCM_ALAW:
+        case CODEC_ID_PCM_MULAW:
+            aiff->block_duration = 1;
+            break;
         case CODEC_ID_ADPCM_IMA_QT:
             codec->block_align = 34*codec->channels;
             break;
@@ -139,6 +148,7 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size,
             codec->block_align = 35;
             break;
         default:
+            aiff->block_duration = 1;
             break;
         }
         if (codec->block_align > 0)
@@ -258,6 +268,11 @@ static int aiff_read_header(AVFormatContext *s)
             st->codec->extradata_size = size;
             avio_read(pb, st->codec->extradata, size);
             break;
+        case MKTAG('C','H','A','N'):
+            if (size < 12)
+                return AVERROR_INVALIDDATA;
+            ff_mov_read_chan(s, size, st->codec);
+            break;
         default: /* Jump */
             if (size & 1)   /* Always even aligned */
                 size++;
@@ -321,5 +336,5 @@ AVInputFormat ff_aiff_demuxer = {
     .read_header    = aiff_read_header,
     .read_packet    = aiff_read_packet,
     .read_seek      = ff_pcm_read_seek,
-    .codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0},
+    .codec_tag      = (const AVCodecTag* const []){ ff_codec_aiff_tags, 0 },
 };