mirror of
https://github.com/arut/nginx-rtmp-module.git
synced 2025-08-06 15:00:18 +08:00
added control redirect
This commit is contained in:
@ -196,9 +196,12 @@ ngx_rtmp_control_drop_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
|
|||||||
static const char *
|
static const char *
|
||||||
ngx_rtmp_control_redirect_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
|
ngx_rtmp_control_redirect_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
|
||||||
{
|
{
|
||||||
u_char *n;
|
ngx_str_t name;
|
||||||
ngx_str_t name;
|
ngx_rtmp_play_t vplay;
|
||||||
ngx_rtmp_control_ctx_t *ctx;
|
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_str_null(&name);
|
||||||
ngx_http_arg(r, (u_char *) "newname", sizeof("newname") - 1, &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";
|
return "newname not specified";
|
||||||
}
|
}
|
||||||
|
|
||||||
n = ngx_palloc(r->pool, name.len + 1);
|
if (name.len >= NGX_RTMP_MAX_NAME) {
|
||||||
if (n == NULL) {
|
name.len = NGX_RTMP_MAX_NAME - 1;
|
||||||
return "allocation failed";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = ngx_http_get_module_ctx(r, ngx_rtmp_control_module);
|
||||||
|
|
||||||
ctx->count++;
|
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;
|
return NGX_CONF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user