#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <inttypes.h>
#include "mp_msg.h"
#include "help_mp.h"
#include "stream/stream.h"
#include "demuxer.h"
#include "stheader.h"
#define FOURCC_VORBIS mmioFOURCC('v', 'r', 'b', 's')
#define FOURCC_SPEEX mmioFOURCC('s', 'p', 'x', ' ')
#define FOURCC_THEORA mmioFOURCC('t', 'h', 'e', 'o')
#ifdef TREMOR
#include <tremor/ogg.h>
#include <tremor/ivorbiscodec.h>
#else
#include <ogg/ogg.h>
#include <vorbis/codec.h>
#endif
#ifdef HAVE_OGGTHEORA
#include <theora/theora.h>
extern int _ilog (unsigned int); /* defined in many places in theora/lib/ */
#endif
#define BLOCK_SIZE 4096
/* Theora decoder context : we won't be able to interpret granule positions
* without using theora_granule_time with the theora_state of the stream.
* This is duplicated in `vd_theora.c'; put this in a common header?
*/
#ifdef HAVE_OGGTHEORA
typedef struct theora_struct_st {
theora_state st;
theora_comment cc;
theora_info inf;
} theora_struct_t;
#endif
//// OggDS headers
// Header for the new header format
typedef struct stream_header_video
{
ogg_int32_t width;
ogg_int32_t height;
} stream_header_video;
typedef struct stream_header_audio
{
ogg_int16_t channels;
ogg_int16_t blockalign;
ogg_int32_t avgbytespersec;
} stream_header_audio;
typedef struct __attribute__((__packed__)) stream_header
{
char streamtype[8];
char subtype[4];
ogg_int32_t size; // size of the structure
ogg_int64_t time_unit; // in reference time
ogg_int64_t samples_per_unit;
ogg_int32_t default_len; // in media time
ogg_int32_t buffersize;
ogg_int16_t bits_per_sample;
ogg_int16_t padding;
union
{
// Video specific
stream_header_video video;
// Audio specific
stream_header_audio audio;
} sh;
} stream_header;
/// Our private datas
typedef struct ogg_syncpoint {
int64_t granulepos;
off_t page_pos;
} ogg_syncpoint_t;
/// A logical stream
typedef struct ogg_stream {
/// Timestamping stuff
float samplerate; /// granulpos 2 time
int64_t lastpos;
int32_t lastsize;
// Logical stream state
ogg_stream_state stream;
int hdr_packets;
int vorbis;
int speex;
int theora;
int flac;
int text;
int id;
vorbis_info vi;
int vi_inited;
void *ogg_d;
} ogg_stream_t;
typedef struct ogg_demuxer {
/// Physical stream state
ogg_sync_state sync;
/// Current page
ogg_page page;
/// Logical streams
ogg_stream_t *subs;
int num_sub;
ogg_syncpoint_t* syncpoints;
int num_syncpoint;
off_t pos, last_size;
int64_t final_granulepos;
/* Used for subtitle switching. */
int n_text;
int *text_ids;
char **text_langs;
} ogg_demuxer_t;
#define NUM_VORBIS_HDR_PACKETS 3
/// Some defines from OggDS
#define PACKET_TYPE_HEADER 0x01
#define PACKET_TYPE_BITS 0x07
#define PACKET_LEN_BITS01 0xc0
|