annotate demuxer.h @ 951:9fb176abc1a7

Some fixups for SDL/aalib.
author atmosfear
date Sat, 02 Jun 2001 22:12:28 +0000
parents 1b905517c684
children 3bcc435cd5a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
589
62f483490686 sorry...
arpi_esp
parents:
diff changeset
1
647
feffffff5d0e demux buffer increased 4m->8m
arpi_esp
parents: 589
diff changeset
2 #define MAX_PACKS 4096
feffffff5d0e demux buffer increased 4m->8m
arpi_esp
parents: 589
diff changeset
3 #define MAX_PACK_BYTES 0x800000
589
62f483490686 sorry...
arpi_esp
parents:
diff changeset
4
62f483490686 sorry...
arpi_esp
parents:
diff changeset
5 #define DEMUXER_TYPE_UNKNOWN 0
62f483490686 sorry...
arpi_esp
parents:
diff changeset
6 #define DEMUXER_TYPE_MPEG_ES 1
62f483490686 sorry...
arpi_esp
parents:
diff changeset
7 #define DEMUXER_TYPE_MPEG_PS 2
62f483490686 sorry...
arpi_esp
parents:
diff changeset
8 #define DEMUXER_TYPE_AVI 3
62f483490686 sorry...
arpi_esp
parents:
diff changeset
9 #define DEMUXER_TYPE_AVI_NI 4
62f483490686 sorry...
arpi_esp
parents:
diff changeset
10 #define DEMUXER_TYPE_AVI_NINI 5
62f483490686 sorry...
arpi_esp
parents:
diff changeset
11 #define DEMUXER_TYPE_ASF 6
62f483490686 sorry...
arpi_esp
parents:
diff changeset
12
62f483490686 sorry...
arpi_esp
parents:
diff changeset
13 #define DEMUXER_TIME_NONE 0
62f483490686 sorry...
arpi_esp
parents:
diff changeset
14 #define DEMUXER_TIME_PTS 1
62f483490686 sorry...
arpi_esp
parents:
diff changeset
15 #define DEMUXER_TIME_FILE 2
62f483490686 sorry...
arpi_esp
parents:
diff changeset
16 #define DEMUXER_TIME_BPS 3
62f483490686 sorry...
arpi_esp
parents:
diff changeset
17
62f483490686 sorry...
arpi_esp
parents:
diff changeset
18
62f483490686 sorry...
arpi_esp
parents:
diff changeset
19 typedef struct demux_packet_st {
62f483490686 sorry...
arpi_esp
parents:
diff changeset
20 int len;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
21 float pts;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
22 int pos; // pozicio indexben (AVI) ill. fileban (MPG)
62f483490686 sorry...
arpi_esp
parents:
diff changeset
23 unsigned char* buffer;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
24 struct demux_packet_st* next;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
25 } demux_packet_t;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
26
62f483490686 sorry...
arpi_esp
parents:
diff changeset
27 typedef struct {
62f483490686 sorry...
arpi_esp
parents:
diff changeset
28 int buffer_pos; // current buffer position
62f483490686 sorry...
arpi_esp
parents:
diff changeset
29 int buffer_size; // current buffer size
62f483490686 sorry...
arpi_esp
parents:
diff changeset
30 unsigned char* buffer; // current buffer
62f483490686 sorry...
arpi_esp
parents:
diff changeset
31 float pts; // current buffer's pts
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 647
diff changeset
32 int pts_bytes; // number of bytes read after last pts stamp
589
62f483490686 sorry...
arpi_esp
parents:
diff changeset
33 int eof; // end of demuxed stream? (true if all buffer empty)
62f483490686 sorry...
arpi_esp
parents:
diff changeset
34 int pos; // position in the input stream (file)
62f483490686 sorry...
arpi_esp
parents:
diff changeset
35 int dpos; // position in the demuxed stream
889
1b905517c684 AVI -bps desync problem solved
arpi_esp
parents: 746
diff changeset
36 int pack_no; // serial number of packet
589
62f483490686 sorry...
arpi_esp
parents:
diff changeset
37 //---------------
62f483490686 sorry...
arpi_esp
parents:
diff changeset
38 int packs; // number of packets in buffer
62f483490686 sorry...
arpi_esp
parents:
diff changeset
39 int bytes; // total bytes of packets in buffer
62f483490686 sorry...
arpi_esp
parents:
diff changeset
40 demux_packet_t *first; // read to current buffer from here
62f483490686 sorry...
arpi_esp
parents:
diff changeset
41 demux_packet_t *last; // append new packets from input stream to here
62f483490686 sorry...
arpi_esp
parents:
diff changeset
42 int id; // stream ID (for multiple audio/video streams)
62f483490686 sorry...
arpi_esp
parents:
diff changeset
43 int type; // stream type (currently used only for audio)
62f483490686 sorry...
arpi_esp
parents:
diff changeset
44 struct demuxer_st *demuxer; // parent demuxer structure (stream handler)
62f483490686 sorry...
arpi_esp
parents:
diff changeset
45 // ---- asf -----
62f483490686 sorry...
arpi_esp
parents:
diff changeset
46 demux_packet_t *asf_packet; // read asf fragments here
62f483490686 sorry...
arpi_esp
parents:
diff changeset
47 int asf_seq;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
48 // ---- stream header ----
62f483490686 sorry...
arpi_esp
parents:
diff changeset
49 void* sh;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
50 } demux_stream_t;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
51
62f483490686 sorry...
arpi_esp
parents:
diff changeset
52 typedef struct demuxer_st {
62f483490686 sorry...
arpi_esp
parents:
diff changeset
53 stream_t *stream;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
54 int synced; // stream synced (used by mpeg)
62f483490686 sorry...
arpi_esp
parents:
diff changeset
55 int filepos; // input stream current pos.
62f483490686 sorry...
arpi_esp
parents:
diff changeset
56 // int endpos; // input stream end pos. (return EOF fi filepos>endpos)
62f483490686 sorry...
arpi_esp
parents:
diff changeset
57 int type; // mpeg system stream, mpeg elementary s., avi raw, avi indexed
62f483490686 sorry...
arpi_esp
parents:
diff changeset
58 // int time_src;// time source (pts/file/bps)
62f483490686 sorry...
arpi_esp
parents:
diff changeset
59 unsigned int movi_start;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
60 unsigned int movi_end;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
61 //
62f483490686 sorry...
arpi_esp
parents:
diff changeset
62 demux_stream_t *audio;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
63 demux_stream_t *video;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
64 demux_stream_t *sub;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
65
62f483490686 sorry...
arpi_esp
parents:
diff changeset
66 // index:
62f483490686 sorry...
arpi_esp
parents:
diff changeset
67 // AVIINDEXENTRY* idx;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
68 void* idx;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
69 int idx_size;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
70 int idx_pos;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
71 int idx_pos_a;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
72 int idx_pos_v;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
73 int idx_offset; // ennyit kell hozzaadni az index offset ertekekhez
62f483490686 sorry...
arpi_esp
parents:
diff changeset
74
62f483490686 sorry...
arpi_esp
parents:
diff changeset
75 // stream headers:
62f483490686 sorry...
arpi_esp
parents:
diff changeset
76 // sh_audio_t* a_streams[256];
62f483490686 sorry...
arpi_esp
parents:
diff changeset
77 // sh_video_t* v_streams[256];
62f483490686 sorry...
arpi_esp
parents:
diff changeset
78 void* a_streams[256];
62f483490686 sorry...
arpi_esp
parents:
diff changeset
79 void* v_streams[256];
62f483490686 sorry...
arpi_esp
parents:
diff changeset
80 char s_streams[32]; // dvd subtitles
62f483490686 sorry...
arpi_esp
parents:
diff changeset
81 } demuxer_t;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
82
62f483490686 sorry...
arpi_esp
parents:
diff changeset
83 inline static demux_packet_t* new_demux_packet(int len){
62f483490686 sorry...
arpi_esp
parents:
diff changeset
84 demux_packet_t* dp=malloc(sizeof(demux_packet_t));
62f483490686 sorry...
arpi_esp
parents:
diff changeset
85 dp->len=len;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
86 dp->buffer=malloc(len);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
87 dp->next=NULL;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
88 dp->pts=0;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
89 dp->pos=0;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
90 return dp;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
91 }
62f483490686 sorry...
arpi_esp
parents:
diff changeset
92
62f483490686 sorry...
arpi_esp
parents:
diff changeset
93 inline static void free_demux_packet(demux_packet_t* dp){
62f483490686 sorry...
arpi_esp
parents:
diff changeset
94 free(dp->buffer);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
95 free(dp);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
96 }
62f483490686 sorry...
arpi_esp
parents:
diff changeset
97
62f483490686 sorry...
arpi_esp
parents:
diff changeset
98 demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
99 demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id,int s_id);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
100
62f483490686 sorry...
arpi_esp
parents:
diff changeset
101 void ds_add_packet(demux_stream_t *ds,demux_packet_t* dp);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
102 void ds_read_packet(demux_stream_t *ds,stream_t *stream,int len,float pts,int pos);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
103
62f483490686 sorry...
arpi_esp
parents:
diff changeset
104 int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
105 int ds_fill_buffer(demux_stream_t *ds);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
106
62f483490686 sorry...
arpi_esp
parents:
diff changeset
107 inline static int ds_tell(demux_stream_t *ds){
62f483490686 sorry...
arpi_esp
parents:
diff changeset
108 return (ds->dpos-ds->buffer_size)+ds->buffer_pos;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
109 }
62f483490686 sorry...
arpi_esp
parents:
diff changeset
110
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 647
diff changeset
111 inline static int ds_tell_pts(demux_stream_t *ds){
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 647
diff changeset
112 return (ds->pts_bytes-ds->buffer_size)+ds->buffer_pos;
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 647
diff changeset
113 }
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 647
diff changeset
114
589
62f483490686 sorry...
arpi_esp
parents:
diff changeset
115 int demux_read_data(demux_stream_t *ds,unsigned char* mem,int len);
746
cd1f0d4de0b8 new audio playback and A-V sync code
arpi_esp
parents: 647
diff changeset
116 int demux_read_data_pack(demux_stream_t *ds,unsigned char* mem,int len);
589
62f483490686 sorry...
arpi_esp
parents:
diff changeset
117
62f483490686 sorry...
arpi_esp
parents:
diff changeset
118 #if 1
62f483490686 sorry...
arpi_esp
parents:
diff changeset
119 #define demux_getc(ds) (\
62f483490686 sorry...
arpi_esp
parents:
diff changeset
120 (ds->buffer_pos<ds->buffer_size) ? ds->buffer[ds->buffer_pos++] \
62f483490686 sorry...
arpi_esp
parents:
diff changeset
121 :((!ds_fill_buffer(ds))? (-1) : ds->buffer[ds->buffer_pos++] ) )
62f483490686 sorry...
arpi_esp
parents:
diff changeset
122 #else
62f483490686 sorry...
arpi_esp
parents:
diff changeset
123 inline static int demux_getc(demux_stream_t *ds){
62f483490686 sorry...
arpi_esp
parents:
diff changeset
124 if(ds->buffer_pos>=ds->buffer_size){
62f483490686 sorry...
arpi_esp
parents:
diff changeset
125 if(!ds_fill_buffer(ds)){
62f483490686 sorry...
arpi_esp
parents:
diff changeset
126 // printf("DEMUX_GETC: EOF reached!\n");
62f483490686 sorry...
arpi_esp
parents:
diff changeset
127 return -1; // EOF
62f483490686 sorry...
arpi_esp
parents:
diff changeset
128 }
62f483490686 sorry...
arpi_esp
parents:
diff changeset
129 }
62f483490686 sorry...
arpi_esp
parents:
diff changeset
130 // printf("[%02X]",ds->buffer[ds->buffer_pos]);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
131 return ds->buffer[ds->buffer_pos++];
62f483490686 sorry...
arpi_esp
parents:
diff changeset
132 }
62f483490686 sorry...
arpi_esp
parents:
diff changeset
133 #endif
62f483490686 sorry...
arpi_esp
parents:
diff changeset
134
62f483490686 sorry...
arpi_esp
parents:
diff changeset
135 void ds_free_packs(demux_stream_t *ds);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
136 int ds_get_packet(demux_stream_t *ds,unsigned char **start);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
137 int ds_get_packet_sub(demux_stream_t *ds,unsigned char **start);
62f483490686 sorry...
arpi_esp
parents:
diff changeset
138
62f483490686 sorry...
arpi_esp
parents:
diff changeset
139
62f483490686 sorry...
arpi_esp
parents:
diff changeset
140 static inline int avi_stream_id(unsigned int id){
62f483490686 sorry...
arpi_esp
parents:
diff changeset
141 unsigned char *p=(unsigned char *)&id;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
142 unsigned char a,b;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
143 a=p[0]-'0'; b=p[1]-'0';
62f483490686 sorry...
arpi_esp
parents:
diff changeset
144 if(a>9 || b>9) return 100; // invalid ID
62f483490686 sorry...
arpi_esp
parents:
diff changeset
145 return a*10+b;
62f483490686 sorry...
arpi_esp
parents:
diff changeset
146 }
62f483490686 sorry...
arpi_esp
parents:
diff changeset
147
62f483490686 sorry...
arpi_esp
parents:
diff changeset
148
62f483490686 sorry...
arpi_esp
parents:
diff changeset
149