mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-14 16:01:09 +02:00
added pause support
This commit is contained in:
parent
ae71903de4
commit
083b0cd629
|
@ -25,6 +25,8 @@ ngx_rtmp_play_pt ngx_rtmp_play;
|
|||
ngx_rtmp_fcsubscribe_pt ngx_rtmp_fcsubscribe;
|
||||
ngx_rtmp_fcunsubscribe_pt ngx_rtmp_fcunsubscribe;
|
||||
|
||||
ngx_rtmp_pause_pt ngx_rtmp_pause;
|
||||
|
||||
|
||||
static ngx_int_t ngx_rtmp_cmd_postconfiguration(ngx_conf_t *cf);
|
||||
|
||||
|
@ -898,6 +900,116 @@ ngx_rtmp_cmd_fcsubscribe(ngx_rtmp_session_t *s, ngx_rtmp_fcsubscribe_t *v)
|
|||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_cmd_pause_init(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||
ngx_chain_t *in)
|
||||
{
|
||||
static ngx_rtmp_pause_t v;
|
||||
|
||||
static ngx_rtmp_amf_elt_t in_elts[] = {
|
||||
|
||||
{ NGX_RTMP_AMF_NUMBER,
|
||||
ngx_null_string,
|
||||
NULL, 0 },
|
||||
|
||||
{ NGX_RTMP_AMF_NULL,
|
||||
ngx_null_string,
|
||||
NULL, 0 },
|
||||
|
||||
{ NGX_RTMP_AMF_BOOLEAN,
|
||||
ngx_null_string,
|
||||
&v.pause, 0 },
|
||||
|
||||
{ NGX_RTMP_AMF_NUMBER,
|
||||
ngx_null_string,
|
||||
&v.position, 0 },
|
||||
};
|
||||
|
||||
ngx_memzero(&v, sizeof(v));
|
||||
|
||||
/* parse input */
|
||||
if (ngx_rtmp_receive_amf(s, in, in_elts,
|
||||
sizeof(in_elts) / sizeof(in_elts[0])))
|
||||
{
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"pause: pause=%i position=%i",
|
||||
(ngx_int_t)v.pause, (ngx_int_t)v.position);
|
||||
|
||||
return ngx_rtmp_pause
|
||||
? ngx_rtmp_pause(s, &v)
|
||||
: NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_cmd_pause(ngx_rtmp_session_t *s, ngx_rtmp_pause_t *v)
|
||||
{
|
||||
ngx_rtmp_header_t h;
|
||||
|
||||
static double trans;
|
||||
|
||||
static ngx_rtmp_amf_elt_t out_inf[] = {
|
||||
|
||||
{ NGX_RTMP_AMF_STRING,
|
||||
ngx_string("code"),
|
||||
"NetStream.Pause.Notify", 0 },
|
||||
|
||||
{ NGX_RTMP_AMF_STRING,
|
||||
ngx_string("level"),
|
||||
"status", 0 },
|
||||
|
||||
{ NGX_RTMP_AMF_STRING,
|
||||
ngx_string("description"),
|
||||
"Paused.", 0 },
|
||||
};
|
||||
|
||||
static ngx_rtmp_amf_elt_t out_elts[] = {
|
||||
|
||||
{ NGX_RTMP_AMF_STRING,
|
||||
ngx_null_string,
|
||||
"onStatus", 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) },
|
||||
};
|
||||
|
||||
/* send onStatus reply */
|
||||
memset(&h, 0, sizeof(h));
|
||||
h.type = NGX_RTMP_MSG_AMF_CMD;
|
||||
h.csid = NGX_RTMP_CMD_CSID_AMF;
|
||||
h.msid = NGX_RTMP_CMD_MSID;
|
||||
|
||||
if (v->pause) {
|
||||
out_inf[0].data = "NetStream.Pause.Notify";
|
||||
return ngx_rtmp_send_user_stream_eof(s, NGX_RTMP_CMD_MSID) != NGX_OK
|
||||
|| ngx_rtmp_send_amf(s, &h, out_elts,
|
||||
sizeof(out_elts) / sizeof(out_elts[0])) != NGX_OK
|
||||
? NGX_ERROR
|
||||
: NGX_OK;
|
||||
}
|
||||
|
||||
out_inf[0].data = "NetStream.Unpause.Notify";
|
||||
return ngx_rtmp_send_user_stream_begin(s, NGX_RTMP_CMD_MSID) != NGX_OK
|
||||
|| ngx_rtmp_send_amf(s, &h, out_elts,
|
||||
sizeof(out_elts) / sizeof(out_elts[0])) != NGX_OK
|
||||
? NGX_ERROR
|
||||
: NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_cmd_disconnect(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||
ngx_chain_t *in)
|
||||
|
@ -921,6 +1033,8 @@ static ngx_rtmp_amf_handler_t ngx_rtmp_cmd_map[] = {
|
|||
{ ngx_string("play"), ngx_rtmp_cmd_play_init },
|
||||
{ ngx_string("fcsubscribe"), ngx_rtmp_cmd_fcsubscribe_init },
|
||||
/*{ ngx_string("fcunsubscribe"), ngx_rtmp_cmd_fcunsubscribe_init },*/
|
||||
|
||||
{ ngx_string("pause"), ngx_rtmp_cmd_pause_init },
|
||||
};
|
||||
|
||||
|
||||
|
@ -965,5 +1079,7 @@ ngx_rtmp_cmd_postconfiguration(ngx_conf_t *cf)
|
|||
ngx_rtmp_fcsubscribe = ngx_rtmp_cmd_fcsubscribe;
|
||||
/*ngx_rtmp_fcunsubscribe = ngx_rtmp_cmd_fcunsubsrcibe;*/
|
||||
|
||||
ngx_rtmp_pause = ngx_rtmp_cmd_pause;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,12 @@ typedef struct {
|
|||
} ngx_rtmp_play_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t pause;
|
||||
double position;
|
||||
} ngx_rtmp_pause_t;
|
||||
|
||||
|
||||
typedef ngx_int_t (*ngx_rtmp_connect_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_connect_t *v);
|
||||
typedef ngx_int_t (*ngx_rtmp_create_stream_pt)(ngx_rtmp_session_t *s,
|
||||
|
@ -94,6 +100,9 @@ typedef ngx_int_t (*ngx_rtmp_fcsubscribe_pt)(ngx_rtmp_session_t *s,
|
|||
typedef ngx_int_t (*ngx_rtmp_fcunsubscribe_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_fcunsubscribe_t *v);
|
||||
|
||||
typedef ngx_int_t (*ngx_rtmp_pause_pt)(ngx_rtmp_session_t *s,
|
||||
ngx_rtmp_pause_t *v);
|
||||
|
||||
|
||||
extern ngx_rtmp_connect_pt ngx_rtmp_connect;
|
||||
extern ngx_rtmp_create_stream_pt ngx_rtmp_create_stream;
|
||||
|
@ -107,5 +116,7 @@ extern ngx_rtmp_play_pt ngx_rtmp_play;
|
|||
extern ngx_rtmp_fcsubscribe_pt ngx_rtmp_fcsubscribe;
|
||||
extern ngx_rtmp_fcunsubscribe_pt ngx_rtmp_fcunsubscribe;
|
||||
|
||||
extern ngx_rtmp_pause_pt ngx_rtmp_pause;
|
||||
|
||||
|
||||
#endif /*_NGX_RTMP_CMD_H_INCLUDED_ */
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
static ngx_rtmp_publish_pt next_publish;
|
||||
static ngx_rtmp_play_pt next_play;
|
||||
static ngx_rtmp_delete_stream_pt next_delete_stream;
|
||||
static ngx_rtmp_pause_pt next_pause;
|
||||
|
||||
|
||||
static ngx_int_t ngx_rtmp_live_postconfiguration(ngx_conf_t *cf);
|
||||
|
@ -275,6 +276,36 @@ next:
|
|||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_live_pause(ngx_rtmp_session_t *s, ngx_rtmp_pause_t *v)
|
||||
{
|
||||
ngx_rtmp_live_ctx_t *ctx;
|
||||
ngx_rtmp_live_app_conf_t *lacf;
|
||||
|
||||
lacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_live_module);
|
||||
if (lacf == NULL) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
|
||||
if (ctx == NULL) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (v->pause) {
|
||||
ctx->flags |= NGX_RTMP_LIVE_PAUSED;
|
||||
} else {
|
||||
ctx->flags &= ~NGX_RTMP_LIVE_PAUSED;
|
||||
}
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
|
||||
"live: %spaused", v->pause ? "" : "un");
|
||||
|
||||
next:
|
||||
return next_pause(s, v);
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
||||
ngx_chain_t *in)
|
||||
|
@ -373,7 +404,7 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
|
|||
|
||||
/* broadcast to all subscribers */
|
||||
for (pctx = ctx->stream->ctx; pctx; pctx = pctx->next) {
|
||||
if (pctx == ctx) {
|
||||
if (pctx == ctx || (pctx->flags & NGX_RTMP_LIVE_PAUSED)) {
|
||||
continue;
|
||||
}
|
||||
++peers;
|
||||
|
@ -502,5 +533,8 @@ ngx_rtmp_live_postconfiguration(ngx_conf_t *cf)
|
|||
next_delete_stream = ngx_rtmp_delete_stream;
|
||||
ngx_rtmp_delete_stream = ngx_rtmp_live_delete_stream;
|
||||
|
||||
next_pause = ngx_rtmp_pause;
|
||||
ngx_rtmp_pause = ngx_rtmp_live_pause;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
/* session flags */
|
||||
#define NGX_RTMP_LIVE_PUBLISHING 0x01
|
||||
#define NGX_RTMP_LIVE_PAUSED 0x02
|
||||
|
||||
|
||||
/* Chunk stream ids for output */
|
||||
|
|
Loading…
Reference in a new issue