self->mix_format, NULL);
}
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL),
- ("IAudioClient::Initialize () failed: %s",
- gst_wasapi_util_hresult_to_string (hr)));
+ ("IAudioClient::Initialize () failed: %s", msg));
+ g_free (msg);
goto beach;
}
/* Frames the card hasn't rendered yet */
hr = IAudioClient_GetCurrentPadding (self->client, &n_frames_padding);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (self, "IAudioClient::GetCurrentPadding failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ msg);
+ g_free (msg);
length = 0;
goto beach;
}
hr = IAudioRenderClient_GetBuffer (self->render_client, n_frames,
(BYTE **) & dst);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ELEMENT_ERROR (self, RESOURCE, WRITE, (NULL),
- ("IAudioRenderClient::GetBuffer failed: %s",
- gst_wasapi_util_hresult_to_string (hr)));
+ ("IAudioRenderClient::GetBuffer failed: %s", msg));
+ g_free (msg);
length = 0;
goto beach;
}
hr = IAudioRenderClient_ReleaseBuffer (self->render_client, n_frames,
self->mute ? AUDCLNT_BUFFERFLAGS_SILENT : 0);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (self, "IAudioRenderClient::ReleaseBuffer failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ msg);
+ g_free (msg);
length = 0;
goto beach;
}
hr = IAudioClient_GetCurrentPadding (self->client, &delay);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ELEMENT_ERROR (self, RESOURCE, READ, (NULL),
- ("IAudioClient::GetCurrentPadding failed %s",
- gst_wasapi_util_hresult_to_string (hr)));
+ ("IAudioClient::GetCurrentPadding failed %s", msg));
+ g_free (msg);
}
return delay;
if (self->client) {
hr = IAudioClient_Stop (self->client);
if (hr != S_OK) {
- GST_ERROR_OBJECT (self, "IAudioClient::Stop () failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
+ GST_ERROR_OBJECT (self, "IAudioClient::Stop () failed: %s", msg);
+ g_free (msg);
return;
}
hr = IAudioClient_Reset (self->client);
if (hr != S_OK) {
- GST_ERROR_OBJECT (self, "IAudioClient::Reset () failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
+ GST_ERROR_OBJECT (self, "IAudioClient::Reset () failed: %s", msg);
+ g_free (msg);
return;
}
}
self->mix_format, NULL);
}
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ, (NULL),
- ("IAudioClient::Initialize () failed: %s",
- gst_wasapi_util_hresult_to_string (hr)));
+ ("IAudioClient::Initialize () failed: %s", msg));
+ g_free (msg);
goto beach;
}
hr = IAudioCaptureClient_GetBuffer (self->capture_client,
(BYTE **) & from, &have_frames, &flags, NULL, NULL);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
if (hr == AUDCLNT_S_BUFFER_EMPTY)
GST_WARNING_OBJECT (self, "IAudioCaptureClient::GetBuffer failed: %s"
- ", retrying", gst_wasapi_util_hresult_to_string (hr));
+ ", retrying", msg);
else
GST_ERROR_OBJECT (self, "IAudioCaptureClient::GetBuffer failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ msg);
+ g_free (msg);
length = 0;
goto beach;
}
/* Always release all captured buffers if we've captured any at all */
hr = IAudioCaptureClient_ReleaseBuffer (self->capture_client, have_frames);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (self,
- "IAudioCaptureClient::ReleaseBuffer () failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ "IAudioCaptureClient::ReleaseBuffer () failed: %s", msg);
+ g_free (msg);
goto beach;
}
}
hr = IAudioClient_GetCurrentPadding (self->client, &delay);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ELEMENT_ERROR (self, RESOURCE, READ, (NULL),
- ("IAudioClient::GetCurrentPadding failed %s",
- gst_wasapi_util_hresult_to_string (hr)));
+ ("IAudioClient::GetCurrentPadding failed %s", msg));
+ g_free (msg);
}
return delay;
if (self->client) {
hr = IAudioClient_Stop (self->client);
if (hr != S_OK) {
- GST_ERROR_OBJECT (self, "IAudioClient::Stop () failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
+ GST_ERROR_OBJECT (self, "IAudioClient::Stop () failed: %s", msg);
+ g_free (msg);
return;
}
hr = IAudioClient_Reset (self->client);
if (hr != S_OK) {
- GST_ERROR_OBJECT (self, "IAudioClient::Reset () failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
+ GST_ERROR_OBJECT (self, "IAudioClient::Reset () failed: %s", msg);
+ g_free (msg);
return;
}
}
}
}
-const gchar *
-gst_wasapi_util_hresult_to_string (HRESULT hr)
+static const gchar *
+hresult_to_string_fallback (HRESULT hr)
{
const gchar *s = "unknown error";
case AUDCLNT_S_POSITION_STALLED:
s = "AUDCLNT_S_POSITION_STALLED";
break;
+ case E_POINTER:
+ s = "E_POINTER";
+ break;
case E_INVALIDARG:
s = "E_INVALIDARG";
break;
return s;
}
+gchar *
+gst_wasapi_util_hresult_to_string (HRESULT hr)
+{
+ DWORD flags;
+ gchar *ret_text;
+ LPTSTR error_text = NULL;
+
+ flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER
+ | FORMAT_MESSAGE_IGNORE_INSERTS;
+ FormatMessage (flags, NULL, hr, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) & error_text, 0, NULL);
+
+ /* If we couldn't get the error msg, try the fallback switch statement */
+ if (error_text == NULL)
+ return g_strdup (hresult_to_string_fallback (hr));
+
+#ifdef UNICODE
+ /* If UNICODE is defined, LPTSTR is LPWSTR which is UTF-16 */
+ ret_text = g_utf16_to_utf8 (error_text, 0, NULL, NULL, NULL);
+#else
+ ret_text = g_strdup (error_text);
+#endif
+
+ LocalFree (error_text);
+ return ret_text;
+}
+
static IMMDeviceEnumerator *
gst_wasapi_util_get_device_enumerator (GstElement * element)
{
hr = CoCreateInstance (&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
&IID_IMMDeviceEnumerator, (void **) &enumerator);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (element, "CoCreateInstance (MMDeviceEnumerator) failed"
- ": %s", gst_wasapi_util_hresult_to_string (hr));
+ ": %s", msg);
+ g_free (msg);
return NULL;
}
hr = IMMDeviceEnumerator_EnumAudioEndpoints (enumerator, eAll, dwStateMask,
&device_collection);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (element, "IMMDeviceEnumerator::EnumAudioEndpoints "
- "failed: %s", gst_wasapi_util_hresult_to_string (hr));
+ "failed: %s", msg);
+ g_free (msg);
goto err;
}
hr = IMMDeviceCollection_GetCount (device_collection, &count);
if (hr != S_OK) {
- GST_ERROR_OBJECT (element, "Failed to count devices: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
+ GST_ERROR_OBJECT (element, "Failed to count devices: %s", msg);
+ g_free (msg);
goto err;
}
hr = IMMDevice_Activate (item, &IID_IAudioClient, CLSCTX_ALL, NULL,
(void **) &client);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (element, "IMMDevice::Activate (IID_IAudioClient) failed"
- "on %s: %s", strid, gst_wasapi_util_hresult_to_string (hr));
+ "on %s: %s", strid, msg);
+ g_free (msg);
goto next;
}
hr = IAudioClient_GetMixFormat (client, &format);
if (hr != S_OK || format == NULL) {
- GST_ERROR_OBJECT ("GetMixFormat failed on %s: %s", strid,
- gst_wasapi_util_hresult_to_string (hr));
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
+ GST_ERROR_OBJECT ("GetMixFormat failed on %s: %s", strid, msg);
+ g_free (msg);
goto next;
}
hr = IAudioClient_GetMixFormat (client, &format);
if (hr != S_OK || format == NULL) {
- GST_ERROR_OBJECT (element, "GetMixFormat failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
+ GST_ERROR_OBJECT (element, "GetMixFormat failed: %s", msg);
+ g_free (msg);
return FALSE;
}
hr = IMMDevice_OpenPropertyStore (device, STGM_READ, &prop_store);
if (hr != S_OK) {
- GST_ERROR_OBJECT (element, "OpenPropertyStore failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
+ GST_ERROR_OBJECT (element, "OpenPropertyStore failed: %s", msg);
+ g_free (msg);
return FALSE;
}
hr = IPropertyStore_GetValue (prop_store, &PKEY_AudioEngine_DeviceFormat,
&var);
if (hr != S_OK) {
- GST_ERROR_OBJECT (element, "GetValue failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
+ GST_ERROR_OBJECT (element, "GetValue failed: %s", msg);
+ g_free (msg);
IUnknown_Release (prop_store);
return FALSE;
}
hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint (enumerator,
capture ? eCapture : eRender, role, &device);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (element,
- "IMMDeviceEnumerator::GetDefaultAudioEndpoint failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ "IMMDeviceEnumerator::GetDefaultAudioEndpoint failed: %s", msg);
+ g_free (msg);
goto beach;
}
} else {
hr = IMMDeviceEnumerator_GetDevice (enumerator, device_strid, &device);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (element, "IMMDeviceEnumerator::GetDevice (%S) failed"
- ": %s", device_strid, gst_wasapi_util_hresult_to_string (hr));
+ ": %s", device_strid, msg);
+ g_free (msg);
goto beach;
}
}
hr = IMMDevice_Activate (device, &IID_IAudioClient, CLSCTX_ALL, NULL,
(void **) &client);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (element, "IMMDevice::Activate (IID_IAudioClient) failed"
- ": %s", gst_wasapi_util_hresult_to_string (hr));
+ ": %s", msg);
+ g_free (msg);
goto beach;
}
hr = IAudioClient_GetService (client, &IID_IAudioRenderClient,
(void **) &render_client);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (element,
- "IAudioClient::GetService (IID_IAudioRenderClient) failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ "IAudioClient::GetService (IID_IAudioRenderClient) failed: %s", msg);
+ g_free (msg);
goto beach;
}
hr = IAudioClient_GetService (client, &IID_IAudioCaptureClient,
(void **) &capture_client);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (element,
- "IAudioClient::GetService (IID_IAudioCaptureClient) failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ "IAudioClient::GetService (IID_IAudioCaptureClient) failed: %s", msg);
+ g_free (msg);
goto beach;
}
hr = IAudioClient_GetService (client, &IID_IAudioClock, (void **) &clock);
if (hr != S_OK) {
+ gchar *msg = gst_wasapi_util_hresult_to_string (hr);
GST_ERROR_OBJECT (element,
- "IAudioClient::GetService (IID_IAudioClock) failed: %s",
- gst_wasapi_util_hresult_to_string (hr));
+ "IAudioClient::GetService (IID_IAudioClock) failed: %s", msg);
+ g_free (msg);
goto beach;
}