Skip to content

Commit 737ea5c

Browse files
committed
implemented HLS EVENT playlist type
1 parent 67443c2 commit 737ea5c

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

hls/ngx_rtmp_hls_module.c

+30-3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ typedef struct {
9393
ngx_str_t path;
9494
ngx_uint_t naming;
9595
ngx_uint_t slicing;
96+
ngx_uint_t type;
9697
ngx_path_t *slot;
9798
ngx_msec_t max_audio_delay;
9899
size_t audio_buffer_size;
@@ -111,6 +112,10 @@ typedef struct {
111112
#define NGX_RTMP_HLS_SLICING_ALIGNED 2
112113

113114

115+
#define NGX_RTMP_HLS_TYPE_LIVE 1
116+
#define NGX_RTMP_HLS_TYPE_EVENT 2
117+
118+
114119
static ngx_conf_enum_t ngx_rtmp_hls_naming_slots[] = {
115120
{ ngx_string("sequential"), NGX_RTMP_HLS_NAMING_SEQUENTIAL },
116121
{ ngx_string("timestamp"), NGX_RTMP_HLS_NAMING_TIMESTAMP },
@@ -126,6 +131,13 @@ static ngx_conf_enum_t ngx_rtmp_hls_slicing_slots[] = {
126131
};
127132

128133

134+
static ngx_conf_enum_t ngx_rtmp_hls_type_slots[] = {
135+
{ ngx_string("live"), NGX_RTMP_HLS_TYPE_LIVE },
136+
{ ngx_string("event"), NGX_RTMP_HLS_TYPE_EVENT },
137+
{ ngx_null_string, 0 }
138+
};
139+
140+
129141
static ngx_command_t ngx_rtmp_hls_commands[] = {
130142

131143
{ ngx_string("hls"),
@@ -205,6 +217,13 @@ static ngx_command_t ngx_rtmp_hls_commands[] = {
205217
offsetof(ngx_rtmp_hls_app_conf_t, slicing),
206218
&ngx_rtmp_hls_slicing_slots },
207219

220+
{ ngx_string("hls_type"),
221+
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
222+
ngx_conf_set_enum_slot,
223+
NGX_RTMP_APP_CONF_OFFSET,
224+
offsetof(ngx_rtmp_hls_app_conf_t, type),
225+
&ngx_rtmp_hls_type_slots },
226+
208227
{ ngx_string("hls_max_audio_delay"),
209228
NGX_RTMP_MAIN_CONF|NGX_RTMP_SRV_CONF|NGX_RTMP_APP_CONF|NGX_CONF_TAKE1,
210229
ngx_conf_set_msec_slot,
@@ -521,8 +540,11 @@ ngx_rtmp_hls_write_playlist(ngx_rtmp_session_t *s)
521540
"#EXTM3U\n"
522541
"#EXT-X-VERSION:3\n"
523542
"#EXT-X-MEDIA-SEQUENCE:%uL\n"
524-
"#EXT-X-TARGETDURATION:%ui\n",
525-
ctx->frag, max_frag);
543+
"#EXT-X-TARGETDURATION:%ui\n"
544+
"%s",
545+
ctx->frag, max_frag,
546+
hacf->type == NGX_RTMP_HLS_TYPE_EVENT ?
547+
"#EXT-X-PLAYLIST-TYPE: EVENT\n" : "");
526548

527549
n = ngx_write_fd(fd, buffer, p - buffer);
528550
if (n < 0) {
@@ -2068,6 +2090,7 @@ ngx_rtmp_hls_create_app_conf(ngx_conf_t *cf)
20682090
conf->nested = NGX_CONF_UNSET;
20692091
conf->naming = NGX_CONF_UNSET_UINT;
20702092
conf->slicing = NGX_CONF_UNSET_UINT;
2093+
conf->type = NGX_CONF_UNSET_UINT;
20712094
conf->max_audio_delay = NGX_CONF_UNSET_MSEC;
20722095
conf->audio_buffer_size = NGX_CONF_UNSET_SIZE;
20732096
conf->cleanup = NGX_CONF_UNSET;
@@ -2097,6 +2120,8 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
20972120
NGX_RTMP_HLS_NAMING_SEQUENTIAL);
20982121
ngx_conf_merge_uint_value(conf->slicing, prev->slicing,
20992122
NGX_RTMP_HLS_SLICING_PLAIN);
2123+
ngx_conf_merge_uint_value(conf->type, prev->type,
2124+
NGX_RTMP_HLS_TYPE_LIVE);
21002125
ngx_conf_merge_msec_value(conf->max_audio_delay, prev->max_audio_delay,
21012126
300);
21022127
ngx_conf_merge_size_value(conf->audio_buffer_size, prev->audio_buffer_size,
@@ -2110,7 +2135,9 @@ ngx_rtmp_hls_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
21102135

21112136
/* schedule cleanup */
21122137

2113-
if (conf->path.len == 0 || !conf->cleanup) {
2138+
if (conf->path.len == 0 || !conf->cleanup ||
2139+
conf->type == NGX_RTMP_HLS_TYPE_EVENT)
2140+
{
21142141
return NGX_CONF_OK;
21152142
}
21162143

0 commit comments

Comments
 (0)