annotate src/http/modules/ngx_http_mp4_module.c @ 8869:e5a17d6041bd quic

Fixed mismerge of ssl_reject_handshake in 71b7453fb11f. In particular, this fixes rejecting "listen .. quic|http3" configurations without TLSv1.3 configured.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 29 Sep 2021 15:01:53 +0300
parents 7a55311b0dc3
children 24f7904dbfa0
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
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
30 #define NGX_HTTP_MP4_STSC_START 18
4098
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
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
32 #define NGX_HTTP_MP4_STSC_END 20
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
33 #define NGX_HTTP_MP4_STSZ_ATOM 21
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
34 #define NGX_HTTP_MP4_STSZ_DATA 22
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
35 #define NGX_HTTP_MP4_STCO_ATOM 23
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
36 #define NGX_HTTP_MP4_STCO_DATA 24
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
37 #define NGX_HTTP_MP4_CO64_ATOM 25
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
38 #define NGX_HTTP_MP4_CO64_DATA 26
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
39
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
40 #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
41
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 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
45 size_t max_buffer_size;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 } ngx_http_mp4_conf_t;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 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
50 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
51 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
52 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
53 } 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
54
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
55
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
56 typedef struct {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 uint32_t timescale;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 uint32_t time_to_sample_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 uint32_t sample_to_chunk_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 uint32_t sync_samples_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 uint32_t composition_offset_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 uint32_t sample_sizes_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 uint32_t chunks;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 ngx_uint_t start_sample;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
66 ngx_uint_t end_sample;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67 ngx_uint_t start_chunk;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
68 ngx_uint_t end_chunk;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
69 ngx_uint_t start_chunk_samples;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
70 ngx_uint_t end_chunk_samples;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
71 uint64_t start_chunk_samples_size;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
72 uint64_t end_chunk_samples_size;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 off_t start_offset;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
74 off_t end_offset;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 size_t tkhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77 size_t mdhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 size_t hdlr_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 size_t vmhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 size_t smhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 size_t dinf_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 size_t size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 ngx_chain_t out[NGX_HTTP_MP4_LAST_ATOM + 1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 ngx_buf_t trak_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 ngx_buf_t tkhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 ngx_buf_t mdia_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 ngx_buf_t mdhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 ngx_buf_t hdlr_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 ngx_buf_t minf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 ngx_buf_t vmhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 ngx_buf_t smhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 ngx_buf_t dinf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 ngx_buf_t stbl_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 ngx_buf_t stsd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 ngx_buf_t stts_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 ngx_buf_t stts_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 ngx_buf_t stss_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100 ngx_buf_t stss_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 ngx_buf_t ctts_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 ngx_buf_t ctts_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103 ngx_buf_t stsc_atom_buf;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
104 ngx_buf_t stsc_start_chunk_buf;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
105 ngx_buf_t stsc_end_chunk_buf;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 ngx_buf_t stsc_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 ngx_buf_t stsz_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 ngx_buf_t stsz_data_buf;
4107
7705911c9d10 Fix of struct field name.
Igor Sysoev <igor@sysoev.ru>
parents: 4106
diff changeset
109 ngx_buf_t stco_atom_buf;
7705911c9d10 Fix of struct field name.
Igor Sysoev <igor@sysoev.ru>
parents: 4106
diff changeset
110 ngx_buf_t stco_data_buf;
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
111 ngx_buf_t co64_atom_buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
112 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
113
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
114 ngx_mp4_stsc_entry_t stsc_start_chunk_entry;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
115 ngx_mp4_stsc_entry_t stsc_end_chunk_entry;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 } ngx_http_mp4_trak_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 ngx_file_t file;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 u_char *buffer;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 u_char *buffer_start;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124 u_char *buffer_pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 u_char *buffer_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 size_t buffer_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 off_t offset;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 off_t end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 off_t content_length;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 ngx_uint_t start;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
132 ngx_uint_t length;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 uint32_t timescale;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 ngx_http_request_t *request;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 ngx_array_t trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136 ngx_http_mp4_trak_t traks[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 size_t ftyp_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 size_t moov_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141 ngx_chain_t *out;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 ngx_chain_t ftyp_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 ngx_chain_t moov_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 ngx_chain_t mvhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 ngx_chain_t mdat_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 ngx_chain_t mdat_data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 ngx_buf_t ftyp_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 ngx_buf_t moov_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 ngx_buf_t mvhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 ngx_buf_t mdat_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 ngx_buf_t mdat_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 u_char moov_atom_header[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 u_char mdat_atom_header[16];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 } ngx_http_mp4_file_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 char *name;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 ngx_int_t (*handler)(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 } ngx_http_mp4_atom_handler_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164
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 #define ngx_mp4_atom_header(mp4) (mp4->buffer_pos - 8)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167 #define ngx_mp4_atom_data(mp4) mp4->buffer_pos
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
168 #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
169
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
170
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
171 #define ngx_mp4_atom_next(mp4, n) \
7400
be5cb9c67c05 Mp4: fixed possible pointer overflow on 32-bit platforms.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7376
diff changeset
172 \
be5cb9c67c05 Mp4: fixed possible pointer overflow on 32-bit platforms.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7376
diff changeset
173 if (n > (size_t) (mp4->buffer_end - mp4->buffer_pos)) { \
be5cb9c67c05 Mp4: fixed possible pointer overflow on 32-bit platforms.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7376
diff changeset
174 mp4->buffer_pos = mp4->buffer_end; \
be5cb9c67c05 Mp4: fixed possible pointer overflow on 32-bit platforms.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7376
diff changeset
175 \
be5cb9c67c05 Mp4: fixed possible pointer overflow on 32-bit platforms.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7376
diff changeset
176 } else { \
be5cb9c67c05 Mp4: fixed possible pointer overflow on 32-bit platforms.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7376
diff changeset
177 mp4->buffer_pos += (size_t) n; \
be5cb9c67c05 Mp4: fixed possible pointer overflow on 32-bit platforms.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7376
diff changeset
178 } \
be5cb9c67c05 Mp4: fixed possible pointer overflow on 32-bit platforms.
Maxim Dounin <mdounin@mdounin.ru>
parents: 7376
diff changeset
179 \
5359
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
180 mp4->offset += n
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 #define ngx_mp4_set_atom_name(p, n1, n2, n3, n4) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 ((u_char *) (p))[4] = n1; \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 ((u_char *) (p))[5] = n2; \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 ((u_char *) (p))[6] = n3; \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187 ((u_char *) (p))[7] = n4
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 #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
190 ( ((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
191 + ( ((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
192 + ( ((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
193 + ( ((u_char *) (p))[3]) )
4085
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_32value(p, n) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 ((u_char *) (p))[0] = (u_char) ((n) >> 24); \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197 ((u_char *) (p))[1] = (u_char) ((n) >> 16); \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 ((u_char *) (p))[2] = (u_char) ((n) >> 8); \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199 ((u_char *) (p))[3] = (u_char) (n)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201 #define ngx_mp4_get_64value(p) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 ( ((uint64_t) ((u_char *) (p))[0] << 56) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 + ((uint64_t) ((u_char *) (p))[1] << 48) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204 + ((uint64_t) ((u_char *) (p))[2] << 40) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 + ((uint64_t) ((u_char *) (p))[3] << 32) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 + ((uint64_t) ((u_char *) (p))[4] << 24) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 + ( ((u_char *) (p))[5] << 16) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208 + ( ((u_char *) (p))[6] << 8) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209 + ( ((u_char *) (p))[7]) )
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 #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
212 ((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
213 ((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
214 ((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
215 ((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
216 ((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
217 ((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
218 ((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
219 ((u_char *) (p))[7] = (u_char) (n)
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 #define ngx_mp4_last_trak(mp4) \
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 &((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
223
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
225 static ngx_int_t ngx_http_mp4_handler(ngx_http_request_t *r);
6782
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
226 static ngx_int_t ngx_http_mp4_atofp(u_char *line, size_t n, size_t point);
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
227
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 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
229 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
230 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
231 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
232 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
233 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 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
235 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 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
237 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 static size_t ngx_http_mp4_update_mdat_atom(ngx_http_mp4_file_t *mp4,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
239 off_t start_offset, off_t end_offset);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 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
241 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242 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
243 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244 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
245 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246 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
247 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248 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
249 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
250 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
251 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
252 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
253 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254 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
255 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256 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
257 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 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
259 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260 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
261 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262 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
263 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
264 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
265 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
266 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
267 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
268 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
269 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
270 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
271 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272 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
273 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274 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
275 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276 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
277 ngx_http_mp4_trak_t *trak);
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
278 static ngx_int_t ngx_http_mp4_crop_stts_data(ngx_http_mp4_file_t *mp4,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
279 ngx_http_mp4_trak_t *trak, ngx_uint_t start);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
280 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
281 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
282 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
283 ngx_http_mp4_trak_t *trak);
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
284 static void ngx_http_mp4_crop_stss_data(ngx_http_mp4_file_t *mp4,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
285 ngx_http_mp4_trak_t *trak, ngx_uint_t start);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
286 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
287 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
288 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
289 ngx_http_mp4_trak_t *trak);
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
290 static void ngx_http_mp4_crop_ctts_data(ngx_http_mp4_file_t *mp4,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
291 ngx_http_mp4_trak_t *trak, ngx_uint_t start);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
292 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
293 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
294 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
295 ngx_http_mp4_trak_t *trak);
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
296 static ngx_int_t ngx_http_mp4_crop_stsc_data(ngx_http_mp4_file_t *mp4,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
297 ngx_http_mp4_trak_t *trak, ngx_uint_t start);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
298 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
299 uint64_t atom_data_size);
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
300 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
301 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
302 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
303 uint64_t atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
304 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
305 ngx_http_mp4_trak_t *trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
306 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
307 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
308 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
309 uint64_t atom_data_size);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
310 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
311 ngx_http_mp4_trak_t *trak);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
312 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
313 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
314
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
315 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
316 static void *ngx_http_mp4_create_conf(ngx_conf_t *cf);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
317 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
318
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
319
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
320 static ngx_command_t ngx_http_mp4_commands[] = {
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 { ngx_string("mp4"),
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
323 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324 ngx_http_mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
327 NULL },
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 { ngx_string("mp4_buffer_size"),
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330 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
331 ngx_conf_set_size_slot,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
332 NGX_HTTP_LOC_CONF_OFFSET,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
333 offsetof(ngx_http_mp4_conf_t, buffer_size),
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
334 NULL },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
335
4089
e27670e1ab70 mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
Igor Sysoev <igor@sysoev.ru>
parents: 4088
diff changeset
336 { ngx_string("mp4_max_buffer_size"),
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
337 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
338 ngx_conf_set_size_slot,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
339 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
340 offsetof(ngx_http_mp4_conf_t, max_buffer_size),
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
341 NULL },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
342
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
343 ngx_null_command
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
344 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
345
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
346
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
347 static ngx_http_module_t ngx_http_mp4_module_ctx = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
348 NULL, /* preconfiguration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
349 NULL, /* postconfiguration */
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 NULL, /* create main configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352 NULL, /* init main configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
353
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
354 NULL, /* create server configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
355 NULL, /* merge server configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357 ngx_http_mp4_create_conf, /* create location configuration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
358 ngx_http_mp4_merge_conf /* merge location configuration */
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
361
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
362 ngx_module_t ngx_http_mp4_module = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
363 NGX_MODULE_V1,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
364 &ngx_http_mp4_module_ctx, /* module context */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
365 ngx_http_mp4_commands, /* module directives */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
366 NGX_HTTP_MODULE, /* module type */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367 NULL, /* init master */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
368 NULL, /* init module */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
369 NULL, /* init process */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
370 NULL, /* init thread */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
371 NULL, /* exit thread */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
372 NULL, /* exit process */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
373 NULL, /* exit master */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
374 NGX_MODULE_V1_PADDING
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
375 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
376
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
377
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
378 static ngx_http_mp4_atom_handler_t ngx_http_mp4_atoms[] = {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
379 { "ftyp", ngx_http_mp4_read_ftyp_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
380 { "moov", ngx_http_mp4_read_moov_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
381 { "mdat", ngx_http_mp4_read_mdat_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
382 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
384
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
385 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
386 { "mvhd", ngx_http_mp4_read_mvhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
387 { "trak", ngx_http_mp4_read_trak_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
388 { "cmov", ngx_http_mp4_read_cmov_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
389 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
390 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
391
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
392 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
393 { "tkhd", ngx_http_mp4_read_tkhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
394 { "mdia", ngx_http_mp4_read_mdia_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
395 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
396 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
397
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
398 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
399 { "mdhd", ngx_http_mp4_read_mdhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
400 { "hdlr", ngx_http_mp4_read_hdlr_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
401 { "minf", ngx_http_mp4_read_minf_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
402 { NULL, NULL }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
405 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
406 { "vmhd", ngx_http_mp4_read_vmhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
407 { "smhd", ngx_http_mp4_read_smhd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
408 { "dinf", ngx_http_mp4_read_dinf_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
409 { "stbl", ngx_http_mp4_read_stbl_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
410 { NULL, NULL }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
411 };
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
412
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
413 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
414 { "stsd", ngx_http_mp4_read_stsd_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
415 { "stts", ngx_http_mp4_read_stts_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
416 { "stss", ngx_http_mp4_read_stss_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
417 { "ctts", ngx_http_mp4_read_ctts_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
418 { "stsc", ngx_http_mp4_read_stsc_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
419 { "stsz", ngx_http_mp4_read_stsz_atom },
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
420 { "stco", ngx_http_mp4_read_stco_atom },
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
421 { "co64", ngx_http_mp4_read_co64_atom },
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
422 { NULL, NULL }
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
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 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
427 ngx_http_mp4_handler(ngx_http_request_t *r)
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 u_char *last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
430 size_t root;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
431 ngx_int_t rc, start, end;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
432 ngx_uint_t level, length;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
433 ngx_str_t path, value;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
434 ngx_log_t *log;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
435 ngx_buf_t *b;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436 ngx_chain_t out;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
437 ngx_http_mp4_file_t *mp4;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
438 ngx_open_file_info_t of;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
439 ngx_http_core_loc_conf_t *clcf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
440
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
441 if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
442 return NGX_HTTP_NOT_ALLOWED;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
445 if (r->uri.data[r->uri.len - 1] == '/') {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
446 return NGX_DECLINED;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
447 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
448
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
449 rc = ngx_http_discard_request_body(r);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
450
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
451 if (rc != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
452 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
453 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
454
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
455 last = ngx_http_map_uri_to_path(r, &path, &root, 0);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
456 if (last == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
457 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
458 }
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 log = r->connection->log;
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 path.len = last - path.data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
463
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
464 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
465 "http mp4 filename: \"%V\"", &path);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
466
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
467 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
468
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
469 ngx_memzero(&of, sizeof(ngx_open_file_info_t));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
470
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
471 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
472 of.directio = NGX_MAX_OFF_T_VALUE;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
473 of.valid = clcf->open_file_cache_valid;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
474 of.min_uses = clcf->open_file_cache_min_uses;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
475 of.errors = clcf->open_file_cache_errors;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
476 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
477
13e09cf11d4e Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents: 4478
diff changeset
478 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
479 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
480 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
481
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
482 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
483 != NGX_OK)
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 switch (of.err) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
486
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
487 case 0:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
488 return NGX_HTTP_INTERNAL_SERVER_ERROR;
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 case NGX_ENOENT:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
491 case NGX_ENOTDIR:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
492 case NGX_ENAMETOOLONG:
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 level = NGX_LOG_ERR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
495 rc = NGX_HTTP_NOT_FOUND;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
496 break;
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 case NGX_EACCES:
4478
08713bac87fc Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents: 4412
diff changeset
499 #if (NGX_HAVE_OPENAT)
08713bac87fc Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents: 4412
diff changeset
500 case NGX_EMLINK:
08713bac87fc Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents: 4412
diff changeset
501 case NGX_ELOOP:
08713bac87fc Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents: 4412
diff changeset
502 #endif
4085
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 level = NGX_LOG_ERR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
505 rc = NGX_HTTP_FORBIDDEN;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
506 break;
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 default:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
509
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
510 level = NGX_LOG_CRIT;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
511 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
512 break;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
513 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
514
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
515 if (rc != NGX_HTTP_NOT_FOUND || clcf->log_not_found) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
516 ngx_log_error(level, log, of.err,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
517 "%s \"%s\" failed", of.failed, path.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
518 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
519
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
520 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
521 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
522
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
523 if (!of.is_file) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
524 return NGX_DECLINED;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
525 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
526
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
527 r->root_tested = !r->error_page;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
528 r->allow_ranges = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
529
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
530 start = -1;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
531 length = 0;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
532 r->headers_out.content_length_n = of.size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
533 mp4 = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
534 b = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
535
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
536 if (r->args.len) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
537
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
538 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
539
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
540 /*
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
541 * A Flash player may send start value with a lot of digits
6782
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
542 * after dot so a custom function is used instead of ngx_atofp().
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
543 */
67a4654ba7d9 Using strtod() instead of atofp() to support a lot of digits after dot in
Igor Sysoev <igor@sysoev.ru>
parents: 4155
diff changeset
544
6782
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
545 start = ngx_http_mp4_atofp(value.data, value.len, 3);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
546 }
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
547
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
548 if (ngx_http_arg(r, (u_char *) "end", 3, &value) == NGX_OK) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
549
6782
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
550 end = ngx_http_mp4_atofp(value.data, value.len, 3);
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
551
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
552 if (end > 0) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
553 if (start < 0) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
554 start = 0;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
555 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
556
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
557 if (end > start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
558 length = end - start;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
559 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
560 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
561 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
562 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
563
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
564 if (start >= 0) {
5621
345e4fd4bb64 Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5620
diff changeset
565 r->single_range = 1;
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
566
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
567 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
568 if (mp4 == NULL) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
569 return NGX_HTTP_INTERNAL_SERVER_ERROR;
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
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
572 mp4->file.fd = of.fd;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
573 mp4->file.name = path;
5496
9d056f10fb99 Style: removed surplus semicolons.
Valentin Bartenev <vbart@nginx.com>
parents: 5359
diff changeset
574 mp4->file.log = r->connection->log;
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
575 mp4->end = of.size;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
576 mp4->start = (ngx_uint_t) start;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
577 mp4->length = length;
5202
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
578 mp4->request = r;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
579
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
580 switch (ngx_http_mp4_process(mp4)) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
581
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
582 case NGX_DECLINED:
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
583 if (mp4->buffer) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
584 ngx_pfree(r->pool, mp4->buffer);
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
585 }
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
586
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
587 ngx_pfree(r->pool, mp4);
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
588 mp4 = NULL;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
589
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
590 break;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
591
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
592 case NGX_OK:
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
593 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
594 break;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
595
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
596 default: /* NGX_ERROR */
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
597 if (mp4->buffer) {
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
598 ngx_pfree(r->pool, mp4->buffer);
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
599 }
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
600
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
601 ngx_pfree(r->pool, mp4);
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
602
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
603 return NGX_HTTP_INTERNAL_SERVER_ERROR;
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
604 }
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
605 }
322434f13bd8 Mp4: indentation and style, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5097
diff changeset
606
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
607 log->action = "sending mp4 to client";
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 (clcf->directio <= of.size) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
610
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
611 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
612 * DIRECTIO is set on transfer only
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
613 * to allow kernel to cache "moov" atom
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
616 if (ngx_directio_on(of.fd) == NGX_FILE_ERROR) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
617 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
618 ngx_directio_on_n " \"%s\" failed", path.data);
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
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
621 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
622
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
623 if (mp4) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
624 mp4->file.directio = 1;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
628 r->headers_out.status = NGX_HTTP_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
629 r->headers_out.last_modified_time = of.mtime;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
630
4748
192f54280a7a Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4705
diff changeset
631 if (ngx_http_set_etag(r) != NGX_OK) {
192f54280a7a Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4705
diff changeset
632 return NGX_HTTP_INTERNAL_SERVER_ERROR;
192f54280a7a Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4705
diff changeset
633 }
192f54280a7a Entity tags: set for static respones.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4705
diff changeset
634
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
635 if (ngx_http_set_content_type(r) != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636 return NGX_HTTP_INTERNAL_SERVER_ERROR;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
639 if (mp4 == NULL) {
6973
99934aade555 Use ngx_calloc_buf() where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents: 6818
diff changeset
640 b = ngx_calloc_buf(r->pool);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
641 if (b == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
642 return NGX_HTTP_INTERNAL_SERVER_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
643 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
645 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
646 if (b->file == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
647 return NGX_HTTP_INTERNAL_SERVER_ERROR;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
651 rc = ngx_http_send_header(r);
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 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
654 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
655 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
656
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
657 if (mp4) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
658 return ngx_http_output_filter(r, mp4->out);
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661 b->file_pos = 0;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
662 b->file_last = of.size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
663
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
664 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
665 b->last_buf = (r == r->main) ? 1 : 0;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
666 b->last_in_chain = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
667
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
668 b->file->fd = of.fd;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
669 b->file->name = path;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
670 b->file->log = log;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
671 b->file->directio = of.is_directio;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
672
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
673 out.buf = b;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
674 out.next = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
675
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
676 return ngx_http_output_filter(r, &out);
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
680 static ngx_int_t
6782
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
681 ngx_http_mp4_atofp(u_char *line, size_t n, size_t point)
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
682 {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
683 ngx_int_t value, cutoff, cutlim;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
684 ngx_uint_t dot;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
685
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
686 /* same as ngx_atofp(), but allows additional digits */
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
687
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
688 if (n == 0) {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
689 return NGX_ERROR;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
690 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
691
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
692 cutoff = NGX_MAX_INT_T_VALUE / 10;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
693 cutlim = NGX_MAX_INT_T_VALUE % 10;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
694
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
695 dot = 0;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
696
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
697 for (value = 0; n--; line++) {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
698
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
699 if (*line == '.') {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
700 if (dot) {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
701 return NGX_ERROR;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
702 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
703
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
704 dot = 1;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
705 continue;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
706 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
707
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
708 if (*line < '0' || *line > '9') {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
709 return NGX_ERROR;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
710 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
711
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
712 if (point == 0) {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
713 continue;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
714 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
715
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
716 if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
717 return NGX_ERROR;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
718 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
719
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
720 value = value * 10 + (*line - '0');
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
721 point -= dot;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
722 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
723
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
724 while (point--) {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
725 if (value > cutoff) {
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
726 return NGX_ERROR;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
727 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
728
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
729 value = value * 10;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
730 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
731
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
732 return value;
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
733 }
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
734
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
735
b123eae3fd4e Mp4: introduced custom version of ngx_atofp().
Maxim Dounin <mdounin@mdounin.ru>
parents: 6722
diff changeset
736 static ngx_int_t
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
737 ngx_http_mp4_process(ngx_http_mp4_file_t *mp4)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
738 {
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
739 off_t start_offset, end_offset, adjustment;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
740 ngx_int_t rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
741 ngx_uint_t i, j;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
742 ngx_chain_t **prev;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
743 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
744 ngx_http_mp4_conf_t *conf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
745
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
746 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
747 "mp4 start:%ui, length:%ui", mp4->start, mp4->length);
4085
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 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
750
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
751 mp4->buffer_size = conf->buffer_size;
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 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
754 if (rc != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
755 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
756 }
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 if (mp4->trak.nelts == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
759 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
760 "no mp4 trak atoms were found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
761 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
762 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
763 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
764
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
765 if (mp4->mdat_atom.buf == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
766 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
767 "no mp4 mdat atom was found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
768 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
769 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
770 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
771
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
772 prev = &mp4->out;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
773
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
774 if (mp4->ftyp_atom.buf) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
775 *prev = &mp4->ftyp_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
776 prev = &mp4->ftyp_atom.next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
777 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
778
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
779 *prev = &mp4->moov_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
780 prev = &mp4->moov_atom.next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
781
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
782 if (mp4->mvhd_atom.buf) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
783 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
784 *prev = &mp4->mvhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
785 prev = &mp4->mvhd_atom.next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
786 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
787
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
788 start_offset = mp4->end;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
789 end_offset = 0;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
790 trak = mp4->trak.elts;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
791
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
792 for (i = 0; i < mp4->trak.nelts; i++) {
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 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
795 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
796 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
797
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
798 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
799 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
800 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
801
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
802 ngx_http_mp4_update_ctts_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
803
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
804 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
805 return NGX_ERROR;
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
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
808 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
809 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
810 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
811
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
812 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
813 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
814 return NGX_ERROR;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
815 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
816
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
817 } else {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
818 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
819 return NGX_ERROR;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
820 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
821 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
822
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
823 ngx_http_mp4_update_stbl_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
824 ngx_http_mp4_update_minf_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
825 trak[i].size += trak[i].mdhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
826 trak[i].size += trak[i].hdlr_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
827 ngx_http_mp4_update_mdia_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
828 trak[i].size += trak[i].tkhd_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
829 ngx_http_mp4_update_trak_atom(mp4, &trak[i]);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
830
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
831 mp4->moov_size += trak[i].size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
832
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
833 if (start_offset > trak[i].start_offset) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
834 start_offset = trak[i].start_offset;
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
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
837 if (end_offset < trak[i].end_offset) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
838 end_offset = trak[i].end_offset;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
839 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
840
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
841 *prev = &trak[i].out[NGX_HTTP_MP4_TRAK_ATOM];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
842 prev = &trak[i].out[NGX_HTTP_MP4_TRAK_ATOM].next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
843
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
844 for (j = 0; j < NGX_HTTP_MP4_LAST_ATOM + 1; j++) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
845 if (trak[i].out[j].buf) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
846 *prev = &trak[i].out[j];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
847 prev = &trak[i].out[j].next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
848 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
849 }
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
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
852 if (end_offset < start_offset) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
853 end_offset = start_offset;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
854 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
855
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
856 mp4->moov_size += 8;
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 ngx_mp4_set_32value(mp4->moov_atom_header, mp4->moov_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
859 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
860 mp4->content_length += mp4->moov_size;
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 *prev = &mp4->mdat_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
863
5097
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
864 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
865 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
866 "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
867 mp4->file.name.data);
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
868 return NGX_ERROR;
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
869 }
37671d0042b7 Mp4: fixed handling of too small mdat atoms (ticket #266).
Maxim Dounin <mdounin@mdounin.ru>
parents: 4820
diff changeset
870
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
871 adjustment = mp4->ftyp_size + mp4->moov_size
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
872 + ngx_http_mp4_update_mdat_atom(mp4, start_offset, end_offset)
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
873 - start_offset;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
874
4088
8fe1da7b8386 bugfix of r4086: nginx could not be built without debug log.
Igor Sysoev <igor@sysoev.ru>
parents: 4087
diff changeset
875 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
876 "mp4 adjustment:%O", adjustment);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
877
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
878 for (i = 0; i < mp4->trak.nelts; i++) {
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
879 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
880 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
881 } else {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
882 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
883 }
4085
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
886 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
887 }
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 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
891 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
892 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
893 } ngx_mp4_atom_header_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
894
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
895 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
896 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
897 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
898 u_char size64[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
899 } ngx_mp4_atom_header64_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
900
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 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
903 ngx_http_mp4_read_atom(ngx_http_mp4_file_t *mp4,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
904 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
905 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
906 off_t end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
907 size_t atom_header_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
908 u_char *atom_header, *atom_name;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
909 uint64_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
910 ngx_int_t rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
911 ngx_uint_t n;
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 end = mp4->offset + atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
914
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
915 while (mp4->offset < end) {
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 (ngx_http_mp4_read(mp4, sizeof(uint32_t)) != NGX_OK) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
918 return NGX_ERROR;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
919 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
920
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
921 atom_header = mp4->buffer_pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
922 atom_size = ngx_mp4_get_32value(atom_header);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
923 atom_header_size = sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
924
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
925 if (atom_size == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
926 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
927 "mp4 atom end");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
928 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
929 }
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 if (atom_size < sizeof(ngx_mp4_atom_header_t)) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
932
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
933 if (atom_size == 1) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
934
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
935 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
936 != NGX_OK)
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
937 {
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
938 return NGX_ERROR;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
939 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
940
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
941 /* 64-bit atom size */
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
942 atom_header = mp4->buffer_pos;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
943 atom_size = ngx_mp4_get_64value(atom_header + 8);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
944 atom_header_size = sizeof(ngx_mp4_atom_header64_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
945
7376
e5069816039b Mp4: fixed reading 64-bit atoms.
Roman Arutyunyan <arut@nginx.com>
parents: 6973
diff changeset
946 if (atom_size < sizeof(ngx_mp4_atom_header64_t)) {
e5069816039b Mp4: fixed reading 64-bit atoms.
Roman Arutyunyan <arut@nginx.com>
parents: 6973
diff changeset
947 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
e5069816039b Mp4: fixed reading 64-bit atoms.
Roman Arutyunyan <arut@nginx.com>
parents: 6973
diff changeset
948 "\"%s\" mp4 atom is too small:%uL",
e5069816039b Mp4: fixed reading 64-bit atoms.
Roman Arutyunyan <arut@nginx.com>
parents: 6973
diff changeset
949 mp4->file.name.data, atom_size);
e5069816039b Mp4: fixed reading 64-bit atoms.
Roman Arutyunyan <arut@nginx.com>
parents: 6973
diff changeset
950 return NGX_ERROR;
e5069816039b Mp4: fixed reading 64-bit atoms.
Roman Arutyunyan <arut@nginx.com>
parents: 6973
diff changeset
951 }
e5069816039b Mp4: fixed reading 64-bit atoms.
Roman Arutyunyan <arut@nginx.com>
parents: 6973
diff changeset
952
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
953 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
954 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
955 "\"%s\" mp4 atom is too small:%uL",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
956 mp4->file.name.data, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
957 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
958 }
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
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
961 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
962 return NGX_ERROR;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
963 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
964
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
965 atom_header = mp4->buffer_pos;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
966 atom_name = atom_header + sizeof(uint32_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
967
4088
8fe1da7b8386 bugfix of r4086: nginx could not be built without debug log.
Igor Sysoev <igor@sysoev.ru>
parents: 4087
diff changeset
968 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
969 "mp4 atom: %*s @%O:%uL",
6478
3ef7bb882ad4 Fixed logging with variable field width.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6474
diff changeset
970 (size_t) 4, atom_name, mp4->offset, atom_size);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
971
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
972 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
973 || mp4->offset + (off_t) atom_size > end)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
974 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
975 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
976 "\"%s\" mp4 atom too large:%uL",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
977 mp4->file.name.data, atom_size);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
978 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
979 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
980
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
981 for (n = 0; atom[n].name; n++) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
982
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
983 if (ngx_strncmp(atom_name, atom[n].name, 4) == 0) {
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_mp4_atom_next(mp4, atom_header_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
986
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
987 rc = atom[n].handler(mp4, atom_size - atom_header_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
988 if (rc != NGX_OK) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
989 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
990 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
991
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
992 goto next;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
993 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
994 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
995
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
996 ngx_mp4_atom_next(mp4, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
997
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
998 next:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
999 continue;
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 return NGX_OK;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1005
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1006 static ngx_int_t
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1007 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
1008 {
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1009 ssize_t n;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1010
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1011 if (mp4->buffer_pos + size <= mp4->buffer_end) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1012 return NGX_OK;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1013 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1014
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1015 if (mp4->offset + (off_t) mp4->buffer_size > mp4->end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1016 mp4->buffer_size = (size_t) (mp4->end - mp4->offset);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1017 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1018
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1019 if (mp4->buffer_size < size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1020 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1021 "\"%s\" mp4 file truncated", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1022 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1023 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1024
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1025 if (mp4->buffer == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1026 mp4->buffer = ngx_palloc(mp4->request->pool, mp4->buffer_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1027 if (mp4->buffer == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1028 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1029 }
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 mp4->buffer_start = mp4->buffer;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1032 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1033
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1034 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
1035 mp4->offset);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1036
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1037 if (n == NGX_ERROR) {
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
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1041 if ((size_t) n != mp4->buffer_size) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1042 ngx_log_error(NGX_LOG_CRIT, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1043 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
1044 n, mp4->buffer_size, mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1045 return NGX_ERROR;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1046 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1047
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1048 mp4->buffer_pos = mp4->buffer_start;
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1049 mp4->buffer_end = mp4->buffer_start + mp4->buffer_size;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1050
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1051 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1052 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1053
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1054
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1055 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1056 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
1057 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1058 u_char *ftyp_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1059 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1060 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1061
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1062 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
1063
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1064 if (atom_data_size > 1024
5359
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
1065 || 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
1066 {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1067 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1068 "\"%s\" mp4 ftyp atom is too large:%uL",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1069 mp4->file.name.data, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1070 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1071 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1072
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1073 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
1074
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1075 ftyp_atom = ngx_palloc(mp4->request->pool, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1076 if (ftyp_atom == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1077 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1078 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1079
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1080 ngx_mp4_set_32value(ftyp_atom, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1081 ngx_mp4_set_atom_name(ftyp_atom, 'f', 't', 'y', 'p');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1082
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 * only moov atom content is guaranteed to be in mp4->buffer
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1085 * during sending response, so ftyp atom content should be copied
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 ngx_memcpy(ftyp_atom + sizeof(ngx_mp4_atom_header_t),
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1088 ngx_mp4_atom_data(mp4), (size_t) atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1089
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1090 atom = &mp4->ftyp_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1091 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1092 atom->pos = ftyp_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1093 atom->last = ftyp_atom + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1094
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1095 mp4->ftyp_atom.buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1096 mp4->ftyp_size = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1097 mp4->content_length = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1098
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1099 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1100
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1101 return NGX_OK;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1104
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1105 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1106 * 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
1107 * will be set to this buffer part after moov atom processing.
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1108 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1109 #define NGX_HTTP_MP4_MOOV_BUFFER_EXCESS (4 * 1024)
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 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1112 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
1113 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1114 ngx_int_t rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1115 ngx_uint_t no_mdat;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1116 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1117 ngx_http_mp4_conf_t *conf;
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 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
1120
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1121 no_mdat = (mp4->mdat_atom.buf == NULL);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1122
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1123 if (no_mdat && mp4->start == 0 && mp4->length == 0) {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1124 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1125 * send original file if moov atom resides before
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1126 * mdat atom and client requests integral file
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 return NGX_DECLINED;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1129 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1130
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1131 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
1132
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1133 if (atom_data_size > mp4->buffer_size) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1134
4089
e27670e1ab70 mp4_max_moov_size directive has been renamed to mp4_max_buffer_size.
Igor Sysoev <igor@sysoev.ru>
parents: 4088
diff changeset
1135 if (atom_data_size > conf->max_buffer_size) {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1136 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1137 "\"%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
1138 "you may want to increase mp4_max_buffer_size",
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1139 mp4->file.name.data, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1140 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1141 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1142
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1143 ngx_pfree(mp4->request->pool, mp4->buffer);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1144 mp4->buffer = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1145 mp4->buffer_pos = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1146 mp4->buffer_end = NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1147
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1148 mp4->buffer_size = (size_t) atom_data_size
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1149 + NGX_HTTP_MP4_MOOV_BUFFER_EXCESS * no_mdat;
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
4705
9a43b145a8ba Mp4: fixed build on win32 after r4689.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4688
diff changeset
1152 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
1153 return NGX_ERROR;
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1154 }
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1155
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1156 mp4->trak.elts = &mp4->traks;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1157 mp4->trak.size = sizeof(ngx_http_mp4_trak_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1158 mp4->trak.nalloc = 2;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1159 mp4->trak.pool = mp4->request->pool;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1160
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1161 atom = &mp4->moov_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1162 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1163 atom->pos = mp4->moov_atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1164 atom->last = mp4->moov_atom_header + 8;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1165
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1166 mp4->moov_atom.buf = &mp4->moov_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1167
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1168 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
1169
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1170 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
1171
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1172 if (no_mdat) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1173 mp4->buffer_start = mp4->buffer_pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1174 mp4->buffer_size = NGX_HTTP_MP4_MOOV_BUFFER_EXCESS;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1175
4688
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1176 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
1177 mp4->buffer = NULL;
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1178 mp4->buffer_pos = NULL;
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1179 mp4->buffer_end = NULL;
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1180 }
5fedb27c3e36 Mp4: fixed streaming if moov atom is at buffer edge.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4687
diff changeset
1181
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1182 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1183 /* skip atoms after moov atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1184 mp4->offset = mp4->end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1185 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1186
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1187 return rc;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1188 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1189
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1190
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1191 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1192 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
1193 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1194 ngx_buf_t *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1195
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1196 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
1197
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1198 data = &mp4->mdat_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1199 data->file = &mp4->file;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1200 data->in_file = 1;
6722
6136a51f9c21 Do not set last_buf flag in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents: 6504
diff changeset
1201 data->last_buf = (mp4->request == mp4->request->main) ? 1 : 0;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1202 data->last_in_chain = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1203 data->file_last = mp4->offset + atom_data_size;
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 mp4->mdat_atom.buf = &mp4->mdat_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1206 mp4->mdat_atom.next = &mp4->mdat_data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1207 mp4->mdat_data.buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1208
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1209 if (mp4->trak.nelts) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1210 /* skip atoms after mdat atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1211 mp4->offset = mp4->end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1212
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1213 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1214 ngx_mp4_atom_next(mp4, atom_data_size);
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1217 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1218 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1219
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1220
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1221 static size_t
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1222 ngx_http_mp4_update_mdat_atom(ngx_http_mp4_file_t *mp4, off_t start_offset,
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1223 off_t end_offset)
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1224 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1225 off_t atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1226 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1227 uint32_t atom_header_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1228 uint64_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1229 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1230
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1231 atom_data_size = end_offset - start_offset;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1232 mp4->mdat_data.buf->file_pos = start_offset;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1233 mp4->mdat_data.buf->file_last = end_offset;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1234
4088
8fe1da7b8386 bugfix of r4086: nginx could not be built without debug log.
Igor Sysoev <igor@sysoev.ru>
parents: 4087
diff changeset
1235 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
1236 "mdat new offset @%O:%O", start_offset, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1237
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1238 atom_header = mp4->mdat_atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1239
6818
2b2239a1e0d4 Mp4: fixed setting wrong mdat atom size in very rare cases.
hucongcong <hucong.c@foxmail.com>
parents: 6782
diff changeset
1240 if ((uint64_t) atom_data_size
2b2239a1e0d4 Mp4: fixed setting wrong mdat atom size in very rare cases.
hucongcong <hucong.c@foxmail.com>
parents: 6782
diff changeset
1241 > (uint64_t) 0xffffffff - sizeof(ngx_mp4_atom_header_t))
2b2239a1e0d4 Mp4: fixed setting wrong mdat atom size in very rare cases.
hucongcong <hucong.c@foxmail.com>
parents: 6782
diff changeset
1242 {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1243 atom_size = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1244 atom_header_size = sizeof(ngx_mp4_atom_header64_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1245 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
1246 sizeof(ngx_mp4_atom_header64_t) + atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1247 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1248 atom_size = sizeof(ngx_mp4_atom_header_t) + atom_data_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1249 atom_header_size = sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1250 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1251
4282
71cdac0b9ea6 Fix of "Content-Length" header of MP4 response if start argument was used.
Igor Sysoev <igor@sysoev.ru>
parents: 4189
diff changeset
1252 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
1253
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1254 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1255 ngx_mp4_set_atom_name(atom_header, 'm', 'd', 'a', 't');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1256
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1257 atom = &mp4->mdat_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1258 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1259 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1260 atom->last = atom_header + atom_header_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1261
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1262 return atom_header_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1263 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1264
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 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1267 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1268 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1269 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1270 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1271 u_char creation_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1272 u_char modification_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1273 u_char timescale[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1274 u_char duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1275 u_char rate[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1276 u_char volume[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1277 u_char reserved[10];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1278 u_char matrix[36];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1279 u_char preview_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1280 u_char preview_duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1281 u_char poster_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1282 u_char selection_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1283 u_char selection_duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1284 u_char current_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1285 u_char next_track_id[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1286 } ngx_mp4_mvhd_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1287
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1288 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1289 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1290 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1291 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1292 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1293 u_char creation_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1294 u_char modification_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1295 u_char timescale[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1296 u_char duration[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1297 u_char rate[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1298 u_char volume[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1299 u_char reserved[10];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1300 u_char matrix[36];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1301 u_char preview_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1302 u_char preview_duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1303 u_char poster_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1304 u_char selection_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1305 u_char selection_duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1306 u_char current_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1307 u_char next_track_id[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1308 } ngx_mp4_mvhd64_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1309
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1310
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1311 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1312 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
1313 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1314 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1315 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1316 uint32_t timescale;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1317 uint64_t duration, start_time, length_time;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1318 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1319 ngx_mp4_mvhd_atom_t *mvhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1320 ngx_mp4_mvhd64_atom_t *mvhd64_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1321
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1322 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
1323
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1324 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1325 mvhd_atom = (ngx_mp4_mvhd_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1326 mvhd64_atom = (ngx_mp4_mvhd64_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1327 ngx_mp4_set_atom_name(atom_header, 'm', 'v', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1328
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1329 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
1330 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1331 "\"%s\" mp4 mvhd atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1332 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1333 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1334
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1335 if (mvhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1336 /* version 0: 32-bit duration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1337 timescale = ngx_mp4_get_32value(mvhd_atom->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1338 duration = ngx_mp4_get_32value(mvhd_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1339
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1340 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1341 /* version 1: 64-bit duration */
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1342
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1343 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
1344 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1345 "\"%s\" mp4 mvhd atom too small",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1346 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1347 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1348 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1349
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1350 timescale = ngx_mp4_get_32value(mvhd64_atom->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1351 duration = ngx_mp4_get_64value(mvhd64_atom->duration);
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 mp4->timescale = timescale;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1355
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1356 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1357 "mvhd timescale:%uD, duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1358 timescale, duration, (double) duration / timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1359
5543
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1360 start_time = (uint64_t) mp4->start * timescale / 1000;
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1361
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1362 if (duration < start_time) {
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1363 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1364 "\"%s\" mp4 start time exceeds file duration",
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1365 mp4->file.name.data);
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1366 return NGX_ERROR;
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1367 }
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1368
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1369 duration -= start_time;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1370
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1371 if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1372 length_time = (uint64_t) mp4->length * timescale / 1000;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1373
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1374 if (duration > length_time) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1375 duration = length_time;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1376 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1377 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1378
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1379 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1380 "mvhd new duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1381 duration, (double) duration / timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1382
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1383 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
1384 ngx_mp4_set_32value(mvhd_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1385
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1386 if (mvhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1387 ngx_mp4_set_32value(mvhd_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1388
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1389 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1390 ngx_mp4_set_64value(mvhd64_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1391 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1392
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1393 atom = &mp4->mvhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1394 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1395 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1396 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1397
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1398 mp4->mvhd_atom.buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1399
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1400 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1401
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1402 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1403 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1404
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1405
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1406 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1407 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
1408 {
4099
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1409 u_char *atom_header, *atom_end;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1410 off_t atom_file_end;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1411 ngx_int_t rc;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1412 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1413 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1414
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1415 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
1416
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1417 trak = ngx_array_push(&mp4->trak);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1418 if (trak == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1419 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1420 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1421
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1422 ngx_memzero(trak, sizeof(ngx_http_mp4_trak_t));
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 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1425 ngx_mp4_set_atom_name(atom_header, 't', 'r', 'a', 'k');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1426
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1427 atom = &trak->trak_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1428 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1429 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1430 atom->last = atom_header + sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1431
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1432 trak->out[NGX_HTTP_MP4_TRAK_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1433
5359
2fda9065d0f4 Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5358
diff changeset
1434 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
1435 atom_file_end = mp4->offset + atom_data_size;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1436
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1437 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
1438
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1439 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
1440 "mp4 trak atom: %i", rc);
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1441
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1442 if (rc == NGX_DECLINED) {
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1443 /* skip this trak */
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1444 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
1445 mp4->trak.nelts--;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1446 mp4->buffer_pos = atom_end;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1447 mp4->offset = atom_file_end;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1448 return NGX_OK;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1449 }
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1450
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1451 return rc;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1452 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1455 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1456 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
1457 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1458 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1459 ngx_buf_t *atom;
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 trak->size += sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1462 atom = &trak->trak_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1463 ngx_mp4_set_32value(atom->pos, trak->size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1464 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1467 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1468 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
1469 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1470 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1471 "\"%s\" mp4 compressed moov atom (cmov) is not supported",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1472 mp4->file.name.data);
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 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1475 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1478 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1479 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1480 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1481 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1482 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1483 u_char creation_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1484 u_char modification_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1485 u_char track_id[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1486 u_char reserved1[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1487 u_char duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1488 u_char reserved2[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1489 u_char layer[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1490 u_char group[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1491 u_char volume[2];
6504
293413010217 Fixed spelling.
Josh Soref <timeless@gmail.com>
parents: 6478
diff changeset
1492 u_char reserved3[2];
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1493 u_char matrix[36];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1494 u_char width[4];
6504
293413010217 Fixed spelling.
Josh Soref <timeless@gmail.com>
parents: 6478
diff changeset
1495 u_char height[4];
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1496 } ngx_mp4_tkhd_atom_t;
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 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1499 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1500 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1501 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1502 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1503 u_char creation_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1504 u_char modification_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1505 u_char track_id[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1506 u_char reserved1[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1507 u_char duration[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1508 u_char reserved2[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1509 u_char layer[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1510 u_char group[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1511 u_char volume[2];
6504
293413010217 Fixed spelling.
Josh Soref <timeless@gmail.com>
parents: 6478
diff changeset
1512 u_char reserved3[2];
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1513 u_char matrix[36];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1514 u_char width[4];
6504
293413010217 Fixed spelling.
Josh Soref <timeless@gmail.com>
parents: 6478
diff changeset
1515 u_char height[4];
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1516 } ngx_mp4_tkhd64_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1517
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1518
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1519 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1520 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
1521 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1522 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1523 size_t atom_size;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1524 uint64_t duration, start_time, length_time;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1525 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1526 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1527 ngx_mp4_tkhd_atom_t *tkhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1528 ngx_mp4_tkhd64_atom_t *tkhd64_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1529
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1530 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
1531
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1532 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1533 tkhd_atom = (ngx_mp4_tkhd_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1534 tkhd64_atom = (ngx_mp4_tkhd64_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1535 ngx_mp4_set_atom_name(tkhd_atom, 't', 'k', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1536
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1537 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
1538 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1539 "\"%s\" mp4 tkhd atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1540 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1541 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1542
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1543 if (tkhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1544 /* version 0: 32-bit duration */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1545 duration = ngx_mp4_get_32value(tkhd_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1546
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1547 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1548 /* version 1: 64-bit duration */
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1549
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1550 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
1551 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1552 "\"%s\" mp4 tkhd atom too small",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1553 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1554 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1555 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1556
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1557 duration = ngx_mp4_get_64value(tkhd64_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1558 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1559
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1560 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1561 "tkhd duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1562 duration, (double) duration / mp4->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1563
5543
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1564 start_time = (uint64_t) mp4->start * mp4->timescale / 1000;
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1565
5629
c7bbc5fcf27c Mp4: fixed seeking to a track end.
Roman Arutyunyan <arut@nginx.com>
parents: 5622
diff changeset
1566 if (duration <= start_time) {
5543
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1567 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1568 "tkhd duration is less than start time");
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1569 return NGX_DECLINED;
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1570 }
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1571
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1572 duration -= start_time;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1573
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1574 if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1575 length_time = (uint64_t) mp4->length * mp4->timescale / 1000;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1576
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1577 if (duration > length_time) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1578 duration = length_time;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1579 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1580 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1581
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1582 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1583 "tkhd new duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1584 duration, (double) duration / mp4->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 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
1587
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1588 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1589 trak->tkhd_size = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1590
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1591 ngx_mp4_set_32value(tkhd_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1592
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1593 if (tkhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1594 ngx_mp4_set_32value(tkhd_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1595
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1596 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1597 ngx_mp4_set_64value(tkhd64_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1598 }
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 atom = &trak->tkhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1601 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1602 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1603 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1604
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1605 trak->out[NGX_HTTP_MP4_TKHD_ATOM].buf = atom;
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 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1608
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1609 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1610 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1613 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1614 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
1615 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1616 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1617 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1618 ngx_http_mp4_trak_t *trak;
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 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
1621
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1622 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1623 ngx_mp4_set_atom_name(atom_header, 'm', 'd', 'i', 'a');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1624
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1625 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1626
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1627 atom = &trak->mdia_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1628 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1629 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1630 atom->last = atom_header + sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1631
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1632 trak->out[NGX_HTTP_MP4_MDIA_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1633
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1634 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
1635 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1638 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1639 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
1640 ngx_http_mp4_trak_t *trak)
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 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1643
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1644 trak->size += sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1645 atom = &trak->mdia_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1646 ngx_mp4_set_32value(atom->pos, trak->size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1647 }
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 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1651 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1652 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1653 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1654 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1655 u_char creation_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1656 u_char modification_time[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1657 u_char timescale[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1658 u_char duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1659 u_char language[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1660 u_char quality[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1661 } ngx_mp4_mdhd_atom_t;
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 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1664 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1665 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1666 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1667 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1668 u_char creation_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1669 u_char modification_time[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1670 u_char timescale[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1671 u_char duration[8];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1672 u_char language[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1673 u_char quality[2];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1674 } ngx_mp4_mdhd64_atom_t;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1677 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1678 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
1679 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1680 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1681 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1682 uint32_t timescale;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1683 uint64_t duration, start_time, length_time;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1684 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1685 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1686 ngx_mp4_mdhd_atom_t *mdhd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1687 ngx_mp4_mdhd64_atom_t *mdhd64_atom;
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 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
1690
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1691 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1692 mdhd_atom = (ngx_mp4_mdhd_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1693 mdhd64_atom = (ngx_mp4_mdhd64_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1694 ngx_mp4_set_atom_name(mdhd_atom, 'm', 'd', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1695
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1696 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
1697 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1698 "\"%s\" mp4 mdhd atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1699 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1700 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1701
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1702 if (mdhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1703 /* version 0: everything is 32-bit */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1704 timescale = ngx_mp4_get_32value(mdhd_atom->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1705 duration = ngx_mp4_get_32value(mdhd_atom->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1706
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1707 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1708 /* version 1: 64-bit duration and 32-bit timescale */
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1709
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1710 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
1711 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1712 "\"%s\" mp4 mdhd atom too small",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1713 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1714 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1715 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
1716
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1717 timescale = ngx_mp4_get_32value(mdhd64_atom->timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1718 duration = ngx_mp4_get_64value(mdhd64_atom->duration);
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 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1722 "mdhd timescale:%uD, duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1723 timescale, duration, (double) duration / timescale);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1724
5543
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1725 start_time = (uint64_t) mp4->start * timescale / 1000;
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1726
5629
c7bbc5fcf27c Mp4: fixed seeking to a track end.
Roman Arutyunyan <arut@nginx.com>
parents: 5622
diff changeset
1727 if (duration <= start_time) {
5543
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1728 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1729 "mdhd duration is less than start time");
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1730 return NGX_DECLINED;
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1731 }
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1732
5730c0193842 Mp4: skip tracks shorter than seek position (ticket #414).
Roman Arutyunyan <arut@nginx.com>
parents: 5542
diff changeset
1733 duration -= start_time;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1734
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1735 if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1736 length_time = (uint64_t) mp4->length * timescale / 1000;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1737
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1738 if (duration > length_time) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1739 duration = length_time;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1740 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1741 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
1742
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1743 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1744 "mdhd new duration:%uL, time:%.3fs",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1745 duration, (double) duration / timescale);
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 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
1748
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1749 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1750 trak->mdhd_size = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1751 trak->timescale = timescale;
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 ngx_mp4_set_32value(mdhd_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1754
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1755 if (mdhd_atom->version[0] == 0) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1756 ngx_mp4_set_32value(mdhd_atom->duration, duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1757
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1758 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1759 ngx_mp4_set_64value(mdhd64_atom->duration, duration);
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1762 atom = &trak->mdhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1763 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1764 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1765 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1766
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1767 trak->out[NGX_HTTP_MP4_MDHD_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1768
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1769 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1770
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1771 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1772 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1773
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 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1776 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
1777 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1778 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1779 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1780 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1781 ngx_http_mp4_trak_t *trak;
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 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
1784
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1785 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1786 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
1787 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1788 ngx_mp4_set_atom_name(atom_header, 'h', 'd', 'l', 'r');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1789
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1790 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1791
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1792 atom = &trak->hdlr_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1793 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1794 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1795 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1796
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1797 trak->hdlr_size = atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1798 trak->out[NGX_HTTP_MP4_HDLR_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1799
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1800 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1801
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1802 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1803 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1806 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1807 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
1808 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1809 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1810 ngx_buf_t *atom;
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_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
1814
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1815 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1816 ngx_mp4_set_atom_name(atom_header, 'm', 'i', 'n', 'f');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1817
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1818 trak = ngx_mp4_last_trak(mp4);
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 atom = &trak->minf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1821 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1822 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1823 atom->last = atom_header + sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1824
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1825 trak->out[NGX_HTTP_MP4_MINF_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1826
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1827 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
1828 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1829
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1830
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1831 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1832 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
1833 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1834 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1835 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1836
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1837 trak->size += sizeof(ngx_mp4_atom_header_t)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1838 + trak->vmhd_size
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1839 + trak->smhd_size
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1840 + trak->dinf_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1841 atom = &trak->minf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1842 ngx_mp4_set_32value(atom->pos, trak->size);
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
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 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1847 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
1848 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1849 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1850 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1851 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1852 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1853
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1854 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
1855
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1856 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1857 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
1858 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1859 ngx_mp4_set_atom_name(atom_header, 'v', 'm', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1860
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1861 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1862
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1863 atom = &trak->vmhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1864 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1865 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1866 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1867
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1868 trak->vmhd_size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1869 trak->out[NGX_HTTP_MP4_VMHD_ATOM].buf = atom;
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 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1872
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1873 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1874 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1877 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1878 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
1879 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1880 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1881 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1882 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1883 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1884
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1885 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
1886
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1887 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1888 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
1889 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1890 ngx_mp4_set_atom_name(atom_header, 's', 'm', 'h', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1891
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1892 trak = ngx_mp4_last_trak(mp4);
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 atom = &trak->smhd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1895 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1896 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1897 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1898
5807
6d468b45f40e Mp4: use trak->smhd_size in ngx_http_mp4_read_smhd_atom().
Roman Arutyunyan <arut@nginx.com>
parents: 5638
diff changeset
1899 trak->smhd_size += atom_size;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1900 trak->out[NGX_HTTP_MP4_SMHD_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1901
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1902 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1903
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1904 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1905 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1908 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1909 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
1910 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1911 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1912 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1913 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1914 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1915
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1916 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
1917
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1918 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1919 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
1920 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1921 ngx_mp4_set_atom_name(atom_header, 'd', 'i', 'n', 'f');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1922
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1923 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1924
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1925 atom = &trak->dinf_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1926 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1927 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1928 atom->last = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1929
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1930 trak->dinf_size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1931 trak->out[NGX_HTTP_MP4_DINF_ATOM].buf = atom;
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 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1934
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1935 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1936 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1937
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1938
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1939 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1940 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
1941 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1942 u_char *atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1943 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1944 ngx_http_mp4_trak_t *trak;
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 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
1947
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1948 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1949 ngx_mp4_set_atom_name(atom_header, 's', 't', 'b', 'l');
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 trak = ngx_mp4_last_trak(mp4);
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 atom = &trak->stbl_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1954 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1955 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1956 atom->last = atom_header + sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1957
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1958 trak->out[NGX_HTTP_MP4_STBL_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1959
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1960 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
1961 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1962
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1963
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1964 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1965 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
1966 ngx_http_mp4_trak_t *trak)
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 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1969
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1970 trak->size += sizeof(ngx_mp4_atom_header_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1971 atom = &trak->stbl_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1972 ngx_mp4_set_32value(atom->pos, trak->size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1973 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1976 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1977 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1978 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1979 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1980 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1981 u_char entries[4];
4099
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1982
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1983 u_char media_size[4];
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
1984 u_char media_name[4];
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1985 } ngx_mp4_stsd_atom_t;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1988 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1989 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
1990 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1991 u_char *atom_header, *atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1992 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1993 ngx_buf_t *atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1994 ngx_mp4_stsd_atom_t *stsd_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1995 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1996
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1997 /* sample description atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1998
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1999 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
2000
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2001 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2002 stsd_atom = (ngx_mp4_stsd_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2003 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
2004 atom_table = atom_header + atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2005 ngx_mp4_set_32value(stsd_atom->size, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2006 ngx_mp4_set_atom_name(stsd_atom, 's', 't', 's', 'd');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2007
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2008 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
2009 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
2010 "\"%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
2011 return NGX_ERROR;
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
2012 }
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
2013
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
2014 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
2015 "stsd entries:%uD, media:%*s",
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
2016 ngx_mp4_get_32value(stsd_atom->entries),
6478
3ef7bb882ad4 Fixed logging with variable field width.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6474
diff changeset
2017 (size_t) 4, stsd_atom->media_name);
4099
9ee6944590c0 Skipping traks with unsupported media formats.
Igor Sysoev <igor@sysoev.ru>
parents: 4098
diff changeset
2018
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2019 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2020
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2021 atom = &trak->stsd_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2022 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2023 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2024 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2025
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2026 trak->out[NGX_HTTP_MP4_STSD_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2027 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2028
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2029 ngx_mp4_atom_next(mp4, atom_data_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 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2032 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2033
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2034
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2035 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2036 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2037 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2038 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2039 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2040 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2041 } ngx_mp4_stts_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2042
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2043 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2044 u_char count[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2045 u_char duration[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2046 } ngx_mp4_stts_entry_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_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
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_mp4_stts_atom_t *stts_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2056 ngx_http_mp4_trak_t *trak;
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 /* time-to-sample 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 stts 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 stts_atom = (ngx_mp4_stts_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2064 ngx_mp4_set_atom_name(stts_atom, 's', 't', 't', '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_mp4_stts_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 stts 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(stts_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 "mp4 time-to-sample entries:%uD", entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2076
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2077 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
2078 + entries * sizeof(ngx_mp4_stts_entry_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2079 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2080 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2081 "\"%s\" mp4 stts atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2082 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2083 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2084
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2085 atom_table = atom_header + sizeof(ngx_mp4_stts_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2086 atom_end = atom_table + entries * sizeof(ngx_mp4_stts_entry_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2087
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2088 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2089 trak->time_to_sample_entries = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2090
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2091 atom = &trak->stts_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2092 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2093 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2094 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2095
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2096 data = &trak->stts_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2097 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2098 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2099 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2100
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2101 trak->out[NGX_HTTP_MP4_STTS_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2102 trak->out[NGX_HTTP_MP4_STTS_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2103
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2104 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2105
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2106 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2107 }
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 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2111 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
2112 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2113 {
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2114 size_t atom_size;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2115 ngx_buf_t *atom, *data;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2116 ngx_mp4_stts_atom_t *stts_atom;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2117
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2118 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2119 * mdia.minf.stbl.stts updating requires trak->timescale
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2120 * from mdia.mdhd atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2121 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2122
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2123 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2124 "mp4 stts atom update");
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 data = trak->out[NGX_HTTP_MP4_STTS_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2127
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2128 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2129 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2130 "no mp4 stts atoms were found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2131 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2132 return NGX_ERROR;
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
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2135 if (ngx_http_mp4_crop_stts_data(mp4, trak, 1) != NGX_OK) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2136 return NGX_ERROR;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2137 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2138
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2139 if (ngx_http_mp4_crop_stts_data(mp4, trak, 0) != NGX_OK) {
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2140 return NGX_ERROR;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2141 }
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2142
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2143 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2144 "time-to-sample entries:%uD", trak->time_to_sample_entries);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2145
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2146 atom_size = sizeof(ngx_mp4_stts_atom_t) + (data->last - data->pos);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2147 trak->size += atom_size;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2148
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2149 atom = trak->out[NGX_HTTP_MP4_STTS_ATOM].buf;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2150 stts_atom = (ngx_mp4_stts_atom_t *) atom->pos;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2151 ngx_mp4_set_32value(stts_atom->size, atom_size);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2152 ngx_mp4_set_32value(stts_atom->entries, trak->time_to_sample_entries);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2153
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2154 return NGX_OK;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2155 }
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2156
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2157
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2158 static ngx_int_t
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2159 ngx_http_mp4_crop_stts_data(ngx_http_mp4_file_t *mp4,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2160 ngx_http_mp4_trak_t *trak, ngx_uint_t start)
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2161 {
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2162 uint32_t count, duration, rest;
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2163 uint64_t start_time;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2164 ngx_buf_t *data;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2165 ngx_uint_t start_sample, entries, start_sec;
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2166 ngx_mp4_stts_entry_t *entry, *end;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2167
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2168 if (start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2169 start_sec = mp4->start;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2170
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2171 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2172 "mp4 stts crop start_time:%ui", start_sec);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2173
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2174 } else if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2175 start_sec = mp4->length;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2176
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2177 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2178 "mp4 stts crop end_time:%ui", start_sec);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2179
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2180 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2181 return NGX_OK;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2182 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2183
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2184 data = trak->out[NGX_HTTP_MP4_STTS_DATA].buf;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2185
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2186 start_time = (uint64_t) start_sec * trak->timescale / 1000;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2187
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2188 entries = trak->time_to_sample_entries;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2189 start_sample = 0;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2190 entry = (ngx_mp4_stts_entry_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2191 end = (ngx_mp4_stts_entry_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2192
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2193 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2194 count = ngx_mp4_get_32value(entry->count);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2195 duration = ngx_mp4_get_32value(entry->duration);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2196
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2197 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2198 "time:%uL, count:%uD, duration:%uD",
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2199 start_time, count, duration);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2200
4306
05f3174483de Fix of mp4 module seeking.
Igor Sysoev <igor@sysoev.ru>
parents: 4282
diff changeset
2201 if (start_time < (uint64_t) count * duration) {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2202 start_sample += (ngx_uint_t) (start_time / duration);
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2203 rest = (uint32_t) (start_time / duration);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2204 goto found;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2205 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2206
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2207 start_sample += count;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2208 start_time -= count * duration;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2209 entries--;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2210 entry++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2211 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2212
5638
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2213 if (start) {
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2214 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2215 "start time is out mp4 stts samples in \"%s\"",
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2216 mp4->file.name.data);
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2217
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2218 return NGX_ERROR;
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2219
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2220 } else {
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2221 trak->end_sample = trak->start_sample + start_sample;
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2222
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2223 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2224 "end_sample:%ui", trak->end_sample);
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2225
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2226 return NGX_OK;
0c0dd1aacdf5 Mp4: allow end values bigger than track duration.
Roman Arutyunyan <arut@nginx.com>
parents: 5630
diff changeset
2227 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2228
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2229 found:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2230
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2231 if (start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2232 ngx_mp4_set_32value(entry->count, count - rest);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2233 data->pos = (u_char *) entry;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2234 trak->time_to_sample_entries = entries;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2235 trak->start_sample = start_sample;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2236
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2237 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2238 "start_sample:%ui, new count:%uD",
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2239 trak->start_sample, count - rest);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2240
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2241 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2242 ngx_mp4_set_32value(entry->count, rest);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2243 data->last = (u_char *) (entry + 1);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2244 trak->time_to_sample_entries -= entries - 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2245 trak->end_sample = trak->start_sample + start_sample;
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2246
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2247 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2248 "end_sample:%ui, new count:%uD",
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2249 trak->end_sample, rest);
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2250 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2251
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2252 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2253 }
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2256 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2257 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2258 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2259 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2260 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2261 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2262 } ngx_http_mp4_stss_atom_t;
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2265 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2266 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
2267 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2268 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2269 uint32_t entries;
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_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2272 ngx_http_mp4_stss_atom_t *stss_atom;
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 /* sync samples atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2275
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2276 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
2277
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2278 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2279 stss_atom = (ngx_http_mp4_stss_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2280 ngx_mp4_set_atom_name(stss_atom, 's', 't', 's', 's');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2281
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2282 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
2283 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2284 "\"%s\" mp4 stss atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2285 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2286 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2287
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2288 entries = ngx_mp4_get_32value(stss_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2289
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2290 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
2291 "sync sample entries:%uD", entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2292
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2293 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2294 trak->sync_samples_entries = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2295
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2296 atom_table = atom_header + sizeof(ngx_http_mp4_stss_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2297
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2298 atom = &trak->stss_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2299 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2300 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2301 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2302
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2303 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
2304 + entries * sizeof(uint32_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2305 {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2306 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
2307 "\"%s\" mp4 stss atom too small", mp4->file.name.data);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2308 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2309 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2310
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2311 atom_end = atom_table + entries * sizeof(uint32_t);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2312
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2313 data = &trak->stss_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2314 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2315 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2316 data->last = atom_end;
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 trak->out[NGX_HTTP_MP4_STSS_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2319 trak->out[NGX_HTTP_MP4_STSS_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2320
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2321 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2322
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2323 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2324 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2325
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 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2328 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
2329 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2330 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2331 size_t atom_size;
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2332 uint32_t sample, start_sample, *entry, *end;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2333 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2334 ngx_http_mp4_stss_atom_t *stss_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2335
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2336 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2337 * mdia.minf.stbl.stss updating requires trak->start_sample
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2338 * 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
2339 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2340 */
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 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2343 "mp4 stss atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2344
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2345 data = trak->out[NGX_HTTP_MP4_STSS_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2346
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2347 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2348 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2349 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2350
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2351 ngx_http_mp4_crop_stss_data(mp4, trak, 1);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2352 ngx_http_mp4_crop_stss_data(mp4, trak, 0);
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2353
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2354 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2355 "sync sample entries:%uD", trak->sync_samples_entries);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2356
5622
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2357 if (trak->sync_samples_entries) {
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2358 entry = (uint32_t *) data->pos;
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2359 end = (uint32_t *) data->last;
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2360
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2361 start_sample = trak->start_sample;
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2362
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2363 while (entry < end) {
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2364 sample = ngx_mp4_get_32value(entry);
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2365 sample -= start_sample;
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2366 ngx_mp4_set_32value(entry, sample);
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2367 entry++;
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2368 }
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2369
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2370 } else {
a23c35496c2f Mp4: skipped empty stss atom table in output.
Sergey Kandaurov <pluknet@nginx.com>
parents: 5621
diff changeset
2371 trak->out[NGX_HTTP_MP4_STSS_DATA].buf = NULL;
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2372 }
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2373
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2374 atom_size = sizeof(ngx_http_mp4_stss_atom_t) + (data->last - data->pos);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2375 trak->size += atom_size;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2376
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2377 atom = trak->out[NGX_HTTP_MP4_STSS_ATOM].buf;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2378 stss_atom = (ngx_http_mp4_stss_atom_t *) atom->pos;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2379
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2380 ngx_mp4_set_32value(stss_atom->size, atom_size);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2381 ngx_mp4_set_32value(stss_atom->entries, trak->sync_samples_entries);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2382
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2383 return NGX_OK;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2384 }
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2385
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2386
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2387 static void
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2388 ngx_http_mp4_crop_stss_data(ngx_http_mp4_file_t *mp4,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2389 ngx_http_mp4_trak_t *trak, ngx_uint_t start)
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2390 {
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2391 uint32_t sample, start_sample, *entry, *end;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2392 ngx_buf_t *data;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2393 ngx_uint_t entries;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2394
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2395 /* sync samples starts from 1 */
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2396
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2397 if (start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2398 start_sample = trak->start_sample + 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2399
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2400 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2401 "mp4 stss crop start_sample:%uD", start_sample);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2402
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2403 } else if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2404 start_sample = trak->end_sample + 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2405
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2406 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2407 "mp4 stss crop end_sample:%uD", start_sample);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2408
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2409 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2410 return;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2411 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2412
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2413 data = trak->out[NGX_HTTP_MP4_STSS_DATA].buf;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2414
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2415 entries = trak->sync_samples_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2416 entry = (uint32_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2417 end = (uint32_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2418
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2419 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2420 sample = ngx_mp4_get_32value(entry);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2421
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2422 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2423 "sync:%uD", sample);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2424
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2425 if (sample >= start_sample) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2426 goto found;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2427 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2428
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2429 entries--;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2430 entry++;
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
5542
847c308917af Mp4: fix seeks after the last key frame.
Roman Arutyunyan <arut@nginx.com>
parents: 5496
diff changeset
2433 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2434 "sample is out of mp4 stss atom");
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2435
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2436 found:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2437
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2438 if (start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2439 data->pos = (u_char *) entry;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2440 trak->sync_samples_entries = entries;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2441
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2442 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2443 data->last = (u_char *) entry;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2444 trak->sync_samples_entries -= entries;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2445 }
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2446 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2447
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2448
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2449 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2450 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2451 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2452 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2453 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2454 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2455 } ngx_mp4_ctts_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2456
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2457 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2458 u_char count[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2459 u_char offset[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2460 } ngx_mp4_ctts_entry_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2461
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2462
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2463 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2464 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
2465 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2466 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2467 uint32_t entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2468 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2469 ngx_mp4_ctts_atom_t *ctts_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2470 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2471
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2472 /* composition offsets atom */
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 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
2475
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2476 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2477 ctts_atom = (ngx_mp4_ctts_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2478 ngx_mp4_set_atom_name(ctts_atom, 'c', 't', 't', 's');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2479
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2480 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
2481 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2482 "\"%s\" mp4 ctts atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2483 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2484 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2485
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2486 entries = ngx_mp4_get_32value(ctts_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2487
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2488 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
2489 "composition offset entries:%uD", entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2490
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2491 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2492 trak->composition_offset_entries = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2493
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2494 atom_table = atom_header + sizeof(ngx_mp4_ctts_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2495
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2496 atom = &trak->ctts_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2497 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2498 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2499 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2500
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2501 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
2502 + entries * sizeof(ngx_mp4_ctts_entry_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2503 {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2504 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
2505 "\"%s\" mp4 ctts atom too small", mp4->file.name.data);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2506 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2507 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2508
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2509 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
2510
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2511 data = &trak->ctts_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2512 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2513 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2514 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2515
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2516 trak->out[NGX_HTTP_MP4_CTTS_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2517 trak->out[NGX_HTTP_MP4_CTTS_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2518
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2519 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2520
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2521 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2522 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2523
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2524
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2525 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2526 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
2527 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2528 {
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2529 size_t atom_size;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2530 ngx_buf_t *atom, *data;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2531 ngx_mp4_ctts_atom_t *ctts_atom;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2532
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2533 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2534 * mdia.minf.stbl.ctts updating requires trak->start_sample
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2535 * 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
2536 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2537 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2538
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2539 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2540 "mp4 ctts atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2541
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2542 data = trak->out[NGX_HTTP_MP4_CTTS_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2543
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2544 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2545 return;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2546 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2547
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2548 ngx_http_mp4_crop_ctts_data(mp4, trak, 1);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2549 ngx_http_mp4_crop_ctts_data(mp4, trak, 0);
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2550
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2551 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2552 "composition offset entries:%uD",
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2553 trak->composition_offset_entries);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2554
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2555 if (trak->composition_offset_entries == 0) {
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2556 trak->out[NGX_HTTP_MP4_CTTS_ATOM].buf = NULL;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2557 trak->out[NGX_HTTP_MP4_CTTS_DATA].buf = NULL;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2558 return;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2559 }
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2560
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2561 atom_size = sizeof(ngx_mp4_ctts_atom_t) + (data->last - data->pos);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2562 trak->size += atom_size;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2563
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2564 atom = trak->out[NGX_HTTP_MP4_CTTS_ATOM].buf;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2565 ctts_atom = (ngx_mp4_ctts_atom_t *) atom->pos;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2566
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2567 ngx_mp4_set_32value(ctts_atom->size, atom_size);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2568 ngx_mp4_set_32value(ctts_atom->entries, trak->composition_offset_entries);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2569
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2570 return;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2571 }
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2572
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2573
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2574 static void
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2575 ngx_http_mp4_crop_ctts_data(ngx_http_mp4_file_t *mp4,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2576 ngx_http_mp4_trak_t *trak, ngx_uint_t start)
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2577 {
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2578 uint32_t count, start_sample, rest;
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2579 ngx_buf_t *data;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2580 ngx_uint_t entries;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2581 ngx_mp4_ctts_entry_t *entry, *end;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2582
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2583 /* sync samples starts from 1 */
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2584
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2585 if (start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2586 start_sample = trak->start_sample + 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2587
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2588 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2589 "mp4 ctts crop start_sample:%uD", start_sample);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2590
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2591 } else if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2592 start_sample = trak->end_sample - trak->start_sample + 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2593
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2594 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2595 "mp4 ctts crop end_sample:%uD", start_sample);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2596
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2597 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2598 return;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2599 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2600
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2601 data = trak->out[NGX_HTTP_MP4_CTTS_DATA].buf;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2602
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2603 entries = trak->composition_offset_entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2604 entry = (ngx_mp4_ctts_entry_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2605 end = (ngx_mp4_ctts_entry_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2606
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2607 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2608 count = ngx_mp4_get_32value(entry->count);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2609
4088
8fe1da7b8386 bugfix of r4086: nginx could not be built without debug log.
Igor Sysoev <igor@sysoev.ru>
parents: 4087
diff changeset
2610 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2611 "sample:%uD, count:%uD, offset:%uD",
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2612 start_sample, count, ngx_mp4_get_32value(entry->offset));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2613
6474
Ruslan Ermilov <ru@nginx.com>
parents: 5807
diff changeset
2614 if (start_sample <= count) {
Ruslan Ermilov <ru@nginx.com>
parents: 5807
diff changeset
2615 rest = start_sample - 1;
Ruslan Ermilov <ru@nginx.com>
parents: 5807
diff changeset
2616 goto found;
Ruslan Ermilov <ru@nginx.com>
parents: 5807
diff changeset
2617 }
Ruslan Ermilov <ru@nginx.com>
parents: 5807
diff changeset
2618
Ruslan Ermilov <ru@nginx.com>
parents: 5807
diff changeset
2619 start_sample -= count;
Ruslan Ermilov <ru@nginx.com>
parents: 5807
diff changeset
2620 entries--;
Ruslan Ermilov <ru@nginx.com>
parents: 5807
diff changeset
2621 entry++;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2622 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2623
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2624 if (start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2625 data->pos = (u_char *) end;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2626 trak->composition_offset_entries = 0;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2627 }
4085
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 return;
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 found:
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2632
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2633 if (start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2634 ngx_mp4_set_32value(entry->count, count - rest);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2635 data->pos = (u_char *) entry;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2636 trak->composition_offset_entries = entries;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2637
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2638 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2639 ngx_mp4_set_32value(entry->count, rest);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2640 data->last = (u_char *) (entry + 1);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2641 trak->composition_offset_entries -= entries - 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2642 }
4085
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
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2645
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2646 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2647 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2648 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2649 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2650 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2651 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2652 } ngx_mp4_stsc_atom_t;
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 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2656 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
2657 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2658 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2659 uint32_t entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2660 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2661 ngx_mp4_stsc_atom_t *stsc_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2662 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2663
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2664 /* sample-to-chunk atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2665
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2666 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
2667
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2668 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2669 stsc_atom = (ngx_mp4_stsc_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2670 ngx_mp4_set_atom_name(stsc_atom, 's', 't', 's', 'c');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2671
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2672 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
2673 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2674 "\"%s\" mp4 stsc atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2675 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2676 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2677
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2678 entries = ngx_mp4_get_32value(stsc_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2679
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2680 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
2681 "sample-to-chunk entries:%uD", entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2682
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2683 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
2684 + entries * sizeof(ngx_mp4_stsc_entry_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2685 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2686 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2687 "\"%s\" mp4 stsc atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2688 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2689 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2690
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2691 atom_table = atom_header + sizeof(ngx_mp4_stsc_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2692 atom_end = atom_table + entries * sizeof(ngx_mp4_stsc_entry_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2693
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2694 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2695 trak->sample_to_chunk_entries = entries;
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 atom = &trak->stsc_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2698 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2699 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2700 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2701
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2702 data = &trak->stsc_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2703 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2704 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2705 data->last = atom_end;
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 trak->out[NGX_HTTP_MP4_STSC_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2708 trak->out[NGX_HTTP_MP4_STSC_DATA].buf = data;
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 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2711
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2712 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2713 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2714
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 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2717 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
2718 ngx_http_mp4_trak_t *trak)
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 size_t atom_size;
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2721 uint32_t chunk;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2722 ngx_buf_t *atom, *data;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2723 ngx_mp4_stsc_atom_t *stsc_atom;
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2724 ngx_mp4_stsc_entry_t *entry, *end;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2725
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2726 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2727 * mdia.minf.stbl.stsc updating requires trak->start_sample
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2728 * 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
2729 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2730 */
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_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2733 "mp4 stsc atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2734
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2735 data = trak->out[NGX_HTTP_MP4_STSC_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2736
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2737 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2738 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2739 "no mp4 stsc atoms were found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2740 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2741 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2742 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2743
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2744 if (trak->sample_to_chunk_entries == 0) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2745 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2746 "zero number of entries in stsc atom in \"%s\"",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2747 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2748 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2749 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
2750
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2751 if (ngx_http_mp4_crop_stsc_data(mp4, trak, 1) != NGX_OK) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2752 return NGX_ERROR;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2753 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2754
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2755 if (ngx_http_mp4_crop_stsc_data(mp4, trak, 0) != NGX_OK) {
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2756 return NGX_ERROR;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2757 }
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2758
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2759 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2760 "sample-to-chunk entries:%uD",
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2761 trak->sample_to_chunk_entries);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2762
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2763 entry = (ngx_mp4_stsc_entry_t *) data->pos;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2764 end = (ngx_mp4_stsc_entry_t *) data->last;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2765
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2766 while (entry < end) {
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2767 chunk = ngx_mp4_get_32value(entry->chunk);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2768 chunk -= trak->start_chunk;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2769 ngx_mp4_set_32value(entry->chunk, chunk);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2770 entry++;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2771 }
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2772
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2773 atom_size = sizeof(ngx_mp4_stsc_atom_t)
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2774 + trak->sample_to_chunk_entries * sizeof(ngx_mp4_stsc_entry_t);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2775
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2776 trak->size += atom_size;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2777
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2778 atom = trak->out[NGX_HTTP_MP4_STSC_ATOM].buf;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2779 stsc_atom = (ngx_mp4_stsc_atom_t *) atom->pos;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2780
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2781 ngx_mp4_set_32value(stsc_atom->size, atom_size);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2782 ngx_mp4_set_32value(stsc_atom->entries, trak->sample_to_chunk_entries);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2783
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2784 return NGX_OK;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2785 }
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2786
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2787
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2788 static ngx_int_t
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2789 ngx_http_mp4_crop_stsc_data(ngx_http_mp4_file_t *mp4,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2790 ngx_http_mp4_trak_t *trak, ngx_uint_t start)
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2791 {
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2792 uint32_t start_sample, chunk, samples, id, next_chunk, n,
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2793 prev_samples;
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2794 ngx_buf_t *data, *buf;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2795 ngx_uint_t entries, target_chunk, chunk_samples;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2796 ngx_mp4_stsc_entry_t *entry, *end, *first;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2797
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2798 entries = trak->sample_to_chunk_entries - 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2799
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2800 if (start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2801 start_sample = (uint32_t) trak->start_sample;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2802
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2803 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2804 "mp4 stsc crop start_sample:%uD", start_sample);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2805
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2806 } else if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2807 start_sample = (uint32_t) (trak->end_sample - trak->start_sample);
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2808 samples = 0;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2809
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2810 data = trak->out[NGX_HTTP_MP4_STSC_START].buf;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2811
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2812 if (data) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2813 entry = (ngx_mp4_stsc_entry_t *) data->pos;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2814 samples = ngx_mp4_get_32value(entry->samples);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2815 entries--;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2816
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2817 if (samples > start_sample) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2818 samples = start_sample;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2819 ngx_mp4_set_32value(entry->samples, samples);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2820 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2821
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2822 start_sample -= samples;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2823 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2824
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2825 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2826 "mp4 stsc crop end_sample:%uD, ext_samples:%uD",
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2827 start_sample, samples);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2828
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2829 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2830 return NGX_OK;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2831 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2832
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2833 data = trak->out[NGX_HTTP_MP4_STSC_DATA].buf;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2834
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2835 entry = (ngx_mp4_stsc_entry_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2836 end = (ngx_mp4_stsc_entry_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2837
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2838 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
2839 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
2840 id = ngx_mp4_get_32value(entry->id);
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2841 prev_samples = 0;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2842 entry++;
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2843
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2844 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2845
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2846 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
2847
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2848 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2849 "sample:%uD, chunk:%uD, chunks:%uD, "
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2850 "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
2851 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
2852
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2853 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
2854
5578
e280ece17020 Mp4: remove useless leading stsc entry in result mp4.
Roman Arutyunyan <arut@nginx.com>
parents: 5544
diff changeset
2855 if (start_sample < n) {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2856 goto found;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2857 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2858
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2859 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
2860
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2861 prev_samples = samples;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2862 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
2863 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
2864 id = ngx_mp4_get_32value(entry->id);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2865 entries--;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2866 entry++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2867 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2868
5544
2f586f1684fa Mp4: fix seeks to standalone last chunk.
Roman Arutyunyan <arut@nginx.com>
parents: 5543
diff changeset
2869 next_chunk = trak->chunks + 1;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2870
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2871 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2872 "sample:%uD, chunk:%uD, chunks:%uD, samples:%uD",
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2873 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
2874
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2875 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
2876
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2877 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
2878 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2879 "%s time is out mp4 stsc chunks in \"%s\"",
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2880 start ? "start" : "end", mp4->file.name.data);
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2881 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
2882 }
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2883
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2884 found:
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2885
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2886 entries++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2887 entry--;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2888
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2889 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
2890 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
2891 "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
2892 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
2893 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
2894 }
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2895
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2896 target_chunk = chunk - 1;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2897 target_chunk += start_sample / samples;
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2898 chunk_samples = start_sample % samples;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2899
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2900 if (start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2901 data->pos = (u_char *) entry;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2902
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2903 trak->sample_to_chunk_entries = entries;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2904 trak->start_chunk = target_chunk;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2905 trak->start_chunk_samples = chunk_samples;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2906
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2907 ngx_mp4_set_32value(entry->chunk, trak->start_chunk + 1);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2908
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2909 samples -= chunk_samples;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2910
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2911 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2912 "start_chunk:%ui, start_chunk_samples:%ui",
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2913 trak->start_chunk, trak->start_chunk_samples);
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2914
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2915 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2916 if (start_sample) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2917 data->last = (u_char *) (entry + 1);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2918 trak->sample_to_chunk_entries -= entries - 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2919 trak->end_chunk_samples = samples;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2920
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2921 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2922 data->last = (u_char *) entry;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2923 trak->sample_to_chunk_entries -= entries;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2924 trak->end_chunk_samples = prev_samples;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2925 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2926
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2927 if (chunk_samples) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2928 trak->end_chunk = target_chunk + 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2929 trak->end_chunk_samples = chunk_samples;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2930
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2931 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2932 trak->end_chunk = target_chunk;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2933 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2934
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2935 samples = chunk_samples;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2936 next_chunk = chunk + 1;
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2937
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2938 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2939 "end_chunk:%ui, end_chunk_samples:%ui",
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
2940 trak->end_chunk, trak->end_chunk_samples);
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2941 }
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2942
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2943 if (chunk_samples && next_chunk - target_chunk == 2) {
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2944
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2945 ngx_mp4_set_32value(entry->samples, samples);
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2946
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2947 } else if (chunk_samples && start) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2948
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2949 first = &trak->stsc_start_chunk_entry;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2950 ngx_mp4_set_32value(first->chunk, 1);
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2951 ngx_mp4_set_32value(first->samples, samples);
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2952 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
2953
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2954 buf = &trak->stsc_start_chunk_buf;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2955 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
2956 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
2957 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
2958
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2959 trak->out[NGX_HTTP_MP4_STSC_START].buf = buf;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2960
5619
517b5b599e3f Mp4: moved atom cropping code out of update functions.
Roman Arutyunyan <arut@nginx.com>
parents: 5578
diff changeset
2961 ngx_mp4_set_32value(entry->chunk, trak->start_chunk + 2);
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2962
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2963 trak->sample_to_chunk_entries++;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2964
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2965 } else if (chunk_samples) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2966
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2967 first = &trak->stsc_end_chunk_entry;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2968 ngx_mp4_set_32value(first->chunk, trak->end_chunk - trak->start_chunk);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2969 ngx_mp4_set_32value(first->samples, samples);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2970 ngx_mp4_set_32value(first->id, id);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2971
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2972 buf = &trak->stsc_end_chunk_buf;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2973 buf->temporary = 1;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2974 buf->pos = (u_char *) first;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2975 buf->last = (u_char *) first + sizeof(ngx_mp4_stsc_entry_t);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2976
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2977 trak->out[NGX_HTTP_MP4_STSC_END].buf = buf;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2978
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
2979 trak->sample_to_chunk_entries++;
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2980 }
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
2981
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2982 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2983 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2984
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2985
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2986 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2987 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2988 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2989 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2990 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2991 u_char uniform_size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2992 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2993 } ngx_mp4_stsz_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2994
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2995
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2996 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2997 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
2998 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2999 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3000 size_t atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3001 uint32_t entries, size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3002 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3003 ngx_mp4_stsz_atom_t *stsz_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3004 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3005
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3006 /* sample sizes atom */
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 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
3009
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3010 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3011 stsz_atom = (ngx_mp4_stsz_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3012 ngx_mp4_set_atom_name(stsz_atom, 's', 't', 's', 'z');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3013
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3014 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
3015 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3016 "\"%s\" mp4 stsz atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3017 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3018 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3019
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3020 size = ngx_mp4_get_32value(stsz_atom->uniform_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3021 entries = ngx_mp4_get_32value(stsz_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3022
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3023 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3024 "sample uniform size:%uD, entries:%uD", size, entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3025
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3026 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3027 trak->sample_sizes_entries = entries;
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 atom_table = atom_header + sizeof(ngx_mp4_stsz_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3030
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3031 atom = &trak->stsz_atom_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3032 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3033 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3034 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3035
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3036 trak->out[NGX_HTTP_MP4_STSZ_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3037
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3038 if (size == 0) {
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3039 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
3040 + entries * sizeof(uint32_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3041 {
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3042 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
3043 "\"%s\" mp4 stsz atom too small",
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3044 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3045 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3046 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3047
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3048 atom_end = atom_table + entries * sizeof(uint32_t);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3049
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3050 data = &trak->stsz_data_buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3051 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3052 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3053 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3054
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3055 trak->out[NGX_HTTP_MP4_STSZ_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3056
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3057 } else {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3058 /* 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
3059 /* TODO : chunk samples */
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3060 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
3061 ngx_mp4_set_32value(atom_header, atom_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3062 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3063 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3064
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3065 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3066
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3067 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3068 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3069
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3070
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3071 static ngx_int_t
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3072 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
3073 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3074 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3075 size_t atom_size;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3076 uint32_t *pos, *end, entries;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3077 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3078 ngx_mp4_stsz_atom_t *stsz_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3079
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3080 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3081 * mdia.minf.stbl.stsz updating requires trak->start_sample
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3082 * 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
3083 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3084 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3086 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3087 "mp4 stsz atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3088
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3089 data = trak->out[NGX_HTTP_MP4_STSZ_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3090
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3091 if (data) {
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3092 entries = trak->sample_sizes_entries;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3093
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3094 if (trak->start_sample > entries) {
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3095 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3096 "start time is out mp4 stsz samples in \"%s\"",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3097 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3098 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3099 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3100
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3101 entries -= trak->start_sample;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3102 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
3103 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
3104
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3105 for (pos = end - trak->start_chunk_samples; pos < end; pos++) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3106 trak->start_chunk_samples_size += ngx_mp4_get_32value(pos);
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
3107 }
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
3108
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
3109 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3110 "chunk samples sizes:%uL",
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3111 trak->start_chunk_samples_size);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3112
7629
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3113 if (trak->start_chunk_samples_size > (uint64_t) mp4->end) {
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3114 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3115 "too large mp4 start samples size in \"%s\"",
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3116 mp4->file.name.data);
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3117 return NGX_ERROR;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3118 }
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3119
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3120 if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3121 if (trak->end_sample - trak->start_sample > entries) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3122 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3123 "end time is out mp4 stsz samples in \"%s\"",
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3124 mp4->file.name.data);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3125 return NGX_ERROR;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3126 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3127
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3128 entries = trak->end_sample - trak->start_sample;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3129 data->last = data->pos + entries * sizeof(uint32_t);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3130 end = (uint32_t *) data->last;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3131
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3132 for (pos = end - trak->end_chunk_samples; pos < end; pos++) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3133 trak->end_chunk_samples_size += ngx_mp4_get_32value(pos);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3134 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3135
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3136 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3137 "mp4 stsz end_chunk_samples_size:%uL",
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3138 trak->end_chunk_samples_size);
7629
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3139
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3140 if (trak->end_chunk_samples_size > (uint64_t) mp4->end) {
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3141 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3142 "too large mp4 end samples size in \"%s\"",
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3143 mp4->file.name.data);
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3144 return NGX_ERROR;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3145 }
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3146 }
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
3147
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3148 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
3149 trak->size += atom_size;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3150
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3151 atom = trak->out[NGX_HTTP_MP4_STSZ_ATOM].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3152 stsz_atom = (ngx_mp4_stsz_atom_t *) atom->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3153
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3154 ngx_mp4_set_32value(stsz_atom->size, atom_size);
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3155 ngx_mp4_set_32value(stsz_atom->entries, entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3156 }
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3157
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3158 return NGX_OK;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3159 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3160
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3161
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3162 typedef struct {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3163 u_char size[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3164 u_char name[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3165 u_char version[1];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3166 u_char flags[3];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3167 u_char entries[4];
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3168 } ngx_mp4_stco_atom_t;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3169
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3170
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3171 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3172 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
3173 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3174 u_char *atom_header, *atom_table, *atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3175 uint32_t entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3176 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3177 ngx_mp4_stco_atom_t *stco_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3178 ngx_http_mp4_trak_t *trak;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3179
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3180 /* chunk offsets atom */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3181
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3182 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
3183
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3184 atom_header = ngx_mp4_atom_header(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3185 stco_atom = (ngx_mp4_stco_atom_t *) atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3186 ngx_mp4_set_atom_name(stco_atom, 's', 't', 'c', 'o');
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3187
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3188 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
3189 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3190 "\"%s\" mp4 stco atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3191 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3192 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3193
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3194 entries = ngx_mp4_get_32value(stco_atom->entries);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3195
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3196 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
3197
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3198 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
3199 + entries * sizeof(uint32_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3200 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3201 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3202 "\"%s\" mp4 stco atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3203 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3204 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3205
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3206 atom_table = atom_header + sizeof(ngx_mp4_stco_atom_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3207 atom_end = atom_table + entries * sizeof(uint32_t);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3208
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3209 trak = ngx_mp4_last_trak(mp4);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3210 trak->chunks = entries;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3211
4107
7705911c9d10 Fix of struct field name.
Igor Sysoev <igor@sysoev.ru>
parents: 4106
diff changeset
3212 atom = &trak->stco_atom_buf;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3213 atom->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3214 atom->pos = atom_header;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3215 atom->last = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3216
4107
7705911c9d10 Fix of struct field name.
Igor Sysoev <igor@sysoev.ru>
parents: 4106
diff changeset
3217 data = &trak->stco_data_buf;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3218 data->temporary = 1;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3219 data->pos = atom_table;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3220 data->last = atom_end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3221
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3222 trak->out[NGX_HTTP_MP4_STCO_ATOM].buf = atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3223 trak->out[NGX_HTTP_MP4_STCO_DATA].buf = data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3224
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3225 ngx_mp4_atom_next(mp4, atom_data_size);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3226
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3227 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3228 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3229
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3230
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3231 static ngx_int_t
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3232 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
3233 ngx_http_mp4_trak_t *trak)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3234 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3235 size_t atom_size;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3236 uint32_t entries;
7629
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3237 uint64_t chunk_offset, samples_size;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3238 ngx_buf_t *atom, *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3239 ngx_mp4_stco_atom_t *stco_atom;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3240
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3241 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3242 * mdia.minf.stbl.stco updating requires trak->start_chunk
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3243 * 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
3244 * atom which may reside after mdia.minf
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3245 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3246
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3247 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3248 "mp4 stco atom update");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3249
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3250 data = trak->out[NGX_HTTP_MP4_STCO_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3251
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3252 if (data == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3253 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3254 "no mp4 stco atoms were found in \"%s\"",
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3255 mp4->file.name.data);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3256 return NGX_ERROR;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3257 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3258
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3259 if (trak->start_chunk > trak->chunks) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3260 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3261 "start time is out mp4 stco chunks in \"%s\"",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3262 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3263 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3264 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3265
4098
a3e07fab98a3 Fix of case when start sample does not reside on chunk boundary.
Igor Sysoev <igor@sysoev.ru>
parents: 4096
diff changeset
3266 data->pos += trak->start_chunk * sizeof(uint32_t);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3267
7629
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3268 chunk_offset = ngx_mp4_get_32value(data->pos);
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3269 samples_size = trak->start_chunk_samples_size;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3270
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3271 if (chunk_offset > (uint64_t) mp4->end - samples_size
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3272 || chunk_offset + samples_size > NGX_MAX_UINT32_VALUE)
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3273 {
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3274 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3275 "too large chunk offset in \"%s\"",
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3276 mp4->file.name.data);
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3277 return NGX_ERROR;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3278 }
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3279
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3280 trak->start_offset = chunk_offset + 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
3281 ngx_mp4_set_32value(data->pos, trak->start_offset);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3282
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3283 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
3284 "start chunk offset:%O", trak->start_offset);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3285
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3286 if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3287
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3288 if (trak->end_chunk > trak->chunks) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3289 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3290 "end time is out mp4 stco chunks in \"%s\"",
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3291 mp4->file.name.data);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3292 return NGX_ERROR;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3293 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3294
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3295 entries = trak->end_chunk - trak->start_chunk;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3296 data->last = data->pos + entries * sizeof(uint32_t);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3297
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3298 if (entries) {
7629
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3299 chunk_offset = ngx_mp4_get_32value(data->last - sizeof(uint32_t));
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3300 samples_size = trak->end_chunk_samples_size;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3301
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3302 if (chunk_offset > (uint64_t) mp4->end - samples_size
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3303 || chunk_offset + samples_size > NGX_MAX_UINT32_VALUE)
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3304 {
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3305 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3306 "too large chunk offset in \"%s\"",
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3307 mp4->file.name.data);
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3308 return NGX_ERROR;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3309 }
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3310
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3311 trak->end_offset = chunk_offset + samples_size;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3312
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3313 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3314 "end chunk offset:%O", trak->end_offset);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3315 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3316
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3317 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3318 entries = trak->chunks - trak->start_chunk;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3319 trak->end_offset = mp4->mdat_data.buf->file_last;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3320 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3321
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3322 if (entries == 0) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3323 trak->start_offset = mp4->end;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3324 trak->end_offset = 0;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3325 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3326
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3327 atom_size = sizeof(ngx_mp4_stco_atom_t) + (data->last - data->pos);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3328 trak->size += atom_size;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3329
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3330 atom = trak->out[NGX_HTTP_MP4_STCO_ATOM].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3331 stco_atom = (ngx_mp4_stco_atom_t *) atom->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3332
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3333 ngx_mp4_set_32value(stco_atom->size, atom_size);
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3334 ngx_mp4_set_32value(stco_atom->entries, entries);
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3335
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3336 return NGX_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3337 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3338
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3339
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3340 static void
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3341 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
3342 ngx_http_mp4_trak_t *trak, int32_t adjustment)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3343 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3344 uint32_t offset, *entry, *end;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3345 ngx_buf_t *data;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3346
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3347 /*
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3348 * moov.trak.mdia.minf.stbl.stco adjustment requires
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3349 * minimal start offset of all traks and new moov atom size
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3350 */
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3351
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3352 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3353 "mp4 stco atom adjustment");
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3354
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3355 data = trak->out[NGX_HTTP_MP4_STCO_DATA].buf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3356 entry = (uint32_t *) data->pos;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3357 end = (uint32_t *) data->last;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3358
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3359 while (entry < end) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3360 offset = ngx_mp4_get_32value(entry);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3361 offset += adjustment;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3362 ngx_mp4_set_32value(entry, offset);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3363 entry++;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3364 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3365 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3366
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3367
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3368 typedef struct {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3369 u_char size[4];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3370 u_char name[4];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3371 u_char version[1];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3372 u_char flags[3];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3373 u_char entries[4];
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3374 } ngx_mp4_co64_atom_t;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3375
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3376
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3377 static ngx_int_t
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3378 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
3379 {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3380 u_char *atom_header, *atom_table, *atom_end;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3381 uint32_t entries;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3382 ngx_buf_t *atom, *data;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3383 ngx_mp4_co64_atom_t *co64_atom;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3384 ngx_http_mp4_trak_t *trak;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3385
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3386 /* chunk offsets atom */
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3387
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3388 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
3389
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3390 atom_header = ngx_mp4_atom_header(mp4);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3391 co64_atom = (ngx_mp4_co64_atom_t *) atom_header;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3392 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
3393
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3394 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
3395 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3396 "\"%s\" mp4 co64 atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3397 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3398 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3399
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3400 entries = ngx_mp4_get_32value(co64_atom->entries);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3401
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3402 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
3403
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3404 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
3405 + entries * sizeof(uint64_t) > atom_data_size)
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3406 {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3407 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3408 "\"%s\" mp4 co64 atom too small", mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3409 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3410 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3411
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3412 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
3413 atom_end = atom_table + entries * sizeof(uint64_t);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3414
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3415 trak = ngx_mp4_last_trak(mp4);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3416 trak->chunks = entries;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3417
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3418 atom = &trak->co64_atom_buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3419 atom->temporary = 1;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3420 atom->pos = atom_header;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3421 atom->last = atom_table;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3422
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3423 data = &trak->co64_data_buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3424 data->temporary = 1;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3425 data->pos = atom_table;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3426 data->last = atom_end;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3427
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3428 trak->out[NGX_HTTP_MP4_CO64_ATOM].buf = atom;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3429 trak->out[NGX_HTTP_MP4_CO64_DATA].buf = data;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3430
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3431 ngx_mp4_atom_next(mp4, atom_data_size);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3432
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3433 return NGX_OK;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3434 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3435
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3436
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3437 static ngx_int_t
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3438 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
3439 ngx_http_mp4_trak_t *trak)
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3440 {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3441 size_t atom_size;
7629
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3442 uint64_t entries, chunk_offset, samples_size;
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3443 ngx_buf_t *atom, *data;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3444 ngx_mp4_co64_atom_t *co64_atom;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3445
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3446 /*
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3447 * mdia.minf.stbl.co64 updating requires trak->start_chunk
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3448 * 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
3449 * atom which may reside after mdia.minf
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3450 */
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3451
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3452 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
3453 "mp4 co64 atom update");
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3454
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3455 data = trak->out[NGX_HTTP_MP4_CO64_DATA].buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3456
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3457 if (data == NULL) {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3458 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
3459 "no mp4 co64 atoms were found in \"%s\"",
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3460 mp4->file.name.data);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3461 return NGX_ERROR;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3462 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3463
4585
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3464 if (trak->start_chunk > trak->chunks) {
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3465 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3466 "start time is out mp4 co64 chunks in \"%s\"",
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3467 mp4->file.name.data);
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3468 return NGX_ERROR;
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3469 }
3f874d645f45 Mp4: sanity checks cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4579
diff changeset
3470
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3471 data->pos += trak->start_chunk * sizeof(uint64_t);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3472
7629
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3473 chunk_offset = ngx_mp4_get_64value(data->pos);
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3474 samples_size = trak->start_chunk_samples_size;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3475
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3476 if (chunk_offset > (uint64_t) mp4->end - samples_size) {
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3477 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3478 "too large chunk offset in \"%s\"",
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3479 mp4->file.name.data);
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3480 return NGX_ERROR;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3481 }
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3482
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3483 trak->start_offset = chunk_offset + samples_size;
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3484 ngx_mp4_set_64value(data->pos, trak->start_offset);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3485
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3486 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
5630
02584b335727 Mp4: improved logging after adding "end" support.
Roman Arutyunyan <arut@nginx.com>
parents: 5629
diff changeset
3487 "start chunk offset:%O", trak->start_offset);
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3488
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3489 if (mp4->length) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3490
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3491 if (trak->end_chunk > trak->chunks) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3492 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3493 "end time is out mp4 co64 chunks in \"%s\"",
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3494 mp4->file.name.data);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3495 return NGX_ERROR;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3496 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3497
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3498 entries = trak->end_chunk - trak->start_chunk;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3499 data->last = data->pos + entries * sizeof(uint64_t);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3500
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3501 if (entries) {
7629
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3502 chunk_offset = ngx_mp4_get_64value(data->last - sizeof(uint64_t));
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3503 samples_size = trak->end_chunk_samples_size;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3504
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3505 if (chunk_offset > (uint64_t) mp4->end - samples_size) {
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3506 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3507 "too large chunk offset in \"%s\"",
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3508 mp4->file.name.data);
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3509 return NGX_ERROR;
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3510 }
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3511
f47f7d3d1bfa Mp4: fixed possible chunk offset overflow.
Roman Arutyunyan <arut@nginx.com>
parents: 7400
diff changeset
3512 trak->end_offset = chunk_offset + samples_size;
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3513
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3514 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3515 "end chunk offset:%O", trak->end_offset);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3516 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3517
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3518 } else {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3519 entries = trak->chunks - trak->start_chunk;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3520 trak->end_offset = mp4->mdat_data.buf->file_last;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3521 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3522
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3523 if (entries == 0) {
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3524 trak->start_offset = mp4->end;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3525 trak->end_offset = 0;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3526 }
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3527
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3528 atom_size = sizeof(ngx_mp4_co64_atom_t) + (data->last - data->pos);
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3529 trak->size += atom_size;
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3530
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3531 atom = trak->out[NGX_HTTP_MP4_CO64_ATOM].buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3532 co64_atom = (ngx_mp4_co64_atom_t *) atom->pos;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3533
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3534 ngx_mp4_set_32value(co64_atom->size, atom_size);
5620
0a567878254b Mp4: added "end" argument support.
Roman Arutyunyan <arut@nginx.com>
parents: 5619
diff changeset
3535 ngx_mp4_set_32value(co64_atom->entries, entries);
4112
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3536
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3537 return NGX_OK;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3538 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3539
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3540
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3541 static void
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3542 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
3543 ngx_http_mp4_trak_t *trak, off_t adjustment)
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3544 {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3545 uint64_t offset, *entry, *end;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3546 ngx_buf_t *data;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3547
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3548 /*
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3549 * moov.trak.mdia.minf.stbl.co64 adjustment requires
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3550 * 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
3551 */
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3552
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3553 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
3554 "mp4 co64 atom adjustment");
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3555
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3556 data = trak->out[NGX_HTTP_MP4_CO64_DATA].buf;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3557 entry = (uint64_t *) data->pos;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3558 end = (uint64_t *) data->last;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3559
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3560 while (entry < end) {
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3561 offset = ngx_mp4_get_64value(entry);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3562 offset += adjustment;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3563 ngx_mp4_set_64value(entry, offset);
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3564 entry++;
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3565 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3566 }
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3567
bc0ca958c270 MP4 co64 atom support added.
Igor Sysoev <igor@sysoev.ru>
parents: 4107
diff changeset
3568
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3569 static char *
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3570 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
3571 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3572 ngx_http_core_loc_conf_t *clcf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3573
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3574 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
3575 clcf->handler = ngx_http_mp4_handler;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3576
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3577 return NGX_CONF_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3578 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3579
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3580
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3581 static void *
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3582 ngx_http_mp4_create_conf(ngx_conf_t *cf)
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3583 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3584 ngx_http_mp4_conf_t *conf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3585
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3586 conf = ngx_palloc(cf->pool, sizeof(ngx_http_mp4_conf_t));
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3587 if (conf == NULL) {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3588 return NULL;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3589 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3590
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3591 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
3592 conf->max_buffer_size = NGX_CONF_UNSET_SIZE;
4085
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3593
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3594 return conf;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3595 }
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3596
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3597
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3598 static char *
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3599 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
3600 {
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3601 ngx_http_mp4_conf_t *prev = parent;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3602 ngx_http_mp4_conf_t *conf = child;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3603
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3604 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
3605 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
3606 10 * 1024 * 1024);
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3607
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3608 return NGX_CONF_OK;
6492c79e943a ngx_http_mp4_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3609 }