]> git.sesse.net Git - vlc/blob - modules/demux/mp4/mp4.h
demux: mp4: add minimal support for exclusive tracks
[vlc] / modules / demux / mp4 / mp4.h
1 /*****************************************************************************
2  * mp4.h : MP4 file input module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001-2004, 2010, 2014 VLC authors and VideoLAN
5  *
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation; either version 2.1 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20  *****************************************************************************/
21 #ifndef _VLC_MP4_H
22 #define _VLC_MP4_H 1
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include "libmp4.h"
34 #include "../asf/asfpacket.h"
35
36 /* Contain all information about a chunk */
37 typedef struct
38 {
39     uint64_t     i_offset; /* absolute position of this chunk in the file */
40     uint32_t     i_sample_description_index; /* index for SampleEntry to use */
41     uint32_t     i_sample_count; /* how many samples in this chunk */
42     uint32_t     i_sample_first; /* index of the first sample in this chunk */
43     uint32_t     i_sample; /* index of the next sample to read in this chunk */
44
45     /* now provide way to calculate pts, dts, and offset without too
46         much memory and with fast access */
47
48     /* with this we can calculate dts/pts without waste memory */
49     uint64_t     i_first_dts;   /* DTS of the first sample */
50     uint64_t     i_last_dts;    /* DTS of the last sample */
51     uint32_t     *p_sample_count_dts;
52     uint32_t     *p_sample_delta_dts;   /* dts delta */
53
54     uint32_t     *p_sample_count_pts;
55     int32_t      *p_sample_offset_pts;  /* pts-dts */
56
57     uint8_t      **p_sample_data;     /* set when b_fragmented is true */
58     uint32_t     *p_sample_size;
59     /* TODO if needed add pts
60         but quickly *add* support for edts and seeking */
61
62 } mp4_chunk_t;
63
64  /* Contain all needed information for read all track with vlc */
65 typedef struct
66 {
67     unsigned int i_track_ID;/* this should be unique */
68
69     int b_ok;               /* The track is usable */
70     int b_enable;           /* is the trak enable by default */
71     bool b_selected;  /* is the trak being played */
72     bool b_chapter;   /* True when used for chapter only */
73     uint32_t i_switch_group;
74
75     bool b_mac_encoding;
76
77     es_format_t fmt;
78     uint8_t     rgi_chans_reordering[AOUT_CHAN_MAX];
79     bool        b_chans_reorder;
80     es_out_id_t *p_es;
81
82     /* display size only ! */
83     int i_width;
84     int i_height;
85     float f_rotation;
86
87     /* more internal data */
88     uint32_t        i_timescale;    /* time scale for this track only */
89     uint16_t        current_qid;    /* Smooth Streaming quality level ID */
90
91     /* elst */
92     int             i_elst;         /* current elst */
93     int64_t         i_elst_time;    /* current elst start time (in movie time scale)*/
94     MP4_Box_t       *p_elst;        /* elst (could be NULL) */
95
96     /* give the next sample to read, i_chunk is to find quickly where
97       the sample is located */
98     uint32_t         i_sample;       /* next sample to read */
99     uint32_t         i_chunk;        /* chunk where next sample is stored */
100     /* total count of chunk and sample */
101     uint32_t         i_chunk_count;
102     uint32_t         i_sample_count;
103
104     mp4_chunk_t    *chunk; /* always defined  for each chunk */
105     mp4_chunk_t    *cchunk; /* current chunk if b_fragmented is true */
106
107     /* sample size, p_sample_size defined only if i_sample_size == 0
108         else i_sample_size is size for all sample */
109     uint32_t         i_sample_size;
110     uint32_t         *p_sample_size; /* XXX perhaps add file offset if take
111                                     too much time to do sumations each time*/
112
113     uint32_t     i_sample_first; /* i_sample_first value
114                                                    of the next chunk */
115     uint64_t     i_first_dts;    /* i_first_dts value
116                                                    of the next chunk */
117
118     MP4_Box_t *p_stbl;  /* will contain all timing information */
119     MP4_Box_t *p_stsd;  /* will contain all data to initialize decoder */
120     MP4_Box_t *p_sample;/* point on actual sdsd */
121
122     bool b_drms;
123     bool b_has_non_empty_cchunk;
124     bool b_codec_need_restart;
125     void      *p_drms;
126     MP4_Box_t *p_skcr;
127
128     mtime_t i_time;
129
130     struct
131     {
132         /* for moof parsing */
133         MP4_Box_t *p_traf;
134         MP4_Box_t *p_tfhd;
135         MP4_Box_t *p_trun;
136         uint64_t   i_traf_base_offset;
137     } context;
138
139     /* ASF packets handling */
140     MP4_Box_t       *p_asf;
141     mtime_t          i_dts_backup;
142     mtime_t          i_pts_backup;
143     asf_track_info_t asfinfo;
144 } mp4_track_t;
145
146 typedef struct mp4_fragment_t mp4_fragment_t;
147 struct mp4_fragment_t
148 {
149     uint64_t i_chunk_range_min_offset;
150     uint64_t i_chunk_range_max_offset;
151     uint64_t i_duration;
152     MP4_Box_t *p_moox;
153     mp4_fragment_t *p_next;
154 };
155
156 int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample );
157 int SetupAudioES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample );
158 int SetupSpuES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample );
159 void SetupMeta( vlc_meta_t *p_meta, MP4_Box_t *p_udta );
160 #endif