diff mbox

[FFmpeg-devel,1/2,1/2] avformat/http: add ff_http_do_new_request2() which supports options to be applied to HTTPContext after initialisation with the new uri

Message ID 20191004215602.5142-2-hello.vectronic@gmail.com
State Accepted
Commit e81c686a95b19966def357ccb113bd4e5e269772
Headers show

Commit Message

vectronic Oct. 4, 2019, 9:56 p.m. UTC
Signed-off-by: vectronic <hello.vectronic@gmail.com>
---
 libavformat/http.c |  8 +++++++-
 libavformat/http.h | 13 +++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

Comments

Liu Steven Oct. 8, 2019, 6:59 a.m. UTC | #1
> 在 2019年10月5日,05:56,vectronic <hello.vectronic@gmail.com> 写道:
> 
> Signed-off-by: vectronic <hello.vectronic@gmail.com>
> ---
> libavformat/http.c |  8 +++++++-
> libavformat/http.h | 13 +++++++++++++
> 2 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/http.c b/libavformat/http.c
> index 71dd6c2b1f..85cbd06092 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -320,8 +320,11 @@ int ff_http_get_shutdown_status(URLContext *h)
>     return ret;
> }
> 
> +int ff_http_do_new_request(URLContext *h, const char *uri) {
> +    return ff_http_do_new_request2(h, uri, NULL);
> +}
> 
> -int ff_http_do_new_request(URLContext *h, const char *uri)
> +int ff_http_do_new_request2(URLContext *h, const char *uri, AVDictionary **opts)
> {
>     HTTPContext *s = h->priv_data;
>     AVDictionary *options = NULL;
> @@ -366,6 +369,9 @@ int ff_http_do_new_request(URLContext *h, const char *uri)
>     if (!s->location)
>         return AVERROR(ENOMEM);
> 
> +    if ((ret = av_opt_set_dict(s, opts)) < 0)
> +        return ret;
> +
>     av_log(s, AV_LOG_INFO, "Opening \'%s\' for %s\n", uri, h->flags & AVIO_FLAG_WRITE ? "writing" : "reading");
>     ret = http_open_cnx(h, &options);
>     av_dict_free(&options);
> diff --git a/libavformat/http.h b/libavformat/http.h
> index 662bd2cab6..5557ce9b58 100644
> --- a/libavformat/http.h
> +++ b/libavformat/http.h
> @@ -56,6 +56,19 @@ int ff_http_get_shutdown_status(URLContext *h);
>  */
> int ff_http_do_new_request(URLContext *h, const char *uri);
> 
> +/**
> + * Send a new HTTP request, reusing the old connection.
> + *
> + * @param h pointer to the resource
> + * @param uri uri used to perform the request
> + * @param options  A dictionary filled with HTTP options. On return
> + * this parameter will be destroyed and replaced with a dict containing options
> + * that were not found. May be NULL.
> + * @return a negative value if an error condition occurred, 0
> + * otherwise
> + */
> +int ff_http_do_new_request2(URLContext *h, const char *uri, AVDictionary **options);
> +
> int ff_http_averror(int status_code, int default_averror);
> 
> #endif /* AVFORMAT_HTTP_H */
> -- 
> 2.21.0 (Apple Git-122)
> 
> _______________________________________________
> 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”.

Patchset lgtm and applied.

Thanks
Steven
diff mbox

Patch

diff --git a/libavformat/http.c b/libavformat/http.c
index 71dd6c2b1f..85cbd06092 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -320,8 +320,11 @@  int ff_http_get_shutdown_status(URLContext *h)
     return ret;
 }
 
+int ff_http_do_new_request(URLContext *h, const char *uri) {
+    return ff_http_do_new_request2(h, uri, NULL);
+}
 
-int ff_http_do_new_request(URLContext *h, const char *uri)
+int ff_http_do_new_request2(URLContext *h, const char *uri, AVDictionary **opts)
 {
     HTTPContext *s = h->priv_data;
     AVDictionary *options = NULL;
@@ -366,6 +369,9 @@  int ff_http_do_new_request(URLContext *h, const char *uri)
     if (!s->location)
         return AVERROR(ENOMEM);
 
+    if ((ret = av_opt_set_dict(s, opts)) < 0)
+        return ret;
+
     av_log(s, AV_LOG_INFO, "Opening \'%s\' for %s\n", uri, h->flags & AVIO_FLAG_WRITE ? "writing" : "reading");
     ret = http_open_cnx(h, &options);
     av_dict_free(&options);
diff --git a/libavformat/http.h b/libavformat/http.h
index 662bd2cab6..5557ce9b58 100644
--- a/libavformat/http.h
+++ b/libavformat/http.h
@@ -56,6 +56,19 @@  int ff_http_get_shutdown_status(URLContext *h);
  */
 int ff_http_do_new_request(URLContext *h, const char *uri);
 
+/**
+ * Send a new HTTP request, reusing the old connection.
+ *
+ * @param h pointer to the resource
+ * @param uri uri used to perform the request
+ * @param options  A dictionary filled with HTTP options. On return
+ * this parameter will be destroyed and replaced with a dict containing options
+ * that were not found. May be NULL.
+ * @return a negative value if an error condition occurred, 0
+ * otherwise
+ */
+int ff_http_do_new_request2(URLContext *h, const char *uri, AVDictionary **options);
+
 int ff_http_averror(int status_code, int default_averror);
 
 #endif /* AVFORMAT_HTTP_H */