Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v2] libavformat/data_uri: export mime_type of data urls
@ 2023-07-03 19:17 David Lou
  2023-09-05  8:27 ` David Lou
  2023-09-05  9:45 ` Anton Khirnov
  0 siblings, 2 replies; 3+ messages in thread
From: David Lou @ 2023-07-03 19:17 UTC (permalink / raw)
  To: ffmpeg-devel

Fix the fact that ffprobe no longer detects m3u8 in a data url correctly.

For example,

ffprobe data:application/vnd.apple.mpegurl;base64,I0VYVE0zVQojRVhULVgtVkVSU0lPTjozCiNFWFQtWC1UQVJHRVREVVJBVElPTjozMAojRVhUSU5GOjMwLApodHRwczovL2Rvd25sb2FkLnNhbXBsZWxpYi5jb20vbXA0L3NhbXBsZS0zMHMubXA0

This provides the mime_type hls detection requires.

Thank you.

Hopefully this patch doesn't get truncated by email again.

Signed-off-by: David Lou <morphological.arts@gmail.com>
---
 libavformat/data_uri.c | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/libavformat/data_uri.c b/libavformat/data_uri.c
index 28eb2b9e08..fdc1a2eef9 100644
--- a/libavformat/data_uri.c
+++ b/libavformat/data_uri.c
@@ -19,18 +19,24 @@
  */
 
 #include <string.h>
+
 #include "libavutil/avstring.h"
 #include "libavutil/avutil.h"
 #include "libavutil/base64.h"
+#include "libavutil/opt.h"
+
 #include "url.h"
 
 typedef struct {
+    const AVClass *class;
     const uint8_t *data;
     void *tofree;
     size_t size;
     size_t pos;
+    char *mime_type;
 } DataContext;
 
+
 static av_cold int data_open(URLContext *h, const char *uri, int flags)
 {
     DataContext *dc = h->priv_data;
@@ -56,8 +62,10 @@ static av_cold int data_open(URLContext *h, const char *uri, int flags)
                        (int)(next - opt), opt);
                 return AVERROR(EINVAL);
             }
-            av_log(h, AV_LOG_VERBOSE, "Content-type: %.*s\n",
-                   (int)(next - opt), opt);
+            av_free(dc->mime_type);
+            dc->mime_type = av_strndup(opt, (int)(next - opt));
+            av_log(h, AV_LOG_VERBOSE, "Content-type: %s\n",
+                   dc->mime_type);
         } else {
             if (!av_strncasecmp(opt, "base64", next - opt)) {
                 base64 = 1;
@@ -110,10 +118,25 @@ static int data_read(URLContext *h, unsigned char *buf, int size)
     return size;
 }
 
+#define OFFSET(x) offsetof(DataContext, x)
+
+static const AVOption options[] = {
+    { "mime_type", "export the MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
+    { NULL }
+};
+
+static const AVClass data_context_class = {
+    .class_name = "data",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 const URLProtocol ff_data_protocol = {
-    .name           = "data",
-    .url_open       = data_open,
-    .url_close      = data_close,
-    .url_read       = data_read,
-    .priv_data_size = sizeof(DataContext),
+    .name               = "data",
+    .url_open           = data_open,
+    .url_close          = data_close,
+    .url_read           = data_read,
+    .priv_data_size     = sizeof(DataContext),
+    .priv_data_class    = &data_context_class,
 };
-- 
2.41.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] libavformat/data_uri: export mime_type of data urls
  2023-07-03 19:17 [FFmpeg-devel] [PATCH v2] libavformat/data_uri: export mime_type of data urls David Lou
@ 2023-09-05  8:27 ` David Lou
  2023-09-05  9:45 ` Anton Khirnov
  1 sibling, 0 replies; 3+ messages in thread
From: David Lou @ 2023-09-05  8:27 UTC (permalink / raw)
  To: ffmpeg-devel

ping

On Tue, Jul 4, 2023 at 3:17 AM David Lou <morphological.arts@gmail.com>
wrote:

> Fix the fact that ffprobe no longer detects m3u8 in a data url correctly.
>
> For example,
>
> ffprobe
> data:application/vnd.apple.mpegurl;base64,I0VYVE0zVQojRVhULVgtVkVSU0lPTjozCiNFWFQtWC1UQVJHRVREVVJBVElPTjozMAojRVhUSU5GOjMwLApodHRwczovL2Rvd25sb2FkLnNhbXBsZWxpYi5jb20vbXA0L3NhbXBsZS0zMHMubXA0
>
> This provides the mime_type hls detection requires.
>
> Thank you.
>
> Hopefully this patch doesn't get truncated by email again.
>
> Signed-off-by: David Lou <morphological.arts@gmail.com>
> ---
>  libavformat/data_uri.c | 37 ++++++++++++++++++++++++++++++-------
>  1 file changed, 30 insertions(+), 7 deletions(-)
>
> diff --git a/libavformat/data_uri.c b/libavformat/data_uri.c
> index 28eb2b9e08..fdc1a2eef9 100644
> --- a/libavformat/data_uri.c
> +++ b/libavformat/data_uri.c
> @@ -19,18 +19,24 @@
>   */
>
>  #include <string.h>
> +
>  #include "libavutil/avstring.h"
>  #include "libavutil/avutil.h"
>  #include "libavutil/base64.h"
> +#include "libavutil/opt.h"
> +
>  #include "url.h"
>
>  typedef struct {
> +    const AVClass *class;
>      const uint8_t *data;
>      void *tofree;
>      size_t size;
>      size_t pos;
> +    char *mime_type;
>  } DataContext;
>
> +
>  static av_cold int data_open(URLContext *h, const char *uri, int flags)
>  {
>      DataContext *dc = h->priv_data;
> @@ -56,8 +62,10 @@ static av_cold int data_open(URLContext *h, const char
> *uri, int flags)
>                         (int)(next - opt), opt);
>                  return AVERROR(EINVAL);
>              }
> -            av_log(h, AV_LOG_VERBOSE, "Content-type: %.*s\n",
> -                   (int)(next - opt), opt);
> +            av_free(dc->mime_type);
> +            dc->mime_type = av_strndup(opt, (int)(next - opt));
> +            av_log(h, AV_LOG_VERBOSE, "Content-type: %s\n",
> +                   dc->mime_type);
>          } else {
>              if (!av_strncasecmp(opt, "base64", next - opt)) {
>                  base64 = 1;
> @@ -110,10 +118,25 @@ static int data_read(URLContext *h, unsigned char
> *buf, int size)
>      return size;
>  }
>
> +#define OFFSET(x) offsetof(DataContext, x)
> +
> +static const AVOption options[] = {
> +    { "mime_type", "export the MIME type", OFFSET(mime_type),
> AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_EXPORT |
> AV_OPT_FLAG_READONLY },
> +    { NULL }
> +};
> +
> +static const AVClass data_context_class = {
> +    .class_name = "data",
> +    .item_name  = av_default_item_name,
> +    .option     = options,
> +    .version    = LIBAVUTIL_VERSION_INT,
> +};
> +
>  const URLProtocol ff_data_protocol = {
> -    .name           = "data",
> -    .url_open       = data_open,
> -    .url_close      = data_close,
> -    .url_read       = data_read,
> -    .priv_data_size = sizeof(DataContext),
> +    .name               = "data",
> +    .url_open           = data_open,
> +    .url_close          = data_close,
> +    .url_read           = data_read,
> +    .priv_data_size     = sizeof(DataContext),
> +    .priv_data_class    = &data_context_class,
>  };
> --
> 2.41.0
>
>
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] libavformat/data_uri: export mime_type of data urls
  2023-07-03 19:17 [FFmpeg-devel] [PATCH v2] libavformat/data_uri: export mime_type of data urls David Lou
  2023-09-05  8:27 ` David Lou
@ 2023-09-05  9:45 ` Anton Khirnov
  1 sibling, 0 replies; 3+ messages in thread
From: Anton Khirnov @ 2023-09-05  9:45 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Quoting David Lou (2023-07-03 21:17:40)
> Fix the fact that ffprobe no longer detects m3u8 in a data url correctly.
> 
> For example,
> 
> ffprobe data:application/vnd.apple.mpegurl;base64,I0VYVE0zVQojRVhULVgtVkVSU0lPTjozCiNFWFQtWC1UQVJHRVREVVJBVElPTjozMAojRVhUSU5GOjMwLApodHRwczovL2Rvd25sb2FkLnNhbXBsZWxpYi5jb20vbXA0L3NhbXBsZS0zMHMubXA0
> 
> This provides the mime_type hls detection requires.
> 
> Thank you.
> 
> Hopefully this patch doesn't get truncated by email again.
> 
> Signed-off-by: David Lou <morphological.arts@gmail.com>
> ---
>  libavformat/data_uri.c | 37 ++++++++++++++++++++++++++++++-------
>  1 file changed, 30 insertions(+), 7 deletions(-)
> 
> diff --git a/libavformat/data_uri.c b/libavformat/data_uri.c
> index 28eb2b9e08..fdc1a2eef9 100644
> --- a/libavformat/data_uri.c
> +++ b/libavformat/data_uri.c
> @@ -19,18 +19,24 @@
>   */
>  
>  #include <string.h>
> +

Spurious extra line. Same below DataContext.

>  #include "libavutil/avstring.h"
>  #include "libavutil/avutil.h"
>  #include "libavutil/base64.h"
> +#include "libavutil/opt.h"
> +
>  #include "url.h"
>  
>  typedef struct {
> +    const AVClass *class;
>      const uint8_t *data;
>      void *tofree;
>      size_t size;
>      size_t pos;
> +    char *mime_type;
>  } DataContext;
>  
> +
>  static av_cold int data_open(URLContext *h, const char *uri, int flags)
>  {
>      DataContext *dc = h->priv_data;
> @@ -56,8 +62,10 @@ static av_cold int data_open(URLContext *h, const char *uri, int flags)
>                         (int)(next - opt), opt);
>                  return AVERROR(EINVAL);
>              }
> -            av_log(h, AV_LOG_VERBOSE, "Content-type: %.*s\n",
> -                   (int)(next - opt), opt);
> +            av_free(dc->mime_type);
> +            dc->mime_type = av_strndup(opt, (int)(next - opt));

You need to check the result for NULL and return AVERROR(ENOMEM) on
failure.

A FATE test would be very nice.

-- 
Anton Khirnov
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-05  9:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 19:17 [FFmpeg-devel] [PATCH v2] libavformat/data_uri: export mime_type of data urls David Lou
2023-09-05  8:27 ` David Lou
2023-09-05  9:45 ` Anton Khirnov

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