[FFmpeg-devel] [PATCH 3/3] avformat/udp: Enable FIFO when using windows sockets.

Matt Oliver protogonoi at gmail.com
Wed Dec 7 08:05:13 EET 2016


Signed-off-by: Matt Oliver <protogonoi at gmail.com>
---
 libavformat/udp.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index f8c861d..0e4766f 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -64,6 +64,14 @@
 #define HAVE_PTHREAD_CANCEL 0
 #endif

+#if !HAVE_PTHREAD_CANCEL && (HAVE_THREADS && HAVE_WINSOCK2_H)
+/* Winsock2 recv function can be unblocked by shutting down and closing
the socket */
+#define pthread_setcancelstate(x, y)
+#define pthread_cancel
+#undef HAVE_PTHREAD_CANCEL
+#define HAVE_PTHREAD_CANCEL 1
+#endif
+
 #if HAVE_PTHREAD_CANCEL
 #include "libavutil/thread.h"
 #endif
@@ -1144,8 +1152,14 @@ static int udp_close(URLContext *h)
     if (s->thread_started) {
         int ret;
         // Cancel only read, as write has been signaled as success to the
user
-        if (h->flags & AVIO_FLAG_READ)
+        if (h->flags & AVIO_FLAG_READ) {
+#   if !HAVE_PTHREAD_CANCEL && (HAVE_THREADS && HAVE_WINSOCK2_H)
+            closesocket(s->udp_fd);
+            s->udp_fd = INVALID_SOCKET;
+#   else
             pthread_cancel(s->circular_buffer_thread);
+#   endif
+        }
         ret = pthread_join(s->circular_buffer_thread, NULL);
         if (ret != 0)
             av_log(h, AV_LOG_ERROR, "pthread_join(): %s\n", strerror(ret));
@@ -1153,7 +1167,8 @@ static int udp_close(URLContext *h)
         pthread_cond_destroy(&s->cond);
     }
 #endif
-    closesocket(s->udp_fd);
+    if(s->udp_fd != INVALID_SOCKET)
+        closesocket(s->udp_fd);
     av_fifo_freep(&s->fifo);
     return 0;
 }
-- 
2.10.2.windows.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-avformat-udp-Enable-FIFO-when-using-windows-sockets.patch
Type: application/octet-stream
Size: 1854 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161207/27b32f04/attachment.obj>


More information about the ffmpeg-devel mailing list