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

Matt Oliver protogonoi at gmail.com
Mon Dec 12 07:00:16 EET 2016


---
 libavformat/udp.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

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

+#if HAVE_THREADS && HAVE_WINSOCK2_H
+/* Winsock2 recv function can be unblocked by shutting down 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
@@ -526,6 +534,8 @@ static void *circular_buffer_task_rx( void *_URLContext)
                 goto end;
             }
             continue;
+        } else if (len == 0) {
+            goto end;
         }
         AV_WL32(s->tmp, len);

@@ -1144,8 +1154,13 @@ 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_THREADS && HAVE_WINSOCK2_H
+            shutdown(s->udp_fd, SD_BOTH);
+#   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));
--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-avformat-udp-Enable-FIFO-when-using-windows-sockets.patch
Type: application/octet-stream
Size: 1733 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161212/e420eb84/attachment.obj>


More information about the ffmpeg-devel mailing list