Commit 18024afd authored by Jörg Höhle's avatar Jörg Höhle Committed by Alexandre Julliard

winealsa: Fix AudioCaptureClient Get/ReleaseBuffer protocol.

parent 8bf8bd97
...@@ -115,7 +115,6 @@ struct ACImpl { ...@@ -115,7 +115,6 @@ struct ACImpl {
HANDLE timer; HANDLE timer;
BYTE *local_buffer, *tmp_buffer; BYTE *local_buffer, *tmp_buffer;
int buf_state;
long getbuf_last; /* <0 when using tmp_buffer */ long getbuf_last; /* <0 when using tmp_buffer */
CRITICAL_SECTION lock; CRITICAL_SECTION lock;
...@@ -126,12 +125,6 @@ struct ACImpl { ...@@ -126,12 +125,6 @@ struct ACImpl {
struct list entry; struct list entry;
}; };
enum BufferStates {
NOT_LOCKED = 0,
LOCKED_NORMAL, /* public buffer piece is from local_buffer */
LOCKED_WRAPPED /* public buffer piece is wrapped around, in tmp_buffer */
};
typedef struct _SessionMgr { typedef struct _SessionMgr {
IAudioSessionManager2 IAudioSessionManager2_iface; IAudioSessionManager2 IAudioSessionManager2_iface;
...@@ -1757,7 +1750,7 @@ static HRESULT WINAPI AudioClient_Reset(IAudioClient *iface) ...@@ -1757,7 +1750,7 @@ static HRESULT WINAPI AudioClient_Reset(IAudioClient *iface)
return AUDCLNT_E_NOT_STOPPED; return AUDCLNT_E_NOT_STOPPED;
} }
if(This->buf_state != NOT_LOCKED || This->getbuf_last){ if(This->getbuf_last){
LeaveCriticalSection(&This->lock); LeaveCriticalSection(&This->lock);
return AUDCLNT_E_BUFFER_OPERATION_PENDING; return AUDCLNT_E_BUFFER_OPERATION_PENDING;
} }
...@@ -2127,7 +2120,6 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface, ...@@ -2127,7 +2120,6 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface,
UINT64 *qpcpos) UINT64 *qpcpos)
{ {
ACImpl *This = impl_from_IAudioCaptureClient(iface); ACImpl *This = impl_from_IAudioCaptureClient(iface);
HRESULT hr;
TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This, data, frames, flags, TRACE("(%p)->(%p, %p, %p, %p, %p)\n", This, data, frames, flags,
devpos, qpcpos); devpos, qpcpos);
...@@ -2137,18 +2129,18 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface, ...@@ -2137,18 +2129,18 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface,
EnterCriticalSection(&This->lock); EnterCriticalSection(&This->lock);
if(This->buf_state != NOT_LOCKED){ if(This->getbuf_last){
LeaveCriticalSection(&This->lock); LeaveCriticalSection(&This->lock);
return AUDCLNT_E_OUT_OF_ORDER; return AUDCLNT_E_OUT_OF_ORDER;
} }
hr = IAudioCaptureClient_GetNextPacketSize(iface, frames); /* hr = GetNextPacketSize(iface, frames); */
if(FAILED(hr)){ if(This->held_frames < This->mmdev_period_frames){
*frames = 0;
LeaveCriticalSection(&This->lock); LeaveCriticalSection(&This->lock);
return hr; return AUDCLNT_S_BUFFER_EMPTY;
} }
*frames = This->mmdev_period_frames;
*flags = 0;
if(This->lcl_offs_frames + *frames > This->bufsize_frames){ if(This->lcl_offs_frames + *frames > This->bufsize_frames){
UINT32 chunk_bytes, offs_bytes, frames_bytes; UINT32 chunk_bytes, offs_bytes, frames_bytes;
...@@ -2175,10 +2167,17 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface, ...@@ -2175,10 +2167,17 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface,
*data = This->local_buffer + *data = This->local_buffer +
This->lcl_offs_frames * This->fmt->nBlockAlign; This->lcl_offs_frames * This->fmt->nBlockAlign;
This->buf_state = LOCKED_NORMAL; This->getbuf_last = *frames;
*flags = 0;
if(devpos || qpcpos) if(devpos)
IAudioClock_GetPosition(&This->IAudioClock_iface, devpos, qpcpos); *devpos = This->written_frames;
if(qpcpos){ /* fixme: qpc of recording time */
LARGE_INTEGER stamp, freq;
QueryPerformanceCounter(&stamp);
QueryPerformanceFrequency(&freq);
*qpcpos = (stamp.QuadPart * (INT64)10000000) / freq.QuadPart;
}
LeaveCriticalSection(&This->lock); LeaveCriticalSection(&This->lock);
...@@ -2194,16 +2193,27 @@ static HRESULT WINAPI AudioCaptureClient_ReleaseBuffer( ...@@ -2194,16 +2193,27 @@ static HRESULT WINAPI AudioCaptureClient_ReleaseBuffer(
EnterCriticalSection(&This->lock); EnterCriticalSection(&This->lock);
if(This->buf_state == NOT_LOCKED){ if(!done){
This->getbuf_last = 0;
LeaveCriticalSection(&This->lock);
return S_OK;
}
if(!This->getbuf_last){
LeaveCriticalSection(&This->lock); LeaveCriticalSection(&This->lock);
return AUDCLNT_E_OUT_OF_ORDER; return AUDCLNT_E_OUT_OF_ORDER;
} }
if(This->getbuf_last != done){
LeaveCriticalSection(&This->lock);
return AUDCLNT_E_INVALID_SIZE;
}
This->written_frames += done;
This->held_frames -= done; This->held_frames -= done;
This->lcl_offs_frames += done; This->lcl_offs_frames += done;
This->lcl_offs_frames %= This->bufsize_frames; This->lcl_offs_frames %= This->bufsize_frames;
This->getbuf_last = 0;
This->buf_state = NOT_LOCKED;
LeaveCriticalSection(&This->lock); LeaveCriticalSection(&This->lock);
...@@ -2217,7 +2227,16 @@ static HRESULT WINAPI AudioCaptureClient_GetNextPacketSize( ...@@ -2217,7 +2227,16 @@ static HRESULT WINAPI AudioCaptureClient_GetNextPacketSize(
TRACE("(%p)->(%p)\n", This, frames); TRACE("(%p)->(%p)\n", This, frames);
return AudioClient_GetCurrentPadding(&This->IAudioClient_iface, frames); if(!frames)
return E_POINTER;
EnterCriticalSection(&This->lock);
*frames = This->held_frames < This->mmdev_period_frames ? 0 : This->mmdev_period_frames;
LeaveCriticalSection(&This->lock);
return S_OK;
} }
static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl = static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl =
......
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