Debian Codegraph @

include/mp4.h

raw symbols SCIP
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 */
16
17 #define MP4_BLOCK_SIZE 4096
18
19 #define FOURCC_EQ(a, b) ((a)[0] == (b)[0] && (a)[1] == (b)[1] && (a)[2] && (b)[2] && (a)[3] == (b)[3])
20
21 typedef enum {
22 AAC_INVALID = 0,
23 AAC_MAIN = 1, /* AAC Main */
24 AAC_LC = 2, /* AAC Low complexity */
25 AAC_SSR = 3, /* AAC SSR */
26 AAC_LTP = 4, /* AAC Long term prediction */
27 AAC_HE = 5, /* AAC High efficiency (SBR) */
28 AAC_SCALE = 6, /* Scalable */
29 AAC_TWINVQ = 7, /* TwinVQ */
30 AAC_CELP = 8, /* CELP */
31 AAC_HVXC = 9, /* HVXC */
32 AAC_TTSI = 12, /* TTSI */
33 AAC_MS = 13, /* Main synthetic */
34 AAC_WAVE = 14, /* Wavetable synthesis */
35 AAC_MIDI = 15, /* General MIDI */
36 AAC_FX = 16, /* Algorithmic Synthesis and Audio FX */
37 AAC_LC_ER = 17, /* AAC Low complexity with error recovery */
38 AAC_LTP_ER = 19, /* AAC Long term prediction with error recovery */
39 AAC_SCALE_ER = 20, /* AAC scalable with error recovery */
40 AAC_TWINVQ_ER = 21, /* TwinVQ with error recovery */
41 AAC_BSAC_ER = 22, /* BSAC with error recovery */
42 AAC_LD_ER = 23, /* AAC LD with error recovery */
43 AAC_CELP_ER = 24, /* CELP with error recovery */
44 AAC_HXVC_ER = 25, /* HXVC with error recovery */
45 AAC_HILN_ER = 26, /* HILN with error recovery */
46 AAC_PARAM_ER = 27, /* Parametric with error recovery */
47 AAC_SSC = 28, /* AAC SSC */
48 AAC_PS = 29, /* Parametric Stereo */
49 AAC_ESCAPE = 31, /* Escape */
50 AAC_SLS = 37, /* Scalable Lossless */
51 } aac_object_type;
52
53 const uint32_t samplerate_table[16] = {
54 96000, 88200, 64000, 48000, 44100, 32000, 24000,
55 22050, 16000, 12000, 11025, 8000, 7350, -1, -1, 0
56 };
57
58 const uint8_t bps_table[4] = {
59 8, 16, 20, 24
60 };
61
62 typedef struct tts {
63 uint32_t sample_count;
64 uint32_t sample_duration;
65 } tts;
66
67 typedef struct stc {
68 uint32_t first_chunk;
69 uint32_t samples_per_chunk;
70 } stc;
71
72 typedef struct mp4info {
73 PerlIO *infile;
74 char *file;
75 Buffer *buf;
76 uint64_t file_size; // total file size
77 uint64_t size; // total size of box; 0 => remainder of file
78 uint8_t hsize; // header size in box
79 uint64_t rsize; // remaining size in box outside header
80 uint64_t audio_offset;
81 uint64_t audio_size;
82 HV *info;
83 HV *tags;
84 uint32_t current_track;
85 uint32_t track_count;
86 uint8_t seen_moov;
87 uint8_t dlna_invalid;
88
89 // Things needed for DLNA detection
90 uint8_t audio_object_type;
91 uint16_t channels;
92 uint32_t samplerate;
93 uint32_t bitrate;
94
95 // Data structures used to support seeking
96 // Based on code from Rockbox
97
98 uint8_t seeking; // flag if we're seeking
99 uint32_t old_st_size; // size of original st* boxes
100 uint32_t new_st_size; // size of rewritten st* boxes
101 uint32_t meta_size; // size of variable meta box
102 SV *seekhdr; // rewritten header during second seek pass
103
104 // stsc
105 uint32_t num_sample_to_chunks;
106 struct stc *sample_to_chunk;
107 SV *new_stsc;
108
109 // stco
110 uint32_t *chunk_offset;
111 uint32_t num_chunk_offsets;
112 SV *new_stco;
113
114 // stts
115 struct tts *time_to_sample;
116 uint32_t num_time_to_samples;
117 SV *new_stts;
118
119 // stsz
120 uint16_t *sample_byte_size;
121 uint32_t num_sample_byte_sizes;
122 SV *new_stsz;
123 } mp4info;
124
125 static int get_mp4tags(PerlIO *infile, char *file, HV *info, HV *tags);
126 off_t mp4_find_frame(PerlIO *infile, char *file, int offset);
127 int mp4_find_frame_return_info(PerlIO *infile, char *file, int offset, HV *info);
128
129 mp4info * _mp4_parse(PerlIO *infile, char *file, HV *info, HV *tags, uint8_t seeking);
130 int _mp4_read_box(mp4info *mp4);
131 uint8_t _mp4_parse_ftyp(mp4info *mp4);
132 uint8_t _mp4_parse_mvhd(mp4info *mp4);
133 uint8_t _mp4_parse_tkhd(mp4info *mp4);
134 uint8_t _mp4_parse_mdhd(mp4info *mp4);
135 uint8_t _mp4_parse_hdlr(mp4info *mp4);
136 uint8_t _mp4_parse_stsd(mp4info *mp4);
137 uint8_t _mp4_parse_mp4a(mp4info *mp4);
138 uint8_t _mp4_parse_esds(mp4info *mp4);
139 uint8_t _mp4_parse_alac(mp4info *mp4);
140 uint8_t _mp4_parse_stts(mp4info *mp4);
141 uint8_t _mp4_parse_stsc(mp4info *mp4);
142 uint8_t _mp4_parse_stsz(mp4info *mp4);
143 uint8_t _mp4_parse_stco(mp4info *mp4);
144 uint8_t _mp4_parse_meta(mp4info *mp4);
145 uint8_t _mp4_parse_ilst(mp4info *mp4);
146 uint8_t _mp4_parse_ilst_data(mp4info *mp4, uint32_t size, SV *key);
147 uint8_t _mp4_parse_ilst_custom(mp4info *mp4, uint32_t size);
148 HV * _mp4_get_current_trackinfo(mp4info *mp4);
149 uint32_t _mp4_descr_length(Buffer *buf);
150 void _mp4_skip(mp4info *mp4, uint32_t size);
151 uint32_t _mp4_samples_in_chunk(mp4info *mp4, uint32_t chunk);
152 uint32_t _mp4_total_samples(mp4info *mp4);
153 uint32_t _mp4_get_sample_duration(mp4info *mp4, uint32_t sample);