mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-03 04:52:28 +00:00
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:
parent
7a7cdc0797
commit
a81398b70f
2 changed files with 31 additions and 3 deletions
|
@ -28,8 +28,9 @@
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
/* ssize_t is not available, so match return value of read()/write() on MSVC */
|
/* ssize_t is not available, so match return value of recv()/send() on MSVC */
|
||||||
# define ssize_t int
|
# define ssize_t int
|
||||||
|
# include <winsock2.h>
|
||||||
#endif
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.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",
|
GST_TRACE_OBJECT (comm->element, "Writing %u bytes to fdout",
|
||||||
(unsigned) size);
|
(unsigned) size);
|
||||||
while (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 =
|
ssize_t written =
|
||||||
write (comm->fdout, (const unsigned char *) data + offset, size);
|
write (comm->fdout, (const unsigned char *) data + offset, size);
|
||||||
if (written < 0) {
|
if (written < 0) {
|
||||||
|
@ -238,6 +253,7 @@ write_to_fd_raw (GstIpcPipelineComm * comm, const void *data, size_t size)
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
size -= written;
|
size -= written;
|
||||||
offset += written;
|
offset += written;
|
||||||
}
|
}
|
||||||
|
@ -1752,7 +1768,19 @@ again:
|
||||||
mem = gst_allocator_alloc (NULL, comm->read_chunk_size, NULL);
|
mem = gst_allocator_alloc (NULL, comm->read_chunk_size, NULL);
|
||||||
|
|
||||||
gst_memory_map (mem, &map, GST_MAP_WRITE);
|
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);
|
sz = read (comm->pollFDin.fd, map.data, map.size);
|
||||||
|
#endif
|
||||||
gst_memory_unmap (mem, &map);
|
gst_memory_unmap (mem, &map);
|
||||||
|
|
||||||
if (sz <= 0) {
|
if (sz <= 0) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ gstipcpipeline = library('gstipcpipeline',
|
||||||
ipcpipeline_sources,
|
ipcpipeline_sources,
|
||||||
c_args : gst_plugins_bad_args,
|
c_args : gst_plugins_bad_args,
|
||||||
include_directories : [configinc],
|
include_directories : [configinc],
|
||||||
dependencies : [gstbase_dep],
|
dependencies : [gstbase_dep] + winsock2,
|
||||||
install : true,
|
install : true,
|
||||||
install_dir : plugins_install_dir,
|
install_dir : plugins_install_dir,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue