From dd19680ed9066e8b13ac618661c8337f9b3a5f60 Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Fri, 20 Jul 2012 13:06:17 +0400 Subject: [PATCH] skipped on_publish/access/record for auto-pushed connections --- ngx_rtmp.h | 3 +++ ngx_rtmp_access_module.c | 5 +++++ ngx_rtmp_auto_push_module.c | 37 ++++++++++++++++++++++++------------- ngx_rtmp_init.c | 16 ++++++++++++++-- ngx_rtmp_notify_module.c | 4 ++++ ngx_rtmp_record_module.c | 4 ++++ 6 files changed, 54 insertions(+), 15 deletions(-) diff --git a/ngx_rtmp.h b/ngx_rtmp.h index 96a9aa5..015acfb 100644 --- a/ngx_rtmp.h +++ b/ngx_rtmp.h @@ -205,6 +205,9 @@ typedef struct { unsigned ping_active:1; unsigned ping_reset:1; + /* auto-pushed? */ + unsigned auto_pushed:1; + /* input stream 0 (reserved by RTMP spec) * is used as free chain link */ diff --git a/ngx_rtmp_access_module.c b/ngx_rtmp_access_module.c index 4551ae8..5d939ef 100644 --- a/ngx_rtmp_access_module.c +++ b/ngx_rtmp_access_module.c @@ -400,10 +400,15 @@ ngx_rtmp_access_rule(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) static ngx_int_t ngx_rtmp_access_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) { + if (s->auto_pushed) { + goto next; + } + if (ngx_rtmp_access(s, NGX_RTMP_ACCESS_PUBLISH) != NGX_OK) { return NGX_ERROR; } +next: return next_publish(s, v); } diff --git a/ngx_rtmp_auto_push_module.c b/ngx_rtmp_auto_push_module.c index 9bede59..211a67a 100644 --- a/ngx_rtmp_auto_push_module.c +++ b/ngx_rtmp_auto_push_module.c @@ -26,6 +26,7 @@ typedef struct ngx_rtmp_auto_push_ctx_s ngx_rtmp_auto_push_ctx_t; struct ngx_rtmp_auto_push_ctx_s { ngx_int_t *slots; /* NGX_MAX_PROCESSES */ ngx_str_t name; + ngx_str_t args; ngx_event_t push_evt; }; @@ -88,7 +89,6 @@ ngx_module_t ngx_rtmp_auto_push_module = { #define NGX_RTMP_AUTO_PUSH_SOCKNAME "nginx-rtmp" -#define NGX_RTMP_AUTO_PUSH_PAGEURL "nginx-auto-push" static ngx_int_t @@ -296,8 +296,9 @@ ngx_rtmp_auto_push_reconnect(ngx_event_t *ev) ngx_int_t n; ngx_rtmp_relay_target_t at; u_char path[sizeof("unix:") + NGX_MAX_PATH]; - u_char flash_ver[sizeof("APSH.") + 2 - + NGX_OFF_T_LEN * 2]; + u_char flash_ver[sizeof("APSH ,") + + NGX_OFF_T_LEN * 2]; + u_char play_path[NGX_RTMP_MAX_NAME]; u_char *p; ngx_str_t *u; ngx_pid_t pid; @@ -313,9 +314,16 @@ ngx_rtmp_auto_push_reconnect(ngx_event_t *ev) } ngx_memzero(&at, sizeof(at)); - ngx_str_set(&at.page_url, NGX_RTMP_AUTO_PUSH_PAGEURL); + ngx_str_set(&at.page_url, "nginx-auto-push"); at.tag = &ngx_rtmp_auto_push_module; + if (ctx->args.len) { + at.play_path.data = play_path; + at.play_path.len = ngx_snprintf(play_path, sizeof(play_path), + "%V?%V", &ctx->name, &ctx->args) - + play_path; + } + slot = ctx->slots; for (n = 0; n < NGX_MAX_PROCESSES; ++n, ++slot) { @@ -350,7 +358,7 @@ ngx_rtmp_auto_push_reconnect(ngx_event_t *ev) continue; } - p = ngx_snprintf(flash_ver, sizeof(flash_ver) - 1, "APSH,%i,%i", + p = ngx_snprintf(flash_ver, sizeof(flash_ver) - 1, "APSH %i,%i", (ngx_int_t) ngx_process_slot, (ngx_int_t) ngx_pid); at.flash_ver.data = flash_ver; at.flash_ver.len = p - flash_ver; @@ -383,17 +391,13 @@ ngx_rtmp_auto_push_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) ngx_rtmp_auto_push_conf_t *apcf; ngx_rtmp_auto_push_ctx_t *ctx; - apcf = (ngx_rtmp_auto_push_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, - ngx_rtmp_auto_push_module); - if (apcf->auto_push == 0) { + if (s->auto_pushed) { goto next; } - /* auto-push from another worker? */ - if (s->page_url.len == sizeof(NGX_RTMP_AUTO_PUSH_PAGEURL) - 1 && - ngx_memcmp(s->page_url.data, NGX_RTMP_AUTO_PUSH_PAGEURL, - s->page_url.len) == 0) - { + apcf = (ngx_rtmp_auto_push_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, + ngx_rtmp_auto_push_module); + if (apcf->auto_push == 0) { goto next; } @@ -426,6 +430,13 @@ ngx_rtmp_auto_push_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) } ngx_memcpy(ctx->name.data, v->name, ctx->name.len); + ctx->args.len = ngx_strlen(v->args); + ctx->args.data = ngx_palloc(s->connection->pool, ctx->args.len); + if (ctx->args.data == NULL) { + goto next; + } + ngx_memcpy(ctx->args.data, v->args, ctx->args.len); + ngx_rtmp_auto_push_reconnect(&ctx->push_evt); next: diff --git a/ngx_rtmp_init.c b/ngx_rtmp_init.c index a0d3537..eee172e 100644 --- a/ngx_rtmp_init.c +++ b/ngx_rtmp_init.c @@ -20,6 +20,7 @@ ngx_rtmp_init_connection(ngx_connection_t *c) ngx_rtmp_in_addr_t *addr; ngx_rtmp_session_t *s; ngx_rtmp_addr_conf_t *addr_conf; + ngx_int_t unix_socket; #if (NGX_HAVE_INET6) struct sockaddr_in6 *sin6; ngx_rtmp_in6_addr_t *addr6; @@ -31,6 +32,7 @@ ngx_rtmp_init_connection(ngx_connection_t *c) /* AF_INET only */ port = c->listening->servers; + unix_socket = 0; if (port->naddrs > 1) { @@ -70,6 +72,9 @@ ngx_rtmp_init_connection(ngx_connection_t *c) break; #endif + case AF_UNIX: + unix_socket = 1; + default: /* AF_INET */ sin = (struct sockaddr_in *) sa; @@ -98,6 +103,9 @@ ngx_rtmp_init_connection(ngx_connection_t *c) break; #endif + case AF_UNIX: + unix_socket = 1; + default: /* AF_INET */ addr = port->addrs; addr_conf = &addr[0].conf; @@ -105,11 +113,15 @@ ngx_rtmp_init_connection(ngx_connection_t *c) } } - ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client connected", - c->number, &c->addr_text); + /*ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client connected", + c->number, &c->addr_text);*/ s = ngx_rtmp_init_session(c, addr_conf); + /* only auto-pushed connections are + * done through unix socket */ + s->auto_pushed = unix_socket; + if (s) { ngx_rtmp_handshake(s); } diff --git a/ngx_rtmp_notify_module.c b/ngx_rtmp_notify_module.c index aef8241..f8c7928 100644 --- a/ngx_rtmp_notify_module.c +++ b/ngx_rtmp_notify_module.c @@ -442,6 +442,10 @@ ngx_rtmp_notify_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) ngx_rtmp_notify_app_conf_t *nacf; ngx_rtmp_netcall_init_t ci; + if (s->auto_pushed) { + goto next; + } + nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module); if (nacf == NULL) { goto next; diff --git a/ngx_rtmp_record_module.c b/ngx_rtmp_record_module.c index ef81261..5f24e53 100644 --- a/ngx_rtmp_record_module.c +++ b/ngx_rtmp_record_module.c @@ -302,6 +302,10 @@ ngx_rtmp_record_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) ngx_rtmp_record_app_conf_t *racf; ngx_rtmp_record_ctx_t *ctx; + if (s->auto_pushed) { + goto next; + } + racf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_record_module); if (racf == NULL || racf->flags & NGX_RTMP_RECORD_OFF) {