From patchwork Tue Aug 30 12:09:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Neil Roberts X-Patchwork-Id: 37564 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp2514845pzh; Tue, 30 Aug 2022 05:10:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR49/lBHOvHn0Kvq4VR0jeuRSssx/Hv03mbUpKrnBY/gJkFGt0XPbCUrM0DVqZ9Dk+0E7oRm X-Received: by 2002:a17:906:6086:b0:731:3970:48d0 with SMTP id t6-20020a170906608600b00731397048d0mr16897990ejj.16.1661861438603; Tue, 30 Aug 2022 05:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661861438; cv=none; d=google.com; s=arc-20160816; b=wl0xP5ioNa7A0KPFFE+N8q9Uk/gZ1qIk581JAvd01mXuVEp7RUXsuKV+Ql5FABpMrb xkkNFxfvOhW8zSojq8jeyf4ZJsFeETnsKOf+JXAjpWBvBC4kTszP7bH4nSVotasW5FgL d8wf/EUpW2qW570Oi6jKFOInYv5Hv/A97mhxqmx8OktMB77Lay4xbeSdLFPY7o9KvqNu JAxqhMd9K3fDuajnIjdTbIfW00Aw3GJxhf6wiboa2NcQHB7VjttkjH3tsoKu1n5d6dCi nATZ953xg2yddLGuWq7OlY8rk2BafCGZuQn9a19YHIEDn17amLjdjVMgxPhVRAnqGizW KE2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=05luOHoOFMctwIRXcuxH/mPfV1ck0lb+QdlvPmFiXks=; b=jILXLCxQS/aS0beVYWaXF3NrdzQEz3kuZoApxAslvCCfn7cqVNw8iW4khyVfox3kzW QHx8JGyef5DiG9/tJaBtnd/E+dqkux88bkhyXJ6KajsUqrso/aFvL2TZLpiIkmhTkoYQ BMedq9Rdqc65EUZzV34VDfXskW3ertilH3kYShCRmvvjxrIrTEvTXTOayT0mPO0dmNtI /IMxWad9hdsQrJPDtIsYW78xNH9h9Q6BcuzmxoonGG3cQnCZ3ynOyM0zSis1WS4UDp/P R4xGMZnxEB6uF/LeBzaaWqaeSsooZo4TRnvydyG32pSEF2/wR38oWEBglQoXeVZz04qX 249Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@yahoo.co.uk header.s=s2048 header.b="p9Q/lOHI"; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ga8-20020a1709070c0800b007306121368esi9919900ejc.668.2022.08.30.05.10.37; Tue, 30 Aug 2022 05:10:38 -0700 (PDT) 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=@yahoo.co.uk header.s=s2048 header.b="p9Q/lOHI"; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EBB8568BABC; Tue, 30 Aug 2022 15:10:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from sonic311-30.consmr.mail.ir2.yahoo.com (sonic311-30.consmr.mail.ir2.yahoo.com [77.238.176.162]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D461968B993 for ; Tue, 30 Aug 2022 15:10:26 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1661861425; bh=smxvZK4WDGTWvf+hMxi5dpRHzWB6xV8qZcTyTq8X73E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=p9Q/lOHIGaZqjb2rYbzFN+4N8NQuYmhDCDoxvPKx2BvmZ9qNkX3UquBuxsp8ea2BULJCkYaYCS7D6TzIfPHfiM37Y9wSQYmdBPdGA419vd+S/GovIfHiQG3PPuMMl0aBg1YuBeg/NFMV3JoqqwE4Kq6qBZzRAOtOeuhRxYBNyjvoBpKFyA7c4PNWNcBLxlTB91Xl9broscOrr9CCvhjv/499Z2wLtHGlDBNlSq7026zt+DD5//x3DhE994LvAN/aIP8Jk6TF8T1ROw3c3bDWJbqL1MpfGnb4FypiQJxRWFtYWOU7pXHwdhRUbeEn0JpSTrTm4OwTC/aSYfU//3UCzQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1661861425; bh=/gtpq4HeVsdltRlTPlCKz8oN+/aNbqL4NqVlEdhvUzU=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=PSkuRApu7l050kIz6G1TPe6l+XiiGumTQ+pVtQF/Eu0BOAcW57ZUG+eAGu0vZZqv+HmvVHZMXgALmV0neU8Bn/RwAzOXda/RRj8sGwmUt0cnJ5u18XtgqglUwlXD945xj5IDQL96MGX4aqxuiFhUIjybN1Yo+VI5K5Kd39KBBFhTmJy++gJsEYVYe6HDHL75GkE/xC4yJ2rOqTMNnHBxxyHoy8vt+/O02O8e5IpcJ6ujDWok9gN0AaZAlqgjkxK8yLKeqfiln7C1uh/uqQiyaCTrnaKBHlvrdzh08u7yca5Xw+UcjylMUO5m9T/BQzAlz3nIxg/SMiLAwnsl6Csr0w== X-YMail-OSG: P1GsvrIVM1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eSWzIzkrXrJes_sVjxmnWg5mIYlM8crl2LAOXzCLA277hzseB5 YznpRdzXRUTZy8_s4FTCG2Jd.ciz8BhsEl69aN6wlN9cIuOHnpaTd.McnYdyId2gP7fQ3uRzLsnd HXM.F3BqkNe0T1vpqzzQ4iDRO_R5hi5fOgtyzqLLvvoZQIA-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ir2.yahoo.com with HTTP; Tue, 30 Aug 2022 12:10:25 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-m57bk (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID cd239fc55189361b064b71248153a937; Tue, 30 Aug 2022 12:10:24 +0000 (UTC) From: Neil Roberts To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Aug 2022 14:09:53 +0200 Message-Id: <20220830120954.452255-1-bpeeluk@yahoo.co.uk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829215422.GK2088045@pb2> References: <20220829215422.GK2088045@pb2> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/2] avformat/file: Add a specialized url_check callback for pipe protocol X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Michael Niedermayer Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 7422r18XnOlJ Using file_check for the pipe protocol doesn't make sense. For example, for a URL like “pipe:0” it would end up checking whether the “pipe:0” file exists. This patch instead makes it check the access modes on the corresponding file descriptor using fcntl on *nix and DuplicateHandle on Windows. v2: Use DuplicateHandle on Windows to check whether the duplicated handle can have the corresponding access flags. Signed-off-by: Neil Roberts --- libavformat/file.c | 74 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/libavformat/file.c b/libavformat/file.c index 98c9e81bcb..b3f7bc9282 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -375,9 +375,8 @@ const URLProtocol ff_file_protocol = { #if CONFIG_PIPE_PROTOCOL -static int pipe_open(URLContext *h, const char *filename, int flags) +static int pipe_get_fd(const char *filename, int flags) { - FileContext *c = h->priv_data; int fd; char *final; av_strstart(filename, "pipe:", &filename); @@ -390,6 +389,14 @@ static int pipe_open(URLContext *h, const char *filename, int flags) fd = 0; } } + + return fd; +} + +static int pipe_open(URLContext *h, const char *filename, int flags) +{ + FileContext *c = h->priv_data; + int fd = pipe_get_fd(filename, flags); #if HAVE_SETMODE setmode(fd, O_BINARY); #endif @@ -398,13 +405,74 @@ static int pipe_open(URLContext *h, const char *filename, int flags) return 0; } +static int pipe_check(URLContext *h, int mask) +{ + int fd = pipe_get_fd(h->filename, mask); + int access = 0; + +#ifdef _WIN32 + + HANDLE pipe_handle = (HANDLE) _get_osfhandle(fd); + HANDLE tmp_handle; + + if (pipe_handle == INVALID_HANDLE_VALUE) + return AVERROR(errno); + + if (mask & AVIO_FLAG_READ && + DuplicateHandle(GetCurrentProcess(), /* hSourceProcessHandle */ + pipe_handle, + GetCurrentProcess(), /* hTargetProcessHandle */ + &tmp_handle, + FILE_READ_DATA, + FALSE, /* bInheritHandle */ + 0 /* options */)) { + access |= AVIO_FLAG_READ; + CloseHandle(tmp_handle); + } + + if (mask & AVIO_FLAG_WRITE && + DuplicateHandle(GetCurrentProcess(), /* hSourceProcessHandle */ + pipe_handle, + GetCurrentProcess(), /* hTargetProcessHandle */ + &tmp_handle, + FILE_WRITE_DATA, + FALSE, /* bInheritHandle */ + 0 /* options */)) { + access |= AVIO_FLAG_WRITE; + CloseHandle(tmp_handle); + } + +#else /* _WIN32 */ + + int status_flags = fcntl(fd, F_GETFL); + + if (status_flags == -1) + return AVERROR(errno); + + switch (status_flags & O_ACCMODE) { + case O_RDONLY: + access = AVIO_FLAG_READ; + break; + case O_WRONLY: + access = AVIO_FLAG_WRITE; + break; + case O_RDWR: + access = AVIO_FLAG_READ | AVIO_FLAG_WRITE; + break; + } + +#endif /* _WIN32 */ + + return access & mask; +} + const URLProtocol ff_pipe_protocol = { .name = "pipe", .url_open = pipe_open, .url_read = file_read, .url_write = file_write, .url_get_file_handle = file_get_handle, - .url_check = file_check, + .url_check = pipe_check, .priv_data_size = sizeof(FileContext), .priv_data_class = &pipe_class, .default_whitelist = "crypto,data" From patchwork Tue Aug 30 12:09:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Roberts X-Patchwork-Id: 37563 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp2515103pzh; Tue, 30 Aug 2022 05:11:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR5wOGVBxsFsAwUWxBlKDaid+6+9Zor1t1vwRvp9aq4i3rXfCxV5rEMWaOjicagTJ26jVz0Q X-Received: by 2002:a05:6402:3506:b0:43e:954b:bc8a with SMTP id b6-20020a056402350600b0043e954bbc8amr20567945edd.266.1661861461561; Tue, 30 Aug 2022 05:11:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661861461; cv=none; d=google.com; s=arc-20160816; b=pW8SA1DqhtT21PxSwynJSVnqVjDTMk4N5Ou0HEBHsBMO4e0YccQGbGJ6erF/AKxTqK T2Lc67SZHhqqrQnmVQiTrFF8huMxPcYEQQ1zW+mfCeNee6gJ9VlW/qW9PNCTSMMfOG0f HIiIl3yraI/goHK5x7ieRX5gY8wqpPgWqiNRXfG3vGXYvRzpaEY1UZ0JNEEOftWkyOAx Ia9EKJ+0UK+7wxlfa/MexMG8iSyKGv9fIHk6oJ2+RQemEiFXw3tLaX/JysLWhFXde2Sa bhWEu7KomPh8QFeHoFucsAvC1ZTwgqgOTca24XmsXbo4mC4rush0gG7mCX45wikRo9Tw avnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=pRrfqufhb4v7is3smecKZ+xQyhXndoUDN48Qf+rLFyI=; b=l66Koxw9OdSO+zVD4dIQpD6MxptW0Ltx0yZAXBaxXASiuldImDiKCw5hhEAreb4IDf WZCmwYdfgvO72CTsxNyI+ECmtAkA+rL3PqmTh6RRCxQRFv1hRrQWITQvVYKZHf4SzP89 pqr4yfR9HQXqzsWNGCIZrEbCpf5OPZ7EZnMbUkHHImh4mPpYVnDwlr0JtLpXvf7b8Arz yfkbJO7hvoWK1yxMt1OmSYVTM7GhhheD3ZxWvP2PwavQMuhItJsXWfthVVcQE+ZAo8N/ +YWEGx5TZOey1p603OzzU/irDw2OxORn3Adean4FF/2NpD9zz1jWvrpfcBAOrt3cj2cK ypxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@yahoo.co.uk header.s=s2048 header.b=BHrYR7Dm; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k3-20020a1709063e0300b00733002330edsi1848728eji.342.2022.08.30.05.10.50; Tue, 30 Aug 2022 05:11:01 -0700 (PDT) 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=@yahoo.co.uk header.s=s2048 header.b=BHrYR7Dm; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2622868BAEC; Tue, 30 Aug 2022 15:10:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from sonic310-57.consmr.mail.ir2.yahoo.com (sonic310-57.consmr.mail.ir2.yahoo.com [77.238.177.30]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2FD7E68B149 for ; Tue, 30 Aug 2022 15:10:37 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1661861436; bh=AwhGwQonBXV4fi/s7z6/NnX52BjIwq3GLGFgAHkAWQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=BHrYR7DmQIpNGL9MUEFB1zfXIZ9FlNl4bOVhuhTvexB/sKnPhEgXSOZ/5w2bFJnaF09PaappJWII+6/Dqb8kS57880VqAhzIbRuvfGjADoeqDQRj1sr0bE04g67jM/pMVT73RVT42wVcEqr6jIWoYPsx0grTIPP0f9upw/JXOPqKuBSckolRUfDECug2LvfMjWHb7ebvBO+qSFx3PulmUcBMSt0HX3sls4f7QEMiA0u64tknA1nVVFdexoOYjDHeKheV707OoE6OCSEUJUWAF1MeME8W0nRsqGM5rbYzAQgCrP2b+dEB5KgWeOpLWGLJPFTcZ+MIutz44G1DvpWZ2A== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1661861436; bh=yC/S5Z4xTZ5LixK3eC2xyDGgKLuBZ4oKgil1vH3rAPs=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=WTuKJv607uxPWr9dyfP/m0a3+J4VeoBXQY8eir+5Q6uSqPHNU3Bm9HVuh3FvwP/i5DvfUvaE4dLCbTXfQe8VRKhq4hPmyLXd518QbBPiuakB2ENaLSEh35+1JlqbovOtwbpD28RE1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OKyW_eA03nXZ5uDWD_rB MWh7.MLbagy7hv98v2L88eJs58Ir.9DrNBgGu0HFEnFr87kyn5rFZomfvdxr_gCurHnRl.wWYlEy dCOCei27WeOJCuw54YAjFB4k_qDYXIPEFRRqb.ljyUjMq5SbUyq0gjLOclou6Lz5DaN9dy9GjYJl wAYDri.qWuJc79LLAGcRKtAKx9gS.0eMdRtA_OGl6hPi8DKZbctGFhJmoN9olOvSnirazn7MOXEp lXlT3joA0pcHv3C3fE1695dkF7cNM8QrjtkYYXmmkqnlV2XrPZXSgZNcyVq..3HVFuoAwu1OOeK5 Nosw05Zopuemt_xbCz0x1PObsm8GQAQMhz4jYm8AImw-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ir2.yahoo.com with HTTP; Tue, 30 Aug 2022 12:10:36 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-5fxhh (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID d799474098d1407f2db818b0fae1fd02; Tue, 30 Aug 2022 12:10:34 +0000 (UTC) From: Neil Roberts To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Aug 2022 14:09:54 +0200 Message-Id: <20220830120954.452255-2-bpeeluk@yahoo.co.uk> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220830120954.452255-1-bpeeluk@yahoo.co.uk> References: <20220829215422.GK2088045@pb2> <20220830120954.452255-1-bpeeluk@yahoo.co.uk> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/2] avformat/tests: Add a test for avio_check with the pipe protocol X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Michael Niedermayer Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: U6ooOeyIuviP Creates a UNIX pipe and then verifies that avio_check returns the right access flags for the two ends of the pipe. v2: Add support for the Windows version of _pipe Signed-off-by: Neil Roberts --- libavformat/Makefile | 1 + libavformat/tests/.gitignore | 1 + libavformat/tests/pipe.c | 108 +++++++++++++++++++++++++++++++++++ tests/fate/libavformat.mak | 5 ++ 4 files changed, 115 insertions(+) create mode 100644 libavformat/tests/pipe.c diff --git a/libavformat/Makefile b/libavformat/Makefile index f67a99f839..9c681c58c5 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -732,6 +732,7 @@ TESTPROGS-$(CONFIG_MOV_MUXER) += movenc TESTPROGS-$(CONFIG_NETWORK) += noproxy TESTPROGS-$(CONFIG_SRTP) += srtp TESTPROGS-$(CONFIG_IMF_DEMUXER) += imf +TESTPROGS-$(CONFIG_PIPE_PROTOCOL) += pipe TOOLS = aviocat \ ismindex \ diff --git a/libavformat/tests/.gitignore b/libavformat/tests/.gitignore index cdd0cce061..567d6f9e40 100644 --- a/libavformat/tests/.gitignore +++ b/libavformat/tests/.gitignore @@ -7,3 +7,4 @@ /srtp /url /seek_utils +/pipe diff --git a/libavformat/tests/pipe.c b/libavformat/tests/pipe.c new file mode 100644 index 0000000000..18a8551fd5 --- /dev/null +++ b/libavformat/tests/pipe.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2022 Neil Roberts + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include "libavformat/avio.h" +#include "libavutil/error.h" + +static int check_pipe(const char *url, int mask, int expected) +{ + int flags = avio_check(url, mask); + + if (flags < 0) { + fprintf(stderr, + "avio_check for %s with mask 0x%x failed: %s\n", + url, + mask, + av_err2str(flags)); + return 0; + } + + if (flags != expected) { + fprintf(stderr, + "Wrong result returned from avio_check for %s with mask 0x%x. " + "Expected 0x%x but received 0x%x\n", + url, + mask, + expected, + flags); + return 0; + } + + return 1; +} + +int main(int argc, char **argv) +{ + int ret = 0; + int pipe_fds[2]; + char read_url[20], write_url[20]; + int check_invalid_ret; + int pipe_ret; + +#ifdef _WIN32 + pipe_ret = _pipe(pipe_fds, 1024 /* psize */, 0 /* textmode */); +#else + pipe_ret = pipe(pipe_fds); +#endif + + if (pipe_ret == -1) { + fprintf(stderr, "error creating pipe: %s\n", strerror(errno)); + return 1; + } + + snprintf(read_url, sizeof(read_url), "pipe:%d", pipe_fds[0]); + snprintf(write_url, sizeof(write_url), "pipe:%d", pipe_fds[1]); + + if (!check_pipe(read_url, + AVIO_FLAG_READ | AVIO_FLAG_WRITE, + AVIO_FLAG_READ)) + ret = 1; + + if (!check_pipe(write_url, + AVIO_FLAG_READ | AVIO_FLAG_WRITE, + AVIO_FLAG_WRITE)) + ret = 1; + + /* Ensure that we don't get flags that we didn't ask for */ + if (!check_pipe(read_url, AVIO_FLAG_WRITE, 0)) + ret = 1; + + close(pipe_fds[0]); + close(pipe_fds[1]); + + /* An invalid fd should return EBADF */ + check_invalid_ret = avio_check(read_url, AVIO_FLAG_READ); + + if (check_invalid_ret != AVERROR(EBADF)) { + fprintf(stderr, + "avio_check on invalid FD expected to return %i " + "but %i was received\n", + AVERROR(EBADF), + check_invalid_ret); + ret = 1; + } + + return ret; +} diff --git a/tests/fate/libavformat.mak b/tests/fate/libavformat.mak index d2acb4c9e0..7a22f54c04 100644 --- a/tests/fate/libavformat.mak +++ b/tests/fate/libavformat.mak @@ -26,6 +26,11 @@ FATE_LIBAVFORMAT-$(CONFIG_IMF_DEMUXER) += fate-imf fate-imf: libavformat/tests/imf$(EXESUF) fate-imf: CMD = run libavformat/tests/imf$(EXESUF) +FATE_LIBAVFORMAT-$(CONFIG_PIPE_PROTOCOL) += fate-pipe +fate-pipe: libavformat/tests/pipe$(EXESUF) +fate-pipe: CMD = run libavformat/tests/pipe$(EXESUF) +fate-pipe: CMP = null + FATE_LIBAVFORMAT += fate-seek_utils fate-seek_utils: libavformat/tests/seek_utils$(EXESUF) fate-seek_utils: CMD = run libavformat/tests/seek_utils$(EXESUF)