[Git][pulseaudio/pulseaudio][stable-16.x] 5 commits: time-smoother-2: Fix stream time when stream starts paused

Arun Raghavan (@arun) gitlab at gitlab.freedesktop.org
Fri Sep 13 18:02:38 UTC 2024



Arun Raghavan pushed to branch stable-16.x at PulseAudio / pulseaudio


Commits:
686ae9c6 by Georg Chini at 2024-09-13T12:33:02-04:00
time-smoother-2: Fix stream time when stream starts paused

When a stream is started but has not yet called smoother_2_put(), pa_smoother_2_get()
returns the time since the start of the stream even if the stream was started paused.
When the stream is started paused, pa_smoother_2_get() should return 0 instead. This
patch fixes the problem.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/745>

- - - - -
f2836dc6 by Igor V. Kovalenko at 2024-09-13T12:38:21-04:00
rtp: Accept CRLF delimiters in SDP as required by RFC 4566

RFC 4566 states that SDP record is terminated with CRLF, and parsers should be
able to accept records terminated with just LF. Pulseaudio only accepts LF here.

Fix this by accepting both CRLF and LF terminators.

- - - - -
a8b28d86 by Igor V. Kovalenko at 2024-09-13T12:38:21-04:00
shell-completion: Fix typo in --use-pid-file= suggestion

Fixes #3786

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/799>

- - - - -
9a428e4c by Igor V. Kovalenko at 2024-09-13T12:38:21-04:00
Fix crash running in restricted environment.

When `pwd.h` header is not available (i.e. not using glibc) and environment
variables are not set (e.g. running via `env --ignore-environment`) client
library would crash due to uninitialized variable in `pa_get_home_dir()`.
Add missing initialization to fix that.

Fixes: #3792
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/800>

- - - - -
0647fcb6 by Arun Raghavan at 2024-09-13T12:38:21-04:00
tests: Don't run volume tests with impossible alignments

This worked so far somehow, but we were sending in some samples at
unrealistic alignments (given that pa_memblockq will be frame-aligned,
and we expect all operations to occur per-frame as well).

Fixes: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/3803
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/812>

- - - - -


7 changed files:

- shell-completion/bash/pactl
- src/modules/rtp/sap.c
- src/modules/rtp/sdp.c
- src/modules/rtp/sdp.h
- src/pulse/util.c
- src/pulsecore/time-smoother_2.c
- src/tests/cpu-volume-test.c


Changes:

=====================================
shell-completion/bash/pactl
=====================================
@@ -500,7 +500,7 @@ _pulseaudio()
                 --start -k --kill --check --system= -D --daemonize= --fail= --high-priority=
                 --realtime= --disallow-module-loading= --disallow-exit= --exit-idle-time=
                 --scache-idle-time= --log-level= -v --log-target= --log-meta= --log-time=
-                --log-backtrace= -p --dl-search-path= --resample-method= --use-pit-file=
+                --log-backtrace= -p --dl-search-path= --resample-method= --use-pid-file=
                 --no-cpu-limit= --disable-shm= --enable-memfd= -L --load= -F --file= -C -n'
     _init_completion -n = || return
 


=====================================
src/modules/rtp/sap.c
=====================================
@@ -213,7 +213,9 @@ int pa_sap_recv(pa_sap_context *c, bool *goodbye) {
     if ((unsigned) size >= sizeof(MIME_TYPE) && pa_streq(e, MIME_TYPE)) {
         e += sizeof(MIME_TYPE);
         size -= (int) sizeof(MIME_TYPE);
-    } else if ((unsigned) size < sizeof(PA_SDP_HEADER)-1 || strncmp(e, PA_SDP_HEADER, sizeof(PA_SDP_HEADER)-1)) {
+    } else if ((unsigned) size < sizeof(PA_SDP_HEADER)-1 || strncmp(e, PA_SDP_HEADER, sizeof(PA_SDP_HEADER)-1)
+            || strcspn(e, "\r\n") != sizeof(PA_SDP_HEADER)-1) {
+        /* SDP header does not start with v=0[\r]\n */
         pa_log_warn("Invalid SDP header.");
         goto fail;
     }


=====================================
src/modules/rtp/sdp.c
=====================================
@@ -73,7 +73,7 @@ char *pa_sdp_build(int af, const void *src, const void *dst, const char *name, u
     pa_assert_se(inet_ntop(af, dst, buf_dst, sizeof(buf_dst)));
 
     return pa_sprintf_malloc(
-            PA_SDP_HEADER
+            PA_SDP_HEADER "\n"
             "o=%s %lu 0 IN %s %s\n"
             "s=%s\n"
             "c=IN %s %s\n"
@@ -131,17 +131,29 @@ pa_sdp_info *pa_sdp_parse(const char *t, pa_sdp_info *i, int is_goodbye) {
     i->payload = 255;
     i->enable_opus = false;
 
-    if (!pa_startswith(t, PA_SDP_HEADER)) {
+    if (pa_startswith(t, PA_SDP_HEADER)) {
+        t += sizeof(PA_SDP_HEADER) - 1;
+
+        /* CR delimiter is optional */
+        if (*t == '\r')
+            t++;
+
+        /* LF delimiter is mandatory */
+        if (*t == '\n')
+            t++;
+        else {
+            pa_log("Failed to parse SDP data: missing header record terminator LF.");
+            goto fail;
+        }
+    } else {
         pa_log("Failed to parse SDP data: invalid header.");
         goto fail;
     }
 
-    t += sizeof(PA_SDP_HEADER)-1;
-
     while (*t) {
         size_t l;
 
-        l = strcspn(t, "\n");
+        l = strcspn(t, "\r\n");
 
         if (l <= 2) {
             pa_log("Failed to parse SDP data: line too short: >%s<.", t);
@@ -241,8 +253,17 @@ pa_sdp_info *pa_sdp_parse(const char *t, pa_sdp_info *i, int is_goodbye) {
 
         t += l;
 
+        /* CR delimiter is optional */
+        if (*t == '\r')
+            t++;
+
+        /* LF delimiter is mandatory */
         if (*t == '\n')
             t++;
+        else {
+            pa_log("Failed to parse SDP data: missing record terminator LF.");
+            goto fail;
+        }
     }
 
     if (!i->origin || (!is_goodbye && (!i->salen || i->payload > 127 || !ss_valid || port == 0))) {


=====================================
src/modules/rtp/sdp.h
=====================================
@@ -26,7 +26,7 @@
 
 #include <pulse/sample.h>
 
-#define PA_SDP_HEADER "v=0\n"
+#define PA_SDP_HEADER "v=0"
 
 typedef struct pa_sdp_info {
     char *origin;


=====================================
src/pulse/util.c
=====================================
@@ -167,7 +167,7 @@ char *pa_get_host_name(char *s, size_t l) {
 
 char *pa_get_home_dir(char *s, size_t l) {
     char *e;
-    char *dir;
+    char *dir = NULL;
 #ifdef HAVE_PWD_H
     struct passwd *r;
 #endif


=====================================
src/pulsecore/time-smoother_2.c
=====================================
@@ -295,7 +295,7 @@ pa_usec_t pa_smoother_2_get(pa_smoother_2 *s, pa_usec_t time_stamp) {
 
     /* If the smoother has not started, just return system time since resume */
     if (!s->start_time) {
-        if (time_stamp >= s->resume_time)
+        if (time_stamp >= s->resume_time && !s->paused)
             current_time = time_stamp - s->resume_time;
         else
             current_time = 0;


=====================================
src/tests/cpu-volume-test.c
=====================================
@@ -43,6 +43,7 @@ static void run_volume_test(
         int channels,
         bool correct,
         bool perf) {
+    fail_unless(align % channels == 0);
 
     PA_DECLARE_ALIGNED(8, int16_t, s[SAMPLES]) = { 0 };
     PA_DECLARE_ALIGNED(8, int16_t, s_ref[SAMPLES]) = { 0 };
@@ -56,8 +57,6 @@ static void run_volume_test(
     samples_ref = s_ref + (8 - align);
     samples_orig = s_orig + (8 - align);
     nsamples = SAMPLES - (8 - align);
-    if (nsamples % channels)
-        nsamples -= nsamples % channels;
     size = nsamples * sizeof(int16_t);
 
     pa_random(samples, size);
@@ -119,12 +118,12 @@ START_TEST (svolume_mmx_test) {
 
     pa_log_debug("Checking MMX svolume");
     for (i = 1; i <= 3; i++) {
-        for (j = 0; j < 7; j++)
-            run_volume_test(mmx_func, orig_func, j, i, true, false);
+        for (j = 0; j <= 7; j += i)
+            run_volume_test(mmx_func, orig_func, j, i, true, j == 0);
     }
     run_volume_test(mmx_func, orig_func, 7, 1, true, true);
-    run_volume_test(mmx_func, orig_func, 7, 2, true, true);
-    run_volume_test(mmx_func, orig_func, 7, 3, true, true);
+    run_volume_test(mmx_func, orig_func, 6, 2, true, true);
+    run_volume_test(mmx_func, orig_func, 6, 3, true, true);
 }
 END_TEST
 
@@ -146,12 +145,12 @@ START_TEST (svolume_sse_test) {
 
     pa_log_debug("Checking SSE2 svolume");
     for (i = 1; i <= 3; i++) {
-        for (j = 0; j < 7; j++)
-            run_volume_test(sse_func, orig_func, j, i, true, false);
+        for (j = 0; j < 7; j += i)
+            run_volume_test(sse_func, orig_func, j, i, true, j == 0);
     }
     run_volume_test(sse_func, orig_func, 7, 1, true, true);
-    run_volume_test(sse_func, orig_func, 7, 2, true, true);
-    run_volume_test(sse_func, orig_func, 7, 3, true, true);
+    run_volume_test(sse_func, orig_func, 6, 2, true, true);
+    run_volume_test(sse_func, orig_func, 6, 3, true, true);
 }
 END_TEST
 #endif /* defined (__i386__) || defined (__amd64__) */
@@ -175,12 +174,12 @@ START_TEST (svolume_arm_test) {
 
     pa_log_debug("Checking ARM svolume");
     for (i = 1; i <= 3; i++) {
-        for (j = 0; j < 7; j++)
-            run_volume_test(arm_func, orig_func, j, i, true, false);
+        for (j = 0; j < 7; j += i)
+            run_volume_test(arm_func, orig_func, j, i, true, j == 0);
     }
     run_volume_test(arm_func, orig_func, 7, 1, true, true);
-    run_volume_test(arm_func, orig_func, 7, 2, true, true);
-    run_volume_test(arm_func, orig_func, 7, 3, true, true);
+    run_volume_test(arm_func, orig_func, 6, 2, true, true);
+    run_volume_test(arm_func, orig_func, 6, 3, true, true);
 }
 END_TEST
 #endif /* defined (__arm__) && defined (__linux__) */
@@ -207,11 +206,11 @@ START_TEST (svolume_orc_test) {
 
     pa_log_debug("Checking Orc svolume");
     for (i = 1; i <= 2; i++) {
-        for (j = 0; j < 7; j++)
-            run_volume_test(orc_func, orig_func, j, i, true, false);
+        for (j = 0; j < 7; j += i)
+            run_volume_test(orc_func, orig_func, j, i, true, j == 0);
     }
     run_volume_test(orc_func, orig_func, 7, 1, true, true);
-    run_volume_test(orc_func, orig_func, 7, 2, true, true);
+    run_volume_test(orc_func, orig_func, 6, 2, true, true);
 }
 END_TEST
 



View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/e5ad31e873eed62bc580a86a61177047f9e8c491...0647fcb6222a119a90703f52c8ed4a8397801d41

-- 
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/e5ad31e873eed62bc580a86a61177047f9e8c491...0647fcb6222a119a90703f52c8ed4a8397801d41
You're receiving this email because of your account on gitlab.freedesktop.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20240913/0cb7c24e/attachment-0001.htm>


More information about the pulseaudio-commits mailing list