@@ -20,7 +20,9 @@ static void *ngx_http_flv_live_create_loc_conf(ngx_conf_t *cf);
2020static  char  * ngx_http_flv_live_merge_loc_conf (ngx_conf_t  * cf , void  * parent ,
2121 void  * child );
2222
23- static  u_char  ngx_flv_live_header [] =  "FLV\x1\x50円0円0円\x90円0円0円0円" ;
23+ static  u_char  ngx_flv_live_audio_header [] =  "FLV\x1\x10円0円0円\x90円0円0円0円" ;
24+ static  u_char  ngx_flv_live_video_header [] =  "FLV\x1\x40円0円0円\x90円0円0円0円" ;
25+ static  u_char  ngx_flv_live_av_header [] =  "FLV\x1\x50円0円0円\x90円0円0円0円" ;
2426
2527static  ngx_keyval_t  ngx_http_flv_live_headers [] =  {
2628 { ngx_string ("Cache-Control" ), ngx_string ("no-cache" ) },
@@ -41,6 +43,8 @@ typedef struct {
4143 ngx_str_t  swf_url ;
4244 ngx_str_t  tc_url ;
4345 ngx_str_t  page_url ;
46+  ngx_uint_t  audio ;
47+  ngx_uint_t  video ;
4448
4549 ngx_rtmp_addr_conf_t  * addr_conf ;
4650} ngx_http_flv_live_loc_conf_t ;
@@ -49,7 +53,7 @@ typedef struct {
4953static  ngx_command_t  ngx_http_flv_live_commands [] =  {
5054
5155 { ngx_string ("flv_live" ),
52-  NGX_HTTP_LOC_CONF |NGX_CONF_TAKE12 ,
56+  NGX_HTTP_LOC_CONF |NGX_CONF_TAKE123 ,
5357 ngx_http_flv_live ,
5458 NGX_HTTP_LOC_CONF_OFFSET ,
5559 0 ,
@@ -97,11 +101,14 @@ ngx_http_flv_live_send_header(ngx_http_request_t *r)
97101 ngx_keyval_t  * h ;
98102 ngx_buf_t  * b ;
99103 ngx_chain_t  out ;
104+  ngx_http_flv_live_loc_conf_t  * hflcf ;
100105
101106 if  (r -> header_sent ) {
102107 return  NGX_OK ;
103108 }
104109
110+  hflcf  =  ngx_http_get_module_loc_conf (r , ngx_http_flv_live_module );
111+ 105112 r -> headers_out .status  =  NGX_HTTP_OK ;
106113 r -> keepalive  =  0 ; /* set Connection to closed */ 
107114
@@ -124,8 +131,32 @@ ngx_http_flv_live_send_header(ngx_http_request_t *r)
124131 return  NGX_HTTP_INTERNAL_SERVER_ERROR ;
125132 }
126133
127-  b -> start  =  b -> pos  =  ngx_flv_live_header ;
128-  b -> end  =  b -> last  =  ngx_flv_live_header  +  sizeof (ngx_flv_live_header ) -  1 ;
134+  switch  (hflcf -> audio  | (hflcf -> video  <  1 )) {
135+  case  1 : // audio only 
136+  b -> start  =  b -> pos  =  ngx_flv_live_audio_header ;
137+  b -> end  =  b -> last  =  ngx_flv_live_audio_header  + 
138+  sizeof (ngx_flv_live_audio_header ) -  1 ;
139+  break ;
140+ 141+  case  2 : // video only 
142+  b -> start  =  b -> pos  =  ngx_flv_live_video_header ;
143+  b -> end  =  b -> last  =  ngx_flv_live_video_header  + 
144+  sizeof (ngx_flv_live_video_header ) -  1 ;
145+  break ;
146+ 147+  case  3 : // audio and video 
148+  b -> start  =  b -> pos  =  ngx_flv_live_av_header ;
149+  b -> end  =  b -> last  =  ngx_flv_live_av_header  + 
150+  sizeof (ngx_flv_live_av_header ) -  1 ;
151+  break ;
152+ 153+  default :
154+  ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
155+  "flv-live: send_header| av header config error." );
156+ 157+  return  NGX_HTTP_INTERNAL_SERVER_ERROR ;
158+  }
159+ 129160 b -> memory  =  1 ;
130161
131162 out .buf  =  b ;
@@ -631,6 +662,7 @@ ngx_http_flv_live(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
631662 ngx_http_flv_live_loc_conf_t  * hflcf ;
632663 ngx_str_t  * value , v ;
633664 ngx_uint_t  i ;
665+  ngx_uint_t  audio , video ;
634666
635667 clcf  =  ngx_http_conf_get_module_loc_conf (cf , ngx_http_core_module );
636668 clcf -> handler  =  ngx_http_flv_live_handler ;
@@ -644,15 +676,37 @@ ngx_http_flv_live(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
644676 return  NGX_CONF_ERROR ;
645677 }
646678
679+  audio  =  NGX_CONF_UNSET_UINT ;
680+  video  =  NGX_CONF_UNSET_UINT ;
681+ 647682 for  (i  =  2 ; i  <  cf -> args -> nelts ; ++ i ) {
648683 if  (ngx_strncmp (value [i ].data , "app=" , 4 ) ==  0 ) {
649684 v .data  =  value [i ].data  +  4 ;
650685 v .len  =  value [i ].len  -  4 ;
651686 hflcf -> app  =  v ;
687+  } else  if  (ngx_strncmp (value [i ].data , "audio=" , 6 ) ==  0 ) {
688+  v .data  =  value [i ].data  +  6 ;
689+  v .len  =  value [i ].len  -  6 ;
690+  audio  =  ngx_atoi (v .data , v .len );
691+  } else  if  (ngx_strncmp (value [i ].data , "video=" , 6 ) ==  0 ) {
692+  v .data  =  value [i ].data  +  6 ;
693+  v .len  =  value [i ].len  -  6 ;
694+  video  =  ngx_atoi (v .data , v .len );
652695 } else  {
653696 return  NGX_CONF_ERROR ;
654697 }
655698 }
656699
700+  if  (audio  ==  NGX_CONF_UNSET_UINT ) {
701+  audio  =  1 ;
702+  }
703+ 704+  if  (video  ==  NGX_CONF_UNSET_UINT ) {
705+  video  =  1 ;
706+  }
707+ 708+  hflcf -> audio  =  audio ;
709+  hflcf -> video  =  video ;
710+ 657711 return  NGX_CONF_OK ;
658712}
0 commit comments