]> git.sesse.net Git - vlc/blobdiff - modules/codec/lpcm.c
Clean up properly on exit.
[vlc] / modules / codec / lpcm.c
index 73b90780963d8fed23c889c48ba98d7eac7b6080..1360a4f1c44965e7d7eb0bab78188cbaadb399c9 100644 (file)
@@ -493,7 +493,11 @@ static int OpenEncoder( vlc_object_t *p_this )
  *****************************************************************************/
 static void CloseEncoder ( vlc_object_t *p_this )
 {
-    VLC_UNUSED(p_this);
+    encoder_t     *p_enc = (encoder_t *)p_this;
+    encoder_sys_t *p_sys = p_enc->p_sys;
+
+    free( p_sys->p_buffer );
+    free( p_sys );
 }
 
 /*****************************************************************************
@@ -559,9 +563,14 @@ static block_t *EncodeFrames( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
         p_sys->i_buffer_used = 0;
         i_bytes_consumed += i_consume_bytes;
 
-        p_block->i_dts = p_block->i_pts = p_aout_buf->i_pts +
+        /* We need to find i_length by means of next_pts due to possible roundoff errors. */
+        mtime_t this_pts = p_aout_buf->i_pts +
             (i * p_sys->i_frame_samples + i_start_offset) * CLOCK_FREQ / p_sys->i_rate;
-        p_block->i_length = p_sys->i_frame_samples * CLOCK_FREQ / p_sys->i_rate;
+        mtime_t next_pts = p_aout_buf->i_pts +
+            ((i + 1) * p_sys->i_frame_samples + i_start_offset) * CLOCK_FREQ / p_sys->i_rate;
+
+        p_block->i_pts = p_block->i_dts = this_pts;
+        p_block->i_length = next_pts - this_pts;
 
         if( !p_first_block )
             p_first_block = p_last_block = p_block;