All: preliminary support for audio while playing faster/slower (1/4 -> 4).
[vlc.git] / modules / codec / a52.c
index bbff46e..844507a 100644 (file)
@@ -29,6 +29,7 @@
 #include <vlc/vlc.h>
 #include <vlc_codec.h>
 #include <vlc_aout.h>
+#include <vlc_input.h>
 #include <vlc_block_helper.h>
 
 #define A52_HEADER_SIZE 7
@@ -57,6 +58,7 @@ struct decoder_sys_t
     int i_frame_size, i_bit_rate;
     unsigned int i_rate, i_channels, i_channels_conf;
 
+    int i_input_rate;
 };
 
 enum {
@@ -128,6 +130,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     aout_DateSet( &p_sys->end_date, 0 );
 
     p_sys->bytestream = block_BytestreamInit( p_dec );
+    p_sys->i_input_rate = INPUT_RATE_DEFAULT;
 
     /* Set output properties */
     p_dec->fmt_out.i_cat = AUDIO_ES;
@@ -187,6 +190,9 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
+    if( (*pp_block)->i_rate > 0 )
+        p_sys->i_input_rate = (*pp_block)->i_rate;
+
     block_BytestreamPush( &p_sys->bytestream, *pp_block );
 
     while( 1 )
@@ -385,7 +391,8 @@ static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
     if( p_buf == NULL ) return NULL;
 
     p_buf->start_date = aout_DateGet( &p_sys->end_date );
-    p_buf->end_date = aout_DateIncrement( &p_sys->end_date, A52_FRAME_NB );
+    p_buf->end_date = aout_DateIncrement( &p_sys->end_date,
+                                          A52_FRAME_NB * p_sys->i_input_rate / INPUT_RATE_DEFAULT );
 
     return p_buf;
 }
@@ -403,8 +410,10 @@ static block_t *GetSoutBuffer( decoder_t *p_dec )
 
     p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date );
 
-    p_block->i_length = aout_DateIncrement( &p_sys->end_date, A52_FRAME_NB ) -
-        p_block->i_pts;
+    p_block->i_length =
+        aout_DateIncrement( &p_sys->end_date,
+                            A52_FRAME_NB * p_sys->i_input_rate / INPUT_RATE_DEFAULT ) -
+            p_block->i_pts;
 
     return p_block;
 }