mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-18 17:21:08 +02:00
record append implemented
This commit is contained in:
parent
6903ac23e4
commit
349259329d
|
@ -89,6 +89,14 @@ static ngx_command_t ngx_rtmp_record_commands[] = {
|
|||
offsetof(ngx_rtmp_record_app_conf_t, unique),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("record_append"),
|
||||
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|
|
||||
NGX_RTMP_REC_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_flag_slot,
|
||||
NGX_RTMP_APP_CONF_OFFSET,
|
||||
offsetof(ngx_rtmp_record_app_conf_t, append),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("record_lock"),
|
||||
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|
|
||||
NGX_RTMP_REC_CONF|NGX_CONF_TAKE1,
|
||||
|
@ -184,6 +192,7 @@ ngx_rtmp_record_create_app_conf(ngx_conf_t *cf)
|
|||
racf->max_frames = NGX_CONF_UNSET;
|
||||
racf->interval = NGX_CONF_UNSET;
|
||||
racf->unique = NGX_CONF_UNSET;
|
||||
racf->append = NGX_CONF_UNSET;
|
||||
racf->lock_file = NGX_CONF_UNSET;
|
||||
racf->notify = NGX_CONF_UNSET;
|
||||
racf->url = NGX_CONF_UNSET_PTR;
|
||||
|
@ -208,6 +217,7 @@ ngx_rtmp_record_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||
ngx_conf_merge_size_value(conf->max_size, prev->max_size, 0);
|
||||
ngx_conf_merge_size_value(conf->max_frames, prev->max_frames, 0);
|
||||
ngx_conf_merge_value(conf->unique, prev->unique, 0);
|
||||
ngx_conf_merge_value(conf->append, prev->append, 0);
|
||||
ngx_conf_merge_value(conf->lock_file, prev->lock_file, 0);
|
||||
ngx_conf_merge_value(conf->notify, prev->notify, 0);
|
||||
ngx_conf_merge_msec_value(conf->interval, prev->interval,
|
||||
|
@ -421,6 +431,7 @@ ngx_rtmp_record_node_open(ngx_rtmp_session_t *s,
|
|||
ngx_rtmp_record_app_conf_t *rracf;
|
||||
ngx_err_t err;
|
||||
ngx_str_t path;
|
||||
ngx_int_t mode, create_mode;
|
||||
|
||||
rracf = rctx->conf;
|
||||
|
||||
|
@ -438,10 +449,13 @@ ngx_rtmp_record_node_open(ngx_rtmp_session_t *s,
|
|||
|
||||
ngx_rtmp_record_make_path(s, rctx, &path);
|
||||
|
||||
mode = rracf->append ? NGX_FILE_APPEND : NGX_FILE_WRONLY;
|
||||
create_mode = rracf->append ? NGX_FILE_CREATE_OR_OPEN : NGX_FILE_TRUNCATE;
|
||||
|
||||
ngx_memzero(&rctx->file, sizeof(rctx->file));
|
||||
rctx->file.offset = 0;
|
||||
rctx->file.log = s->connection->log;
|
||||
rctx->file.fd = ngx_open_file(path.data, NGX_FILE_WRONLY, NGX_FILE_TRUNCATE,
|
||||
rctx->file.fd = ngx_open_file(path.data, mode, create_mode,
|
||||
NGX_FILE_DEFAULT_ACCESS);
|
||||
|
||||
if (rctx->file.fd == NGX_INVALID_FILE) {
|
||||
|
@ -474,6 +488,20 @@ ngx_rtmp_record_node_open(ngx_rtmp_session_t *s,
|
|||
rracf->id.data ? (char *) rracf->id.data : "");
|
||||
}
|
||||
|
||||
if (rracf->append) {
|
||||
/* need non-zero offset to skip header */
|
||||
rctx->file.offset = lseek(rctx->file.fd, 0, SEEK_END);
|
||||
if (rctx->file.offset == (off_t) -1) {
|
||||
ngx_log_error(NGX_LOG_CRIT, s->connection->log, ngx_errno,
|
||||
"record: %V seek failed", &rracf->id);
|
||||
lseek(rctx->file.fd, 0, SEEK_SET);
|
||||
rctx->file.offset = 0;
|
||||
} else {
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"record: append offset=%O", rctx->file.offset);
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
@ -948,7 +976,9 @@ ngx_rtmp_record_node_av(ngx_rtmp_session_t *s, ngx_rtmp_record_rec_ctx_t *rctx,
|
|||
}
|
||||
|
||||
if (rctx->file.offset == 0) {
|
||||
rctx->epoch = h->timestamp;
|
||||
if (!rracf->append) {
|
||||
rctx->epoch = h->timestamp;
|
||||
}
|
||||
|
||||
if (ngx_rtmp_record_write_header(&rctx->file) != NGX_OK) {
|
||||
ngx_rtmp_record_node_close(s, rctx);
|
||||
|
|
|
@ -26,6 +26,7 @@ typedef struct {
|
|||
ngx_msec_t interval;
|
||||
ngx_str_t suffix;
|
||||
ngx_flag_t unique;
|
||||
ngx_flag_t append;
|
||||
ngx_flag_t lock_file;
|
||||
ngx_flag_t notify;
|
||||
ngx_url_t *url;
|
||||
|
|
Loading…
Reference in a new issue