Mercurial > mplayer.hg
annotate demuxer.c @ 848:738dc5a2bb39
Changed some #ifdef to include modify ASF structs definition
when STREAMING is defined.
author | bertrand |
---|---|
date | Mon, 21 May 2001 13:04:34 +0000 |
parents | c71695c30006 |
children | 1b905517c684 |
rev | line source |
---|---|
1 | 1 //=================== DEMUXER v2.5 ========================= |
2 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
3 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
4 #include <stdlib.h> |
1 | 5 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
6 extern int verbose; // defined in mplayer.c |
1 | 7 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
8 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
9 #include "demuxer.h" |
1 | 10 |
11 demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id){ | |
12 demux_stream_t* ds=malloc(sizeof(demux_stream_t)); | |
13 ds->buffer_pos=ds->buffer_size=0; | |
14 ds->buffer=NULL; | |
15 ds->pts=0; | |
746 | 16 ds->pts_bytes=0; |
1 | 17 ds->eof=0; |
18 ds->pos=0; | |
19 ds->dpos=0; | |
20 //--------------- | |
21 ds->packs=0; | |
22 ds->bytes=0; | |
23 ds->first=ds->last=NULL; | |
24 ds->id=id; | |
25 ds->type=-1; | |
26 ds->demuxer=demuxer; | |
27 //---------------- | |
28 ds->asf_seq=-1; | |
29 ds->asf_packet=NULL; | |
291 | 30 //---------------- |
31 ds->sh=NULL; | |
1 | 32 return ds; |
33 } | |
34 | |
552 | 35 demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id,int s_id){ |
1 | 36 demuxer_t *d=malloc(sizeof(demuxer_t)); |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
37 memset(d,0,sizeof(demuxer_t)); |
1 | 38 d->stream=stream; |
598 | 39 d->movi_start=stream->start_pos; |
40 d->movi_end=stream->end_pos; | |
1 | 41 d->synced=0; |
42 d->filepos=0; | |
43 d->audio=new_demuxer_stream(d,a_id); | |
44 d->video=new_demuxer_stream(d,v_id); | |
552 | 45 d->sub=new_demuxer_stream(d,s_id); |
1 | 46 d->type=type; |
47 return d; | |
48 } | |
49 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
50 void ds_add_packet(demux_stream_t *ds,demux_packet_t* dp){ |
1 | 51 // demux_packet_t* dp=new_demux_packet(len); |
52 // stream_read(stream,dp->buffer,len); | |
53 // dp->pts=pts; //(float)pts/90000.0f; | |
54 // dp->pos=pos; | |
55 // append packet to DS stream: | |
56 ++ds->packs; | |
57 ds->bytes+=dp->len; | |
58 if(ds->last){ | |
59 // next packet in stream | |
60 ds->last->next=dp; | |
61 ds->last=dp; | |
62 } else { | |
63 // first packet in stream | |
64 ds->first=ds->last=dp; | |
65 } | |
66 if(verbose>=2) | |
67 printf("DEMUX: Append packet to %s, len=%d pts=%5.3f pos=%d [packs: A=%d V=%d]\n", | |
68 (ds==ds->demuxer->audio)?"d_audio":"d_video", | |
69 dp->len,dp->pts,dp->pos,ds->demuxer->audio->packs,ds->demuxer->video->packs); | |
70 } | |
71 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
72 void ds_read_packet(demux_stream_t *ds,stream_t *stream,int len,float pts,int pos){ |
1 | 73 demux_packet_t* dp=new_demux_packet(len); |
74 stream_read(stream,dp->buffer,len); | |
75 dp->pts=pts; //(float)pts/90000.0f; | |
76 dp->pos=pos; | |
77 // append packet to DS stream: | |
78 ds_add_packet(ds,dp); | |
79 } | |
80 | |
81 // return value: | |
82 // 0 = EOF or no stream found or invalid type | |
83 // 1 = successfully read a packet | |
84 int demux_mpg_es_fill_buffer(demuxer_t *demux); | |
85 int demux_mpg_fill_buffer(demuxer_t *demux); | |
86 int demux_avi_fill_buffer(demuxer_t *demux); | |
87 int demux_avi_fill_buffer_ni(demuxer_t *demux,demux_stream_t *ds); | |
88 int demux_avi_fill_buffer_nini(demuxer_t *demux,demux_stream_t *ds); | |
89 int demux_asf_fill_buffer(demuxer_t *demux); | |
90 | |
91 int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds){ | |
92 // Note: parameter 'ds' can be NULL! | |
93 switch(demux->type){ | |
94 case DEMUXER_TYPE_MPEG_ES: return demux_mpg_es_fill_buffer(demux); | |
95 case DEMUXER_TYPE_MPEG_PS: return demux_mpg_fill_buffer(demux); | |
96 case DEMUXER_TYPE_AVI: return demux_avi_fill_buffer(demux); | |
97 case DEMUXER_TYPE_AVI_NI: return demux_avi_fill_buffer_ni(demux,ds); | |
98 case DEMUXER_TYPE_AVI_NINI: return demux_avi_fill_buffer_nini(demux,ds); | |
99 case DEMUXER_TYPE_ASF: return demux_asf_fill_buffer(demux); | |
100 } | |
101 return 0; | |
102 } | |
103 | |
104 // return value: | |
105 // 0 = EOF | |
106 // 1 = succesfull | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
107 int ds_fill_buffer(demux_stream_t *ds){ |
1 | 108 demuxer_t *demux=ds->demuxer; |
109 if(ds->buffer) free(ds->buffer); | |
110 if(verbose>2){ | |
111 if(ds==demux->audio) printf("ds_fill_buffer(d_audio) called\n");else | |
112 if(ds==demux->video) printf("ds_fill_buffer(d_video) called\n");else | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
113 printf("ds_fill_buffer(unknown 0x%X) called\n",(unsigned int)ds); |
1 | 114 } |
115 while(1){ | |
116 if(ds->packs){ | |
117 demux_packet_t *p=ds->first; | |
118 // copy useful data: | |
119 ds->buffer=p->buffer; | |
120 ds->buffer_pos=0; | |
121 ds->buffer_size=p->len; | |
122 ds->pos=p->pos; | |
123 ds->dpos+=p->len; // !!! | |
746 | 124 if(p->pts){ |
125 ds->pts=p->pts; | |
126 ds->pts_bytes=0; | |
127 } | |
128 ds->pts_bytes+=p->len; // !!! | |
1 | 129 // free packet: |
130 ds->bytes-=p->len; | |
131 ds->first=p->next; | |
132 if(!ds->first) ds->last=NULL; | |
133 free(p); | |
134 --ds->packs; | |
135 return 1; //ds->buffer_size; | |
136 } | |
137 if(demux->audio->packs>=MAX_PACKS || demux->audio->bytes>=MAX_PACK_BYTES){ | |
138 printf("\nDEMUXER: Too many (%d in %d bytes) audio packets in the buffer!\n",demux->audio->packs,demux->audio->bytes); | |
139 printf("(maybe you play a non-interleaved stream/file or audio codec failed)\n"); | |
140 break; | |
141 } | |
142 if(demux->video->packs>=MAX_PACKS || demux->video->bytes>=MAX_PACK_BYTES){ | |
143 printf("\nDEMUXER: Too many (%d in %d bytes) video packets in the buffer!\n",demux->video->packs,demux->video->bytes); | |
144 printf("(maybe you play a non-interleaved stream/file or video codec failed)\n"); | |
145 break; | |
146 } | |
147 if(!demux_fill_buffer(demux,ds)) break; // EOF | |
148 } | |
149 ds->buffer_pos=ds->buffer_size=0; | |
150 ds->buffer=NULL; | |
151 if(verbose) printf("ds_fill_buffer: EOF reached (stream: %s) \n",ds==demux->audio?"audio":"video"); | |
152 ds->eof=1; | |
153 return 0; | |
154 } | |
155 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
156 int demux_read_data(demux_stream_t *ds,unsigned char* mem,int len){ |
1 | 157 int x; |
158 int bytes=0; | |
159 while(len>0){ | |
160 x=ds->buffer_size-ds->buffer_pos; | |
161 if(x==0){ | |
162 if(!ds_fill_buffer(ds)) return bytes; | |
163 } else { | |
164 if(x>len) x=len; | |
165 if(mem) memcpy(mem+bytes,&ds->buffer[ds->buffer_pos],x); | |
166 bytes+=x;len-=x;ds->buffer_pos+=x; | |
167 } | |
168 } | |
169 return bytes; | |
170 } | |
171 | |
746 | 172 int demux_read_data_pack(demux_stream_t *ds,unsigned char* mem,int len){ |
173 int x; | |
174 int bytes=0; | |
175 while(len>0){ | |
176 x=ds->buffer_size-ds->buffer_pos; | |
177 if(x==0){ | |
178 if(!ds_fill_buffer(ds)) return bytes; | |
179 } else { | |
180 if(x>len) x=len; | |
181 if(mem) memcpy(mem+bytes,&ds->buffer[ds->buffer_pos],x); | |
182 bytes+=x;len-=x;ds->buffer_pos+=x; | |
183 return bytes; // stop at end of package! (for correct timestamping) | |
184 } | |
185 } | |
186 return bytes; | |
187 } | |
188 | |
189 | |
1 | 190 void ds_free_packs(demux_stream_t *ds){ |
191 demux_packet_t *dp=ds->first; | |
192 while(dp){ | |
193 demux_packet_t *dn=dp->next; | |
194 free(dp->buffer); | |
195 free(dp); | |
196 dp=dn; | |
197 } | |
198 if(ds->asf_packet){ | |
199 // free unfinished .asf fragments: | |
200 free(ds->asf_packet->buffer); | |
201 free(ds->asf_packet); | |
202 ds->asf_packet=NULL; | |
203 } | |
204 ds->first=ds->last=NULL; | |
205 ds->packs=0; // !!!!! | |
206 ds->bytes=0; | |
207 if(ds->buffer) free(ds->buffer); | |
208 ds->buffer=NULL; | |
209 ds->buffer_pos=ds->buffer_size; | |
828 | 210 ds->pts=0; ds->pts_bytes=0; |
1 | 211 } |
212 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
213 int ds_get_packet(demux_stream_t *ds,unsigned char **start){ |
1 | 214 while(1){ |
215 int len; | |
216 if(ds->buffer_pos>=ds->buffer_size){ | |
217 if(!ds_fill_buffer(ds)){ | |
218 // EOF | |
219 *start = NULL; | |
220 return -1; | |
221 } | |
222 } | |
223 len=ds->buffer_size-ds->buffer_pos; | |
224 *start = &ds->buffer[ds->buffer_pos]; | |
225 ds->buffer_pos+=len; | |
226 return len; | |
227 } | |
228 } | |
554 | 229 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
230 int ds_get_packet_sub(demux_stream_t *ds,unsigned char **start){ |
554 | 231 while(1){ |
232 int len; | |
233 if(ds->buffer_pos>=ds->buffer_size){ | |
234 *start = NULL; | |
235 if(!ds->packs) return -1; // no sub | |
236 if(!ds_fill_buffer(ds)) return -1; // EOF | |
237 } | |
238 len=ds->buffer_size-ds->buffer_pos; | |
239 *start = &ds->buffer[ds->buffer_pos]; | |
240 ds->buffer_pos+=len; | |
241 return len; | |
242 } | |
243 } | |
244 |