From: Mark Gaiser <markg85@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Mark Gaiser <markg85@gmail.com>
Subject: [FFmpeg-devel] [PATCH 3/5] Merge IPNS and IPFS handling.
Date: Mon, 31 Jan 2022 14:51:14 +0100
Message-ID: <20220131135116.14035-4-markg85@gmail.com> (raw)
In-Reply-To: <20220131135116.14035-1-markg85@gmail.com>
Only the open function needs to detect which one is used.
Signed-off-by: Mark Gaiser <markg85@gmail.com>
---
libavformat/ipfs.c | 99 +++++++++++-----------------------------------
1 file changed, 22 insertions(+), 77 deletions(-)
diff --git a/libavformat/ipfs.c b/libavformat/ipfs.c
index 8daf032dd2..22487c6cc8 100644
--- a/libavformat/ipfs.c
+++ b/libavformat/ipfs.c
@@ -1,6 +1,6 @@
/*
* IPFS protocol.
- * Copyright (c) 2021 Mark Gaiser
+ * Copyright (c) 2022 Mark Gaiser
*
* This file is part of FFmpeg.
*
@@ -47,23 +47,30 @@ typedef struct Context {
static int ipfs_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
{
const char *gatewaysuffix;
+ const char *protocolPathSuffix = "ipfs/";
int ret = 0;
Context *c = h->priv_data;
+ int isIpfs = (av_strstart(uri, "ipfs://", &gatewaysuffix) || av_strstart(uri, "ipfs:", &gatewaysuffix));
+ int isIpns = (av_strstart(uri, "ipns://", &gatewaysuffix) || av_strstart(uri, "ipns:", &gatewaysuffix));
- if (!av_strstart(uri, "ipfs://", &gatewaysuffix) &&
- !av_strstart(uri, "ipfs:", &gatewaysuffix)) {
- av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri);
+ if (!isIpfs && !isIpns) {
ret = AVERROR(EINVAL);
+ av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri);
goto err;
}
-
- char* ipfs_gateway = "http://localhost:8080/";
-
- c->fulluri = malloc(strlen(ipfs_gateway)+strlen(gatewaysuffix) + 1);
-
- strcpy(c->fulluri, ipfs_gateway);
+
+ // If we have IPNS, update the protocol
+ if (isIpns) {
+ protocolPathSuffix = "ipns/";
+ }
+
+ // Concatenate the url. This ends up with something like: http://localhost:8080/ipfs/Qm.....
+ c->fulluri = malloc(strlen(c->gateway) + strlen(protocolPathSuffix) + strlen(gatewaysuffix) + 1);
+ strcpy(c->fulluri, c->gateway);
+ strcat(c->fulluri, protocolPathSuffix);
strcat(c->fulluri, gatewaysuffix);
+ // Pass the URL back to FFMpeg's protocol handler.
if ((ret = ffurl_open_whitelist(&c->inner, c->fulluri, flags,
&h->interrupt_callback, options,
h->protocol_whitelist, h->protocol_blacklist, h)) < 0) {
@@ -105,72 +112,10 @@ static int ipfs_close(URLContext *h)
return ret;
}
-static int ipns_open(URLContext *h, const char *uri, int flags, AVDictionary **options)
-{
- const char *gatewaysuffix;
- int ret = 0;
- Context *c = h->priv_data;
-
- if (!av_strstart(uri, "ipns://", &gatewaysuffix) &&
- !av_strstart(uri, "ipns:", &gatewaysuffix)) {
- av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri);
- ret = AVERROR(EINVAL);
- goto err;
- }
-
- char* ipfs_gateway = "https://ipfs.io/ipns/";
-
- c->fulluri = malloc(strlen(ipfs_gateway)+strlen(gatewaysuffix) + 1);
-
- strcpy(c->fulluri, ipfs_gateway);
- strcat(c->fulluri, gatewaysuffix);
-
- if ((ret = ffurl_open_whitelist(&c->inner, c->fulluri, flags,
- &h->interrupt_callback, options,
- h->protocol_whitelist, h->protocol_blacklist, h)) < 0) {
- av_log(h, AV_LOG_ERROR, "Unable to open resource: %s\n", c->fulluri);
- goto err;
- }
-
-err:
- return ret;
-}
-
-static int ipns_read(URLContext *h, unsigned char *buf, int size)
-{
- Context *c = h->priv_data;
- int ret;
-
- ret = ffurl_read(c->inner, buf, size);
-
- return ret;
-}
-
-static int64_t ipns_seek(URLContext *h, int64_t pos, int whence)
-{
- Context *c = h->priv_data;
- int64_t ret;
-
- ret = ffurl_seek(c->inner, pos, whence);
-
- return ret;
-}
-
-static int ipns_close(URLContext *h)
-{
- Context *c = h->priv_data;
- int ret;
-
- ret = ffurl_closep(&c->inner);
-
- return ret;
-}
-
#define OFFSET(x) offsetof(Context, x)
-#define D AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
- {"gateway", "The gateway to ask for IPFS data.", OFFSET(gateway), AV_OPT_TYPE_BINARY, .flags = D },
+ {"gateway", "The gateway to ask for IPFS data.", OFFSET(gateway), AV_OPT_TYPE_STRING, {.str = "http://localhost:8080/"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
{NULL},
};
@@ -193,10 +138,10 @@ const URLProtocol ff_ipfs_protocol = {
const URLProtocol ff_ipns_protocol = {
.name = "ipns",
- .url_open2 = ipns_open,
- .url_read = ipns_read,
- .url_seek = ipns_seek,
- .url_close = ipns_close,
+ .url_open2 = ipfs_open,
+ .url_read = ipfs_read,
+ .url_seek = ipfs_seek,
+ .url_close = ipfs_close,
.priv_data_size = sizeof(Context),
.priv_data_class = &ipfs_context_class,
};
--
2.35.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-01-31 13:53 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-31 13:51 [FFmpeg-devel] [PATCH 0/5] Add IPFS and IPNS protocol support Mark Gaiser
2022-01-31 13:51 ` [FFmpeg-devel] [PATCH 1/5] Early version of IPFS " Mark Gaiser
2022-01-31 15:59 ` Michael Niedermayer
2022-01-31 16:06 ` James Almer
2022-01-31 16:34 ` Mark Gaiser
2022-01-31 20:26 ` Lynne
2022-01-31 22:04 ` Mark Gaiser
2022-01-31 13:51 ` [FFmpeg-devel] [PATCH 2/5] Fix up IPNS support Mark Gaiser
2022-01-31 16:00 ` Michael Niedermayer
2022-01-31 13:51 ` Mark Gaiser [this message]
2022-01-31 13:51 ` [FFmpeg-devel] [PATCH 4/5] Implement logic to determine the IPFS gateway Mark Gaiser
2022-01-31 13:51 ` [FFmpeg-devel] [PATCH 5/5] Fix review feedback Mark Gaiser
2022-01-31 15:46 ` Michael Niedermayer
2022-01-31 16:33 ` Mark Gaiser
2022-01-31 15:52 ` [FFmpeg-devel] [PATCH 0/5] Add IPFS and IPNS protocol support Tomas Härdin
2022-01-31 16:31 ` Mark Gaiser
2022-01-31 20:22 ` Tomas Härdin
2022-01-31 22:00 ` Mark Gaiser
2022-02-01 16:39 ` Tomas Härdin
2022-02-01 21:18 ` Mark Gaiser
2022-02-02 12:51 ` Tomas Härdin
2022-02-02 13:32 ` Mark Gaiser
2022-02-01 10:06 ` Michael Niedermayer
2022-02-01 16:43 ` Tomas Härdin
2022-02-02 13:48 ` Michael Niedermayer
2022-02-04 10:28 ` Tomas Härdin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220131135116.14035-4-markg85@gmail.com \
--to=markg85@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git