comparison demuxer.c @ 746:cd1f0d4de0b8

new audio playback and A-V sync code
author arpi_esp
date Thu, 10 May 2001 03:39:54 +0000
parents c7117e17e20b
children c71695c30006
comparison
equal deleted inserted replaced
745:c653430f0789 746:cd1f0d4de0b8
11 demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id){ 11 demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id){
12 demux_stream_t* ds=malloc(sizeof(demux_stream_t)); 12 demux_stream_t* ds=malloc(sizeof(demux_stream_t));
13 ds->buffer_pos=ds->buffer_size=0; 13 ds->buffer_pos=ds->buffer_size=0;
14 ds->buffer=NULL; 14 ds->buffer=NULL;
15 ds->pts=0; 15 ds->pts=0;
16 ds->pts_bytes=0;
16 ds->eof=0; 17 ds->eof=0;
17 ds->pos=0; 18 ds->pos=0;
18 ds->dpos=0; 19 ds->dpos=0;
19 //--------------- 20 //---------------
20 ds->packs=0; 21 ds->packs=0;
118 ds->buffer=p->buffer; 119 ds->buffer=p->buffer;
119 ds->buffer_pos=0; 120 ds->buffer_pos=0;
120 ds->buffer_size=p->len; 121 ds->buffer_size=p->len;
121 ds->pos=p->pos; 122 ds->pos=p->pos;
122 ds->dpos+=p->len; // !!! 123 ds->dpos+=p->len; // !!!
123 ds->pts=p->pts; 124 if(p->pts){
125 ds->pts=p->pts;
126 ds->pts_bytes=0;
127 }
128 ds->pts_bytes+=p->len; // !!!
124 // free packet: 129 // free packet:
125 ds->bytes-=p->len; 130 ds->bytes-=p->len;
126 ds->first=p->next; 131 ds->first=p->next;
127 if(!ds->first) ds->last=NULL; 132 if(!ds->first) ds->last=NULL;
128 free(p); 133 free(p);
161 bytes+=x;len-=x;ds->buffer_pos+=x; 166 bytes+=x;len-=x;ds->buffer_pos+=x;
162 } 167 }
163 } 168 }
164 return bytes; 169 return bytes;
165 } 170 }
171
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
166 189
167 void ds_free_packs(demux_stream_t *ds){ 190 void ds_free_packs(demux_stream_t *ds){
168 demux_packet_t *dp=ds->first; 191 demux_packet_t *dp=ds->first;
169 while(dp){ 192 while(dp){
170 demux_packet_t *dn=dp->next; 193 demux_packet_t *dn=dp->next;