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

2015-04-02 Thread Stephan Holljes
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)

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

2015-03-30 Thread Nicolas George
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.

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


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2015-03-29 Thread wm4
On Sun, 29 Mar 2015 04:13:18 +0200
Stephan Holljes klaxa1...@googlemail.com wrote:

 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
 ---
  doc/protocols.texi |  3 +++
  libavformat/http.c | 26 +-
  2 files changed, 28 insertions(+), 1 deletion(-)
 
 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 da3c9be..c769918 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,9 +323,31 @@ static int http_open(URLContext *h, const char *uri, int 
 flags,
 No trailing CRLF found in HTTP header.\n);
  }
  
 +if (s-listen) {
 +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);
 +ret = ffurl_open(s-hd, lower_url, AVIO_FLAG_READ_WRITE,
 + h-interrupt_callback, options);
 +if (ret  0)
 +goto fail;
 +if (ret = ffurl_write(s-hd, header, strlen(header))  0)
 +goto fail;
 +return 0;
 +}
  ret = http_open_cnx(h, options);
  if (ret  0)
 -av_dict_free(s-chained_options);
 +goto fail;
 +return ret;
 +
 +fail:
 +av_dict_free(s-chained_options);
  return ret;
  }
  

Maybe this should be in a separate function at least.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2015-03-28 Thread Stephan Holljes
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
---
 doc/protocols.texi |  3 +++
 libavformat/http.c | 26 +-
 2 files changed, 28 insertions(+), 1 deletion(-)

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 da3c9be..c769918 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,9 +323,31 @@ static int http_open(URLContext *h, const char *uri, int 
flags,
No trailing CRLF found in HTTP header.\n);
 }
 
+if (s-listen) {
+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);
+ret = ffurl_open(s-hd, lower_url, AVIO_FLAG_READ_WRITE,
+ h-interrupt_callback, options);
+if (ret  0)
+goto fail;
+if (ret = ffurl_write(s-hd, header, strlen(header))  0)
+goto fail;
+return 0;
+}
 ret = http_open_cnx(h, options);
 if (ret  0)
-av_dict_free(s-chained_options);
+goto fail;
+return ret;
+
+fail:
+av_dict_free(s-chained_options);
 return ret;
 }
 
-- 
2.3.3
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2015-03-25 Thread Stephan Holljes
I hope this time the patch is formatted correctly. I also attached it
in case it is corrupted again.
I changed the indentation of the code and used ffurl_open() instead of
creating my own listening socket.

I am still having some trouble with the Content-Type header. I would
guess creating functions like http_write_header() as the counterpart
for http_read_header() would be the most appropriate approach?


---
 libavformat/http.c | 33 -
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index da3c9be..472d8dd 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -96,6 +96,8 @@ typedef struct HTTPContext {
 int send_expect_100;
 char *method;
 int reconnect;
+int listen;
+int header_sent;
 } HTTPContext;

 #define OFFSET(x) offsetof(HTTPContext, x)
@@ -127,6 +129,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, D },
 { NULL }
 };

@@ -300,7 +303,9 @@ static int http_open(URLContext *h, const char
*uri, int flags,
  AVDictionary **options)
 {
 HTTPContext *s = h-priv_data;
-int ret;
+int port, ret = 0;
+char hostname[1024];
+char lower_url[100];

 if( s-seekable == 1 )
 h-is_streamed = 0;
@@ -321,6 +326,20 @@ static int http_open(URLContext *h, const char
*uri, int flags,
No trailing CRLF found in HTTP header.\n);
 }

+if (s-listen) {
+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, AV_DICT_APPEND);
+ret = ffurl_open(s-hd, lower_url, AVIO_FLAG_READ_WRITE,
+   h-interrupt_callback, options);
+if (ret  0) {
+return ret;
+}
+
+return ret;
+}
 ret = http_open_cnx(h, options);
 if (ret  0)
 av_dict_free(s-chained_options);
@@ -1100,10 +1119,22 @@ static int http_read(URLContext *h, uint8_t
*buf, int size)
 static int http_write(URLContext *h, const uint8_t *buf, int size)
 {
 char temp[11] = ;  /* 32-bit hex + CRLF + nul */
+char header[] = HTTP 200 OK\r\nContent-Type:
application/octet-stream\r\n\r\n;
 int ret;
 char crlf[] = \r\n;
 HTTPContext *s = h-priv_data;
+if (s-listen) {
+if (!s-header_sent) {
+ret = ffurl_write(s-hd, header, strlen(header));
+if (ret  0) {
+return ff_neterrno();
+}
+s-header_sent = 1;
+}

+ret = ffurl_write(s-hd, buf, size);
+return ret  0 ? ff_neterrno() : ret;
+}
 if (!s-chunked_post) {
 /* non-chunked data is sent without any special encoding */
 return ffurl_write(s-hd, buf, size);
-- 
2.3.3

On Sun, Mar 22, 2015 at 10:33 AM, Nicolas George geo...@nsup.org wrote:
 Le primidi 1er germinal, an CCXXIII, Stephan Holljes a écrit :
 Please comment.

 As Michael pointed out, the patch was mangled at sending. That happens with
 mail user agent that rely on rich text editor and do not let users control
 the formatting finely. Using git send-email or attaching the file will solve
 the problem. They also include authorship and date information.


 Regards,
 Stephan Holljes

 ---
  libavformat/http.c |  113
 ++--
  1 file changed, 83 insertions(+), 30 deletions(-)

 diff --git a/libavformat/http.c b/libavformat/http.c
 index da3c9be..d61e4e2 100644
 --- a/libavformat/http.c
 +++ b/libavformat/http.c
 @@ -96,8 +96,12 @@ typedef struct HTTPContext {
  int send_expect_100;
  char *method;
  int reconnect;
 +int listen;
 +int fd;
 +int header_sent;
  } HTTPContext;

 +
  #define OFFSET(x) offsetof(HTTPContext, x)
  #define D AV_OPT_FLAG_DECODING_PARAM
  #define E AV_OPT_FLAG_ENCODING_PARAM
 @@ -127,6 +131,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, D },
  { NULL }
  };

 @@ -299,8 +304,10 @@ int ff_http_averror(int 

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

2015-03-22 Thread Nicolas George
Le primidi 1er germinal, an CCXXIII, Stephan Holljes a écrit :
 Please comment.

As Michael pointed out, the patch was mangled at sending. That happens with
mail user agent that rely on rich text editor and do not let users control
the formatting finely. Using git send-email or attaching the file will solve
the problem. They also include authorship and date information.

 
 Regards,
 Stephan Holljes
 
 ---
  libavformat/http.c |  113
 ++--
  1 file changed, 83 insertions(+), 30 deletions(-)
 
 diff --git a/libavformat/http.c b/libavformat/http.c
 index da3c9be..d61e4e2 100644
 --- a/libavformat/http.c
 +++ b/libavformat/http.c
 @@ -96,8 +96,12 @@ typedef struct HTTPContext {
  int send_expect_100;
  char *method;
  int reconnect;
 +int listen;
 +int fd;
 +int header_sent;
  } HTTPContext;
 
 +
  #define OFFSET(x) offsetof(HTTPContext, x)
  #define D AV_OPT_FLAG_DECODING_PARAM
  #define E AV_OPT_FLAG_ENCODING_PARAM
 @@ -127,6 +131,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, D },
  { NULL }
  };
 
 @@ -299,8 +304,10 @@ int ff_http_averror(int status_code, int
 default_averror)
  static int http_open(URLContext *h, const char *uri, int flags,
   AVDictionary **options)
  {
 +struct addrinfo hints = { 0 }, *ai;
  HTTPContext *s = h-priv_data;
 -int ret;
 +int ret = -1, fd;
 +char portstr[] = 8080; // allow non-root users for now
 
  if( s-seekable == 1 )
  h-is_streamed = 0;
 @@ -320,11 +327,39 @@ static int http_open(URLContext *h, const char *uri,
 int flags,
  av_log(h, AV_LOG_WARNING,
 No trailing CRLF found in HTTP header.\n);
  }

 +if (s-listen) {
 +hints.ai_family = AF_UNSPEC;
 +hints.ai_socktype = SOCK_STREAM;
 +hints.ai_flags |= AI_PASSIVE;
 +ret = getaddrinfo(NULL, portstr, hints, ai);
 +if (ret) {
 +av_log(h, AV_LOG_ERROR, borked);
 +return AVERROR(EIO);
 +}
 +fd = ff_socket(ai-ai_family,
 +   ai-ai_socktype,
 +   ai-ai_protocol);
 +if (fd  0) {
 +ret = ff_neterrno();
 +freeaddrinfo(ai);
 +return -1;
 +}

This part looks copied from tcp.c. It would be much better to use the API
provided by TCP. In other words, just like the client part does:

err = ffurl_open(s-hd, buf, AVIO_FLAG_READ_WRITE,
 h-interrupt_callback, options);

you should do the same thing for creating the listening socket, just adding
the listen option. There are several reasons for doing that.

First, you avoid reimplementing all the interrupt_callback logic and cie,
which would be necessary for a complete implementation.

Second, this code with getaddrinfo is slightly wrong (wrt multi-protocol
hosts), so when it gets fixed in tcp.c, it would benefit to all the code.

 
 -ret = http_open_cnx(h, options);
 -if (ret  0)
 -av_dict_free(s-chained_options);
 -return ret;
 +fd = ff_listen_bind(fd, ai-ai_addr, ai-ai_addrlen, -1, h);
 +if (fd  0) {
 +freeaddrinfo(ai);
 +return fd;
 +}
 +h-is_streamed = 1;
 +s-fd = fd;
 +freeaddrinfo(ai);
 +return 0;
 +} else {
 +ret = http_open_cnx(h, options);
 +if (ret  0)
 +av_dict_free(s-chained_options);
 +return ret;
 +}
  }
 
  static int http_getc(HTTPContext *s)
 @@ -1102,25 +1137,40 @@ static int http_write(URLContext *h, const uint8_t
 *buf, int size)
  char temp[11] = ;  /* 32-bit hex + CRLF + nul */
  int ret;
  char crlf[] = \r\n;
 +char header[] = HTTP 200 OK\r\n\r\n;
  HTTPContext *s = h-priv_data;
 +if (!s-listen) {
 +if (!s-chunked_post) {
 +/* non-chunked data is sent without any special encoding */
 +return ffurl_write(s-hd, buf, size);
 +}
 
 -if (!s-chunked_post) {
 -/* non-chunked data is sent without any special encoding */
 -return ffurl_write(s-hd, buf, size);
 -}
 -
 -/* silently ignore zero-size data since chunk encoding that would
 - * signal EOF */
 -if (size  0) {
 -/* upload data using chunked encoding */
 -snprintf(temp, sizeof(temp), %x\r\n, size);
 +/* silently ignore zero-size data since chunk encoding that would
 + * signal EOF */
 +if (size  0) {
 +/* upload 

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

2015-03-21 Thread Stephan Holljes
Hi,

what would be the correct way to create patches that won't be corrupted? I
merely tried to copy what I have seen on the mailing-list before,
apparently I didn't do a very good job ;)

Regards,
Stephan Holljes

On Sun, Mar 22, 2015 at 12:24 AM, Michael Niedermayer michae...@gmx.at
wrote:

 On Sat, Mar 21, 2015 at 11:00:09PM +0100, Stephan Holljes wrote:
  Hi,
 
  this is a patch for a proof-of-concept for an http server.
 
  Usage on the server side:
 
  ffmpeg -i test.mp3 -c copy -listen 1 -f mp3 http://0.0.0.0
 
  Usage on the client side:
 
  ffplay http://localhost:8080
 
  I looked at tls.c and tcp.c and copied parts of the code.
  Please comment.
 
  Regards,
  Stephan Holljes
 
  ---
   libavformat/http.c |  113
  ++--
   1 file changed, 83 insertions(+), 30 deletions(-)
 
  diff --git a/libavformat/http.c b/libavformat/http.c
  index da3c9be..d61e4e2 100644
  --- a/libavformat/http.c
  +++ b/libavformat/http.c
  @@ -96,8 +96,12 @@ typedef struct HTTPContext {
   int send_expect_100;
   char *method;
   int reconnect;
  +int listen;
  +int fd;
  +int header_sent;
   } HTTPContext;
 
  +
   #define OFFSET(x) offsetof(HTTPContext, x)
   #define D AV_OPT_FLAG_DECODING_PARAM
   #define E AV_OPT_FLAG_ENCODING_PARAM
  @@ -127,6 +131,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, D },

 it appears this patch has been corrupted by extra newlines from
 word/line wrap

 please resend as an attachment

 [...]
 --
 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

 Breaking DRM is a little like attempting to break through a door even
 though the window is wide open and the only thing in the house is a bunch
 of things you dont want and which you would get tomorrow for free anyway

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


diff --git a/libavformat/http.c b/libavformat/http.c
index da3c9be..d61e4e2 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -96,8 +96,12 @@ typedef struct HTTPContext {
 int send_expect_100;
 char *method;
 int reconnect;
+int listen;
+int fd;
+int header_sent;
 } HTTPContext;
 
+
 #define OFFSET(x) offsetof(HTTPContext, x)
 #define D AV_OPT_FLAG_DECODING_PARAM
 #define E AV_OPT_FLAG_ENCODING_PARAM
@@ -127,6 +131,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, D },
 { NULL }
 };
 
@@ -299,8 +304,10 @@ int ff_http_averror(int status_code, int default_averror)
 static int http_open(URLContext *h, const char *uri, int flags,
  AVDictionary **options)
 {
+struct addrinfo hints = { 0 }, *ai;
 HTTPContext *s = h-priv_data;
-int ret;
+int ret = -1, fd;
+char portstr[] = 8080; // allow non-root users for now
 
 if( s-seekable == 1 )
 h-is_streamed = 0;
@@ -320,11 +327,39 @@ static int http_open(URLContext *h, const char *uri, int flags,
 av_log(h, AV_LOG_WARNING,
No trailing CRLF found in HTTP header.\n);
 }
+if (s-listen) {
+hints.ai_family = AF_UNSPEC;
+hints.ai_socktype = SOCK_STREAM;
+hints.ai_flags |= AI_PASSIVE;
+ret = getaddrinfo(NULL, portstr, hints, ai);
+if (ret) {
+av_log(h, AV_LOG_ERROR, borked);
+return AVERROR(EIO);
+}
+fd = ff_socket(ai-ai_family,
+   ai-ai_socktype,
+   ai-ai_protocol);
+if (fd  0) {
+ret = ff_neterrno();
+freeaddrinfo(ai);
+return -1;
+}
 
-ret = http_open_cnx(h, options);
-if (ret  0)
-av_dict_free(s-chained_options);
-return ret;
+fd = ff_listen_bind(fd, ai-ai_addr, ai-ai_addrlen, -1, h);
+if (fd  0) {
+freeaddrinfo(ai);
+return fd;
+}
+h-is_streamed = 1;
+s-fd = fd;
+freeaddrinfo(ai);
+return 0;
+} else {
+ret = http_open_cnx(h, options);
+

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

2015-03-21 Thread Michael Niedermayer
On Sun, Mar 22, 2015 at 12:33:57AM +0100, Stephan Holljes wrote:
 Hi,
 
 what would be the correct way to create patches that won't be corrupted? I
 merely tried to copy what I have seen on the mailing-list before,
 apparently I didn't do a very good job ;)

git send-email -1
would send the most recent commit on the current branch, see the
manual for exact usage

or

git format-patch -1
would create the git patch that can be attached

about the patch itself i tried it with wget and firefox it seems to
work but firefox failed to detect it as mp3, i guess some content type
is missing

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2015-03-21 Thread Stephan Holljes
On Sun, Mar 22, 2015 at 2:34 AM, Michael Niedermayer michae...@gmx.at
wrote:

 On Sun, Mar 22, 2015 at 12:33:57AM +0100, Stephan Holljes wrote:
  Hi,
 
  what would be the correct way to create patches that won't be corrupted?
 I
  merely tried to copy what I have seen on the mailing-list before,
  apparently I didn't do a very good job ;)

 git send-email -1
 would send the most recent commit on the current branch, see the
 manual for exact usage

 or

 git format-patch -1
 would create the git patch that can be attached

 about the patch itself i tried it with wget and firefox it seems to
 work but firefox failed to detect it as mp3, i guess some content type
 is missing


That would be my guess, too. I will look into that.



 [...]

 --
 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

 Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope

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


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