From 9e634ae882f6a6a91a2404a97cc8146666ddaa4d Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Sun, 1 Dec 2013 10:28:21 +0400 Subject: [PATCH] improved mp4 brands --- dash/ngx_rtmp_dash_module.c | 10 +++----- dash/ngx_rtmp_mp4.c | 48 +++++++++++++++++++++---------------- dash/ngx_rtmp_mp4.h | 4 ++-- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/dash/ngx_rtmp_dash_module.c b/dash/ngx_rtmp_dash_module.c index 1e2dae5..c99f310 100644 --- a/dash/ngx_rtmp_dash_module.c +++ b/dash/ngx_rtmp_dash_module.c @@ -489,8 +489,7 @@ ngx_rtmp_dash_write_init_segments(ngx_rtmp_session_t *s) b.end = b.start + sizeof(buffer); b.pos = b.last = b.start; - ngx_rtmp_mp4_write_ftyp(&b, NGX_RTMP_MP4_FILETYPE_INIT, - NGX_RTMP_MP4_VIDEO_TRACK); + ngx_rtmp_mp4_write_ftyp(&b); ngx_rtmp_mp4_write_moov(s, &b, NGX_RTMP_MP4_VIDEO_TRACK); rc = ngx_write_fd(fd, b.start, (size_t) (b.last - b.start)); @@ -516,8 +515,7 @@ ngx_rtmp_dash_write_init_segments(ngx_rtmp_session_t *s) b.pos = b.last = b.start; - ngx_rtmp_mp4_write_ftyp(&b, NGX_RTMP_MP4_FILETYPE_INIT, - NGX_RTMP_MP4_AUDIO_TRACK); + ngx_rtmp_mp4_write_ftyp(&b); ngx_rtmp_mp4_write_moov(s, &b, NGX_RTMP_MP4_AUDIO_TRACK); rc = ngx_write_fd(fd, b.start, (size_t) (b.last - b.start)); @@ -559,9 +557,7 @@ ngx_rtmp_dash_close_fragment(ngx_rtmp_session_t *s, ngx_rtmp_dash_track_t *t) b.end = buffer + sizeof(buffer); b.pos = b.last = b.start; - ngx_rtmp_mp4_write_ftyp(&b, NGX_RTMP_MP4_FILETYPE_SEG, t->type == 'v' ? - NGX_RTMP_MP4_VIDEO_TRACK : - NGX_RTMP_MP4_AUDIO_TRACK); + ngx_rtmp_mp4_write_styp(&b); pos = b.last; b.last += 44; /* leave room for sidx */ diff --git a/dash/ngx_rtmp_mp4.c b/dash/ngx_rtmp_mp4.c index f884d4d..c02fd45 100644 --- a/dash/ngx_rtmp_mp4.c +++ b/dash/ngx_rtmp_mp4.c @@ -183,40 +183,46 @@ ngx_rtmp_mp4_write_matrix(ngx_buf_t *buf, uint32_t a, uint32_t b, uint32_t c, ngx_int_t -ngx_rtmp_mp4_write_ftyp(ngx_buf_t *b, ngx_rtmp_mp4_file_type_t ftype, - ngx_rtmp_mp4_track_type_t ttype) +ngx_rtmp_mp4_write_ftyp(ngx_buf_t *b) { u_char *pos; - switch (ftype) { + pos = ngx_rtmp_mp4_start_box(b, "ftyp"); - case NGX_RTMP_MP4_FILETYPE_INIT: + /* major brand */ + ngx_rtmp_mp4_box(b, "iso6"); - pos = ngx_rtmp_mp4_start_box(b, "ftyp"); + /* minor version */ + ngx_rtmp_mp4_field_32(b, 1); - ngx_rtmp_mp4_box(b, "iso5"); - ngx_rtmp_mp4_field_32(b, 1); + /* compatible brands */ + ngx_rtmp_mp4_box(b, "isom"); + ngx_rtmp_mp4_box(b, "iso6"); + ngx_rtmp_mp4_box(b, "dash"); - if (ttype == NGX_RTMP_MP4_VIDEO_TRACK) { - ngx_rtmp_mp4_box(b, "avc1"); - } + ngx_rtmp_mp4_update_box_size(b, pos); - ngx_rtmp_mp4_box(b, "iso5"); - ngx_rtmp_mp4_box(b, "dash"); + return NGX_OK; +} - break; - default: /* NGX_RTMP_MP4_FILETYPE_SEG */ +ngx_int_t +ngx_rtmp_mp4_write_styp(ngx_buf_t *b) +{ + u_char *pos; - pos = ngx_rtmp_mp4_start_box(b, "styp"); + pos = ngx_rtmp_mp4_start_box(b, "styp"); - ngx_rtmp_mp4_box(b, "msdh"); - ngx_rtmp_mp4_field_32(b, 0); - ngx_rtmp_mp4_box(b, "msdh"); - ngx_rtmp_mp4_box(b, "msix"); + /* major brand */ + ngx_rtmp_mp4_box(b, "iso6"); - break; - } + /* minor version */ + ngx_rtmp_mp4_field_32(b, 1); + + /* compatible brands */ + ngx_rtmp_mp4_box(b, "isom"); + ngx_rtmp_mp4_box(b, "iso6"); + ngx_rtmp_mp4_box(b, "dash"); ngx_rtmp_mp4_update_box_size(b, pos); diff --git a/dash/ngx_rtmp_mp4.h b/dash/ngx_rtmp_mp4.h index 7f67262..697b6c8 100644 --- a/dash/ngx_rtmp_mp4.h +++ b/dash/ngx_rtmp_mp4.h @@ -36,8 +36,8 @@ typedef enum { } ngx_rtmp_mp4_track_type_t; -ngx_int_t ngx_rtmp_mp4_write_ftyp(ngx_buf_t *b, ngx_rtmp_mp4_file_type_t ftype, - ngx_rtmp_mp4_track_type_t ttype); +ngx_int_t ngx_rtmp_mp4_write_ftyp(ngx_buf_t *b); +ngx_int_t ngx_rtmp_mp4_write_styp(ngx_buf_t *b); ngx_int_t ngx_rtmp_mp4_write_moov(ngx_rtmp_session_t *s, ngx_buf_t *b, ngx_rtmp_mp4_track_type_t ttype); ngx_int_t ngx_rtmp_mp4_write_moof(ngx_buf_t *b, uint32_t earliest_pres_time,