]> git.sesse.net Git - vlc/blobdiff - modules/demux/aiff.c
Don't include config.h from the headers - refs #297.
[vlc] / modules / demux / aiff.c
index b502a39d49a6d8cb8022f04065c415936bc411f1..da74d56739fc0ee398329b0a66171ecfcbd71d13 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * aiff.c: Audio Interchange File Format demuxer
  *****************************************************************************
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004-2007 the VideoLAN team
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
-#include <vlc/input.h>
+#include <vlc_demux.h>
 
 /* TODO:
  *  - ...
@@ -75,7 +78,7 @@ static int Demux  ( demux_t *p_demux );
 static int Control( demux_t *p_demux, int i_query, va_list args );
 
 /* GetF80BE: read a 80 bits float in big endian */
-static unsigned int GetF80BE( uint8_t p[10] )
+static unsigned int GetF80BE( const uint8_t p[10] )
 {
     unsigned int i_mantissa = GetDWBE( &p[2] );
     int          i_exp = 30 - p[1];
@@ -101,22 +104,19 @@ static int Open( vlc_object_t *p_this )
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
 
-    uint8_t     *p_peek;
+    const uint8_t *p_peek;
 
-    if( stream_Peek( p_demux->s, &p_peek, 12 ) < 12 ) return VLC_EGENERIC;
-    if( strncmp( &p_peek[0], "FORM", 4 ) || strncmp( &p_peek[8], "AIFF", 4 ) )
-    {
+    if( stream_Peek( p_demux->s, &p_peek, 12 ) < 12 )
+        return VLC_EGENERIC;
+    if( memcmp( p_peek, "FORM", 4 )
+     || memcmp( &p_peek[8], "AIFF", 4 ) )
         return VLC_EGENERIC;
-    }
 
     /* skip aiff header */
     stream_Read( p_demux->s, NULL, 12 );
 
     /* Fill p_demux field */
-    p_demux->pf_demux = Demux;
-    p_demux->pf_control = Control;
-    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
-
+    DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys;
     es_format_Init( &p_sys->fmt, UNKNOWN_ES, 0 );
     p_sys->i_time = 1;
     p_sys->i_ssnd_pos = -1;
@@ -125,22 +125,14 @@ static int Open( vlc_object_t *p_this )
     {
         uint32_t i_size;
 
-        if( stream_Peek( p_demux->s, &p_peek, 8 ) < 8 )
-        {
-            msg_Dbg( p_demux, "cannot peek()" );
-            goto error;
-        }
+        CHECK_PEEK_GOTO( p_peek, 8 );
         i_size = GetDWBE( &p_peek[4] );
 
         msg_Dbg( p_demux, "chunk fcc=%4.4s size=%d", p_peek, i_size );
 
-        if( !strncmp( &p_peek[0], "COMM", 4 ) )
+        if( !memcmp( p_peek, "COMM", 4 ) )
         {
-            if( stream_Peek( p_demux->s, &p_peek, 18 + 8 ) < 18 + 8 )
-            {
-                msg_Dbg( p_demux, "cannot peek()" );
-                goto error;
-            }
+            CHECK_PEEK_GOTO( p_peek, 18+8 );
             es_format_Init( &p_sys->fmt, AUDIO_ES, VLC_FOURCC( 't', 'w', 'o', 's' ) );
             p_sys->fmt.audio.i_channels = GetWBE( &p_peek[8] );
             p_sys->fmt.audio.i_bitspersample = GetWBE( &p_peek[14] );
@@ -149,14 +141,9 @@ static int Open( vlc_object_t *p_this )
             msg_Dbg( p_demux, "COMM: channels=%d samples_frames=%d bits=%d rate=%d",
                      GetWBE( &p_peek[8] ), GetDWBE( &p_peek[10] ), GetWBE( &p_peek[14] ), GetF80BE( &p_peek[16] ) );
         }
-        else if( !strncmp( &p_peek[0], "SSND", 4 ) )
+        else if( !memcmp( p_peek, "SSND", 4 ) )
         {
-            if( stream_Peek( p_demux->s, &p_peek, 8 + 8 ) < 8 + 8 )
-            {
-                msg_Dbg( p_demux, "cannot peek()" );
-                goto error;
-            }
-
+            CHECK_PEEK_GOTO( p_peek, 8+8 );
             p_sys->i_ssnd_pos = stream_Tell( p_demux->s );
             p_sys->i_ssnd_size = i_size;
             p_sys->i_ssnd_offset = GetDWBE( &p_peek[8] );
@@ -173,6 +160,8 @@ static int Open( vlc_object_t *p_this )
 
         /* Skip this chunk */
         i_size += 8;
+        if( (i_size % 2) != 0 )
+            i_size++;
         if( stream_Read( p_demux->s, NULL, i_size ) != (int)i_size )
         {
             msg_Warn( p_demux, "incomplete file" );
@@ -184,7 +173,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_ssnd_end   = p_sys->i_ssnd_start + p_sys->i_ssnd_size;
 
     p_sys->i_ssnd_fsize = p_sys->fmt.audio.i_channels *
-                          ( p_sys->fmt.audio.i_bitspersample + 7 ) / 8;
+                          ((p_sys->fmt.audio.i_bitspersample + 7) / 8);
 
     if( p_sys->i_ssnd_fsize <= 0 )
     {