[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] memblockq: Adjust tail chunk offset into memblock after split
PulseAudio Marge Bot (@pulseaudio-merge-bot)
gitlab at gitlab.freedesktop.org
Wed Oct 25 13:32:36 UTC 2023
PulseAudio Marge Bot pushed to branch master at PulseAudio / pulseaudio
Commits:
06ccfbb9 by Igor V. Kovalenko at 2023-10-25T13:21:34+00:00
memblockq: Adjust tail chunk offset into memblock after split
If pa_memblockq_push needs to write into the middle of a chunk, target chunk
is split into head and tail sharing the same memblock. Size of head and
tail chunks is adjusted correctly, head chunk pointer into memblock remains
unchanged from target chunk.
The problem is with tail chunk offset into memblock which should be advanced
past write region of memblock, but currently it is left as 0.
This is causing an issue where seeking a few frames back into the middle of
memblock and writing a frame there ends up with tail chunk referencing frames
from very beginning of memblock causing corrupted output from memblockq.
Fix this by adjusting tail chunk offset into memblock past write region and
add a test case.
Fixes #3789
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/798>
- - - - -
2 changed files:
- src/pulsecore/memblockq.c
- src/tests/memblockq-test.c
Changes:
=====================================
src/pulsecore/memblockq.c
=====================================
@@ -353,6 +353,7 @@ int pa_memblockq_push(pa_memblockq* bq, const pa_memchunk *uchunk) {
/* Drop it from the new entry */
p->index = q->index + (int64_t) d;
+ p->chunk.index = d;
p->chunk.length -= d;
/* Add it to the list */
=====================================
src/tests/memblockq-test.c
=====================================
@@ -632,6 +632,55 @@ START_TEST (memblockq_test_tlength_change) {
}
END_TEST
+START_TEST (memblockq_test_push_to_middle) {
+ const char *expected_contents = "123456FE90______";
+ pa_sample_spec ss = {
+ .format = PA_SAMPLE_S16BE,
+ .rate = 48000,
+ .channels = 1
+ };
+
+ pa_memchunk silence;
+ pa_mempool *p;
+ pa_memblockq *bq;
+ pa_memchunk chunk1, chunk2;
+ pa_memchunk out;
+
+ pa_strbuf *buf;
+ char *str;
+
+ p = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0, true);
+ ck_assert_ptr_ne(p, NULL);
+ silence = memchunk_from_str(p, "__");
+
+ bq = pa_memblockq_new("test memblockq", 0, 200, 10, &ss, 4, 4, 40, &silence);
+
+ chunk1 = memchunk_from_str(p, "1234567890");
+ pa_memblockq_push(bq, &chunk1);
+ chunk2 = memchunk_from_str(p, "FE");
+ pa_memblockq_seek(bq, -4, 0, true);
+ pa_memblockq_push(bq, &chunk2);
+
+ pa_memblockq_peek_fixed_size(bq, 16, &out);
+
+ buf = pa_strbuf_new();
+ fprintf(stderr, "EXPECTED >%s<\n", expected_contents);
+ fprintf(stderr, "ACTUAL >");
+ dump_chunk(&out, buf);
+ fprintf(stderr, "<\n");
+ pa_memblock_unref(out.memblock);
+ str = pa_strbuf_to_string_free(buf);
+ fail_unless(pa_streq(str, expected_contents));
+ pa_xfree(str);
+
+ /* cleanup */
+ pa_memblockq_free(bq);
+ pa_memblock_unref(chunk1.memblock);
+ pa_memblock_unref(chunk2.memblock);
+ pa_memblock_unref(silence.memblock);
+ pa_mempool_unref(p);
+}
+END_TEST
int main(int argc, char *argv[]) {
int failed = 0;
@@ -650,6 +699,7 @@ int main(int argc, char *argv[]) {
tcase_add_test(tc, memblockq_test_length_changes);
tcase_add_test(tc, memblockq_test_pop_missing);
tcase_add_test(tc, memblockq_test_tlength_change);
+ tcase_add_test(tc, memblockq_test_push_to_middle);
suite_add_tcase(s, tc);
sr = srunner_create(s);
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/06ccfbb996e5b8b31f04f97795e8c9f083bea332
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/06ccfbb996e5b8b31f04f97795e8c9f083bea332
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/20231025/d9412533/attachment-0001.htm>
More information about the pulseaudio-commits
mailing list