mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-16 16:51:07 +02:00
vod-http is now working
This commit is contained in:
parent
eacfd8fac4
commit
b8424c9b63
|
@ -491,15 +491,17 @@ ngx_rtmp_netcall_send(ngx_event_t *wev)
|
|||
|
||||
|
||||
ngx_chain_t *
|
||||
ngx_rtmp_netcall_http_format_header(ngx_str_t *uri, ngx_str_t *host,
|
||||
ngx_pool_t *pool, size_t content_length,
|
||||
ngx_str_t *content_type)
|
||||
ngx_rtmp_netcall_http_format_header(ngx_int_t method, ngx_str_t *uri,
|
||||
ngx_str_t *host, ngx_pool_t *pool,
|
||||
size_t content_length,
|
||||
ngx_str_t *content_type)
|
||||
{
|
||||
ngx_chain_t *cl;
|
||||
ngx_buf_t *b;
|
||||
const char *method_s;
|
||||
|
||||
static char rq_tmpl[] =
|
||||
"POST %V HTTP/1.0\r\n"
|
||||
"%s %V HTTP/1.0\r\n"
|
||||
"Host: %V\r\n"
|
||||
"Content-Type: %V\r\n"
|
||||
"Connection: Close\r\n"
|
||||
|
@ -513,6 +515,7 @@ ngx_rtmp_netcall_http_format_header(ngx_str_t *uri, ngx_str_t *host,
|
|||
}
|
||||
|
||||
b = ngx_create_temp_buf(pool, sizeof(rq_tmpl)
|
||||
+ sizeof("POST") - 1 /* longest method */
|
||||
+ uri->len
|
||||
+ host->len
|
||||
+ content_type->len
|
||||
|
@ -523,9 +526,21 @@ ngx_rtmp_netcall_http_format_header(ngx_str_t *uri, ngx_str_t *host,
|
|||
}
|
||||
|
||||
cl->buf = b;
|
||||
cl->next = NULL;
|
||||
|
||||
switch (method) {
|
||||
case NGX_RTMP_NETCALL_HTTP_GET:
|
||||
method_s = "GET";
|
||||
break;
|
||||
case NGX_RTMP_NETCALL_HTTP_POST:
|
||||
method_s = "POST";
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b->last = ngx_snprintf(b->last, b->end - b->last, rq_tmpl,
|
||||
uri, host, content_type, content_length);
|
||||
method_s, uri, host, content_type, content_length);
|
||||
|
||||
return cl;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ typedef ngx_int_t (*ngx_rtmp_netcall_sink_pt)(ngx_rtmp_session_t *s,
|
|||
typedef ngx_int_t (*ngx_rtmp_netcall_handle_pt)(ngx_rtmp_session_t *s,
|
||||
void *arg, ngx_chain_t *in);
|
||||
|
||||
#define NGX_RTMP_NETCALL_HTTP_GET 1
|
||||
#define NGX_RTMP_NETCALL_HTTP_POST 2
|
||||
|
||||
|
||||
/* If handle is NULL then netcall is created detached
|
||||
* which means it's completely independent of RTMP
|
||||
|
@ -48,9 +51,9 @@ ngx_int_t ngx_rtmp_netcall_create(ngx_rtmp_session_t *s,
|
|||
/* HTTP handling */
|
||||
ngx_chain_t * ngx_rtmp_netcall_http_format_session(ngx_rtmp_session_t *s,
|
||||
ngx_pool_t *pool);
|
||||
ngx_chain_t * ngx_rtmp_netcall_http_format_header(ngx_str_t *uri,
|
||||
ngx_str_t *host, ngx_pool_t *pool, size_t content_length,
|
||||
ngx_str_t *content_type);
|
||||
ngx_chain_t * ngx_rtmp_netcall_http_format_header(ngx_int_t method,
|
||||
ngx_str_t *uri, ngx_str_t *host, ngx_pool_t *pool,
|
||||
size_t content_length, ngx_str_t *content_type);
|
||||
ngx_chain_t * ngx_rtmp_netcall_http_skip_header(ngx_chain_t *in);
|
||||
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ ngx_rtmp_notify_publish_create(ngx_rtmp_session_t *s, void *arg,
|
|||
|
||||
b = ngx_create_temp_buf(pool,
|
||||
sizeof("&call=publish") +
|
||||
sizeof("&addr=") + addr_text->len +
|
||||
sizeof("&addr=") + addr_text->len *3 +
|
||||
sizeof("&name=") + name_len * 3 +
|
||||
sizeof("&type=") + type_len * 3 +
|
||||
1 + args_len);
|
||||
|
@ -250,7 +250,8 @@ ngx_rtmp_notify_publish_create(ngx_rtmp_session_t *s, void *arg,
|
|||
|
||||
/* HTTP header */
|
||||
url = nacf->url[NGX_RTMP_NOTIFY_PUBLISH];
|
||||
hl = ngx_rtmp_netcall_http_format_header(&url->uri, &url->host,
|
||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_POST,
|
||||
&url->uri, &url->host,
|
||||
pool, cl->buf->last - cl->buf->pos + (pl->buf->last - pl->buf->pos),
|
||||
&ngx_rtmp_notify_urlencoded);
|
||||
|
||||
|
@ -301,7 +302,7 @@ ngx_rtmp_notify_play_create(ngx_rtmp_session_t *s, void *arg,
|
|||
|
||||
b = ngx_create_temp_buf(pool,
|
||||
sizeof("&call=play") +
|
||||
sizeof("&addr=") + addr_text->len +
|
||||
sizeof("&addr=") + addr_text->len * 3 +
|
||||
sizeof("&name=") + name_len * 3 +
|
||||
sizeof("&start=&duration=&reset=") + NGX_OFF_T_LEN * 3
|
||||
+ 1 + args_len);
|
||||
|
@ -332,7 +333,8 @@ ngx_rtmp_notify_play_create(ngx_rtmp_session_t *s, void *arg,
|
|||
|
||||
/* HTTP header */
|
||||
url = nacf->url[NGX_RTMP_NOTIFY_PLAY];
|
||||
hl = ngx_rtmp_netcall_http_format_header(&url->uri, &url->host,
|
||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_POST,
|
||||
&url->uri, &url->host,
|
||||
pool, cl->buf->last - cl->buf->pos + (pl->buf->last - pl->buf->pos),
|
||||
&ngx_rtmp_notify_urlencoded);
|
||||
|
||||
|
@ -382,7 +384,7 @@ ngx_rtmp_notify_done_create(ngx_rtmp_session_t *s, void *arg,
|
|||
|
||||
b = ngx_create_temp_buf(pool,
|
||||
sizeof("&call=") + cbname_len +
|
||||
sizeof("&addr=") + addr_text->len +
|
||||
sizeof("&addr=") + addr_text->len * 3 +
|
||||
sizeof("&name=") + name_len * 3
|
||||
+ 1 + args_len);
|
||||
if (b == NULL) {
|
||||
|
@ -409,7 +411,8 @@ ngx_rtmp_notify_done_create(ngx_rtmp_session_t *s, void *arg,
|
|||
}
|
||||
|
||||
/* HTTP header */
|
||||
hl = ngx_rtmp_netcall_http_format_header(&ds->url->uri, &ds->url->host,
|
||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_POST,
|
||||
&ds->url->uri, &ds->url->host,
|
||||
pool, cl->buf->last - cl->buf->pos + (pl->buf->last - pl->buf->pos),
|
||||
&ngx_rtmp_notify_urlencoded);
|
||||
|
||||
|
@ -464,7 +467,7 @@ ngx_rtmp_notify_record_done_create(ngx_rtmp_session_t *s, void *arg,
|
|||
b = ngx_create_temp_buf(pool,
|
||||
sizeof("&call=record_done") +
|
||||
sizeof("&recorder=") + v->recorder.len +
|
||||
sizeof("&addr=") + addr_text->len +
|
||||
sizeof("&addr=") + addr_text->len *3 +
|
||||
sizeof("&name=") + name_len * 3 +
|
||||
sizeof("&path=") + v->path.len * 3 +
|
||||
+ 1 + args_len);
|
||||
|
@ -499,7 +502,8 @@ ngx_rtmp_notify_record_done_create(ngx_rtmp_session_t *s, void *arg,
|
|||
|
||||
/* HTTP header */
|
||||
url = nacf->url[NGX_RTMP_NOTIFY_RECORD_DONE];
|
||||
hl = ngx_rtmp_netcall_http_format_header(&url->uri, &url->host,
|
||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_POST,
|
||||
&url->uri, &url->host,
|
||||
pool, cl->buf->last - cl->buf->pos + (pl->buf->last - pl->buf->pos),
|
||||
&ngx_rtmp_notify_urlencoded);
|
||||
|
||||
|
|
|
@ -381,7 +381,7 @@ ngx_rtmp_play_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
|
|||
|
||||
pacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_play_module);
|
||||
|
||||
if (pacf == NULL || pacf->root.len == 0) {
|
||||
if (pacf == NULL || (pacf->root.len == 0 && pacf->url == NULL)) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
|
@ -458,8 +458,11 @@ ngx_rtmp_play_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
|
|||
goto next;
|
||||
}
|
||||
|
||||
ctx->file.fd = NGX_INVALID_FILE;
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"play: %V", &ctx->fmt->name);
|
||||
"play %s: %V", pacf->url ? "remote" : "local",
|
||||
&ctx->fmt->name);
|
||||
|
||||
sfx = &ctx->fmt->sfx;
|
||||
|
||||
|
@ -471,17 +474,26 @@ ngx_rtmp_play_play(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
|
|||
sfx = &nosfx;
|
||||
}
|
||||
|
||||
p = ngx_snprintf(path, sizeof(path), "%V/%V%V", &pacf->root, &name, sfx);
|
||||
*p = 0;
|
||||
|
||||
ctx->file.fd = NGX_INVALID_FILE;
|
||||
|
||||
/* remote? */
|
||||
if (pacf->url) {
|
||||
ctx->name.data = ngx_palloc(s->connection->pool, name.len + sfx->len);
|
||||
if (ctx->name.data == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
p = ngx_sprintf(ctx->name.data, "%V%V", &name, sfx);
|
||||
*p = 0;
|
||||
|
||||
ctx->name.len = p - ctx->name.data;
|
||||
|
||||
return ngx_rtmp_play_open_remote(s, v);
|
||||
}
|
||||
|
||||
/* open local */
|
||||
|
||||
p = ngx_snprintf(path, sizeof(path), "%V/%V%V", &pacf->root, &name, sfx);
|
||||
*p = 0;
|
||||
|
||||
ctx->file.fd = ngx_open_file(path, NGX_FILE_RDONLY, NGX_FILE_OPEN,
|
||||
NGX_FILE_DEFAULT_ACCESS);
|
||||
|
||||
|
@ -540,71 +552,50 @@ ngx_rtmp_play_remote_create(ngx_rtmp_session_t *s, void *arg, ngx_pool_t *pool)
|
|||
ngx_rtmp_play_t *v = arg;
|
||||
|
||||
ngx_rtmp_play_app_conf_t *pacf;
|
||||
ngx_chain_t *hl, *cl, *pl;
|
||||
ngx_buf_t *b;
|
||||
ngx_rtmp_play_ctx_t *ctx;
|
||||
ngx_chain_t *hl;
|
||||
ngx_str_t *addr_text, uri;
|
||||
u_char *p;
|
||||
size_t name_len, args_len;
|
||||
size_t args_len, len;
|
||||
static ngx_str_t text_plain = ngx_string("text/plain");
|
||||
|
||||
pacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_play_module);
|
||||
|
||||
/* common variables */
|
||||
cl = ngx_rtmp_netcall_http_format_session(s, pool);
|
||||
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_play_module);
|
||||
|
||||
if (cl == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* publish variables */
|
||||
pl = ngx_alloc_chain_link(pool);
|
||||
|
||||
if (pl == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
name_len = ngx_strlen(v->name);
|
||||
args_len = ngx_strlen(v->args);
|
||||
addr_text = &s->connection->addr_text;
|
||||
|
||||
b = ngx_create_temp_buf(pool,
|
||||
sizeof("&addr=") + addr_text->len +
|
||||
1 + args_len);
|
||||
if (b == NULL) {
|
||||
len = pacf->url->uri.len + ctx->name.len +
|
||||
sizeof("?addr=") + addr_text->len * 3 +
|
||||
1 + args_len;
|
||||
|
||||
uri.data = ngx_palloc(pool, len);
|
||||
if (uri.data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pl->buf = b;
|
||||
|
||||
b->last = ngx_cpymem(b->last, (u_char*)"&addr=", sizeof("&addr=") -1);
|
||||
b->last = (u_char*)ngx_escape_uri(b->last, addr_text->data,
|
||||
addr_text->len, 0);
|
||||
p= uri.data;
|
||||
|
||||
p = ngx_cpymem(p, pacf->url->uri.data, pacf->url->uri.len);
|
||||
p = ngx_cpymem(p, ctx->name.data, ctx->name.len);
|
||||
p = ngx_cpymem(p, (u_char*)"?addr=", sizeof("&addr=") -1);
|
||||
p = (u_char*)ngx_escape_uri(p, addr_text->data, addr_text->len, 0);
|
||||
if (args_len) {
|
||||
*b->last++ = '&';
|
||||
b->last = (u_char *)ngx_cpymem(b->last, v->args, args_len);
|
||||
*p++ = '&';
|
||||
p = (u_char *) ngx_cpymem(p, v->args, args_len);
|
||||
}
|
||||
|
||||
/* create uri */
|
||||
uri.len = pacf->url->uri.len + name_len;
|
||||
uri.data = ngx_palloc(pool, uri.len);
|
||||
|
||||
p = ngx_cpymem(uri.data, pacf->url->uri.data, pacf->url->uri.len);
|
||||
ngx_memcpy(p, v->name, name_len);
|
||||
uri.len = p - uri.data;
|
||||
|
||||
/* HTTP header */
|
||||
hl = ngx_rtmp_netcall_http_format_header(&uri, &pacf->url->host,
|
||||
pool, cl->buf->last - cl->buf->pos + (pl->buf->last - pl->buf->pos),
|
||||
&text_plain);
|
||||
hl = ngx_rtmp_netcall_http_format_header(NGX_RTMP_NETCALL_HTTP_GET,
|
||||
&uri, &pacf->url->host, pool, 0, &text_plain);
|
||||
|
||||
if (hl == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hl->next = cl;
|
||||
cl->next = pl;
|
||||
pl->next = NULL;
|
||||
|
||||
return hl;
|
||||
}
|
||||
|
||||
|
@ -632,20 +623,23 @@ ngx_rtmp_play_remote_sink(ngx_rtmp_session_t *s, ngx_chain_t *in)
|
|||
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_play_module);
|
||||
|
||||
/* skip HTTP header */
|
||||
for (; in && ctx->ncrs != 2; in = in->next) {
|
||||
while (in && ctx->ncrs != 2) {
|
||||
b = in->buf;
|
||||
|
||||
for (; b->pos != b->last && ctx->ncrs != 2; ++b->pos) {
|
||||
switch (*b->pos) {
|
||||
case '\n':
|
||||
++ctx->ncrs;
|
||||
break;
|
||||
case '\r':
|
||||
break;
|
||||
default:
|
||||
ctx->ncrs = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (b->pos == b->last) {
|
||||
in = in->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* write to temp file */
|
||||
|
@ -721,7 +715,8 @@ ngx_rtmp_play_open_remote(ngx_rtmp_session_t *s, ngx_rtmp_play_t *v)
|
|||
static char *
|
||||
ngx_rtmp_play_url(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_rtmp_play_app_conf_t *pacf;
|
||||
ngx_rtmp_play_app_conf_t *pacf = conf;
|
||||
|
||||
ngx_str_t url;
|
||||
ngx_url_t *u;
|
||||
size_t add;
|
||||
|
|
|
@ -40,6 +40,7 @@ typedef struct {
|
|||
ngx_rtmp_play_fmt_t *fmt;
|
||||
ngx_event_t send_evt;
|
||||
ngx_uint_t ncrs;
|
||||
ngx_str_t name;
|
||||
} ngx_rtmp_play_ctx_t;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue