Skip to content

Commit 96e60a4

Browse files
committed
fixed dash mp4 format & writer style
1 parent 6e1008e commit 96e60a4

File tree

3 files changed

+113
-110
lines changed

3 files changed

+113
-110
lines changed

dash/ngx_rtmp_dash_module.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,13 @@ ngx_rtmp_dash_write_playlist(ngx_rtmp_session_t *s)
457457
static ngx_int_t
458458
ngx_rtmp_dash_write_init_segments(ngx_rtmp_session_t *s)
459459
{
460-
ngx_fd_t fd;
461-
ngx_int_t rc;
462-
ngx_buf_t b;
463-
ngx_rtmp_dash_ctx_t *ctx;
464-
ngx_rtmp_codec_ctx_t *codec_ctx;
465-
ngx_rtmp_mp4_metadata_t metadata;
460+
ngx_fd_t fd;
461+
ngx_int_t rc;
462+
ngx_buf_t b;
463+
ngx_rtmp_dash_ctx_t *ctx;
464+
ngx_rtmp_codec_ctx_t *codec_ctx;
466465

467-
static u_char buffer[NGX_RTMP_DASH_BUFSIZE];
466+
static u_char buffer[NGX_RTMP_DASH_BUFSIZE];
468467

469468
ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_dash_module);
470469
codec_ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_codec_module);
@@ -473,9 +472,6 @@ ngx_rtmp_dash_write_init_segments(ngx_rtmp_session_t *s)
473472
return NGX_ERROR;
474473
}
475474

476-
metadata.width = codec_ctx->width;
477-
metadata.height = codec_ctx->height;
478-
479475
/* init video */
480476

481477
*ngx_sprintf(ctx->stream.data + ctx->stream.len, "init.m4v") = 0;
@@ -493,10 +489,9 @@ ngx_rtmp_dash_write_init_segments(ngx_rtmp_session_t *s)
493489
b.end = b.start + sizeof(buffer);
494490
b.pos = b.last = b.start;
495491

496-
metadata.video = 1;
497-
498-
ngx_rtmp_mp4_write_ftyp(&b, NGX_RTMP_MP4_FILETYPE_INIT, &metadata);
499-
ngx_rtmp_mp4_write_moov(s, &b, &metadata);
492+
ngx_rtmp_mp4_write_ftyp(&b, NGX_RTMP_MP4_FILETYPE_INIT,
493+
NGX_RTMP_MP4_VIDEO_TRACK);
494+
ngx_rtmp_mp4_write_moov(s, &b, NGX_RTMP_MP4_VIDEO_TRACK);
500495

501496
rc = ngx_write_fd(fd, b.start, (size_t) (b.last - b.start));
502497
if (rc == NGX_ERROR) {
@@ -521,10 +516,9 @@ ngx_rtmp_dash_write_init_segments(ngx_rtmp_session_t *s)
521516

522517
b.pos = b.last = b.start;
523518

524-
metadata.video = 0;
525-
526-
ngx_rtmp_mp4_write_ftyp(&b, NGX_RTMP_MP4_FILETYPE_INIT, &metadata);
527-
ngx_rtmp_mp4_write_moov(s, &b, &metadata);
519+
ngx_rtmp_mp4_write_ftyp(&b, NGX_RTMP_MP4_FILETYPE_INIT,
520+
NGX_RTMP_MP4_AUDIO_TRACK);
521+
ngx_rtmp_mp4_write_moov(s, &b, NGX_RTMP_MP4_AUDIO_TRACK);
528522

529523
rc = ngx_write_fd(fd, b.start, (size_t) (b.last - b.start));
530524
if (rc == NGX_ERROR) {
@@ -565,7 +559,9 @@ ngx_rtmp_dash_close_fragment(ngx_rtmp_session_t *s, ngx_rtmp_dash_track_t *t)
565559
b.end = buffer + sizeof(buffer);
566560
b.pos = b.last = b.start;
567561

568-
ngx_rtmp_mp4_write_ftyp(&b, NGX_RTMP_MP4_FILETYPE_SEG, NULL);
562+
ngx_rtmp_mp4_write_ftyp(&b, NGX_RTMP_MP4_FILETYPE_SEG, t->type == 'v' ?
563+
NGX_RTMP_MP4_VIDEO_TRACK :
564+
NGX_RTMP_MP4_AUDIO_TRACK);
569565

570566
pos = b.last;
571567
b.last += 44; /* leave room for sidx */
@@ -1046,10 +1042,11 @@ static ngx_int_t
10461042
ngx_rtmp_dash_append(ngx_rtmp_session_t *s, ngx_chain_t *in,
10471043
ngx_rtmp_dash_track_t *t, ngx_int_t key, uint32_t timestamp, uint32_t delay)
10481044
{
1049-
u_char *p;
1050-
size_t size, bsize;
1045+
u_char *p;
1046+
size_t size, bsize;
1047+
ngx_rtmp_mp4_sample_t *smpl;
10511048

1052-
static u_char buffer[NGX_RTMP_DASH_BUFSIZE];
1049+
static u_char buffer[NGX_RTMP_DASH_BUFSIZE];
10531050

10541051
p = buffer;
10551052
size = 0;
@@ -1081,15 +1078,17 @@ ngx_rtmp_dash_append(ngx_rtmp_session_t *s, ngx_chain_t *in,
10811078
return NGX_ERROR;
10821079
}
10831080

1084-
t->samples[t->sample_count].delay = delay;
1085-
t->samples[t->sample_count].size = (uint32_t) size;
1086-
t->samples[t->sample_count].duration = 0;
1087-
t->samples[t->sample_count].timestamp = timestamp;
1088-
t->samples[t->sample_count].key = (key ? 1 : 0);
1081+
smpl = &t->samples[t->sample_count];
1082+
1083+
smpl->delay = delay;
1084+
smpl->size = (uint32_t) size;
1085+
smpl->duration = 0;
1086+
smpl->timestamp = timestamp;
1087+
smpl->key = (key ? 1 : 0);
10891088

10901089
if (t->sample_count > 0) {
1091-
t->samples[t->sample_count - 1].duration = timestamp -
1092-
t->samples[t->sample_count - 1].timestamp;
1090+
smpl = &t->samples[t->sample_count - 1];
1091+
smpl->duration = timestamp - smpl->timestamp;
10931092
}
10941093

10951094
t->sample_count++;

0 commit comments

Comments
 (0)