From patchwork Wed Apr 6 12:00:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Gaiser X-Patchwork-Id: 34685 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp849602pzb; Wed, 6 Apr 2022 05:02:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdJtHrN9yXz7HC0baFrR6A0IVajIuwPOdJdMdExAuQMlzqYNZLwXlQLUiChdVL0zKRF1K8 X-Received: by 2002:a17:906:698a:b0:6ce:b983:babf with SMTP id i10-20020a170906698a00b006ceb983babfmr8270484ejr.553.1649246543629; Wed, 06 Apr 2022 05:02:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649246543; cv=none; d=google.com; s=arc-20160816; b=d8giVp2CFphOWKD3bH0lwOCbGjP+QGwS3R3L7aWv0cMUkh2okCzJMQCMfq5YSmJRow NQkRF6f9f+K4ehsiqi4j1VwgCiAmP2W87khaVYAXYZhCRdeZ5SXvJlo5miMZxWFUpZt/ lX57ejCa4X48Qb8ChtNOB/bwZliORubMuPTeIy3a7RW27dcnKI0TvhN666hpc33PeyNC dmnLX2H3/FOrdQLou5QwFh6HaFGhDXr5SEuzpXIP0f38Y8qTWpPLpipDW23Bfc/ZbUVG 277T3hzjuidC0ovMM5h8uLKtz7uIhFdGtEph42zifX1kLkSN+j+Ob7AyqT3oDpagHMg3 3hzA== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=U8JI9VgDtCnw03YCWA+mKd34LKHw5Frw9BfBSpuU3EA=; b=ADhR3roFLa5A0fIF3EuNmqDlB476yzrAXUvxGt4Ok7MAuwIQVfvKNyrxyKCTWKVcJT oIUwq4JZ1UvKB6ZzmYoYi477wcvbk3Ggw0jHj1UANAEvhHePvrGb8la6krXFVAzkvrQV mDkdekKgS8X9rmitJbdGckaA30k4pLZnIhUsUowqcFOguCVCkhod3c2zLUxayjjpF0YY bR14HOoBz9bLhXbdqVxkyjlJ91U24OL+EIfB/UoDNa5zX9EUDrDH/NmmFgMQVZMuy2HV weB0NpJBOVTuz8BK9ZF6+iYmaST5CEJ/nFp3n+xWDGSLMS3/V1nTaJ2l9LxRFk7KeQIo ppQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Ap5IvYua; 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 sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dd17-20020a170906c83100b006df76385c0fsi10601490ejb.175.2022.04.06.05.02.23; Wed, 06 Apr 2022 05:02:23 -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=@gmail.com header.s=20210112 header.b=Ap5IvYua; 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 sp=QUARANTINE 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 C97C168B2C8; Wed, 6 Apr 2022 15:02:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 211A068AF88 for ; Wed, 6 Apr 2022 15:02:05 +0300 (EEST) Received: by mail-ed1-f51.google.com with SMTP id w18so2284356edi.13 for ; Wed, 06 Apr 2022 05:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4HVwL6Y/9Gb7C3GmSbCPp8YyOayv6vp1SBaQPHuu1VQ=; b=Ap5IvYuaXZ1ChcPoHJTG1Re+18r5sHOjKyVEenivYkL9wSeDjNlDvlmMxhqGLYqJ8t TMX7FxkN8/0prV5m7AAzZUVrg7d2oWg/khkL9QU1GvcNb9gV7G4/9DynfW126hA5Ra+s WTEC3UelJflO7I8MMg27uwGLTdDsQRGTQaav3aEIEpBfyJxdRxGrPevaPgwNjbet9hkO OmOLsotgwPzSJ1JMgVgOSpQkEAsqrU/D2guUCz+ilAu5Oh0++Ds+Rys2ot55VFRbqyNS TXgYgcnflxYdMXXmavnXpxWH8bmolobGHL446UB5/tUp2UF142WKggtvCqW8w4iPuQi0 Ivrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=4HVwL6Y/9Gb7C3GmSbCPp8YyOayv6vp1SBaQPHuu1VQ=; b=lVYj/N9ljEbdDqpgDZJt5/CfbKWCcoG+JoLtjxwwPF3IT2IX2EHqHIiKkQ44vUERTX 91KiNghGjc2FrnUpFLQW01RzBdL3WEF6+SNWRBtFfiU2xH7uW9TH+p1qsbK483zb/WFn jQIa8WSWLC/pLueVTg+RaAMtBmXTOFn6kq7Jgev7QKSHSNAAsF8g/Vhwx8maiX5OMhe7 /BuuI/xXQtOqw2HQaFDZUxHfMN3gtXivJLHsTiKTaf+v/stQ0ZGukOqGO6DP6icywecr mqZEdWs760xi0PihEfpLrMjYmBh4Lo1zpDcwV2VblGoh8l/DISlo4zZp/xwKN3XZCpzR qOAw== X-Gm-Message-State: AOAM530vJWCPMl/8z+RhE2Smv5/YAneQ5PyabGHuiONi0/NU2nCe9uki 9wlYXdeoBMYPY4oZqYRR7i6Q9xKUmyk= X-Received: by 2002:a05:6402:1941:b0:413:2822:9c8 with SMTP id f1-20020a056402194100b00413282209c8mr8365535edz.13.1649246523888; Wed, 06 Apr 2022 05:02:03 -0700 (PDT) Received: from localhost.localdomain (92-110-137-10.cable.dynamic.v4.ziggo.nl. [92.110.137.10]) by smtp.gmail.com with ESMTPSA id bs7-20020a056402304700b004197e5d2350sm7616448edb.54.2022.04.06.05.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:02:03 -0700 (PDT) From: Mark Gaiser To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Apr 2022 14:00:55 +0200 Message-Id: <20220406120056.10537-1-markg85@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v13 0/1] Add IPFS protocol support. 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: Mark Gaiser Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: OH48HPeH5xKs Hi, This patch series adds support for IPFS. V13: - Apply clang-format on the changes - Remove trailing whitespace V12: - Removed last ifdef, we only need stat for "file exists" purposes. - To be sure, added back os_support.h as it does change stat to _stati64 on windows. V11: - Cleaned up the headers. What's there is actually needed now. - Some more strict checking (namely on fgets) - Merged long log in one log entry. - Another allocation check (this time for "fulluri") - Lots of formatting changes (not visual) to be more in line with the soft 80 char limit. V10: - Removed free on c->gateway in ipfs_close to fix a double free. V9: - dweb.link as fallback gateway. This is managed by Protocol Labs (like IPFS). - Change all errors to warnings as not having a gateway still gives you a working video playback. - Changed the console output to be more clear. V8: - Removed unnecessary change to set the first gateway_buffer character to 0. It made no sense as the buffer is always overwritten in the function context. - Change %li to %zu (it's intended to print the sizeof in all cases) V7: - Removed sanitize_ipfs_gateway. Only the http/https check stayed and that's now in translate_ipfs_to_http. - Added a check for ipfs_cid. It's only to show an error is someone happens to profide `ffplay ipfs://` without a cid. - All snprintf usages are now checked. - Adding a / to a gateway if it didn't end with it is now done in the same line that composes the full resulting url. - And a couple more minor things. V6: - Moved the gateway buffer (now called gateway_buffer) to IPFSGatewayContext - Changed nearly all PATH_MAX uses to sizeof(...) uses for future flexibility - The rest is relatively minor feedback changes V5: - "c->gateway" is now not modified anymore - Moved most variables to the stack - Even more strict checks with the auto detection logic - Errors are now AVERROR :) - Added more logging and changed some debug ones to info ones as they are valuable to aid debugging as a user when something goes wrong. V3 (V4): - V4: title issue from V3.. - A lot of style changes - Made url checks a lot more strict - av_asprintf leak fixes - So many changes that a diff to v2 is again not sensible. V2: - Squashed and changed so much that a diff to v1 was not sensible. The following is a short summary. In the IPFS ecosystem you access it's content by a "Content IDentifier" (CID). This CID is, in simplified terms, a hash of the content. IPFS itself is a distributed network where any user can run a node to be part of the network and access files by their CID. If any reachable node within that network has the CID, you can get it. IPFS (as a technology) has two protocols, ipfs and ipns. The ipfs protocol is the immutable way to access content. The ipns protocol is a mutable layer on top of it. It's essentially a new CID that points to a ipfs CID. This "pointer" if you will can be changed to point to something else. Much more information on how this technology works can be found here [1]. This patch series allows to interact natively with IPFS. That means being able to access files like: - ffplay ipfs:// - ffplay ipns:// There are multiple ways to access files on the IPFS network. This patch series uses the gateway driven way. An IPFS node - by default - exposes a local gateway (say http://localhost:8080) which is then used to get content from IPFS. The gateway functionality on the IPFS side contains optimizations to be as ideal to streaming data as it can be. Optimizations that the http protocol in ffmpeg also has and are thus reused for free in this approach. A note on other "more appropiate" ways, as I received some feedback on that. For ffmpeg purposes the gateway approach is ideal! There is a "libipfs" but that would spin up an ipfs node with the overhead of: - bootstrapping - connecting to nodes - finding other nodes to connect too - finally finding your file This alternative approach could take minutes before a file is played. The gateway approach immediately connects to an already running node thus gives the file the fastest. Much of the logic in this patch series is to find that gateway and essentially rewrite: "ipfs://" to: "http://localhost:8080/ipfs/" Once that's found it's forwared to the protocol handler where eventually the http protocol is going to handle it. Note that it could also be https. There's enough flexibility in the implementation to allow the user to provide a gateway. There are also public https gateways which can be used just as well. After this patch is accepted, I'll work on getting IPFS supported in: - mpv (requires this ffmpeg patch) - vlc (prefers this patch but can be made to work without this patch) - kodi (requires this ffmpeg patch) Best regards, Mark Gaiser [1] https://docs.ipfs.io/concepts/ Mark Gaiser (1): avformat: Add IPFS protocol support. configure | 2 + doc/protocols.texi | 30 ++++ libavformat/Makefile | 2 + libavformat/ipfsgateway.c | 339 ++++++++++++++++++++++++++++++++++++++ libavformat/protocols.c | 2 + 5 files changed, 375 insertions(+) create mode 100644 libavformat/ipfsgateway.c