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