Skip to content

Commit 053b3ef

Browse files
authored
Merge pull request #1 from arut/master
merge
2 parents 04f0ab9 + e636a04 commit 053b3ef

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

dash/ngx_rtmp_dash_module.c

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ typedef struct {
5252
ngx_str_t playlist_bak;
5353
ngx_str_t name;
5454
ngx_str_t stream;
55-
ngx_time_t start_time;
55+
time_t start_time;
5656

5757
ngx_uint_t nfrags;
5858
ngx_uint_t frag;
@@ -228,8 +228,8 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
228228
ngx_rtmp_dash_app_conf_t *dacf;
229229

230230
static u_char buffer[NGX_RTMP_DASH_BUFSIZE];
231-
static u_char start_time[sizeof("1970-09-28T12:00:00+06:00")];
232-
static u_char end_time[sizeof("1970-09-28T12:00:00+06:00")];
231+
static u_char start_time[sizeof("1970-09-28T12:00:00Z")];
232+
static u_char pub_time[sizeof("1970-09-28T12:00:00Z")];
233233

234234
dacf = ngx_rtmp_get_module_app_conf(s, ngx_rtmp_dash_module);
235235
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_dash_module);
@@ -259,11 +259,10 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
259259
" type=\"dynamic\"\n" \
260260
" xmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n" \
261261
" availabilityStartTime=\"%s\"\n" \
262-
" availabilityEndTime=\"%s\"\n" \
262+
" publishTime=\"%s\"\n" \
263263
" minimumUpdatePeriod=\"PT%uiS\"\n" \
264264
" minBufferTime=\"PT%uiS\"\n" \
265-
" timeShiftBufferDepth=\"PT0H0M0.00S\"\n" \
266-
" suggestedPresentationDelay=\"PT%uiS\"\n" \
265+
" timeShiftBufferDepth=\"PT%uiS\"\n" \
267266
" profiles=\"urn:hbbtv:dash:profile:isoff-live:2012," \
268267
"urn:mpeg:dash:profile:isoff-live:2011\"\n" \
269268
" xmlns:xsi=\"http://www.w3.org/2011/XMLSchema-instance\"\n" \
@@ -285,11 +284,9 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
285284
" width=\"%ui\"\n" \
286285
" height=\"%ui\"\n" \
287286
" frameRate=\"%ui\"\n" \
288-
" sar=\"1:1\"\n" \
289287
" startWithSAP=\"1\"\n" \
290288
" bandwidth=\"%ui\">\n" \
291289
" <SegmentTemplate\n" \
292-
" presentationTimeOffset=\"0\"\n" \
293290
" timescale=\"1000\"\n" \
294291
" media=\"%V%s$Time$.m4v\"\n" \
295292
" initialization=\"%V%sinit.m4v\">\n" \
@@ -323,7 +320,6 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
323320
" startWithSAP=\"1\"\n" \
324321
" bandwidth=\"%ui\">\n" \
325322
" <SegmentTemplate\n" \
326-
" presentationTimeOffset=\"0\"\n" \
327323
" timescale=\"1000\"\n" \
328324
" media=\"%V%s$Time$.m4a\"\n" \
329325
" initialization=\"%V%sinit.m4a\">\n" \
@@ -341,38 +337,28 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
341337
" </Period>\n" \
342338
"</MPD>\n"
343339

344-
ngx_libc_localtime(ctx->start_time.sec +
345-
ngx_rtmp_dash_get_frag(s, 0)->timestamp / 1000, &tm);
346-
347-
*ngx_sprintf(start_time, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
348-
tm.tm_year + 1900, tm.tm_mon + 1,
349-
tm.tm_mday, tm.tm_hour,
350-
tm.tm_min, tm.tm_sec,
351-
ctx->start_time.gmtoff < 0 ? '-' : '+',
352-
ngx_abs(ctx->start_time.gmtoff / 60),
353-
ngx_abs(ctx->start_time.gmtoff % 60)) = 0;
354-
355-
ngx_libc_localtime(ctx->start_time.sec +
356-
(ngx_rtmp_dash_get_frag(s, ctx->nfrags - 1)->timestamp +
357-
ngx_rtmp_dash_get_frag(s, ctx->nfrags - 1)->duration) /
358-
1000, &tm);
359-
360-
*ngx_sprintf(end_time, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
361-
tm.tm_year + 1900, tm.tm_mon + 1,
362-
tm.tm_mday, tm.tm_hour,
363-
tm.tm_min, tm.tm_sec,
364-
ctx->start_time.gmtoff < 0 ? '-' : '+',
365-
ngx_abs(ctx->start_time.gmtoff / 60),
366-
ngx_abs(ctx->start_time.gmtoff % 60)) = 0;
340+
ngx_libc_gmtime(ctx->start_time, &tm);
341+
342+
ngx_sprintf(start_time, "%4d-%02d-%02dT%02d:%02d:%02dZ%Z",
343+
tm.tm_year + 1900, tm.tm_mon + 1,
344+
tm.tm_mday, tm.tm_hour,
345+
tm.tm_min, tm.tm_sec);
346+
347+
ngx_libc_gmtime(ngx_time(), &tm);
348+
349+
ngx_sprintf(pub_time, "%4d-%02d-%02dT%02d:%02d:%02dZ%Z",
350+
tm.tm_year + 1900, tm.tm_mon + 1,
351+
tm.tm_mday, tm.tm_hour,
352+
tm.tm_min, tm.tm_sec);
367353

368354
last = buffer + sizeof(buffer);
369355

370356
p = ngx_slprintf(buffer, last, NGX_RTMP_DASH_MANIFEST_HEADER,
371357
start_time,
372-
end_time,
373-
(ngx_uint_t) (dacf->fraglen / 1000),
358+
pub_time,
374359
(ngx_uint_t) (dacf->fraglen / 1000),
375-
(ngx_uint_t) (dacf->fraglen / 500));
360+
(ngx_uint_t) (dacf->fraglen / 500),
361+
(ngx_uint_t) (dacf->playlen / 1000));
376362

377363
n = ngx_write_fd(fd, buffer, p - buffer);
378364

@@ -952,7 +938,7 @@ ngx_rtmp_dash_publish(ngx_rtmp_session_t *s, ngx_rtmp_publish_t *v)
952938
"dash: playlist='%V' playlist_bak='%V' stream_pattern='%V'",
953939
&ctx->playlist, &ctx->playlist_bak, &ctx->stream);
954940

955-
ctx->start_time = *ngx_cached_time;
941+
ctx->start_time = ngx_time();
956942

957943
if (ngx_rtmp_dash_ensure_directory(s) != NGX_OK) {
958944
return NGX_ERROR;

ngx_rtmp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ typedef struct {
135135
#define NGX_RTMP_MSG_AGGREGATE 22
136136
#define NGX_RTMP_MSG_MAX 22
137137

138+
#define NGX_RTMP_MAX_CHUNK_SIZE 10485760
139+
138140
#define NGX_RTMP_CONNECT NGX_RTMP_MSG_MAX + 1
139141
#define NGX_RTMP_DISCONNECT NGX_RTMP_MSG_MAX + 2
140142
#define NGX_RTMP_HANDSHAKE_DONE NGX_RTMP_MSG_MAX + 3

ngx_rtmp_handler.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,12 @@ ngx_rtmp_set_chunk_size(ngx_rtmp_session_t *s, ngx_uint_t size)
821821
ngx_log_debug1(NGX_LOG_DEBUG_RTMP, s->connection->log, 0,
822822
"setting chunk_size=%ui", size);
823823

824+
if (size > NGX_RTMP_MAX_CHUNK_SIZE) {
825+
ngx_log_error(NGX_LOG_ALERT, s->connection->log, 0,
826+
"too big RTMP chunk size:%ui", size);
827+
return NGX_ERROR;
828+
}
829+
824830
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
825831

826832
s->in_old_pool = s->in_pool;

0 commit comments

Comments
 (0)