Commit d68da462 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

mmdevice: fix thread initialization and cleanup

parent dffdc4c7
...@@ -85,8 +85,8 @@ struct aout_sys_t ...@@ -85,8 +85,8 @@ struct aout_sys_t
CONDITION_VARIABLE request_wait; CONDITION_VARIABLE request_wait;
CONDITION_VARIABLE reply_wait; CONDITION_VARIABLE reply_wait;
bool active; /**< Flag to request thread to keep running */ bool killed; /**< Flag to terminate the thread */
bool running; /**< Whether the thread is still running */ bool running; /**< Whether the thread is running */
int8_t mute; /**< Requested mute state or negative value */ int8_t mute; /**< Requested mute state or negative value */
float volume; /**< Requested volume or negative value */ float volume; /**< Requested volume or negative value */
}; };
...@@ -439,7 +439,10 @@ static void MMThread(void *data) ...@@ -439,7 +439,10 @@ static void MMThread(void *data)
msg_Err(aout, "cannot get simple volume (error 0x%lx)", hr); msg_Err(aout, "cannot get simple volume (error 0x%lx)", hr);
EnterCriticalSection(&sys->lock); EnterCriticalSection(&sys->lock);
while (sys->active) sys->running = true;
WakeConditionVariable(&sys->reply_wait);
while (!sys->killed)
{ {
/* Update volume */ /* Update volume */
if (sys->volume >= 0.f) if (sys->volume >= 0.f)
...@@ -471,6 +474,7 @@ static void MMThread(void *data) ...@@ -471,6 +474,7 @@ static void MMThread(void *data)
&sys->session_events); &sys->session_events);
IAudioSessionControl_Release(control); IAudioSessionControl_Release(control);
} }
Leave();
EnterCriticalSection(&sys->lock); EnterCriticalSection(&sys->lock);
sys->running = false; sys->running = false;
...@@ -526,8 +530,8 @@ static int Open(vlc_object_t *obj) ...@@ -526,8 +530,8 @@ static int Open(vlc_object_t *obj)
InitializeCriticalSection(&sys->lock); InitializeCriticalSection(&sys->lock);
InitializeConditionVariable(&sys->request_wait); InitializeConditionVariable(&sys->request_wait);
InitializeConditionVariable(&sys->reply_wait); InitializeConditionVariable(&sys->reply_wait);
sys->active = true; sys->killed = false;
sys->running = true; sys->running = false;
sys->volume = -1.f; sys->volume = -1.f;
sys->mute = -1; sys->mute = -1;
...@@ -575,6 +579,11 @@ static int Open(vlc_object_t *obj) ...@@ -575,6 +579,11 @@ static int Open(vlc_object_t *obj)
/* Note: thread handle released by CRT, ignore it. */ /* Note: thread handle released by CRT, ignore it. */
if (_beginthread(MMThread, 0, aout) == (uintptr_t)-1) if (_beginthread(MMThread, 0, aout) == (uintptr_t)-1)
goto error; goto error;
EnterCriticalSection(&sys->lock);
while (!sys->running)
SleepConditionVariableCS(&sys->reply_wait, &sys->lock, INFINITE);
LeaveCriticalSection(&sys->lock);
Leave(); Leave();
aout->sys = sys; aout->sys = sys;
...@@ -606,7 +615,7 @@ static void Close(vlc_object_t *obj) ...@@ -606,7 +615,7 @@ static void Close(vlc_object_t *obj)
aout_sys_t *sys = aout->sys; aout_sys_t *sys = aout->sys;
EnterCriticalSection(&sys->lock); EnterCriticalSection(&sys->lock);
sys->active = false; sys->killed = true;
WakeConditionVariable(&sys->request_wait); WakeConditionVariable(&sys->request_wait);
while (sys->running) while (sys->running)
SleepConditionVariableCS(&sys->reply_wait, &sys->lock, INFINITE); SleepConditionVariableCS(&sys->reply_wait, &sys->lock, INFINITE);
......
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