ogg.h 7.1 KB
Newer Older
1 2 3
/*****************************************************************************
 * ogg.h : ogg stream demux module for vlc
 *****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2001-2010 VLC authors and VideoLAN
5 6 7 8 9
 *
 * Authors: Gildas Bazin <gbazin@netcourrier.com>
 *          Andre Pang <Andre.Pang@csiro.au> (Annodex support)
 *          Gabriel Finch <salsaman@gmail.com> (moved from ogg.c to ogg.h)
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
10 11 12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
13 14 15 16
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
20 21 22
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24
 *****************************************************************************/

25 26 27 28 29 30 31 32
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifdef HAVE_LIBVORBIS
  #include <vorbis/codec.h>
#endif

33
/*****************************************************************************
34
 * Definitions of structures and functions used by this plugin
35 36
 *****************************************************************************/

37 38 39 40 41 42 43 44 45 46 47 48 49 50
//#define OGG_DEMUX_DEBUG 1
#ifdef OGG_DEMUX_DEBUG
  #define DemuxDebug(code) code
#else
  #define DemuxDebug(code)
#endif

/* Some defines from OggDS http://svn.xiph.org/trunk/oggds/ */
#define PACKET_TYPE_HEADER   0x01
#define PACKET_TYPE_BITS     0x07
#define PACKET_LEN_BITS01    0xc0
#define PACKET_LEN_BITS2     0x02
#define PACKET_IS_SYNCPOINT  0x08

51
typedef struct oggseek_index_entry demux_index_entry_t;
52
typedef struct ogg_skeleton_t ogg_skeleton_t;
53

54 55 56 57 58 59
typedef struct backup_queue
{
    block_t *p_block;
    mtime_t i_duration;
} backup_queue_t;

60 61 62 63 64 65 66 67 68 69 70 71 72 73
typedef struct logical_stream_s
{
    ogg_stream_state os;                        /* logical stream of packets */

    es_format_t      fmt;
    es_format_t      fmt_old;                  /* format of old ES is reused */
    es_out_id_t      *p_es;
    double           f_rate;

    int              i_serial_no;

    /* the header of some logical streams (eg vorbis) contain essential
     * data for the decoder. We back them up here in case we need to re-feed
     * them to the decoder. */
74
    bool             b_force_backup;
75
    int              i_packets_backup;
76
    int32_t          i_extra_headers_packets;
77 78
    void             *p_headers;
    int              i_headers;
.'s avatar
. committed
79
    ogg_int64_t      i_previous_granulepos;
80
    ogg_int64_t      i_granulepos_offset;/* first granule offset */
81 82 83 84 85 86 87

    /* program clock reference (in units of 90kHz) derived from the previous
     * granulepos */
    mtime_t          i_pcr;
    mtime_t          i_previous_pcr;

    /* Misc */
88 89
    bool b_initializing;
    bool b_finished;
90
    bool b_reinit;
91
    bool b_oggds;
92
    int i_granule_shift;
93

94 95
    /* Opus has a starting offset in the headers. */
    int i_pre_skip;
.'s avatar
. committed
96 97
    /* Vorbis and Opus can trim the end of a stream using granule positions. */
    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 103 104
    /* keyframe index for seeking, created as we discover keyframes */
    demux_index_entry_t *idx;

105 106 107
    /* Skeleton data */
    ogg_skeleton_t *p_skel;

108
    /* skip some frames after a seek */
109
    unsigned int i_skip_frames;
110 111 112 113

    /* data start offset (absolute) in bytes */
    int64_t i_data_start;

114 115 116
    /* for Annodex logical bitstreams */
    int i_secondary_header_packets;

117
    /* All blocks which can't be sent because track PCR isn't known yet */
118 119 120 121 122 123
    struct
    {
        block_t **pp_blocks;
        uint8_t i_size; /* max 255 */
        uint8_t i_used;
    } prepcr;
124
    /* All blocks that are queued because ES isn't created yet */
125
    block_t *p_preparse_block;
126 127 128 129 130 131 132 133

    union
    {
#ifdef HAVE_LIBVORBIS
        struct
        {
            vorbis_info *p_info;
            vorbis_comment *p_comment;
134
            int i_headers_flags;
135 136 137 138 139 140 141 142 143 144 145 146
            int i_prev_blocksize;
        } vorbis;
#endif
        struct
        {
            /* kate streams have the number of headers in the ID header */
            int i_num_headers;
        } kate;
        struct
        {
            bool b_interlaced;
        } dirac;
147 148 149 150 151
        struct
        {
            int32_t i_framesize;
            int32_t i_framesperpacket;
        } speex;
152 153 154 155
        struct
        {
            bool b_old;
        } flac;
156 157
    } special;

158 159
} logical_stream_t;

160 161 162 163 164 165 166 167 168 169 170 171
struct ogg_skeleton_t
{
    int            i_messages;
    char         **ppsz_messages;
    unsigned char *p_index;
    uint64_t       i_index;
    uint64_t       i_index_size;
    int64_t        i_indexstampden;/* time denominator */
    int64_t        i_indexfirstnum;/* first sample time numerator */
    int64_t        i_indexlastnum;
};

172 173 174 175 176 177
struct demux_sys_t
{
    ogg_sync_state oy;        /* sync and verify incoming physical bitstream */

    int i_streams;                           /* number of logical bitstreams */
    logical_stream_t **pp_stream;  /* pointer to an array of logical streams */
178
    logical_stream_t *p_skelstream; /* pointer to skeleton stream if any */
179 180 181 182 183 184

    logical_stream_t *p_old_stream; /* pointer to a old logical stream to avoid recreating it */

    /* program clock reference (in units of 90kHz) derived from the pcr of
     * the sub-streams */
    mtime_t i_pcr;
185
    mtime_t i_nzpcr_offset;
186 187 188
    /* informative only */
    mtime_t i_pcr_jitter;
    int64_t i_access_delay;
189

190 191 192
    /* new stream or starting from a chain */
    bool b_chained_boundary;

193 194
    /* bitrate */
    int     i_bitrate;
195
    bool    b_partial_bitrate;
196 197 198 199

    /* after reading all headers, the first data page is stuffed into the relevant stream, ready to use */
    bool    b_page_waiting;

200 201 202 203 204 205 206 207 208 209 210 211
    /* count of total frames in video stream */
    int64_t i_total_frames;

    /* length of file in bytes */
    int64_t i_total_length;

    /* offset position in file (for reading) */
    int64_t i_input_position;

    /* current page being parsed */
    ogg_page current_page;

212
    /* */
213
    vlc_meta_t          *p_meta;
214 215
    int                 i_seekpoints;
    seekpoint_t         **pp_seekpoints;
216

217 218 219 220 221 222 223
    /* skeleton */
    struct
    {
        uint16_t major;
        uint16_t minor;
    } skeleton;

224
    /* */
225 226
    int                 i_attachments;
    input_attachment_t  **attachments;
227

228 229
    /* preparsing info */
    bool b_preparsing_done;
230
    bool b_es_created;
231

232 233
    /* Length, if available. */
    int64_t i_length;
234

235 236
    bool b_slave;

237
};
238 239 240


unsigned const char * Read7BitsVariableLE( unsigned const char *,
241
                                           unsigned const char *,
242 243 244
                                           uint64_t * );
bool Ogg_GetBoundsUsingSkeletonIndex( logical_stream_t *p_stream, int64_t i_time,
                                      int64_t *pi_lower, int64_t *pi_upper );