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