renamed broadcast module to live module

This commit is contained in:
Roman Arutyunyan 2012-03-23 16:39:28 +04:00
parent 31d18ed447
commit 1934e838df
2 changed files with 123 additions and 123 deletions

4
config
View file

@ -4,7 +4,7 @@ CORE_MODULES="$CORE_MODULES
ngx_rtmp_module \
ngx_rtmp_core_module \
ngx_rtmp_access_module \
ngx_rtmp_broadcast_module \
ngx_rtmp_live_module \
"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
@ -17,5 +17,5 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
$ngx_addon_dir/ngx_rtmp_receive.c \
$ngx_addon_dir/ngx_rtmp_core_module.c \
$ngx_addon_dir/ngx_rtmp_access_module.c \
$ngx_addon_dir/ngx_rtmp_broadcast_module.c \
$ngx_addon_dir/ngx_rtmp_live_module.c \
"

View file

@ -8,71 +8,71 @@
#include "ngx_rtmp.h"
/* Standard stream ids for broadcasting */
#define NGX_RTMP_BROADCAST_CSID_AMF0 5
#define NGX_RTMP_BROADCAST_CSID_AUDIO 6
#define NGX_RTMP_BROADCAST_CSID_VIDEO 7
/* Standard stream ids for liveing */
#define NGX_RTMP_LIVE_CSID_AMF0 5
#define NGX_RTMP_LIVE_CSID_AUDIO 6
#define NGX_RTMP_LIVE_CSID_VIDEO 7
static ngx_int_t ngx_rtmp_broadcast_postconfiguration(ngx_conf_t *cf);
static void * ngx_rtmp_broadcast_create_app_conf(ngx_conf_t *cf);
static char * ngx_rtmp_broadcast_merge_app_conf(ngx_conf_t *cf,
static ngx_int_t ngx_rtmp_live_postconfiguration(ngx_conf_t *cf);
static void * ngx_rtmp_live_create_app_conf(ngx_conf_t *cf);
static char * ngx_rtmp_live_merge_app_conf(ngx_conf_t *cf,
void *parent, void *child);
static ngx_int_t ngx_rtmp_broadcast_publish(ngx_rtmp_session_t *s,
static ngx_int_t ngx_rtmp_live_publish(ngx_rtmp_session_t *s,
ngx_rtmp_header_t *h, ngx_chain_t *in);
static ngx_int_t ngx_rtmp_broadcast_play(ngx_rtmp_session_t *s,
static ngx_int_t ngx_rtmp_live_play(ngx_rtmp_session_t *s,
ngx_rtmp_header_t *h, ngx_chain_t *in);
static ngx_int_t ngx_rtmp_broadcast_set_data_frame(ngx_rtmp_session_t *s,
static ngx_int_t ngx_rtmp_live_set_data_frame(ngx_rtmp_session_t *s,
ngx_rtmp_header_t *h, ngx_chain_t *in);
static ngx_int_t ngx_rtmp_broadcast_stream_length(ngx_rtmp_session_t *s,
static ngx_int_t ngx_rtmp_live_stream_length(ngx_rtmp_session_t *s,
ngx_rtmp_header_t *h, ngx_chain_t *in);
static ngx_rtmp_amf0_handler_t ngx_rtmp_broadcast_map[] = {
{ ngx_string("publish"), ngx_rtmp_broadcast_publish },
{ ngx_string("play"), ngx_rtmp_broadcast_play },
{ ngx_string("-@setDataFrame"), ngx_rtmp_broadcast_set_data_frame },
{ ngx_string("getStreamLength"), ngx_rtmp_broadcast_stream_length },
{ ngx_string("releaseStream"), ngx_rtmp_amf0_default },
{ ngx_string("FCPublish"), ngx_rtmp_amf0_default },
{ ngx_string("FCSubscribe"), ngx_rtmp_amf0_default },
static ngx_rtmp_amf0_handler_t ngx_rtmp_live_map[] = {
{ ngx_string("publish"), ngx_rtmp_live_publish },
{ ngx_string("play"), ngx_rtmp_live_play },
{ ngx_string("-@setDataFrame"), ngx_rtmp_live_set_data_frame },
{ ngx_string("getStreamLength"), ngx_rtmp_live_stream_length },
{ ngx_string("releaseStream"), ngx_rtmp_amf0_default },
{ ngx_string("FCPublish"), ngx_rtmp_amf0_default },
{ ngx_string("FCSubscribe"), ngx_rtmp_amf0_default },
};
typedef struct ngx_rtmp_broadcast_ctx_s ngx_rtmp_broadcast_ctx_t;
typedef struct ngx_rtmp_live_ctx_s ngx_rtmp_live_ctx_t;
typedef struct {
ngx_int_t nbuckets;
ngx_rtmp_broadcast_ctx_t **contexts;
ngx_rtmp_live_ctx_t **contexts;
ngx_flag_t live;
ngx_flag_t wait_key_frame;
} ngx_rtmp_broadcast_app_conf_t;
} ngx_rtmp_live_app_conf_t;
static ngx_command_t ngx_rtmp_broadcast_commands[] = {
static ngx_command_t ngx_rtmp_live_commands[] = {
{ ngx_string("live"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
NGX_RTMP_APP_CONF_OFFSET,
offsetof(ngx_rtmp_broadcast_app_conf_t, live),
offsetof(ngx_rtmp_live_app_conf_t, live),
NULL },
{ ngx_string("stream_buckets"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_RTMP_APP_CONF_OFFSET,
offsetof(ngx_rtmp_broadcast_app_conf_t, nbuckets),
offsetof(ngx_rtmp_live_app_conf_t, nbuckets),
NULL },
{ ngx_string("wait_key_frame"),
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_CONF_TAKE1,
ngx_conf_set_flag_slot,
NGX_RTMP_APP_CONF_OFFSET,
offsetof(ngx_rtmp_broadcast_app_conf_t, wait_key_frame),
offsetof(ngx_rtmp_live_app_conf_t, wait_key_frame),
NULL },
@ -80,22 +80,22 @@ static ngx_command_t ngx_rtmp_broadcast_commands[] = {
};
static ngx_rtmp_module_t ngx_rtmp_broadcast_module_ctx = {
static ngx_rtmp_module_t ngx_rtmp_live_module_ctx = {
NULL, /* preconfiguration */
ngx_rtmp_broadcast_postconfiguration, /* postconfiguration */
ngx_rtmp_live_postconfiguration, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
ngx_rtmp_broadcast_create_app_conf, /* create app configuration */
ngx_rtmp_broadcast_merge_app_conf /* merge app configuration */
ngx_rtmp_live_create_app_conf, /* create app configuration */
ngx_rtmp_live_merge_app_conf /* merge app configuration */
};
ngx_module_t ngx_rtmp_broadcast_module = {
ngx_module_t ngx_rtmp_live_module = {
NGX_MODULE_V1,
&ngx_rtmp_broadcast_module_ctx, /* module context */
ngx_rtmp_broadcast_commands, /* module directives */
&ngx_rtmp_live_module_ctx, /* module context */
ngx_rtmp_live_commands, /* module directives */
NGX_RTMP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
@ -109,16 +109,16 @@ ngx_module_t ngx_rtmp_broadcast_module = {
/* session flags */
#define NGX_RTMP_BROADCAST_PUBLISHING 0x01
#define NGX_RTMP_BROADCAST_PLAYING 0x02
#define NGX_RTMP_BROADCAST_KEYFRAME 0x04
#define NGX_RTMP_BROADCAST_DATA_FRAME 0x08
#define NGX_RTMP_LIVE_PUBLISHING 0x01
#define NGX_RTMP_LIVE_PLAYING 0x02
#define NGX_RTMP_LIVE_KEYFRAME 0x04
#define NGX_RTMP_LIVE_DATA_FRAME 0x08
struct ngx_rtmp_broadcast_ctx_s {
struct ngx_rtmp_live_ctx_s {
ngx_str_t stream;
ngx_rtmp_session_t *session;
ngx_rtmp_broadcast_ctx_t *next;
ngx_rtmp_live_ctx_t *next;
ngx_uint_t flags;
uint32_t csid;
ngx_chain_t *data_frame;
@ -126,74 +126,74 @@ struct ngx_rtmp_broadcast_ctx_s {
static void *
ngx_rtmp_broadcast_create_app_conf(ngx_conf_t *cf)
ngx_rtmp_live_create_app_conf(ngx_conf_t *cf)
{
ngx_rtmp_broadcast_app_conf_t *bacf;
ngx_rtmp_live_app_conf_t *lacf;
bacf = ngx_pcalloc(cf->pool, sizeof(ngx_rtmp_broadcast_app_conf_t));
if (bacf == NULL) {
lacf = ngx_pcalloc(cf->pool, sizeof(ngx_rtmp_live_app_conf_t));
if (lacf == NULL) {
return NULL;
}
bacf->live = NGX_CONF_UNSET;
bacf->nbuckets = NGX_CONF_UNSET;
bacf->wait_key_frame = NGX_CONF_UNSET;
lacf->live = NGX_CONF_UNSET;
lacf->nbuckets = NGX_CONF_UNSET;
lacf->wait_key_frame = NGX_CONF_UNSET;
return bacf;
return lacf;
}
static char *
ngx_rtmp_broadcast_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_rtmp_live_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_rtmp_broadcast_app_conf_t *prev = parent;
ngx_rtmp_broadcast_app_conf_t *conf = child;
ngx_rtmp_live_app_conf_t *prev = parent;
ngx_rtmp_live_app_conf_t *conf = child;
ngx_conf_merge_value(conf->live, prev->live, 0);
ngx_conf_merge_value(conf->nbuckets, prev->nbuckets, 1024);
ngx_conf_merge_value(conf->wait_key_frame, prev->wait_key_frame, 1);
conf->contexts = ngx_pcalloc(cf->pool,
sizeof(ngx_rtmp_broadcast_ctx_t *) * conf->nbuckets);
sizeof(ngx_rtmp_live_ctx_t *) * conf->nbuckets);
return NGX_CONF_OK;
}
static ngx_rtmp_broadcast_ctx_t **
ngx_rtmp_broadcast_get_head(ngx_rtmp_session_t *s)
static ngx_rtmp_live_ctx_t **
ngx_rtmp_live_get_head(ngx_rtmp_session_t *s)
{
ngx_rtmp_broadcast_app_conf_t *bacf;
ngx_rtmp_broadcast_ctx_t *ctx;
ngx_rtmp_live_app_conf_t *lacf;
ngx_rtmp_live_ctx_t *ctx;
bacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_broadcast_module);
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
if (bacf == NULL) {
if (lacf == NULL) {
return NULL;
}
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_broadcast_module);
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
return &bacf->contexts[
return &lacf->contexts[
ngx_hash_key(ctx->stream.data, ctx->stream.len)
% bacf->nbuckets];
% lacf->nbuckets];
}
static void
ngx_rtmp_broadcast_join(ngx_rtmp_session_t *s, ngx_str_t *stream,
ngx_rtmp_live_join(ngx_rtmp_session_t *s, ngx_str_t *stream,
ngx_uint_t flags)
{
ngx_connection_t *c;
ngx_rtmp_broadcast_ctx_t *ctx, **hctx;
ngx_rtmp_live_ctx_t *ctx, **hctx;
c = s->connection;
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_broadcast_module);
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
if (ctx == NULL) {
ctx = ngx_pcalloc(c->pool, sizeof(ngx_rtmp_broadcast_ctx_t));
ctx = ngx_pcalloc(c->pool, sizeof(ngx_rtmp_live_ctx_t));
ctx->session = s;
ngx_rtmp_set_ctx(s, ctx, ngx_rtmp_broadcast_module);
ngx_rtmp_set_ctx(s, ctx, ngx_rtmp_live_module);
}
if (ctx->stream.len) {
@ -205,7 +205,7 @@ ngx_rtmp_broadcast_join(ngx_rtmp_session_t *s, ngx_str_t *stream,
"live: join '%V'", stream);
ctx->stream = *stream;
hctx = ngx_rtmp_broadcast_get_head(s);
hctx = ngx_rtmp_live_get_head(s);
if (hctx == NULL) {
return;
}
@ -216,15 +216,15 @@ ngx_rtmp_broadcast_join(ngx_rtmp_session_t *s, ngx_str_t *stream,
static ngx_int_t
ngx_rtmp_broadcast_leave(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_rtmp_live_leave(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_chain_t *in)
{
ngx_connection_t *c;
ngx_rtmp_broadcast_ctx_t *ctx, **hctx;
ngx_rtmp_live_ctx_t *ctx, **hctx;
c = s->connection;
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_broadcast_module);
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
if (ctx == NULL) {
return NGX_OK;
}
@ -232,7 +232,7 @@ ngx_rtmp_broadcast_leave(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, c->log, 0,
"live: leave '%V'", &ctx->stream);
hctx = ngx_rtmp_broadcast_get_head(s);
hctx = ngx_rtmp_live_get_head(s);
if (hctx == NULL) {
return NGX_ERROR;
}
@ -263,14 +263,14 @@ ngx_rtmp_get_video_frame_type(ngx_chain_t *in)
static ngx_int_t
ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_chain_t *in)
{
ngx_connection_t *c;
ngx_rtmp_broadcast_ctx_t *ctx, *cctx, *cnext;
ngx_rtmp_live_ctx_t *ctx, *cctx, *cnext;
ngx_chain_t *out;
ngx_rtmp_core_srv_conf_t *cscf;
ngx_rtmp_broadcast_app_conf_t *bacf;
ngx_rtmp_live_app_conf_t *lacf;
ngx_rtmp_session_t *ss;
ngx_rtmp_header_t sh;
ngx_uint_t priority;
@ -278,23 +278,23 @@ ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
int keyframe;
c = s->connection;
bacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_broadcast_module);
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
if (bacf == NULL) {
if (lacf == NULL) {
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, c->log, 0,
"live: NULL application");
return NGX_ERROR;
}
if (!bacf->live) {
if (!lacf->live) {
return NGX_OK;
}
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_broadcast_module);
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
memset(&sh, 0, sizeof(sh));
sh.timestamp = (h->timestamp + s->epoch);/* & 0x00ffffff*/; /*FIXME*/
sh.timestamp = (h->timestamp + s->epoch);
sh.msid = 1;
sh.type = h->type;
@ -304,14 +304,14 @@ ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
keyframe = 0;
if (h->type == NGX_RTMP_MSG_VIDEO) {
sh.csid = NGX_RTMP_BROADCAST_CSID_VIDEO;
sh.csid = NGX_RTMP_LIVE_CSID_VIDEO;
priority = ngx_rtmp_get_video_frame_type(in);
if (priority == NGX_RTMP_VIDEO_KEY_FRAME) {
keyframe = 1;
}
} else if (h->type == NGX_RTMP_MSG_AUDIO) {
sh.csid = NGX_RTMP_BROADCAST_CSID_AUDIO;
sh.csid = NGX_RTMP_LIVE_CSID_AUDIO;
priority = NGX_RTMP_AUDIO_FRAME;
} else {
@ -319,7 +319,7 @@ ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
}
if (ctx == NULL
|| !(ctx->flags & NGX_RTMP_BROADCAST_PUBLISHING))
|| !(ctx->flags & NGX_RTMP_LIVE_PUBLISHING))
{
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, c->log, 0,
"live: received audio/video from non-publisher");
@ -334,14 +334,14 @@ ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_rtmp_prepare_message(s, &sh, NULL, out);
/* broadcast to all subscribers */
for (cctx = *ngx_rtmp_broadcast_get_head(s); cctx; cctx = cnext) {
/* live to all subscribers */
for (cctx = *ngx_rtmp_live_get_head(s); cctx; cctx = cnext) {
/* session can die further in loop
* so save next ptr while it's not too late */
cnext = cctx->next;
if (cctx == ctx
|| !(cctx->flags & NGX_RTMP_BROADCAST_PLAYING)
|| !(cctx->flags & NGX_RTMP_LIVE_PLAYING)
|| cctx->stream.len != ctx->stream.len
|| ngx_strncmp(cctx->stream.data, ctx->stream.data,
ctx->stream.len))
@ -354,7 +354,7 @@ ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
/* if we have metadata check if the subscriber
* has already received one */
if (ctx->data_frame
&& !(cctx->flags & NGX_RTMP_BROADCAST_DATA_FRAME))
&& !(cctx->flags & NGX_RTMP_LIVE_DATA_FRAME))
{
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"live: sending data_frame");
@ -365,14 +365,14 @@ ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
}
if (rc == NGX_OK) {
cctx->flags |= NGX_RTMP_BROADCAST_DATA_FRAME;
cctx->flags |= NGX_RTMP_LIVE_DATA_FRAME;
}
}
/* waiting for a keyframe? */
if (bacf->wait_key_frame
if (lacf->wait_key_frame
&& sh.type == NGX_RTMP_MSG_VIDEO
&& !(cctx->flags & NGX_RTMP_BROADCAST_KEYFRAME)
&& !(cctx->flags & NGX_RTMP_LIVE_KEYFRAME)
&& !keyframe)
{
continue;
@ -380,11 +380,11 @@ ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
if (ngx_rtmp_send_message(ss, out, priority) == NGX_OK
&& keyframe
&& !(cctx->flags & NGX_RTMP_BROADCAST_KEYFRAME))
&& !(cctx->flags & NGX_RTMP_LIVE_KEYFRAME))
{
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
"live: keyframe sent");
cctx->flags |= NGX_RTMP_BROADCAST_KEYFRAME;
cctx->flags |= NGX_RTMP_LIVE_KEYFRAME;
}
}
@ -395,10 +395,10 @@ ngx_rtmp_broadcast_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
static ngx_int_t
ngx_rtmp_broadcast_publish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_rtmp_live_publish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_chain_t *in)
{
ngx_rtmp_broadcast_app_conf_t *bacf;
ngx_rtmp_live_app_conf_t *lacf;
ngx_rtmp_header_t sh;
ngx_str_t stream;
@ -429,9 +429,9 @@ ngx_rtmp_broadcast_publish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
{ NGX_RTMP_AMF0_OBJECT, NULL, out_inf, sizeof(out_inf) },
};
bacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_broadcast_module);
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
if (bacf == NULL || !bacf->live) {
if (lacf == NULL || !lacf->live) {
return NGX_OK;
}
@ -452,7 +452,7 @@ ngx_rtmp_broadcast_publish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
stream.len = ngx_strlen(v.name);
stream.data = ngx_palloc(s->connection->pool, stream.len);
ngx_memcpy(stream.data, v.name, stream.len);
ngx_rtmp_broadcast_join(s, &stream, NGX_RTMP_BROADCAST_PUBLISHING);
ngx_rtmp_live_join(s, &stream, NGX_RTMP_LIVE_PUBLISHING);
/* TODO: we can probably make any use of v.type: live/record/append */
@ -464,7 +464,7 @@ ngx_rtmp_broadcast_publish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
/* send onStatus reply */
memset(&sh, 0, sizeof(sh));
sh.type = NGX_RTMP_MSG_AMF0_CMD;
sh.csid = NGX_RTMP_BROADCAST_CSID_AMF0;
sh.csid = NGX_RTMP_LIVE_CSID_AMF0;
sh.msid = h->msid;
if (ngx_rtmp_send_amf0(s, &sh, out_elts,
@ -478,10 +478,10 @@ ngx_rtmp_broadcast_publish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
static ngx_int_t
ngx_rtmp_broadcast_play(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_rtmp_live_play(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_chain_t *in)
{
ngx_rtmp_broadcast_app_conf_t *bacf;
ngx_rtmp_live_app_conf_t *lacf;
ngx_rtmp_header_t sh;
ngx_str_t stream;
@ -548,9 +548,9 @@ ngx_rtmp_broadcast_play(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
{ NGX_RTMP_AMF0_OBJECT, NULL, out4_inf, sizeof(out4_inf) },
};
bacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_broadcast_module);
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
if (bacf == NULL || !bacf->live) {
if (lacf == NULL || !lacf->live) {
return NGX_OK;
}
@ -571,7 +571,7 @@ ngx_rtmp_broadcast_play(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
stream.len = ngx_strlen(v.name);
stream.data = ngx_palloc(s->connection->pool, stream.len);
ngx_memcpy(stream.data, v.name, stream.len);
ngx_rtmp_broadcast_join(s, &stream, NGX_RTMP_BROADCAST_PLAYING);
ngx_rtmp_live_join(s, &stream, NGX_RTMP_LIVE_PLAYING);
/* start stream */
if (ngx_rtmp_send_user_stream_begin(s, 1) != NGX_OK) {
@ -581,7 +581,7 @@ ngx_rtmp_broadcast_play(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
/* send onStatus reply */
memset(&sh, 0, sizeof(sh));
sh.type = NGX_RTMP_MSG_AMF0_CMD;
sh.csid = NGX_RTMP_BROADCAST_CSID_AMF0;
sh.csid = NGX_RTMP_LIVE_CSID_AMF0;
sh.msid = h->msid;
if (ngx_rtmp_send_amf0(s, &sh, out_elts,
@ -616,12 +616,12 @@ ngx_rtmp_broadcast_play(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
static ngx_int_t
ngx_rtmp_broadcast_set_data_frame(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_rtmp_live_set_data_frame(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
ngx_chain_t *in)
{
ngx_rtmp_broadcast_app_conf_t *bacf;
ngx_rtmp_live_app_conf_t *lacf;
ngx_connection_t *c;
ngx_rtmp_broadcast_ctx_t *ctx;
ngx_rtmp_live_ctx_t *ctx;
ngx_rtmp_amf0_ctx_t act;
ngx_rtmp_header_t sh;
ngx_rtmp_core_srv_conf_t *cscf;
@ -630,19 +630,19 @@ ngx_rtmp_broadcast_set_data_frame(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
{ NGX_RTMP_AMF0_STRING, NULL, "@setDataFrame", 0 },
};
bacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_broadcast_module);
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
if (bacf == NULL || !bacf->live) {
if (lacf == NULL || !lacf->live) {
return NGX_OK;
}
c = s->connection;
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_broadcast_module);
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, c->log, 0, "live: data_frame");
/* TODO: allow sending more meta packages to change broadcast content */
/* TODO: allow sending more meta packages to change live content */
if (ctx->data_frame) {
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, c->log, 0,
@ -679,7 +679,7 @@ ngx_rtmp_broadcast_set_data_frame(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
}
memset(&sh, 0, sizeof(sh));
sh.csid = NGX_RTMP_BROADCAST_CSID_AMF0;
sh.csid = NGX_RTMP_LIVE_CSID_AMF0;
sh.msid = 1;
sh.type = NGX_RTMP_MSG_AMF0_META;
@ -690,10 +690,10 @@ ngx_rtmp_broadcast_set_data_frame(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
static ngx_int_t
ngx_rtmp_broadcast_stream_length(ngx_rtmp_session_t *s,
ngx_rtmp_live_stream_length(ngx_rtmp_session_t *s,
ngx_rtmp_header_t *h, ngx_chain_t *in)
{
ngx_rtmp_broadcast_app_conf_t *bacf;
ngx_rtmp_live_app_conf_t *lacf;
ngx_rtmp_header_t sh;
static double trans;
@ -709,9 +709,9 @@ ngx_rtmp_broadcast_stream_length(ngx_rtmp_session_t *s,
{ NGX_RTMP_AMF0_NUMBER, NULL, &length, 0 },
};
bacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_broadcast_module);
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
if (bacf == NULL || !bacf->live) {
if (lacf == NULL || !lacf->live) {
return NGX_OK;
}
@ -736,7 +736,7 @@ ngx_rtmp_broadcast_stream_length(ngx_rtmp_session_t *s,
static ngx_int_t
ngx_rtmp_broadcast_postconfiguration(ngx_conf_t *cf)
ngx_rtmp_live_postconfiguration(ngx_conf_t *cf)
{
ngx_rtmp_core_main_conf_t *cmcf;
ngx_rtmp_handler_pt *h;
@ -747,23 +747,23 @@ ngx_rtmp_broadcast_postconfiguration(ngx_conf_t *cf)
/* register event handlers */
h = ngx_array_push(&cmcf->events[NGX_RTMP_MSG_AUDIO]);
*h = ngx_rtmp_broadcast_av;
*h = ngx_rtmp_live_av;
h = ngx_array_push(&cmcf->events[NGX_RTMP_MSG_VIDEO]);
*h = ngx_rtmp_broadcast_av;
*h = ngx_rtmp_live_av;
h = ngx_array_push(&cmcf->events[NGX_RTMP_DISCONNECT]);
*h = ngx_rtmp_broadcast_leave;
*h = ngx_rtmp_live_leave;
/* register AMF0 callbacks */
ncalls = sizeof(ngx_rtmp_broadcast_map)
/ sizeof(ngx_rtmp_broadcast_map[0]);
ncalls = sizeof(ngx_rtmp_live_map)
/ sizeof(ngx_rtmp_live_map[0]);
ch = ngx_array_push_n(&cmcf->amf0, ncalls);
if (h == NULL) {
return NGX_ERROR;
}
bh = ngx_rtmp_broadcast_map;
bh = ngx_rtmp_live_map;
for(n = 0; n < ncalls; ++n, ++ch, ++bh) {
*ch = *bh;
}