[Mplayer-cvslog] CVS: main/libao2 ao_dxr3.c,1.7,1.8

David Holm mswitch at mplayer.dev.hu
Fri Nov 30 21:01:02 CET 2001


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

Modified Files:
	ao_dxr3.c 
Log Message:
ao_dxr3.c:
Decided to go with a calculated rate instead of retun 0.0 in get_delay
Added upsampling since the DXR3 only supports 44100Hz and 48000Hz

vo_dxr3.c:
Fixed stride bug when playing back YUY2 streams
Removed some code which could cause mplayer to lock up on exit
Added BGR24 support for codecs that don't support YUY2 (xanim codecs?)
Fixed another bug in the YV12 playback that caused the last few lines being cropped


Index: ao_dxr3.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_dxr3.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ao_dxr3.c	30 Nov 2001 16:11:36 -0000	1.7
+++ ao_dxr3.c	30 Nov 2001 20:01:00 -0000	1.8
@@ -34,7 +34,6 @@
 static audio_buf_info dxr3_buf_info;
 static int fd_control = 0, fd_audio = 0;
 
-// to set/get/query special features/parameters
 static int control(int cmd,int arg)
 {
     switch(cmd)
@@ -49,8 +48,6 @@
     return CONTROL_UNKNOWN;
 }
 
-// open & setup audio device
-// return: 1=success 0=fail
 static int init(int rate,int channels,int format,int flags)
 {
   int ioval;
@@ -86,12 +83,26 @@
         if( ioctl (fd_audio, SNDCTL_DSP_STEREO, &ao_data.channels) < 0 )
 	    printf( "AO: [dxr3] Unable to set number of channels\n" );
   
-	// set rate
 	ao_data.bps = (channels+1)*rate;
 	ao_data.samplerate=rate;
 	if( ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_data.samplerate) < 0 )
+	{
 	    printf( "AO: [dxr3] Unable to set samplerate\n" );
-	printf("AO: [dxr3] Using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate);
+	    return 0;
+	}
+	if( rate < ao_data.samplerate )
+	{
+	    ao_data.samplerate = 44100;
+	    ioctl(fd_audio, SNDCTL_DSP_SPEED, &ao_data.samplerate);
+    	    if( ao_data.samplerate != 44100 )
+	    {
+	        printf( "AO: [dxr3] Unable to set samplerate\n" );
+	        return 0;
+	    }
+	    printf("AO: [dxr3] Using %d Hz samplerate (requested: %d) (Upsampling)\n",ao_data.samplerate,rate);
+	    ao_data.samplerate = rate;
+	}
+	else printf("AO: [dxr3] Using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate);
   }
   else ao_data.bps *= 2;
 
@@ -125,7 +136,6 @@
   return 1;
 }
 
-// close audio device
 static void uninit()
 {
     printf( "AO: [dxr3] Uninitializing\n" );
@@ -135,14 +145,12 @@
     close( fd_control ); /* Just in case */
 }
 
-// stop playing and empty buffers (for seeking/pause)
 static void reset()
 {
     if( ioctl(fd_audio, SNDCTL_DSP_RESET, NULL) < 0 )
 	printf( "AO: [dxr3] Unable to reset device\n" );
 }
 
-// stop playing, keep buffers (for pause)
 static void audio_pause()
 {
   int ioval;
@@ -159,7 +167,6 @@
   }
 }
 
-// resume playing, after audio_pause()
 static void audio_resume()
 {
   int ioval;
@@ -175,7 +182,6 @@
   }
 }
 
-// return: how many bytes can be played without blocking
 static int get_space()
 {
     int space = 0;
@@ -191,22 +197,63 @@
 }
 
 static int play(void* data,int len,int flags)
-{
+{    
     if( ioctl( fd_audio, EM8300_IOCTL_AUDIO_SETPTS, &ao_data.pts ) < 0 )
 	printf( "AO: [dxr3] Unable to set PTS\n" );
+    if( ao_data.samplerate < 44100 )
+    {
+	int i,j,ratio,len2;
+	unsigned char *data2,*s,*d;
+	
+	ratio = 44100/ao_data.samplerate;ratio/=2;ratio*=2;
+	len2 = len * ratio;
+	data2 = malloc(len2);
+	
+	s = data;
+	d = data2;
+	
+	//Upsampler
+	if( ao_data.format == AFMT_U8 )
+	{
+	    for(i=0;i<ratio/2;i++)
+		for(j=0;j<len;j++)
+		{
+		    *d = *s;
+		    d++;
+		    *d = *s;
+		    d++;s++;
+		}
+	}
+	else
+	{
+	    for(i=0;i<ratio/2;i++)
+		for(j=0;j<len/2;j++)
+		{
+		    *d = *s;
+		    d++;s++;
+		    *d = *s;
+		    d++;s--;
+		    *d = *s;
+		    d++;s++;
+		    *d = *s;
+		    d++;s++;
+		}
+	}
+	if( len2 < 0 ) return 0;
+	write(fd_audio,data2,len2);
+	return len;
+    }
     return write(fd_audio,data,len);
 }
 
-// return: how many unplayed bytes are in the buffer
 static float get_delay()
 {
-/*    int r=0;
+    int r=0;
     if( ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r) < 0 )
     {
         printf( "AO: [dxr3] Unable to get unplayed bytes in buffer\n" );
 	return ((float)ao_data.buffersize)/(float)ao_data.bps;
     }
-    return (((float)r)/(float)ao_data.bps);*/
-    return 0.0;
+    return (((float)r)/(float)ao_data.bps);
 }
 




More information about the MPlayer-cvslog mailing list