GNOME Bugzilla – Bug 515312
[RFC] Make networking elements work on windows
Last modified: 2008-06-13 14:10:29 UTC
This patch tries to make networking elements actually work on Windows. It's only a RFC quality patch, but it makes udpsrc/udpsink/rtspsrc work and thus, streaming pipelines built upon them are working like a charm. In fact, it's a kind of "compatibility layer" to make BSD-socket code work on windows. This layer is in the gstreamer/gst/windows directory. It is just a thin wrapper around winsocks calls and a bunch of defines to do the trick. For instance, ioctl (udpsrc->sock, FIONREAD, &readsize) will be turned into an gst_win_fd_ioctl () call on windows, a thin wrapper around ioctlsocket. You write Unix code, it works for free on windows ! (well that's the final goal) $ diffstat gstreamer-winsocks-v0.patch configure.ac | 14 gst/Makefile.am | 13 gst/gst_private.h | 4 gst/gstinfo.c | 8 gst/windows/Makefile.am | 22 + gst/windows/gstwin-common.h | 112 +++++++ gst/windows/gstwin-fd.c | 166 +++++++++++ gst/windows/gstwin-fd.h | 48 +++ gst/windows/gstwin-libcmisc.c | 55 +++ gst/windows/gstwin-libcmisc.h | 33 ++ gst/windows/gstwin-networking.c | 594 ++++++++++++++++++++++++++++++++++++++++ gst/windows/gstwin-networking.h | 118 +++++++ gst/windows/gstwindows.h | 31 ++ 13 files changed, 1215 insertions(+), 3 deletions(-) Using this base, I've cleaned-up a few elements $ diffstat gst-base-winsocks-v0.patch rtsp/gstrtspconnection.c | 127 +++++------------------------------------------ sdp/gstsdpmessage.c | 2 2 files changed, 17 insertions(+), 112 deletions(-) $ diffstat gst-good-winsocks-v0.patch Makefile.am | 4 +- gstdynudpsink.c | 10 +++---- gstdynudpsink.h | 17 ++++++++++- gstmultiudpsink.c | 17 +++++++---- gstmultiudpsink.h | 16 ++++++++++- gstudp.c | 5 --- gstudpnetutils.c | 62 ------------------------------------------- gstudpnetutils.h | 77 ------------------------------------------------------ gstudpsink.h | 1 gstudpsrc.c | 46 ++++---------------------------- gstudpsrc.h | 14 ++++++++- 11 files changed, 67 insertions(+), 202 deletions(-) Any comments ? Are GStreamer developers interested in such a piece of code ? If so, what can be done to make the patch become a good candidate for inclusion ?
Created attachment 104752 [details] [review] Patch against gstreamer HEAD
Created attachment 104753 [details] [review] Patch against gst-plugins-base HEAD
Created attachment 104754 [details] [review] Patch against gst-plugins-good HEAD
The ultimate idea is to implement windows support in the code provided by Bug #505417. Maybe it needs some more things to make it work?
Unfortunately, this code (bug #505417) won't work as is on Windows : - select() only works on socket descriptors, so if you give, say, a pipe descriptor to select(), it will exit with SOCKET_ERROR as return value and WSAGetLastError() will give WSAENOTSOCK. - What can be done without too much work: emulate socketpair() on windows by creating 2 sockets on the loopback device, but still, gst_poll_add_fd() will only work with sockets (as long as select will remain the heart of gst_poll on windows). - Option #2: try to get WaitForMultipleObjects() to work, but I never saw any serious piece of code using it without resorting to launching a bunch of threads waiting for a class of descriptors and I'm probably the wrong guy to try this as my windows programming skills are not that high. - Still, some of the above patch is needed: * define socklen_t for windows * inet_aton(), socketpair() replacement * handle WSAStartup()/WSACleanup() * #define WINVER 0x0501 to use getaddrinfo() and freeaddrinfo() * wrappers around functions are still needed to provided BSD-like behaviour to networking code (eg. open() returns INVALID_SOCKET on error), setting errno as needed. So what do you think ? should I try to get bug #505417 code to work on windows while providing a thin layer to make the remaining networking code work too ? Is it ok if the first GstPoll code on windows only works on sockets ?
It might be sufficient for now to make GstPoll work on Windows with files OR sockets, but not both at the same time. At least it's a starting point for something more complicated.
Well, I managed to get the time to merge the patch above with GstPoll. The result looks promising, I got udpsrc working like a charm. So : C:\test-gstpoll\bin>gst-launch-0.10.exe -v --gst-plugin-path=c:\test-gstpoll\lib\gstreamer-0.10 --gst-debug-no-color udpsrc uri="udp://239.1.2.3:1234" ! flutsdemux ! ffdec_mpeg2video ! queue ! ffmpegcolorspace ! directdrawsink sync=0 works as intended. Changes : gstreamer * merged bug #505417 and bug #515312. in short #515312 defines a layer to be make various Unix and POSIX calls have the expected behaviour on widows while #505417 abstracts a waiting loop. gstpoll (bug #505417) * include gst/windows/gstwindows.h in gstpoll.h: - wraps close(), socketpair() for windows builds - struct pollfd & POLL* defines - on Windows, current code will use select() to wait. On windows select() only works with socket descriptors. This has the side effect to make the gstpoll patch depend on #515312 * FD_SETSIZE is defined to 64 in my mingw headers, and windows socket descriptors are allocated with numbers above FD_SETSIZE. So the check pfd->fd < FD_SIZE is not valid on windows. */ gstwindows (bug #515312) * add support for gstpoll (struct pollfd, POLL* defines) * fix send -> gst_win_net_send macro * enable building gstreamer/libs/gst/net on windows gst-plugins-base * merge of gst/sdp * gst/tcp: bug #515312 still needs work to make this stuff compile, so I still didn't enable it for win32. obviously It's not a regression as this code never worked on windows gst-plugins-good * merged udpsrc.c udpsrc.h Open questions & known issues: * (gstpoll.c) should we add an AC_CHECK_HEADERS for sys/poll.h ? * (windows/gstwin-common.h) I need to define WINVER to 0x0501 to have getaddrinfo() and freeaddrinfo() as those functions are only defined from WinXP and above. We probably should code replacement to be able to compile GStreamer for windows 2000 * I spread the code over 8 files, would you prefer having a couple of file ie. gstsysdeps-win.[ch] instead ? Overview $ diffstat gstreamer-winsocks-gstpoll-v1.patch configure.ac | 19 docs/gst/gstreamer-docs.sgml | 2 docs/gst/gstreamer-sections.txt | 29 + gst/Makefile.am | 15 gst/gst.h | 1 gst/gst_private.h | 4 gst/gstinfo.c | 8 gst/gstpoll.c | 1009 ++++++++++++++++++++++++++++++++++++++ gst/gstpoll.h | 97 +++ gst/windows/Makefile.am | 22 gst/windows/gstwin-common.h | 126 ++++ gst/windows/gstwin-fd.c | 166 ++++++ gst/windows/gstwin-fd.h | 48 + gst/windows/gstwin-libcmisc.c | 55 ++ gst/windows/gstwin-libcmisc.h | 35 + gst/windows/gstwin-networking.c | 594 ++++++++++++++++++++++ gst/windows/gstwin-networking.h | 118 ++++ gst/windows/gstwindows.h | 31 + libs/gst/Makefile.am | 4 libs/gst/net/Makefile.am | 2 libs/gst/net/gstnetclientclock.c | 163 +----- libs/gst/net/gstnetclientclock.h | 11 libs/gst/net/gstnettimeprovider.c | 142 +---- libs/gst/net/gstnettimeprovider.h | 12 plugins/elements/gstfdsink.c | 108 +--- plugins/elements/gstfdsink.h | 2 plugins/elements/gstfdsrc.c | 99 +-- plugins/elements/gstfdsrc.h | 2 tests/check/Makefile.am | 1 tests/check/gst/gstpoll.c | 369 +++++++++++++ 30 files changed, 2925 insertions(+), 369 deletions(-) $ diffstat gst-base-winsocks-gstpoll-v1.patch gst-libs/gst/riff/riff-read.c | 10 gst-libs/gst/rtsp/gstrtspconnection.c | 377 ++++++------------------ gst-libs/gst/rtsp/gstrtspconnection.h | 6 gst-libs/gst/sdp/gstsdpmessage.c | 2 gst/tcp/Makefile.am | 8 gst/tcp/fdsetstress.c | 179 ----------- gst/tcp/gstfdset.c | 532 ---------------------------------- gst/tcp/gstfdset.h | 68 ---- gst/tcp/gstmultifdsink.c | 124 +------ gst/tcp/gstmultifdsink.h | 11 gst/tcp/gsttcp.c | 66 +--- gst/tcp/gsttcp.h | 10 gst/tcp/gsttcpclientsink.c | 21 - gst/tcp/gsttcpclientsink.h | 2 gst/tcp/gsttcpclientsrc.c | 63 +--- gst/tcp/gsttcpclientsrc.h | 4 gst/tcp/gsttcpserversink.c | 20 - gst/tcp/gsttcpserversink.h | 2 gst/tcp/gsttcpserversrc.c | 136 +++----- gst/tcp/gsttcpserversrc.h | 6 20 files changed, 269 insertions(+), 1378 deletions(-) $ diffstat gst-good-winsocks-gstpoll-v1.patch Makefile.am | 4 - gstdynudpsink.c | 10 +- gstdynudpsink.h | 17 ++++ gstmultiudpsink.c | 17 +++- gstmultiudpsink.h | 16 ++++ gstudp.c | 5 - gstudpnetutils.c | 62 ---------------- gstudpnetutils.h | 77 --------------------- gstudpsink.h | 1 gstudpsrc.c | 198 ++++++++++++++---------------------------------------- gstudpsrc.h | 40 ++++++---- 11 files changed, 127 insertions(+), 320 deletions(-)
Created attachment 105500 [details] [review] gstpoll + winsocks against HEAD
Created attachment 105501 [details] [review] gstpoll + winsocks against HEAD
Created attachment 105502 [details] [review] gstpoll + winsocks against HEAD
Ok. Now that gstpoll is committed in tree and that I finally have my GStreamer git tree around, I have cleaned up my patches a lot so they are much simpler to review and comment. FWIT gstreamer (the core) does not compile under windows right now because there are no POLL* defines on windows. I have 3 patches : gstreamer-0001-Add-Windows-compatibility-layer: the core patch gst-base-0001-Make-sdp-library-compile-for-win32: a one liner to make -base cross compile gst-good-0001-Make-libgstudp-work-on-Windows: port libgstudp to use the compat layer code with this: gst-launch-0.10.exe -v --gst-plugin-path=c:\test-git\runtime\lib\gstreamer-0.10 udpsrc uri="udp://239.1.2.3:1234" ! flutsdemux ! ffdec_mpeg2video ! queue max-size-buffers=0 max-size-buffers=0 ! ffmpegcolorspace ! directdrawsink sync=0 works.
Created attachment 106545 [details] [review] against gsteamer HEAD (a few days ago)
Created attachment 106546 [details] [review] against -base HEAD (a few days ago)
Created attachment 106547 [details] [review] against -good HEAD (a few days ago)
Wow, we really need a full network abstraction in core? Not that I actually have a problem with it, mind, as long as someone is going maintain it. It'd be nice if someone else that cares about Windows could chime in.
Hmm, what are the advantages beyond those currently provided by GstPoll?
Huumm, sorry about the late reply, I was offline the last few days. @Jan: Yup, a network abstraction could be useful to make code of elements like udpsrc look much better. However I don't have the time to step up as a maintainer for such an API. @Ole André: the last patches are against gstpoll already, they are orthogonal with gstpoll. They are more a networking abtraction kind of API now that GstPoll is in CVS. My patches were written because I needed to get GStreamer work better on Windows, especially its networking elements (mainly udpsrc and rtspsrc). However, I'm not saying they are the one and only solution, they are just sufficient for my needs. So, the future of those lines is utterly uncertain, maybe it could be better to just close this bug as others are working on better solutions.
closing, alternative is in cvs and released.