[Mplayer-cvslog] CVS: main/libmpdemux asfheader.c,1.28,1.29

Alban Bedel CVS albeu at mplayer.dev.hu
Tue Feb 5 17:50:13 CET 2002


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

Modified Files:
	asfheader.c 
Log Message:
Added auto selection of the best streams and fixed a few compiler
warnings


Index: asfheader.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/asfheader.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- asfheader.c	26 Jan 2002 01:21:41 -0000	1.28
+++ asfheader.c	5 Feb 2002 16:50:10 -0000	1.29
@@ -129,9 +129,13 @@
 
 int read_asf_header(demuxer_t *demuxer){
   static unsigned char buffer[1024];
+  uint32_t* streams = NULL;
   int audio_streams=0;
   int video_streams=0;
-  
+  uint16_t stream_count=0;
+  int best_video = -1;
+  int best_audio = -1;
+
 #if 1
   //printf("ASF file! (subchunks: %d)\n",asfh.cno);
 while(!stream_eof(demuxer->stream)){
@@ -184,7 +188,7 @@
         }
       case ASF_GUID_PREFIX_video_stream: {
         sh_video_t* sh_video=new_sh_video(demuxer,streamh.stream_no & 0x7F);
-        int len=streamh.type_size-(4+4+1+2);
+        unsigned int len=streamh.type_size-(4+4+1+2);
 	++video_streams;
 //        sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize);
         sh_video->bih=calloc((len<sizeof(BITMAPINFOHEADER))?sizeof(BITMAPINFOHEADER):len,1);
@@ -276,11 +280,11 @@
       break;
     }
     case ASF_GUID_PREFIX_stream_group: {
-        uint16_t stream_count, stream_id, i;
+        uint16_t stream_id, i;
         uint32_t max_bitrate;
         char *object=NULL, *ptr=NULL;
         printf("============ ASF Stream group == START ===\n");
-        printf(" object size = %d\n", objh.size);
+        printf(" object size = %d\n", (int)objh.size);
         object = (char*)malloc(objh.size);
 	if( object==NULL ) {
           printf("Memory allocation failed\n");
@@ -291,6 +295,8 @@
 	ptr = object;
         stream_count = *(uint16_t*)ptr;
         ptr += sizeof(uint16_t);
+        if(stream_count > 0)
+              streams = (uint32_t*)malloc(2*stream_count*sizeof(uint32_t));
         printf(" stream count=[0x%x][%u]\n", stream_count, stream_count );
         for( i=0 ; i<stream_count && ptr<((char*)object+objh.size) ; i++ ) {
           stream_id = *(uint16_t*)ptr;
@@ -299,6 +305,8 @@
           max_bitrate = *(uint32_t*)ptr;
           ptr += sizeof(uint32_t);
           printf("   max bitrate=[0x%x][%u]\n", max_bitrate, max_bitrate );
+          streams[2*i] = stream_id;
+          streams[2*i+1] = max_bitrate;
         }
         printf("============ ASF Stream group == END ===\n");
         free( object );
@@ -311,15 +319,32 @@
   if(!stream_seek(demuxer->stream,endpos)) break;
 } // while EOF
 
+if(streams) {
+  uint32_t vr = 0, ar = 0,i;
+  for(i = 0; i < stream_count; i++) {
+    uint32_t id = streams[2*i];
+    uint32_t rate = streams[2*i+1];
+    if(demuxer->v_streams[id] && rate > vr) {
+      vr = rate;
+      best_video = id;
+    } else if(demuxer->a_streams[id] && rate > ar) {
+      ar = rate;
+      best_audio = id;
+    }
+  }
+  free(streams);
+}
+
 mp_msg(MSGT_HEADER,MSGL_V,"ASF: %d audio and %d video streams found\n",audio_streams,video_streams);
 if(!audio_streams) demuxer->audio->id=-2;  // nosound
+else if(best_audio > 0 && demuxer->audio->id == -1) demuxer->audio->id=best_audio;
 if(!video_streams){
     if(!audio_streams){
 	mp_msg(MSGT_HEADER,MSGL_ERR,"ASF: no audio or video headers found - broken file?\n");
 	return 0; 
     }
     demuxer->video->id=-2; // audio-only
-}
+} else if (best_video > 0 && demuxer->video->id == -1) demuxer->video->id = best_video;
 
 #if 0
 if(verbose){




More information about the MPlayer-cvslog mailing list