return vendor;
}
-static gchar *
-gst_d3d11_hres_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);
-
-#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;
-}
-
gboolean
_gst_d3d11_result (HRESULT hr, GstD3D11Device * device, GstDebugCategory * cat,
const gchar * file, const gchar * function, gint line)
if (FAILED (hr)) {
gchar *error_text = NULL;
- error_text = gst_d3d11_hres_to_string (hr);
+ error_text = g_win32_error_message ((guint) hr);
+ /* g_win32_error_message() doesn't cover all HERESULT return code,
+ * so it could be empty string, or null if there was an error
+ * in g_utf16_to_utf8() */
gst_debug_log (cat, GST_LEVEL_WARNING, file, function, line,
- NULL, "D3D11 call failed: 0x%x, %s", (guint) hr, error_text);
+ NULL, "D3D11 call failed: 0x%x, %s", (guint) hr,
+ GST_STR_NULL (error_text));
g_free (error_text);
ret = FALSE;
media_type->Release ();
}
-static gchar *
-gst_mf_hr_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);
-
-#ifdef UNICODE
- ret_text = g_utf16_to_utf8 ((const gunichar2 *) error_text,
- -1, NULL, NULL, NULL);
-#else
- ret_text = g_strdup (error_text);
-#endif
-
- LocalFree (error_text);
- return ret_text;
-}
-
gboolean
_gst_mf_result (HRESULT hr, GstDebugCategory * cat, const gchar * file,
const gchar * function, gint line)
if (FAILED (hr)) {
gchar *error_text = NULL;
- error_text = gst_mf_hr_to_string (hr);
+ error_text = g_win32_error_message ((gint) hr);
+ /* g_win32_error_message() doesn't cover all HERESULT return code,
+ * so it could be empty string, or null if there was an error
+ * in g_utf16_to_utf8() */
gst_debug_log (cat, GST_LEVEL_WARNING, file, function, line,
- NULL, "MediaFoundation call failed: 0x%x, %s", (guint) hr, error_text);
+ NULL, "MediaFoundation call failed: 0x%x, %s", (guint) hr,
+ GST_STR_NULL (error_text));
g_free (error_text);
ret = FALSE;
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
+ gchar *error_text = NULL;
+
+ error_text = g_win32_error_message ((gint) hr);
+ /* g_win32_error_message() seems to be returning empty string for
+ * AUDCLNT_* cases */
+ if (!error_text || strlen (error_text) == 0) {
+ g_free (error_text);
+ error_text = g_strdup (hresult_to_string_fallback (hr));
+ }
- LocalFree (error_text);
- return ret_text;
+ return error_text;
}
static IMMDeviceEnumerator *
return s;
}
-static gchar *
-gst_wasapi2_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;
-}
-
gboolean
_gst_wasapi2_result (HRESULT hr, GstDebugCategory * cat, const gchar * file,
const gchar * function, gint line)
if (FAILED (hr)) {
gchar *error_text = NULL;
+ gboolean free_string = TRUE;
+
+ error_text = g_win32_error_message ((gint) hr);
+ /* g_win32_error_message() seems to be returning empty string for
+ * AUDCLNT_* cases */
+ if (!error_text || strlen (error_text) == 0) {
+ g_free (error_text);
+ error_text = (gchar *) hresult_to_string_fallback (hr);
+
+ free_string = FALSE;
+ }
- error_text = gst_wasapi2_util_hresult_to_string (hr);
gst_debug_log (cat, GST_LEVEL_WARNING, file, function, line,
NULL, "WASAPI call failed: 0x%x, %s", (guint) hr, error_text);
- g_free (error_text);
+
+ if (free_string)
+ g_free (error_text);
ret = FALSE;
}
gchar *
get_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
+ gchar *error_text = NULL;
+
+ error_text = g_win32_error_message ((gint) hr);
+ /* g_win32_error_message() doesn't cover all HERESULT return code,
+ * so it could be empty string, or null if there was an error
+ * in g_utf16_to_utf8() */
+ if (!error_text || strlen (error_text) == 0) {
+ g_free (error_text);
+ error_text = g_strdup (_hresult_to_string_fallback (hr));
+ }
- LocalFree (error_text);
- return ret_text;
+ return error_text;
}