diff mbox

[FFmpeg-devel,1/2] avformat/http: Added a library-internal API for signalling end of chunk

Message ID 1513926282-21191-1-git-send-email-kjeyapal@akamai.com
State New
Headers show

Commit Message

Jeyapal, Karthick Dec. 22, 2017, 7:04 a.m. UTC
From: Karthick Jeyapal <kjeyapal@akamai.com>

Right now there is no explicit way to signal end of chunk, when http_multiple is set.
ff_http_do_new_request() function implicitly signals end of chunk. But that could be too late for certain applications.
Hence added a new function ff_http_signal_end_of_chunk() which could be used internally within libavformat.
---
 libavformat/http.c | 17 ++++++++++++++---
 libavformat/http.h |  9 +++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)

Comments

wm4 Dec. 22, 2017, 7:43 a.m. UTC | #1
On Fri, 22 Dec 2017 12:34:41 +0530
Karthick J <kjeyapal@akamai.com> wrote:

> From: Karthick Jeyapal <kjeyapal@akamai.com>
> 
> Right now there is no explicit way to signal end of chunk, when http_multiple is set.
> ff_http_do_new_request() function implicitly signals end of chunk. But that could be too late for certain applications.
> Hence added a new function ff_http_signal_end_of_chunk() which could be used internally within libavformat.
> ---
>  libavformat/http.c | 17 ++++++++++++++---
>  libavformat/http.h |  9 +++++++++
>  2 files changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/http.c b/libavformat/http.c
> index cf86adc..d8224de 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -307,9 +307,11 @@ int ff_http_do_new_request(URLContext *h, const char *uri)
>      AVDictionary *options = NULL;
>      int ret;
>  
> -    ret = http_shutdown(h, h->flags);
> -    if (ret < 0)
> -        return ret;
> +    if (!s->end_chunked_post) {
> +        ret = http_shutdown(h, h->flags);
> +        if (ret < 0)
> +            return ret;
> +    }
>  
>      s->end_chunked_post = 0;
>      s->chunkend      = 0;
> @@ -325,6 +327,15 @@ int ff_http_do_new_request(URLContext *h, const char *uri)
>      return ret;
>  }
>  
> +int ff_http_signal_end_of_chunk(URLContext *h) {
> +    HTTPContext *s = h->priv_data;
> +    int ret = 0;
> +    if (!s->end_chunked_post) {
> +        ret = http_shutdown(h, h->flags);
> +    }
> +    return ret;
> +}
> +
>  int ff_http_averror(int status_code, int default_averror)
>  {
>      switch (status_code) {
> diff --git a/libavformat/http.h b/libavformat/http.h
> index 7d02713..0eaeb48 100644
> --- a/libavformat/http.h
> +++ b/libavformat/http.h
> @@ -47,6 +47,15 @@ void ff_http_init_auth_state(URLContext *dest, const URLContext *src);
>   */
>  int ff_http_do_new_request(URLContext *h, const char *uri);
>  
> +/**
> + * Send a end of chunk signal(sends a string "0\r\n\r\n"), if applicable.
> + *
> + * @param h pointer to the resource
> + * @return a negative value if an error condition occurred, 0
> + * otherwise
> + */
> +int ff_http_signal_end_of_chunk(URLContext *h);
> +
>  int ff_http_averror(int status_code, int default_averror);
>  
>  #endif /* AVFORMAT_HTTP_H */

I'd really prefer if this HTTP stuff would be added in a much cleaner
way, such as making it part of the AVIO API, or at least the
URLContext API. (Why are there 2 APIs anyway...)
Jeyapal, Karthick Dec. 22, 2017, 8:47 a.m. UTC | #2
On 12/22/17, 1:13 PM, "wm4" <nfxjfg@googlemail.com> wrote:
>

>On Fri, 22 Dec 2017 12:34:41 +0530

>Karthick J <kjeyapal@akamai.com> wrote:

>

>> From: Karthick Jeyapal <kjeyapal@akamai.com>

>> 

>> Right now there is no explicit way to signal end of chunk, when http_multiple is set.

>> ff_http_do_new_request() function implicitly signals end of chunk. But that could be too late for certain applications.

>> Hence added a new function ff_http_signal_end_of_chunk() which could be used internally within libavformat.

>> ---

>>[…]

>

>I'd really prefer if this HTTP stuff would be added in a much cleaner

>way, such as making it part of the AVIO API, or at least the

>URLContext API. (Why are there 2 APIs anyway...)


Thanks for your comments. 
I am now using the ffurl* API as you suggested, in the new patch v2.

Regards,
Karthick
diff mbox

Patch

diff --git a/libavformat/http.c b/libavformat/http.c
index cf86adc..d8224de 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -307,9 +307,11 @@  int ff_http_do_new_request(URLContext *h, const char *uri)
     AVDictionary *options = NULL;
     int ret;
 
-    ret = http_shutdown(h, h->flags);
-    if (ret < 0)
-        return ret;
+    if (!s->end_chunked_post) {
+        ret = http_shutdown(h, h->flags);
+        if (ret < 0)
+            return ret;
+    }
 
     s->end_chunked_post = 0;
     s->chunkend      = 0;
@@ -325,6 +327,15 @@  int ff_http_do_new_request(URLContext *h, const char *uri)
     return ret;
 }
 
+int ff_http_signal_end_of_chunk(URLContext *h) {
+    HTTPContext *s = h->priv_data;
+    int ret = 0;
+    if (!s->end_chunked_post) {
+        ret = http_shutdown(h, h->flags);
+    }
+    return ret;
+}
+
 int ff_http_averror(int status_code, int default_averror)
 {
     switch (status_code) {
diff --git a/libavformat/http.h b/libavformat/http.h
index 7d02713..0eaeb48 100644
--- a/libavformat/http.h
+++ b/libavformat/http.h
@@ -47,6 +47,15 @@  void ff_http_init_auth_state(URLContext *dest, const URLContext *src);
  */
 int ff_http_do_new_request(URLContext *h, const char *uri);
 
+/**
+ * Send a end of chunk signal(sends a string "0\r\n\r\n"), if applicable.
+ *
+ * @param h pointer to the resource
+ * @return a negative value if an error condition occurred, 0
+ * otherwise
+ */
+int ff_http_signal_end_of_chunk(URLContext *h);
+
 int ff_http_averror(int status_code, int default_averror);
 
 #endif /* AVFORMAT_HTTP_H */