2001-04-23 16:12:21 +00:00
|
|
|
|
2001-04-26 20:43:12 +00:00
|
|
|
#define MAX_PACKS 4096
|
|
|
|
#define MAX_PACK_BYTES 0x800000
|
2001-04-23 16:12:21 +00:00
|
|
|
|
|
|
|
#define DEMUXER_TYPE_UNKNOWN 0
|
|
|
|
#define DEMUXER_TYPE_MPEG_ES 1
|
|
|
|
#define DEMUXER_TYPE_MPEG_PS 2
|
|
|
|
#define DEMUXER_TYPE_AVI 3
|
|
|
|
#define DEMUXER_TYPE_AVI_NI 4
|
|
|
|
#define DEMUXER_TYPE_AVI_NINI 5
|
|
|
|
#define DEMUXER_TYPE_ASF 6
|
2001-08-12 01:58:05 +00:00
|
|
|
#define DEMUXER_TYPE_MOV 7
|
2001-11-04 16:57:09 +00:00
|
|
|
#define DEMUXER_TYPE_VIVO 8
|
2001-11-09 23:46:06 +00:00
|
|
|
#define DEMUXER_TYPE_TV 9
|
2001-11-24 23:58:12 +00:00
|
|
|
#define DEMUXER_TYPE_FLI 10
|
2001-04-23 16:12:21 +00:00
|
|
|
|
|
|
|
#define DEMUXER_TIME_NONE 0
|
|
|
|
#define DEMUXER_TIME_PTS 1
|
|
|
|
#define DEMUXER_TIME_FILE 2
|
|
|
|
#define DEMUXER_TIME_BPS 3
|
|
|
|
|
|
|
|
|
2001-07-31 23:18:16 +00:00
|
|
|
// Holds one packet/frame/whatever
|
2001-04-23 16:12:21 +00:00
|
|
|
typedef struct demux_packet_st {
|
|
|
|
int len;
|
|
|
|
float pts;
|
2001-08-11 20:37:33 +00:00
|
|
|
off_t pos; // position in index (AVI) or file (MPG)
|
2001-04-23 16:12:21 +00:00
|
|
|
unsigned char* buffer;
|
2001-06-03 23:37:20 +00:00
|
|
|
int flags; // keyframe, etc
|
2001-04-23 16:12:21 +00:00
|
|
|
struct demux_packet_st* next;
|
|
|
|
} demux_packet_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int buffer_pos; // current buffer position
|
|
|
|
int buffer_size; // current buffer size
|
|
|
|
unsigned char* buffer; // current buffer
|
|
|
|
float pts; // current buffer's pts
|
2001-05-10 03:39:54 +00:00
|
|
|
int pts_bytes; // number of bytes read after last pts stamp
|
2001-04-23 16:12:21 +00:00
|
|
|
int eof; // end of demuxed stream? (true if all buffer empty)
|
2001-07-31 23:18:16 +00:00
|
|
|
off_t pos; // position in the input stream (file)
|
|
|
|
off_t dpos; // position in the demuxed stream
|
2001-05-27 00:02:12 +00:00
|
|
|
int pack_no; // serial number of packet
|
2001-06-03 23:37:20 +00:00
|
|
|
int flags; // flags of current packet (keyframe etc)
|
2001-04-23 16:12:21 +00:00
|
|
|
//---------------
|
|
|
|
int packs; // number of packets in buffer
|
|
|
|
int bytes; // total bytes of packets in buffer
|
|
|
|
demux_packet_t *first; // read to current buffer from here
|
|
|
|
demux_packet_t *last; // append new packets from input stream to here
|
|
|
|
int id; // stream ID (for multiple audio/video streams)
|
|
|
|
struct demuxer_st *demuxer; // parent demuxer structure (stream handler)
|
|
|
|
// ---- asf -----
|
|
|
|
demux_packet_t *asf_packet; // read asf fragments here
|
|
|
|
int asf_seq;
|
2001-10-23 13:55:49 +00:00
|
|
|
// ---- mov -----
|
|
|
|
unsigned int ss_mul,ss_div;
|
2001-04-23 16:12:21 +00:00
|
|
|
// ---- stream header ----
|
|
|
|
void* sh;
|
|
|
|
} demux_stream_t;
|
|
|
|
|
2001-11-21 16:14:14 +00:00
|
|
|
typedef struct demuxer_info_st {
|
|
|
|
char *name;
|
|
|
|
char *author;
|
|
|
|
char *encoder;
|
|
|
|
char *comments;
|
2001-11-22 15:43:24 +00:00
|
|
|
char *copyright;
|
2001-11-21 16:14:14 +00:00
|
|
|
} demuxer_info_t;
|
|
|
|
|
2001-04-23 16:12:21 +00:00
|
|
|
typedef struct demuxer_st {
|
|
|
|
stream_t *stream;
|
|
|
|
int synced; // stream synced (used by mpeg)
|
2001-07-31 23:18:16 +00:00
|
|
|
off_t filepos; // input stream current pos.
|
2001-07-21 22:37:55 +00:00
|
|
|
int type; // demuxer type: mpeg PS, mpeg ES, avi, avi-ni, avi-nini, asf
|
|
|
|
int file_format; // file format: mpeg/avi/asf
|
2001-07-31 23:18:16 +00:00
|
|
|
off_t movi_start;
|
|
|
|
off_t movi_end;
|
2001-08-22 16:42:37 +00:00
|
|
|
int seekable; // flag
|
2001-04-23 16:12:21 +00:00
|
|
|
//
|
2001-08-11 20:37:33 +00:00
|
|
|
demux_stream_t *audio; // audio buffer/demuxer
|
|
|
|
demux_stream_t *video; // video buffer/demuxer
|
|
|
|
demux_stream_t *sub; // dvd subtitle buffer/demuxer
|
2001-04-23 16:12:21 +00:00
|
|
|
|
|
|
|
// stream headers:
|
2001-08-11 20:37:33 +00:00
|
|
|
void* a_streams[256]; // audio streams (sh_audio_t)
|
|
|
|
void* v_streams[256]; // video sterams (sh_video_t)
|
|
|
|
char s_streams[32]; // dvd subtitles (flag)
|
|
|
|
|
|
|
|
void* priv; // fileformat-dependent data
|
2001-11-21 16:14:14 +00:00
|
|
|
demuxer_info_t info;
|
2001-04-23 16:12:21 +00:00
|
|
|
} demuxer_t;
|
|
|
|
|
|
|
|
inline static demux_packet_t* new_demux_packet(int len){
|
|
|
|
demux_packet_t* dp=malloc(sizeof(demux_packet_t));
|
|
|
|
dp->len=len;
|
|
|
|
dp->buffer=malloc(len);
|
|
|
|
dp->next=NULL;
|
|
|
|
dp->pts=0;
|
|
|
|
dp->pos=0;
|
2001-06-03 23:37:20 +00:00
|
|
|
dp->flags=0;
|
2001-04-23 16:12:21 +00:00
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static void free_demux_packet(demux_packet_t* dp){
|
|
|
|
free(dp->buffer);
|
|
|
|
free(dp);
|
|
|
|
}
|
|
|
|
|
|
|
|
demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id);
|
|
|
|
demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id,int s_id);
|
2001-08-22 23:54:57 +00:00
|
|
|
void free_demuxer_stream(demux_stream_t *ds);
|
|
|
|
void free_demuxer(demuxer_t *demuxer);
|
2001-04-23 16:12:21 +00:00
|
|
|
|
|
|
|
void ds_add_packet(demux_stream_t *ds,demux_packet_t* dp);
|
2001-07-31 23:18:16 +00:00
|
|
|
void ds_read_packet(demux_stream_t *ds,stream_t *stream,int len,float pts,off_t pos,int flags);
|
2001-04-23 16:12:21 +00:00
|
|
|
|
|
|
|
int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds);
|
|
|
|
int ds_fill_buffer(demux_stream_t *ds);
|
|
|
|
|
2001-07-31 23:18:16 +00:00
|
|
|
inline static off_t ds_tell(demux_stream_t *ds){
|
2001-04-23 16:12:21 +00:00
|
|
|
return (ds->dpos-ds->buffer_size)+ds->buffer_pos;
|
|
|
|
}
|
|
|
|
|
2001-05-10 03:39:54 +00:00
|
|
|
inline static int ds_tell_pts(demux_stream_t *ds){
|
|
|
|
return (ds->pts_bytes-ds->buffer_size)+ds->buffer_pos;
|
|
|
|
}
|
|
|
|
|
2001-04-23 16:12:21 +00:00
|
|
|
int demux_read_data(demux_stream_t *ds,unsigned char* mem,int len);
|
2001-05-10 03:39:54 +00:00
|
|
|
int demux_read_data_pack(demux_stream_t *ds,unsigned char* mem,int len);
|
2001-04-23 16:12:21 +00:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
#define demux_getc(ds) (\
|
|
|
|
(ds->buffer_pos<ds->buffer_size) ? ds->buffer[ds->buffer_pos++] \
|
|
|
|
:((!ds_fill_buffer(ds))? (-1) : ds->buffer[ds->buffer_pos++] ) )
|
|
|
|
#else
|
|
|
|
inline static int demux_getc(demux_stream_t *ds){
|
|
|
|
if(ds->buffer_pos>=ds->buffer_size){
|
|
|
|
if(!ds_fill_buffer(ds)){
|
|
|
|
// printf("DEMUX_GETC: EOF reached!\n");
|
|
|
|
return -1; // EOF
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// printf("[%02X]",ds->buffer[ds->buffer_pos]);
|
|
|
|
return ds->buffer[ds->buffer_pos++];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void ds_free_packs(demux_stream_t *ds);
|
|
|
|
int ds_get_packet(demux_stream_t *ds,unsigned char **start);
|
|
|
|
int ds_get_packet_sub(demux_stream_t *ds,unsigned char **start);
|
|
|
|
|
|
|
|
|
|
|
|
static inline int avi_stream_id(unsigned int id){
|
|
|
|
unsigned char *p=(unsigned char *)&id;
|
|
|
|
unsigned char a,b;
|
2001-07-12 15:35:52 +00:00
|
|
|
#if WORDS_BIGENDIAN
|
|
|
|
a=p[3]-'0'; b=p[2]-'0';
|
|
|
|
#else
|
2001-04-23 16:12:21 +00:00
|
|
|
a=p[0]-'0'; b=p[1]-'0';
|
2001-07-12 15:35:52 +00:00
|
|
|
#endif
|
2001-04-23 16:12:21 +00:00
|
|
|
if(a>9 || b>9) return 100; // invalid ID
|
|
|
|
return a*10+b;
|
|
|
|
}
|
|
|
|
|
2001-08-12 15:46:09 +00:00
|
|
|
demuxer_t* demux_open(stream_t *stream,int file_format,int aid,int vid,int sid);
|
|
|
|
int demux_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
|
2001-04-23 16:12:21 +00:00
|
|
|
|
2001-10-30 17:03:11 +00:00
|
|
|
// AVI demuxer params:
|
|
|
|
extern int index_mode; // -1=untouched 0=don't use index 1=use (geneate) index
|
|
|
|
extern int force_ni;
|
|
|
|
extern int pts_from_bps;
|
|
|
|
|
2001-11-22 15:43:24 +00:00
|
|
|
int demux_info_add(demuxer_t *demuxer, char *opt, char *param);
|
|
|
|
int demux_info_print(demuxer_t *demuxer);
|