]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/flac.c
Use same string in definition as in ui
[vlc] / modules / packetizer / flac.c
index 449b88d490121c85ac7979dbdf94fd45d78b3aa6..19de0bfc364dac78c9280d3ba36e8f6d3d1e8523 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * flac.c: flac packetizer module.
  *****************************************************************************
- * Copyright (C) 1999-2001 the VideoLAN team
+ * Copyright (C) 1999-2001 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *          Sigmund Augdal Helberg <dnumgis@videolan.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program 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.
  *
  * This program 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 General Public License for more details.
+ * 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 General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -36,6 +36,7 @@
 
 #include <vlc_block_helper.h>
 #include <vlc_bits.h>
+#include "packetizer_helper.h"
 
 /*****************************************************************************
  * Module descriptor
@@ -89,16 +90,27 @@ struct decoder_sys_t
     unsigned int i_rate, i_channels, i_bits_per_sample;
 };
 
-enum
+static const int pi_channels_maps[9] =
 {
-    STATE_NOSYNC,
-    STATE_SYNC,
-    STATE_HEADER,
-    STATE_NEXT_SYNC,
-    STATE_GET_DATA,
-    STATE_SEND_DATA
+    0,
+    AOUT_CHAN_CENTER,
+    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
+    AOUT_CHAN_CENTER | AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
+    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT
+     | AOUT_CHAN_REARRIGHT,
+    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
+     | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT,
+    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
+     | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE,
+    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
+     | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
+     | AOUT_CHAN_MIDDLERIGHT,
+    AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_REARLEFT
+     | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT
+     | AOUT_CHAN_LFE
 };
 
+
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -127,7 +139,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_state       = STATE_NOSYNC;
     p_sys->b_stream_info = false;
     p_sys->i_pts         = VLC_TS_INVALID;
-    p_sys->bytestream    = block_BytestreamInit();
+    block_BytestreamInit( &p_sys->bytestream );
 
     /* */
     es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
@@ -237,7 +249,7 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
             while( block_PeekBytes( &p_sys->bytestream, p_header, 2 )
                    == VLC_SUCCESS )
             {
-                if( p_header[0] == 0xFF && p_header[1] == 0xF8 )
+                if( p_header[0] == 0xFF && (p_header[1] & 0xFE) == 0xF8 )
                 {
                     p_sys->i_state = STATE_SYNC;
                     break;
@@ -304,7 +316,7 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
                                           MAX_FLAC_HEADER_SIZE )
                    == VLC_SUCCESS )
             {
-                if( p_header[0] == 0xFF && p_header[1] == 0xF8 )
+                if( p_header[0] == 0xFF && (p_header[1] & 0xFE) == 0xF8 )
                 {
                     /* Check if frame is valid and get frame info */
                     int i_frame_length =
@@ -336,7 +348,7 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
             }
 
         case STATE_SEND_DATA:
-            p_sout_block = block_New( p_dec, p_sys->i_frame_size );
+            p_sout_block = block_Alloc( p_sys->i_frame_size );
 
             /* Copy the whole frame into the buffer. When we reach this point
              * we already know we have enough data available. */
@@ -347,6 +359,11 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
             if( p_sys->i_pts == p_sys->bytestream.p_block->i_pts )
                 p_sys->i_pts = p_sys->bytestream.p_block->i_pts = VLC_TS_INVALID;
 
+            p_dec->fmt_out.audio.i_channels = p_sys->i_channels;
+            p_dec->fmt_out.audio.i_physical_channels =
+                p_dec->fmt_out.audio.i_original_channels =
+                    pi_channels_maps[p_sys->stream_info.channels];
+
             /* So p_block doesn't get re-added several times */
             *pp_block = block_BytestreamPop( &p_sys->bytestream );
 
@@ -378,15 +395,9 @@ static int SyncInfo( decoder_t *p_dec, uint8_t *p_buf,
     int i_header, i_temp, i_read;
     unsigned i_blocksize = 0;
     int i_blocksize_hint = 0, i_sample_rate_hint = 0;
-    uint64_t i_sample_number = 0;
-
-    bool b_variable_blocksize = ( p_sys->b_stream_info &&
-        p_sys->stream_info.min_blocksize != p_sys->stream_info.max_blocksize );
-    bool b_fixed_blocksize = ( p_sys->b_stream_info &&
-        p_sys->stream_info.min_blocksize == p_sys->stream_info.max_blocksize );
 
     /* Check syncword */
-    if( p_buf[0] != 0xFF || p_buf[1] != 0xF8 ) return 0;
+    if( p_buf[0] != 0xFF || (p_buf[1] & 0xFE) != 0xF8 ) return 0;
 
     /* Check there is no emulated sync code in the rest of the header */
     if( p_buf[2] == 0xff || p_buf[3] == 0xFF ) return 0;
@@ -395,7 +406,8 @@ static int SyncInfo( decoder_t *p_dec, uint8_t *p_buf,
     switch( i_temp = p_buf[2] >> 4 )
     {
     case 0:
-        if( b_fixed_blocksize )
+        if( p_sys->b_stream_info &&
+            p_sys->stream_info.min_blocksize == p_sys->stream_info.max_blocksize )
             i_blocksize = p_sys->stream_info.min_blocksize;
         else return 0; /* We can't do anything with this */
         break;
@@ -427,6 +439,10 @@ static int SyncInfo( decoder_t *p_dec, uint8_t *p_buf,
         i_blocksize = 256 << (i_temp - 8);
         break;
     }
+    if( p_sys->b_stream_info &&
+        ( i_blocksize < p_sys->stream_info.min_blocksize ||
+          i_blocksize > p_sys->stream_info.max_blocksize ) )
+        return 0;
 
     /* Find samplerate */
     switch( i_temp = p_buf[2] & 0x0f )
@@ -546,20 +562,9 @@ static int SyncInfo( decoder_t *p_dec, uint8_t *p_buf,
     /* End of fixed size header */
     i_header = 4;
 
-    /* Find Sample/Frame number */
-    if( i_blocksize_hint && b_variable_blocksize )
-    {
-        i_sample_number = read_utf8( &p_buf[i_header++], &i_read );
-        if( i_sample_number == INT64_C(0xffffffffffffffff) ) return 0;
-    }
-    else
-    {
-        i_sample_number = read_utf8( &p_buf[i_header++], &i_read );
-        if( i_sample_number == INT64_C(0xffffffffffffffff) ) return 0;
-
-        if( p_sys->b_stream_info )
-            i_sample_number *= p_sys->stream_info.min_blocksize;
-    }
+    /* Check Sample/Frame number */
+    if( read_utf8( &p_buf[i_header++], &i_read ) == INT64_C(0xffffffffffffffff) )
+        return 0;
 
     i_header += i_read;