Merge Android 24Q1 Release (ab/11220357)

Bug: 319669529
Merged-In: I5a675bb7b6cd6d067f523496b3350139fb552030
Change-Id: I30b06e072bd3aa63075695542e2a12252212ff9a
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index 063a256..c0f4746 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -290,6 +290,9 @@
  */
 int pcm_set_avail_min(struct pcm *pcm, int avail_min);
 
+/* Gets the count of underruns for playback and count of overruns for capture. */
+int pcm_get_xruns(struct pcm *pcm);
+
 /*
  * MIXER API
  */
diff --git a/pcm.c b/pcm.c
index 6d7dc29..dd74c87 100644
--- a/pcm.c
+++ b/pcm.c
@@ -256,7 +256,7 @@
     unsigned int flags;
     bool running:1;
     bool prepared:1;
-    int underruns;
+    int xruns;
     unsigned int buffer_size;
     unsigned long boundary;
     char error[PCM_ERROR_MAX];
@@ -561,7 +561,7 @@
                 /* we failed to make our window -- try to restart if we are
                  * allowed to do so.  Otherwise, simply allow the EPIPE error to
                  * propagate up to the app level */
-                pcm->underruns++;
+                pcm->xruns++;
                 if (pcm->flags & PCM_NORESTART)
                     return -EPIPE;
                 continue;
@@ -595,7 +595,7 @@
             pcm->running = false;
             if (errno == EPIPE) {
                     /* we failed to make our window -- try to restart */
-                pcm->underruns++;
+                pcm->xruns++;
                 continue;
             }
             return oops(pcm, errno, "cannot read stream data");
@@ -1055,7 +1055,7 @@
     }
 #endif
 
-    pcm->underruns = 0;
+    pcm->xruns = 0;
     return pcm;
 
 fail:
@@ -1382,3 +1382,7 @@
 
     return pcm->ops->ioctl(pcm->data, request, arg);
 }
+
+int pcm_get_xruns(struct pcm *pcm) {
+    return pcm->xruns;
+}