[Mplayer-cvslog] CVS: main/libmpdemux aviwrite.c,1.7,1.8

Arpi of Ize arpi at mplayerhq.hu
Mon Aug 5 13:26:38 CEST 2002


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv27487

Modified Files:
	aviwrite.c 
Log Message:
PPC endianess fix by Colin Leroy <colin at colino.net>


Index: aviwrite.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/aviwrite.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- aviwrite.c	12 Apr 2002 10:40:38 -0000	1.7
+++ aviwrite.c	5 Aug 2002 11:26:26 -0000	1.8
@@ -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,11 @@
 }
 
 static void write_avi_chunk(FILE *f,unsigned int id,int len,void* data){
-fwrite(&id,4,1,f);
-fwrite(&len,4,1,f);
+ int le_len = le2me_32(len);
+ int le_id = le2me_32(id);
+ fwrite(&le_id,4,1,f);
+ fwrite(&le_len,4,1,f);
+
 if(len>0){
   if(data){
     // DATA
@@ -93,8 +98,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 */
+
     // alter counters:
     if(s->h.dwSampleSize){
 	// CBR
@@ -112,10 +117,15 @@
 
 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
+  list_id = le2me_32(list_id);
+  le_len = le2me_32(len);
+  le_id = le2me_32(id);
   fwrite(&list_id,4,1,f);
-  fwrite(&len,4,1,f);
-  fwrite(&id,4,1,f);
+  fwrite(&le_len,4,1,f);
+  fwrite(&le_id,4,1,f);
 }
 
 // muxer->streams[i]->wf->cbSize
@@ -126,11 +136,22 @@
   int i;
   unsigned int hdrsize;
   // RIFF header:
+#ifdef WORDS_BIGENDIAN 
+  /* FIXME: updating the header on big-endian causes the video
+   * to be unreadable ("AVI_NI: No video stream found!").
+   * Just don't update it (no seeking, not playable with WMP,
+   * but better than nothing)
+   */
+  if(muxer->file_end != 0)
+      return;
+#endif
   riff[0]=mmioFOURCC('R','I','F','F');
   riff[1]=muxer->file_end;  // filesize
   riff[2]=formtypeAVI; // 'AVI '
+  riff[0]=le2me_32(riff[0]);
+  riff[1]=le2me_32(riff[1]);
+  riff[2]=le2me_32(riff[2]);
   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,7 +180,10 @@
       }
   }
   write_avi_list(f,listtypeAVIHEADER,hdrsize);
-  write_avi_chunk(f,ckidAVIMAINHDR,sizeof(muxer->avih),&muxer->avih);
+  
+  le2me_MainAVIHeader(&muxer->avih);
+  write_avi_chunk(f,ckidAVIMAINHDR,sizeof(muxer->avih),&muxer->avih); /* MainAVIHeader */
+  le2me_MainAVIHeader(&muxer->avih);
 
   // stream headers:
   for(i=0;i<muxer->avih.dwStreams;i++){
@@ -173,19 +197,32 @@
 	  break;
       }
       write_avi_list(f,listtypeSTREAMHEADER,hdrsize);
-      write_avi_chunk(f,ckidSTREAMHEADER,sizeof(muxer->streams[i]->h),&muxer->streams[i]->h); // strh
+      le2me_AVIStreamHeader(&muxer->streams[i]->h);
+      write_avi_chunk(f,ckidSTREAMHEADER,sizeof(muxer->streams[i]->h),&muxer->streams[i]->h); /* AVISTreamHeader */ // strh
+      le2me_AVIStreamHeader(&muxer->streams[i]->h);
+
       switch(muxer->streams[i]->type){
       case AVIWRITE_TYPE_VIDEO:
-          write_avi_chunk(f,ckidSTREAMFORMAT,muxer->streams[i]->bih->biSize,muxer->streams[i]->bih);
+{
+          int biSize=muxer->streams[i]->bih->biSize;
+          le2me_BITMAPINFOHEADER(muxer->streams[i]->bih);
+          write_avi_chunk(f,ckidSTREAMFORMAT,biSize,muxer->streams[i]->bih); /* BITMAPINFOHEADER */
+          le2me_BITMAPINFOHEADER(muxer->streams[i]->bih);
+}
 	  break;
       case AVIWRITE_TYPE_AUDIO:
-          write_avi_chunk(f,ckidSTREAMFORMAT,WFSIZE(muxer->streams[i]->wf),muxer->streams[i]->wf);
+{
+          int wfsize = WFSIZE(muxer->streams[i]->wf);
+          le2me_WAVEFORMATEX(muxer->streams[i]->wf);
+          write_avi_chunk(f,ckidSTREAMFORMAT,wfsize,muxer->streams[i]->wf); /* WAVEFORMATEX */
+          le2me_WAVEFORMATEX(muxer->streams[i]->wf);
+}	  
 	  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);
@@ -194,11 +231,13 @@
 void aviwrite_write_index(aviwrite_t *muxer,FILE *f){
   muxer->movi_end=ftell(f);
   if(muxer->idx && muxer->idx_pos>0){
+      int i;
       // fixup index entries:
-//      int i;
 //      for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4;
       // write index chunk:
-      write_avi_chunk(f,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx);
+      for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
+      write_avi_chunk(f,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */
+      for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
       muxer->avih.dwFlags|=AVIF_HASINDEX;
   }
   muxer->file_end=ftell(f);




More information about the MPlayer-cvslog mailing list