comparison libmpdemux/muxer_avi.c @ 9007:12fc55eb3373

Cleanup of the muxer API, func parameters muxer & muxer_f eliminated. patch by Andriy N. Gritsenko <andrej@lucky.net>
author arpi
date Sun, 19 Jan 2003 00:33:11 +0000
parents 35bfd508bf5f
children e00d3351b912
comparison
equal deleted inserted replaced
9006:d00997f12257 9007:12fc55eb3373
28 extern char *info_sourceform; 28 extern char *info_sourceform;
29 extern char *info_comment; 29 extern char *info_comment;
30 30
31 static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){ 31 static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){
32 muxer_stream_t* s; 32 muxer_stream_t* s;
33 if (!muxer) return NULL;
33 if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){ 34 if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
34 printf("Too many streams! increase MUXER_MAX_STREAMS !\n"); 35 printf("Too many streams! increase MUXER_MAX_STREAMS !\n");
35 return NULL; 36 return NULL;
36 } 37 }
37 s=malloc(sizeof(muxer_stream_t)); 38 s=malloc(sizeof(muxer_stream_t));
40 muxer->streams[muxer->avih.dwStreams]=s; 41 muxer->streams[muxer->avih.dwStreams]=s;
41 s->type=type; 42 s->type=type;
42 s->id=muxer->avih.dwStreams; 43 s->id=muxer->avih.dwStreams;
43 s->timer=0.0; 44 s->timer=0.0;
44 s->size=0; 45 s->size=0;
46 s->muxer=muxer;
45 switch(type){ 47 switch(type){
46 case MUXER_TYPE_VIDEO: 48 case MUXER_TYPE_VIDEO:
47 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c'); 49 s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
48 s->h.fccType=streamtypeVIDEO; 50 s->h.fccType=streamtypeVIDEO;
49 if(!muxer->def_v) muxer->def_v=s; 51 if(!muxer->def_v) muxer->def_v=s;
86 } 88 }
87 } 89 }
88 } 90 }
89 } 91 }
90 92
91 static void avifile_write_chunk(muxer_t *muxer,muxer_stream_t *s, FILE *f,size_t len,unsigned int flags){ 93 static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){
94 muxer_t *muxer=s->muxer;
92 95
93 // add to the index: 96 // add to the index:
94 if(muxer->idx_pos>=muxer->idx_size){ 97 if(muxer->idx_pos>=muxer->idx_size){
95 muxer->idx_size+=256; // 4kB 98 muxer->idx_size+=256; // 4kB
96 muxer->idx=realloc(muxer->idx,16*muxer->idx_size); 99 muxer->idx=realloc(muxer->idx,16*muxer->idx_size);
97 } 100 }
98 muxer->idx[muxer->idx_pos].ckid=s->ckid; 101 muxer->idx[muxer->idx_pos].ckid=s->ckid;
99 muxer->idx[muxer->idx_pos].dwFlags=flags; // keyframe? 102 muxer->idx[muxer->idx_pos].dwFlags=flags; // keyframe?
100 muxer->idx[muxer->idx_pos].dwChunkOffset=ftell(f)-(muxer->movi_start-4); 103 muxer->idx[muxer->idx_pos].dwChunkOffset=ftell(muxer->file)-(muxer->movi_start-4);
101 muxer->idx[muxer->idx_pos].dwChunkLength=len; 104 muxer->idx[muxer->idx_pos].dwChunkLength=len;
102 ++muxer->idx_pos; 105 ++muxer->idx_pos;
103 106
104 // write out the chunk: 107 // write out the chunk:
105 write_avi_chunk(f,s->ckid,len,s->buffer); /* unsigned char */ 108 write_avi_chunk(muxer->file,s->ckid,len,s->buffer); /* unsigned char */
106 109
107 // alter counters: 110 // alter counters:
108 if(s->h.dwSampleSize){ 111 if(s->h.dwSampleSize){
109 // CBR 112 // CBR
110 s->h.dwLength+=len/s->h.dwSampleSize; 113 s->h.dwLength+=len/s->h.dwSampleSize;
133 } 136 }
134 137
135 // muxer->streams[i]->wf->cbSize 138 // muxer->streams[i]->wf->cbSize
136 #define WFSIZE(wf) (sizeof(WAVEFORMATEX)+(((wf)->cbSize)?((wf)->cbSize-2):0)) 139 #define WFSIZE(wf) (sizeof(WAVEFORMATEX)+(((wf)->cbSize)?((wf)->cbSize-2):0))
137 140
138 static void avifile_write_header(muxer_t *muxer,FILE *f){ 141 static void avifile_write_header(muxer_t *muxer){
139 uint32_t riff[3]; 142 uint32_t riff[3];
140 unsigned int i; 143 unsigned int i;
141 unsigned int hdrsize; 144 unsigned int hdrsize;
142 muxer_info_t info[16]; 145 muxer_info_t info[16];
146 FILE *f=muxer->file;
143 147
144 // RIFF header: 148 // RIFF header:
145 riff[0]=mmioFOURCC('R','I','F','F'); 149 riff[0]=mmioFOURCC('R','I','F','F');
146 riff[1]=muxer->file_end-2*sizeof(unsigned int); // filesize 150 riff[1]=muxer->file_end-2*sizeof(unsigned int); // filesize
147 riff[2]=formtypeAVI; // 'AVI ' 151 riff[2]=formtypeAVI; // 'AVI '
273 // 'movi' header: 277 // 'movi' header:
274 write_avi_list(f,listtypeAVIMOVIE,muxer->movi_end-ftell(f)-12); 278 write_avi_list(f,listtypeAVIMOVIE,muxer->movi_end-ftell(f)-12);
275 muxer->movi_start=ftell(f); 279 muxer->movi_start=ftell(f);
276 } 280 }
277 281
278 static void avifile_write_index(muxer_t *muxer,FILE *f){ 282 static void avifile_write_index(muxer_t *muxer){
279 muxer->movi_end=ftell(f); 283 muxer->movi_end=ftell(muxer->file);
280 if(muxer->idx && muxer->idx_pos>0){ 284 if(muxer->idx && muxer->idx_pos>0){
281 int i; 285 int i;
282 // fixup index entries: 286 // fixup index entries:
283 // for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4; 287 // for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4;
284 // write index chunk: 288 // write index chunk:
285 for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i])); 289 for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
286 write_avi_chunk(f,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */ 290 write_avi_chunk(muxer->file,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */
287 for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i])); 291 for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
288 muxer->avih.dwFlags|=AVIF_HASINDEX; 292 muxer->avih.dwFlags|=AVIF_HASINDEX;
289 } 293 }
290 muxer->file_end=ftell(f); 294 muxer->file_end=ftell(muxer->file);
291 } 295 }
292 296
293 void muxer_init_muxer_avi(muxer_t *muxer){ 297 void muxer_init_muxer_avi(muxer_t *muxer){
294 muxer->cont_new_stream = &avifile_new_stream; 298 muxer->cont_new_stream = &avifile_new_stream;
295 muxer->cont_write_chunk = &avifile_write_chunk; 299 muxer->cont_write_chunk = &avifile_write_chunk;