annotate src/http/modules/ngx_http_mp4_module.c @ 5359:2fda9065d0f4

Win32: Borland C compatibility fixes. Several false positive warnings silenced, notably W8012 "Comparing signed and unsigned" (due to u_short values promoted to int), and W8072 "Suspicious pointer arithmetic" (due to large type values added to pointers). With this patch, it's now again possible to compile nginx using bcc32, with options we normally compile on win32 minus ipv6 and ssl.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 04 Sep 2013 20:48:23 +0400
parents 670ceaba03d8
children 9d056f10fb99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4402
diff changeset
4 * Copyright (C) Nginx, Inc.
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
12 #define NGX_HTTP_MP4_TRAK_ATOM 0
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
13 #define NGX_HTTP_MP4_TKHD_ATOM 1
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
14 #define NGX_HTTP_MP4_MDIA_ATOM 2
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
15 #define NGX_HTTP_MP4_MDHD_ATOM 3
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
16 #define NGX_HTTP_MP4_HDLR_ATOM 4
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
17 #define NGX_HTTP_MP4_MINF_ATOM 5
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
18 #define NGX_HTTP_MP4_VMHD_ATOM 6
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
19 #define NGX_HTTP_MP4_SMHD_ATOM 7
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
20 #define NGX_HTTP_MP4_DINF_ATOM 8
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
21 #define NGX_HTTP_MP4_STBL_ATOM 9
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
22 #define NGX_HTTP_MP4_STSD_ATOM 10
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
23 #define NGX_HTTP_MP4_STTS_ATOM 11
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
24 #define NGX_HTTP_MP4_STTS_DATA 12
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
25 #define NGX_HTTP_MP4_STSS_ATOM 13
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
26 #define NGX_HTTP_MP4_STSS_DATA 14
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
27 #define NGX_HTTP_MP4_CTTS_ATOM 15
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
28 #define NGX_HTTP_MP4_CTTS_DATA 16
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
29 #define NGX_HTTP_MP4_STSC_ATOM 17
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
30 #define NGX_HTTP_MP4_STSC_CHUNK 18
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
31 #define NGX_HTTP_MP4_STSC_DATA 19
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
32 #define NGX_HTTP_MP4_STSZ_ATOM 20
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
33 #define NGX_HTTP_MP4_STSZ_DATA 21
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
34 #define NGX_HTTP_MP4_STCO_ATOM 22
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
35 #define NGX_HTTP_MP4_STCO_DATA 23
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
36 #define NGX_HTTP_MP4_CO64_ATOM 24
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
37 #define NGX_HTTP_MP4_CO64_DATA 25
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
38
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
39 #define NGX_HTTP_MP4_LAST_ATOM NGX_HTTP_MP4_CO64_DATA
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 size_t buffer_size;
4089
e27670e1ab70 mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
Igor Sysoev <igor@sysoev.ru>
parents: 4088
diff changeset
44 size_t max_buffer_size;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 } ngx_http_mp4_conf_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 typedef struct {
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
49 u_char chunk[4];
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
50 u_char samples[4];
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
51 u_char id[4];
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
52 } ngx_mp4_stsc_entry_t;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
53
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
54
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
55 typedef struct {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 uint32_t timescale;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 uint32_t time_to_sample_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 uint32_t sample_to_chunk_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 uint32_t sync_samples_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 uint32_t composition_offset_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 uint32_t sample_sizes_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 uint32_t chunks;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 ngx_uint_t start_sample;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 ngx_uint_t start_chunk;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
66 ngx_uint_t chunk_samples;
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
67 uint64_t chunk_samples_size;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 off_t start_offset;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 size_t tkhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 size_t mdhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72 size_t hdlr_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 size_t vmhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 size_t smhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 size_t dinf_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 size_t size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 ngx_chain_t out[NGX_HTTP_MP4_LAST_ATOM + 1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 ngx_buf_t trak_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 ngx_buf_t tkhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 ngx_buf_t mdia_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 ngx_buf_t mdhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 ngx_buf_t hdlr_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 ngx_buf_t minf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 ngx_buf_t vmhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 ngx_buf_t smhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 ngx_buf_t dinf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 ngx_buf_t stbl_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 ngx_buf_t stsd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 ngx_buf_t stts_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 ngx_buf_t stts_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 ngx_buf_t stss_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 ngx_buf_t stss_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 ngx_buf_t ctts_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 ngx_buf_t ctts_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 ngx_buf_t stsc_atom_buf;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
98 ngx_buf_t stsc_chunk_buf;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 ngx_buf_t stsc_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100 ngx_buf_t stsz_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 ngx_buf_t stsz_data_buf;
4107
7705911c9d10 Fix of struct field name.
Igor Sysoev <igor@sysoev.ru>
parents: 4106
diff changeset
102 ngx_buf_t stco_atom_buf;
7705911c9d10 Fix of struct field name.
Igor Sysoev <igor@sysoev.ru>
parents: 4106
diff changeset
103 ngx_buf_t stco_data_buf;
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
104 ngx_buf_t co64_atom_buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
105 ngx_buf_t co64_data_buf;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
106
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
107 ngx_mp4_stsc_entry_t stsc_chunk_entry;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 } ngx_http_mp4_trak_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 ngx_file_t file;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114 u_char *buffer;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 u_char *buffer_start;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 u_char *buffer_pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117 u_char *buffer_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 size_t buffer_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 off_t offset;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 off_t end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 off_t content_length;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 ngx_uint_t start;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124 uint32_t timescale;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 ngx_http_request_t *request;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 ngx_array_t trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 ngx_http_mp4_trak_t traks[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 size_t ftyp_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 size_t moov_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 ngx_chain_t *out;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 ngx_chain_t ftyp_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 ngx_chain_t moov_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 ngx_chain_t mvhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136 ngx_chain_t mdat_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 ngx_chain_t mdat_data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 ngx_buf_t ftyp_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 ngx_buf_t moov_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141 ngx_buf_t mvhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 ngx_buf_t mdat_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 ngx_buf_t mdat_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 u_char moov_atom_header[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 u_char mdat_atom_header[16];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147 } ngx_http_mp4_file_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 char *name;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 ngx_int_t (*handler)(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 } ngx_http_mp4_atom_handler_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157 #define ngx_mp4_atom_header(mp4) (mp4->buffer_pos - 8)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 #define ngx_mp4_atom_data(mp4) mp4->buffer_pos
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
159 #define ngx_mp4_atom_data_size(t) (uint64_t) (sizeof(t) - 8)
5359
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
160
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
161
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
162 #define ngx_mp4_atom_next(mp4, n) \
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
163 mp4->buffer_pos += (size_t) n; \
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
164 mp4->offset += n
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167 #define ngx_mp4_set_atom_name(p, n1, n2, n3, n4) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168 ((u_char *) (p))[4] = n1; \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169 ((u_char *) (p))[5] = n2; \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 ((u_char *) (p))[6] = n3; \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171 ((u_char *) (p))[7] = n4
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 #define ngx_mp4_get_32value(p) \
4402
b20019ecfdcc Fixed handling of mp4 above 2G and 32bit offsets (ticket #84).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4382
diff changeset
174 ( ((uint32_t) ((u_char *) (p))[0] << 24) \
b20019ecfdcc Fixed handling of mp4 above 2G and 32bit offsets (ticket #84).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4382
diff changeset
175 + ( ((u_char *) (p))[1] << 16) \
b20019ecfdcc Fixed handling of mp4 above 2G and 32bit offsets (ticket #84).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4382
diff changeset
176 + ( ((u_char *) (p))[2] << 8) \
b20019ecfdcc Fixed handling of mp4 above 2G and 32bit offsets (ticket #84).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4382
diff changeset
177 + ( ((u_char *) (p))[3]) )
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 #define ngx_mp4_set_32value(p, n) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 ((u_char *) (p))[0] = (u_char) ((n) >> 24); \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 ((u_char *) (p))[1] = (u_char) ((n) >> 16); \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 ((u_char *) (p))[2] = (u_char) ((n) >> 8); \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 ((u_char *) (p))[3] = (u_char) (n)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 #define ngx_mp4_get_64value(p) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 ( ((uint64_t) ((u_char *) (p))[0] << 56) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187 + ((uint64_t) ((u_char *) (p))[1] << 48) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 + ((uint64_t) ((u_char *) (p))[2] << 40) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 + ((uint64_t) ((u_char *) (p))[3] << 32) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190 + ((uint64_t) ((u_char *) (p))[4] << 24) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191 + ( ((u_char *) (p))[5] << 16) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 + ( ((u_char *) (p))[6] << 8) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 + ( ((u_char *) (p))[7]) )
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195 #define ngx_mp4_set_64value(p, n) \
4155
d9636bf3f159 Fix of building on platforms with 32-bit off_t. (closed #23)
Igor Sysoev <igor@sysoev.ru>
parents: 4112
diff changeset
196 ((u_char *) (p))[0] = (u_char) ((uint64_t) (n) >> 56); \
d9636bf3f159 Fix of building on platforms with 32-bit off_t. (closed #23)
Igor Sysoev <igor@sysoev.ru>
parents: 4112
diff changeset
197 ((u_char *) (p))[1] = (u_char) ((uint64_t) (n) >> 48); \
d9636bf3f159 Fix of building on platforms with 32-bit off_t. (closed #23)
Igor Sysoev <igor@sysoev.ru>
parents: 4112
diff changeset
198 ((u_char *) (p))[2] = (u_char) ((uint64_t) (n) >> 40); \
d9636bf3f159 Fix of building on platforms with 32-bit off_t. (closed #23)
Igor Sysoev <igor@sysoev.ru>
parents: 4112
diff changeset
199 ((u_char *) (p))[3] = (u_char) ((uint64_t) (n) >> 32); \
d9636bf3f159 Fix of building on platforms with 32-bit off_t. (closed #23)
Igor Sysoev <igor@sysoev.ru>
parents: 4112
diff changeset
200 ((u_char *) (p))[4] = (u_char) ( (n) >> 24); \
d9636bf3f159 Fix of building on platforms with 32-bit off_t. (closed #23)
Igor Sysoev <igor@sysoev.ru>
parents: 4112
diff changeset
201 ((u_char *) (p))[5] = (u_char) ( (n) >> 16); \
d9636bf3f159 Fix of building on platforms with 32-bit off_t. (closed #23)
Igor Sysoev <igor@sysoev.ru>
parents: 4112
diff changeset
202 ((u_char *) (p))[6] = (u_char) ( (n) >> 8); \
d9636bf3f159 Fix of building on platforms with 32-bit off_t. (closed #23)
Igor Sysoev <igor@sysoev.ru>
parents: 4112
diff changeset
203 ((u_char *) (p))[7] = (u_char) (n)
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 #define ngx_mp4_last_trak(mp4) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 &((ngx_http_mp4_trak_t *) mp4->trak.elts)[mp4->trak.nelts - 1]
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
209 static ngx_int_t ngx_http_mp4_handler(ngx_http_request_t *r);
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
210
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 static ngx_int_t ngx_http_mp4_process(ngx_http_mp4_file_t *mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212 static ngx_int_t ngx_http_mp4_read_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 ngx_http_mp4_atom_handler_t *atom, uint64_t atom_data_size);
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
214 static ngx_int_t ngx_http_mp4_read(ngx_http_mp4_file_t *mp4, size_t size);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215 static ngx_int_t ngx_http_mp4_read_ftyp_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 static ngx_int_t ngx_http_mp4_read_moov_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219 static ngx_int_t ngx_http_mp4_read_mdat_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 static size_t ngx_http_mp4_update_mdat_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 off_t start_offset);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223 static ngx_int_t ngx_http_mp4_read_mvhd_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225 static ngx_int_t ngx_http_mp4_read_trak_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 static void ngx_http_mp4_update_trak_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229 static ngx_int_t ngx_http_mp4_read_cmov_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231 static ngx_int_t ngx_http_mp4_read_tkhd_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 static ngx_int_t ngx_http_mp4_read_mdia_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 static void ngx_http_mp4_update_mdia_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 static ngx_int_t ngx_http_mp4_read_mdhd_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 static ngx_int_t ngx_http_mp4_read_hdlr_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241 static ngx_int_t ngx_http_mp4_read_minf_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243 static void ngx_http_mp4_update_minf_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
245 static ngx_int_t ngx_http_mp4_read_dinf_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
247 static ngx_int_t ngx_http_mp4_read_vmhd_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249 static ngx_int_t ngx_http_mp4_read_smhd_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
250 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
251 static ngx_int_t ngx_http_mp4_read_stbl_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
252 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253 static void ngx_http_mp4_update_stbl_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
255 static ngx_int_t ngx_http_mp4_read_stsd_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
257 static ngx_int_t ngx_http_mp4_read_stts_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
259 static ngx_int_t ngx_http_mp4_update_stts_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
261 static ngx_int_t ngx_http_mp4_read_stss_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
263 static ngx_int_t ngx_http_mp4_update_stss_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
264 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
265 static ngx_int_t ngx_http_mp4_read_ctts_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
266 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
267 static void ngx_http_mp4_update_ctts_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
268 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
269 static ngx_int_t ngx_http_mp4_read_stsc_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
270 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
271 static ngx_int_t ngx_http_mp4_update_stsc_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
273 static ngx_int_t ngx_http_mp4_read_stsz_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274 uint64_t atom_data_size);
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
275 static ngx_int_t ngx_http_mp4_update_stsz_atom(ngx_http_mp4_file_t *mp4,
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
277 static ngx_int_t ngx_http_mp4_read_stco_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
278 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
279 static ngx_int_t ngx_http_mp4_update_stco_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
280 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
281 static void ngx_http_mp4_adjust_stco_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
282 ngx_http_mp4_trak_t *trak, int32_t adjustment);
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
283 static ngx_int_t ngx_http_mp4_read_co64_atom(ngx_http_mp4_file_t *mp4,
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
284 uint64_t atom_data_size);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
285 static ngx_int_t ngx_http_mp4_update_co64_atom(ngx_http_mp4_file_t *mp4,
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
286 ngx_http_mp4_trak_t *trak);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
287 static void ngx_http_mp4_adjust_co64_atom(ngx_http_mp4_file_t *mp4,
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
288 ngx_http_mp4_trak_t *trak, off_t adjustment);
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
289
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
290 static char *ngx_http_mp4(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
291 static void *ngx_http_mp4_create_conf(ngx_conf_t *cf);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
292 static char *ngx_http_mp4_merge_conf(ngx_conf_t *cf, void *parent, void *child);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
293
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
294
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
295 static ngx_command_t ngx_http_mp4_commands[] = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
296
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
297 { ngx_string("mp4"),
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
298 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
299 ngx_http_mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
300 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
301 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
302 NULL },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
303
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
304 { ngx_string("mp4_buffer_size"),
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
305 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
306 ngx_conf_set_size_slot,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
307 NGX_HTTP_LOC_CONF_OFFSET,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
308 offsetof(ngx_http_mp4_conf_t, buffer_size),
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
309 NULL },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
310
4089
e27670e1ab70 mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
Igor Sysoev <igor@sysoev.ru>
parents: 4088
diff changeset
311 { ngx_string("mp4_max_buffer_size"),
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
312 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
313 ngx_conf_set_size_slot,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
314 NGX_HTTP_LOC_CONF_OFFSET,
4089
e27670e1ab70 mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
Igor Sysoev <igor@sysoev.ru>
parents: 4088
diff changeset
315 offsetof(ngx_http_mp4_conf_t, max_buffer_size),
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
316 NULL },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
317
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
318 ngx_null_command
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
319 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
320
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
321
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
322 static ngx_http_module_t ngx_http_mp4_module_ctx = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
323 NULL, /* preconfiguration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324 NULL, /* postconfiguration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326 NULL, /* create main configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
327 NULL, /* init main configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
328
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
329 NULL, /* create server configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330 NULL, /* merge server configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
331
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
332 ngx_http_mp4_create_conf, /* create location configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
333 ngx_http_mp4_merge_conf /* merge location configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
334 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
335
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
336
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
337 ngx_module_t ngx_http_mp4_module = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
338 NGX_MODULE_V1,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
339 &ngx_http_mp4_module_ctx, /* module context */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
340 ngx_http_mp4_commands, /* module directives */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
341 NGX_HTTP_MODULE, /* module type */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
342 NULL, /* init master */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
343 NULL, /* init module */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
344 NULL, /* init process */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
345 NULL, /* init thread */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
346 NULL, /* exit thread */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
347 NULL, /* exit process */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
348 NULL, /* exit master */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
349 NGX_MODULE_V1_PADDING
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
353 static ngx_http_mp4_atom_handler_t ngx_http_mp4_atoms[] = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
354 { "ftyp", ngx_http_mp4_read_ftyp_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
355 { "moov", ngx_http_mp4_read_moov_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 { "mdat", ngx_http_mp4_read_mdat_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
358 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
359
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
360 static ngx_http_mp4_atom_handler_t ngx_http_mp4_moov_atoms[] = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
361 { "mvhd", ngx_http_mp4_read_mvhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
362 { "trak", ngx_http_mp4_read_trak_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
363 { "cmov", ngx_http_mp4_read_cmov_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
364 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
365 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
366
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367 static ngx_http_mp4_atom_handler_t ngx_http_mp4_trak_atoms[] = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
368 { "tkhd", ngx_http_mp4_read_tkhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
369 { "mdia", ngx_http_mp4_read_mdia_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
370 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
371 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
372
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
373 static ngx_http_mp4_atom_handler_t ngx_http_mp4_mdia_atoms[] = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
374 { "mdhd", ngx_http_mp4_read_mdhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
375 { "hdlr", ngx_http_mp4_read_hdlr_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
376 { "minf", ngx_http_mp4_read_minf_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
377 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
378 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
379
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
380 static ngx_http_mp4_atom_handler_t ngx_http_mp4_minf_atoms[] = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
381 { "vmhd", ngx_http_mp4_read_vmhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
382 { "smhd", ngx_http_mp4_read_smhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383 { "dinf", ngx_http_mp4_read_dinf_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
384 { "stbl", ngx_http_mp4_read_stbl_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
385 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
386 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
387
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
388 static ngx_http_mp4_atom_handler_t ngx_http_mp4_stbl_atoms[] = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
389 { "stsd", ngx_http_mp4_read_stsd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
390 { "stts", ngx_http_mp4_read_stts_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
391 { "stss", ngx_http_mp4_read_stss_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
392 { "ctts", ngx_http_mp4_read_ctts_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
393 { "stsc", ngx_http_mp4_read_stsc_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
394 { "stsz", ngx_http_mp4_read_stsz_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
395 { "stco", ngx_http_mp4_read_stco_atom },
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
396 { "co64", ngx_http_mp4_read_co64_atom },
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
397 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
398 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
399
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
400
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
401 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
402 ngx_http_mp4_handler(ngx_http_request_t *r)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
403 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
404 u_char *last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
405 size_t root;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
406 ngx_int_t rc, start;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
407 ngx_uint_t level;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
408 ngx_str_t path, value;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
409 ngx_log_t *log;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
410 ngx_buf_t *b;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
411 ngx_chain_t out;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
412 ngx_http_mp4_file_t *mp4;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
413 ngx_open_file_info_t of;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
414 ngx_http_core_loc_conf_t *clcf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
415
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
416 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
417 return NGX_HTTP_NOT_ALLOWED;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
418 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
419
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
420 if (r->uri.data[r->uri.len - 1] == '/') {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
421 return NGX_DECLINED;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
422 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
423
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
424 rc = ngx_http_discard_request_body(r);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
425
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
426 if (rc != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
427 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
428 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
429
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
430 last = ngx_http_map_uri_to_path(r, &path, &root, 0);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
431 if (last == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
432 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
433 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
434
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
435 log = r->connection->log;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
437 path.len = last - path.data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
438
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
439 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
440 "http mp4 filename: \"%V\"", &path);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
441
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
442 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
443
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
444 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
445
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
446 of.read_ahead = clcf->read_ahead;
4087
3aa3b7bb9f0d Bugfix of r4086: directio was always enabled if mp4 file was sent as is.
Igor Sysoev <igor@sysoev.ru>
parents: 4085
diff changeset
447 of.directio = NGX_MAX_OFF_T_VALUE;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
448 of.valid = clcf->open_file_cache_valid;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
449 of.min_uses = clcf->open_file_cache_min_uses;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
450 of.errors = clcf->open_file_cache_errors;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
451 of.events = clcf->open_file_cache_events;
4494
13e09cf11d4e Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents: 4478
diff changeset
452
13e09cf11d4e Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents: 4478
diff changeset
453 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) {
13e09cf11d4e Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents: 4478
diff changeset
454 return NGX_HTTP_INTERNAL_SERVER_ERROR;
13e09cf11d4e Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents: 4478
diff changeset
455 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
456
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
457 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
458 != NGX_OK)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
459 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
460 switch (of.err) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
461
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
462 case 0:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
463 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
464
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
465 case NGX_ENOENT:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
466 case NGX_ENOTDIR:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
467 case NGX_ENAMETOOLONG:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
468
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
469 level = NGX_LOG_ERR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
470 rc = NGX_HTTP_NOT_FOUND;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
471 break;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
472
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
473 case NGX_EACCES:
4478
08713bac87fc Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents: 4412
diff changeset
474 #if (NGX_HAVE_OPENAT)
08713bac87fc Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents: 4412
diff changeset
475 case NGX_EMLINK:
08713bac87fc Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents: 4412
diff changeset
476 case NGX_ELOOP:
08713bac87fc Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents: 4412
diff changeset
477 #endif
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
478
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
479 level = NGX_LOG_ERR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
480 rc = NGX_HTTP_FORBIDDEN;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
481 break;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
482
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
483 default:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
484
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
485 level = NGX_LOG_CRIT;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
486 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
487 break;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
488 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
489
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
490 if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
491 ngx_log_error(level, log, of.err,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
492 "%s \"%s\" failed", of.failed, path.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
493 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
494
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
495 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
496 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
497
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
498 if (!of.is_file) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
499
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
500 if (ngx_close_file(of.fd) == NGX_FILE_ERROR) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
501 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
502 ngx_close_file_n " \"%s\" failed", path.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
503 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
504
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
505 return NGX_DECLINED;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
506 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
507
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
508 r->root_tested = !r->error_page;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
509 r->allow_ranges = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
510
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
511 start = -1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
512 r->headers_out.content_length_n = of.size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
513 mp4 = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
514 b = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
515
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
516 if (r->args.len) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
517
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
518 if (ngx_http_arg(r, (u_char *) "start", 5, &value) == NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
519
4156
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
520 /*
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
521 * A Flash player may send start value with a lot of digits
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
522 * after dot so strtod() is used instead of atofp(). NaNs and
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
523 * infinities become negative numbers after (int) conversion.
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
524 */
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
525
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
526 ngx_set_errno(0);
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
527 start = (int) (strtod((char *) value.data, NULL) * 1000);
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
528
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
529 if (ngx_errno != 0) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
530 start = -1;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
531 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
532 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
533 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
534
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
535 if (start >= 0) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
536 r->allow_ranges = 0;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
537
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
538 mp4 = ngx_pcalloc(r->pool, sizeof(ngx_http_mp4_file_t));
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
539 if (mp4 == NULL) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
540 return NGX_HTTP_INTERNAL_SERVER_ERROR;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
541 }
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
542
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
543 mp4->file.fd = of.fd;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
544 mp4->file.name = path;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
545 mp4->file.log = r->connection->log;;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
546 mp4->end = of.size;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
547 mp4->start = (ngx_uint_t) start;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
548 mp4->request = r;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
549
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
550 switch (ngx_http_mp4_process(mp4)) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
551
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
552 case NGX_DECLINED:
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
553 if (mp4->buffer) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
554 ngx_pfree(r->pool, mp4->buffer);
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
555 }
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
556
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
557 ngx_pfree(r->pool, mp4);
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
558 mp4 = NULL;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
559
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
560 break;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
561
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
562 case NGX_OK:
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
563 r->headers_out.content_length_n = mp4->content_length;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
564 break;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
565
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
566 default: /* NGX_ERROR */
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
567 if (mp4->buffer) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
568 ngx_pfree(r->pool, mp4->buffer);
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
569 }
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
570
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
571 ngx_pfree(r->pool, mp4);
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
572
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
573 return NGX_HTTP_INTERNAL_SERVER_ERROR;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
574 }
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
575 }
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
576
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
577 log->action = "sending mp4 to client";
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
578
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
579 if (clcf->directio <= of.size) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
580
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
581 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
582 * DIRECTIO is set on transfer only
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
583 * to allow kernel to cache "moov" atom
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
584 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
585
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
586 if (ngx_directio_on(of.fd) == NGX_FILE_ERROR) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
587 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
588 ngx_directio_on_n " \"%s\" failed", path.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
589 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
590
4087
3aa3b7bb9f0d Bugfix of r4086: directio was always enabled if mp4 file was sent as is.
Igor Sysoev <igor@sysoev.ru>
parents: 4085
diff changeset
591 of.is_directio = 1;
3aa3b7bb9f0d Bugfix of r4086: directio was always enabled if mp4 file was sent as is.
Igor Sysoev <igor@sysoev.ru>
parents: 4085
diff changeset
592
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
593 if (mp4) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
594 mp4->file.directio = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
595 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
596 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
597
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
598 r->headers_out.status = NGX_HTTP_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
599 r->headers_out.last_modified_time = of.mtime;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
600
4748
192f54280a7a Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4705
diff changeset
601 if (ngx_http_set_etag(r) != NGX_OK) {
192f54280a7a Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4705
diff changeset
602 return NGX_HTTP_INTERNAL_SERVER_ERROR;
192f54280a7a Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4705
diff changeset
603 }
192f54280a7a Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4705
diff changeset
604
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
605 if (ngx_http_set_content_type(r) != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
606 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
607 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
608
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
609 if (mp4 == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
610 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
611 if (b == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
612 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
613 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
614
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
615 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
616 if (b->file == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
617 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
618 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
619 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
620
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
621 rc = ngx_http_send_header(r);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
622
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
623 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
624 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
625 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
626
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
627 if (mp4) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
628 return ngx_http_output_filter(r, mp4->out);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
629 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
630
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
631 b->file_pos = 0;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
632 b->file_last = of.size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
633
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
634 b->in_file = b->file_last ? 1 : 0;
4611
2b6cb7528409 Allows particular modules to handle subrequests properly.
Andrey Belov <defan@nginx.com>
parents: 4585
diff changeset
635 b->last_buf = (r == r->main) ? 1 : 0;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636 b->last_in_chain = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
637
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
638 b->file->fd = of.fd;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
639 b->file->name = path;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
640 b->file->log = log;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
641 b->file->directio = of.is_directio;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
642
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
643 out.buf = b;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644 out.next = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
645
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
646 return ngx_http_output_filter(r, &out);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
647 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
648
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
649
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
650 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
651 ngx_http_mp4_process(ngx_http_mp4_file_t *mp4)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
652 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
653 off_t start_offset, adjustment;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
654 ngx_int_t rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
655 ngx_uint_t i, j;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
656 ngx_chain_t **prev;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
657 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
658 ngx_http_mp4_conf_t *conf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
659
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
660 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661 "mp4 start:%ui", mp4->start);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
662
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
663 conf = ngx_http_get_module_loc_conf(mp4->request, ngx_http_mp4_module);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
664
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
665 mp4->buffer_size = conf->buffer_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
666
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
667 rc = ngx_http_mp4_read_atom(mp4, ngx_http_mp4_atoms, mp4->end);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
668 if (rc != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
669 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
670 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
671
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
672 if (mp4->trak.nelts == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
673 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
674 "no mp4 trak atoms were found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
675 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
676 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
677 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
678
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
679 if (mp4->mdat_atom.buf == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
680 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
681 "no mp4 mdat atom was found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
682 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
683 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
684 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
685
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
686 prev = &mp4->out;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
687
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
688 if (mp4->ftyp_atom.buf) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
689 *prev = &mp4->ftyp_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
690 prev = &mp4->ftyp_atom.next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
691 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
692
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
693 *prev = &mp4->moov_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
694 prev = &mp4->moov_atom.next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
695
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
696 if (mp4->mvhd_atom.buf) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
697 mp4->moov_size += mp4->mvhd_atom_buf.last - mp4->mvhd_atom_buf.pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
698 *prev = &mp4->mvhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
699 prev = &mp4->mvhd_atom.next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
700 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
701
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
702 start_offset = mp4->end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
703 trak = mp4->trak.elts;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
704
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
705 for (i = 0; i < mp4->trak.nelts; i++) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
706
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
707 if (ngx_http_mp4_update_stts_atom(mp4, &trak[i]) != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
708 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
709 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
710
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
711 if (ngx_http_mp4_update_stss_atom(mp4, &trak[i]) != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
712 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
713 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
714
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
715 ngx_http_mp4_update_ctts_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
716
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
717 if (ngx_http_mp4_update_stsc_atom(mp4, &trak[i]) != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
718 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
719 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
720
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
721 if (ngx_http_mp4_update_stsz_atom(mp4, &trak[i]) != NGX_OK) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
722 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
723 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
724
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
725 if (trak[i].out[NGX_HTTP_MP4_CO64_DATA].buf) {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
726 if (ngx_http_mp4_update_co64_atom(mp4, &trak[i]) != NGX_OK) {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
727 return NGX_ERROR;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
728 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
729
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
730 } else {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
731 if (ngx_http_mp4_update_stco_atom(mp4, &trak[i]) != NGX_OK) {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
732 return NGX_ERROR;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
733 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
734 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
735
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
736 ngx_http_mp4_update_stbl_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
737 ngx_http_mp4_update_minf_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
738 trak[i].size += trak[i].mdhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
739 trak[i].size += trak[i].hdlr_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
740 ngx_http_mp4_update_mdia_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
741 trak[i].size += trak[i].tkhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
742 ngx_http_mp4_update_trak_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
743
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
744 mp4->moov_size += trak[i].size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
745
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
746 if (start_offset > trak[i].start_offset) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
747 start_offset = trak[i].start_offset;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
748 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
749
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
750 *prev = &trak[i].out[NGX_HTTP_MP4_TRAK_ATOM];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
751 prev = &trak[i].out[NGX_HTTP_MP4_TRAK_ATOM].next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
752
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
753 for (j = 0; j < NGX_HTTP_MP4_LAST_ATOM + 1; j++) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
754 if (trak[i].out[j].buf) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
755 *prev = &trak[i].out[j];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
756 prev = &trak[i].out[j].next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
757 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
758 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
759 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
760
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
761 mp4->moov_size += 8;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
762
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
763 ngx_mp4_set_32value(mp4->moov_atom_header, mp4->moov_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
764 ngx_mp4_set_atom_name(mp4->moov_atom_header, 'm', 'o', 'o', 'v');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
765 mp4->content_length += mp4->moov_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
766
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
767 *prev = &mp4->mdat_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
768
5097
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
769 if (start_offset > mp4->mdat_data.buf->file_last) {
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
770 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
771 "start time is out mp4 mdat atom in \"%s\"",
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
772 mp4->file.name.data);
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
773 return NGX_ERROR;
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
774 }
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
775
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
776 adjustment = mp4->ftyp_size + mp4->moov_size
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
777 + ngx_http_mp4_update_mdat_atom(mp4, start_offset)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
778 - start_offset;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
779
4088
8fe1da7b8386 bugfix of r4086: nginx could not be built without debug log.
Igor Sysoev <igor@sysoev.ru>
parents: 4087
diff changeset
780 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4579
778ea2f7268c Fixed debug logging.
Igor Sysoev <igor@sysoev.ru>
parents: 4578
diff changeset
781 "mp4 adjustment:%O", adjustment);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
782
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
783 for (i = 0; i < mp4->trak.nelts; i++) {
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
784 if (trak[i].out[NGX_HTTP_MP4_CO64_DATA].buf) {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
785 ngx_http_mp4_adjust_co64_atom(mp4, &trak[i], adjustment);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
786 } else {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
787 ngx_http_mp4_adjust_stco_atom(mp4, &trak[i], (int32_t) adjustment);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
788 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
789 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
790
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
791 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
792 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
793
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
794
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
795 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
796 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
797 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
798 } ngx_mp4_atom_header_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
799
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
800 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
801 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
802 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
803 u_char size64[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
804 } ngx_mp4_atom_header64_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
805
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
806
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
807 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
808 ngx_http_mp4_read_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
809 ngx_http_mp4_atom_handler_t *atom, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
810 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
811 off_t end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
812 size_t atom_header_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
813 u_char *atom_header, *atom_name;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
814 uint64_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
815 ngx_int_t rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
816 ngx_uint_t n;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
817
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
818 end = mp4->offset + atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
819
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
820 while (mp4->offset < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
821
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
822 if (ngx_http_mp4_read(mp4, sizeof(uint32_t)) != NGX_OK) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
823 return NGX_ERROR;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
824 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
825
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
826 atom_header = mp4->buffer_pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
827 atom_size = ngx_mp4_get_32value(atom_header);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
828 atom_header_size = sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
829
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
830 if (atom_size == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
831 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
832 "mp4 atom end");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
833 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
834 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
835
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
836 if (atom_size < sizeof(ngx_mp4_atom_header_t)) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
837
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
838 if (atom_size == 1) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
839
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
840 if (ngx_http_mp4_read(mp4, sizeof(ngx_mp4_atom_header64_t))
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
841 != NGX_OK)
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
842 {
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
843 return NGX_ERROR;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
844 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
845
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
846 /* 64-bit atom size */
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
847 atom_header = mp4->buffer_pos;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
848 atom_size = ngx_mp4_get_64value(atom_header + 8);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
849 atom_header_size = sizeof(ngx_mp4_atom_header64_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
850
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
851 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
852 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
853 "\"%s\" mp4 atom is too small:%uL",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
854 mp4->file.name.data, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
855 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
856 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
857 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
858
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
859 if (ngx_http_mp4_read(mp4, sizeof(ngx_mp4_atom_header_t)) != NGX_OK) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
860 return NGX_ERROR;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
861 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
862
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
863 atom_header = mp4->buffer_pos;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
864 atom_name = atom_header + sizeof(uint32_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
865
4088
8fe1da7b8386 bugfix of r4086: nginx could not be built without debug log.
Igor Sysoev <igor@sysoev.ru>
parents: 4087
diff changeset
866 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
867 "mp4 atom: %*s @%O:%uL",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
868 4, atom_name, mp4->offset, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
869
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
870 if (atom_size > (uint64_t) (NGX_MAX_OFF_T_VALUE - mp4->offset)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
871 || mp4->offset + (off_t) atom_size > end)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
872 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
873 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
874 "\"%s\" mp4 atom too large:%uL",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
875 mp4->file.name.data, atom_size);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
876 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
877 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
878
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
879 for (n = 0; atom[n].name; n++) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
880
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
881 if (ngx_strncmp(atom_name, atom[n].name, 4) == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
882
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
883 ngx_mp4_atom_next(mp4, atom_header_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
884
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
885 rc = atom[n].handler(mp4, atom_size - atom_header_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
886 if (rc != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
887 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
888 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
889
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
890 goto next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
891 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
892 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
893
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
894 ngx_mp4_atom_next(mp4, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
895
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
896 next:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
897 continue;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
898 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
899
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
900 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
901 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
902
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
903
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
904 static ngx_int_t
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
905 ngx_http_mp4_read(ngx_http_mp4_file_t *mp4, size_t size)
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
906 {
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
907 ssize_t n;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
908
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
909 if (mp4->buffer_pos + size <= mp4->buffer_end) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
910 return NGX_OK;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
911 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
912
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
913 if (mp4->offset + (off_t) mp4->buffer_size > mp4->end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
914 mp4->buffer_size = (size_t) (mp4->end - mp4->offset);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
915 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
916
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
917 if (mp4->buffer_size < size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
918 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
919 "\"%s\" mp4 file truncated", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
920 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
921 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
922
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
923 if (mp4->buffer == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
924 mp4->buffer = ngx_palloc(mp4->request->pool, mp4->buffer_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
925 if (mp4->buffer == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
926 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
927 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
928
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
929 mp4->buffer_start = mp4->buffer;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
930 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
931
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
932 n = ngx_read_file(&mp4->file, mp4->buffer_start, mp4->buffer_size,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
933 mp4->offset);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
934
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
935 if (n == NGX_ERROR) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
936 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
937 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
938
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
939 if ((size_t) n != mp4->buffer_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
940 ngx_log_error(NGX_LOG_CRIT, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
941 ngx_read_file_n " read only %z of %z from \"%s\"",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
942 n, mp4->buffer_size, mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
943 return NGX_ERROR;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
944 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
945
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
946 mp4->buffer_pos = mp4->buffer_start;
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
947 mp4->buffer_end = mp4->buffer_start + mp4->buffer_size;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
948
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
949 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
950 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
951
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
952
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
953 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
954 ngx_http_mp4_read_ftyp_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
955 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
956 u_char *ftyp_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
957 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
958 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
959
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
960 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 ftyp atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
961
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
962 if (atom_data_size > 1024
5359
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
963 || ngx_mp4_atom_data(mp4) + (size_t) atom_data_size > mp4->buffer_end)
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
964 {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
965 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
966 "\"%s\" mp4 ftyp atom is too large:%uL",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
967 mp4->file.name.data, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
968 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
969 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
970
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
971 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
972
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
973 ftyp_atom = ngx_palloc(mp4->request->pool, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
974 if (ftyp_atom == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
975 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
976 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
977
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
978 ngx_mp4_set_32value(ftyp_atom, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
979 ngx_mp4_set_atom_name(ftyp_atom, 'f', 't', 'y', 'p');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
980
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
981 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
982 * only moov atom content is guaranteed to be in mp4->buffer
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
983 * during sending response, so ftyp atom content should be copied
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
984 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
985 ngx_memcpy(ftyp_atom + sizeof(ngx_mp4_atom_header_t),
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
986 ngx_mp4_atom_data(mp4), (size_t) atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
987
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
988 atom = &mp4->ftyp_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
989 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
990 atom->pos = ftyp_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
991 atom->last = ftyp_atom + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
992
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
993 mp4->ftyp_atom.buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
994 mp4->ftyp_size = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
995 mp4->content_length = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
996
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
997 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
998
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
999 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1000 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1001
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1002
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1003 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1004 * Small excess buffer to process atoms after moov atom, mp4->buffer_start
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1005 * will be set to this buffer part after moov atom processing.
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1006 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1007 #define NGX_HTTP_MP4_MOOV_BUFFER_EXCESS (4 * 1024)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1008
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1009 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1010 ngx_http_mp4_read_moov_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1011 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1012 ngx_int_t rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1013 ngx_uint_t no_mdat;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1014 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1015 ngx_http_mp4_conf_t *conf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1016
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1017 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 moov atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1018
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1019 no_mdat = (mp4->mdat_atom.buf == NULL);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1020
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1021 if (no_mdat && mp4->start == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1022 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1023 * send original file if moov atom resides before
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1024 * mdat atom and client requests integral file
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1025 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1026 return NGX_DECLINED;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1027 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1028
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1029 conf = ngx_http_get_module_loc_conf(mp4->request, ngx_http_mp4_module);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1030
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1031 if (atom_data_size > mp4->buffer_size) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1032
4089
e27670e1ab70 mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
Igor Sysoev <igor@sysoev.ru>
parents: 4088
diff changeset
1033 if (atom_data_size > conf->max_buffer_size) {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1034 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1035 "\"%s\" mp4 moov atom is too large:%uL, "
4089
e27670e1ab70 mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
Igor Sysoev <igor@sysoev.ru>
parents: 4088
diff changeset
1036 "you may want to increase mp4_max_buffer_size",
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1037 mp4->file.name.data, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1038 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1039 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1040
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1041 ngx_pfree(mp4->request->pool, mp4->buffer);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1042 mp4->buffer = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1043 mp4->buffer_pos = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1044 mp4->buffer_end = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1045
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1046 mp4->buffer_size = (size_t) atom_data_size
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1047 + NGX_HTTP_MP4_MOOV_BUFFER_EXCESS * no_mdat;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1048 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1049
4705
9a43b145a8ba Mp4: fixed build on win32 after r4689.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4688
diff changeset
1050 if (ngx_http_mp4_read(mp4, (size_t) atom_data_size) != NGX_OK) {
4688
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1051 return NGX_ERROR;
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1052 }
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1053
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1054 mp4->trak.elts = &mp4->traks;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1055 mp4->trak.size = sizeof(ngx_http_mp4_trak_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1056 mp4->trak.nalloc = 2;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1057 mp4->trak.pool = mp4->request->pool;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1058
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1059 atom = &mp4->moov_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1060 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1061 atom->pos = mp4->moov_atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1062 atom->last = mp4->moov_atom_header + 8;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1063
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1064 mp4->moov_atom.buf = &mp4->moov_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1065
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1066 rc = ngx_http_mp4_read_atom(mp4, ngx_http_mp4_moov_atoms, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1067
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1068 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 moov atom done");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1069
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1070 if (no_mdat) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1071 mp4->buffer_start = mp4->buffer_pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1072 mp4->buffer_size = NGX_HTTP_MP4_MOOV_BUFFER_EXCESS;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1073
4688
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1074 if (mp4->buffer_start + mp4->buffer_size > mp4->buffer_end) {
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1075 mp4->buffer = NULL;
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1076 mp4->buffer_pos = NULL;
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1077 mp4->buffer_end = NULL;
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1078 }
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1079
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1080 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1081 /* skip atoms after moov atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1082 mp4->offset = mp4->end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1083 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1084
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1085 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1086 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1087
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1088
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1089 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1090 ngx_http_mp4_read_mdat_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1091 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1092 ngx_buf_t *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1093
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1094 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 mdat atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1095
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1096 data = &mp4->mdat_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1097 data->file = &mp4->file;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1098 data->in_file = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1099 data->last_buf = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1100 data->last_in_chain = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1101 data->file_last = mp4->offset + atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1102
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1103 mp4->mdat_atom.buf = &mp4->mdat_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1104 mp4->mdat_atom.next = &mp4->mdat_data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1105 mp4->mdat_data.buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1106
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1107 if (mp4->trak.nelts) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1108 /* skip atoms after mdat atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1109 mp4->offset = mp4->end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1110
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1111 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1112 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1113 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1114
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1115 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1116 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1117
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1118
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1119 static size_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1120 ngx_http_mp4_update_mdat_atom(ngx_http_mp4_file_t *mp4, off_t start_offset)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1121 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1122 off_t atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1123 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1124 uint32_t atom_header_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1125 uint64_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1126 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1127
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1128 atom_data_size = mp4->mdat_data.buf->file_last - start_offset;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1129 mp4->mdat_data.buf->file_pos = start_offset;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1130
4088
8fe1da7b8386 bugfix of r4086: nginx could not be built without debug log.
Igor Sysoev <igor@sysoev.ru>
parents: 4087
diff changeset
1131 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1132 "mdat new offset @%O:%O", start_offset, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1133
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1134 atom_header = mp4->mdat_atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1135
5358
670ceaba03d8 Win32: Open Watcom C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5202
diff changeset
1136 if ((uint64_t) atom_data_size > (uint64_t) 0xffffffff) {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1137 atom_size = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1138 atom_header_size = sizeof(ngx_mp4_atom_header64_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1139 ngx_mp4_set_64value(atom_header + sizeof(ngx_mp4_atom_header_t),
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1140 sizeof(ngx_mp4_atom_header64_t) + atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1141 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1142 atom_size = sizeof(ngx_mp4_atom_header_t) + atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1143 atom_header_size = sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1144 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1145
4282
71cdac0b9ea6 Fix of "Content-Length" header of MP4 response if start argument was used.
Igor Sysoev <igor@sysoev.ru>
parents: 4189
diff changeset
1146 mp4->content_length += atom_header_size + atom_data_size;
71cdac0b9ea6 Fix of "Content-Length" header of MP4 response if start argument was used.
Igor Sysoev <igor@sysoev.ru>
parents: 4189
diff changeset
1147
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1148 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1149 ngx_mp4_set_atom_name(atom_header, 'm', 'd', 'a', 't');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1150
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1151 atom = &mp4->mdat_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1152 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1153 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1154 atom->last = atom_header + atom_header_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1155
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1156 return atom_header_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1157 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1158
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1159
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1160 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1161 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1162 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1163 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1164 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1165 u_char creation_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1166 u_char modification_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1167 u_char timescale[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1168 u_char duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1169 u_char rate[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1170 u_char volume[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1171 u_char reserved[10];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1172 u_char matrix[36];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1173 u_char preview_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1174 u_char preview_duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1175 u_char poster_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1176 u_char selection_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1177 u_char selection_duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1178 u_char current_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1179 u_char next_track_id[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1180 } ngx_mp4_mvhd_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1181
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1182 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1183 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1184 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1185 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1186 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1187 u_char creation_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1188 u_char modification_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1189 u_char timescale[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1190 u_char duration[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1191 u_char rate[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1192 u_char volume[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1193 u_char reserved[10];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1194 u_char matrix[36];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1195 u_char preview_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1196 u_char preview_duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1197 u_char poster_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1198 u_char selection_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1199 u_char selection_duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1200 u_char current_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1201 u_char next_track_id[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1202 } ngx_mp4_mvhd64_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1203
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1204
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1205 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1206 ngx_http_mp4_read_mvhd_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1207 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1208 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1209 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1210 uint32_t timescale;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1211 uint64_t duration;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1212 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1213 ngx_mp4_mvhd_atom_t *mvhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1214 ngx_mp4_mvhd64_atom_t *mvhd64_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1215
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1216 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 mvhd atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1217
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1218 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1219 mvhd_atom = (ngx_mp4_mvhd_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1220 mvhd64_atom = (ngx_mp4_mvhd64_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1221 ngx_mp4_set_atom_name(atom_header, 'm', 'v', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1222
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1223 if (ngx_mp4_atom_data_size(ngx_mp4_mvhd_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1224 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1225 "\"%s\" mp4 mvhd atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1226 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1227 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1228
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1229 if (mvhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1230 /* version 0: 32-bit duration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1231 timescale = ngx_mp4_get_32value(mvhd_atom->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1232 duration = ngx_mp4_get_32value(mvhd_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1233
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1234 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1235 /* version 1: 64-bit duration */
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1236
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1237 if (ngx_mp4_atom_data_size(ngx_mp4_mvhd64_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1238 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1239 "\"%s\" mp4 mvhd atom too small",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1240 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1241 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1242 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1243
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1244 timescale = ngx_mp4_get_32value(mvhd64_atom->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1245 duration = ngx_mp4_get_64value(mvhd64_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1246 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1247
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1248 mp4->timescale = timescale;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1249
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1250 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1251 "mvhd timescale:%uD, duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1252 timescale, duration, (double) duration / timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1253
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1254 duration -= (uint64_t) mp4->start * timescale / 1000;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1255
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1256 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1257 "mvhd new duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1258 duration, (double) duration / timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1259
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1260 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1261 ngx_mp4_set_32value(mvhd_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1262
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1263 if (mvhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1264 ngx_mp4_set_32value(mvhd_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1265
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1266 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1267 ngx_mp4_set_64value(mvhd64_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1268 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1269
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1270 atom = &mp4->mvhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1271 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1272 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1273 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1274
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1275 mp4->mvhd_atom.buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1276
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1277 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1278
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1279 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1280 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1281
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1282
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1283 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1284 ngx_http_mp4_read_trak_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1285 {
4099
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1286 u_char *atom_header, *atom_end;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1287 off_t atom_file_end;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1288 ngx_int_t rc;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1289 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1290 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1291
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1292 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 trak atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1293
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1294 trak = ngx_array_push(&mp4->trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1295 if (trak == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1296 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1297 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1298
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1299 ngx_memzero(trak, sizeof(ngx_http_mp4_trak_t));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1300
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1301 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1302 ngx_mp4_set_atom_name(atom_header, 't', 'r', 'a', 'k');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1303
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1304 atom = &trak->trak_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1305 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1306 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1307 atom->last = atom_header + sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1308
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1309 trak->out[NGX_HTTP_MP4_TRAK_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1310
5359
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
1311 atom_end = mp4->buffer_pos + (size_t) atom_data_size;
4099
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1312 atom_file_end = mp4->offset + atom_data_size;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1313
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1314 rc = ngx_http_mp4_read_atom(mp4, ngx_http_mp4_trak_atoms, atom_data_size);
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1315
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1316 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1317 "mp4 trak atom: %i", rc);
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1318
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1319 if (rc == NGX_DECLINED) {
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1320 /* skip this trak */
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1321 ngx_memzero(trak, sizeof(ngx_http_mp4_trak_t));
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1322 mp4->trak.nelts--;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1323 mp4->buffer_pos = atom_end;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1324 mp4->offset = atom_file_end;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1325 return NGX_OK;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1326 }
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1327
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1328 return rc;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1329 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1330
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1331
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1332 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1333 ngx_http_mp4_update_trak_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1334 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1335 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1336 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1337
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1338 trak->size += sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1339 atom = &trak->trak_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1340 ngx_mp4_set_32value(atom->pos, trak->size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1341 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1342
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1343
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1344 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1345 ngx_http_mp4_read_cmov_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1346 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1347 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1348 "\"%s\" mp4 compressed moov atom (cmov) is not supported",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1349 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1350
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1351 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1352 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1353
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1354
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1355 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1356 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1357 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1358 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1359 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1360 u_char creation_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1361 u_char modification_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1362 u_char track_id[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1363 u_char reserved1[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1364 u_char duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1365 u_char reserved2[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1366 u_char layer[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1367 u_char group[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1368 u_char volume[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1369 u_char reverved3[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1370 u_char matrix[36];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1371 u_char width[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1372 u_char heigth[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1373 } ngx_mp4_tkhd_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1374
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1375 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1376 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1377 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1378 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1379 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1380 u_char creation_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1381 u_char modification_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1382 u_char track_id[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1383 u_char reserved1[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1384 u_char duration[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1385 u_char reserved2[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1386 u_char layer[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1387 u_char group[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1388 u_char volume[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1389 u_char reverved3[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1390 u_char matrix[36];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1391 u_char width[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1392 u_char heigth[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1393 } ngx_mp4_tkhd64_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1394
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1395
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1396 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1397 ngx_http_mp4_read_tkhd_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1398 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1399 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1400 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1401 uint64_t duration;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1402 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1403 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1404 ngx_mp4_tkhd_atom_t *tkhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1405 ngx_mp4_tkhd64_atom_t *tkhd64_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1406
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1407 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 tkhd atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1408
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1409 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1410 tkhd_atom = (ngx_mp4_tkhd_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1411 tkhd64_atom = (ngx_mp4_tkhd64_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1412 ngx_mp4_set_atom_name(tkhd_atom, 't', 'k', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1413
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1414 if (ngx_mp4_atom_data_size(ngx_mp4_tkhd_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1415 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1416 "\"%s\" mp4 tkhd atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1417 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1418 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1419
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1420 if (tkhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1421 /* version 0: 32-bit duration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1422 duration = ngx_mp4_get_32value(tkhd_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1423
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1424 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1425 /* version 1: 64-bit duration */
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1426
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1427 if (ngx_mp4_atom_data_size(ngx_mp4_tkhd64_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1428 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1429 "\"%s\" mp4 tkhd atom too small",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1430 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1431 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1432 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1433
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1434 duration = ngx_mp4_get_64value(tkhd64_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1435 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1436
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1437 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1438 "tkhd duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1439 duration, (double) duration / mp4->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1440
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1441 duration -= (uint64_t) mp4->start * mp4->timescale / 1000;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1442
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1443 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1444 "tkhd new duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1445 duration, (double) duration / mp4->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1446
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1447 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1448
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1449 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1450 trak->tkhd_size = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1451
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1452 ngx_mp4_set_32value(tkhd_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1453
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1454 if (tkhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1455 ngx_mp4_set_32value(tkhd_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1456
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1457 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1458 ngx_mp4_set_64value(tkhd64_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1459 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1460
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1461 atom = &trak->tkhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1462 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1463 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1464 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1465
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1466 trak->out[NGX_HTTP_MP4_TKHD_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1467
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1468 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1469
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1470 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1471 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1472
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1473
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1474 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1475 ngx_http_mp4_read_mdia_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1476 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1477 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1478 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1479 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1480
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1481 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "process mdia atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1482
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1483 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1484 ngx_mp4_set_atom_name(atom_header, 'm', 'd', 'i', 'a');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1485
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1486 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1487
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1488 atom = &trak->mdia_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1489 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1490 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1491 atom->last = atom_header + sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1492
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1493 trak->out[NGX_HTTP_MP4_MDIA_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1494
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1495 return ngx_http_mp4_read_atom(mp4, ngx_http_mp4_mdia_atoms, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1496 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1497
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1498
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1499 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1500 ngx_http_mp4_update_mdia_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1501 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1502 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1503 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1504
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1505 trak->size += sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1506 atom = &trak->mdia_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1507 ngx_mp4_set_32value(atom->pos, trak->size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1508 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1509
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1510
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1511 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1512 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1513 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1514 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1515 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1516 u_char creation_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1517 u_char modification_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1518 u_char timescale[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1519 u_char duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1520 u_char language[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1521 u_char quality[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1522 } ngx_mp4_mdhd_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1523
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1524 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1525 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1526 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1527 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1528 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1529 u_char creation_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1530 u_char modification_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1531 u_char timescale[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1532 u_char duration[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1533 u_char language[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1534 u_char quality[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1535 } ngx_mp4_mdhd64_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1536
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1537
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1538 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1539 ngx_http_mp4_read_mdhd_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1540 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1541 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1542 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1543 uint32_t timescale;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1544 uint64_t duration;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1545 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1546 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1547 ngx_mp4_mdhd_atom_t *mdhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1548 ngx_mp4_mdhd64_atom_t *mdhd64_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1549
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1550 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 mdhd atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1551
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1552 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1553 mdhd_atom = (ngx_mp4_mdhd_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1554 mdhd64_atom = (ngx_mp4_mdhd64_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1555 ngx_mp4_set_atom_name(mdhd_atom, 'm', 'd', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1556
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1557 if (ngx_mp4_atom_data_size(ngx_mp4_mdhd_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1558 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1559 "\"%s\" mp4 mdhd atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1560 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1561 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1562
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1563 if (mdhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1564 /* version 0: everything is 32-bit */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1565 timescale = ngx_mp4_get_32value(mdhd_atom->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1566 duration = ngx_mp4_get_32value(mdhd_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1567
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1568 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1569 /* version 1: 64-bit duration and 32-bit timescale */
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1570
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1571 if (ngx_mp4_atom_data_size(ngx_mp4_mdhd64_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1572 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1573 "\"%s\" mp4 mdhd atom too small",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1574 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1575 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1576 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1577
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1578 timescale = ngx_mp4_get_32value(mdhd64_atom->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1579 duration = ngx_mp4_get_64value(mdhd64_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1580 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1581
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1582 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1583 "mdhd timescale:%uD, duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1584 timescale, duration, (double) duration / timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1585
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1586 duration -= (uint64_t) mp4->start * timescale / 1000;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1587
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1588 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1589 "mdhd new duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1590 duration, (double) duration / timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1591
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1592 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1593
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1594 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1595 trak->mdhd_size = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1596 trak->timescale = timescale;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1597
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1598 ngx_mp4_set_32value(mdhd_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1599
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1600 if (mdhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1601 ngx_mp4_set_32value(mdhd_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1602
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1603 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1604 ngx_mp4_set_64value(mdhd64_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1605 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1606
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1607 atom = &trak->mdhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1608 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1609 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1610 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1611
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1612 trak->out[NGX_HTTP_MP4_MDHD_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1613
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1614 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1615
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1616 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1617 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1618
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1619
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1620 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1621 ngx_http_mp4_read_hdlr_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1622 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1623 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1624 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1625 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1626 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1627
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1628 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 hdlr atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1629
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1630 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1631 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1632 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1633 ngx_mp4_set_atom_name(atom_header, 'h', 'd', 'l', 'r');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1634
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1635 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1636
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1637 atom = &trak->hdlr_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1638 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1639 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1640 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1641
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1642 trak->hdlr_size = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1643 trak->out[NGX_HTTP_MP4_HDLR_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1644
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1645 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1646
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1647 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1648 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1649
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1650
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1651 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1652 ngx_http_mp4_read_minf_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1653 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1654 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1655 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1656 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1657
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1658 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "process minf atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1659
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1660 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1661 ngx_mp4_set_atom_name(atom_header, 'm', 'i', 'n', 'f');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1662
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1663 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1664
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1665 atom = &trak->minf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1666 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1667 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1668 atom->last = atom_header + sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1669
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1670 trak->out[NGX_HTTP_MP4_MINF_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1671
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1672 return ngx_http_mp4_read_atom(mp4, ngx_http_mp4_minf_atoms, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1673 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1674
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1675
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1676 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1677 ngx_http_mp4_update_minf_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1678 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1679 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1680 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1681
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1682 trak->size += sizeof(ngx_mp4_atom_header_t)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1683 + trak->vmhd_size
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1684 + trak->smhd_size
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1685 + trak->dinf_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1686 atom = &trak->minf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1687 ngx_mp4_set_32value(atom->pos, trak->size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1688 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1689
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1690
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1691 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1692 ngx_http_mp4_read_vmhd_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1693 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1694 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1695 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1696 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1697 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1698
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1699 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 vmhd atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1700
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1701 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1702 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1703 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1704 ngx_mp4_set_atom_name(atom_header, 'v', 'm', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1705
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1706 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1707
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1708 atom = &trak->vmhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1709 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1710 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1711 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1712
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1713 trak->vmhd_size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1714 trak->out[NGX_HTTP_MP4_VMHD_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1715
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1716 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1717
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1718 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1719 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1720
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1721
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1722 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1723 ngx_http_mp4_read_smhd_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1724 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1725 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1726 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1727 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1728 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1729
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1730 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 smhd atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1731
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1732 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1733 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1734 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1735 ngx_mp4_set_atom_name(atom_header, 's', 'm', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1736
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1737 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1738
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1739 atom = &trak->smhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1740 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1741 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1742 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1743
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1744 trak->vmhd_size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1745 trak->out[NGX_HTTP_MP4_SMHD_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1746
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1747 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1748
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1749 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1750 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1751
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1752
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1753 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1754 ngx_http_mp4_read_dinf_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1755 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1756 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1757 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1758 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1759 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1760
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1761 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 dinf atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1762
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1763 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1764 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1765 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1766 ngx_mp4_set_atom_name(atom_header, 'd', 'i', 'n', 'f');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1767
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1768 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1769
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1770 atom = &trak->dinf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1771 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1772 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1773 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1774
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1775 trak->dinf_size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1776 trak->out[NGX_HTTP_MP4_DINF_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1777
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1778 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1779
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1780 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1781 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1782
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1783
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1784 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1785 ngx_http_mp4_read_stbl_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1786 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1787 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1788 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1789 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1790
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1791 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "process stbl atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1792
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1793 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1794 ngx_mp4_set_atom_name(atom_header, 's', 't', 'b', 'l');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1795
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1796 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1797
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1798 atom = &trak->stbl_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1799 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1800 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1801 atom->last = atom_header + sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1802
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1803 trak->out[NGX_HTTP_MP4_STBL_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1804
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1805 return ngx_http_mp4_read_atom(mp4, ngx_http_mp4_stbl_atoms, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1806 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1807
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1808
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1809 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1810 ngx_http_mp4_update_stbl_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1811 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1812 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1813 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1814
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1815 trak->size += sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1816 atom = &trak->stbl_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1817 ngx_mp4_set_32value(atom->pos, trak->size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1818 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1819
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1820
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1821 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1822 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1823 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1824 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1825 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1826 u_char entries[4];
4099
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1827
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1828 u_char media_size[4];
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1829 u_char media_name[4];
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1830 } ngx_mp4_stsd_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1831
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1832
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1833 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1834 ngx_http_mp4_read_stsd_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1835 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1836 u_char *atom_header, *atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1837 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1838 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1839 ngx_mp4_stsd_atom_t *stsd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1840 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1841
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1842 /* sample description atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1843
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1844 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 stsd atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1845
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1846 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1847 stsd_atom = (ngx_mp4_stsd_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1848 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1849 atom_table = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1850 ngx_mp4_set_32value(stsd_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1851 ngx_mp4_set_atom_name(stsd_atom, 's', 't', 's', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1852
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1853 if (ngx_mp4_atom_data_size(ngx_mp4_stsd_atom_t) > atom_data_size) {
4099
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1854 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1855 "\"%s\" mp4 stsd atom too small", mp4->file.name.data);
4099
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1856 return NGX_ERROR;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1857 }
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1858
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1859 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1860 "stsd entries:%uD, media:%*s",
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1861 ngx_mp4_get_32value(stsd_atom->entries),
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1862 4, stsd_atom->media_name);
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1863
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1864 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1865
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1866 atom = &trak->stsd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1867 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1868 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1869 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1870
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1871 trak->out[NGX_HTTP_MP4_STSD_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1872 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1873
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1874 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1875
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1876 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1877 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1878
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1879
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1880 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1881 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1882 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1883 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1884 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1885 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1886 } ngx_mp4_stts_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1887
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1888 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1889 u_char count[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1890 u_char duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1891 } ngx_mp4_stts_entry_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1892
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1893
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1894 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1895 ngx_http_mp4_read_stts_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1896 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1897 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1898 uint32_t entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1899 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1900 ngx_mp4_stts_atom_t *stts_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1901 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1902
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1903 /* time-to-sample atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1904
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1905 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 stts atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1906
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1907 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1908 stts_atom = (ngx_mp4_stts_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1909 ngx_mp4_set_atom_name(stts_atom, 's', 't', 't', 's');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1910
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1911 if (ngx_mp4_atom_data_size(ngx_mp4_stts_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1912 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1913 "\"%s\" mp4 stts atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1914 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1915 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1916
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1917 entries = ngx_mp4_get_32value(stts_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1918
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1919 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4096
f9a1646b9611 Fix of debug message format.
Igor Sysoev <igor@sysoev.ru>
parents: 4095
diff changeset
1920 "mp4 time-to-sample entries:%uD", entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1921
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1922 if (ngx_mp4_atom_data_size(ngx_mp4_stts_atom_t)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1923 + entries * sizeof(ngx_mp4_stts_entry_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1924 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1925 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1926 "\"%s\" mp4 stts atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1927 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1928 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1929
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1930 atom_table = atom_header + sizeof(ngx_mp4_stts_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1931 atom_end = atom_table + entries * sizeof(ngx_mp4_stts_entry_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1932
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1933 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1934 trak->time_to_sample_entries = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1935
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1936 atom = &trak->stts_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1937 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1938 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1939 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1940
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1941 data = &trak->stts_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1942 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1943 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1944 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1945
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1946 trak->out[NGX_HTTP_MP4_STTS_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1947 trak->out[NGX_HTTP_MP4_STTS_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1948
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1949 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1950
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1951 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1952 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1953
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1954
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1955 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1956 ngx_http_mp4_update_stts_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1957 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1958 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1959 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1960 uint32_t entries, count, duration;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1961 uint64_t start_time;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1962 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1963 ngx_uint_t start_sample;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1964 ngx_mp4_stts_atom_t *stts_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1965 ngx_mp4_stts_entry_t *entry, *end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1966
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1967 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1968 * mdia.minf.stbl.stts updating requires trak->timescale
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1969 * from mdia.mdhd atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1970 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1971
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1972 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1973 "mp4 stts atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1974
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1975 data = trak->out[NGX_HTTP_MP4_STTS_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1976
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1977 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1978 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1979 "no mp4 stts atoms were found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1980 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1981 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1982 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1983
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1984 entries = trak->time_to_sample_entries;
4189
a12c558503f0 Fixing mp4 module seeking on 32-bit platforms.
Igor Sysoev <igor@sysoev.ru>
parents: 4156
diff changeset
1985 start_time = (uint64_t) mp4->start * trak->timescale / 1000;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1986
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1987 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4096
f9a1646b9611 Fix of debug message format.
Igor Sysoev <igor@sysoev.ru>
parents: 4095
diff changeset
1988 "time-to-sample start_time:%uL", start_time);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1989
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1990 start_sample = 0;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1991 entry = (ngx_mp4_stts_entry_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1992 end = (ngx_mp4_stts_entry_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1993
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1994 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1995 count = ngx_mp4_get_32value(entry->count);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1996 duration = ngx_mp4_get_32value(entry->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1997
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1998 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1999 "count:%uD, duration:%uD", count, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2000
4306
05f3174483de Fix of mp4 module seeking.
Igor Sysoev <igor@sysoev.ru>
parents: 4282
diff changeset
2001 if (start_time < (uint64_t) count * duration) {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2002 start_sample += (ngx_uint_t) (start_time / duration);
4578
dbbc5ad46216 Fixed previous commit.
Igor Sysoev <igor@sysoev.ru>
parents: 4577
diff changeset
2003 count -= (uint32_t) (start_time / duration);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2004 ngx_mp4_set_32value(entry->count, count);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2005 goto found;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2006 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2007
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2008 start_sample += count;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2009 start_time -= count * duration;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2010 entries--;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2011 entry++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2012 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2013
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2014 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
4094
c98b7e351332 Fix of error message.
Igor Sysoev <igor@sysoev.ru>
parents: 4093
diff changeset
2015 "start time is out mp4 stts samples in \"%s\"",
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2016 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2017
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2018 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2019
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2020 found:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2021
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2022 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2023 "start_sample:%ui, new count:%uD", start_sample, count);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2024
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2025 trak->start_sample = start_sample;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2026
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2027 data->pos = (u_char *) entry;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2028 atom_size = sizeof(ngx_mp4_stts_atom_t) + (data->last - data->pos);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2029 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2030
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2031 atom = trak->out[NGX_HTTP_MP4_STTS_ATOM].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2032 stts_atom = (ngx_mp4_stts_atom_t *) atom->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2033 ngx_mp4_set_32value(stts_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2034 ngx_mp4_set_32value(stts_atom->entries, entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2035
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2036 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2037 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2038
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2039
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2040 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2041 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2042 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2043 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2044 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2045 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2046 } ngx_http_mp4_stss_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2047
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2048
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2049 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2050 ngx_http_mp4_read_stss_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2051 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2052 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2053 uint32_t entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2054 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2055 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2056 ngx_http_mp4_stss_atom_t *stss_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2057
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2058 /* sync samples atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2059
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2060 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 stss atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2061
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2062 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2063 stss_atom = (ngx_http_mp4_stss_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2064 ngx_mp4_set_atom_name(stss_atom, 's', 't', 's', 's');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2065
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2066 if (ngx_mp4_atom_data_size(ngx_http_mp4_stss_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2067 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2068 "\"%s\" mp4 stss atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2069 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2070 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2071
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2072 entries = ngx_mp4_get_32value(stss_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2073
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2074 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4096
f9a1646b9611 Fix of debug message format.
Igor Sysoev <igor@sysoev.ru>
parents: 4095
diff changeset
2075 "sync sample entries:%uD", entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2076
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2077 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2078 trak->sync_samples_entries = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2079
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2080 atom_table = atom_header + sizeof(ngx_http_mp4_stss_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2081
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2082 atom = &trak->stss_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2083 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2084 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2085 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2086
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2087 if (ngx_mp4_atom_data_size(ngx_http_mp4_stss_atom_t)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2088 + entries * sizeof(uint32_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2089 {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2090 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2091 "\"%s\" mp4 stss atom too small", mp4->file.name.data);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2092 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2093 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2094
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2095 atom_end = atom_table + entries * sizeof(uint32_t);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2096
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2097 data = &trak->stss_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2098 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2099 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2100 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2101
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2102 trak->out[NGX_HTTP_MP4_STSS_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2103 trak->out[NGX_HTTP_MP4_STSS_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2104
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2105 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2106
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2107 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2108 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2109
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2110
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2111 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2112 ngx_http_mp4_update_stss_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2113 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2114 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2115 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2116 uint32_t entries, sample, start_sample, *entry, *end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2117 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2118 ngx_http_mp4_stss_atom_t *stss_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2119
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2120 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2121 * mdia.minf.stbl.stss updating requires trak->start_sample
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2122 * from mdia.minf.stbl.stts which depends on value from mdia.mdhd
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2123 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2124 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2125
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2126 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2127 "mp4 stss atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2128
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2129 data = trak->out[NGX_HTTP_MP4_STSS_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2130
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2131 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2132 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2133 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2134
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2135 /* sync samples starts from 1 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2136 start_sample = trak->start_sample + 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2137 entries = trak->sync_samples_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2138
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2139 entry = (uint32_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2140 end = (uint32_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2141
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2142 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2143 sample = ngx_mp4_get_32value(entry);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2144
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2145 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2146 "start:%uD, sync:%uD", start_sample, sample);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2147
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2148 if (sample >= start_sample) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2149 goto found;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2150 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2151
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2152 entries--;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2153 entry++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2154 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2155
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2156 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2157 "start sample is out of mp4 stss atom in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2158 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2159
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2160 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2161
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2162 found:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2163
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2164 data->pos = (u_char *) entry;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2165
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2166 start_sample = trak->start_sample;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2167
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2168 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2169 sample = ngx_mp4_get_32value(entry);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2170 sample -= start_sample;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2171 ngx_mp4_set_32value(entry, sample);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2172 entry++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2173 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2174
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2175 atom_size = sizeof(ngx_http_mp4_stss_atom_t) + (data->last - data->pos);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2176 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2177
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2178 atom = trak->out[NGX_HTTP_MP4_STSS_ATOM].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2179 stss_atom = (ngx_http_mp4_stss_atom_t *) atom->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2180
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2181 ngx_mp4_set_32value(stss_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2182 ngx_mp4_set_32value(stss_atom->entries, entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2183
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2184 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2185 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2186
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2187
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2188 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2189 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2190 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2191 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2192 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2193 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2194 } ngx_mp4_ctts_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2195
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2196 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2197 u_char count[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2198 u_char offset[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2199 } ngx_mp4_ctts_entry_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2200
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2201
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2202 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2203 ngx_http_mp4_read_ctts_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2204 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2205 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2206 uint32_t entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2207 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2208 ngx_mp4_ctts_atom_t *ctts_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2209 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2210
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2211 /* composition offsets atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2212
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2213 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 ctts atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2214
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2215 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2216 ctts_atom = (ngx_mp4_ctts_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2217 ngx_mp4_set_atom_name(ctts_atom, 'c', 't', 't', 's');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2218
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2219 if (ngx_mp4_atom_data_size(ngx_mp4_ctts_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2220 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2221 "\"%s\" mp4 ctts atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2222 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2223 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2224
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2225 entries = ngx_mp4_get_32value(ctts_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2226
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2227 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4096
f9a1646b9611 Fix of debug message format.
Igor Sysoev <igor@sysoev.ru>
parents: 4095
diff changeset
2228 "composition offset entries:%uD", entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2229
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2230 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2231 trak->composition_offset_entries = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2232
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2233 atom_table = atom_header + sizeof(ngx_mp4_ctts_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2234
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2235 atom = &trak->ctts_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2236 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2237 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2238 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2239
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2240 if (ngx_mp4_atom_data_size(ngx_mp4_ctts_atom_t)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2241 + entries * sizeof(ngx_mp4_ctts_entry_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2242 {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2243 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2244 "\"%s\" mp4 ctts atom too small", mp4->file.name.data);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2245 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2246 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2247
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2248 atom_end = atom_table + entries * sizeof(ngx_mp4_ctts_entry_t);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2249
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2250 data = &trak->ctts_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2251 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2252 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2253 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2254
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2255 trak->out[NGX_HTTP_MP4_CTTS_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2256 trak->out[NGX_HTTP_MP4_CTTS_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2257
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2258 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2259
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2260 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2261 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2262
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2263
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2264 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2265 ngx_http_mp4_update_ctts_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2266 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2267 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2268 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2269 uint32_t entries, count, start_sample;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2270 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2271 ngx_mp4_ctts_atom_t *ctts_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2272 ngx_mp4_ctts_entry_t *entry, *end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2273
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2274 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2275 * mdia.minf.stbl.ctts updating requires trak->start_sample
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2276 * from mdia.minf.stbl.stts which depends on value from mdia.mdhd
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2277 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2278 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2279
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2280 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2281 "mp4 ctts atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2282
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2283 data = trak->out[NGX_HTTP_MP4_CTTS_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2284
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2285 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2286 return;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2287 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2288
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2289 /* sync samples starts from 1 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2290 start_sample = trak->start_sample + 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2291 entries = trak->composition_offset_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2292 entry = (ngx_mp4_ctts_entry_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2293 end = (ngx_mp4_ctts_entry_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2294
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2295 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2296 count = ngx_mp4_get_32value(entry->count);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2297
4088
8fe1da7b8386 bugfix of r4086: nginx could not be built without debug log.
Igor Sysoev <igor@sysoev.ru>
parents: 4087
diff changeset
2298 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2299 "start:%uD, count:%uD, offset:%uD",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2300 start_sample, count, ngx_mp4_get_32value(entry->offset));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2301
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2302 if (start_sample <= count) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2303 count -= (start_sample - 1);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2304 ngx_mp4_set_32value(entry->count, count);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2305 goto found;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2306 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2307
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2308 start_sample -= count;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2309 entries--;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2310 entry++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2311 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2312
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2313 trak->out[NGX_HTTP_MP4_CTTS_ATOM].buf = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2314 trak->out[NGX_HTTP_MP4_CTTS_DATA].buf = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2315
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2316 return;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2317
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2318 found:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2319
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2320 data->pos = (u_char *) entry;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2321 atom_size = sizeof(ngx_mp4_ctts_atom_t) + (data->last - data->pos);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2322 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2323
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2324 atom = trak->out[NGX_HTTP_MP4_CTTS_ATOM].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2325 ctts_atom = (ngx_mp4_ctts_atom_t *) atom->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2326
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2327 ngx_mp4_set_32value(ctts_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2328 ngx_mp4_set_32value(ctts_atom->entries, entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2329
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2330 return;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2331 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2332
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2333
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2334 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2335 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2336 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2337 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2338 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2339 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2340 } ngx_mp4_stsc_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2341
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2342
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2343 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2344 ngx_http_mp4_read_stsc_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2345 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2346 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2347 uint32_t entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2348 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2349 ngx_mp4_stsc_atom_t *stsc_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2350 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2351
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2352 /* sample-to-chunk atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2353
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2354 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 stsc atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2355
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2356 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2357 stsc_atom = (ngx_mp4_stsc_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2358 ngx_mp4_set_atom_name(stsc_atom, 's', 't', 's', 'c');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2359
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2360 if (ngx_mp4_atom_data_size(ngx_mp4_stsc_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2361 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2362 "\"%s\" mp4 stsc atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2363 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2364 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2365
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2366 entries = ngx_mp4_get_32value(stsc_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2367
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2368 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4096
f9a1646b9611 Fix of debug message format.
Igor Sysoev <igor@sysoev.ru>
parents: 4095
diff changeset
2369 "sample-to-chunk entries:%uD", entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2370
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2371 if (ngx_mp4_atom_data_size(ngx_mp4_stsc_atom_t)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2372 + entries * sizeof(ngx_mp4_stsc_entry_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2373 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2374 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2375 "\"%s\" mp4 stsc atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2376 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2377 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2378
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2379 atom_table = atom_header + sizeof(ngx_mp4_stsc_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2380 atom_end = atom_table + entries * sizeof(ngx_mp4_stsc_entry_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2381
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2382 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2383 trak->sample_to_chunk_entries = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2384
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2385 atom = &trak->stsc_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2386 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2387 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2388 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2389
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2390 data = &trak->stsc_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2391 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2392 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2393 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2394
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2395 trak->out[NGX_HTTP_MP4_STSC_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2396 trak->out[NGX_HTTP_MP4_STSC_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2397
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2398 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2399
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2400 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2401 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2402
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2403
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2404 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2405 ngx_http_mp4_update_stsc_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2406 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2407 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2408 size_t atom_size;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2409 uint32_t start_sample, entries, chunk, samples, id,
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2410 next_chunk, n;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2411 ngx_buf_t *atom, *data, *buf;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2412 ngx_mp4_stsc_atom_t *stsc_atom;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2413 ngx_mp4_stsc_entry_t *entry, *first, *end;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2414
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2415 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2416 * mdia.minf.stbl.stsc updating requires trak->start_sample
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2417 * from mdia.minf.stbl.stts which depends on value from mdia.mdhd
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2418 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2419 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2420
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2421 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2422 "mp4 stsc atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2423
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2424 data = trak->out[NGX_HTTP_MP4_STSC_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2425
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2426 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2427 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2428 "no mp4 stsc atoms were found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2429 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2430 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2431 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2432
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2433 if (trak->sample_to_chunk_entries == 0) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2434 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2435 "zero number of entries in stsc atom in \"%s\"",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2436 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2437 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2438 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2439
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2440 start_sample = (uint32_t) trak->start_sample;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2441 entries = trak->sample_to_chunk_entries - 1;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2442
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2443 entry = (ngx_mp4_stsc_entry_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2444 end = (ngx_mp4_stsc_entry_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2445
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2446 chunk = ngx_mp4_get_32value(entry->chunk);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2447 samples = ngx_mp4_get_32value(entry->samples);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2448 id = ngx_mp4_get_32value(entry->id);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2449 entry++;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2450
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2451 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2452
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2453 next_chunk = ngx_mp4_get_32value(entry->chunk);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2454
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2455 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2456 "start_sample:%uD, chunk:%uD, chunks:%uD, "
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2457 "samples:%uD, id:%uD",
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2458 start_sample, chunk, next_chunk - chunk, samples, id);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2459
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2460 n = (next_chunk - chunk) * samples;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2461
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2462 if (start_sample <= n) {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2463 goto found;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2464 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2465
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2466 start_sample -= n;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2467
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2468 chunk = next_chunk;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2469 samples = ngx_mp4_get_32value(entry->samples);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2470 id = ngx_mp4_get_32value(entry->id);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2471 entries--;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2472 entry++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2473 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2474
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2475 next_chunk = trak->chunks;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2476
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2477 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2478 "start_sample:%uD, chunk:%uD, chunks:%uD, samples:%uD",
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2479 start_sample, chunk, next_chunk - chunk, samples);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2480
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2481 n = (next_chunk - chunk) * samples;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2482
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2483 if (start_sample > n) {
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2484 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2485 "start time is out mp4 stsc chunks in \"%s\"",
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2486 mp4->file.name.data);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2487 return NGX_ERROR;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2488 }
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2489
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2490 found:
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2491
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2492 entries++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2493 entry--;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2494
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2495 if (samples == 0) {
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2496 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2497 "zero number of samples in \"%s\"",
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2498 mp4->file.name.data);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2499 return NGX_ERROR;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2500 }
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2501
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2502 trak->start_chunk = chunk - 1;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2503
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2504 trak->start_chunk += start_sample / samples;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2505 trak->chunk_samples = start_sample % samples;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2506
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2507 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2508 "start chunk:%ui, samples:%uD",
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2509 trak->start_chunk, trak->chunk_samples);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2510
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2511 data->pos = (u_char *) entry;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2512 atom_size = sizeof(ngx_mp4_stsc_atom_t) + (data->last - data->pos);
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2513
4382
b4d54fa76853 Fixed mp4 if first entry in stsc was skipped (ticket #72).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4306
diff changeset
2514 ngx_mp4_set_32value(entry->chunk, 1);
b4d54fa76853 Fixed mp4 if first entry in stsc was skipped (ticket #72).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4306
diff changeset
2515
4687
7f50a4063100 Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4611
diff changeset
2516 if (trak->chunk_samples && next_chunk - trak->start_chunk == 2) {
7f50a4063100 Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4611
diff changeset
2517
7f50a4063100 Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4611
diff changeset
2518 /* last chunk in the entry */
7f50a4063100 Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4611
diff changeset
2519
7f50a4063100 Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4611
diff changeset
2520 ngx_mp4_set_32value(entry->samples, samples - trak->chunk_samples);
7f50a4063100 Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4611
diff changeset
2521
7f50a4063100 Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4611
diff changeset
2522 } else if (trak->chunk_samples) {
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2523
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2524 first = &trak->stsc_chunk_entry;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2525 ngx_mp4_set_32value(first->chunk, 1);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2526 ngx_mp4_set_32value(first->samples, samples - trak->chunk_samples);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2527 ngx_mp4_set_32value(first->id, id);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2528
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2529 buf = &trak->stsc_chunk_buf;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2530 buf->temporary = 1;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2531 buf->pos = (u_char *) first;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2532 buf->last = (u_char *) first + sizeof(ngx_mp4_stsc_entry_t);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2533
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2534 trak->out[NGX_HTTP_MP4_STSC_CHUNK].buf = buf;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2535
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2536 ngx_mp4_set_32value(entry->chunk, 2);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2537
4687
7f50a4063100 Mp4: fixed non-keyframe seeks in some cases (ticket #175).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4611
diff changeset
2538 entries++;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2539 atom_size += sizeof(ngx_mp4_stsc_entry_t);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2540 }
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2541
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2542 while (++entry < end) {
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2543 chunk = ngx_mp4_get_32value(entry->chunk);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2544 chunk -= trak->start_chunk;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2545 ngx_mp4_set_32value(entry->chunk, chunk);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2546 }
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2547
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2548 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2549
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2550 atom = trak->out[NGX_HTTP_MP4_STSC_ATOM].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2551 stsc_atom = (ngx_mp4_stsc_atom_t *) atom->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2552
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2553 ngx_mp4_set_32value(stsc_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2554 ngx_mp4_set_32value(stsc_atom->entries, entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2555
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2556 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2557 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2558
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2559
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2560 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2561 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2562 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2563 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2564 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2565 u_char uniform_size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2566 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2567 } ngx_mp4_stsz_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2568
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2569
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2570 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2571 ngx_http_mp4_read_stsz_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2572 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2573 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2574 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2575 uint32_t entries, size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2576 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2577 ngx_mp4_stsz_atom_t *stsz_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2578 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2579
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2580 /* sample sizes atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2581
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2582 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 stsz atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2583
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2584 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2585 stsz_atom = (ngx_mp4_stsz_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2586 ngx_mp4_set_atom_name(stsz_atom, 's', 't', 's', 'z');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2587
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2588 if (ngx_mp4_atom_data_size(ngx_mp4_stsz_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2589 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2590 "\"%s\" mp4 stsz atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2591 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2592 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2593
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2594 size = ngx_mp4_get_32value(stsz_atom->uniform_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2595 entries = ngx_mp4_get_32value(stsz_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2596
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2597 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2598 "sample uniform size:%uD, entries:%uD", size, entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2599
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2600 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2601 trak->sample_sizes_entries = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2602
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2603 atom_table = atom_header + sizeof(ngx_mp4_stsz_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2604
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2605 atom = &trak->stsz_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2606 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2607 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2608 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2609
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2610 trak->out[NGX_HTTP_MP4_STSZ_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2611
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2612 if (size == 0) {
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2613 if (ngx_mp4_atom_data_size(ngx_mp4_stsz_atom_t)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2614 + entries * sizeof(uint32_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2615 {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2616 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2617 "\"%s\" mp4 stsz atom too small",
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2618 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2619 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2620 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2621
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2622 atom_end = atom_table + entries * sizeof(uint32_t);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2623
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2624 data = &trak->stsz_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2625 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2626 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2627 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2628
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2629 trak->out[NGX_HTTP_MP4_STSZ_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2630
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2631 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2632 /* if size != 0 then all samples are the same size */
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2633 /* TODO : chunk samples */
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2634 atom_size = sizeof(ngx_mp4_atom_header_t) + (size_t) atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2635 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2636 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2637 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2638
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2639 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2640
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2641 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2642 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2643
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2644
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2645 static ngx_int_t
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2646 ngx_http_mp4_update_stsz_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2647 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2648 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2649 size_t atom_size;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2650 uint32_t *pos, *end;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2651 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2652 ngx_mp4_stsz_atom_t *stsz_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2653
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2654 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2655 * mdia.minf.stbl.stsz updating requires trak->start_sample
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2656 * from mdia.minf.stbl.stts which depends on value from mdia.mdhd
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2657 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2658 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2659
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2660 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2661 "mp4 stsz atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2662
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2663 data = trak->out[NGX_HTTP_MP4_STSZ_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2664
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2665 if (data) {
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2666 if (trak->start_sample > trak->sample_sizes_entries) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2667 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2668 "start time is out mp4 stsz samples in \"%s\"",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2669 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2670 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2671 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2672
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2673 data->pos += trak->start_sample * sizeof(uint32_t);
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2674 end = (uint32_t *) data->pos;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2675
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2676 for (pos = end - trak->chunk_samples; pos < end; pos++) {
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2677 trak->chunk_samples_size += ngx_mp4_get_32value(pos);
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2678 }
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2679
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2680 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2681 "chunk samples sizes:%uL", trak->chunk_samples_size);
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2682
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2683 atom_size = sizeof(ngx_mp4_stsz_atom_t) + (data->last - data->pos);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2684 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2685
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2686 atom = trak->out[NGX_HTTP_MP4_STSZ_ATOM].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2687 stsz_atom = (ngx_mp4_stsz_atom_t *) atom->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2688
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2689 ngx_mp4_set_32value(stsz_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2690 ngx_mp4_set_32value(stsz_atom->entries,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2691 trak->sample_sizes_entries - trak->start_sample);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2692 }
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2693
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2694 return NGX_OK;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2695 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2696
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2697
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2698 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2699 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2700 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2701 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2702 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2703 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2704 } ngx_mp4_stco_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2705
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2706
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2707 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2708 ngx_http_mp4_read_stco_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2709 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2710 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2711 uint32_t entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2712 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2713 ngx_mp4_stco_atom_t *stco_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2714 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2715
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2716 /* chunk offsets atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2717
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2718 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 stco atom");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2719
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2720 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2721 stco_atom = (ngx_mp4_stco_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2722 ngx_mp4_set_atom_name(stco_atom, 's', 't', 'c', 'o');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2723
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2724 if (ngx_mp4_atom_data_size(ngx_mp4_stco_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2725 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2726 "\"%s\" mp4 stco atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2727 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2728 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2729
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2730 entries = ngx_mp4_get_32value(stco_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2731
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2732 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "chunks:%uD", entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2733
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2734 if (ngx_mp4_atom_data_size(ngx_mp4_stco_atom_t)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2735 + entries * sizeof(uint32_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2736 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2737 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2738 "\"%s\" mp4 stco atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2739 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2740 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2741
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2742 atom_table = atom_header + sizeof(ngx_mp4_stco_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2743 atom_end = atom_table + entries * sizeof(uint32_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2744
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2745 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2746 trak->chunks = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2747
4107
7705911c9d10 Fix of struct field name.
Igor Sysoev <igor@sysoev.ru>
parents: 4106
diff changeset
2748 atom = &trak->stco_atom_buf;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2749 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2750 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2751 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2752
4107
7705911c9d10 Fix of struct field name.
Igor Sysoev <igor@sysoev.ru>
parents: 4106
diff changeset
2753 data = &trak->stco_data_buf;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2754 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2755 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2756 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2757
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2758 trak->out[NGX_HTTP_MP4_STCO_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2759 trak->out[NGX_HTTP_MP4_STCO_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2760
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2761 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2762
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2763 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2764 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2765
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2766
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2767 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2768 ngx_http_mp4_update_stco_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2769 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2770 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2771 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2772 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2773 ngx_mp4_stco_atom_t *stco_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2774
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2775 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2776 * mdia.minf.stbl.stco updating requires trak->start_chunk
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2777 * from mdia.minf.stbl.stsc which depends on value from mdia.mdhd
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2778 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2779 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2780
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2781 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2782 "mp4 stco atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2783
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2784 data = trak->out[NGX_HTTP_MP4_STCO_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2785
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2786 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2787 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2788 "no mp4 stco atoms were found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2789 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2790 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2791 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2792
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2793 if (trak->start_chunk > trak->chunks) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2794 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2795 "start time is out mp4 stco chunks in \"%s\"",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2796 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2797 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2798 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2799
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2800 data->pos += trak->start_chunk * sizeof(uint32_t);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2801 atom_size = sizeof(ngx_mp4_stco_atom_t) + (data->last - data->pos);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2802 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2803
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2804 trak->start_offset = ngx_mp4_get_32value(data->pos);
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2805 trak->start_offset += trak->chunk_samples_size;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2806 ngx_mp4_set_32value(data->pos, trak->start_offset);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2807
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2808 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2809 "start chunk offset:%uD", trak->start_offset);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2810
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2811 atom = trak->out[NGX_HTTP_MP4_STCO_ATOM].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2812 stco_atom = (ngx_mp4_stco_atom_t *) atom->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2813
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2814 ngx_mp4_set_32value(stco_atom->size, atom_size);
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2815 ngx_mp4_set_32value(stco_atom->entries, trak->chunks - trak->start_chunk);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2816
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2817 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2818 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2819
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2820
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2821 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2822 ngx_http_mp4_adjust_stco_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2823 ngx_http_mp4_trak_t *trak, int32_t adjustment)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2824 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2825 uint32_t offset, *entry, *end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2826 ngx_buf_t *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2827
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2828 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2829 * moov.trak.mdia.minf.stbl.stco adjustment requires
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2830 * minimal start offset of all traks and new moov atom size
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2831 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2832
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2833 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2834 "mp4 stco atom adjustment");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2835
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2836 data = trak->out[NGX_HTTP_MP4_STCO_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2837 entry = (uint32_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2838 end = (uint32_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2839
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2840 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2841 offset = ngx_mp4_get_32value(entry);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2842 offset += adjustment;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2843 ngx_mp4_set_32value(entry, offset);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2844 entry++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2845 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2846 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2847
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2848
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2849 typedef struct {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2850 u_char size[4];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2851 u_char name[4];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2852 u_char version[1];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2853 u_char flags[3];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2854 u_char entries[4];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2855 } ngx_mp4_co64_atom_t;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2856
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2857
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2858 static ngx_int_t
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2859 ngx_http_mp4_read_co64_atom(ngx_http_mp4_file_t *mp4, uint64_t atom_data_size)
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2860 {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2861 u_char *atom_header, *atom_table, *atom_end;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2862 uint32_t entries;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2863 ngx_buf_t *atom, *data;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2864 ngx_mp4_co64_atom_t *co64_atom;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2865 ngx_http_mp4_trak_t *trak;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2866
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2867 /* chunk offsets atom */
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2868
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2869 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 co64 atom");
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2870
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2871 atom_header = ngx_mp4_atom_header(mp4);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2872 co64_atom = (ngx_mp4_co64_atom_t *) atom_header;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2873 ngx_mp4_set_atom_name(co64_atom, 'c', 'o', '6', '4');
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2874
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2875 if (ngx_mp4_atom_data_size(ngx_mp4_co64_atom_t) > atom_data_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2876 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2877 "\"%s\" mp4 co64 atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2878 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2879 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2880
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2881 entries = ngx_mp4_get_32value(co64_atom->entries);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2882
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2883 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "chunks:%uD", entries);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2884
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2885 if (ngx_mp4_atom_data_size(ngx_mp4_co64_atom_t)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2886 + entries * sizeof(uint64_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2887 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2888 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2889 "\"%s\" mp4 co64 atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2890 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2891 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2892
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2893 atom_table = atom_header + sizeof(ngx_mp4_co64_atom_t);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2894 atom_end = atom_table + entries * sizeof(uint64_t);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2895
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2896 trak = ngx_mp4_last_trak(mp4);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2897 trak->chunks = entries;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2898
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2899 atom = &trak->co64_atom_buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2900 atom->temporary = 1;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2901 atom->pos = atom_header;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2902 atom->last = atom_table;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2903
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2904 data = &trak->co64_data_buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2905 data->temporary = 1;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2906 data->pos = atom_table;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2907 data->last = atom_end;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2908
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2909 trak->out[NGX_HTTP_MP4_CO64_ATOM].buf = atom;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2910 trak->out[NGX_HTTP_MP4_CO64_DATA].buf = data;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2911
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2912 ngx_mp4_atom_next(mp4, atom_data_size);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2913
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2914 return NGX_OK;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2915 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2916
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2917
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2918 static ngx_int_t
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2919 ngx_http_mp4_update_co64_atom(ngx_http_mp4_file_t *mp4,
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2920 ngx_http_mp4_trak_t *trak)
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2921 {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2922 size_t atom_size;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2923 ngx_buf_t *atom, *data;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2924 ngx_mp4_co64_atom_t *co64_atom;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2925
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2926 /*
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2927 * mdia.minf.stbl.co64 updating requires trak->start_chunk
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2928 * from mdia.minf.stbl.stsc which depends on value from mdia.mdhd
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2929 * atom which may reside after mdia.minf
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2930 */
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2931
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2932 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2933 "mp4 co64 atom update");
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2934
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2935 data = trak->out[NGX_HTTP_MP4_CO64_DATA].buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2936
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2937 if (data == NULL) {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2938 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2939 "no mp4 co64 atoms were found in \"%s\"",
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2940 mp4->file.name.data);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2941 return NGX_ERROR;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2942 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2943
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2944 if (trak->start_chunk > trak->chunks) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2945 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2946 "start time is out mp4 co64 chunks in \"%s\"",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2947 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2948 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2949 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2950
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2951 data->pos += trak->start_chunk * sizeof(uint64_t);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2952 atom_size = sizeof(ngx_mp4_co64_atom_t) + (data->last - data->pos);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2953 trak->size += atom_size;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2954
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2955 trak->start_offset = ngx_mp4_get_64value(data->pos);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2956 trak->start_offset += trak->chunk_samples_size;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2957 ngx_mp4_set_64value(data->pos, trak->start_offset);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2958
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2959 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2960 "start chunk offset:%uL", trak->start_offset);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2961
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2962 atom = trak->out[NGX_HTTP_MP4_CO64_ATOM].buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2963 co64_atom = (ngx_mp4_co64_atom_t *) atom->pos;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2964
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2965 ngx_mp4_set_32value(co64_atom->size, atom_size);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2966 ngx_mp4_set_32value(co64_atom->entries, trak->chunks - trak->start_chunk);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2967
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2968 return NGX_OK;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2969 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2970
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2971
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2972 static void
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2973 ngx_http_mp4_adjust_co64_atom(ngx_http_mp4_file_t *mp4,
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2974 ngx_http_mp4_trak_t *trak, off_t adjustment)
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2975 {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2976 uint64_t offset, *entry, *end;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2977 ngx_buf_t *data;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2978
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2979 /*
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2980 * moov.trak.mdia.minf.stbl.co64 adjustment requires
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2981 * minimal start offset of all traks and new moov atom size
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2982 */
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2983
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2984 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2985 "mp4 co64 atom adjustment");
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2986
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2987 data = trak->out[NGX_HTTP_MP4_CO64_DATA].buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2988 entry = (uint64_t *) data->pos;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2989 end = (uint64_t *) data->last;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2990
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2991 while (entry < end) {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2992 offset = ngx_mp4_get_64value(entry);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2993 offset += adjustment;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2994 ngx_mp4_set_64value(entry, offset);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2995 entry++;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2996 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2997 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2998
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
2999
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3000 static char *
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3001 ngx_http_mp4(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3002 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3003 ngx_http_core_loc_conf_t *clcf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3004
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3005 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3006 clcf->handler = ngx_http_mp4_handler;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3007
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3008 return NGX_CONF_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3009 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3010
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3011
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3012 static void *
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3013 ngx_http_mp4_create_conf(ngx_conf_t *cf)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3014 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3015 ngx_http_mp4_conf_t *conf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3016
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3017 conf = ngx_palloc(cf->pool, sizeof(ngx_http_mp4_conf_t));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3018 if (conf == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3019 return NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3020 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3021
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3022 conf->buffer_size = NGX_CONF_UNSET_SIZE;
4089
e27670e1ab70 mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
Igor Sysoev <igor@sysoev.ru>
parents: 4088
diff changeset
3023 conf->max_buffer_size = NGX_CONF_UNSET_SIZE;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3024
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3025 return conf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3026 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3027
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3028
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3029 static char *
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3030 ngx_http_mp4_merge_conf(ngx_conf_t *cf, void *parent, void *child)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3031 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3032 ngx_http_mp4_conf_t *prev = parent;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3033 ngx_http_mp4_conf_t *conf = child;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3034
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3035 ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, 512 * 1024);
4089
e27670e1ab70 mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
Igor Sysoev <igor@sysoev.ru>
parents: 4088
diff changeset
3036 ngx_conf_merge_size_value(conf->max_buffer_size, prev->max_buffer_size,
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3037 10 * 1024 * 1024);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3038
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3039 return NGX_CONF_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3040 }