@@ -181,7 +181,6 @@ static ngx_int_t ngx_http_flv_live_init_handlers(ngx_cycle_t *cycle);
181181static ngx_int_t ngx_http_flv_live_request (ngx_rtmp_session_t * s ,
182182 ngx_rtmp_header_t * h , ngx_chain_t * in );
183183
184- static void ngx_http_flv_live_stop (ngx_rtmp_session_t * s );
185184static ngx_int_t ngx_http_flv_live_play (ngx_rtmp_session_t * s ,
186185 ngx_rtmp_play_t * v );
187186static ngx_int_t ngx_http_flv_live_close_stream (ngx_rtmp_session_t * s ,
@@ -979,30 +978,13 @@ ngx_http_flv_live_request(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
979978 * omit the user control message feedback
980979 */
981980void
982- ngx_http_flv_live_start (ngx_rtmp_session_t * s )
981+ ngx_http_flv_live_set_status (ngx_rtmp_session_t * s , unsigned active )
983982{
984983 ngx_rtmp_live_ctx_t * ctx ;
985984
986985 ctx = ngx_rtmp_get_module_ctx (s , ngx_rtmp_live_module );
987986
988- ctx -> active = 1 ;
989-
990- ctx -> cs [0 ].active = 0 ;
991- ctx -> cs [0 ].dropped = 0 ;
992-
993- ctx -> cs [1 ].active = 0 ;
994- ctx -> cs [1 ].dropped = 0 ;
995- }
996-
997-
998- void
999- ngx_http_flv_live_stop (ngx_rtmp_session_t * s )
1000- {
1001- ngx_rtmp_live_ctx_t * ctx ;
1002-
1003- ctx = ngx_rtmp_get_module_ctx (s , ngx_rtmp_live_module );
1004-
1005- ctx -> active = 0 ;
987+ ctx -> active = active ;
1006988
1007989 ctx -> cs [0 ].active = 0 ;
1008990 ctx -> cs [0 ].dropped = 0 ;
@@ -1021,6 +1003,7 @@ ngx_http_flv_live_join(ngx_rtmp_session_t *s, u_char *name,
10211003 ngx_rtmp_live_app_conf_t * lacf ;
10221004
10231005 ngx_rtmp_relay_app_conf_t * racf ;
1006+ ngx_flag_t create ;
10241007
10251008 /* only for subscribers */
10261009 if (publisher ) {
@@ -1048,14 +1031,22 @@ ngx_http_flv_live_join(ngx_rtmp_session_t *s, u_char *name,
10481031 ngx_memzero (ctx , sizeof (* ctx ));
10491032
10501033 ctx -> session = s ;
1034+ create = 0 ;
10511035
10521036 ngx_log_debug1 (NGX_LOG_DEBUG_RTMP , s -> connection -> log , 0 ,
10531037 "flv live: join '%s'" , name );
10541038
1055- stream = ngx_rtmp_live_get_stream (s , name , lacf -> idle_streams );
1039+ racf = ngx_rtmp_get_module_app_conf (s , ngx_rtmp_relay_module );
1040+ if (racf && racf -> pulls .nelts ) {
1041+ create = 1 ;
1042+ }
1043+
1044+ stream = ngx_rtmp_live_get_stream (s , name ,
1045+ lacf -> idle_streams || s -> wait_notify_play || create );
10561046
10571047 if (stream == NULL ||
1058- !(publisher || (* stream )-> publishing || lacf -> idle_streams ))
1048+ !(publisher || (* stream )-> publishing || lacf -> idle_streams ||
1049+ s -> wait_notify_play || create ))
10591050 {
10601051 ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
10611052 "flv live: stream not found" );
@@ -1069,18 +1060,17 @@ ngx_http_flv_live_join(ngx_rtmp_session_t *s, u_char *name,
10691060 "flv live: stream not publishing, check relay pulls" );
10701061
10711062 do {
1072- /* check if there are some pulls */
1073- racf = ngx_rtmp_get_module_app_conf (s , ngx_rtmp_relay_module );
1074- if (racf && racf -> pulls .nelts ) {
1063+ if (s -> wait_notify_play ) {
10751064 break ;
10761065 }
10771066
10781067 ngx_log_error (NGX_LOG_INFO , s -> connection -> log , 0 ,
1079- "flv live: no racf or relay pulls, check on_play " );
1068+ "flv live: no on_play, check relay pulls" );
10801069
1081- if (!s -> wait_notify_play ) {
1070+ /* check if there are some pulls */
1071+ if (!create ) {
10821072 ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
1083- "flv live: no relay pulls and no on_play , quit" );
1073+ "flv live: no on_play and no relay pulls , quit" );
10841074
10851075 return NGX_ERROR ;
10861076 }
@@ -1106,7 +1096,7 @@ ngx_http_flv_live_join(ngx_rtmp_session_t *s, u_char *name,
11061096 ctx -> cs [1 ].csid = NGX_RTMP_CSID_AUDIO ;
11071097
11081098 if (!ctx -> publishing && ctx -> stream -> active ) {
1109- ngx_http_flv_live_start ( s );
1099+ ngx_http_flv_live_set_status ( s , 1 );
11101100 }
11111101
11121102 return NGX_OK ;
@@ -1242,7 +1232,7 @@ ngx_http_flv_live_close_stream(ngx_rtmp_session_t *s,
12421232 ngx_http_flv_live_close_http_request ((* cctx )-> session );
12431233
12441234 if (!(* cctx )-> publishing && (* cctx )-> stream -> active ) {
1245- ngx_http_flv_live_stop ((* cctx )-> session );
1235+ ngx_http_flv_live_set_status ((* cctx )-> session , 0 );
12461236 }
12471237
12481238 unlink = * cctx ;
@@ -1259,7 +1249,7 @@ ngx_http_flv_live_close_stream(ngx_rtmp_session_t *s,
12591249 for (cctx = & ctx -> stream -> ctx ; * cctx ; /* void */ ) {
12601250 if (* cctx == ctx ) {
12611251 if (!ctx -> publishing && ctx -> stream -> active ) {
1262- ngx_http_flv_live_stop ( s );
1252+ ngx_http_flv_live_set_status ( s , 0 );
12631253 }
12641254
12651255 * cctx = ctx -> next ;
0 commit comments