[FFmpeg-devel] [PATCH 09/10] lavf/file: handle standard file:// URLs.

Marton Balint cus at passwd.hu
Tue Jul 27 23:56:31 EEST 2021



On Tue, 27 Jul 2021, Nicolas George wrote:

> Signed-off-by: Nicolas George <george at nsup.org>
> ---
> libavformat/file.c | 54 +++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 53 insertions(+), 1 deletion(-)

You should mention the relevant rfc - RFC8089.

Also there are a couple of common deviations/extensions from the 
normative standard, referenced in the RFC:

https://datatracker.ietf.org/doc/html/rfc8089#appendix-F

Do you plan to support those?

>
> diff --git a/libavformat/file.c b/libavformat/file.c
> index 2fb93c23fd..82d9e7bab4 100644
> --- a/libavformat/file.c
> +++ b/libavformat/file.c
> @@ -20,6 +20,7 @@
>  */
>
> #include "libavutil/avstring.h"
> +#include "libavutil/bprint.h"
> #include "libavutil/internal.h"
> #include "libavutil/opt.h"
> #include "avformat.h"
> @@ -355,10 +356,61 @@ static int file_close_dir(URLContext *h)
>
> #if CONFIG_FILE_PROTOCOL
>
> +/**
> + * De-escape %hh. Return 0 if no de-escaping needed.
> + */
> +static int url_de_escape(void *log, const char *filename, AVBPrint *out)
> +{
> +    const char *in;
> +
> +    for (in = filename; *in; in++)
> +        if (*in == '%' || *in == '#' || *in == '?')
> +            break;
> +    if (!*in)
> +        return 0;
> +    for (in = filename; *in; in++) {
> +        if (*in == '#' || *in == '?')
> +            break;
> +        if (*in == '%') {
> +            int a = ff_hexpair2int(in + 1);
> +            if (a < 0) {
> +                av_log(log, AV_LOG_ERROR, "Invalid %% char in URL.\n");
> +                return AVERROR(EINVAL);
> +            }
> +            av_bprint_chars(out, a, 1);
> +            in += 2;
> +        } else {
> +            av_bprint_chars(out, *in, 1);
> +        }
> +    }
> +    if (!av_bprint_is_complete(out))
> +        return AVERROR(ENOMEM);
> +    return 1;
> +}
> +
> static int file_open(URLContext *h, const char *filename, int flags)
> {
> +    AVBPrint decoded;
> +    int ret;
> +
>     av_strstart(filename, "file:", &filename);
> -    return file_open_common(h, filename, flags);
> +    av_bprint_init(&decoded, 1, AV_BPRINT_SIZE_UNLIMITED);
> +    if (filename[0] == '/' && filename[1] == '/' && filename[2] == '/') {
> +        filename += 2;
> +        ret = url_de_escape(h, filename, &decoded);
> +        if (ret < 0) {
> +            av_bprint_finalize(&decoded, NULL);
> +            return ret;
> +        }
> +        if (ret)
> +            filename = decoded.str;
> +    } else {
> +        av_log(h, AV_LOG_WARNING,
> +               "'file:path' is deprecated, use 'fs:path' or a standard 'file:///' URL\n");

Well, I guess this is needed for compatiblity, but as far as I see, the 
RFC supports the minimal repepresentation of local file path, so RFC-wise 
this is also valid. So what is the plan here? We will do unescaping and 
remove the deperecation message somewhere in the future?

What about the file://host/file syntax which - at least on Windows - 
should be transformed to //host/file?

Also the question of relative resolution comes to mind, there is some code 
in libavformat/url.c which also handles file path specially, that should 
also be updated, right?

Thanks,
Marton

> +    }
> +    ret = file_open_common(h, filename, flags);
> +    av_bprint_finalize(&decoded, NULL);
> +    return ret;
> }
>
> const URLProtocol ff_file_protocol = {
> -- 
> 2.30.2
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>


More information about the ffmpeg-devel mailing list