ipcpipeline: fix crash and error on windows with SOCKET or _pipe()

The fd was in different meanings on windows:
POSIX read and write use the fd as a file descriptor.
The gst_poll use the fd as a WSASocket.

This patch use WSASocket as default on windows. This is a temporary measure, because IPC has many different implement. There may be a better way in the future.

See #1044

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1822>
This commit is contained in:
jinsl00000 2022-02-25 15:00:05 +08:00 committed by GStreamer Marge Bot
parent 7a7cdc0797
commit a81398b70f
2 changed files with 31 additions and 3 deletions

View file

@ -28,8 +28,9 @@
# include <unistd.h>
#endif
#ifdef _MSC_VER
/* ssize_t is not available, so match return value of read()/write() on MSVC */
#define ssize_t int
/* ssize_t is not available, so match return value of recv()/send() on MSVC */
# define ssize_t int
# include <winsock2.h>
#endif
#include <errno.h>
#include <string.h>
@ -228,6 +229,20 @@ write_to_fd_raw (GstIpcPipelineComm * comm, const void *data, size_t size)
GST_TRACE_OBJECT (comm->element, "Writing %u bytes to fdout",
(unsigned) size);
while (size) {
#ifdef _MSC_VER
ssize_t written =
send (comm->fdout, (const unsigned char *) data + offset, size, 0);
if (written < 0) {
int last_error = WSAGetLastError ();
if (last_error == WSAEWOULDBLOCK)
continue;
gchar *error_text = g_win32_error_message (last_error);
GST_ERROR_OBJECT (comm->element, "Failed to write to fd: %s", error_text);
g_free (error_text);
ret = FALSE;
goto done;
}
#else
ssize_t written =
write (comm->fdout, (const unsigned char *) data + offset, size);
if (written < 0) {
@ -238,6 +253,7 @@ write_to_fd_raw (GstIpcPipelineComm * comm, const void *data, size_t size)
ret = FALSE;
goto done;
}
#endif
size -= written;
offset += written;
}
@ -1752,7 +1768,19 @@ again:
mem = gst_allocator_alloc (NULL, comm->read_chunk_size, NULL);
gst_memory_map (mem, &map, GST_MAP_WRITE);
#ifdef _MSC_VER
sz = recv (comm->pollFDin.fd, map.data, map.size, 0);
if (sz < 0) {
int last_error = WSAGetLastError ();
if (last_error == WSAEWOULDBLOCK) {
errno = EAGAIN;
} else {
errno = last_error;
}
}
#else
sz = read (comm->pollFDin.fd, map.data, map.size);
#endif
gst_memory_unmap (mem, &map);
if (sz <= 0) {

View file

@ -15,7 +15,7 @@ gstipcpipeline = library('gstipcpipeline',
ipcpipeline_sources,
c_args : gst_plugins_bad_args,
include_directories : [configinc],
dependencies : [gstbase_dep],
dependencies : [gstbase_dep] + winsock2,
install : true,
install_dir : plugins_install_dir,
)