@@ -196,9 +196,12 @@ ngx_rtmp_control_drop_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
196
196
static const char *
197
197
ngx_rtmp_control_redirect_handler (ngx_http_request_t * r , ngx_rtmp_session_t * s )
198
198
{
199
- u_char * n ;
200
- ngx_str_t name ;
201
- ngx_rtmp_control_ctx_t * ctx ;
199
+ ngx_str_t name ;
200
+ ngx_rtmp_play_t vplay ;
201
+ ngx_rtmp_publish_t vpublish ;
202
+ ngx_rtmp_live_ctx_t * lctx ;
203
+ ngx_rtmp_control_ctx_t * ctx ;
204
+ ngx_rtmp_close_stream_t vc ;
202
205
203
206
ngx_str_null (& name );
204
207
ngx_http_arg (r , (u_char * ) "newname" , sizeof ("newname" ) - 1 , & name );
@@ -207,20 +210,46 @@ ngx_rtmp_control_redirect_handler(ngx_http_request_t *r, ngx_rtmp_session_t *s)
207
210
return "newname not specified" ;
208
211
}
209
212
210
- n = ngx_palloc (r -> pool , name .len + 1 );
211
- if (n == NULL ) {
212
- return "allocation failed" ;
213
+ if (name .len >= NGX_RTMP_MAX_NAME ) {
214
+ name .len = NGX_RTMP_MAX_NAME - 1 ;
213
215
}
214
216
215
- ngx_memcpy (n , name .data , name .len );
217
+ ctx = ngx_http_get_module_ctx (r , ngx_rtmp_control_module );
218
+ ctx -> count ++ ;
216
219
217
- n [ name . len ] = 0 ;
220
+ ngx_memzero ( & vc , sizeof ( ngx_rtmp_close_stream_t )) ;
218
221
219
- ngx_rtmp_live_redirect (s , n );
222
+ /* close_stream should be synchronous */
223
+ ngx_rtmp_close_stream (s , & vc );
220
224
221
- ctx = ngx_http_get_module_ctx ( r , ngx_rtmp_control_module );
225
+ lctx = ngx_rtmp_get_module_ctx ( s , ngx_rtmp_live_module );
222
226
223
- ctx -> count ++ ;
227
+ if (lctx && lctx -> publishing ) {
228
+ /* publish */
229
+
230
+ ngx_memzero (& vpublish , sizeof (ngx_rtmp_publish_t ));
231
+
232
+ ngx_memcpy (vpublish .name , name .data , name .len );
233
+
234
+ ngx_rtmp_cmd_fill_args (vpublish .name , vpublish .args );
235
+
236
+ if (ngx_rtmp_publish (s , & vpublish ) != NGX_OK ) {
237
+ return "publish failed" ;
238
+ }
239
+
240
+ } else {
241
+ /* play */
242
+
243
+ ngx_memzero (& vplay , sizeof (ngx_rtmp_play_t ));
244
+
245
+ ngx_memcpy (vplay .name , name .data , name .len );
246
+
247
+ ngx_rtmp_cmd_fill_args (vplay .name , vplay .args );
248
+
249
+ if (ngx_rtmp_play (s , & vplay ) != NGX_OK ) {
250
+ return "play failed" ;
251
+ }
252
+ }
224
253
225
254
return NGX_CONF_OK ;
226
255
}
0 commit comments