Commit a6929a54 authored by Anton Baskanov's avatar Anton Baskanov Committed by Alexandre Julliard

dmime: Factor out timeout computation.

parent a93e4cf6
...@@ -110,7 +110,44 @@ static void performance_queue_message(struct performance *This, struct message * ...@@ -110,7 +110,44 @@ static void performance_queue_message(struct performance *This, struct message *
list_add_after(&prev->entry, &message->entry); list_add_after(&prev->entry, &message->entry);
} }
static HRESULT performance_process_message(struct performance *This, DMUS_PMSG *msg, DWORD *timeout) static struct message *performance_get_message(struct performance *This, DWORD *timeout)
{
static const DWORD delivery_flags = DMUS_PMSGF_TOOL_IMMEDIATE | DMUS_PMSGF_TOOL_QUEUE | DMUS_PMSGF_TOOL_ATTIME;
IDirectMusicPerformance *performance = (IDirectMusicPerformance *)&This->IDirectMusicPerformance8_iface;
REFERENCE_TIME latency, offset = 0;
struct message *message;
struct list *ptr;
if (!(ptr = list_head(&This->messages)))
return NULL;
message = LIST_ENTRY(ptr, struct message, entry);
if (FAILED(IDirectMusicPerformance_GetLatencyTime(performance, &latency)))
return NULL;
switch (message->msg.dwFlags & delivery_flags)
{
default:
WARN("No delivery flag found for message %p\n", &message->msg);
/* fallthrough */
case DMUS_PMSGF_TOOL_IMMEDIATE:
break;
case DMUS_PMSGF_TOOL_QUEUE:
offset = This->dwBumperLength * 10000;
/* fallthrough */
case DMUS_PMSGF_TOOL_ATTIME:
if (message->msg.rtTime >= offset && message->msg.rtTime - offset >= latency)
{
*timeout = (message->msg.rtTime - offset - latency) / 10000;
return NULL;
}
break;
}
return message;
}
static HRESULT performance_process_message(struct performance *This, DMUS_PMSG *msg)
{ {
static const DWORD delivery_flags = DMUS_PMSGF_TOOL_IMMEDIATE | DMUS_PMSGF_TOOL_QUEUE | DMUS_PMSGF_TOOL_ATTIME; static const DWORD delivery_flags = DMUS_PMSGF_TOOL_IMMEDIATE | DMUS_PMSGF_TOOL_QUEUE | DMUS_PMSGF_TOOL_ATTIME;
IDirectMusicPerformance *performance = (IDirectMusicPerformance *)&This->IDirectMusicPerformance8_iface; IDirectMusicPerformance *performance = (IDirectMusicPerformance *)&This->IDirectMusicPerformance8_iface;
...@@ -137,10 +174,7 @@ static HRESULT performance_process_message(struct performance *This, DMUS_PMSG * ...@@ -137,10 +174,7 @@ static HRESULT performance_process_message(struct performance *This, DMUS_PMSG *
/* fallthrough */ /* fallthrough */
case DMUS_PMSGF_TOOL_ATTIME: case DMUS_PMSGF_TOOL_ATTIME:
if (msg->rtTime >= offset && msg->rtTime - offset >= latency) if (msg->rtTime >= offset && msg->rtTime - offset >= latency)
{
if (timeout) *timeout = (msg->rtTime - offset - latency) / 10000;
return DMUS_S_REQUEUE; return DMUS_S_REQUEUE;
}
hr = IDirectMusicTool_ProcessPMsg(tool, performance, msg); hr = IDirectMusicTool_ProcessPMsg(tool, performance, msg);
break; break;
...@@ -155,8 +189,7 @@ static HRESULT performance_process_message(struct performance *This, DMUS_PMSG * ...@@ -155,8 +189,7 @@ static HRESULT performance_process_message(struct performance *This, DMUS_PMSG *
static DWORD WINAPI message_thread_proc(void *args) static DWORD WINAPI message_thread_proc(void *args)
{ {
struct performance *This = args; struct performance *This = args;
HRESULT hr = DMUS_S_REQUEUE; HRESULT hr;
struct list *ptr;
TRACE("performance %p message thread\n", This); TRACE("performance %p message thread\n", This);
SetThreadDescription(GetCurrentThread(), L"wine_dmime_message"); SetThreadDescription(GetCurrentThread(), L"wine_dmime_message");
...@@ -166,20 +199,21 @@ static DWORD WINAPI message_thread_proc(void *args) ...@@ -166,20 +199,21 @@ static DWORD WINAPI message_thread_proc(void *args)
while (This->message_thread) while (This->message_thread)
{ {
DWORD timeout = INFINITE; DWORD timeout = INFINITE;
struct message *message;
struct list *next;
while ((ptr = list_head(&This->messages))) if (!(message = performance_get_message(This, &timeout)))
{ {
struct message *message = LIST_ENTRY(ptr, struct message, entry); SleepConditionVariableCS(&This->cond, &This->safe, timeout);
struct list *next = ptr->next; continue;
}
next = message->entry.next;
list_remove(&message->entry); list_remove(&message->entry);
list_init(&message->entry); list_init(&message->entry);
hr = performance_process_message(This, &message->msg, &timeout); hr = performance_process_message(This, &message->msg);
if (hr == DMUS_S_REQUEUE) performance_queue_message(This, message, next); if (hr == DMUS_S_REQUEUE) performance_queue_message(This, message, next);
if (hr != S_OK) break;
}
SleepConditionVariableCS(&This->cond, &This->safe, timeout);
} }
LeaveCriticalSection(&This->safe); LeaveCriticalSection(&This->safe);
...@@ -824,7 +858,7 @@ static HRESULT WINAPI performance_SendPMsg(IDirectMusicPerformance8 *iface, DMUS ...@@ -824,7 +858,7 @@ static HRESULT WINAPI performance_SendPMsg(IDirectMusicPerformance8 *iface, DMUS
if (msg->dwFlags & DMUS_PMSGF_TOOL_IMMEDIATE) if (msg->dwFlags & DMUS_PMSGF_TOOL_IMMEDIATE)
{ {
hr = performance_process_message(This, &message->msg, NULL); hr = performance_process_message(This, &message->msg);
if (hr != DMUS_S_REQUEUE) goto done; if (hr != DMUS_S_REQUEUE) goto done;
} }
......
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