[vlc-commits] mixer: cleanup packetization

Rémi Denis-Courmont git at videolan.org
Thu Jun 9 17:26:22 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jun  9 18:25:32 2011 +0300| [7404d2eb6f2b3739cd537d894fa663e72d03e733] | committer: Rémi Denis-Courmont

mixer: cleanup packetization

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

 src/audio_output/mixer.c |   80 ++++++++++++++++++++-------------------------
 1 files changed, 36 insertions(+), 44 deletions(-)

diff --git a/src/audio_output/mixer.c b/src/audio_output/mixer.c
index 7f87083..c7ade44 100644
--- a/src/audio_output/mixer.c
+++ b/src/audio_output/mixer.c
@@ -194,32 +194,27 @@ static int MixBuffer( aout_instance_t * p_aout, float volume )
 
         /* Additionally check that p_first_byte_to_mix is well located. */
         const unsigned framesize = p_mixer->fmt.i_bytes_per_frame;
-        mtime_t i_buffer = (start_date - p_buffer->i_pts)
-                         * framesize * p_mixer->fmt.i_rate / CLOCK_FREQ;
-
-        if( !((i_buffer + framesize > 0) && (i_buffer < framesize)) )
+        ssize_t delta = (start_date - p_buffer->i_pts)
+                      * p_mixer->fmt.i_rate / CLOCK_FREQ;
+        if( delta != 0 )
+            msg_Warn( p_mixer, "mixer start is not output end (%zd)", delta );
+        if( delta < 0 )
         {
-            msg_Warn( p_mixer, "mixer start is not output start (%"PRId64")",
-                      i_buffer );
-
-            /* Round to the nearest multiple */
-            i_buffer /= p_mixer->fmt.i_bytes_per_frame;
-            i_buffer *= p_mixer->fmt.i_bytes_per_frame;
-            if( i_buffer < 0 )
-            {
-                /* Is it really the best way to do it ? */
-                aout_lock_output_fifo( p_aout );
-                aout_FifoSet( &p_aout->output.fifo, 0 );
-                date_Set( &exact_start_date, 0 );
-                aout_unlock_output_fifo( p_aout );
-                goto giveup;
-            }
-            p_buffer->p_buffer += i_buffer;
-            p_buffer->i_buffer -= i_buffer;
-            i_buffer /= framesize;
-            p_buffer->i_nb_samples -= i_buffer;
-            p_buffer->i_pts += i_buffer * CLOCK_FREQ / p_mixer->fmt.i_rate;
-            p_buffer->i_length -= i_buffer * CLOCK_FREQ / p_mixer->fmt.i_rate;
+            /* Is it really the best way to do it ? */
+            aout_lock_output_fifo( p_aout );
+            aout_FifoSet( &p_aout->output.fifo, 0 );
+            date_Set( &exact_start_date, 0 );
+            aout_unlock_output_fifo( p_aout );
+            goto giveup;
+        }
+        if( delta > 0 )
+        {
+            p_buffer->i_nb_samples -= delta;
+            p_buffer->i_pts += delta * CLOCK_FREQ / p_mixer->fmt.i_rate;
+            p_buffer->i_length -= delta * CLOCK_FREQ / p_mixer->fmt.i_rate;
+            delta *= framesize;
+            p_buffer->p_buffer += delta;
+            p_buffer->i_buffer -= delta;
         }
 
         /* Build packet with adequate number of samples */
@@ -231,28 +226,19 @@ static int MixBuffer( aout_instance_t * p_aout, float volume )
             goto giveup;
         p_buffer->i_nb_samples = samples;
 
-        for( uint8_t *p_out = p_buffer->p_buffer;; )
+        for( uint8_t *p_out = p_buffer->p_buffer; needed > 0; )
         {
-            uint8_t *p_in = p_fifo->p_first->p_buffer;
-            size_t avail = p_fifo->p_first->i_nb_samples * framesize;
-
-            if( avail < needed )
+            aout_buffer_t *p_inbuf = p_fifo->p_first;
+            if( unlikely(p_inbuf == NULL) )
             {
-                vlc_memcpy( p_out, p_in, avail );
-                needed -= avail;
-                p_out += avail;
-
-                /* Next buffer */
-                aout_BufferFree( aout_FifoPop( p_fifo ) );
-                if( p_input->fifo.p_first == NULL )
-                {
-                    msg_Err( p_mixer, "internal amix error" );
-                    vlc_memset( p_out, 0, needed );
-                    break;
-                }
-                p_in = p_fifo->p_first->p_buffer;
+                msg_Err( p_mixer, "internal amix error" );
+                vlc_memset( p_out, 0, needed );
+                break;
             }
-            else
+
+            const uint8_t *p_in = p_inbuf->p_buffer;
+            size_t avail = p_inbuf->i_nb_samples * framesize;
+            if( avail > needed )
             {
                 vlc_memcpy( p_out, p_in, needed );
                 p_fifo->p_first->p_buffer += needed;
@@ -263,6 +249,12 @@ static int MixBuffer( aout_instance_t * p_aout, float volume )
                 p_fifo->p_first->i_length -= needed * CLOCK_FREQ / p_mixer->fmt.i_rate;
                 break;
             }
+
+            vlc_memcpy( p_out, p_in, avail );
+            needed -= avail;
+            p_out += avail;
+            /* Next buffer */
+            aout_BufferFree( aout_FifoPop( p_fifo ) );
         }
     }
     else



More information about the vlc-commits mailing list