]> git.sesse.net Git - vlc/commitdiff
Added a b_discontinuity to aout_buffer_t for non-pcm streams.
authorLaurent Aimar <fenrir@videolan.org>
Mon, 4 Jun 2007 19:39:55 +0000 (19:39 +0000)
committerLaurent Aimar <fenrir@videolan.org>
Mon, 4 Jun 2007 19:39:55 +0000 (19:39 +0000)
Set aout_buffer_t.b_discontinuity in mpeg audio packetizer.
Silent first 3 frames on discontinuity in mad decoder.
(close #590)

include/vlc_aout.h
modules/audio_filter/converter/mpgatofixed32.c
modules/codec/mpeg_audio.c
src/audio_output/aout_internal.h

index d3f20b6cf9eb6628180879ed07122b3c36ff6d42..90fcc01cad259226fcae4ba53c9d3cf2a519578c 100644 (file)
@@ -144,6 +144,7 @@ struct aout_buffer_t
     size_t                  i_size, i_nb_bytes;
     unsigned int            i_nb_samples;
     mtime_t                 start_date, end_date;
+    vlc_bool_t              b_discontinuity; /* Set on discontinuity (for non pcm stream) */
 
     struct aout_buffer_t *  p_next;
 
@@ -155,12 +156,12 @@ struct aout_buffer_t
     void (*pf_release)( aout_buffer_t * );
 };
 
-#define aout_BufferFree( p_buffer )                                         \
+#define aout_BufferFree( p_buffer ) do {                                    \
     if( p_buffer != NULL && (p_buffer)->i_alloc_type == AOUT_ALLOC_HEAP )   \
     {                                                                       \
         free( p_buffer );                                                   \
     }                                                                       \
-    p_buffer = NULL;
+    p_buffer = NULL; } while(0)
 
 /* Size of a frame for S/PDIF output. */
 #define AOUT_SPDIF_SIZE 6144
index 941ef0a9864771863f52e4c341445208126186fe..f0c337607d456ca1d906b59ff94a08474e37c123 100644 (file)
@@ -54,8 +54,10 @@ static block_t *Convert( filter_t *, block_t * );
 struct filter_sys_t
 {
     struct mad_stream mad_stream;
-    struct mad_frame mad_frame;
-    struct mad_synth mad_synth;
+    struct mad_frame  mad_frame;
+    struct mad_synth  mad_synth;
+
+    int               i_reject_count;
 };
 
 /*****************************************************************************
@@ -109,6 +111,7 @@ static int Create( vlc_object_t *p_this )
     mad_frame_init( &p_sys->mad_frame );
     mad_synth_init( &p_sys->mad_synth );
     mad_stream_options( &p_sys->mad_stream, MAD_OPTION_IGNORECRC );
+    p_sys->i_reject_count = 0;
 
     p_filter->pf_do_work = DoWork;
     p_filter->b_in_place = 0;
@@ -135,6 +138,15 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     {
         msg_Dbg( p_aout, "libmad error: %s",
                   mad_stream_errorstr( &p_sys->mad_stream ) );
+        p_sys->i_reject_count = 3;
+    }
+    else if( p_in_buf->b_discontinuity )
+    {
+        p_sys->i_reject_count = 3;
+    }
+
+    if( p_sys->i_reject_count > 0 )
+    {
         if( p_filter->output.i_format == VLC_FOURCC('f','l','3','2') )
         {
             int i;
@@ -148,9 +160,11 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
         {
             memset( p_out_buf->p_buffer, 0, p_out_buf->i_nb_bytes );
         }
+        p_sys->i_reject_count--;
         return;
     }
 
+
     mad_synth_frame( &p_sys->mad_synth, &p_sys->mad_frame );
 
     if ( p_filter->output.i_format == VLC_FOURCC('f','i','3','2') )
index a312e736ef39dd4dc87162db44b1ea103236861c..cb645c8372745b17c942893d6f72484af8dd8797 100644 (file)
@@ -60,6 +60,8 @@ struct decoder_sys_t
     unsigned int i_channels_conf, i_channels;
     unsigned int i_rate, i_max_frame_size, i_frame_length;
     unsigned int i_layer, i_bit_rate;
+
+    vlc_bool_t   b_discontinuity;
 };
 
 enum {
@@ -152,6 +154,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_sys->i_state = STATE_NOSYNC;
     aout_DateSet( &p_sys->end_date, 0 );
     p_sys->bytestream = block_BytestreamInit( p_dec );
+    p_sys->b_discontinuity = VLC_FALSE;
 
     /* Set output properties */
     p_dec->fmt_out.i_cat = AUDIO_ES;
@@ -205,6 +208,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         }
 //        aout_DateSet( &p_sys->end_date, 0 );
         block_Release( *pp_block );
+        p_sys->b_discontinuity = VLC_TRUE;
         return NULL;
     }
 
@@ -281,6 +285,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 msg_Dbg( p_dec, "emulated startcode" );
                 block_SkipByte( &p_sys->bytestream );
                 p_sys->i_state = STATE_NOSYNC;
+                p_sys->b_discontinuity = VLC_TRUE;
                 break;
             }
 
@@ -355,6 +360,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                     msg_Dbg( p_dec, "emulated startcode on next frame" );
                     block_SkipByte( &p_sys->bytestream );
                     p_sys->i_state = STATE_NOSYNC;
+                    p_sys->b_discontinuity = VLC_TRUE;
                     break;
                 }
 
@@ -530,6 +536,8 @@ static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
     p_buf->start_date = aout_DateGet( &p_sys->end_date );
     p_buf->end_date =
         aout_DateIncrement( &p_sys->end_date, p_sys->i_frame_length );
+    p_buf->b_discontinuity = p_sys->b_discontinuity;
+    p_sys->b_discontinuity = VLC_FALSE;
 
     /* Hack for libmad filter */
     p_buf->i_nb_bytes = p_sys->i_frame_size + MAD_BUFFER_GUARD;
index 2c046b2d646d89470049870f7c344d21636a2284..7b8011b4699e052ab32bdbddb46eaebf2a1d4421 100644 (file)
@@ -59,6 +59,7 @@
             (p_new_buffer)->i_size = i_alloc_size;                          \
             (p_new_buffer)->p_buffer = (byte_t *)(p_new_buffer)             \
                                          + sizeof(aout_buffer_t);           \
+            (p_new_buffer)->b_discontinuity = VLC_FALSE;                    \
             if ( (p_previous_buffer) != NULL )                              \
             {                                                               \
                 (p_new_buffer)->start_date =                                \