static HRESULT WINAPI IDsDriverBufferImpl_GetPosition(PIDSDRIVERBUFFER iface, LPDWORD lpdwPlay, LPDWORD lpdwWrite) { IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; snd_pcm_uframes_t hw_pptr, hw_wptr; snd_pcm_state_t state; /* **** */ EnterCriticalSection(&This->pcm_crst); if (!This->pcm) { FIXME("Bad pointer for pcm: %p\n", This->pcm); LeaveCriticalSection(&This->pcm_crst); return DSERR_GENERIC; } if (!lpdwPlay && !lpdwWrite) CommitAll(This); state = snd_pcm_state(This->pcm); if (state != SND_PCM_STATE_PREPARED && state != SND_PCM_STATE_RUNNING) { CheckXRUN(This); state = snd_pcm_state(This->pcm); } if (state == SND_PCM_STATE_RUNNING) { snd_pcm_uframes_t used = This->mmap_buflen_frames - snd_pcm_avail_update(This->pcm); if (This->mmap_pos > used) hw_pptr = This->mmap_pos - used; else hw_pptr = This->mmap_buflen_frames + This->mmap_pos - used; hw_pptr %= This->mmap_buflen_frames; TRACE("At position: %ld (%ld) - Used %ld\n", hw_pptr, This->mmap_pos, used); } else hw_pptr = This->mmap_pos; hw_wptr = This->mmap_pos; LeaveCriticalSection(&This->pcm_crst); /* **** */ if (lpdwPlay) *lpdwPlay = snd_pcm_frames_to_bytes(This->pcm, hw_pptr); if (lpdwWrite) *lpdwWrite = snd_pcm_frames_to_bytes(This->pcm, hw_wptr); TRACE("hw_pptr=0x%08x, hw_wptr=0x%08x playpos=%d, writepos=%d\n", (unsigned int)hw_pptr, (unsigned int)hw_wptr, lpdwPlay?*lpdwPlay:-1, lpdwWrite?*lpdwWrite:-1); return DS_OK; }
static HRESULT WINAPI IDsCaptureDriverBufferImpl_GetPosition(PIDSCDRIVERBUFFER iface, LPDWORD lpdwCappos, LPDWORD lpdwReadpos) { IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface; snd_pcm_uframes_t hw_pptr, hw_wptr; EnterCriticalSection(&This->pcm_crst); if (!This->pcm) { FIXME("Bad pointer for pcm: %p\n", This->pcm); LeaveCriticalSection(&This->pcm_crst); return DSERR_GENERIC; } if (snd_pcm_state(This->pcm) != SND_PCM_STATE_RUNNING) { CheckXRUN(This); hw_pptr = This->mmap_pos; } else { /* FIXME: Unused at the moment */ snd_pcm_uframes_t used = CommitAll(This, FALSE); if (This->mmap_pos > used) hw_pptr = This->mmap_pos - used; else hw_pptr = This->mmap_buflen_frames - used + This->mmap_pos; } hw_wptr = This->mmap_pos; if (lpdwCappos) *lpdwCappos = realpos_to_fakepos(This, hw_pptr); if (lpdwReadpos) *lpdwReadpos = realpos_to_fakepos(This, hw_wptr); LeaveCriticalSection(&This->pcm_crst); TRACE("hw_pptr=%u, hw_wptr=%u playpos=%u(%p), writepos=%u(%p)\n", (unsigned int)hw_pptr, (unsigned int)hw_wptr, realpos_to_fakepos(This, hw_pptr), lpdwCappos, realpos_to_fakepos(This, hw_wptr), lpdwReadpos); return DS_OK; }