Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #1249 bug #1481

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,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 \
"


Expand Down
58 changes: 42 additions & 16 deletions ngx_rtmp_record_module.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

/*
* Copyright (C) Roman Arutyunyan
* Copyright (C) Winshining
*/


Expand Down Expand Up @@ -42,6 +43,7 @@ static ngx_int_t ngx_rtmp_record_node_close(ngx_rtmp_session_t *s,
static void ngx_rtmp_record_make_path(ngx_rtmp_session_t *s,
ngx_rtmp_record_rec_ctx_t *rctx, ngx_str_t *path);
static ngx_int_t ngx_rtmp_record_init(ngx_rtmp_session_t *s);
static ngx_int_t ngx_rtmp_record_init_ctx(ngx_rtmp_session_t *s);


static ngx_conf_bitmask_t ngx_rtmp_record_mask[] = {
Expand Down Expand Up @@ -589,14 +591,14 @@ ngx_rtmp_record_node_open(ngx_rtmp_session_t *s,
static ngx_int_t
ngx_rtmp_record_init(ngx_rtmp_session_t *s)
{
ngx_uint_t n;
ngx_rtmp_record_app_conf_t *racf, **rracf;
ngx_rtmp_record_rec_ctx_t *rctx;
ngx_rtmp_record_ctx_t *ctx;
ngx_uint_t n;

ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_record_module);

if (ctx) {
if (ctx && !s->auto_pushed) {
return NGX_OK;
}

Expand All @@ -606,13 +608,11 @@ ngx_rtmp_record_init(ngx_rtmp_session_t *s)
return NGX_OK;
}

ctx = ngx_pcalloc(s->connection->pool, sizeof(ngx_rtmp_record_ctx_t));

if (ctx == NULL) {
if (ngx_rtmp_record_init_ctx(s) != NGX_OK) {
return NGX_ERROR;
}

ngx_rtmp_set_ctx(s, ctx, ngx_rtmp_record_module);
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_record_module);

if (ngx_array_init(&ctx->rec, s->connection->pool, racf->rec.nelts,
sizeof(ngx_rtmp_record_rec_ctx_t))
Expand Down Expand Up @@ -640,6 +640,26 @@ ngx_rtmp_record_init(ngx_rtmp_session_t *s)
}


static ngx_int_t
ngx_rtmp_record_init_ctx(ngx_rtmp_session_t *s)
{
ngx_rtmp_record_ctx_t *ctx;

ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_record_module);
if (ctx == NULL) {
ctx = ngx_pcalloc(s->connection->pool, sizeof(ngx_rtmp_record_ctx_t));

if (ctx == NULL) {
return NGX_ERROR;
}

ngx_rtmp_set_ctx(s, ctx, ngx_rtmp_record_module);
}

return NGX_OK;
}


static void
ngx_rtmp_record_start(ngx_rtmp_session_t *s)
{
Expand Down Expand Up @@ -706,24 +726,22 @@ ngx_rtmp_record_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
ngx_rtmp_record_ctx_t *ctx;
u_char *p;

if (s->auto_pushed) {
goto next;
}

racf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_record_module);

if (racf == NULL || racf->rec.nelts == 0) {
goto next;
}

if (ngx_rtmp_record_init(s) != NGX_OK) {
return NGX_ERROR;
if (s->auto_pushed) {
if (ngx_rtmp_record_init_ctx(s) != NGX_OK) {
return NGX_ERROR;
}
} else {
if (ngx_rtmp_record_init(s) != NGX_OK) {
return NGX_ERROR;
}
}

ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"record: publish %ui nodes",
racf->rec.nelts);

ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_record_module);

ngx_memcpy(ctx->name, v->name, sizeof(ctx->name));
Expand All @@ -740,6 +758,14 @@ ngx_rtmp_record_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
}
}

if (s->auto_pushed) {
goto next;
}

ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"record: publish %ui nodes",
racf->rec.nelts);

ngx_rtmp_record_start(s);

next:
Expand Down