Re: [PATCH v2 0/8] Adjustments for current FFmpeg git including major bumps

Alexander Strasser <[email protected]> Tue, 9 Apr 2024 07:22:52 +0200
Newsgroups gmane.comp.video.mplayer.devel
Message-ID <[email protected]>
Hi Mike,

I had attached patch in my tree locally.

It worked with jack here, but as menitioned I still need to check
for potenial concurrency problems after switching to the new
ffmpeg fifo implementation.

Best regards,
  Alexander

On 2024-04-08 19:53 -0400, Mike Lieman wrote:
> Hey, I have the jack-audio-connection-kit libraries, which configure picks
> up and builds which have the same issues.   I applied the changes to
> libao2/ao_jack.c    (revision 38458) and it now compiles.
>
> $ svn diff
> Index: libao2/ao_jack.c
> ===================================================================
> --- libao2/ao_jack.c    (revision 38458)
> +++ libao2/ao_jack.c    (working copy)
> @@ -71,7 +71,7 @@
>  #define BUFFSIZE (NUM_CHUNKS * CHUNK_SIZE)
>
>  //! buffer for audio data
> -static AVFifoBuffer *buffer;
> +static AVFifo *buffer;
>
>  /**
>   * \brief insert len bytes into buffer
> @@ -82,9 +82,11 @@
>   * If there is not enough room, the buffer is filled up
>   */
>  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);
> +//  return av_fifo_generic_write(buffer, data, len, NULL);
> +  av_fifo_write(buffer, data, len);
> +  return len;
>  }
>
>  static void silence(float **bufs, int cnt, int num_bufs);
> @@ -125,7 +127,7 @@
>   */
>  static int read_buffer(float **bufs, int cnt, int num_bufs) {
>    struct deinterleave di = {bufs, num_bufs, 0, 0};
> -  int buffered = av_fifo_size(buffer);
> +  int buffered = av_fifo_can_read(buffer);
>    if (cnt * sizeof(float) * num_bufs > buffered) {
>      silence(bufs, cnt, num_bufs);
>      cnt = buffered / sizeof(float) / num_bufs;
> @@ -242,7 +244,7 @@
>      mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] cannot open server\n");
>      goto err_out;
>    }
> -  buffer = av_fifo_alloc(BUFFSIZE);
> +  buffer = av_fifo_alloc2(BUFFSIZE, 1, 0);
>    jack_set_process_callback(client, outputaudio, 0);
>
>    // list matching ports if connections should be made
> @@ -302,7 +304,7 @@
>    free(client_name);
>    if (client)
>      jack_client_close(client);
> -  av_fifo_free(buffer);
> +  av_fifo_freep2(buffer);
>    buffer = NULL;
>    return 0;
>  }
> @@ -315,7 +317,7 @@
>    reset();
>    usec_sleep(100 * 1000);
>    jack_client_close(client);
> -  av_fifo_free(buffer);
> +  av_fifo_freep2(buffer);
>    buffer = NULL;
>  }
>
> @@ -324,7 +326,7 @@
>   */
>  static void reset(void) {
>    paused = 1;
> -  av_fifo_reset(buffer);
> +  av_fifo_reset2(buffer);
>    paused = 0;
>  }
>
> @@ -343,7 +345,7 @@
>  }
>
>  static int get_space(void) {
> -  return av_fifo_space(buffer);
> +  return av_fifo_can_write(buffer);
>  }
>
>  /**
> @@ -357,7 +359,7 @@
>  }
>
>  static float get_delay(void) {
> -  int buffered = av_fifo_size(buffer); // could be less
> +  int buffered = av_fifo_can_read(buffer); // could be less
>    float in_jack = jack_latency;
>    if (estimate && callback_interval > 0) {
>      float elapsed = (float)GetTimer() / 1000000.0 - callback_time;
>
>
>
>
> On Mon, Apr 8, 2024 at 7:07 PM Alexander Strasser <[email protected]> wrote:
>
> > Committed as SVN r38450 to r38457.
> >
> > Committed v2 of the patch set with the minor change that I used patch
> > 7/8 from v1 of the patch set. As Ingo mentioned Reimar already fixed
> > the problem with the ffmpeg dvdvideo demuxer in r38449.
> >
> >
> > On 2024-04-07 23:58 +0200, Ingo Brückl wrote:
> > > On Sun, 7 Apr 2024 17:11:14 +0200, Alexander Strasser wrote:
> > >
> > > > At Ingo:
> > > > Could you test the files you had problems with again with this newer
> > > > version of the patches and probably also with Ivan's patch on top?
> > >
> > > Your patches together with Ivan's patch now fix all the problems I was
> > > having before.
> > >
> > > Thanks to both of you for your work.
> >
> > Thank you so much for testing, Ingo!
> >
> >
> > Greetings,
> >   Alexander

  Alexander

_______________________________________________
MPlayer-dev-eng mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
0001-ao-jack-Switch-from-AVFifoBuffer-to-AVFifo.patch (text/x-diff, 3.7 KB)
From 98f80775dff2b9f83ba9b2e247ef7b2174a107bf Mon Sep 17 00:00:00 2001
From: Alexander Strasser <[email protected]>
Date: Wed, 3 Apr 2024 22:57:40 +0200
Subject: [PATCH] ao jack: Switch from AVFifoBuffer to AVFifo

Removed from lavu on major bump to 59

TODO: Check for potential concurrency problems
---
 libao2/ao_jack.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/libao2/ao_jack.c b/libao2/ao_jack.c
index 8ddd0e21e..80bc5e478 100644
--- a/libao2/ao_jack.c
+++ b/libao2/ao_jack.c
@@ -71,7 +71,7 @@ static volatile float callback_time = 0;
 #define BUFFSIZE (NUM_CHUNKS * CHUNK_SIZE)

 //! buffer for audio data
-static AVFifoBuffer *buffer;
+static AVFifo *buffer;

 /**
  * \brief insert len bytes into buffer
@@ -82,9 +82,10 @@ static AVFifoBuffer *buffer;
  * If there is not enough room, the buffer is filled up
  */
 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 void silence(float **bufs, int cnt, int num_bufs);
@@ -96,10 +97,11 @@ struct deinterleave {
   int pos;
 };

-static void deinterleave(void *info, void *src, int len) {
+static int deinterleave(void *info, void *src, size_t *lenp) {
   struct deinterleave *di = info;
   float *s = src;
   int i;
+  int len = *lenp;
   len /= sizeof(float);
   for (i = 0; i < len; i++) {
     di->bufs[di->cur_buf++][di->pos] = s[i];
@@ -108,6 +110,7 @@ static void deinterleave(void *info, void *src, int len) {
       di->pos++;
     }
   }
+  return 0;
 }

 /**
@@ -125,12 +128,13 @@ static void deinterleave(void *info, void *src, int len) {
  */
 static int read_buffer(float **bufs, int cnt, int num_bufs) {
   struct deinterleave di = {bufs, num_bufs, 0, 0};
-  int buffered = av_fifo_size(buffer);
+  size_t len = cnt * num_bufs * sizeof(float);
+  int buffered = av_fifo_can_read(buffer);
   if (cnt * sizeof(float) * num_bufs > buffered) {
     silence(bufs, cnt, num_bufs);
     cnt = buffered / sizeof(float) / num_bufs;
   }
-  av_fifo_generic_read(buffer, &di, cnt * num_bufs * sizeof(float), deinterleave);
+  av_fifo_read_to_cb(buffer, deinterleave, &di, &len);
   return cnt;
 }

@@ -242,7 +246,7 @@ static int init(int rate, int channels, int format, int flags) {
     mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] cannot open server\n");
     goto err_out;
   }
-  buffer = av_fifo_alloc(BUFFSIZE);
+  buffer = av_fifo_alloc2(BUFFSIZE, 1, 0);
   jack_set_process_callback(client, outputaudio, 0);

   // list matching ports if connections should be made
@@ -302,8 +306,7 @@ err_out:
   free(client_name);
   if (client)
     jack_client_close(client);
-  av_fifo_free(buffer);
-  buffer = NULL;
+  av_fifo_freep2(&buffer);
   return 0;
 }

@@ -315,8 +318,7 @@ static void uninit(int immed) {
   reset();
   usec_sleep(100 * 1000);
   jack_client_close(client);
-  av_fifo_free(buffer);
-  buffer = NULL;
+  av_fifo_freep2(&buffer);
 }

 /**
@@ -324,7 +326,7 @@ static void uninit(int immed) {
  */
 static void reset(void) {
   paused = 1;
-  av_fifo_reset(buffer);
+  av_fifo_reset2(buffer);
   paused = 0;
 }

@@ -343,7 +345,7 @@ static void audio_resume(void) {
 }

 static int get_space(void) {
-  return av_fifo_space(buffer);
+  return av_fifo_can_write(buffer);
 }

 /**
@@ -357,7 +359,7 @@ static int play(void *data, int len, int flags) {
 }

 static float get_delay(void) {
-  int buffered = av_fifo_size(buffer); // could be less
+  int buffered = av_fifo_can_read(buffer); // could be less
   float in_jack = jack_latency;
   if (estimate && callback_interval > 0) {
     float elapsed = (float)GetTimer() / 1000000.0 - callback_time;
--