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