[vlc-commits] aout: move input format to aout_owner

Rémi Denis-Courmont git at videolan.org
Mon Aug 8 22:51:38 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug  8 23:27:52 2011 +0300| [502b865b5ecb542ac693b14c3d95dff380d09ddb] | committer: Rémi Denis-Courmont

aout: move input format to aout_owner

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=502b865b5ecb542ac693b14c3d95dff380d09ddb
---

 src/audio_output/aout_internal.h |    6 ++++--
 src/audio_output/dec.c           |   16 +++++++---------
 src/audio_output/input.c         |   31 ++++++++++++++++++-------------
 3 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index e03dd32..85caf0b 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -51,8 +51,8 @@ block_t *aout_FilterBufferNew( filter_t *, int );
 /** an input stream for the audio output */
 struct aout_input_t
 {
-    audio_sample_format_t   input;
     float                   multiplier; /**< Replay gain multiplier */
+    unsigned            samplerate; /**< Input sample rate */
 
     /* pre-filters */
     filter_t *              pp_filters[AOUT_MAX_FILTERS];
@@ -106,6 +106,7 @@ typedef struct
     } volume; /**< Volume and gain management (FIXME: input manager?) */
 
     audio_sample_format_t mixer_format;
+    audio_sample_format_t input_format;
 
     /* Filters between mixer and output */
     filter_t *filters[AOUT_MAX_FILTERS];
@@ -130,7 +131,8 @@ static inline aout_owner_t *aout_owner (audio_output_t *aout)
  *****************************************************************************/
 
 /* From input.c : */
-int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_request_vout_t * );
+int aout_InputNew(audio_output_t *, const audio_sample_format_t *,
+                  aout_input_t *, const aout_request_vout_t *);
 int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
 block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
                          block_t *p_buffer, int i_input_rate, date_t * );
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index f60fa4d..50c3534 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -83,8 +83,6 @@ int aout_DecNew( audio_output_t *p_aout,
 
     p_input->b_error = true;
 
-    memcpy( &p_input->input, p_format,
-            sizeof(audio_sample_format_t) );
     if( p_replay_gain )
         p_input->replay_gain = *p_replay_gain;
 
@@ -98,6 +96,7 @@ int aout_DecNew( audio_output_t *p_aout,
     var_Destroy( p_aout, "audio-channels" );
 
     /* Recreate the output using the new format. */
+    owner->input_format = *p_format;
     if( aout_OutputNew( p_aout, p_format ) < 0 )
         goto error;
 
@@ -108,7 +107,7 @@ int aout_DecNew( audio_output_t *p_aout,
     date_Set (&owner->sync.date, VLC_TS_INVALID);
 
     owner->input = p_input;
-    aout_InputNew( p_aout, p_input, p_request_vout );
+    aout_InputNew( p_aout, p_format, p_input, p_request_vout );
     aout_unlock( p_aout );
     return 0;
 error:
@@ -161,7 +160,7 @@ static void aout_CheckRestart (audio_output_t *aout)
     owner->volume.mixer = NULL;
     aout_OutputDelete (aout);
 
-    if (aout_OutputNew (aout, &input->input))
+    if (aout_OutputNew (aout, &owner->input_format))
     {
         input->b_error = true;
         return; /* we are officially screwed */
@@ -169,7 +168,7 @@ static void aout_CheckRestart (audio_output_t *aout)
 
     owner->volume.mixer = aout_MixerNew (aout, owner->mixer_format.i_format);
 
-    if (aout_InputNew (aout, input, &input->request_vout))
+    if (aout_InputNew (aout, &owner->input_format, input, &input->request_vout))
         assert (input->b_error);
     else
         assert (!input->b_error);
@@ -187,10 +186,9 @@ block_t *aout_DecNewBuffer (audio_output_t *aout, size_t samples)
 {
     /* NOTE: the caller is responsible for serializing input change */
     aout_owner_t *owner = aout_owner (aout);
-    aout_input_t *input = owner->input;
 
-    size_t length = samples * input->input.i_bytes_per_frame
-                            / input->input.i_frame_length;
+    size_t length = samples * owner->input_format.i_bytes_per_frame
+                            / owner->input_format.i_frame_length;
     block_t *block = block_Alloc( length );
     if( likely(block != NULL) )
     {
@@ -222,7 +220,7 @@ int aout_DecPlay (audio_output_t *p_aout, block_t *p_buffer, int i_input_rate)
     assert( p_buffer->i_pts > 0 );
 
     p_buffer->i_length = (mtime_t)p_buffer->i_nb_samples * 1000000
-                                / p_input->input.i_rate;
+                                / owner->input_format.i_rate;
 
     aout_lock( p_aout );
     if( p_input->b_error )
diff --git a/src/audio_output/input.c b/src/audio_output/input.c
index 72fcba4..d51f8b6 100644
--- a/src/audio_output/input.c
+++ b/src/audio_output/input.c
@@ -66,7 +66,10 @@ static vout_thread_t *RequestVout( void *,
 /*****************************************************************************
  * aout_InputNew : allocate a new input and rework the filter pipeline
  *****************************************************************************/
-int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_request_vout_t *p_request_vout )
+int aout_InputNew( audio_output_t * p_aout,
+                   const audio_sample_format_t *restrict format,
+                   aout_input_t * p_input,
+                   const aout_request_vout_t *p_request_vout )
 {
     aout_owner_t *owner = aout_owner (p_aout);
     audio_sample_format_t chain_input_format;
@@ -75,7 +78,8 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r
     char *psz_filters, *psz_visual, *psz_scaletempo;
     int i_visual;
 
-    aout_FormatPrint( p_aout, "input", &p_input->input );
+    aout_FormatPrint( p_aout, "input", format );
+    p_input->samplerate = format->i_rate;
 
     p_input->i_nb_resamplers = p_input->i_nb_filters = 0;
 
@@ -91,9 +95,9 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r
     }
 
     /* Prepare format structure */
-    chain_input_format  = p_input->input;
+    chain_input_format  = *format;
     chain_output_format = owner->mixer_format;
-    chain_output_format.i_rate = p_input->input.i_rate;
+    chain_output_format.i_rate = format->i_rate;
     aout_FormatPrepare( &chain_output_format );
 
     /* Now add user filters */
@@ -382,7 +386,7 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r
     /* Create resamplers. */
     if (AOUT_FMT_LINEAR(&owner->mixer_format))
     {
-        chain_output_format.i_rate = (__MAX(p_input->input.i_rate,
+        chain_output_format.i_rate = (__MAX(p_input->samplerate,
                                             owner->mixer_format.i_rate)
                                  * (100 + AOUT_MAX_RESAMPLING)) / 100;
         if ( chain_output_format.i_rate == owner->mixer_format.i_rate )
@@ -400,7 +404,7 @@ int aout_InputNew( audio_output_t * p_aout, aout_input_t * p_input, const aout_r
         }
 
         /* Setup the initial rate of the resampler */
-        p_input->pp_resamplers[0]->fmt_in.audio.i_rate = p_input->input.i_rate;
+        p_input->pp_resamplers[0]->fmt_in.audio.i_rate = p_input->samplerate;
     }
     p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
 
@@ -453,13 +457,14 @@ int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input )
  *****************************************************************************/
 void aout_InputCheckAndRestart( audio_output_t * p_aout, aout_input_t * p_input )
 {
+    aout_owner_t *owner = aout_owner(p_aout);
     aout_assert_locked( p_aout );
 
     if( !p_input->b_restart )
         return;
 
     aout_InputDelete( p_aout, p_input );
-    aout_InputNew( p_aout, p_input, &p_input->request_vout );
+    aout_InputNew( p_aout, &owner->input_format, p_input, &p_input->request_vout );
 
     p_input->b_restart = false;
 }
@@ -513,8 +518,8 @@ block_t *aout_InputPlay(audio_output_t *p_aout, aout_input_t *p_input,
     {
         unsigned int * const pi_rate = &p_input->p_playback_rate_filter->fmt_in.audio.i_rate;
 #define F(r,ir) ( INPUT_RATE_DEFAULT * (r) / (ir) )
-        const int i_delta = *pi_rate - F(p_input->input.i_rate,p_input->i_last_input_rate);
-        *pi_rate = F(p_input->input.i_rate + i_delta, i_input_rate);
+        const int i_delta = *pi_rate - F(p_input->samplerate,p_input->i_last_input_rate);
+        *pi_rate = F(p_input->samplerate + i_delta, i_input_rate);
 #undef F
         p_input->i_last_input_rate = i_input_rate;
     }
@@ -628,8 +633,8 @@ block_t *aout_InputPlay(audio_output_t *p_aout, aout_input_t *p_input,
          * resampling */
         unsigned int i_nominal_rate =
           (p_input->pp_resamplers[0] == p_input->p_playback_rate_filter)
-          ? INPUT_RATE_DEFAULT * p_input->input.i_rate / i_input_rate
-          : p_input->input.i_rate;
+          ? INPUT_RATE_DEFAULT * p_input->samplerate / i_input_rate
+          : p_input->samplerate;
         if( p_input->pp_resamplers[0]->fmt_in.audio.i_rate == i_nominal_rate )
         {
             p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
@@ -724,8 +729,8 @@ static void inputResamplingStop( aout_input_t *p_input )
     {
         p_input->pp_resamplers[0]->fmt_in.audio.i_rate =
             ( p_input->pp_resamplers[0] == p_input->p_playback_rate_filter )
-            ? INPUT_RATE_DEFAULT * p_input->input.i_rate / p_input->i_last_input_rate
-            : p_input->input.i_rate;
+            ? INPUT_RATE_DEFAULT * p_input->samplerate / p_input->i_last_input_rate
+            : p_input->samplerate;
     }
 }
 



More information about the vlc-commits mailing list