[vlc-devel] Subtitles synchronization : identified a bug cause that breaks audio output under linux / need help

Pascal Thomet pthomet at gmail.com
Sat Apr 27 14:02:45 CEST 2013


Hi,

I have potentially identified a defect in the code that causes audio output
to be broken under
linux (and a buzz sound to be emitted under OSX).

This bug arises when trying to synchronize audio and subtitles, and can be
triggered easily like this :
- open a video + subtitles
- select the menu "tools/track synchronisation"
- enter "-10" into the "subtitle track synchro" field
--> The video pauses for 10 seconds, and then the sound is gone…

Another (faster) way to trigger it is to use the shortcuts I added recently
(commit f7211d5efa4cd9ef392230d85fdf3470edefab39 ) :
- open a video + subtitles
- Press "Shift-H" (bookmark audio)
- Wait 5 seconds and press "Shift-J" (bookmark subtitle)
- Press "Shift-K" (correct delay between sub and video)


I found a way to solve this bug (it eliminates the pause, and preserves the
sound), but I need help
because I am not familiar enough with the source tree (yet).
For the moment, I barely commented out the line that causes the problem,
which is not a viable solution.


The culprit seems to be in src/input/input.c :: UpdatePtsDelay(...)

static void UpdatePtsDelay( input_thread_t *p_input )
{
  //...
  //...Code that calculates i_audio_delay, i_spu_delay, and i_pts_delay
  //...

    /* Update cr_average depending on the caching */
    const int i_cr_average = var_GetInteger( p_input, "cr-average" ) *
i_pts_delay / DEFAULT_PTS_DELAY;

    es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, i_audio_delay
);
    es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, i_spu_delay );
    es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, 0, i_cr_average
);  //SetJitter is the root cause of the bug
}


The line that causes the bug is es_out_SetJitter(...) : it causes a delay,
and may break the sound !
So I made a test (I commented out the call to es_out_SetJitter and added
some logs), as shown below :

static void UpdatePtsDelay( input_thread_t *p_input )
{
  //...
  //...Code that calculates i_audio_delay, i_spu_delay, and i_pts_delay
  //...

    /* Update cr_average depending on the caching */
    const int i_cr_average = var_GetInteger( p_input, "cr-average" ) *
i_pts_delay / DEFAULT_PTS_DELAY;

    msg_Info(p_input, "audio_delay=%lld spu_delay=%lld  i_pts_delay=%lld
i_extra_delay=%lld i_cr_average=%i",
            i_audio_delay,     i_spu_delay, i_pts_delay, i_extra_delay,
i_cr_average
    );
    es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, i_audio_delay
);
    es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, i_spu_delay );
    //es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, 0, i_cr_average
);
}


Analysis :
************
Here is what I see with those logs if I apply a delay of -4.5 seconds to
the subtitles :
[0x7fe6400009b8] main input: audio_delay=0 spu_delay=-4542986
i_pts_delay=4842986 i_extra_delay=-4542986 i_cr_average=645

In a first analysis, it seems that  i_pts_delay=4842986 will create a pause
of 4.8 seconds in the video/audio output (I am not sure of it, though).

But what I do not understand is : why would applying a simple subtitle
delay require the jitter to be corrected?


Does anyone know better than me?


Regards,

Pascal Thomet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20130427/1218b2df/attachment.html>


More information about the vlc-devel mailing list