mirror of
https://github.com/zotanmew/nginx-rtmp-module.git
synced 2024-05-13 23:51:08 +02:00
added control redirect
This commit is contained in:
parent
5b68307710
commit
ef424df677
|
@ -196,9 +196,12 @@ ngx_rtmp_control_drop_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
|
|||
static const char *
|
||||
ngx_rtmp_control_redirect_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
|
||||
{
|
||||
u_char *n;
|
||||
ngx_str_t name;
|
||||
ngx_rtmp_control_ctx_t *ctx;
|
||||
ngx_str_t name;
|
||||
ngx_rtmp_play_t vplay;
|
||||
ngx_rtmp_publish_t vpublish;
|
||||
ngx_rtmp_live_ctx_t *lctx;
|
||||
ngx_rtmp_control_ctx_t *ctx;
|
||||
ngx_rtmp_close_stream_t vc;
|
||||
|
||||
ngx_str_null(&name);
|
||||
ngx_http_arg(r, (u_char *) "newname", sizeof("newname") - 1, &name);
|
||||
|
@ -207,21 +210,47 @@ ngx_rtmp_control_redirect_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
|
|||
return "newname not specified";
|
||||
}
|
||||
|
||||
n = ngx_palloc(r->pool, name.len + 1);
|
||||
if (n == NULL) {
|
||||
return "allocation failed";
|
||||
if (name.len >= NGX_RTMP_MAX_NAME) {
|
||||
name.len = NGX_RTMP_MAX_NAME - 1;
|
||||
}
|
||||
|
||||
ngx_memcpy(n, name.data, name.len);
|
||||
|
||||
n[name.len] = 0;
|
||||
|
||||
ngx_rtmp_live_redirect(s, n);
|
||||
|
||||
ctx = ngx_http_get_module_ctx(r, ngx_rtmp_control_module);
|
||||
|
||||
ctx->count++;
|
||||
|
||||
ngx_memzero(&vc, sizeof(ngx_rtmp_close_stream_t));
|
||||
|
||||
/* close_stream should be synchronous */
|
||||
ngx_rtmp_close_stream(s, &vc);
|
||||
|
||||
lctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_live_module);
|
||||
|
||||
if (lctx && lctx->publishing) {
|
||||
/* publish */
|
||||
|
||||
ngx_memzero(&vpublish, sizeof(ngx_rtmp_publish_t));
|
||||
|
||||
ngx_memcpy(vpublish.name, name.data, name.len);
|
||||
|
||||
ngx_rtmp_cmd_fill_args(vpublish.name, vpublish.args);
|
||||
|
||||
if (ngx_rtmp_publish(s, &vpublish) != NGX_OK) {
|
||||
return "publish failed";
|
||||
}
|
||||
|
||||
} else {
|
||||
/* play */
|
||||
|
||||
ngx_memzero(&vplay, sizeof(ngx_rtmp_play_t));
|
||||
|
||||
ngx_memcpy(vplay.name, name.data, name.len);
|
||||
|
||||
ngx_rtmp_cmd_fill_args(vplay.name, vplay.args);
|
||||
|
||||
if (ngx_rtmp_play(s, &vplay) != NGX_OK) {
|
||||
return "play failed";
|
||||
}
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue