#ifdef HAVE_UNISTD_H
# include <unistd.h> /* getpid on UNIX */
#endif
-#ifdef HAVE_PROCESS_H
-# include <process.h> /* getpid on win32 */
-#endif
#include "gst/gst-i18n-plugin.h"
#include <string.h>
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <processthreadsapi.h>
+#endif
+
#ifndef GST_DISABLE_GST_DEBUG
#define GST_CAT_DEFAULT gst_pb_utils_missing_plugins_ensure_debug_category()
}
#endif /* GST_DISABLE_GST_DEBUG */
+/* use glib's abstraction once it's landed
+ * https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2475 */
+#ifdef G_OS_WIN32
+static inline DWORD
+_gst_getpid (void)
+{
+ return GetCurrentProcessId ();
+}
+#else
+static inline pid_t
+_gst_getpid (void)
+{
+ return getpid ();
+}
+#endif
+
#define GST_DETAIL_STRING_MARKER "gstreamer"
typedef enum
if (progname) {
g_string_append_printf (str, "%s|", progname);
} else {
- g_string_append_printf (str, "pid/%lu|", (gulong) getpid ());
+ g_string_append_printf (str, "pid/%lu|", (gulong) _gst_getpid ());
}
desc = gst_missing_plugin_message_get_description (msg);
if (progname) {
g_string_append_printf (s, "%s|", progname);
} else {
- g_string_append_printf (s, "pid/%lu|", (gulong) getpid ());
+ g_string_append_printf (s, "pid/%lu|", (gulong) _gst_getpid ());
}
if (description) {
#include <stdio.h> /* fprintf */
#include <glib/gstdio.h>
#include <errno.h>
-#ifdef HAVE_UNISTD_H
-# include <unistd.h> /* getpid on UNIX */
-#endif
-#ifdef HAVE_PROCESS_H
-# include <process.h> /* getpid on win32 */
-#endif
#include <string.h> /* G_VA_COPY */
-#ifdef G_OS_WIN32
-# define WIN32_LEAN_AND_MEAN /* prevents from including too many things */
-# include <windows.h> /* GetStdHandle, windows console */
-#endif
#include "gst_private.h"
#include "gstutils.h"
#include <glib/gprintf.h>
#endif /* !GST_DISABLE_GST_DEBUG */
+#ifdef HAVE_UNISTD_H
+# include <unistd.h> /* getpid on UNIX */
+#endif
+
+#ifdef G_OS_WIN32
+# define WIN32_LEAN_AND_MEAN /* prevents from including too many things */
+# include <windows.h> /* GetStdHandle, windows console */
+# include <processthreadsapi.h> /* GetCurrentProcessId */
+/* getpid() is not allowed in case of UWP, use GetCurrentProcessId() instead
+ * which can be used on both desktop and UWP */
+#endif
+
+/* use glib's abstraction once it's landed
+ * https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2475 */
+#ifdef G_OS_WIN32
+static inline DWORD
+_gst_getpid (void)
+{
+ return GetCurrentProcessId ();
+}
+#else
+static inline pid_t
+_gst_getpid (void)
+{
+ return getpid ();
+}
+#endif
+
#ifdef HAVE_UNWIND
/* No need for remote debugging so turn on the 'local only' optimizations in
* libunwind */
gchar *name;
name = g_strdup (env);
- name = _replace_pattern_in_gst_debug_file_name (name, "%p", getpid ());
+ name = _replace_pattern_in_gst_debug_file_name (name, "%p", _gst_getpid ());
name = _replace_pattern_in_gst_debug_file_name (name, "%r", g_random_int ());
return name;
#else
#define PTR_FMT "%10p"
#endif
+#ifdef G_OS_WIN32
+#define PID_FMT "%5lu"
+#else
#define PID_FMT "%5d"
+#endif
#define CAT_FMT "%20s %s:%d:%s:%s"
#define NOCOLOR_PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
&elapsed);
ret = g_strdup_printf ("%" GST_TIME_FORMAT NOCOLOR_PRINT_FMT,
- GST_TIME_ARGS (elapsed), getpid (), g_thread_self (),
+ GST_TIME_ARGS (elapsed), _gst_getpid (), g_thread_self (),
gst_debug_level_get_name (level), gst_debug_category_get_name
(category), file, line, function, obj_str, message_str);
_gst_debug_log_preamble (message, object, &file, &message_str, &obj,
&elapsed);
- pid = getpid ();
+ pid = _gst_getpid ();
color_mode = gst_debug_get_color_mode ();
if (color_mode != GST_DEBUG_COLOR_MODE_OFF) {
#ifdef HAVE_DW
/* Due to plugins being loaded, mapping of process might have changed,
* so always scan it. */
- if (dwfl_linux_proc_report (dwfl, getpid ()) != 0)
+ if (dwfl_linux_proc_report (dwfl, _gst_getpid ()) != 0)
goto done;
#endif
gint line, GObject * object, GstDebugMessage * message, gpointer user_data)
{
GstRingBufferLogger *logger = user_data;
- gint pid;
GThread *thread;
GstClockTime elapsed;
gchar *obj = NULL;
}
elapsed = GST_CLOCK_DIFF (_priv_gst_start_time, gst_util_get_timestamp ());
- pid = getpid ();
thread = g_thread_self ();
/* no color, all platforms */
#define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
output =
g_strdup_printf ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
- pid, thread, gst_debug_level_get_name (level),
+ _gst_getpid (), thread, gst_debug_level_get_name (level),
gst_debug_category_get_name (category), file, line, function, obj,
message_str);
#undef PRINT_FMT
#define CK_DLL_EXP extern
#endif
-#if _MSC_VER
+#ifdef _MSC_VER
#include <WinSock2.h> /* struct timeval, API used in gettimeofday implementation */
#include <io.h> /* read, write */
-#include <process.h> /* getpid */
#include <BaseTsd.h> /* for ssize_t */
+#include <processthreadsapi.h> /* GetCurrentProcessId */
+/* getpid() is not allowed in case of UWP, use GetCurrentProcessId() instead
+ * which can be used on both desktop and UWP */
+#define getpid GetCurrentProcessId
typedef SSIZE_T ssize_t;
#endif /* _MSC_VER */
CK_DLL_EXP void *rpl_realloc (void *p, size_t n);
#endif /* !HAVE_REALLOC */
-#if !HAVE_GETPID && HAVE__GETPID
+#if !HAVE_GETPID && HAVE__GETPID && !defined(_MSC_VER)
#define getpid _getpid
#endif /* !HAVE_GETPID && HAVE__GETPID */