<div dir="ltr"><div>Hi,<br><br>I have potentially identified a defect in the code that causes audio output to be broken under<br>linux (and a buzz sound to be emitted under OSX).<br><br>This bug arises when trying to synchronize audio and subtitles, and can be triggered easily like this :<br>
- open a video + subtitles<br>- select the menu "tools/track synchronisation"<br>- enter "-10" into the "subtitle track synchro" field<br>--> The video pauses for 10 seconds, and then the sound is gone…<br>
<br></div><div>Another (faster) way to trigger it is to use the shortcuts I added recently (commit f7211d5efa4cd9ef392230d85fdf3470edefab39 ) :<br>- open a video + subtitles<br>- Press "Shift-H" (bookmark audio)<br>
</div><div>- Wait 5 seconds and press "Shift-J" (bookmark subtitle)<br></div><div>- Press "Shift-K" (correct delay between sub and video)<br></div><div><br></div><div><br>I found a way to solve this bug (it eliminates the pause, and preserves the sound), but I need help <br>
because I am not familiar enough with the source tree (yet).<br></div><div>For the moment, I barely commented out the line that causes the problem, which is not a viable solution.<br><br><br></div><div>The culprit seems to be in src/input/input.c :: UpdatePtsDelay(...)<br>
</div><div><br>static void UpdatePtsDelay( input_thread_t *p_input )<br>{<br>  //...<br></div><div>  //...Code that calculates i_audio_delay,  i_spu_delay, and i_pts_delay <br>  //...<br></div><div><br>    /* Update cr_average depending on the caching */<br>
    const int i_cr_average = var_GetInteger( p_input, "cr-average" ) * i_pts_delay / DEFAULT_PTS_DELAY;<br><br>    es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, i_audio_delay );<br>    es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, i_spu_delay );<br>
    es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, 0, i_cr_average );  //SetJitter is the root cause of the bug<br>}<br><br></div><div><br>The line that causes the bug is es_out_SetJitter(...) : it causes a delay, and may break the sound !<br>
So I made a test (I commented out the call to es_out_SetJitter and added some logs), as shown below :<br><br>static void UpdatePtsDelay( input_thread_t *p_input )<br>{<br>  //...<br><div>  //...Code that calculates i_audio_delay,  i_spu_delay, and i_pts_delay <br>
  //...<br></div><br>    /* Update cr_average depending on the caching */<br>    const int i_cr_average = var_GetInteger( p_input, "cr-average" ) * i_pts_delay / DEFAULT_PTS_DELAY;<br><br>    msg_Info(p_input, "audio_delay=%lld spu_delay=%lld  i_pts_delay=%lld i_extra_delay=%lld i_cr_average=%i",<br>
            i_audio_delay,     i_spu_delay, i_pts_delay, i_extra_delay, i_cr_average<br>    );<br>    es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, i_audio_delay );<br>    es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, i_spu_delay );<br>
    //es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, 0, i_cr_average );<br>}<br><br></div><div><br></div><div>Analysis : <br>************<br>Here is what I see with those logs if I apply a delay of -4.5 seconds to the subtitles : <br>
</div>[0x7fe6400009b8] main input: audio_delay=0 spu_delay=-4542986  i_pts_delay=4842986 i_extra_delay=-4542986 i_cr_average=645<br><div><br></div><div>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).<br>
<br></div><div>But what I do not understand is : why would applying a simple subtitle delay require the jitter to be corrected?<br><br><br></div><div>Does anyone know better than me?<br></div><div><br><br></div><div>Regards,<br>
<br>Pascal Thomet<br></div><div><br></div><div><br><br><span class=""></span><span class=""></span></div></div>