Index: aviwrite.c =================================================================== RCS file: /cvsroot/mplayer/main/libmpdemux/aviwrite.c,v retrieving revision 1.7 diff -u -r1.7 aviwrite.c --- aviwrite.c 12 Apr 2002 10:40:38 -0000 1.7 +++ aviwrite.c 22 Jul 2002 01:30:28 -0000 @@ -13,8 +13,10 @@ #include "wine/mmreg.h" #include "wine/avifmt.h" #include "wine/vfw.h" +#include "bswap.h" #include "aviwrite.h" +#include "aviheader.h" aviwrite_stream_t* aviwrite_new_stream(aviwrite_t *muxer,int type){ aviwrite_stream_t* s; @@ -55,8 +57,17 @@ } static void write_avi_chunk(FILE *f,unsigned int id,int len,void* data){ -fwrite(&id,4,1,f); -fwrite(&len,4,1,f); +#ifdef WORDS_BIGENDIAN + register int i; + int le_len = le2me_32(len); + int le_id = le2me_32(id); + fwrite(&le_id,4,1,f); + fwrite(&le_len,4,1,f); +#else + fwrite(&id,4,1,f); + fwrite(&len,4,1,f); +#endif + if(len>0){ if(data){ // DATA @@ -80,7 +91,6 @@ } void aviwrite_write_chunk(aviwrite_t *muxer,aviwrite_stream_t *s, FILE *f,int len,unsigned int flags){ - // add to the index: if(muxer->idx_pos>=muxer->idx_size){ muxer->idx_size+=256; // 4kB @@ -93,8 +103,8 @@ ++muxer->idx_pos; // write out the chunk: - write_avi_chunk(f,s->ckid,len,s->buffer); - + write_avi_chunk(f,s->ckid,len,s->buffer); /* unsigned char */ +/*#endif*/ // alter counters: if(s->h.dwSampleSize){ // CBR @@ -112,10 +122,21 @@ static void write_avi_list(FILE *f,unsigned int id,int len){ unsigned int list_id=FOURCC_LIST; + int le_len; + int le_id; len+=4; // list fix +#ifdef WORDS_BIGENDIAN + list_id = le2me_32(list_id); + le_len = le2me_32(len); + le_id = le2me_32(id); + fwrite(&list_id,4,1,f); + fwrite(&le_len,4,1,f); + fwrite(&le_id,4,1,f); +#else fwrite(&list_id,4,1,f); fwrite(&len,4,1,f); fwrite(&id,4,1,f); +#endif } // muxer->streams[i]->wf->cbSize @@ -129,8 +150,14 @@ riff[0]=mmioFOURCC('R','I','F','F'); riff[1]=muxer->file_end; // filesize riff[2]=formtypeAVI; // 'AVI ' +printf("muxer->file_end = %d\n",riff[1]); +#ifdef WORDS_BIGENDIAN + riff[0]=le2me_32(riff[0]); + riff[1]=le2me_32(riff[1]); + riff[2]=le2me_32(riff[2]); +#endif fwrite(&riff,12,1,f); - + // update AVI header: if(muxer->def_v){ muxer->avih.dwMicroSecPerFrame=1000000.0*muxer->def_v->h.dwScale/muxer->def_v->h.dwRate; @@ -159,8 +186,16 @@ } } write_avi_list(f,listtypeAVIHEADER,hdrsize); - write_avi_chunk(f,ckidAVIMAINHDR,sizeof(muxer->avih),&muxer->avih); - + +/* for BE machines */ +#ifdef WORDS_BIGENDIAN + le2me_MainAVIHeader(&muxer->avih); +#endif + write_avi_chunk(f,ckidAVIMAINHDR,sizeof(muxer->avih),&muxer->avih); /* MainAVIHeader */ +/* put it back as it was */ +#ifdef WORDS_BIGENDIAN + le2me_MainAVIHeader(&muxer->avih); +#endif // stream headers: for(i=0;iavih.dwStreams;i++){ hdrsize=sizeof(muxer->streams[i]->h)+8; // strh @@ -173,21 +208,50 @@ break; } write_avi_list(f,listtypeSTREAMHEADER,hdrsize); - write_avi_chunk(f,ckidSTREAMHEADER,sizeof(muxer->streams[i]->h),&muxer->streams[i]->h); // strh +#ifdef WORDS_BIGENDIAN + le2me_AVIStreamHeader(&muxer->streams[i]->h); +#endif + write_avi_chunk(f,ckidSTREAMHEADER,sizeof(muxer->streams[i]->h),&muxer->streams[i]->h); /* AVISTreamHeader */ // strh +/* put it back as it was */ +#ifdef WORDS_BIGENDIAN + le2me_AVIStreamHeader(&muxer->streams[i]->h); +#endif switch(muxer->streams[i]->type){ case AVIWRITE_TYPE_VIDEO: - write_avi_chunk(f,ckidSTREAMFORMAT,muxer->streams[i]->bih->biSize,muxer->streams[i]->bih); +#ifdef WORDS_BIGENDIAN +{ + int biSize=muxer->streams[i]->bih->biSize; + le2me_BITMAPINFOHEADER(muxer->streams[i]->bih); + write_avi_chunk(f,ckidSTREAMFORMAT,biSize,muxer->streams[i]->bih); /* BITMAPINFOHEADER */ + /* put it back as it was */ + le2me_BITMAPINFOHEADER(muxer->streams[i]->bih); +} +#else + write_avi_chunk(f,ckidSTREAMFORMAT,muxer->streams[i]->bih->biSize,muxer->streams[i]->bih); /* BITMAPINFOHEADER */ +#endif break; case AVIWRITE_TYPE_AUDIO: - write_avi_chunk(f,ckidSTREAMFORMAT,WFSIZE(muxer->streams[i]->wf),muxer->streams[i]->wf); +#ifdef WORDS_BIGENDIAN +{ + int wfsize = WFSIZE(muxer->streams[i]->wf); + le2me_WAVEFORMATEX(muxer->streams[i]->wf); + write_avi_chunk(f,ckidSTREAMFORMAT,wfsize,muxer->streams[i]->wf); /* WAVEFORMATEX */ + /* put it back as it was */ + le2me_WAVEFORMATEX(muxer->streams[i]->wf); +} +#else + write_avi_chunk(f,ckidSTREAMFORMAT,WFSIZE(muxer->streams[i]->wf),muxer->streams[i]->wf); /* WAVEFORMATEX */ +#endif break; } } // JUNK: - write_avi_chunk(f,ckidAVIPADDING,2048-(ftell(f)&2047)-8,NULL); + write_avi_chunk(f,ckidAVIPADDING,2048-(ftell(f)&2047)-8,NULL); /* junk */ + // 'movi' header: write_avi_list(f,listtypeAVIMOVIE,muxer->movi_end-ftell(f)-12); + muxer->movi_start=ftell(f); } @@ -198,7 +262,17 @@ // int i; // for(i=0;iidx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4; // write index chunk: - write_avi_chunk(f,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); +#ifdef WORDS_BIGENDIAN +{ + int pos=16*muxer->idx_pos; + le2me_AVIINDEXENTRY(muxer->idx); + write_avi_chunk(f,ckidAVINEWINDEX,pos,muxer->idx); /* AVIINDEXENTRY */ + /* put it back as it was */ + le2me_AVIINDEXENTRY(muxer->idx); +} +#else + write_avi_chunk(f,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */ +#endif muxer->avih.dwFlags|=AVIF_HASINDEX; } muxer->file_end=ftell(f);