From f29fbc89a4f59d171e856edd508781b417e3b736 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Thu, 17 Sep 2015 14:13:29 +0300 Subject: [PATCH 01/10] Add dummy response for onFCPublish --- ngx_rtmp_live_module.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index 888c61f..f31198f 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -1194,6 +1194,21 @@ ngx_rtmp_live_on_fi(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, sizeof(out_elts) / sizeof(out_elts[0])); } +static ngx_int_t +ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, + ngx_chain_t *in) +{ + static ngx_rtmp_amf_elt_t out_elts[] = { + + { NGX_RTMP_AMF_STRING, + ngx_null_string, + "onFCPublish", 0 } + }; + + return ngx_rtmp_live_data(s, h, in, out_elts, + sizeof(out_elts) / sizeof(out_elts[0])); +} + static ngx_int_t ngx_rtmp_live_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v) @@ -1320,5 +1335,9 @@ ngx_rtmp_live_postconfiguration(ngx_conf_t *cf) ngx_str_set(&ch->name, "onFi"); ch->handler = ngx_rtmp_live_on_fi; + ch = ngx_array_push(&cmcf->amf); + ngx_str_set(&ch->name, "onFCPublish"); + ch->handler = ngx_rtmp_live_on_fcpublish; + return NGX_OK; } From 414053862c61b80c42d754e7d8509d7c91680028 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Thu, 17 Sep 2015 20:12:24 +0300 Subject: [PATCH 02/10] Add amf sender for FCPublish --- ngx_rtmp.h | 1 + ngx_rtmp_live_module.c | 30 ++++++++++++++----- ngx_rtmp_send.c | 67 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/ngx_rtmp.h b/ngx_rtmp.h index c3fa8ee..0674a6e 100644 --- a/ngx_rtmp.h +++ b/ngx_rtmp.h @@ -586,6 +586,7 @@ ngx_int_t ngx_rtmp_send_sample_access(ngx_rtmp_session_t *s); 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); /* Frame types */ diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index f31198f..1316d32 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -1198,15 +1198,31 @@ static ngx_int_t ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, ngx_chain_t *in) { - static ngx_rtmp_amf_elt_t out_elts[] = { - { NGX_RTMP_AMF_STRING, - ngx_null_string, - "onFCPublish", 0 } - }; + ngx_rtmp_live_app_conf_t *lacf; + ngx_rtmp_live_ctx_t *ctx; - return ngx_rtmp_live_data(s, h, in, out_elts, - sizeof(out_elts) / sizeof(out_elts[0])); + 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; + } + + if (ctx->publishing == 0) { + ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, + "live: FCPublish from non-publisher: name=%s, ip=%s", ctx->stream->name, s->addr_text); + return NGX_OK; + } + + return ngx_rtmp_send_fcpublish(s, ctx->stream->name); } diff --git a/ngx_rtmp_send.c b/ngx_rtmp_send.c index d2e2c4b..6cb19f4 100644 --- a/ngx_rtmp_send.c +++ b/ngx_rtmp_send.c @@ -733,6 +733,73 @@ ngx_rtmp_send_close_method(ngx_rtmp_session_t *s, char *methodName) } +ngx_chain_t * +ngx_rtmp_create_fcpublish(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.Publish.Start", 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, + "onFCPublish", 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: fcpublish desc='%s'", + desc); + + out_inf[2].data = desc; + trans = 0; + + 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_fcpublish(ngx_rtmp_session_t *s, char *desc) +{ + return ngx_rtmp_send_shared_packet(s, + ngx_rtmp_create_fcpublish(s, desc)); +} + + ngx_chain_t * ngx_rtmp_create_sample_access(ngx_rtmp_session_t *s) { From 8fda94268cda79373d692239bbdaecaf0040a339 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Thu, 17 Sep 2015 21:14:02 +0300 Subject: [PATCH 03/10] Fix callback names, add FCUnpublish callback --- ngx_rtmp.h | 1 + ngx_rtmp_live_module.c | 39 +++++++++++++++++++++++- ngx_rtmp_send.c | 69 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/ngx_rtmp.h b/ngx_rtmp.h index 0674a6e..06e728b 100644 --- a/ngx_rtmp.h +++ b/ngx_rtmp.h @@ -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 */ diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index 1316d32..186d272 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -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; } diff --git a/ngx_rtmp_send.c b/ngx_rtmp_send.c index 6cb19f4..30bb134 100644 --- a/ngx_rtmp_send.c +++ b/ngx_rtmp_send.c @@ -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) { From 100ecc4fe861379e79fec65a7ae681ca8c5122d5 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Fri, 18 Sep 2015 00:35:26 +0300 Subject: [PATCH 04/10] Second version of callbacks: - more debug output - moved code from send module --- ngx_rtmp_live_module.c | 114 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index 186d272..9706f0c 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -1204,25 +1204,78 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, 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: FCPublish - no live config!"); return NGX_ERROR; } if (!lacf->live || in == NULL || in->buf == NULL) { + ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, + "live: FCPublish - no live or no buffer!"); return NGX_OK; } ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module); if (ctx == NULL || ctx->stream == NULL) { + ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, + "live: FCPublish - no context or no stream!"); return NGX_OK; } - if (ctx->publishing == 0) { +/* if (ctx->publishing == 0) { ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, "live: FCPublish from non-publisher: name=%s, ip=%s", ctx->stream->name, s->addr_text); return NGX_OK; } +*/ - return ngx_rtmp_send_fcpublish(s, ctx->stream->name); + 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.Publish.Start", 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, + "onFCPublish", 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, s->connection->log, 0, + "create: fcpublish stream='%s'", ctx->stream->name); + + out_inf[2].data = ctx->stream->name; + trans = 3.0; // magick from ffmpeg + +// return ngx_rtmp_send_fcpublish(s, ctx->stream->name); + + return ngx_rtmp_live_data(s, h, in, out_elts, + sizeof(out_elts) / sizeof(out_elts[0])); } @@ -1236,26 +1289,79 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, 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: FCUnpublish - no live config!"); return NGX_ERROR; } if (!lacf->live || in == NULL || in->buf == NULL) { + ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, + "live: FCUnpublish - no live or no buffer!"); return NGX_OK; } ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module); if (ctx == NULL || ctx->stream == NULL) { + ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, + "live: FCUnpublish - no context or no stream!"); return NGX_OK; } // Probably wrong. Need testing, debug-log. - if (ctx->publishing == 0) { +/* 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 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, s->connection->log, 0, + "create: fcunpublish stream='%s'", ctx->stream->name); + + out_inf[2].data = ctx->stream->name; + trans = 5.0; // magick from ffmpeg + +// return ngx_rtmp_send_fcunpublish(s, ctx->stream->name); + + return ngx_rtmp_live_data(s, h, in, out_elts, + sizeof(out_elts) / sizeof(out_elts[0])); } From 5d6ea2314f014ccd849d317b31e8427dfbe194f5 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Fri, 18 Sep 2015 01:56:10 +0300 Subject: [PATCH 05/10] Change magick numbers --- ngx_rtmp_live_module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index 9706f0c..491eb67 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -1270,7 +1270,7 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, "create: fcpublish stream='%s'", ctx->stream->name); out_inf[2].data = ctx->stream->name; - trans = 3.0; // magick from ffmpeg + trans = 0; // return ngx_rtmp_send_fcpublish(s, ctx->stream->name); @@ -1356,7 +1356,7 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, "create: fcunpublish stream='%s'", ctx->stream->name); out_inf[2].data = ctx->stream->name; - trans = 5.0; // magick from ffmpeg + trans = 0; // return ngx_rtmp_send_fcunpublish(s, ctx->stream->name); From b4bbfff24b0d340f6bdc96ecc732133d5e21b6d9 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Fri, 18 Sep 2015 02:08:50 +0300 Subject: [PATCH 06/10] Change magick numbers in send module --- ngx_rtmp_send.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ngx_rtmp_send.c b/ngx_rtmp_send.c index 30bb134..e7b86a2 100644 --- a/ngx_rtmp_send.c +++ b/ngx_rtmp_send.c @@ -779,7 +779,8 @@ ngx_rtmp_create_fcpublish(ngx_rtmp_session_t *s, char *desc) desc); out_inf[2].data = desc; - trans = 3.0; // magick from ffmpeg +// trans = 3.0; // magick from ffmpeg + trans = 0; memset(&h, 0, sizeof(h)); @@ -846,7 +847,8 @@ ngx_rtmp_create_fcunpublish(ngx_rtmp_session_t *s, char *desc) desc); out_inf[2].data = desc; - trans = 5.0; // magick from ffmpeg +// trans = 5.0; // magick from ffmpeg + trans = 0; memset(&h, 0, sizeof(h)); From 091936ea2dfcd3124b0ad0cdc481a699bed4bc96 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Fri, 18 Sep 2015 19:10:38 +0300 Subject: [PATCH 07/10] Trying to recieve fc(un)publish data - there is no stream at the moment. --- ngx_rtmp_live_module.c | 123 +++++++++++++++++++++++++++++++++-------- 1 file changed, 99 insertions(+), 24 deletions(-) diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index 491eb67..546749c 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -1202,6 +1202,38 @@ 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; + u_char action[128]; + u_char stream[1024]; + } v; + + static ngx_rtmp_amf_elt_t in_elts[] = { + + { NGX_RTMP_AMF_STRING, + ngx_null_string, + &v.action, 0 }, + + { NGX_RTMP_AMF_NUMBER, + ngx_null_string, + &v.trans, 0 }, + + { NGX_RTMP_AMF_NULL, + ngx_null_string, + NULL, 0 }, + + { NGX_RTMP_AMF_STRING, + ngx_null_string, + &v.stream, 0 }, + }; + + static ngx_rtmp_amf_elt_t in_elts_meta[] = { + + { NGX_RTMP_AMF_OBJECT, + ngx_null_string, + in_inf, sizeof(in_inf) }, + }; + 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, @@ -1216,19 +1248,28 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, } ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module); - if (ctx == NULL || ctx->stream == NULL) { + if (ctx == NULL) { ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, - "live: FCPublish - no context or no stream!"); + "live: FCPublish - no context!"); return NGX_OK; } -/* if (ctx->publishing == 0) { - ngx_log_error(NGX_LOG_INFO, s->connection->log, 0, - "live: FCPublish from non-publisher: name=%s, ip=%s", ctx->stream->name, s->addr_text); - return NGX_OK; + ngx_memzero(&v, sizeof(v)); + if (h->type == NGX_RTMP_MSG_AMF_META) { + ngx_rtmp_receive_amf(s, in, in_elts_meta, + sizeof(in_elts_meta) / sizeof(in_elts_meta[0])); + } else { + ngx_rtmp_receive_amf(s, in, in_elts, + sizeof(in_elts) / sizeof(in_elts[0])); } -*/ + ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, + "live: onFCPublish: action='%s' stream='%s'", + v.action, v.stream); + + return ngx_rtmp_send_fcpublish(s, v.stream); + +/* static double trans; static ngx_rtmp_amf_elt_t out_inf[] = { @@ -1243,7 +1284,7 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, { NGX_RTMP_AMF_STRING, ngx_string("description"), - NULL, 0 }, + v.stream, 0 }, }; static ngx_rtmp_amf_elt_t out_elts[] = { @@ -1266,16 +1307,11 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, sizeof(out_inf) }, }; - ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, - "create: fcpublish stream='%s'", ctx->stream->name); - - out_inf[2].data = ctx->stream->name; trans = 0; -// return ngx_rtmp_send_fcpublish(s, ctx->stream->name); - return ngx_rtmp_live_data(s, h, in, out_elts, sizeof(out_elts) / sizeof(out_elts[0])); + */ } @@ -1287,6 +1323,38 @@ 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; + u_char action[128]; + u_char stream[1024]; + } v; + + static ngx_rtmp_amf_elt_t in_elts[] = { + + { NGX_RTMP_AMF_STRING, + ngx_null_string, + &v.action, 0 }, + + { NGX_RTMP_AMF_NUMBER, + ngx_null_string, + &v.trans, 0 }, + + { NGX_RTMP_AMF_NULL, + ngx_null_string, + NULL, 0 }, + + { NGX_RTMP_AMF_STRING, + ngx_null_string, + &v.stream, 0 }, + }; + + static ngx_rtmp_amf_elt_t in_elts_meta[] = { + + { NGX_RTMP_AMF_OBJECT, + ngx_null_string, + in_inf, sizeof(in_inf) }, + }; + 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, @@ -1301,20 +1369,28 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, } ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module); - if (ctx == NULL || ctx->stream == NULL) { + if (ctx == NULL) { ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, - "live: FCUnpublish - no context or no stream!"); + "live: FCUnpublish - no context!"); 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; + ngx_memzero(&v, sizeof(v)); + if (h->type == NGX_RTMP_MSG_AMF_META) { + ngx_rtmp_receive_amf(s, in, in_elts_meta, + sizeof(in_elts_meta) / sizeof(in_elts_meta[0])); + } else { + ngx_rtmp_receive_amf(s, in, in_elts, + sizeof(in_elts) / sizeof(in_elts[0])); } -*/ + ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, + "live: onFCUnpublish: action='%s' stream='%s'", + v.action, v.stream); + + return ngx_rtmp_send_fcunpublish(s, v.stream); + +/* static double trans; static ngx_rtmp_amf_elt_t out_inf[] = { @@ -1358,10 +1434,9 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, out_inf[2].data = ctx->stream->name; trans = 0; -// return ngx_rtmp_send_fcunpublish(s, ctx->stream->name); - return ngx_rtmp_live_data(s, h, in, out_elts, sizeof(out_elts) / sizeof(out_elts[0])); + */ } From 498ff9a46883998c994d3a20fabc4db839ff4244 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Fri, 18 Sep 2015 19:30:56 +0300 Subject: [PATCH 08/10] Fix unused vars --- ngx_rtmp_live_module.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index 546749c..419a455 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -1227,13 +1227,6 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, &v.stream, 0 }, }; - static ngx_rtmp_amf_elt_t in_elts_meta[] = { - - { NGX_RTMP_AMF_OBJECT, - ngx_null_string, - in_inf, sizeof(in_inf) }, - }; - 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, @@ -1255,13 +1248,8 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, } ngx_memzero(&v, sizeof(v)); - if (h->type == NGX_RTMP_MSG_AMF_META) { - ngx_rtmp_receive_amf(s, in, in_elts_meta, - sizeof(in_elts_meta) / sizeof(in_elts_meta[0])); - } else { - ngx_rtmp_receive_amf(s, in, in_elts, - sizeof(in_elts) / sizeof(in_elts[0])); - } + ngx_rtmp_receive_amf(s, in, in_elts, + sizeof(in_elts) / sizeof(in_elts[0])); ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, "live: onFCPublish: action='%s' stream='%s'", @@ -1348,13 +1336,6 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, &v.stream, 0 }, }; - static ngx_rtmp_amf_elt_t in_elts_meta[] = { - - { NGX_RTMP_AMF_OBJECT, - ngx_null_string, - in_inf, sizeof(in_inf) }, - }; - 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, @@ -1376,13 +1357,8 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, } ngx_memzero(&v, sizeof(v)); - if (h->type == NGX_RTMP_MSG_AMF_META) { - ngx_rtmp_receive_amf(s, in, in_elts_meta, - sizeof(in_elts_meta) / sizeof(in_elts_meta[0])); - } else { - ngx_rtmp_receive_amf(s, in, in_elts, - sizeof(in_elts) / sizeof(in_elts[0])); - } + ngx_rtmp_receive_amf(s, in, in_elts, + sizeof(in_elts) / sizeof(in_elts[0])); ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, "live: onFCUnpublish: action='%s' stream='%s'", From 5b62a17516cd60fd6c1bd6907d79041e56a627e6 Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Fri, 18 Sep 2015 19:56:13 +0300 Subject: [PATCH 09/10] Remove ctx checks - not in context? Not used thou. --- ngx_rtmp_live_module.c | 106 ----------------------------------------- 1 file changed, 106 deletions(-) diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index 419a455..ed6a15b 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -1240,13 +1240,6 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, return NGX_OK; } - ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module); - if (ctx == NULL) { - ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, - "live: FCPublish - no context!"); - return NGX_OK; - } - ngx_memzero(&v, sizeof(v)); ngx_rtmp_receive_amf(s, in, in_elts, sizeof(in_elts) / sizeof(in_elts[0])); @@ -1256,50 +1249,6 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, v.action, v.stream); return ngx_rtmp_send_fcpublish(s, v.stream); - -/* - 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.Publish.Start", 0 }, - - { NGX_RTMP_AMF_STRING, - ngx_string("description"), - v.stream, 0 }, - }; - - static ngx_rtmp_amf_elt_t out_elts[] = { - - { NGX_RTMP_AMF_STRING, - ngx_null_string, - "onFCPublish", 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; - - return ngx_rtmp_live_data(s, h, in, out_elts, - sizeof(out_elts) / sizeof(out_elts[0])); - */ } @@ -1349,13 +1298,6 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, return NGX_OK; } - ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module); - if (ctx == NULL) { - ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, - "live: FCUnpublish - no context!"); - return NGX_OK; - } - ngx_memzero(&v, sizeof(v)); ngx_rtmp_receive_amf(s, in, in_elts, sizeof(in_elts) / sizeof(in_elts[0])); @@ -1365,54 +1307,6 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, v.action, v.stream); return ngx_rtmp_send_fcunpublish(s, v.stream); - -/* - 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, s->connection->log, 0, - "create: fcunpublish stream='%s'", ctx->stream->name); - - out_inf[2].data = ctx->stream->name; - trans = 0; - - return ngx_rtmp_live_data(s, h, in, out_elts, - sizeof(out_elts) / sizeof(out_elts[0])); - */ } From 83cb5a6f909c85fe20dab6b4d50e484880e11d9f Mon Sep 17 00:00:00 2001 From: Sergey Dryabzhinsky Date: Fri, 18 Sep 2015 21:18:50 +0300 Subject: [PATCH 10/10] Seems like action name is readed before. Try to fix reading string length. --- ngx_rtmp_live_module.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ngx_rtmp_live_module.c b/ngx_rtmp_live_module.c index ed6a15b..45d6aab 100644 --- a/ngx_rtmp_live_module.c +++ b/ngx_rtmp_live_module.c @@ -1210,10 +1210,11 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, static ngx_rtmp_amf_elt_t in_elts[] = { - { NGX_RTMP_AMF_STRING, +// Already readed +/* { NGX_RTMP_AMF_STRING, ngx_null_string, - &v.action, 0 }, - + &v.action, sizeof(v.action) }, +*/ { NGX_RTMP_AMF_NUMBER, ngx_null_string, &v.trans, 0 }, @@ -1224,7 +1225,7 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, { NGX_RTMP_AMF_STRING, ngx_null_string, - &v.stream, 0 }, + &v.stream, sizeof(v.stream) }, }; lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module); @@ -1245,8 +1246,8 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, sizeof(in_elts) / sizeof(in_elts[0])); ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, - "live: onFCPublish: action='%s' stream='%s'", - v.action, v.stream); + "live: onFCPublish: stream='%s'", + v.stream); return ngx_rtmp_send_fcpublish(s, v.stream); } @@ -1268,10 +1269,11 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, static ngx_rtmp_amf_elt_t in_elts[] = { - { NGX_RTMP_AMF_STRING, +// Already readed +/* { NGX_RTMP_AMF_STRING, ngx_null_string, - &v.action, 0 }, - + &v.action, sizeof(v.action) }, +*/ { NGX_RTMP_AMF_NUMBER, ngx_null_string, &v.trans, 0 }, @@ -1282,7 +1284,7 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, { NGX_RTMP_AMF_STRING, ngx_null_string, - &v.stream, 0 }, + &v.stream, sizeof(v.stream) }, }; lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module); @@ -1303,8 +1305,8 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, sizeof(in_elts) / sizeof(in_elts[0])); ngx_log_error(NGX_LOG_DEBUG, s->connection->log, 0, - "live: onFCUnpublish: action='%s' stream='%s'", - v.action, v.stream); + "live: onFCUnpublish: stream='%s'", + v.stream); return ngx_rtmp_send_fcunpublish(s, v.stream); }