mirror of
https://github.com/arut/nginx-rtmp-module.git
synced 2025-08-06 15:00:18 +08:00
early relay implementation
This commit is contained in:
@ -7,7 +7,6 @@
|
||||
|
||||
|
||||
static void ngx_rtmp_close_connection(ngx_connection_t *c);
|
||||
static void ngx_rtmp_init_session(ngx_connection_t *c);
|
||||
static u_char * ngx_rtmp_log_error(ngx_log_t *log, u_char *buf, size_t len);
|
||||
|
||||
|
||||
@ -18,7 +17,6 @@ ngx_rtmp_init_connection(ngx_connection_t *c)
|
||||
ngx_rtmp_port_t *port;
|
||||
struct sockaddr *sa;
|
||||
struct sockaddr_in *sin;
|
||||
ngx_rtmp_log_ctx_t *ctx;
|
||||
ngx_rtmp_in_addr_t *addr;
|
||||
ngx_rtmp_session_t *s;
|
||||
ngx_rtmp_addr_conf_t *addr_conf;
|
||||
@ -107,10 +105,28 @@ 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);
|
||||
|
||||
s = ngx_rtmp_init_session(c, addr_conf);
|
||||
|
||||
if (s) {
|
||||
ngx_rtmp_handshake(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ngx_rtmp_session_t *
|
||||
ngx_rtmp_init_session(ngx_connection_t *c, ngx_rtmp_addr_conf_t *addr_conf)
|
||||
{
|
||||
ngx_rtmp_session_t *s;
|
||||
ngx_rtmp_core_srv_conf_t *cscf;
|
||||
ngx_rtmp_log_ctx_t *ctx;
|
||||
|
||||
s = ngx_pcalloc(c->pool, sizeof(ngx_rtmp_session_t));
|
||||
if (s == NULL) {
|
||||
ngx_rtmp_close_connection(c);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s->main_conf = addr_conf->ctx->main_conf;
|
||||
@ -121,13 +137,10 @@ ngx_rtmp_init_connection(ngx_connection_t *c)
|
||||
c->data = s;
|
||||
s->connection = c;
|
||||
|
||||
ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client connected",
|
||||
c->number, &c->addr_text);
|
||||
|
||||
ctx = ngx_palloc(c->pool, sizeof(ngx_rtmp_log_ctx_t));
|
||||
if (ctx == NULL) {
|
||||
ngx_rtmp_close_connection(c);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->client = &c->addr_text;
|
||||
@ -140,28 +153,12 @@ ngx_rtmp_init_connection(ngx_connection_t *c)
|
||||
|
||||
c->log_error = NGX_ERROR_INFO;
|
||||
|
||||
ngx_rtmp_init_session(c);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ngx_rtmp_init_session(ngx_connection_t *c)
|
||||
{
|
||||
ngx_rtmp_session_t *s;
|
||||
ngx_rtmp_core_main_conf_t *cmcf;
|
||||
ngx_rtmp_core_srv_conf_t *cscf;
|
||||
size_t n;
|
||||
ngx_rtmp_handler_pt *h;
|
||||
ngx_array_t *ch;
|
||||
|
||||
s = c->data;
|
||||
|
||||
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
|
||||
|
||||
s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_rtmp_max_module);
|
||||
if (s->ctx == NULL) {
|
||||
ngx_rtmp_close_connection(c);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -169,7 +166,7 @@ ngx_rtmp_init_session(ngx_connection_t *c)
|
||||
* cscf->max_streams);
|
||||
if (s->in_streams == NULL) {
|
||||
ngx_rtmp_close_connection(c);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s->epoch = ngx_current_msec;
|
||||
@ -177,21 +174,12 @@ ngx_rtmp_init_session(ngx_connection_t *c)
|
||||
ngx_rtmp_set_chunk_size(s, NGX_RTMP_DEFAULT_CHUNK_SIZE);
|
||||
|
||||
|
||||
/* call connect callbacks */
|
||||
cmcf = ngx_rtmp_get_module_main_conf(s, ngx_rtmp_core_module);
|
||||
|
||||
ch = &cmcf->events[NGX_RTMP_CONNECT];
|
||||
h = ch->elts;
|
||||
for(n = 0; n < ch->nelts; ++n, ++h) {
|
||||
if (*h) {
|
||||
if ((*h)(s, NULL, NULL) != NGX_OK) {
|
||||
ngx_rtmp_finalize_session(s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ngx_rtmp_fire_event(s, NGX_RTMP_CONNECT, NULL, NULL) != NGX_OK) {
|
||||
ngx_rtmp_finalize_session(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ngx_rtmp_handshake(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@ -248,9 +236,6 @@ ngx_rtmp_close_session_handler(ngx_event_t *e)
|
||||
ngx_connection_t *c;
|
||||
ngx_rtmp_core_main_conf_t *cmcf;
|
||||
ngx_rtmp_core_srv_conf_t *cscf;
|
||||
ngx_rtmp_handler_pt *h;
|
||||
ngx_array_t *dh;
|
||||
size_t n;
|
||||
|
||||
s = e->data;
|
||||
c = s->connection;
|
||||
@ -261,14 +246,7 @@ ngx_rtmp_close_session_handler(ngx_event_t *e)
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, c->log, 0, "close session");
|
||||
|
||||
if (s) {
|
||||
dh = &cmcf->events[NGX_RTMP_DISCONNECT];
|
||||
h = dh->elts;
|
||||
|
||||
for(n = 0; n < dh->nelts; ++n, ++h) {
|
||||
if (*h) {
|
||||
(*h)(s, NULL, NULL);
|
||||
}
|
||||
}
|
||||
ngx_rtmp_fire_event(s, NGX_RTMP_DISCONNECT, NULL, NULL);
|
||||
|
||||
if (s->in_old_pool) {
|
||||
ngx_destroy_pool(s->in_old_pool);
|
||||
|
Reference in New Issue
Block a user