1 /*****************************************************************************
2 * ogg.h : ogg stream demux module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2010 VLC authors and VideoLAN
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)
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.
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.
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 *****************************************************************************/
30 #include <vorbis/codec.h>
33 /*****************************************************************************
34 * Definitions of structures and functions used by this plugin
35 *****************************************************************************/
37 //#define OGG_DEMUX_DEBUG 1
38 #ifdef OGG_DEMUX_DEBUG
39 #define DemuxDebug(code) code
41 #define DemuxDebug(code)
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
51 typedef struct oggseek_index_entry demux_index_entry_t
;
52 typedef struct ogg_skeleton_t ogg_skeleton_t
;
54 typedef struct backup_queue
60 typedef struct logical_stream_s
62 ogg_stream_state os
; /* logical stream of packets */
65 es_format_t fmt_old
; /* format of old ES is reused */
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. */
76 int32_t i_extra_headers_packets
;
79 ogg_int64_t i_previous_granulepos
;
80 ogg_int64_t i_granulepos_offset
;/* first granule offset */
82 /* program clock reference (in units of 90kHz) derived from the previous
85 mtime_t i_previous_pcr
;
94 /* Opus has a starting offset in the headers. */
96 /* Vorbis and Opus can trim the end of a stream using granule positions. */
99 /* offset of first keyframe for theora; can be 0 or 1 depending on version number */
100 int8_t i_keyframe_offset
;
102 /* keyframe index for seeking, created as we discover keyframes */
103 demux_index_entry_t
*idx
;
106 ogg_skeleton_t
*p_skel
;
108 /* skip some frames after a seek */
109 unsigned int i_skip_frames
;
111 /* data start offset (absolute) in bytes */
112 int64_t i_data_start
;
114 /* for Annodex logical bitstreams */
115 int i_secondary_header_packets
;
117 /* All blocks which can't be sent because track PCR isn't known yet */
121 uint8_t i_size
; /* max 255 */
124 /* All blocks that are queued because ES isn't created yet */
125 block_t
*p_preparse_block
;
129 #ifdef HAVE_LIBVORBIS
133 vorbis_comment
*p_comment
;
135 int i_prev_blocksize
;
140 /* kate streams have the number of headers in the ID header */
150 int32_t i_framesperpacket
;
160 struct ogg_skeleton_t
163 char **ppsz_messages
;
164 unsigned char *p_index
;
166 uint64_t i_index_size
;
167 int64_t i_indexstampden
;/* time denominator */
168 int64_t i_indexfirstnum
;/* first sample time numerator */
169 int64_t i_indexlastnum
;
174 ogg_sync_state oy
; /* sync and verify incoming physical bitstream */
176 int i_streams
; /* number of logical bitstreams */
177 logical_stream_t
**pp_stream
; /* pointer to an array of logical streams */
178 logical_stream_t
*p_skelstream
; /* pointer to skeleton stream if any */
180 logical_stream_t
*p_old_stream
; /* pointer to a old logical stream to avoid recreating it */
182 /* program clock reference (in units of 90kHz) derived from the pcr of
185 mtime_t i_nzpcr_offset
;
186 /* informative only */
187 mtime_t i_pcr_jitter
;
188 int64_t i_access_delay
;
190 /* new stream or starting from a chain */
191 bool b_chained_boundary
;
195 bool b_partial_bitrate
;
197 /* after reading all headers, the first data page is stuffed into the relevant stream, ready to use */
200 /* count of total frames in video stream */
201 int64_t i_total_frames
;
203 /* length of file in bytes */
204 int64_t i_total_length
;
206 /* offset position in file (for reading) */
207 int64_t i_input_position
;
209 /* current page being parsed */
210 ogg_page current_page
;
215 seekpoint_t
**pp_seekpoints
;
226 input_attachment_t
**attachments
;
228 /* preparsing info */
229 bool b_preparsing_done
;
232 /* Length, if available. */
240 unsigned const char * Read7BitsVariableLE( unsigned const char *,
241 unsigned const char *,
243 bool Ogg_GetBoundsUsingSkeletonIndex( logical_stream_t
*p_stream
, int64_t i_time
,
244 int64_t *pi_lower
, int64_t *pi_upper
);