On Mon, Mar 30, 2015 at 5:19 PM, Nicolas George <geo...@nsup.org> wrote:
> Le nonidi 9 germinal, an CCXXIII, Stephan Holljes a écrit :
>> I hope this addresses the issues mentioned.
>> I added a new label in case of failure in http_open() in favor of
>> duplicated code (i.e. calling av_dict_free() multiple times). I copied
>> the style from the other functions.
>>
>> Signed-off-by: Stephan Holljes <klaxa1...@googlemail.com>
>
> The patch looks good to me (acronym to learn: LGTM) as is or with the code
> moved into a separate function point.
>
> Except one more point that was not addressed earlier: if you want to add
> comments to a Git patch email, you need to put them between the "---" and
> the first "diff --git" lines. That is where the small stats "2 files
> changed, 28 insertions(+), 1 deletion(-)" is already inserted, it is
> considered as a simple comment too.
>
> If you put them before the "---" line, it becomes part of the commit message
> when the patch is applied from the mail. For the final version, maybe better
> attach the patch or push it to a public clone.
>
> At this point, I suspect you can consider this will be applied soon (better
> give it maybe two days before asking for merging) and, if you want to
> strengthen your application, make the patch even better, for example getting
> it to work for input as well as output.

How would http listening work as an input option?

>
> For that, I suspect it will be convenient for you to isolate the code in its
> own function, that makes handling the variables and the failure code path
> easier, so you probably better follow wm4's advice.
>
> Regards,
>
> --
>   Nicolas George
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

I moved the functionality opening the listening socket to a new function.
The patch is attached.
Sorry for the late reply, I had exams.

Regards,
Stephan Holljes
From c01ec773448a76485895171cbfb296657d56da97 Mon Sep 17 00:00:00 2001
From: Stephan Holljes <klaxa1...@googlemail.com>
Date: Thu, 2 Apr 2015 22:49:07 +0200
Subject: [PATCH] libavformat/http.c: Add proof-of-concept http server.

Signed-off-by: Stephan Holljes <klaxa1...@googlemail.com>
---
 doc/protocols.texi |  3 +++
 libavformat/http.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 34 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.
+
+@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 45533e4..3276737 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 }
 };
 
@@ -296,6 +298,31 @@ int ff_http_averror(int status_code, int default_averror)
         return default_averror;
 }
 
+static int http_listen(URLContext *h, const char *uri, int flags,
+                       AVDictionary **options) {
+    HTTPContext *s = h->priv_data;
+    int ret;
+    static const char header[] = "HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nTransfer-Encoding: chunked\r\n\r\n";
+    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);
+    av_dict_set(options, "listen", "1", 0);
+    if (ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,
+                         &h->interrupt_callback, options) < 0)
+        goto fail;
+    if (ret = ffurl_write(s->hd, header, strlen(header)) < 0)
+        goto fail;
+    return 0;
+
+fail:
+    av_dict_free(&s->chained_options);
+    return ret;
+}
+
 static int http_open(URLContext *h, const char *uri, int flags,
                      AVDictionary **options)
 {
@@ -321,12 +348,16 @@ static int http_open(URLContext *h, const char *uri, int flags,
                    "No trailing CRLF found in HTTP header.\n");
     }
 
+    if (s->listen) {
+        return http_listen(h, uri, flags, options);
+    }
     ret = http_open_cnx(h, options);
     if (ret < 0)
         av_dict_free(&s->chained_options);
     return ret;
 }
 
+
 static int http_getc(HTTPContext *s)
 {
     int len;
-- 
2.3.3

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to