Append support of Fi command. Return system date and time.

This commit is contained in:
Sergey Dryabzhinsky 2015-09-18 23:24:45 +03:00
parent 7abda68ef7
commit a344ee6607
3 changed files with 103 additions and 10 deletions

View file

@ -588,6 +588,7 @@ ngx_int_t ngx_rtmp_send_redirect_status(ngx_rtmp_session_t *s,
ngx_int_t ngx_rtmp_send_close_method(ngx_rtmp_session_t *s, char *methodName);
ngx_int_t ngx_rtmp_send_fcpublish(ngx_rtmp_session_t *s, char *desc);
ngx_int_t ngx_rtmp_send_fcunpublish(ngx_rtmp_session_t *s, char *desc);
ngx_int_t ngx_rtmp_send_fi(ngx_rtmp_session_t *s);
/* Frame types */

View file

@ -1183,15 +1183,22 @@ static ngx_int_t
ngx_rtmp_live_on_fi(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_chain_t *in)
{
static ngx_rtmp_amf_elt_t out_elts[] = {
ngx_rtmp_live_app_conf_t *lacf;
{ NGX_RTMP_AMF_STRING,
ngx_null_string,
"onFi", 0 }
};
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
if (lacf == NULL) {
ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0,
"live: Fi - no live config!");
return NGX_ERROR;
}
return ngx_rtmp_live_data(s, h, in, out_elts,
sizeof(out_elts) / sizeof(out_elts[0]));
if (!lacf->live || in == NULL || in->buf == NULL) {
ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0,
"live: Fi - no live or no buffer!");
return NGX_OK;
}
return ngx_rtmp_send_fi(s);
}
static ngx_int_t
@ -1200,7 +1207,6 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
{
ngx_rtmp_live_app_conf_t *lacf;
ngx_rtmp_live_ctx_t *ctx;
static struct {
double trans;
@ -1259,7 +1265,6 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
{
ngx_rtmp_live_app_conf_t *lacf;
ngx_rtmp_live_ctx_t *ctx;
static struct {
double trans;
@ -1434,7 +1439,7 @@ ngx_rtmp_live_postconfiguration(ngx_conf_t *cf)
ch->handler = ngx_rtmp_live_on_cue_point;
ch = ngx_array_push(&cmcf->amf);
ngx_str_set(&ch->name, "onFi");
ngx_str_set(&ch->name, "Fi");
ch->handler = ngx_rtmp_live_on_fi;
ch = ngx_array_push(&cmcf->amf);

View file

@ -3,6 +3,7 @@
* Copyright (C) Roman Arutyunyan
*/
#include <sys/time.h>
#include <ngx_config.h>
#include <ngx_core.h>
@ -867,6 +868,92 @@ ngx_rtmp_send_fcunpublish(ngx_rtmp_session_t *s, char *desc)
}
ngx_chain_t *
ngx_rtmp_create_fi(ngx_rtmp_session_t *s)
{
ngx_rtmp_header_t h;
static double trans;
struct tm tm;
struct timeval tv;
struct timezone tz;
int errfl;
static u_char buf_time[NGX_TIME_T_LEN + 1];
static u_char buf_date[NGX_TIME_T_LEN + 1];
static ngx_rtmp_amf_elt_t out_inf[] = {
{ NGX_RTMP_AMF_STRING,
ngx_string("st"),
NULL, 0 },
{ NGX_RTMP_AMF_STRING,
ngx_string("sd"),
NULL, 0 },
};
static ngx_rtmp_amf_elt_t out_elts[] = {
{ NGX_RTMP_AMF_STRING,
ngx_null_string,
"onFi", 0 },
{ NGX_RTMP_AMF_NUMBER,
ngx_null_string,
&trans, 0 },
{ NGX_RTMP_AMF_NULL,
ngx_null_string,
NULL, 0 },
{ NGX_RTMP_AMF_OBJECT,
ngx_null_string,
out_inf,
sizeof(out_inf) },
};
trans = 0;
errfl = gettimeofday(&tv, &tz);
if (errfl) {
ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0,
"create: fi - can't get time!");
return NULL;
}
ngx_libc_localtime((time_t)tv.tv_sec, &tm);
memset(buf_time, 0, sizeof(buf_time));
memset(buf_date, 0, sizeof(buf_date));
errfl = sprintf(buf_time, "%02d:%02d:%02d.%d", tm.tm_hour, tm.tm_min, tm.tm_sec, (int)tv.tv_usec);
errfl = sprintf(buf_date, "%04d-%02d-%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
out_inf[0].data = buf_time;
out_inf[1].data = buf_date;
memset(&h, 0, sizeof(h));
h.type = NGX_RTMP_MSG_AMF_CMD;
h.csid = NGX_RTMP_CSID_AMF;
h.msid = NGX_RTMP_MSID;
return ngx_rtmp_create_amf(s, &h, out_elts,
sizeof(out_elts) / sizeof(out_elts[0]));
}
ngx_int_t
ngx_rtmp_send_fi(ngx_rtmp_session_t *s)
{
return ngx_rtmp_send_shared_packet(s,
ngx_rtmp_create_fi(s));
}
ngx_chain_t *
ngx_rtmp_create_sample_access(ngx_rtmp_session_t *s)
{