From patchwork Wed Dec 7 06:05:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Oliver X-Patchwork-Id: 1708 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.86 with SMTP id o83csp124682vsa; Tue, 6 Dec 2016 22:05:24 -0800 (PST) X-Received: by 10.28.225.11 with SMTP id y11mr835017wmg.93.1481090724636; Tue, 06 Dec 2016 22:05:24 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 71si7007767wmp.95.2016.12.06.22.05.24; Tue, 06 Dec 2016 22:05:24 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5584689E3A; Wed, 7 Dec 2016 08:05:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f194.google.com (mail-io0-f194.google.com [209.85.223.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E33F3689A44 for ; Wed, 7 Dec 2016 08:05:04 +0200 (EET) Received: by mail-io0-f194.google.com with SMTP id h133so26166885ioe.2 for ; Tue, 06 Dec 2016 22:05:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=7KOMcF63Tq6pt2lk+7LNIJGs5W/fZqlWBTKcYxMIU/g=; b=P2WHbFxJwgxRfHtOgiPRWwXqSQ4xnyeJAF5WX83Z5paOSGSDSMv1gRPUPMMj5cl4kZ Rs2xadH6RFQUJJ8HKVoWFcIGUIISN0prkJxDJ8L5hXRrfsAJPf8C+HzPIfTjfVYy0pfy mS1mCO1Qt+RulukZIjyg4dHAIs/WaCXQp8gqybm6XLFYO2p9ZpNjsZ4Jaw2oFPP4CDRf 1cthRaGLnZN8LdYTurl9T7kPf6MS7BLqrrb7vTdmUiEYwbLrjp2i/mkR9StYa17Fextf rDuRyeox3JHWpsVWBiGV1RF2YqKBIzvHzy6sr/yiVEufTXXNPrE7xk6YpVc4iMW2hY7L egKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=7KOMcF63Tq6pt2lk+7LNIJGs5W/fZqlWBTKcYxMIU/g=; b=Z+Uhlg2z0itcNlhSGFcCSR+YkFreD6IxtK5Xxh7cXW3lylj1vuaSISb5HGKNcV8aV8 Z9J3pyDQ6MQbh9/EptcciAT1Is2lkHm0ubwQ57ig91HrbXdSiLtIOzaakJB8DQDUhXu2 yg5Fwslv27FJa3liZX/tz8anpEbjvjfFmEO5cWpg8c8T1GpjJyLBscyLdJXiUVmn9NzX DqdBoUe7tlL1tiJU5/wvJSD38XbFYwjtz5+beYhVwUSOIBTtjlg0ymL4kLL6rPXHrrQ2 WUVQqd2/3mZo4+SAfx+5yUrUfpRrlUrVoj4dbqbbloAIeI8ktfI7J9xzu3E2xWaTOvi7 GX/Q== X-Gm-Message-State: AKaTC00sheueOzbRRF5Tu7ic6RFuMo8EIW2tGCa09i8NQYPm3GKOvB9w0Jx9KiHssSQXZtUav3HCt/U4/9hpdQ== X-Received: by 10.107.22.6 with SMTP id 6mr59274525iow.8.1481090714336; Tue, 06 Dec 2016 22:05:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.36.65.90 with HTTP; Tue, 6 Dec 2016 22:05:13 -0800 (PST) From: Matt Oliver Date: Wed, 7 Dec 2016 17:05:13 +1100 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH 3/3] avformat/udp: Enable FIFO when using windows sockets. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Matt Oliver --- libavformat/udp.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) #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; } 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"