]> git.sesse.net Git - vlc/blob - modules/demux/ogg.h
mediacodec: don't loop in GetOutput
[vlc] / modules / demux / ogg.h
1 /*****************************************************************************
2  * ogg.h : ogg stream demux module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001-2010 VLC authors and VideoLAN
5  *
6  * Authors: Gildas Bazin <gbazin@netcourrier.com>
7  *          Andre Pang <Andre.Pang@csiro.au> (Annodex support)
8  *          Gabriel Finch <salsaman@gmail.com> (moved from ogg.c to ogg.h)
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #ifdef HAVE_LIBVORBIS
30   #include <vorbis/codec.h>
31 #endif
32
33 /*****************************************************************************
34  * Definitions of structures and functions used by this plugin
35  *****************************************************************************/
36
37 //#define OGG_DEMUX_DEBUG 1
38 #ifdef OGG_DEMUX_DEBUG
39   #define DemuxDebug(code) code
40 #else
41   #define DemuxDebug(code)
42 #endif
43
44 /* Some defines from OggDS http://svn.xiph.org/trunk/oggds/ */
45 #define PACKET_TYPE_HEADER   0x01
46 #define PACKET_TYPE_BITS     0x07
47 #define PACKET_LEN_BITS01    0xc0
48 #define PACKET_LEN_BITS2     0x02
49 #define PACKET_IS_SYNCPOINT  0x08
50
51 typedef struct oggseek_index_entry demux_index_entry_t;
52 typedef struct ogg_skeleton_t ogg_skeleton_t;
53
54 typedef struct backup_queue
55 {
56     block_t *p_block;
57     mtime_t i_duration;
58 } backup_queue_t;
59
60 typedef struct logical_stream_s
61 {
62     ogg_stream_state os;                        /* logical stream of packets */
63
64     es_format_t      fmt;
65     es_format_t      fmt_old;                  /* format of old ES is reused */
66     es_out_id_t      *p_es;
67     double           f_rate;
68
69     int              i_serial_no;
70
71     /* the header of some logical streams (eg vorbis) contain essential
72      * data for the decoder. We back them up here in case we need to re-feed
73      * them to the decoder. */
74     bool             b_force_backup;
75     int              i_packets_backup;
76     int32_t          i_extra_headers_packets;
77     void             *p_headers;
78     int              i_headers;
79     ogg_int64_t      i_previous_granulepos;
80     ogg_int64_t      i_granulepos_offset;/* first granule offset */
81
82     /* program clock reference (in units of 90kHz) derived from the previous
83      * granulepos */
84     mtime_t          i_pcr;
85     mtime_t          i_previous_pcr;
86
87     /* Misc */
88     bool b_initializing;
89     bool b_finished;
90     bool b_reinit;
91     bool b_oggds;
92     int i_granule_shift;
93
94     /* Opus has a starting offset in the headers. */
95     int i_pre_skip;
96     /* Vorbis and Opus can trim the end of a stream using granule positions. */
97     int i_end_trim;
98
99     /* offset of first keyframe for theora; can be 0 or 1 depending on version number */
100     int8_t i_keyframe_offset;
101
102     /* keyframe index for seeking, created as we discover keyframes */
103     demux_index_entry_t *idx;
104
105     /* Skeleton data */
106     ogg_skeleton_t *p_skel;
107
108     /* skip some frames after a seek */
109     unsigned int i_skip_frames;
110
111     /* data start offset (absolute) in bytes */
112     int64_t i_data_start;
113
114     /* for Annodex logical bitstreams */
115     int i_secondary_header_packets;
116
117     /* All blocks which can't be sent because track PCR isn't known yet */
118     struct
119     {
120         block_t **pp_blocks;
121         uint8_t i_size; /* max 255 */
122         uint8_t i_used;
123     } prepcr;
124     /* All blocks that are queued because ES isn't created yet */
125     block_t *p_preparse_block;
126
127     union
128     {
129 #ifdef HAVE_LIBVORBIS
130         struct
131         {
132             vorbis_info *p_info;
133             vorbis_comment *p_comment;
134             int i_headers_flags;
135             int i_prev_blocksize;
136         } vorbis;
137 #endif
138         struct
139         {
140             /* kate streams have the number of headers in the ID header */
141             int i_num_headers;
142         } kate;
143         struct
144         {
145             bool b_interlaced;
146         } dirac;
147         struct
148         {
149             int32_t i_framesize;
150             int32_t i_framesperpacket;
151         } speex;
152     } special;
153
154 } logical_stream_t;
155
156 struct ogg_skeleton_t
157 {
158     int            i_messages;
159     char         **ppsz_messages;
160     unsigned char *p_index;
161     uint64_t       i_index;
162     uint64_t       i_index_size;
163     int64_t        i_indexstampden;/* time denominator */
164     int64_t        i_indexfirstnum;/* first sample time numerator */
165     int64_t        i_indexlastnum;
166 };
167
168 struct demux_sys_t
169 {
170     ogg_sync_state oy;        /* sync and verify incoming physical bitstream */
171
172     int i_streams;                           /* number of logical bitstreams */
173     logical_stream_t **pp_stream;  /* pointer to an array of logical streams */
174     logical_stream_t *p_skelstream; /* pointer to skeleton stream if any */
175
176     logical_stream_t *p_old_stream; /* pointer to a old logical stream to avoid recreating it */
177
178     /* program clock reference (in units of 90kHz) derived from the pcr of
179      * the sub-streams */
180     mtime_t i_pcr;
181     mtime_t i_nzpcr_offset;
182     /* informative only */
183     mtime_t i_pcr_jitter;
184     int64_t i_access_delay;
185
186     /* new stream or starting from a chain */
187     bool b_chained_boundary;
188
189     /* bitrate */
190     int     i_bitrate;
191     bool    b_partial_bitrate;
192
193     /* after reading all headers, the first data page is stuffed into the relevant stream, ready to use */
194     bool    b_page_waiting;
195
196     /* count of total frames in video stream */
197     int64_t i_total_frames;
198
199     /* length of file in bytes */
200     int64_t i_total_length;
201
202     /* offset position in file (for reading) */
203     int64_t i_input_position;
204
205     /* current page being parsed */
206     ogg_page current_page;
207
208     /* */
209     vlc_meta_t          *p_meta;
210     int                 i_seekpoints;
211     seekpoint_t         **pp_seekpoints;
212
213     /* skeleton */
214     struct
215     {
216         uint16_t major;
217         uint16_t minor;
218     } skeleton;
219
220     /* */
221     int                 i_attachments;
222     input_attachment_t  **attachments;
223
224     /* preparsing info */
225     bool b_preparsing_done;
226     bool b_es_created;
227
228     /* Length, if available. */
229     int64_t i_length;
230
231 };
232
233
234 unsigned const char * Read7BitsVariableLE( unsigned const char *,
235                                            unsigned const char *,
236                                            uint64_t * );
237 bool Ogg_GetBoundsUsingSkeletonIndex( logical_stream_t *p_stream, int64_t i_time,
238                                       int64_t *pi_lower, int64_t *pi_upper );