Skip to content

Commit ee55c21

Browse files
committed
Merge branch 'master' into control-redirect
2 parents 1385440 + a8d1484 commit ee55c21

5 files changed

+47
-47
lines changed

hls/ngx_rtmp_hls_module.c

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ ngx_rtmp_hls_get_fragment_id(ngx_rtmp_session_t *s, uint64_t ts)
741741

742742

743743
static ngx_int_t
744-
ngx_rtmp_hls_close_fragment(ngx_rtmp_session_t *s, ngx_int_t discont)
744+
ngx_rtmp_hls_close_fragment(ngx_rtmp_session_t *s)
745745
{
746746
ngx_rtmp_hls_ctx_t *ctx;
747747

@@ -750,9 +750,8 @@ ngx_rtmp_hls_close_fragment(ngx_rtmp_session_t *s, ngx_int_t discont)
750750
return NGX_OK;
751751
}
752752

753-
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
754-
"hls: close fragment n=%uL, discont=%i",
755-
ctx->frag, discont);
753+
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
754+
"hls: close fragment n=%uL", ctx->frag);
756755

757756
ngx_close_file(ctx->file.fd);
758757

@@ -1269,9 +1268,9 @@ ngx_rtmp_hls_close_stream(ngx_rtmp_session_t *s, ngx_rtmp_close_stream_t *v)
12691268
}
12701269

12711270
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
1272-
"hls: delete stream");
1271+
"hls: close stream");
12731272

1274-
ngx_rtmp_hls_close_fragment(s, 1);
1273+
ngx_rtmp_hls_close_fragment(s);
12751274

12761275
next:
12771276
return next_close_stream(s, v);
@@ -1394,7 +1393,7 @@ ngx_rtmp_hls_update_fragment(ngx_rtmp_session_t *s, uint64_t ts,
13941393
}
13951394

13961395
if (boundary) {
1397-
ngx_rtmp_hls_close_fragment(s, 0);
1396+
ngx_rtmp_hls_close_fragment(s);
13981397
ngx_rtmp_hls_open_fragment(s, ts, !f);
13991398
}
14001399

@@ -1480,7 +1479,7 @@ ngx_rtmp_hls_audio(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
14801479
}
14811480

14821481
if (codec_ctx->audio_codec_id != NGX_RTMP_AUDIO_AAC ||
1483-
codec_ctx->aac_header == NULL)
1482+
codec_ctx->aac_header == NULL || ngx_rtmp_is_codec_header(in))
14841483
{
14851484
return NGX_OK;
14861485
}
@@ -1797,11 +1796,12 @@ ngx_rtmp_hls_video(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
17971796
/*
17981797
* start new fragment if
17991798
* - we have video key frame AND
1800-
* - we have audio buffered or have no audio at all
1799+
* - we have audio buffered or have no audio at all or stream is closed
18011800
*/
18021801

18031802
b = ctx->aframe;
1804-
boundary = frame.key && (codec_ctx->aac_header == NULL || b->last > b->pos);
1803+
boundary = frame.key && (codec_ctx->aac_header == NULL || !ctx->opened ||
1804+
(b && b->last > b->pos));
18051805

18061806
ngx_rtmp_hls_update_fragment(s, frame.dts, boundary, 1);
18071807

@@ -1823,38 +1823,19 @@ ngx_rtmp_hls_video(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
18231823
}
18241824

18251825

1826-
static void
1827-
ngx_rtmp_hls_discontinue(ngx_rtmp_session_t *s)
1828-
{
1829-
ngx_rtmp_hls_ctx_t *ctx;
1830-
1831-
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_hls_module);
1832-
1833-
if (ctx == NULL || !ctx->opened) {
1834-
return;
1835-
}
1836-
1837-
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
1838-
"hld: discontinue");
1839-
1840-
ngx_close_file(ctx->file.fd);
1841-
ctx->opened = 0;
1842-
}
1843-
1844-
18451826
static ngx_int_t
18461827
ngx_rtmp_hls_stream_begin(ngx_rtmp_session_t *s, ngx_rtmp_stream_begin_t *v)
18471828
{
1848-
ngx_rtmp_hls_discontinue(s);
1849-
18501829
return next_stream_begin(s, v);
18511830
}
18521831

18531832

18541833
static ngx_int_t
18551834
ngx_rtmp_hls_stream_eof(ngx_rtmp_session_t *s, ngx_rtmp_stream_eof_t *v)
18561835
{
1857-
ngx_rtmp_hls_discontinue(s);
1836+
ngx_rtmp_hls_flush_audio(s);
1837+
1838+
ngx_rtmp_hls_close_fragment(s);
18581839

18591840
return next_stream_eof(s, v);
18601841
}

ngx_rtmp_auto_push_module.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle)
102102
#if (NGX_HAVE_UNIX_DOMAIN)
103103
ngx_rtmp_auto_push_conf_t *apcf;
104104
ngx_listening_t *ls, *lss;
105-
struct sockaddr_un *sun;
105+
struct sockaddr_un *saun;
106106
int reuseaddr;
107107
ngx_socket_t s;
108108
size_t n;
@@ -157,26 +157,26 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle)
157157
ls->addr_ntop = 0;
158158

159159
ls->socklen = sizeof(struct sockaddr_un);
160-
sun = ngx_pcalloc(cycle->pool, ls->socklen);
161-
ls->sockaddr = (struct sockaddr *) sun;
160+
saun = ngx_pcalloc(cycle->pool, ls->socklen);
161+
ls->sockaddr = (struct sockaddr *) saun;
162162
if (ls->sockaddr == NULL) {
163163
return NGX_ERROR;
164164
}
165-
sun->sun_family = AF_UNIX;
166-
*ngx_snprintf((u_char *) sun->sun_path, sizeof(sun->sun_path),
165+
saun->sun_family = AF_UNIX;
166+
*ngx_snprintf((u_char *) saun->sun_path, sizeof(saun->sun_path),
167167
"%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i",
168168
&apcf->socket_dir, ngx_process_slot)
169169
= 0;
170170

171171
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, cycle->log, 0,
172172
"auto_push: create socket '%s'",
173-
sun->sun_path);
173+
saun->sun_path);
174174

175-
if (ngx_file_info(sun->sun_path, &fi) != ENOENT) {
175+
if (ngx_file_info(saun->sun_path, &fi) != ENOENT) {
176176
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, cycle->log, 0,
177177
"auto_push: delete existing socket '%s'",
178-
sun->sun_path);
179-
ngx_delete_file(sun->sun_path);
178+
saun->sun_path);
179+
ngx_delete_file(saun->sun_path);
180180
}
181181

182182
ngx_str_set(&ls->addr_text, "worker_socket");
@@ -205,7 +205,7 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle)
205205
}
206206
}
207207

208-
if (bind(s, (struct sockaddr *) sun, sizeof(*sun)) == -1) {
208+
if (bind(s, (struct sockaddr *) saun, sizeof(*saun)) == -1) {
209209
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
210210
ngx_nonblocking_n " worker_socket bind failed");
211211
goto sock_error;
@@ -228,7 +228,7 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle)
228228
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
229229
ngx_close_socket_n " worker_socket failed");
230230
}
231-
ngx_delete_file(sun->sun_path);
231+
ngx_delete_file(saun->sun_path);
232232

233233
return NGX_ERROR;
234234

ngx_rtmp_exec_module.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,9 @@ ngx_rtmp_exec_close_stream(ngx_rtmp_session_t *s, ngx_rtmp_close_stream_t *v)
12351235
if (ctx->flags & NGX_RTMP_EXEC_PUBLISHING) {
12361236
ngx_rtmp_exec_unmanaged(s, &eacf->conf[NGX_RTMP_EXEC_PUBLISH_DONE],
12371237
"publish_done");
1238-
} else {
1238+
}
1239+
1240+
if (ctx->flags & NGX_RTMP_EXEC_PLAYING) {
12391241
ngx_rtmp_exec_unmanaged(s, &eacf->conf[NGX_RTMP_EXEC_PLAY_DONE],
12401242
"play_done");
12411243
}

ngx_rtmp_notify_module.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <ngx_config.h>
88
#include <ngx_core.h>
9+
#include <ngx_md5.h>
910
#include "ngx_rtmp.h"
1011
#include "ngx_rtmp_cmd_module.h"
1112
#include "ngx_rtmp_netcall_module.h"
@@ -979,6 +980,22 @@ ngx_rtmp_notify_connect_handle(ngx_rtmp_session_t *s,
979980
}
980981

981982

983+
static void
984+
ngx_rtmp_notify_set_name(u_char *dst, size_t dst_len, u_char *src,
985+
size_t src_len)
986+
{
987+
u_char result[16], *p;
988+
ngx_md5_t md5;
989+
990+
ngx_md5_init(&md5);
991+
ngx_md5_update(&md5, src, src_len);
992+
ngx_md5_final(result, &md5);
993+
994+
p = ngx_hex_dump(dst, result, ngx_min((dst_len - 1) / 2, 16));
995+
*p = '\0';
996+
}
997+
998+
982999
static ngx_int_t
9831000
ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s,
9841001
void *arg, ngx_chain_t *in)
@@ -1025,7 +1042,7 @@ ngx_rtmp_notify_publish_handle(ngx_rtmp_session_t *s,
10251042

10261043
nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module);
10271044
if (nacf->relay_redirect) {
1028-
*ngx_cpymem(v->name, name, rc) = 0;
1045+
ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t) rc);
10291046
}
10301047

10311048
ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
@@ -1104,7 +1121,7 @@ ngx_rtmp_notify_play_handle(ngx_rtmp_session_t *s,
11041121

11051122
nacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_notify_module);
11061123
if (nacf->relay_redirect) {
1107-
*ngx_cpymem(v->name, name, rc) = 0;
1124+
ngx_rtmp_notify_set_name(v->name, NGX_RTMP_MAX_NAME, name, (size_t) rc);
11081125
}
11091126

11101127
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,

ngx_rtmp_stat_module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ ngx_rtmp_stat_bw(ngx_http_request_t *r, ngx_chain_t ***lll,
255255
ngx_rtmp_bandwidth_t *bw, char *name,
256256
ngx_uint_t flags)
257257
{
258-
u_char buf[NGX_INT64_LEN + 1];
258+
u_char buf[NGX_INT64_LEN + 9];
259259

260260
ngx_rtmp_update_bandwidth(bw, 0);
261261

0 commit comments

Comments
 (0)