static void test_uninitialized(IAudioClient *ac) { HRESULT hr; UINT32 num; REFERENCE_TIME t1; HANDLE handle = CreateEventW(NULL, FALSE, FALSE, NULL); IUnknown *unk; hr = IAudioClient_GetBufferSize(ac, &num); ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetBufferSize call returns %08x\n", hr); hr = IAudioClient_GetStreamLatency(ac, &t1); ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetStreamLatency call returns %08x\n", hr); hr = IAudioClient_GetCurrentPadding(ac, &num); ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetCurrentPadding call returns %08x\n", hr); hr = IAudioClient_Start(ac); ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Start call returns %08x\n", hr); hr = IAudioClient_Stop(ac); ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Stop call returns %08x\n", hr); hr = IAudioClient_Reset(ac); ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized Reset call returns %08x\n", hr); hr = IAudioClient_SetEventHandle(ac, handle); ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized SetEventHandle call returns %08x\n", hr); hr = IAudioClient_GetService(ac, &IID_IAudioStreamVolume, (void**)&unk); ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Uninitialized GetService call returns %08x\n", hr); CloseHandle(handle); }
static void test_audioclient(void) { IAudioClient *ac; IUnknown *unk; HRESULT hr; ULONG ref; WAVEFORMATEX *pwfx, *pwfx2; REFERENCE_TIME t1, t2; HANDLE handle; hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void**)&ac); ok(hr == S_OK, "Activation failed with %08x\n", hr); if(hr != S_OK) return; handle = CreateEventW(NULL, FALSE, FALSE, NULL); hr = IAudioClient_QueryInterface(ac, &IID_IUnknown, NULL); ok(hr == E_POINTER, "QueryInterface(NULL) returned %08x\n", hr); unk = (void*)(LONG_PTR)0x12345678; hr = IAudioClient_QueryInterface(ac, &IID_NULL, (void**)&unk); ok(hr == E_NOINTERFACE, "QueryInterface(IID_NULL) returned %08x\n", hr); ok(!unk, "QueryInterface(IID_NULL) returned non-null pointer %p\n", unk); hr = IAudioClient_QueryInterface(ac, &IID_IUnknown, (void**)&unk); ok(hr == S_OK, "QueryInterface(IID_IUnknown) returned %08x\n", hr); if (unk) { ref = IUnknown_Release(unk); ok(ref == 1, "Released count is %u\n", ref); } hr = IAudioClient_QueryInterface(ac, &IID_IAudioClient, (void**)&unk); ok(hr == S_OK, "QueryInterface(IID_IAudioClient) returned %08x\n", hr); if (unk) { ref = IUnknown_Release(unk); ok(ref == 1, "Released count is %u\n", ref); } hr = IAudioClient_GetDevicePeriod(ac, NULL, NULL); ok(hr == E_POINTER, "Invalid GetDevicePeriod call returns %08x\n", hr); hr = IAudioClient_GetDevicePeriod(ac, &t1, NULL); ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr); hr = IAudioClient_GetDevicePeriod(ac, NULL, &t2); ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr); hr = IAudioClient_GetDevicePeriod(ac, &t1, &t2); ok(hr == S_OK, "Valid GetDevicePeriod call returns %08x\n", hr); trace("Returned periods: %u.%05u ms %u.%05u ms\n", (UINT)(t1/10000), (UINT)(t1 % 10000), (UINT)(t2/10000), (UINT)(t2 % 10000)); hr = IAudioClient_GetMixFormat(ac, NULL); ok(hr == E_POINTER, "GetMixFormat returns %08x\n", hr); hr = IAudioClient_GetMixFormat(ac, &pwfx); ok(hr == S_OK, "Valid GetMixFormat returns %08x\n", hr); if (hr == S_OK) { trace("pwfx: %p\n", pwfx); trace("Tag: %04x\n", pwfx->wFormatTag); trace("bits: %u\n", pwfx->wBitsPerSample); trace("chan: %u\n", pwfx->nChannels); trace("rate: %u\n", pwfx->nSamplesPerSec); trace("align: %u\n", pwfx->nBlockAlign); trace("extra: %u\n", pwfx->cbSize); ok(pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE, "wFormatTag is %x\n", pwfx->wFormatTag); if (pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE) { WAVEFORMATEXTENSIBLE *pwfxe = (void*)pwfx; trace("Res: %u\n", pwfxe->Samples.wReserved); trace("Mask: %x\n", pwfxe->dwChannelMask); trace("Alg: %s\n", IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM)?"PCM": (IsEqualGUID(&pwfxe->SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)?"FLOAT":"Other")); } hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, &pwfx2); ok(hr == S_OK, "Valid IsFormatSupported(Shared) call returns %08x\n", hr); ok(pwfx2 == NULL, "pwfx2 is non-null\n"); CoTaskMemFree(pwfx2); hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, NULL, NULL); ok(hr == E_POINTER, "IsFormatSupported(NULL) call returns %08x\n", hr); hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_SHARED, pwfx, NULL); ok(hr == E_POINTER, "IsFormatSupported(Shared,NULL) call returns %08x\n", hr); hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, NULL); ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT, "IsFormatSupported(Exclusive) call returns %08x\n", hr); hr = IAudioClient_IsFormatSupported(ac, AUDCLNT_SHAREMODE_EXCLUSIVE, pwfx, &pwfx2); ok(hr == S_OK || hr == AUDCLNT_E_UNSUPPORTED_FORMAT, "IsFormatSupported(Exclusive) call returns %08x\n", hr); ok(pwfx2 == NULL, "pwfx2 non-null on exclusive IsFormatSupported\n"); hr = IAudioClient_IsFormatSupported(ac, 0xffffffff, pwfx, NULL); ok(hr == E_INVALIDARG || hr == AUDCLNT_E_UNSUPPORTED_FORMAT, "IsFormatSupported(0xffffffff) call returns %08x\n", hr); } test_uninitialized(ac); hr = IAudioClient_Initialize(ac, 3, 0, 5000000, 0, pwfx, NULL); ok(hr == AUDCLNT_E_NOT_INITIALIZED, "Initialize with invalid sharemode returns %08x\n", hr); hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0xffffffff, 5000000, 0, pwfx, NULL); ok(hr == E_INVALIDARG, "Initialize with invalid flags returns %08x\n", hr); /* It seems that if length > 2s or periodicity != 0 the length is ignored and call succeeds * Since we can only initialize successfully once, skip those tests. */ hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, NULL, NULL); ok(hr == E_POINTER, "Initialize with null format returns %08x\n", hr); hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, pwfx, NULL); ok(hr == S_OK, "Valid Initialize returns %08x\n", hr); if (hr != S_OK) { skip("Cannot initialize %08x, remainder of tests is useless\n", hr); CoTaskMemFree(pwfx); return; } hr = IAudioClient_GetStreamLatency(ac, NULL); ok(hr == E_POINTER, "GetStreamLatency(NULL) call returns %08x\n", hr); hr = IAudioClient_GetStreamLatency(ac, &t1); ok(hr == S_OK, "Valid GetStreamLatency call returns %08x\n", hr); trace("Returned latency: %u.%05u ms\n", (UINT)(t1/10000), (UINT)(t1 % 10000)); hr = IAudioClient_Initialize(ac, AUDCLNT_SHAREMODE_SHARED, 0, 5000000, 0, pwfx, NULL); ok(hr == AUDCLNT_E_ALREADY_INITIALIZED, "Calling Initialize twice returns %08x\n", hr); hr = IAudioClient_SetEventHandle(ac, NULL); ok(hr == E_INVALIDARG, "SetEventHandle(NULL) returns %08x\n", hr); hr = IAudioClient_SetEventHandle(ac, handle); ok(hr == AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED || broken(hr == HRESULT_FROM_WIN32(ERROR_INVALID_NAME)) || broken(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) /* Some 2k8 */ || broken(hr == HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME)) /* Some Vista */ , "SetEventHandle returns %08x\n", hr); hr = IAudioClient_Reset(ac); ok(hr == S_OK, "Reset on a resetted stream returns %08x\n", hr); hr = IAudioClient_Stop(ac); ok(hr == S_FALSE, "Stop on a stopped stream returns %08x\n", hr); hr = IAudioClient_Start(ac); ok(hr == S_OK, "Start on a stopped stream returns %08x\n", hr); IAudioClient_Release(ac); CloseHandle(handle); CoTaskMemFree(pwfx); }
static gboolean gst_wasapi_sink_prepare (GstAudioSink * asink, GstAudioRingBufferSpec * spec) { GstWasapiSink *self = GST_WASAPI_SINK (asink); gboolean res = FALSE; HRESULT hr; REFERENCE_TIME latency_rt, def_period, min_period; WAVEFORMATEXTENSIBLE format; IAudioRenderClient *render_client = NULL; hr = IAudioClient_GetDevicePeriod (self->client, &def_period, &min_period); if (hr != S_OK) { GST_ERROR_OBJECT (self, "IAudioClient::GetDevicePeriod () failed"); goto beach; } gst_wasapi_util_audio_info_to_waveformatex (&spec->info, &format); self->info = spec->info; hr = IAudioClient_Initialize (self->client, AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, spec->buffer_time / 100, 0, (WAVEFORMATEX *) & format, NULL); if (hr != S_OK) { GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL), ("IAudioClient::Initialize () failed: %s", gst_wasapi_util_hresult_to_string (hr))); goto beach; } hr = IAudioClient_GetStreamLatency (self->client, &latency_rt); if (hr != S_OK) { GST_ERROR_OBJECT (self, "IAudioClient::GetStreamLatency () failed"); goto beach; } GST_INFO_OBJECT (self, "default period: %d (%d ms), " "minimum period: %d (%d ms), " "latency: %d (%d ms)", (guint32) def_period, (guint32) def_period / 10000, (guint32) min_period, (guint32) min_period / 10000, (guint32) latency_rt, (guint32) latency_rt / 10000); /* FIXME: What to do with the latency? */ hr = IAudioClient_SetEventHandle (self->client, self->event_handle); if (hr != S_OK) { GST_ERROR_OBJECT (self, "IAudioClient::SetEventHandle () failed"); goto beach; } if (!gst_wasapi_util_get_render_client (GST_ELEMENT (self), self->client, &render_client)) { goto beach; } hr = IAudioClient_Start (self->client); if (hr != S_OK) { GST_ERROR_OBJECT (self, "IAudioClient::Start failed"); goto beach; } self->render_client = render_client; render_client = NULL; res = TRUE; beach: if (render_client != NULL) IUnknown_Release (render_client); return res; }
HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) { HRESULT hres; REFERENCE_TIME period; UINT32 frames; DWORD period_ms; IAudioClient *client = NULL; IAudioRenderClient *render = NULL; IAudioStreamVolume *volume = NULL; DWORD fraglen; WAVEFORMATEX *wfx = NULL; DWORD oldspeakerconfig = device->speaker_config; TRACE("(%p, %d)\n", device, forcewave); hres = IMMDevice_Activate(device->mmdevice, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void **)&client); if(FAILED(hres)){ WARN("Activate failed: %08x\n", hres); return hres; } hres = DSOUND_WaveFormat(device, client, forcewave, &wfx); if (FAILED(hres)) { IAudioClient_Release(client); return hres; } hres = IAudioClient_Initialize(client, AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST | AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 800000, 0, wfx, NULL); if(FAILED(hres)){ IAudioClient_Release(client); ERR("Initialize failed: %08x\n", hres); return hres; } IAudioClient_SetEventHandle(client, device->sleepev); hres = IAudioClient_GetService(client, &IID_IAudioRenderClient, (void**)&render); if(FAILED(hres)) goto err_service; hres = IAudioClient_GetService(client, &IID_IAudioStreamVolume, (void**)&volume); if(FAILED(hres)) goto err_service; /* Now kick off the timer so the event fires periodically */ hres = IAudioClient_Start(client); if (FAILED(hres)) { WARN("Start failed with %08x\n", hres); goto err; } hres = IAudioClient_GetStreamLatency(client, &period); if (FAILED(hres)) { WARN("GetStreamLatency failed with %08x\n", hres); goto err; } hres = IAudioClient_GetBufferSize(client, &frames); if (FAILED(hres)) { WARN("GetBufferSize failed with %08x\n", hres); goto err; } period_ms = (period + 9999) / 10000; fraglen = MulDiv(wfx->nSamplesPerSec, period, 10000000) * wfx->nBlockAlign; TRACE("period %u ms fraglen %u buflen %u\n", period_ms, fraglen, frames * wfx->nBlockAlign); hres = DSOUND_PrimaryOpen(device, wfx, frames, forcewave); if(FAILED(hres)) goto err; DSOUND_ReleaseDevice(device); device->client = client; device->render = render; device->volume = volume; device->fraglen = fraglen; device->aclen = frames * wfx->nBlockAlign; if (period_ms < 3) device->sleeptime = 5; else device->sleeptime = period_ms * 5 / 2; return S_OK; err_service: WARN("GetService failed: %08x\n", hres); err: device->speaker_config = oldspeakerconfig; DSOUND_ParseSpeakerConfig(device); if (volume) IAudioStreamVolume_Release(volume); if (render) IAudioRenderClient_Release(render); IAudioClient_Release(client); HeapFree(GetProcessHeap(), 0, wfx); return hres; }
HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) { UINT prebuf_frames; REFERENCE_TIME prebuf_rt; WAVEFORMATEX *wfx = NULL; HRESULT hres; REFERENCE_TIME period; DWORD period_ms; TRACE("(%p, %d)\n", device, forcewave); if(device->client){ IAudioClient_Release(device->client); device->client = NULL; } if(device->render){ IAudioRenderClient_Release(device->render); device->render = NULL; } if(device->clock){ IAudioClock_Release(device->clock); device->clock = NULL; } if(device->volume){ IAudioStreamVolume_Release(device->volume); device->volume = NULL; } hres = IMMDevice_Activate(device->mmdevice, &IID_IAudioClient, CLSCTX_INPROC_SERVER, NULL, (void **)&device->client); if(FAILED(hres)) { WARN("Activate failed: %08x\n", hres); return hres; } hres = DSOUND_WaveFormat(device, device->client, forcewave, &wfx); if (FAILED(hres)) { IAudioClient_Release(device->client); device->client = NULL; return hres; } HeapFree(GetProcessHeap(), 0, device->pwfx); device->pwfx = wfx; prebuf_frames = device->prebuf * DSOUND_fraglen(device) / device->pwfx->nBlockAlign; prebuf_rt = (10000000 * (UINT64)prebuf_frames) / device->pwfx->nSamplesPerSec; hres = IAudioClient_Initialize(device->client, AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST | AUDCLNT_STREAMFLAGS_EVENTCALLBACK, prebuf_rt, 0, device->pwfx, NULL); if(FAILED(hres)){ IAudioClient_Release(device->client); device->client = NULL; WARN("Initialize failed: %08x\n", hres); return hres; } IAudioClient_SetEventHandle(device->client, device->sleepev); hres = IAudioClient_GetService(device->client, &IID_IAudioRenderClient, (void**)&device->render); if(FAILED(hres)){ IAudioClient_Release(device->client); device->client = NULL; WARN("GetService failed: %08x\n", hres); return hres; } hres = IAudioClient_GetService(device->client, &IID_IAudioClock, (void**)&device->clock); if(FAILED(hres)){ IAudioClient_Release(device->client); IAudioRenderClient_Release(device->render); device->client = NULL; device->render = NULL; WARN("GetService failed: %08x\n", hres); return hres; } hres = IAudioClient_GetService(device->client, &IID_IAudioStreamVolume, (void**)&device->volume); if(FAILED(hres)){ IAudioClient_Release(device->client); IAudioRenderClient_Release(device->render); IAudioClock_Release(device->clock); device->client = NULL; device->render = NULL; device->clock = NULL; WARN("GetService failed: %08x\n", hres); return hres; } /* Now kick off the timer so the event fires periodically */ hres = IAudioClient_Start(device->client); if (FAILED(hres)) WARN("starting failed with %08x\n", hres); hres = IAudioClient_GetStreamLatency(device->client, &period); if (FAILED(hres)) { WARN("GetStreamLatency failed with %08x\n", hres); period_ms = 10; } else period_ms = (period + 9999) / 10000; TRACE("period %u ms fraglen %u prebuf %u\n", period_ms, device->fraglen, device->prebuf); if (period_ms < 3) device->sleeptime = 5; else device->sleeptime = period_ms * 5 / 2; return S_OK; }