[MPlayer-cvslog] r27668 - trunk/TOOLS/asfinfo.c

diego subversion at mplayerhq.hu
Sun Sep 28 12:14:46 CEST 2008


Author: diego
Date: Sun Sep 28 12:14:45 2008
New Revision: 27668

Log:
cosmetics: prettyprinting


Modified:
   trunk/TOOLS/asfinfo.c

Modified: trunk/TOOLS/asfinfo.c
==============================================================================
--- trunk/TOOLS/asfinfo.c	(original)
+++ trunk/TOOLS/asfinfo.c	Sun Sep 28 12:14:45 2008
@@ -6,46 +6,46 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-typedef struct __attribute__((packed)) 
+typedef struct __attribute__((packed))
 {
-    long        biSize; // sizeof(BITMAPINFOHEADER)
-    long        biWidth;
-    long        biHeight;
-    short       biPlanes; // unused
-    short       biBitCount;
-    long        biCompression; // fourcc of image
-    long        biSizeImage;   // size of image. For uncompressed images
-                               // ( biCompression 0 or 3 ) can be zero.
+  long      biSize;          // sizeof(BITMAPINFOHEADER)
+  long      biWidth;
+  long      biHeight;
+  short     biPlanes;        // unused
+  short     biBitCount;
+  long      biCompression;   // fourcc of image
+  long      biSizeImage;     // size of image. For uncompressed images
+                             // ( biCompression 0 or 3 ) can be zero.
 
 
-    long        biXPelsPerMeter; // unused
-    long        biYPelsPerMeter; // unused
-    long        biClrUsed;     // valid only for palettized images.
-                               // Number of colors in palette.
-    long        biClrImportant;
+  long      biXPelsPerMeter; // unused
+  long      biYPelsPerMeter; // unused
+  long      biClrUsed;       // valid only for palettized images.
+                             // Number of colors in palette.
+  long      biClrImportant;
 } BITMAPINFOHEADER;
 
 typedef struct
 {
-  short   wFormatTag; // value that identifies compression format
-  short   nChannels;
-  long  nSamplesPerSec;
-  long  nAvgBytesPerSec;
-  short   nBlockAlign; // size of a data sample
-  short   wBitsPerSample;
-  short   cbSize;    // size of format-specific data
+  short     wFormatTag;      // value that identifies compression format
+  short     nChannels;
+  long      nSamplesPerSec;
+  long      nAvgBytesPerSec;
+  short     nBlockAlign;     // size of a data sample
+  short     wBitsPerSample;
+  short     cbSize;          // size of format-specific data
 } WAVEFORMATEX;
 
 typedef struct __attribute__((packed)) {
-  unsigned char guid[16];
+  unsigned char      guid[16];
   unsigned long long size;
 } ASF_obj_header_t;
 
 typedef struct __attribute__((packed)) {
   ASF_obj_header_t objh;
-  unsigned int cno; // number of subchunks
-  unsigned char v1; // unknown (0x01)
-  unsigned char v2; // unknown (0x02)
+  unsigned int     cno; // number of subchunks
+  unsigned char    v1; // unknown (0x01)
+  unsigned char    v2; // unknown (0x02)
 } ASF_header_t;
 
 typedef struct __attribute__((packed)) {
@@ -106,150 +106,168 @@ static char* chunk_type(unsigned char* g
 }
 
 static void print_wave_header(WAVEFORMATEX *h){
-
   printf("======= WAVE Format =======\n");
-  
-  printf("Format Tag: %d (0x%X)\n",h->wFormatTag,h->wFormatTag);
-  printf("Channels: %d\n",h->nChannels);
-  printf("Samplerate: %ld\n",h->nSamplesPerSec);
-  printf("avg byte/sec: %ld\n",h->nAvgBytesPerSec);
-  printf("Block align: %d\n",h->nBlockAlign);
-  printf("bits/sample: %d\n",h->wBitsPerSample);
-  printf("cbSize: %d\n",h->cbSize);
-  
+
+  printf("Format Tag: %d (0x%X)\n", h->wFormatTag, h->wFormatTag);
+  printf("Channels: %d\n", h->nChannels);
+  printf("Samplerate: %ld\n", h->nSamplesPerSec);
+  printf("avg byte/sec: %ld\n", h->nAvgBytesPerSec);
+  printf("Block align: %d\n", h->nBlockAlign);
+  printf("bits/sample: %d\n", h->wBitsPerSample);
+  printf("cbSize: %d\n", h->cbSize);
+
   switch(h->wFormatTag){
-      case 0x01:        printf("Audio in PCM format\n");break;
-      case 0x50:        printf("Audio in MPEG Layer 1/2 format\n");break;
-      case 0x55:        printf("Audio in MPEG Layer-3 format\n");break; // ACM
-      case 0x02:        printf("Audio in MS ADPCM format\n");break;  // ACM
-      case 0x11:        printf("Audio in IMA ADPCM format\n");break; // ACM
-      case 0x31:
-      case 0x32:        printf("Audio in MS GSM 6.10 format\n");break; // ACM
-      case 0x160:
-      case 0x161:       printf("Audio in DivX WMA format\n");break; // ACM
-      default:          printf("Audio in UNKNOWN (id=0x%X) format\n",h->wFormatTag);
+    case 0x01:        printf("Audio in PCM format\n"); break;
+    case 0x50:        printf("Audio in MPEG Layer 1/2 format\n"); break;
+    case 0x55:        printf("Audio in MPEG Layer-3 format\n"); break; // ACM
+    case 0x02:        printf("Audio in MS ADPCM format\n"); break;  // ACM
+    case 0x11:        printf("Audio in IMA ADPCM format\n"); break; // ACM
+    case 0x31:
+    case 0x32:        printf("Audio in MS GSM 6.10 format\n"); break; // ACM
+    case 0x160:
+    case 0x161:       printf("Audio in DivX WMA format\n"); break; // ACM
+    default:          printf("Audio in UNKNOWN (id=0x%X) format\n", h->wFormatTag);
   }
 
   printf("===========================\n");
-  
-
 }
 
 static void print_video_header(BITMAPINFOHEADER *h){
   printf("======= VIDEO Format ======\n");
-	printf("  biSize %ld\n", h->biSize);
-	printf("  biWidth %ld\n", h->biWidth);
-	printf("  biHeight %ld\n", h->biHeight);
-	printf("  biPlanes %d\n", h->biPlanes);
-	printf("  biBitCount %d\n", h->biBitCount);
-	printf("  biCompression %ld='%.4s'\n", h->biCompression, &h->biCompression);
-	printf("  biSizeImage %ld\n", h->biSizeImage);
+  printf("  biSize %ld\n", h->biSize);
+  printf("  biWidth %ld\n", h->biWidth);
+  printf("  biHeight %ld\n", h->biHeight);
+  printf("  biPlanes %d\n", h->biPlanes);
+  printf("  biBitCount %d\n", h->biBitCount);
+  printf("  biCompression %ld='%.4s'\n", h->biCompression, &h->biCompression);
+  printf("  biSizeImage %ld\n", h->biSizeImage);
   printf("===========================\n");
 }
 
 FILE* streams[128];
 
-int main(int argc,char* argv[]){
-FILE *f=fopen(argc>1?argv[1]:"Alice Deejay - Back In My Life.asf","rb");
+int main(int argc, char* argv[]){
+  FILE *f = fopen(argc > 1 ? argv[1] : "Alice Deejay - Back In My Life.asf", "rb");
 
-if(!f){ printf("file not found\n");exit(1);}
+  if(!f){
+    printf("file not found\n");
+    exit(1);
+  }
 
-//printf("sizeof=%d\n",sizeof(objh));
-//printf("sizeof=%d\n",sizeof(asfh));
+  //printf("sizeof=%d\n", sizeof(objh));
+  //printf("sizeof=%d\n", sizeof(asfh));
 
-fread(&asfh,sizeof(asfh),1,f); // header obj
-//for(i=0;i<16;i++) printf("%02X ",asfh.objh.guid[i]);
-printf("[%s] %d  (subchunks: %d)\n",chunk_type(asfh.objh.guid),(int) asfh.objh.size,asfh.cno);
+  fread(&asfh, sizeof(asfh), 1, f); // header obj
+  //for(i = 0; i < 16; i++)
+  //  printf("%02X ", asfh.objh.guid[i]);
+  printf("[%s] %d  (subchunks: %d)\n", chunk_type(asfh.objh.guid),
+         (int) asfh.objh.size, asfh.cno);
 
-while(fread(&objh,sizeof(objh),1,f)>0){
-  int pos=ftell(f);
-//  for(i=0;i<16;i++) printf("%02X ",objh.guid[i]);
-  printf("0x%08X  [%s] %d\n",pos-sizeof(objh), chunk_type(objh.guid),(int) objh.size);
-  switch(*((unsigned int*)&objh.guid)){
-    case 0xB7DC0791: // guid_stream_header
-      fread(&streamh,sizeof(streamh),1,f);
-      printf("stream type: %s\n",chunk_type(streamh.type));
-      printf("stream concealment: %s\n",chunk_type(streamh.concealment));
-      printf("type: %d bytes,  stream: %d bytes  ID: %d\n",(int)streamh.type_size,(int)streamh.stream_size,(int)streamh.stream_no);
-      printf("FILEPOS=0x%lX\n",ftell(f));
-      // type-specific data:
-      fread(buffer,streamh.type_size,1,f);
-      switch(*((unsigned int*)&streamh.type)){
-      case 0xF8699E40:  // guid_audio_stream
-        print_wave_header((WAVEFORMATEX*)buffer);
+  while(fread(&objh, sizeof(objh), 1, f) > 0){
+    int pos = ftell(f);
+    //for(i = 0; i < 16; i++)
+    //  printf("%02X ", objh.guid[i]);
+    printf("0x%08X  [%s] %d\n", pos-sizeof(objh), chunk_type(objh.guid),
+           (int) objh.size);
+    switch(*((unsigned int*)&objh.guid)){
+      case 0xB7DC0791: // guid_stream_header
+        fread(&streamh, sizeof(streamh), 1, f);
+        printf("stream type: %s\n", chunk_type(streamh.type));
+        printf("stream concealment: %s\n", chunk_type(streamh.concealment));
+        printf("type: %d bytes,  stream: %d bytes  ID: %d\n",
+               (int)streamh.type_size, (int)streamh.stream_size,
+               (int)streamh.stream_no);
+        printf("FILEPOS=0x%lX\n", ftell(f));
+        // type-specific data:
+        fread(buffer,streamh.type_size,1,f);
+        switch(*((unsigned int*)&streamh.type)){
+        case 0xF8699E40:  // guid_audio_stream
+          print_wave_header((WAVEFORMATEX*)buffer);
+          break;
+        case 0xBC19EFC0:  // guid_video_stream
+          print_video_header((BITMAPINFOHEADER*)&buffer[4 + 4 + 1 + 2]);
+          break;
+        }
+        // stream-specific data:
+        fread(buffer, streamh.stream_size, 1, f);
         break;
-      case 0xBC19EFC0:  // guid_video_stream
-        print_video_header((BITMAPINFOHEADER*)&buffer[4+4+1+2]);
+      //case 0xD6E229D1:
+      //  return "guid_header_2_0";
+      case 0x8CABDCA1: // guid_file_header
+        fread(&fileh, sizeof(fileh), 1, f);
+        printf("packets: %d  flags: %d  pack_size: %d  frame_size: %d\n",
+               (int)fileh.packets, (int)fileh.flags, (int)fileh.packetsize,
+               (int)fileh.frame_size);
         break;
-      }
-      // stream-specific data:
-      fread(buffer,streamh.stream_size,1,f);
-      break;
-//    case 0xD6E229D1: return "guid_header_2_0";
-    case 0x8CABDCA1: // guid_file_header
-      fread(&fileh,sizeof(fileh),1,f);
-      printf("packets: %d  flags: %d  pack_size: %d  frame_size: %d\n",(int)fileh.packets,(int)fileh.flags,(int)fileh.packetsize,(int)fileh.frame_size);
-      break;
-    case 0x75b22636: // guid_data_chunk
-      { int endp=pos+objh.size-sizeof(objh);
-        unsigned char* packet=malloc((int)fileh.packetsize);
-        int fpos;
-        fseek(f,26,SEEK_CUR);
-        while((fpos=ftell(f))<endp){
-          fread(packet,(int)fileh.packetsize,1,f);
-          if(packet[0]==0x82){
-            unsigned char flags=packet[3];
-            unsigned char* p=&packet[5];
-            unsigned long time;
-            unsigned short duration;
-            int segs=1;
-            int seg;
-            int padding=0;
-            if(flags&8){
-              padding=p[0];++p;
-            } else
-            if(flags&16){
-              padding=p[0]|(p[1]<<8);p+=2;
-            }
-            time=*((unsigned long*)p);p+=4;
-            duration=*((unsigned short*)p);p+=2;
-            if(flags&1){
-              segs=p[0]-0x80;++p;
-            }
-            printf("%08X:  flag=%02X  segs=%d  pad=%d  time=%ld  dur=%d\n",
-              fpos,flags,segs,padding,time,duration);
-            for(seg=0;seg<segs;seg++){
-              ASF_segmhdr_t* sh=(ASF_segmhdr_t*)p;
-              int len=0;
-              p+=sizeof(ASF_segmhdr_t);
-              if(sh->flag&8) p+=8;// else
-              if(sh->flag&1) ++p;
-              if(flags&1){
-                len=*((unsigned short*)p);p+=2;
+      case 0x75b22636: // guid_data_chunk
+        { int endp = pos + objh.size - sizeof(objh);
+          unsigned char* packet = malloc((int)fileh.packetsize);
+          int fpos;
+          fseek(f, 26, SEEK_CUR);
+          while((fpos = ftell(f)) < endp){
+            fread(packet, (int)fileh.packetsize, 1, f);
+            if(packet[0] == 0x82){
+              unsigned char flags = packet[3];
+              unsigned char* p = &packet[5];
+              unsigned long time;
+              unsigned short duration;
+              int segs = 1;
+              int seg;
+              int padding=0;
+              if(flags & 8){
+                padding = p[0];
+                ++p;
+              } else
+              if(flags & 16){
+                padding = p[0] | (p[1] << 8);
+                p += 2;
               }
-              printf("  seg #%d: streamno=%d  seq=%d  flag=%02X  len=%d\n",seg,sh->streamno&0x7F,sh->seq,sh->flag,len);
-#ifdef SAVE_STREAMS
-              if(!streams[sh->streamno&0x7F]){
-                char name[256];
-                snprintf(name,256,"stream%02X.dat",sh->streamno&0x7F);
-                streams[sh->streamno&0x7F]=fopen(name,"wb");
+              time = *((unsigned long*)p);
+              p += 4;
+              duration = *((unsigned short*)p);
+              p += 2;
+              if(flags & 1){
+                segs = p[0] - 0x80;
+                ++p;
               }
-              fwrite(p,len,1,streams[sh->streamno&0x7F]);
-#endif
-              p+=len;
-            }
-          } else
-            printf("%08X:  UNKNOWN  %02X %02X %02X %02X %02X...\n",fpos,packet[0],packet[1],packet[2],packet[3],packet[4]);
+              printf("%08X:  flag=%02X  segs=%d  pad=%d  time=%ld  dur=%d\n",
+                     fpos, flags, segs, padding, time, duration);
+              for(seg = 0; seg < segs; seg++){
+                ASF_segmhdr_t* sh = (ASF_segmhdr_t*)p;
+                int len = 0;
+                p += sizeof(ASF_segmhdr_t);
+                if(sh->flag & 8) p+=8;// else
+                if(sh->flag & 1) ++p;
+                if(flags & 1){
+                  len = *((unsigned short*)p);
+                  p += 2;
+                }
+                printf("  seg #%d: streamno=%d  seq=%d  flag=%02X  len=%d\n",
+                       seg, sh->streamno&0x7F, sh->seq, sh->flag, len);
+  #ifdef SAVE_STREAMS
+                if(!streams[sh->streamno & 0x7F]){
+                  char name[256];
+                  snprintf(name, 256, "stream%02X.dat", sh->streamno & 0x7F);
+                  streams[sh->streamno & 0x7F] = fopen(name, "wb");
+                }
+                fwrite(p, len, 1, streams[sh->streamno & 0x7F]);
+  #endif
+                p += len;
+              }
+            } else
+              printf("%08X:  UNKNOWN  %02X %02X %02X %02X %02X...\n", fpos,
+                     packet[0], packet[1], packet[2], packet[3], packet[4]);
+          }
         }
-      }
-      break;
+        break;
 
-//    case 0x33000890: return "guid_index_chunk";
+        //case 0x33000890:
+        //  return "guid_index_chunk";
 
+    }
+    fseek(f, pos + objh.size - sizeof(objh), SEEK_SET);
   }
-  fseek(f,pos+objh.size-sizeof(objh),SEEK_SET);
-}
 
-return 0;
+  return 0;
 }
 



More information about the MPlayer-cvslog mailing list