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

1. Fixed recording start into new file when file size limit was reached. #2

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
1 change: 1 addition & 0 deletions ngx_rtmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ typedef struct ngx_rtmp_core_srv_conf_s {
size_t max_message;
ngx_flag_t play_time_fix;
ngx_flag_t publish_time_fix;
ngx_msec_t delta_pts_fix;
ngx_flag_t busy;
size_t out_queue;
size_t out_cork;
Expand Down
10 changes: 10 additions & 0 deletions ngx_rtmp_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ static ngx_command_t ngx_rtmp_core_commands[] = {
offsetof(ngx_rtmp_core_srv_conf_t, publish_time_fix),
NULL },

{ ngx_string("delta_pts_fix"),
NGX_RTMP_MAIN_CONF | NGX_RTMP_SRV_CONF | NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
NGX_RTMP_SRV_CONF_OFFSET,
offsetof(ngx_rtmp_core_srv_conf_t, delta_pts_fix),
NULL },

{ ngx_string("buflen"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
Expand Down Expand Up @@ -250,6 +257,7 @@ ngx_rtmp_core_create_srv_conf(ngx_conf_t *cf)
conf->publish_time_fix = NGX_CONF_UNSET;
conf->buflen = NGX_CONF_UNSET_MSEC;
conf->busy = NGX_CONF_UNSET;
conf->delta_pts_fix = NGX_CONF_UNSET_MSEC;

return conf;
}
Expand Down Expand Up @@ -279,6 +287,8 @@ ngx_rtmp_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_msec_value(conf->buflen, prev->buflen, 1000);
ngx_conf_merge_value(conf->busy, prev->busy, 0);

ngx_conf_merge_msec_value(conf->delta_pts_fix, prev->delta_pts_fix, 0);

if (prev->pool == NULL) {
prev->pool = ngx_create_pool(4096, &cf->cycle->new_log);
if (prev->pool == NULL) {
Expand Down
37 changes: 29 additions & 8 deletions ngx_rtmp_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,23 @@ ngx_rtmp_recv(ngx_event_t *rev)
}
}

ngx_log_debug8(NGX_LOG_DEBUG_RTMP, c->log, 0,
/*
st->dtime (pts delta) from some "Truen" cameras periodically contains illegal value - near 0xFFFFFFFF or 0x7FFFFFFF.
This code makes primitive fix of such deltas.
*/
if ((0!=cscf->delta_pts_fix) && (st->dtime > cscf->delta_pts_fix))//do workaround for invalid timestamp
{
ngx_log_error(NGX_LOG_WARN, c->log, 0,"RTMP mheader fmt=%d (%d) time=%uD+%uD mlen=%D len=%D msid=%D delta_pts_fix=%d st->dtime=%lu",(int)fmt, (int)h->type, h->timestamp, st->dtime, h->mlen, st->len, h->msid, cscf->delta_pts_fix, st->dtime);
st->dtime = 1;
}
else
{
ngx_log_debug8(NGX_LOG_DEBUG_RTMP, c->log, 0,
"RTMP mheader fmt=%d %s (%d) "
"time=%uD+%uD mlen=%D len=%D msid=%D",
(int)fmt, ngx_rtmp_message_type(h->type), (int)h->type,
h->timestamp, st->dtime, h->mlen, st->len, h->msid);
}

/* header done */
b->pos = p;
Expand Down Expand Up @@ -751,15 +763,24 @@ ngx_rtmp_send_message(ngx_rtmp_session_t *s, ngx_chain_t *out,

ngx_int_t
ngx_rtmp_receive_message(ngx_rtmp_session_t *s,
ngx_rtmp_header_t *h, ngx_chain_t *in)
ngx_rtmp_header_t *h, ngx_chain_t *in)
{
ngx_rtmp_core_main_conf_t *cmcf;
ngx_array_t *evhs;
size_t n;
ngx_rtmp_handler_pt *evh;

cmcf = ngx_rtmp_get_module_main_conf(s, ngx_rtmp_core_module);
ngx_rtmp_core_main_conf_t *cmcf;
ngx_array_t *evhs;
size_t n;
ngx_rtmp_handler_pt *evh;

cmcf = ngx_rtmp_get_module_main_conf(s, ngx_rtmp_core_module);
/*
if (h->type == NGX_RTMP_MSG_VIDEO)
{
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, "V LIVE RECV timestamp=%uD", h->timestamp);
}
else
{
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, "A LIVE RECV timestamp=%uD", h->timestamp);
}
*/
#ifdef NGX_DEBUG
{
int nbufs;
Expand Down
35 changes: 26 additions & 9 deletions ngx_rtmp_notify_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,23 +747,36 @@ ngx_rtmp_notify_record_done_create(ngx_rtmp_session_t *s, void *arg,
ngx_chain_t *pl;
ngx_buf_t *b;
size_t name_len, args_len;
char szFinishTime[16] = { 0 };
uint32_t buff_size = 0;

ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_notify_module);

pl = ngx_alloc_chain_link(pool);
if (pl == NULL) {
return NULL;
}

if(v->last_frame_time)
{
struct tm xtm;
ngx_libc_localtime(v->last_frame_time, &xtm);
strftime((char *)szFinishTime, sizeof(szFinishTime), "%Y%m%dT%H%M%S", &xtm);
}

name_len = ngx_strlen(ctx->name);
args_len = ngx_strlen(ctx->args);

b = ngx_create_temp_buf(pool,
sizeof("&call=record_done") +
sizeof("&recorder=") + v->recorder.len +
sizeof("&name=") + name_len * 3 +
sizeof("&path=") + v->path.len * 3 +
1 + args_len);
buff_size = sizeof("&call=record_done") +
sizeof("&recorder=") + v->recorder.len +
sizeof("&name=") + name_len * 3 +
sizeof("&path=") + v->path.len * 3 +
1 + args_len;

if (v->last_frame_time)
buff_size += sizeof("&endtime=") + sizeof(szFinishTime);

b = ngx_create_temp_buf(pool, buff_size);

if (b == NULL) {
return NULL;
}
Expand All @@ -786,14 +799,18 @@ ngx_rtmp_notify_record_done_create(ngx_rtmp_session_t *s, void *arg,
b->last = ngx_cpymem(b->last, (u_char*) "&path=", sizeof("&path=") - 1);
b->last = (u_char*) ngx_escape_uri(b->last, v->path.data, v->path.len,
NGX_ESCAPE_ARGS);
if (v->last_frame_time)
{
b->last = ngx_cpymem(b->last, (u_char*) "&endtime=", sizeof("&endtime=") - 1);
b->last = ngx_cpymem(b->last, (u_char*)szFinishTime, sizeof(szFinishTime) - 1);
}

if (args_len) {
*b->last++ = '&';
b->last = (u_char *) ngx_cpymem(b->last, ctx->args, args_len);
}

return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_RECORD_DONE,
pl);
return ngx_rtmp_notify_create_request(s, pool, NGX_RTMP_NOTIFY_RECORD_DONE, pl);
}


Expand Down
Loading