@@ -518,15 +518,15 @@ ngx_rtmp_hls_write_playlist(ngx_rtmp_session_t *s)
518
518
p = buffer ;
519
519
end = p + sizeof (buffer );
520
520
521
- p = ngx_slprintf (buffer , end ,
521
+ p = ngx_slprintf (p , end ,
522
522
"#EXTM3U\n"
523
523
"#EXT-X-VERSION:3\n"
524
524
"#EXT-X-MEDIA-SEQUENCE:%uL\n"
525
525
"#EXT-X-TARGETDURATION:%ui\n" ,
526
526
ctx -> frag , max_frag );
527
527
528
528
if (hacf -> type == NGX_RTMP_HLS_TYPE_EVENT ) {
529
- ngx_slprintf (p , end , "#EXT-X-PLAYLIST-TYPE: EVENT\n" );
529
+ p = ngx_slprintf (p , end , "#EXT-X-PLAYLIST-TYPE: EVENT\n" );
530
530
}
531
531
532
532
n = ngx_write_fd (fd , buffer , p - buffer );
@@ -565,7 +565,7 @@ ngx_rtmp_hls_write_playlist(ngx_rtmp_session_t *s)
565
565
p = ngx_slprintf (p , end , "#EXT-X-KEY:METHOD=AES-128,"
566
566
"URI=\"%V%V%s%uL.key\",IV=0x%032XL" ,
567
567
& hacf -> keys_url , & key_name_part ,
568
- key_sep , f -> key_id );
568
+ key_sep , f -> key_id , f -> key_id );
569
569
}
570
570
571
571
p = ngx_slprintf (p , end ,
@@ -914,18 +914,19 @@ ngx_rtmp_hls_open_fragment(ngx_rtmp_session_t *s, uint64_t ts,
914
914
ctx -> keyfile .data ? ctx -> keyfile .data : (u_char * ) "" ,
915
915
ctx -> frag , ctx -> nfrags , ts , discont );
916
916
917
- if (ngx_rtmp_mpegts_open_file ( & ctx -> file , ctx -> stream . data ,
918
- s -> connection -> log )
917
+ if (hacf -> keys &&
918
+ ngx_rtmp_mpegts_init_encryption ( & ctx -> file , ctx -> key , 16 , ctx -> key_id )
919
919
!= NGX_OK )
920
920
{
921
+ ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
922
+ "hls: failed to initialize hls encryption" );
921
923
return NGX_ERROR ;
922
924
}
923
925
924
- if (hacf -> keys &&
925
- ngx_rtmp_mpegts_init_encryption (& ctx -> file , ctx -> key , 16 , id ) != NGX_OK )
926
+ if (ngx_rtmp_mpegts_open_file (& ctx -> file , ctx -> stream .data ,
927
+ s -> connection -> log )
928
+ != NGX_OK )
926
929
{
927
- ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
928
- "hls: failed to initialize hls encryption" );
929
930
return NGX_ERROR ;
930
931
}
931
932
@@ -938,6 +939,7 @@ ngx_rtmp_hls_open_fragment(ngx_rtmp_session_t *s, uint64_t ts,
938
939
f -> active = 1 ;
939
940
f -> discont = discont ;
940
941
f -> id = id ;
942
+ f -> key_id = ctx -> key_id ;
941
943
942
944
ctx -> frag_ts = ts ;
943
945
@@ -2096,8 +2098,8 @@ ngx_rtmp_hls_cleanup_dir(ngx_str_t *ppath, ngx_msec_t playlen)
2096
2098
{
2097
2099
max_age = playlen / 1000 ;
2098
2100
2099
- } else if (name .len >= 4 && name .data [name .len - 3 ] == '.' &&
2100
- name .data [name .len - 2 ] == 'k' &&
2101
+ } else if (name .len >= 4 && name .data [name .len - 4 ] == '.' &&
2102
+ name .data [name .len - 3 ] == 'k' &&
2101
2103
name .data [name .len - 2 ] == 'e' &&
2102
2104
name .data [name .len - 1 ] == 'y' )
2103
2105
{
@@ -2296,15 +2298,13 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
2296
2298
}
2297
2299
}
2298
2300
2299
- if (conf -> keys_path .len == 0 ) {
2300
- conf -> keys_path = conf -> path ;
2301
- }
2301
+ ngx_conf_merge_str_value (conf -> path , prev -> path , "" );
2302
2302
2303
- if (conf -> keys && conf -> keys_path . len && conf -> cleanup &&
2304
- ngx_strcmp (conf -> keys_path .data , conf -> path .data ) = = 0 &&
2303
+ if (conf -> keys && conf -> cleanup && conf -> keys_path . len &&
2304
+ ngx_strcmp (conf -> keys_path .data , conf -> path .data ) ! = 0 &&
2305
2305
conf -> type != NGX_RTMP_HLS_TYPE_EVENT )
2306
2306
{
2307
- if (conf -> keys_path .data [conf -> path .len - 1 ] == '/' ) {
2307
+ if (conf -> keys_path .data [conf -> keys_path .len - 1 ] == '/' ) {
2308
2308
conf -> keys_path .len -- ;
2309
2309
}
2310
2310
@@ -2332,7 +2332,11 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
2332
2332
}
2333
2333
}
2334
2334
2335
- ngx_conf_merge_str_value (conf -> path , prev -> path , "" );
2335
+ ngx_conf_merge_str_value (conf -> keys_path , prev -> keys_path , "" );
2336
+
2337
+ if (conf -> keys_path .len == 0 ) {
2338
+ conf -> keys_path = conf -> path ;
2339
+ }
2336
2340
2337
2341
return NGX_CONF_OK ;
2338
2342
}
0 commit comments