Commit febe55b8 authored by Gildas Bazin's avatar Gildas Bazin

* modules/audio_output/directx.c: backported directx audio output fix from trunk (#13322).

parent b4ab7eab
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
#include <mmsystem.h> #include <mmsystem.h>
#include <dsound.h> #include <dsound.h>
#define FRAME_SIZE 2048 /* The size is in samples, not in bytes */ #define FRAME_SIZE ((int)p_aout->output.output.i_rate/20) /* Size in samples */
#define FRAMES_NUM 8 #define FRAMES_NUM 8 /* Needs to be > 3 */
/* frame buffer status */ /* frame buffer status */
#define FRAME_QUEUED 0 #define FRAME_QUEUED 0
...@@ -1038,7 +1038,7 @@ static void DirectSoundThread( notification_thread_t *p_notif ) ...@@ -1038,7 +1038,7 @@ static void DirectSoundThread( notification_thread_t *p_notif )
HANDLE notification_events[FRAMES_NUM]; HANDLE notification_events[FRAMES_NUM];
HRESULT dsresult; HRESULT dsresult;
aout_instance_t *p_aout = p_notif->p_aout; aout_instance_t *p_aout = p_notif->p_aout;
int i, i_which_frame, i_last_frame, i_next_frame; int i, i_which_frame, i_last_frame;
mtime_t mtime; mtime_t mtime;
vlc_bool_t b_sleek; vlc_bool_t b_sleek;
...@@ -1083,7 +1083,7 @@ static void DirectSoundThread( notification_thread_t *p_notif ) ...@@ -1083,7 +1083,7 @@ static void DirectSoundThread( notification_thread_t *p_notif )
while( !p_notif->b_die ) while( !p_notif->b_die )
{ {
aout_buffer_t *p_buffer; aout_buffer_t *p_buffer;
long l_latency; long l_position, l_latency = 0;
/* wait for the position notification */ /* wait for the position notification */
i_which_frame = WaitForMultipleObjects( FRAMES_NUM, i_which_frame = WaitForMultipleObjects( FRAMES_NUM,
...@@ -1098,52 +1098,43 @@ static void DirectSoundThread( notification_thread_t *p_notif ) ...@@ -1098,52 +1098,43 @@ static void DirectSoundThread( notification_thread_t *p_notif )
/* We take into account the current latency */ /* We take into account the current latency */
if SUCCEEDED( IDirectSoundBuffer_GetCurrentPosition( if SUCCEEDED( IDirectSoundBuffer_GetCurrentPosition(
p_aout->output.p_sys->p_dsbuffer, p_aout->output.p_sys->p_dsbuffer,
&l_latency, NULL ) ) &l_position, NULL ) )
{ {
if( l_latency > (i_which_frame * FRAME_SIZE) /* Latency is in samples */
&& l_latency < ((i_which_frame+1) * FRAME_SIZE) ) l_position /= p_aout->output.output.i_bytes_per_frame;
{ l_latency = l_position - i_which_frame * FRAME_SIZE;
l_latency = - ( l_latency /
p_aout->output.output.i_bytes_per_frame % /* That sucks but latency can apparently be negative up to -FRAME_SIZE
FRAME_SIZE ); * ie. the notification is done in advance. */
} if( l_latency > FRAME_SIZE * (FRAMES_NUM-1) )
else l_latency -= (FRAME_SIZE * FRAMES_NUM);
{ else if( l_latency < -FRAME_SIZE )
l_latency = FRAME_SIZE - ( l_latency / l_latency += (FRAME_SIZE * FRAMES_NUM);
p_aout->output.output.i_bytes_per_frame %
FRAME_SIZE );
}
}
else
{
l_latency = 0;
} }
/* Mark last frame as empty */ /* Mark last frame as empty */
i_last_frame = (i_which_frame + FRAMES_NUM -1) % FRAMES_NUM; i_last_frame = (i_which_frame + FRAMES_NUM -1) % FRAMES_NUM;
i_next_frame = (i_which_frame + 1) % FRAMES_NUM;
p_notif->i_frame_status[i_last_frame] = FRAME_EMPTY; p_notif->i_frame_status[i_last_frame] = FRAME_EMPTY;
/* Try to fill in as many frame buffers as possible */ /* Try to fill in as many frame buffers as possible */
for( i = i_next_frame; (i % FRAMES_NUM) != i_which_frame; i++ ) for( i = i_which_frame + 1; i < i_which_frame + FRAMES_NUM; i++ )
{ {
/* Check if frame buf is already filled */ /* Check if frame buf is already filled */
if( p_notif->i_frame_status[i % FRAMES_NUM] == FRAME_QUEUED ) if( p_notif->i_frame_status[i % FRAMES_NUM] == FRAME_QUEUED )
continue; continue;
if( ((i - i_which_frame) * FRAME_SIZE - l_latency) < 0 )
{
msg_Warn( p_aout, "dectected underrun!");
}
p_buffer = aout_OutputNextBuffer( p_aout, p_buffer = aout_OutputNextBuffer( p_aout,
mtime + 1000000 / p_aout->output.output.i_rate * mtime + I64C(1000000) * ((i - i_which_frame) * FRAME_SIZE -
((i - i_next_frame + 1) * FRAME_SIZE + l_latency), b_sleek ); l_latency) / p_aout->output.output.i_rate, b_sleek );
/* If there is no audio data available and we have some buffered /* If there is no audio data available and we have some buffered
* already, then just wait for the next time */ * already, then just wait for the next time */
if( !p_buffer && (i != i_next_frame) ) if( !p_buffer && (i != i_which_frame + 1) ) break;
{
//msg_Err( p_aout, "only %i frame buffers filled!",
// i - i_next_frame );
break;
}
if( FillBuffer( p_aout, (i%FRAMES_NUM), p_buffer ) if( FillBuffer( p_aout, (i%FRAMES_NUM), p_buffer )
!= VLC_SUCCESS ) != VLC_SUCCESS )
......
...@@ -212,6 +212,15 @@ static void DestroyFilter( vlc_object_t *p_this ) ...@@ -212,6 +212,15 @@ static void DestroyFilter( vlc_object_t *p_this )
{ {
return; return;
} }
var_DelCallback( p_input->p_libvlc, "marq-x", MarqueeCallback, p_sys );
var_DelCallback( p_input->p_libvlc, "marq-y", MarqueeCallback, p_sys );
var_DelCallback( p_input->p_libvlc, "marq-marquee", MarqueeCallback, p_sys );
var_DelCallback( p_input->p_libvlc, "marq-timeout", MarqueeCallback, p_sys );
var_DelCallback( p_input->p_libvlc, "marq-position", MarqueeCallback, p_sys );
var_DelCallback( p_input->p_libvlc, "marq-color", MarqueeCallback, p_sys );
var_DelCallback( p_input->p_libvlc, "marq-opacity", MarqueeCallback, p_sys );
var_DelCallback( p_input->p_libvlc, "marq-size", MarqueeCallback, p_sys );
var_Destroy( p_input->p_libvlc , "marq-marquee" ); var_Destroy( p_input->p_libvlc , "marq-marquee" );
var_Destroy( p_input->p_libvlc , "marq-x" ); var_Destroy( p_input->p_libvlc , "marq-x" );
var_Destroy( p_input->p_libvlc , "marq-y" ); var_Destroy( p_input->p_libvlc , "marq-y" );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment