8
8
#include <ngx_config.h>
9
9
#include <ngx_core.h>
10
10
#include "ngx_rtmp.h"
11
+ #include "ngx_rtmp_cmd_module.h"
11
12
#include "ngx_live_relay.h"
12
13
#include "ngx_dynamic_resolver.h"
13
14
#include "ngx_toolkit_misc.h"
14
15
#include "ngx_netcall.h"
15
16
16
17
18
+ static ngx_rtmp_publish_pt next_publish ;
19
+ static ngx_rtmp_play_pt next_play ;
20
+ static ngx_rtmp_close_stream_pt next_close_stream ;
21
+
22
+
17
23
static ngx_live_push_pt next_push ;
18
24
static ngx_live_pull_pt next_pull ;
19
25
static ngx_live_push_close_pt next_push_close ;
@@ -137,6 +143,9 @@ typedef struct {
137
143
ngx_rtmp_oclp_event_t * event ;
138
144
ngx_uint_t type ;
139
145
ngx_live_relay_t * relay ;
146
+
147
+ ngx_rtmp_publish_t publish_v ;
148
+ ngx_rtmp_play_t play_v ;
140
149
} ngx_rtmp_oclp_ctx_t ;
141
150
142
151
@@ -815,85 +824,97 @@ static void
815
824
ngx_rtmp_oclp_pnotify_start_handle (ngx_netcall_ctx_t * nctx , ngx_int_t code )
816
825
{
817
826
ngx_rtmp_session_t * s ;
827
+ ngx_rtmp_oclp_ctx_t * octx ;
818
828
819
829
s = nctx -> data ;
820
830
821
- if (code != NGX_HTTP_OK ) {
831
+ octx = ngx_rtmp_get_module_ctx (s , ngx_rtmp_oclp_module );
832
+
833
+ if (code < NGX_HTTP_OK || code > NGX_HTTP_SPECIAL_RESPONSE ) {
822
834
ngx_log_error (NGX_LOG_ERR , ngx_cycle -> log , 0 ,
823
835
"oclp %s start notify error: %i" ,
824
836
ngx_rtmp_oclp_app_type [nctx -> type ], code );
825
837
826
838
if (code != -1 ) {
827
- if (nctx -> type == NGX_RTMP_OCLP_PUBLISH ) {
828
- ngx_rtmp_send_status (s , "NetStream.Publish.Forbidden" , "status" ,
829
- "Publish stream Forbidden" );
830
- } else {
831
- s -> status = 403 ;
832
- ngx_rtmp_send_status (s , "NetStream.Play.Forbidden" , "status" ,
833
- "Play stream Forbidden" );
834
- }
835
- ngx_rtmp_finalize_session (s );
839
+ goto error ;
836
840
}
837
841
838
- return ;
842
+ goto next ;
843
+ }
844
+
845
+ next :
846
+ if (octx -> type == NGX_RTMP_OCLP_PUBLISH ) {
847
+ if (next_publish (s , & octx -> publish_v ) != NGX_OK ) {
848
+ goto error ;
849
+ }
850
+ } else {
851
+ if (next_play (s , & octx -> play_v ) != NGX_OK ) {
852
+ goto error ;
853
+ }
839
854
}
840
855
841
856
ngx_rtmp_oclp_common_update_create (s , nctx );
857
+
858
+ return ;
859
+
860
+ error :
861
+ if (octx -> type == NGX_RTMP_OCLP_PUBLISH ) {
862
+ ngx_rtmp_send_status (s , "NetStream.Publish.Forbidden" , "status" ,
863
+ "Publish stream Forbidden" );
864
+ } else {
865
+ s -> status = 403 ;
866
+ ngx_rtmp_send_status (s , "NetStream.Play.Forbidden" , "status" ,
867
+ "Play stream Forbidden" );
868
+ }
869
+ ngx_rtmp_finalize_session (s );
842
870
}
843
871
844
- void
845
- ngx_rtmp_oclp_pnotify_start (ngx_rtmp_session_t * s , unsigned publishing )
872
+ static ngx_int_t
873
+ ngx_rtmp_oclp_pnotify_start (ngx_rtmp_session_t * s , ngx_uint_t type )
846
874
{
847
875
ngx_rtmp_oclp_app_conf_t * oacf ;
848
876
ngx_rtmp_oclp_event_t * event ;
849
877
ngx_rtmp_oclp_ctx_t * ctx ;
850
878
ngx_netcall_ctx_t * nctx ;
851
- ngx_uint_t type ;
852
-
853
- if (s -> relay || s -> interprocess ) {
854
- return ;
855
- }
856
-
857
- type = publishing ? NGX_RTMP_OCLP_PUBLISH : NGX_RTMP_OCLP_PLAY ;
858
879
859
880
oacf = ngx_rtmp_get_module_app_conf (s , ngx_rtmp_oclp_module );
860
881
861
882
if (oacf -> events [type ].nelts == 0 ) {
862
- return ;
883
+ return NGX_DECLINED ;
863
884
}
864
885
865
886
ctx = ngx_rtmp_get_module_ctx (s , ngx_rtmp_oclp_module );
866
887
if (ctx == NULL ) {
867
888
ctx = ngx_pcalloc (s -> pool , sizeof (ngx_rtmp_oclp_ctx_t ));
868
889
if (ctx == NULL ) {
869
- return ;
890
+ ngx_log_error (NGX_LOG_ERR , s -> log , 0 , "palloc oclp ctx failed" );
891
+ return NGX_ERROR ;
870
892
}
871
893
ngx_rtmp_set_ctx (s , ctx , ngx_rtmp_oclp_module );
872
894
}
873
895
874
896
event = oacf -> events [type ].elts ;
875
897
876
- if (oacf -> events [type ].nelts &&
877
- (event -> stage & NGX_RTMP_OCLP_START ) == NGX_RTMP_OCLP_START )
878
- {
879
- nctx = ngx_netcall_create_ctx (type , & event -> groupid ,
880
- event -> stage , event -> timeout , event -> update , 0 );
898
+ nctx = ngx_netcall_create_ctx (type , & event -> groupid ,
899
+ event -> stage , event -> timeout , event -> update , 0 );
881
900
882
- ngx_rtmp_oclp_common_url (& nctx -> url , s , event , nctx ,
883
- NGX_RTMP_OCLP_START );
884
- nctx -> handler = ngx_rtmp_oclp_pnotify_start_handle ;
885
- nctx -> data = s ;
901
+ ngx_rtmp_oclp_common_url (& nctx -> url , s , event , nctx ,
902
+ NGX_RTMP_OCLP_START );
903
+ nctx -> handler = ngx_rtmp_oclp_pnotify_start_handle ;
904
+ nctx -> data = s ;
886
905
887
- ctx -> nctx = nctx ;
906
+ ctx -> nctx = nctx ;
907
+ ctx -> type = type ;
888
908
889
- ngx_log_error (NGX_LOG_INFO , s -> log , 0 , "oclp %s start create %V" ,
890
- ngx_rtmp_oclp_app_type [nctx -> type ], & nctx -> url );
909
+ ngx_log_error (NGX_LOG_INFO , s -> log , 0 , "oclp %s start create %V" ,
910
+ ngx_rtmp_oclp_app_type [nctx -> type ], & nctx -> url );
891
911
892
- ngx_netcall_create (nctx , s -> log );
893
- }
912
+ ngx_netcall_create (nctx , s -> log );
913
+
914
+ return NGX_OK ;
894
915
}
895
916
896
- void
917
+ static void
897
918
ngx_rtmp_oclp_pnotify_done (ngx_rtmp_session_t * s )
898
919
{
899
920
ngx_rtmp_oclp_ctx_t * ctx ;
@@ -1459,6 +1480,73 @@ ngx_rtmp_oclp_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h, ngx_chain_t *in)
1459
1480
return NGX_OK ;
1460
1481
}
1461
1482
1483
+ static ngx_int_t
1484
+ ngx_rtmp_oclp_publish (ngx_rtmp_session_t * s , ngx_rtmp_publish_t * v )
1485
+ {
1486
+ ngx_rtmp_oclp_ctx_t * octx ;
1487
+
1488
+ if (s -> relay || s -> interprocess ) {
1489
+ goto next ;
1490
+ }
1491
+
1492
+ switch (ngx_rtmp_oclp_pnotify_start (s , NGX_RTMP_OCLP_PUBLISH )) {
1493
+ case NGX_OK :
1494
+ break ;
1495
+ case NGX_DECLINED :
1496
+ goto next ;
1497
+ default :
1498
+ return NGX_ERROR ;
1499
+ }
1500
+
1501
+ octx = ngx_rtmp_get_module_ctx (s , ngx_rtmp_oclp_module );
1502
+ ngx_memcpy (& octx -> publish_v , v , sizeof (ngx_rtmp_publish_t ));
1503
+
1504
+ return NGX_OK ;
1505
+
1506
+ next :
1507
+ return next_publish (s , v );
1508
+ }
1509
+
1510
+ static ngx_int_t
1511
+ ngx_rtmp_oclp_play (ngx_rtmp_session_t * s , ngx_rtmp_play_t * v )
1512
+ {
1513
+ ngx_rtmp_oclp_ctx_t * octx ;
1514
+
1515
+ if (s -> relay || s -> interprocess ) {
1516
+ goto next ;
1517
+ }
1518
+
1519
+ switch (ngx_rtmp_oclp_pnotify_start (s , NGX_RTMP_OCLP_PLAY )) {
1520
+ case NGX_OK :
1521
+ break ;
1522
+ case NGX_DECLINED :
1523
+ goto next ;
1524
+ default :
1525
+ return NGX_ERROR ;
1526
+ }
1527
+
1528
+ octx = ngx_rtmp_get_module_ctx (s , ngx_rtmp_oclp_module );
1529
+ ngx_memcpy (& octx -> play_v , v , sizeof (ngx_rtmp_play_t ));
1530
+
1531
+ return NGX_OK ;
1532
+
1533
+ next :
1534
+ return next_play (s , v );
1535
+ }
1536
+
1537
+ static ngx_int_t
1538
+ ngx_rtmp_oclp_close_stream (ngx_rtmp_session_t * s , ngx_rtmp_close_stream_t * v )
1539
+ {
1540
+ if (s -> relay || s -> interprocess ) {
1541
+ goto next ;
1542
+ }
1543
+
1544
+ ngx_rtmp_oclp_pnotify_done (s );
1545
+
1546
+ next :
1547
+ return next_close_stream (s , v );
1548
+ }
1549
+
1462
1550
static ngx_int_t
1463
1551
ngx_rtmp_oclp_postconfiguration (ngx_conf_t * cf )
1464
1552
{
@@ -1485,5 +1573,14 @@ ngx_rtmp_oclp_postconfiguration(ngx_conf_t *cf)
1485
1573
next_pull_close = ngx_live_pull_close ;
1486
1574
ngx_live_pull_close = ngx_rtmp_oclp_pull_close ;
1487
1575
1576
+ next_publish = ngx_rtmp_publish ;
1577
+ ngx_rtmp_publish = ngx_rtmp_oclp_publish ;
1578
+
1579
+ next_play = ngx_rtmp_play ;
1580
+ ngx_rtmp_play = ngx_rtmp_oclp_play ;
1581
+
1582
+ next_close_stream = ngx_rtmp_close_stream ;
1583
+ ngx_rtmp_close_stream = ngx_rtmp_oclp_close_stream ;
1584
+
1488
1585
return NGX_OK ;
1489
1586
}
0 commit comments