]> git.sesse.net Git - vlc/blobdiff - modules/demux/voc.c
MKV: factorize the es_out_Send() and es_out_Control() calls
[vlc] / modules / demux / voc.c
index 13d86d1b28feb78de8bae83fa220bb5d273703fe..9fe503c3fcedae5710f966dd1148f3c8ea9c1b36 100644 (file)
@@ -6,19 +6,19 @@
  *
  * Authors: RĂ©mi Denis-Courmont <rem # 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -32,9 +32,6 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_demux.h>
-#include <vlc_aout.h>
-
-#include <vlc_codecs.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -196,7 +193,7 @@ static int ReadBlockHeader( demux_t *p_demux )
                 return VLC_EGENERIC;
             }
 
-            new_fmt.i_codec = VLC_FOURCC('u','8',' ',' ');
+            new_fmt.i_codec = VLC_CODEC_U8;
             new_fmt.audio.i_rate = fix_voc_sr( 1000000L / (256L - buf[0]) );
             new_fmt.audio.i_bytes_per_frame = 1;
             new_fmt.audio.i_frame_length = 1;
@@ -221,7 +218,7 @@ static int ReadBlockHeader( demux_t *p_demux )
             i_block_size = 0;
             p_sys->i_silence_countdown = GetWLE( buf );
 
-            new_fmt.i_codec = VLC_FOURCC('u','8',' ',' ');
+            new_fmt.i_codec = VLC_CODEC_U8;
             new_fmt.audio.i_rate = fix_voc_sr( 1000000L / (256L - buf[0]) );
             new_fmt.audio.i_bytes_per_frame = 1;
             new_fmt.audio.i_frame_length = 1;
@@ -272,7 +269,7 @@ static int ReadBlockHeader( demux_t *p_demux )
                 return VLC_EGENERIC;
             }
 
-            new_fmt.i_codec = VLC_FOURCC('u','8',' ',' ');
+            new_fmt.i_codec = VLC_CODEC_U8;
             new_fmt.audio.i_channels = buf[3] + 1; /* can't be nul */
             new_fmt.audio.i_rate = 256000000L /
                           ((65536L - GetWLE(buf)) * new_fmt.audio.i_channels);
@@ -285,7 +282,7 @@ static int ReadBlockHeader( demux_t *p_demux )
             /* read subsequent block 1 */
             if( stream_Read( p_demux->s, buf, 4 ) < 4 )
                 return VLC_EGENERIC; /* EOF */
+
             i_block_size = GetDWLE( buf ) >> 8;
             msg_Dbg( p_demux, "new block: type: %u, size: %u",
                     (unsigned)*buf, i_block_size );
@@ -323,11 +320,11 @@ static int ReadBlockHeader( demux_t *p_demux )
                     switch( new_fmt.audio.i_bitspersample )
                     {
                         case 8:
-                            new_fmt.i_codec = VLC_FOURCC('u','8',' ',' ');
+                            new_fmt.i_codec = VLC_CODEC_U8;
                             break;
 
                         case 16:
-                            new_fmt.i_codec = VLC_FOURCC('u','1','6','l');
+                            new_fmt.i_codec = VLC_CODEC_U16L;
                             break;
 
                         default:
@@ -341,11 +338,11 @@ static int ReadBlockHeader( demux_t *p_demux )
                     switch( new_fmt.audio.i_bitspersample )
                     {
                         case 8:
-                            new_fmt.i_codec = VLC_FOURCC('s','8',' ',' ');
+                            new_fmt.i_codec = VLC_CODEC_S8;
                             break;
 
                         case 16:
-                            new_fmt.i_codec = VLC_FOURCC('s','1','6','l');
+                            new_fmt.i_codec = VLC_CODEC_S16L;
                             break;
 
                         default:
@@ -360,6 +357,12 @@ static int ReadBlockHeader( demux_t *p_demux )
                     return VLC_EGENERIC;
             }
 
+            if( new_fmt.audio.i_channels == 0 )
+            {
+                msg_Err( p_demux, "0 channels detected" );
+                return VLC_EGENERIC;
+            }
+
             new_fmt.audio.i_bytes_per_frame = new_fmt.audio.i_channels
                 * (new_fmt.audio.i_bitspersample / 8);
             new_fmt.audio.i_frame_length = 1;
@@ -424,17 +427,18 @@ static int Demux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     block_t     *p_block;
-    int64_t     i_offset, i;
-
-    i_offset = stream_Tell( p_demux->s );
-
-    while( ( i_offset >= p_sys->i_block_end )
-         && ( p_sys->i_silence_countdown == 0 ) )
-        if( ReadBlockHeader( p_demux ) != VLC_SUCCESS )
-            return 0;
+    int64_t     i;
 
     if( p_sys->i_silence_countdown == 0 )
     {
+        int64_t i_offset = stream_Tell( p_demux->s );
+        if( i_offset >= p_sys->i_block_end )
+        {
+            if( ReadBlockHeader( p_demux ) != VLC_SUCCESS )
+                return 0;
+            return 1;
+        }
+
         i = ( p_sys->i_block_end - i_offset )
             / p_sys->fmt.audio.i_bytes_per_frame;
         if( i > SAMPLES_BUFFER )
@@ -454,7 +458,7 @@ static int Demux( demux_t *p_demux )
         if( i > SAMPLES_BUFFER )
             i = SAMPLES_BUFFER;
 
-        p_block = block_New( p_demux, i );
+        p_block = block_Alloc( i );
         if( p_block == NULL )
             return VLC_ENOMEM;
 
@@ -462,13 +466,14 @@ static int Demux( demux_t *p_demux )
         p_sys->i_silence_countdown -= i;
     }
 
-    p_block->i_dts = p_block->i_pts =
-        date_Increment( &p_sys->pts, p_sys->fmt.audio.i_frame_length * i );
+    p_block->i_dts = p_block->i_pts = VLC_TS_0 + date_Get( &p_sys->pts );
 
     es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
 
     es_out_Send( p_demux->out, p_sys->p_es, p_block );
 
+    date_Increment( &p_sys->pts, p_sys->fmt.audio.i_frame_length * i );
+
     return 1;
 }