Fix callback names, add FCUnpublish callback

This commit is contained in:
Sergey Dryabzhinsky 2015-09-17 21:14:02 +03:00
parent 414053862c
commit 8fda94268c
3 changed files with 107 additions and 2 deletions

View file

@ -587,6 +587,7 @@ ngx_int_t ngx_rtmp_send_redirect_status(ngx_rtmp_session_t *s,
char *callMethod, char *desc, ngx_str_t to_url);
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);
/* Frame types */

View file

@ -1226,6 +1226,39 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
}
static ngx_int_t
ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_chain_t *in)
{
ngx_rtmp_live_app_conf_t *lacf;
ngx_rtmp_live_ctx_t *ctx;
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
if (lacf == NULL) {
return NGX_ERROR;
}
if (!lacf->live || in == NULL || in->buf == NULL) {
return NGX_OK;
}
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
if (ctx == NULL || ctx->stream == NULL) {
return NGX_OK;
}
// Probably wrong. Need testing, debug-log.
if (ctx->publishing == 0) {
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
"live: FCUnpublish from non-publisher: name=%s, ip=%s", ctx->stream->name, s->addr_text);
return NGX_OK;
}
return ngx_rtmp_send_fcunpublish(s, ctx->stream->name);
}
static ngx_int_t
ngx_rtmp_live_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
{
@ -1352,8 +1385,12 @@ ngx_rtmp_live_postconfiguration(ngx_conf_t *cf)
ch->handler = ngx_rtmp_live_on_fi;
ch = ngx_array_push(&cmcf->amf);
ngx_str_set(&ch->name, "onFCPublish");
ngx_str_set(&ch->name, "FCPublish");
ch->handler = ngx_rtmp_live_on_fcpublish;
ch = ngx_array_push(&cmcf->amf);
ngx_str_set(&ch->name, "FCUnpublish");
ch->handler = ngx_rtmp_live_on_fcunpublish;
return NGX_OK;
}

View file

@ -779,7 +779,7 @@ ngx_rtmp_create_fcpublish(ngx_rtmp_session_t *s, char *desc)
desc);
out_inf[2].data = desc;
trans = 0;
trans = 3.0; // magick from ffmpeg
memset(&h, 0, sizeof(h));
@ -800,6 +800,73 @@ ngx_rtmp_send_fcpublish(ngx_rtmp_session_t *s, char *desc)
}
ngx_chain_t *
ngx_rtmp_create_fcunpublish(ngx_rtmp_session_t *s, char *desc)
{
ngx_rtmp_header_t h;
static double trans;
static ngx_rtmp_amf_elt_t out_inf[] = {
{ NGX_RTMP_AMF_STRING,
ngx_string("level"),
"status", 0 },
{ NGX_RTMP_AMF_STRING,
ngx_string("code"),
"NetStream.Unpublish.Success", 0 },
{ NGX_RTMP_AMF_STRING,
ngx_string("description"),
NULL, 0 },
};
static ngx_rtmp_amf_elt_t out_elts[] = {
{ NGX_RTMP_AMF_STRING,
ngx_null_string,
"onFCUnpublish", 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) },
};
ngx_log_error(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"create: fcunpublish desc='%s'",
desc);
out_inf[2].data = desc;
trans = 5.0; // magick from ffmpeg
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_fcunpublish(ngx_rtmp_session_t *s, char *desc)
{
return ngx_rtmp_send_shared_packet(s,
ngx_rtmp_create_fcunpublish(s, desc));
}
ngx_chain_t *
ngx_rtmp_create_sample_access(ngx_rtmp_session_t *s)
{