mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-17 00:51:09 +02:00
Merge branch 'dev' into fetch
This commit is contained in:
commit
dbb9fc8f7c
4
config
4
config
|
@ -15,11 +15,11 @@ RTMP_CORE_MODULES=" \
|
|||
ngx_rtmp_exec_module \
|
||||
ngx_rtmp_auto_push_module \
|
||||
ngx_rtmp_auto_push_index_module \
|
||||
ngx_rtmp_notify_module \
|
||||
ngx_rtmp_log_module \
|
||||
ngx_rtmp_limit_module \
|
||||
ngx_rtmp_hls_module \
|
||||
ngx_rtmp_dash_module \
|
||||
ngx_rtmp_notify_module \
|
||||
"
|
||||
RTMP_HTTP_MODULES=" \
|
||||
ngx_rtmp_stat_module \
|
||||
|
@ -68,7 +68,6 @@ RTMP_CORE_SRCS=" \
|
|||
$ngx_addon_dir/ngx_rtmp_bandwidth.c \
|
||||
$ngx_addon_dir/ngx_rtmp_exec_module.c \
|
||||
$ngx_addon_dir/ngx_rtmp_auto_push_module.c \
|
||||
$ngx_addon_dir/ngx_rtmp_notify_module.c \
|
||||
$ngx_addon_dir/ngx_rtmp_log_module.c \
|
||||
$ngx_addon_dir/ngx_rtmp_limit_module.c \
|
||||
$ngx_addon_dir/ngx_rtmp_bitop.c \
|
||||
|
@ -78,6 +77,7 @@ RTMP_CORE_SRCS=" \
|
|||
$ngx_addon_dir/hls/ngx_rtmp_mpegts.c \
|
||||
$ngx_addon_dir/hls/ngx_rtmp_mpegts_crc.c \
|
||||
$ngx_addon_dir/dash/ngx_rtmp_mp4.c \
|
||||
$ngx_addon_dir/ngx_rtmp_notify_module.c \
|
||||
"
|
||||
RTMP_HTTP_SRCS=" \
|
||||
$ngx_addon_dir/ngx_rtmp_stat_module.c \
|
||||
|
|
|
@ -73,6 +73,7 @@ typedef struct {
|
|||
uint64_t key_id;
|
||||
ngx_uint_t nfrags;
|
||||
ngx_rtmp_hls_frag_t *frags; /* circular 2 * winfrags + 1 */
|
||||
uint64_t mediaseq;
|
||||
|
||||
ngx_uint_t audio_cc;
|
||||
ngx_uint_t video_cc;
|
||||
|
@ -300,7 +301,7 @@ static ngx_command_t ngx_rtmp_hls_commands[] = {
|
|||
ngx_conf_set_enum_slot,
|
||||
NGX_RTMP_APP_CONF_OFFSET,
|
||||
offsetof(ngx_rtmp_hls_app_conf_t, allow_client_cache),
|
||||
&ngx_rtmp_hls_cache },
|
||||
&ngx_rtmp_hls_cache },
|
||||
|
||||
{ ngx_string("hls_variant"),
|
||||
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_1MORE,
|
||||
|
@ -529,7 +530,7 @@ ngx_rtmp_hls_write_variant_playlist(ngx_rtmp_session_t *s)
|
|||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_hls_write_playlist(ngx_rtmp_session_t *s)
|
||||
ngx_rtmp_hls_write_playlist(ngx_rtmp_session_t *s, int final)
|
||||
{
|
||||
static u_char buffer[1024];
|
||||
ngx_fd_t fd;
|
||||
|
@ -605,7 +606,7 @@ ngx_rtmp_hls_write_playlist(ngx_rtmp_session_t *s)
|
|||
"#EXT-X-VERSION:3\n"
|
||||
"#EXT-X-MEDIA-SEQUENCE:%uL\n"
|
||||
"#EXT-X-TARGETDURATION:%ui\n",
|
||||
ctx->frag, max_frag);
|
||||
ctx->mediaseq++, max_frag);
|
||||
|
||||
if (hacf->type == NGX_RTMP_HLS_TYPE_EVENT) {
|
||||
p = ngx_slprintf(p, end, "#EXT-X-PLAYLIST-TYPE:EVENT\n");
|
||||
|
@ -638,6 +639,7 @@ ngx_rtmp_hls_write_playlist(ngx_rtmp_session_t *s)
|
|||
prev_key_id = 0;
|
||||
|
||||
for (i = start_i; i < (ngx_int_t)ctx->nfrags; i++) {
|
||||
for (i = start_i; i < (ngx_int_t) ctx->nfrags; i++) {
|
||||
f = ngx_rtmp_hls_get_frag(s, i);
|
||||
if ((i == 0 || f->discont) && f->datetime && f->datetime->len > 0) {
|
||||
p = ngx_snprintf(buffer, sizeof(buffer), "#EXT-X-PROGRAM-DATE-TIME:");
|
||||
|
@ -687,6 +689,15 @@ ngx_rtmp_hls_write_playlist(ngx_rtmp_session_t *s)
|
|||
}
|
||||
}
|
||||
|
||||
if (final)
|
||||
{
|
||||
p = ngx_slprintf(p, end, "#EXT-X-ENDLIST\n");
|
||||
n = ngx_write_fd(fd, buffer, p - buffer);
|
||||
if (n < 0) {
|
||||
goto write_err;
|
||||
}
|
||||
}
|
||||
|
||||
ngx_close_file(fd);
|
||||
|
||||
if (ngx_rtmp_hls_rename_file(ctx->playlist_bak.data, ctx->playlist.data)
|
||||
|
@ -967,7 +978,7 @@ ngx_rtmp_hls_get_fragment_datetime(ngx_rtmp_session_t *s, uint64_t ts)
|
|||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_hls_close_fragment(ngx_rtmp_session_t *s)
|
||||
ngx_rtmp_hls_close_final_fragment(ngx_rtmp_session_t *s, int final)
|
||||
{
|
||||
ngx_rtmp_hls_ctx_t *ctx;
|
||||
|
||||
|
@ -985,12 +996,19 @@ ngx_rtmp_hls_close_fragment(ngx_rtmp_session_t *s)
|
|||
|
||||
ngx_rtmp_hls_next_frag(s);
|
||||
|
||||
ngx_rtmp_hls_write_playlist(s);
|
||||
ngx_rtmp_hls_write_playlist(s, final);
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_hls_close_fragment(ngx_rtmp_session_t *s)
|
||||
{
|
||||
return ngx_rtmp_hls_close_final_fragment(s, 0);
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_hls_open_fragment(ngx_rtmp_session_t *s, uint64_t ts,
|
||||
ngx_int_t discont)
|
||||
|
@ -1451,7 +1469,7 @@ ngx_rtmp_hls_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
|
|||
goto next;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"hls: publish: name='%s' type='%s'",
|
||||
v->name, v->type);
|
||||
|
||||
|
@ -1651,7 +1669,7 @@ ngx_rtmp_hls_close_stream(ngx_rtmp_session_t *s, ngx_rtmp_close_stream_t *v)
|
|||
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"hls: close stream");
|
||||
|
||||
ngx_rtmp_hls_close_fragment(s);
|
||||
ngx_rtmp_hls_close_final_fragment(s, 1);
|
||||
|
||||
next:
|
||||
return next_close_stream(s, v);
|
||||
|
|
|
@ -1192,7 +1192,7 @@ ngx_rtmp_notify_connect_handle(ngx_rtmp_session_t *s,
|
|||
ngx_rtmp_notify_srv_conf_t *nscf;
|
||||
u_char app[NGX_RTMP_MAX_NAME];
|
||||
|
||||
static ngx_str_t location = ngx_string("location");
|
||||
static ngx_str_t location = ngx_string("x-rtmp-target");
|
||||
|
||||
rc = ngx_rtmp_notify_parse_http_retcode(s, in);
|
||||
|
||||
|
@ -1296,35 +1296,20 @@ next:
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
ngx_rtmp_notify_set_name(u_char *dst, size_t dst_len, u_char *src,
|
||||
size_t src_len)
|
||||
{
|
||||
u_char result[16], *p;
|
||||
ngx_md5_t md5;
|
||||
|
||||
ngx_md5_init(&md5);
|
||||
ngx_md5_update(&md5, src, src_len);
|
||||
ngx_md5_final(result, &md5);
|
||||
|
||||
p = ngx_hex_dump(dst, result, ngx_min((dst_len - 1) / 2, 16));
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s,
|
||||
void *arg, ngx_chain_t *in)
|
||||
{
|
||||
ngx_rtmp_publish_t *v = arg;
|
||||
ngx_int_t rc, send;
|
||||
ngx_int_t rc, len_restream, len_user, send;
|
||||
ngx_str_t local_name;
|
||||
ngx_rtmp_relay_target_t target;
|
||||
ngx_url_t *u;
|
||||
ngx_rtmp_notify_app_conf_t *nacf;
|
||||
u_char name[NGX_RTMP_MAX_NAME];
|
||||
u_char restream[NGX_RTMP_MAX_NAME];
|
||||
u_char user[NGX_RTMP_MAX_NAME];
|
||||
|
||||
static ngx_str_t location = ngx_string("location");
|
||||
static ngx_str_t header_restream = ngx_string("x-rtmp-target");
|
||||
static ngx_str_t header_user = ngx_string("x-rtmp-user");
|
||||
|
||||
rc = ngx_rtmp_notify_parse_http_retcode(s, in);
|
||||
|
||||
|
@ -1364,93 +1349,58 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s,
|
|||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: publish redirect received");
|
||||
|
||||
rc = ngx_rtmp_notify_parse_http_header(s, in, &location, name,
|
||||
sizeof(name) - 1);
|
||||
if (rc <= 0) {
|
||||
len_user = ngx_rtmp_notify_parse_http_header(s, in, &header_user, user, sizeof(user) - 1);
|
||||
if (len_user <= 0) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (ngx_strncasecmp(name, (u_char *) "rtmp://", 7)) {
|
||||
*ngx_cpymem(v->name, name, rc) = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: publish redirect to '%s'", v->name);
|
||||
goto next;
|
||||
}
|
||||
*ngx_cpymem(&v->name, &user, len_user) = 0;
|
||||
|
||||
/* push */
|
||||
|
||||
nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module);
|
||||
|
||||
if (nacf->send_redirect) {
|
||||
// Send 302 redirect and go next
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: publish send 302 redirect");
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: -- for stream '%s' to new location '%*s'", v->name, rc, name);
|
||||
|
||||
local_name.data = ngx_palloc(s->connection->pool, rc+1);
|
||||
local_name.len = rc;
|
||||
*ngx_cpymem(local_name.data, name, rc) = 0;
|
||||
|
||||
/* MAGICK HERE */
|
||||
|
||||
if (!ngx_strncasecmp(s->flashver.data, (u_char *) "FMLE/", 5)) {
|
||||
// Official method, by FMS SDK
|
||||
send = ngx_rtmp_send_redirect_status(s, "onStatus", "Connect here", local_name);
|
||||
send &= ngx_rtmp_send_redirect_status(s, "netStatus", "Connect here", local_name);
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: publish send(o) status = '%ui'", send == NGX_OK);
|
||||
} else {
|
||||
|
||||
// Something by rtmpdump lib
|
||||
send = ngx_rtmp_send_redirect_status(s, "_error", "Connect here", local_name);
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: publish send(e) status = '%ui'", send == NGX_OK);
|
||||
}
|
||||
|
||||
ngx_pfree(s->connection->pool, local_name.data);
|
||||
|
||||
ngx_rtmp_notify_clear_flag(s, NGX_RTMP_NOTIFY_PUBLISHING);
|
||||
|
||||
// Something by rtmpdump lib
|
||||
send = ngx_rtmp_send_close_method(s, "close");
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: publish send(e) close method = '%ui'", send == NGX_OK);
|
||||
|
||||
return send;
|
||||
|
||||
} else if (nacf->relay_redirect) {
|
||||
// Relay local streams, change name
|
||||
|
||||
ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t) rc);
|
||||
}
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: push '%s' to '%*s'", v->name, rc, name);
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "notify: publish redirect to '%s'", v->name);
|
||||
|
||||
local_name.data = v->name;
|
||||
local_name.len = ngx_strlen(v->name);
|
||||
|
||||
ngx_memzero(&target, sizeof(target));
|
||||
|
||||
u = &target.url;
|
||||
u->url = local_name;
|
||||
u->url.data = name + 7;
|
||||
u->url.len = rc - 7;
|
||||
u->default_port = 1935;
|
||||
u->uri_part = 1;
|
||||
u->no_resolve = 1; /* want ip here */
|
||||
|
||||
if (ngx_parse_url(s->connection->pool, u) != NGX_OK) {
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: push failed '%V'", &local_name);
|
||||
return NGX_ERROR;
|
||||
len_restream = ngx_rtmp_notify_parse_http_header(s, in, &header_restream, restream, sizeof(restream) - 1);
|
||||
if (len_restream <= 0) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
ngx_rtmp_relay_push(s, &local_name, &target);
|
||||
u_char *start = restream;
|
||||
u_char *next;
|
||||
|
||||
while (start != NULL) {
|
||||
next = (u_char *) ngx_strchr(start, ',');
|
||||
|
||||
ngx_memzero(&target, sizeof(target));
|
||||
u = &target.url;
|
||||
u->url = local_name;
|
||||
|
||||
if (next) {
|
||||
u->url.data = start + 7;
|
||||
u->url.len = next - start - 7;
|
||||
start = next + 1;
|
||||
} else {
|
||||
u->url.data = start + 7;
|
||||
u->url.len = len_restream - (start - restream) - 7;
|
||||
start = NULL;
|
||||
}
|
||||
|
||||
u->default_port = 1935;
|
||||
u->uri_part = 1;
|
||||
u->no_resolve = 0;
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: processing push '%V'", &u->url);
|
||||
|
||||
if (ngx_parse_url(s->connection->pool, u) != NGX_OK) {
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
"notify: push failed '%V'", &local_name);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_rtmp_relay_push(s, &local_name, &target);
|
||||
}
|
||||
|
||||
next:
|
||||
|
||||
|
@ -1519,6 +1469,7 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s,
|
|||
goto next;
|
||||
}
|
||||
|
||||
|
||||
if (ngx_strncasecmp(name, (u_char *) "rtmp://", 7)) {
|
||||
*ngx_cpymem(v->name, name, rc) = 0;
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
|
@ -1573,7 +1524,7 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s,
|
|||
} else if (nacf->relay_redirect) {
|
||||
// Relay local streams, change name
|
||||
|
||||
ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t) rc);
|
||||
*ngx_cpymem(&v->name, &name, NGX_RTMP_MAX_NAME) = 0;
|
||||
}
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
|
||||
|
|
Loading…
Reference in a new issue