[MPlayer-cvslog] r38455 - trunk/libao2/ao_sdl.c

al subversion at mplayerhq.hu
Tue Apr 9 00:39:30 EEST 2024


Author: al
Date: Tue Apr  9 00:39:30 2024
New Revision: 38455

Log:
ao sdl: Switch from AVFifoBuffer to AVFifo

Removed from lavu on major bump to 59

Switched to the version with SDL_{Lock,Unlock}Audio.

That's probably not in the spirit of the original version
of ao sdl, which tried hard to avoid locking, but as the
new version of FFmpeg fifo buffer seems to be worse for
multi threaded use I rather prefer to be safe here.

P.S.
I didn't really look deep into the details.
The old version of the fifo buffer probably wasn't completely
safe (especially on all CPU archs), but from the code history
it at least tried to.

Modified:
   trunk/libao2/ao_sdl.c

Modified: trunk/libao2/ao_sdl.c
==============================================================================
--- trunk/libao2/ao_sdl.c	Tue Apr  9 00:37:48 2024	(r38454)
+++ trunk/libao2/ao_sdl.c	Tue Apr  9 00:39:30 2024	(r38455)
@@ -62,18 +62,19 @@ LIBAO_EXTERN(sdl)
 #define NUM_CHUNKS 8
 #define BUFFSIZE (NUM_CHUNKS * CHUNK_SIZE)
 
-static AVFifoBuffer *buffer;
+static AVFifo *buffer;
 
 static int write_buffer(unsigned char* data,int len){
-  int free = av_fifo_space(buffer);
+  int free = av_fifo_can_write(buffer);
   if (len > free) len = free;
-  return av_fifo_generic_write(buffer, data, len, NULL);
+  av_fifo_write(buffer, data, len);
+  return len;
 }
 
 static int read_buffer(unsigned char* data,int len){
-  int buffered = av_fifo_size(buffer);
+  int buffered = av_fifo_can_read(buffer);
   if (len > buffered) len = buffered;
-  av_fifo_generic_read(buffer, data, len, NULL);
+  av_fifo_read(buffer, data, len);
   return len;
 }
 
@@ -103,7 +104,7 @@ static int init(int rate,int channels,in
 	SDL_AudioSpec aspec, obtained;
 
 	/* Allocate ring-buffer memory */
-	buffer = av_fifo_alloc(BUFFSIZE);
+	buffer = av_fifo_alloc2(BUFFSIZE, 1, 0);
 
 	mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_SDL_INFO, rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));
 
@@ -219,7 +220,7 @@ static void uninit(int immed){
 	  usec_sleep(get_delay() * 1000 * 1000);
 	SDL_CloseAudio();
 	SDL_QuitSubSystem(SDL_INIT_AUDIO);
-	av_fifo_free(buffer);
+	av_fifo_freep2(&buffer);
 }
 
 // stop playing and empty buffers (for seeking/pause)
@@ -229,7 +230,7 @@ static void reset(void){
 
 	SDL_PauseAudio(1);
 	/* Reset ring-buffer state */
-	av_fifo_reset(buffer);
+	av_fifo_reset2(buffer);
 	SDL_PauseAudio(0);
 }
 
@@ -252,18 +253,17 @@ static void audio_resume(void)
 
 // return: how many bytes can be played without blocking
 static int get_space(void){
-    return av_fifo_space(buffer);
+    return av_fifo_can_write(buffer);
 }
 
 // plays 'len' bytes of 'data'
 // it should round it down to outburst*n
 // return: number of bytes played
 static int play(void* data,int len,int flags){
+	int ret;
 
 	if (!(flags & AOPLAY_FINAL_CHUNK))
 	len = (len/ao_data.outburst)*ao_data.outburst;
-#if 0
-	int ret;
 
 	/* Audio locking prohibits call of outputaudio */
 	SDL_LockAudio();
@@ -272,13 +272,10 @@ static int play(void* data,int len,int f
 	SDL_UnlockAudio();
 
     	return ret;
-#else
-	return write_buffer(data, len);
-#endif
 }
 
 // return: delay in seconds between first and last sample in buffer
 static float get_delay(void){
-    int buffered = av_fifo_size(buffer); // could be less
+    int buffered = av_fifo_can_read(buffer); // could be less
     return (float)(buffered + ao_data.buffersize)/(float)ao_data.bps;
 }


More information about the MPlayer-cvslog mailing list