implemented on_connect & on_disconnect

This commit is contained in:
Roman Arutyunyan
2013-01-28 22:17:19 +04:00
parent 0153d0865b
commit f89bbae235
5 changed files with 479 additions and 87 deletions

View File

@ -9,9 +9,9 @@
static ngx_int_t ngx_rtmp_netcall_postconfiguration(ngx_conf_t *cf);
static void * ngx_rtmp_netcall_create_app_conf(ngx_conf_t *cf);
static char * ngx_rtmp_netcall_merge_app_conf(ngx_conf_t *cf,
void *parent, void *child);
static void * ngx_rtmp_netcall_create_srv_conf(ngx_conf_t *cf);
static char * ngx_rtmp_netcall_merge_srv_conf(ngx_conf_t *cf,
void *parent, void *child);
static void ngx_rtmp_netcall_close(ngx_connection_t *cc);
static void ngx_rtmp_netcall_detach(ngx_connection_t *cc);
@ -24,7 +24,7 @@ typedef struct {
ngx_msec_t timeout;
size_t bufsize;
ngx_log_t *log;
} ngx_rtmp_netcall_app_conf_t;
} ngx_rtmp_netcall_srv_conf_t;
typedef struct ngx_rtmp_netcall_session_s {
@ -55,15 +55,15 @@ static ngx_command_t ngx_rtmp_netcall_commands[] = {
{ ngx_string("netcall_timeout"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_RTMP_APP_CONF_OFFSET,
offsetof(ngx_rtmp_netcall_app_conf_t, timeout),
NGX_RTMP_SRV_CONF_OFFSET,
offsetof(ngx_rtmp_netcall_srv_conf_t, timeout),
NULL },
{ ngx_string("netcall_buffer"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_RTMP_APP_CONF_OFFSET,
offsetof(ngx_rtmp_netcall_app_conf_t, bufsize),
NGX_RTMP_SRV_CONF_OFFSET,
offsetof(ngx_rtmp_netcall_srv_conf_t, bufsize),
NULL },
ngx_null_command
@ -75,10 +75,10 @@ static ngx_rtmp_module_t ngx_rtmp_netcall_module_ctx = {
ngx_rtmp_netcall_postconfiguration, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
ngx_rtmp_netcall_create_app_conf, /* create app configuration */
ngx_rtmp_netcall_merge_app_conf /* merge app configuration */
ngx_rtmp_netcall_create_srv_conf, /* create server configuration */
ngx_rtmp_netcall_merge_srv_conf, /* merge server configuration */
NULL, /* create app configuration */
NULL /* merge app configuration */
};
@ -99,29 +99,29 @@ ngx_module_t ngx_rtmp_netcall_module = {
static void *
ngx_rtmp_netcall_create_app_conf(ngx_conf_t *cf)
ngx_rtmp_netcall_create_srv_conf(ngx_conf_t *cf)
{
ngx_rtmp_netcall_app_conf_t *nacf;
ngx_rtmp_netcall_srv_conf_t *nscf;
nacf = ngx_pcalloc(cf->pool, sizeof(ngx_rtmp_netcall_app_conf_t));
if (nacf == NULL) {
nscf = ngx_pcalloc(cf->pool, sizeof(ngx_rtmp_netcall_srv_conf_t));
if (nscf == NULL) {
return NULL;
}
nacf->timeout = NGX_CONF_UNSET_MSEC;
nacf->bufsize = NGX_CONF_UNSET_SIZE;
nscf->timeout = NGX_CONF_UNSET_MSEC;
nscf->bufsize = NGX_CONF_UNSET_SIZE;
nacf->log = &cf->cycle->new_log;
nscf->log = &cf->cycle->new_log;
return nacf;
return nscf;
}
static char *
ngx_rtmp_netcall_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_rtmp_netcall_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_rtmp_netcall_app_conf_t *prev = parent;
ngx_rtmp_netcall_app_conf_t *conf = child;
ngx_rtmp_netcall_srv_conf_t *prev = parent;
ngx_rtmp_netcall_srv_conf_t *conf = child;
ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 10000);
ngx_conf_merge_size_value(conf->bufsize, prev->bufsize, 1024);
@ -175,7 +175,7 @@ ngx_rtmp_netcall_create(ngx_rtmp_session_t *s, ngx_rtmp_netcall_init_t *ci)
ngx_rtmp_netcall_ctx_t *ctx;
ngx_peer_connection_t *pc;
ngx_rtmp_netcall_session_t *cs;
ngx_rtmp_netcall_app_conf_t *cacf;
ngx_rtmp_netcall_srv_conf_t *nscf;
ngx_connection_t *c, *cc;
ngx_pool_t *pool;
ngx_int_t rc;
@ -183,8 +183,8 @@ ngx_rtmp_netcall_create(ngx_rtmp_session_t *s, ngx_rtmp_netcall_init_t *ci)
pool = NULL;
c = s->connection;
cacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_netcall_module);
if (cacf == NULL) {
nscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_netcall_module);
if (nscf == NULL) {
goto error;
}
@ -203,7 +203,7 @@ ngx_rtmp_netcall_create(ngx_rtmp_session_t *s, ngx_rtmp_netcall_init_t *ci)
* Note we use shared (app-wide) log because
* s->connection->log might be unavailable
* in detached netcall when it's being closed */
pool = ngx_create_pool(4096, cacf->log);
pool = ngx_create_pool(4096, nscf->log);
if (pool == NULL) {
goto error;
}
@ -227,8 +227,8 @@ ngx_rtmp_netcall_create(ngx_rtmp_session_t *s, ngx_rtmp_netcall_init_t *ci)
ngx_memcpy(cs->arg, ci->arg, ci->argsize);
}
cs->timeout = cacf->timeout;
cs->bufsize = cacf->bufsize;
cs->timeout = nscf->timeout;
cs->bufsize = nscf->bufsize;
cs->url = ci->url;
cs->session = s;
cs->filter = ci->filter;
@ -238,7 +238,7 @@ ngx_rtmp_netcall_create(ngx_rtmp_session_t *s, ngx_rtmp_netcall_init_t *ci)
cs->detached = 1;
}
pc->log = cacf->log;
pc->log = nscf->log;
pc->get = ngx_rtmp_netcall_get_peer;
pc->free = ngx_rtmp_netcall_free_peer;
pc->data = cs;