[Mplayer-cvslog] CVS: main dec_audio.c,1.36,1.37

Arpi of Ize arpi at mplayer.dev.hu
Sun Sep 2 19:21:54 CEST 2001


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

Modified Files:
	dec_audio.c 
Log Message:
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg

Index: dec_audio.c
===================================================================
RCS file: /cvsroot/mplayer/main/dec_audio.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- dec_audio.c	2 Sep 2001 01:21:34 -0000	1.36
+++ dec_audio.c	2 Sep 2001 17:21:52 -0000	1.37
@@ -137,7 +137,7 @@
   driver=0;
 #else
   /* OggVorbis audio via libvorbis, compatible with files created by nandub and zorannt codec */
-  sh_audio->audio_out_minsize=4096;
+  sh_audio->audio_out_minsize=1024*4; // 1024 samples/frame
 #endif
   break;
 case AFM_PCM:
@@ -335,9 +335,9 @@
   vorbis_info_init(&sh_audio->ov->vi);
   vorbis_comment_init(&sh_audio->ov->vc);
 
-  printf("OggVorbis: cbsize: %i\n", sh_audio->wf->cbSize);
+  mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: cbsize: %i\n", sh_audio->wf->cbSize);
   memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX), 3*sizeof(uint32_t));
-  printf("OggVorbis: Read header sizes: initial: %i comment: %i codebook: %i\n", hdrsizes[0], hdrsizes[1], hdrsizes[2]);
+  mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: Read header sizes: initial: %i comment: %i codebook: %i\n", hdrsizes[0], hdrsizes[1], hdrsizes[2]);
   /*for(i=12; i <= 40; i+=2) { // header bruteforce :)
     memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+i, 3*sizeof(uint32_t));
     printf("OggVorbis: Read header sizes (%i): %ld %ld %ld\n", i, hdrsizes[0], hdrsizes[1], hdrsizes[2]);
@@ -350,18 +350,18 @@
   hdr.packet = realloc(hdr.packet,hdr.bytes);
   memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t),hdr.bytes);
   if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0)
-    printf("OggVorbis: initial (identification) header broken!\n");
+    mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: initial (identification) header broken!\n");
   hdr.b_o_s  = 0;
   hdr.bytes  = hdrsizes[1];
   hdr.packet = realloc(hdr.packet,hdr.bytes);
   memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0],hdr.bytes);
   if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0)
-    printf("OggVorbis: comment header broken!\n");
+    mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: comment header broken!\n");
   hdr.bytes  = hdrsizes[2];
   hdr.packet = realloc(hdr.packet,hdr.bytes);
   memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1],hdr.bytes);
   if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0)
-    printf("OggVorbis: codebook header broken!\n");
+    mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n");
   hdr.bytes=0;
   hdr.packet = realloc(hdr.packet,hdr.bytes); /* free */
   /* done with the headers */
@@ -372,18 +372,18 @@
   {
     char **ptr=sh_audio->ov->vc.user_comments;
     while(*ptr){
-      printf("OggVorbisComment: %s\n",*ptr);
+      mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr);
       ++ptr;
     }
-      printf("OggVorbis: Bitstream is %d channel, %ldHz, %ldkbit/s %cBR\n",sh_audio->ov->vi.channels,sh_audio->ov->vi.rate,sh_audio->ov->vi.bitrate_nominal/1000, (sh_audio->ov->vi.bitrate_lower!=sh_audio->ov->vi.bitrate_nominal)||(sh_audio->ov->vi.bitrate_upper!=sh_audio->ov->vi.bitrate_nominal)?'V':'C');
-      printf("OggVorbis: Encoded by: %s\n",sh_audio->ov->vc.vendor);
+      mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Bitstream is %d channel, %ldHz, %ldkbit/s %cBR\n",sh_audio->ov->vi.channels,sh_audio->ov->vi.rate,sh_audio->ov->vi.bitrate_nominal/1000, (sh_audio->ov->vi.bitrate_lower!=sh_audio->ov->vi.bitrate_nominal)||(sh_audio->ov->vi.bitrate_upper!=sh_audio->ov->vi.bitrate_nominal)?'V':'C');
+      mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Encoded by: %s\n",sh_audio->ov->vc.vendor);
   }
   sh_audio->channels=sh_audio->ov->vi.channels; 
   sh_audio->samplerate=sh_audio->ov->vi.rate;
   sh_audio->i_bps=sh_audio->ov->vi.bitrate_nominal/8;
     
 //  printf("[\n");
-  sh_audio->a_buffer_len=sh_audio->audio_out_minsize;///ov->vi.channels;
+//  sh_audio->a_buffer_len=sh_audio->audio_out_minsize;///ov->vi.channels;
 //  printf("]\n");
 
   /* OK, got and parsed all three headers. Initialize the Vorbis
@@ -399,16 +399,16 @@
 
   while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) {
     if(ret == -1)
-      printf("OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
+      mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
     else
     if(ret == 0) {
-      printf("OggVorbis: Pageout: need more data to verify page, reading more data.\n");
+      mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: need more data to verify page, reading more data.\n");
       /* submit a a_buffer_len  block to libvorbis' Ogg layer */
-      buffer=ogg_sync_buffer(&sh_audio->ov->oy,sh_audio->a_buffer_len);
-      ogg_sync_wrote(&sh_audio->ov->oy,demux_read_data(sh_audio->ds,buffer,sh_audio->a_buffer_len));
+      buffer=ogg_sync_buffer(&sh_audio->ov->oy,256);
+      ogg_sync_wrote(&sh_audio->ov->oy,demux_read_data(sh_audio->ds,buffer,256));
     }
   }
-  printf("OggVorbis: Pageout: successfull.\n");
+  mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: successfull.\n");
   /* commenting out pagein to leave data (hopefully) to the decoder - atmos */
   ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og); /* we can ignore any errors here
   					 as they'll also become apparent
@@ -418,7 +418,7 @@
   /* serialno first; use it to set up a logical stream */
   ogg_stream_init(&sh_audio->ov->os,ogg_page_serialno(&sh_audio->ov->og));
   
-  printf("OggVorbis: Init OK!\n");
+  mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Init OK!\n");
 
   break;
 }
@@ -461,37 +461,40 @@
         int bytes;
 	int samples;
 	float **pcm;
-        ogg_int16_t convbuffer[4096];
-        int convsize;
-        int readlen=4096;
+        //ogg_int16_t convbuffer[4096];
+//        int convsize;
+        int readlen=1024;
         len=0;
-        convsize=readlen/sh_audio->ov->vi.channels;
+//        convsize=minlen/sh_audio->ov->vi.channels;
 
         while(len < minlen) { /* double loop allows for break in inner loop */
         while(len < minlen) { /* without aborting the outer loop - atmos    */
         ret=ogg_stream_packetout(&sh_audio->ov->os,&sh_audio->ov->op);
         if(ret==0) {
+	  int xxx=0;
           //printf("OggVorbis: Packetout: need more data, paging!\n");
           while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) {
             if(ret == -1)
-              printf("OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
+              mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n");
             else
             if(ret == 0) {
               //printf("OggVorbis: Pageout: need more data to verify page, reading more data.\n");
               /* submit a readlen k block to libvorbis' Ogg layer */
               buffer=ogg_sync_buffer(&sh_audio->ov->oy,readlen);
               bytes=demux_read_data(sh_audio->ds,buffer,readlen);
+	      xxx+=bytes;
               ogg_sync_wrote(&sh_audio->ov->oy,bytes);
               if(bytes==0)
-                printf("OggVorbis: 0Bytes written, possible End of Stream\n");
+                mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: 0Bytes written, possible End of Stream\n");
             }
           }
+	  mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[sync: %d ]\n",xxx);
           //printf("OggVorbis: Pageout: successfull, pagin in.\n");
           if(ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og)<0)
-            printf("OggVorbis: Pagein failed!\n");
+            mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pagein failed!\n");
           break;
         } else if(ret<0) {
-          printf("OggVorbis: Packetout: missing or corrupt data, skipping packet!\n");
+          mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Packetout: missing or corrupt data, skipping packet!\n");
           break;
         } else {
 
@@ -508,11 +511,15 @@
         while((samples=vorbis_synthesis_pcmout(&sh_audio->ov->vd,&pcm))>0){
 	  int i,j;
 	  int clipflag=0;
+	  int convsize=(maxlen-len)/(2*sh_audio->ov->vi.channels); // max size!
 	  int bout=(samples<convsize?samples:convsize);
-		
+	  
+	  if(bout<=0) break;
+
 	  /* convert floats to 16 bit signed ints (host order) and
 	     interleave */
 	  for(i=0;i<sh_audio->ov->vi.channels;i++){
+    	    ogg_int16_t *convbuffer=(ogg_int16_t *)(&buf[len]);
 	    ogg_int16_t *ptr=convbuffer+i;
 	    float  *mono=pcm[i];
 	    for(j=0;j<bout;j++){
@@ -536,12 +543,14 @@
 	  }
 		
 	  if(clipflag)
-	    printf("Clipping in frame %ld\n",(long)(sh_audio->ov->vd.sequence));
+	    mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"Clipping in frame %ld\n",(long)(sh_audio->ov->vd.sequence));
 	
 	  //fwrite(convbuffer,2*sh_audio->ov->vi.channels,bout,stderr); //dump pcm to file for debugging
-	  memcpy(buf+len,convbuffer,2*sh_audio->ov->vi.channels*bout);
+	  //memcpy(buf+len,convbuffer,2*sh_audio->ov->vi.channels*bout);
           len+=2*sh_audio->ov->vi.channels*bout;
-		
+	  
+	  mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[decoded: %d / %d ]\n",bout,samples);
+	  
 	  vorbis_synthesis_read(&sh_audio->ov->vd,bout); /* tell libvorbis how
 							    many samples we
 							    actually consumed */
@@ -550,8 +559,9 @@
         } // while len
         } // outer while len
 	if(ogg_page_eos(&sh_audio->ov->og))
-          printf("OggVorbis: End of Stream reached!\n"); // FIXME clearup decoder, notify mplayer - atmos
+          mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: End of Stream reached!\n"); // FIXME clearup decoder, notify mplayer - atmos
 
+	mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[len: %d ]\n",len);
 
         break;
       }




More information about the MPlayer-cvslog mailing list