[FFmpeg-devel] [GSoC] Proof-of-concept HTTP Server

Nicolas George george at nsup.org
Sat Mar 28 11:20:48 CET 2015


Le septidi 7 germinal, an CCXXIII, Stephan Holljes a écrit :
> I just copied that from the line above, I was not aware of the meaning
> of the letter at all. Changed to "E".

D and E are short-cuts for AV_OPT_FLAG_DECODING_PARAM and
AV_OPT_FLAG_ENCODING_PARAM, that allows front-ends to filter options that
are not useful in a particular situation.

> > > +        av_dict_set(options, "listen", "1", AV_DICT_APPEND);
> > Are you sure about AV_DICT_APPEND?
> Not at all, it seemed like the flag I needed, but it also works with 0
> passed as a flag.

If the option was already present in the table as, maybe, "0", it would have
become "01". That would probably have worked, but just by happenstance.

> What do you mean with the full-duplex connection? Does
> AVIO_FLAG_READ_WRITE not create a read- and writeable socket?

I did not read carefully enough, sorry.

> This patch only adds the variables and options needed and only changes
> http_open().
> 
> I hope this time the use of an alternative mail-client does not corrupt
> it. Regardless, I attached it in case it does anyway.

It seems it was not mangled this time. Feel free to use any one of the
methods.

> Regards,
> Stephan Holljes
> 
> ---
>  doc/protocols.texi |  3 +++
>  libavformat/http.c | 21 +++++++++++++++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index 2a19b41..5b7b6cf 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -277,6 +277,9 @@ Set initial byte offset.
>  
>  @item end_offset
>  Try to limit the request to bytes preceding this offset.
> +
> + at item listen
> +If set to 1 enables experimental HTTP server.
>  @end table
>  
>  @subsection HTTP Cookies
> diff --git a/libavformat/http.c b/libavformat/http.c
> index da3c9be..989dc95 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -96,6 +96,7 @@ typedef struct HTTPContext {
>      int send_expect_100;
>      char *method;
>      int reconnect;
> +    int listen;
>  } HTTPContext;
>  
>  #define OFFSET(x) offsetof(HTTPContext, x)
> @@ -127,6 +128,7 @@ static const AVOption options[] = {
>      { "end_offset", "try to limit the request to bytes preceding this offset", OFFSET(end_off), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, D },
>      { "method", "Override the HTTP method", OFFSET(method), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
>      { "reconnect", "auto reconnect after disconnect before EOF", OFFSET(reconnect), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, D },
> +    { "listen", "listen on HTTP", OFFSET(listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, E },
>      { NULL }
>  };
>  
> @@ -321,6 +323,25 @@ static int http_open(URLContext *h, const char *uri, int flags,
>                     "No trailing CRLF found in HTTP header.\n");
>      }
>  
> +    if (s->listen) {

> +        char header[] = "HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nTransfer-Encoding: chunked\r\n\r\n";

"static const char header" -> you avoid copying the string to the stack at
each call.

> +        char hostname[1024];
> +        char lower_url[100];
> +        int port;
> +        av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
> +                     NULL, 0, uri);

> +        ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port,
> +                NULL);

Indentation looks off.


> +        av_dict_set(options, "listen", "1", 0);
> +        ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,
> +                         &h->interrupt_callback, options);
> +        if (ret < 0)
> +            return ret;
> +        ret = ffurl_write(s->hd, header, strlen(header));

> +        if (ret < 0)
> +            return ret;
> +        return 0;

That could be merged.

> +    }
>      ret = http_open_cnx(h, options);
>      if (ret < 0)
>          av_dict_free(&s->chained_options);

I suspect freeing chained_options should happen in case of failure for the
server mode too, otherwise it will leak.

Apart from that, it looks good. Of course, other developers may have
comments about it.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150328/b6cd715e/attachment.asc>


More information about the ffmpeg-devel mailing list