Fix onFi handler

This commit is contained in:
Sergey Dryabzhinsky 2015-09-19 03:03:13 +03:00
parent a344ee6607
commit b666598e3a
2 changed files with 75 additions and 5 deletions

View file

@ -1184,6 +1184,55 @@ ngx_rtmp_live_on_fi(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_chain_t *in)
{
ngx_rtmp_live_app_conf_t *lacf;
ngx_int_t res;
static struct {
u_char time[NGX_TIME_T_LEN + 1];
u_char date[NGX_TIME_T_LEN + 1];
} v;
static ngx_rtmp_amf_elt_t in_dt_elts[] = {
{ NGX_RTMP_AMF_STRING,
ngx_string("sd"),
&v.date, sizeof(v.date) },
{ NGX_RTMP_AMF_STRING,
ngx_string("st"),
&v.time, sizeof(v.time) },
};
static ngx_rtmp_amf_elt_t in_elts[] = {
{ NGX_RTMP_AMF_MIXED_ARRAY,
ngx_null_string,
in_dt_elts, sizeof(in_dt_elts) },
};
static ngx_rtmp_amf_elt_t out_dt_elts[] = {
{ NGX_RTMP_AMF_STRING,
ngx_string("sd"),
NULL, 0 },
{ NGX_RTMP_AMF_STRING,
ngx_string("st"),
NULL, 0 },
};
static ngx_rtmp_amf_elt_t out_elts[] = {
{ NGX_RTMP_AMF_STRING,
ngx_null_string,
"onFi", 0 },
{ NGX_RTMP_AMF_MIXED_ARRAY,
ngx_null_string,
out_dt_elts, sizeof(out_dt_elts) },
};
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
if (lacf == NULL) {
@ -1198,7 +1247,27 @@ ngx_rtmp_live_on_fi(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
return NGX_OK;
}
return ngx_rtmp_send_fi(s);
ngx_memzero(&v, sizeof(v));
res = ngx_rtmp_receive_amf(s, in, in_elts,
sizeof(in_elts) / sizeof(in_elts[0]));
if (res == NGX_OK) {
ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0,
"live: onFi: date='%s', time='%s'",
v.date, v.time);
out_dt_elts[0].data = v.date;
out_dt_elts[1].data = v.time;
// Pass through datetime from publisher
return ngx_rtmp_live_data(s, h, in, out_elts,
sizeof(out_elts) / sizeof(out_elts[0]));
} else {
// Send our server datetime
return ngx_rtmp_send_fi(s);
}
}
static ngx_int_t
@ -1439,7 +1508,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, "Fi");
ngx_str_set(&ch->name, "onFi");
ch->handler = ngx_rtmp_live_on_fi;
ch = ngx_array_push(&cmcf->amf);

View file

@ -926,11 +926,12 @@ ngx_rtmp_create_fi(ngx_rtmp_session_t *s)
ngx_libc_localtime((time_t)tv.tv_sec, &tm);
memset(buf_time, 0, sizeof(buf_time));
memset(buf_date, 0, sizeof(buf_date));
ngx_memzero(buf_time, sizeof(buf_time));
ngx_memzero(buf_date, 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);
// Strange order, but FMLE send like this
errfl = sprintf(buf_date, "%02d-%02d-%04d", tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
out_inf[0].data = buf_time;
out_inf[1].data = buf_date;