[pulseaudio-commits] 2 commits - src/pulsecore src/tests
Arun Raghavan
arun at kemper.freedesktop.org
Fri Jul 22 09:16:13 UTC 2016
src/pulsecore/memblockq.c | 4 ++
src/pulsecore/protocol-native.c | 9 +---
src/tests/memblockq-test.c | 80 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 86 insertions(+), 7 deletions(-)
New commits:
commit 06b84bfd05b6864548caf2fe323107349ab10026
Author: Pierre Ossman <ossman at cendio.se>
Date: Sun Jun 26 23:39:11 2016 +0200
tests: add test to verify correct minreq behaviour
Fixed up by Ulrich Eckhardt <ulrich.eckhardt at base-42.de>.
Signed-off-by: Arun Raghavan <arun at arunraghavan.net>
diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c
index 2404ee2..c14e394 100644
--- a/src/tests/memblockq-test.c
+++ b/src/tests/memblockq-test.c
@@ -212,6 +212,85 @@ START_TEST (memblockq_test) {
}
END_TEST
+START_TEST (pop_missing_test) {
+ int ret;
+ size_t missing;
+
+ pa_mempool *p;
+ pa_memblockq *bq;
+ pa_memchunk chunk;
+ char buffer[2048];
+ pa_sample_spec ss = {
+ .format = PA_SAMPLE_S16LE,
+ .rate = 48000,
+ .channels = 1
+ };
+
+ pa_log_set_level(PA_LOG_DEBUG);
+
+ bq = pa_memblockq_new("test memblockq", 0, 4096, 2048, &ss, 0, 512, 512, NULL);
+ fail_unless(bq != NULL);
+
+ /* Empty buffer, so expect tlength */
+ missing = pa_memblockq_pop_missing(bq);
+ fail_unless(missing == 2048);
+
+ /* Everything requested, so should be satisfied */
+ missing = pa_memblockq_pop_missing(bq);
+ fail_unless(missing == 0);
+
+ p = pa_mempool_new(PA_MEM_TYPE_PRIVATE, 0, true);
+
+ chunk.memblock = pa_memblock_new_fixed(p, buffer, sizeof(buffer), 1);
+ fail_unless(chunk.memblock != NULL);
+
+ chunk.index = 0;
+ chunk.length = sizeof(buffer);
+
+ /* Fill buffer (i.e. satisfy earlier request) */
+ ret = pa_memblockq_push(bq, &chunk);
+ fail_unless(ret == 0);
+
+ /* Should still be happy */
+ missing = pa_memblockq_pop_missing(bq);
+ fail_unless(missing == 0);
+
+ /* Check that we don't request less than minreq */
+ pa_memblockq_drop(bq, 400);
+ missing = pa_memblockq_pop_missing(bq);
+ ck_assert_int_eq(missing, 0);
+
+ missing = pa_memblockq_pop_missing(bq);
+ fail_unless(missing == 0);
+
+ /* Reduce tlength under what's dropped and under previous minreq */
+ pa_memblockq_set_tlength(bq, 256);
+ pa_memblockq_set_minreq(bq, 64);
+
+ /* We are now overbuffered and should not request more */
+ missing = pa_memblockq_pop_missing(bq);
+ fail_unless(missing == 0);
+
+ /* Drop more data so we are below tlength again, but just barely */
+ pa_memblockq_drop(bq, 1400);
+
+ /* Should still honour minreq */
+ missing = pa_memblockq_pop_missing(bq);
+ fail_unless(missing == 0);
+
+ /* Finally drop enough to fall below minreq */
+ pa_memblockq_drop(bq, 80);
+
+ /* And expect a request */
+ missing = pa_memblockq_pop_missing(bq);
+ fail_unless(missing == 88);
+
+ pa_memblockq_free(bq);
+ pa_memblock_unref(chunk.memblock);
+ pa_mempool_unref(p);
+}
+END_TEST
+
int main(int argc, char *argv[]) {
int failed = 0;
Suite *s;
@@ -221,6 +300,7 @@ int main(int argc, char *argv[]) {
s = suite_create("Memblock Queue");
tc = tcase_create("memblockq");
tcase_add_test(tc, memblockq_test);
+ tcase_add_test(tc, pop_missing_test);
suite_add_tcase(s, tc);
sr = srunner_create(s);
commit eeec52caa0622504f7a0d065dd61db1dbf5a9569
Author: Pierre Ossman <ossman at cendio.se>
Date: Thu May 19 15:26:08 2016 +0200
memblockq: move minreq handling in to memblockq
Having it handled in the callers proved to be a poor fit as it
became difficult to handle a shrinking minreq sanely. It could end
up in a state where the request was never sent downstream to the
client.
diff --git a/src/pulsecore/memblockq.c b/src/pulsecore/memblockq.c
index d283ed2..f660ffa 100644
--- a/src/pulsecore/memblockq.c
+++ b/src/pulsecore/memblockq.c
@@ -840,6 +840,10 @@ size_t pa_memblockq_pop_missing(pa_memblockq *bq) {
if (bq->missing <= 0)
return 0;
+ if (((size_t) bq->missing < bq->minreq) &&
+ !pa_memblockq_prebuf_active(bq))
+ return 0;
+
l = (size_t) bq->missing;
bq->requested += bq->missing;
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index c468edc..0f86bd2 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -1111,8 +1111,7 @@ out:
/* Called from IO context */
static void playback_stream_request_bytes(playback_stream *s) {
- size_t m, minreq;
- int previous_missing;
+ size_t m;
playback_stream_assert_ref(s);
@@ -1132,11 +1131,7 @@ static void playback_stream_request_bytes(playback_stream *s) {
pa_log("request_bytes(%lu)", (unsigned long) m);
#endif
- previous_missing = pa_atomic_add(&s->missing, (int) m);
- minreq = pa_memblockq_get_minreq(s->memblockq);
-
- if (pa_memblockq_prebuf_active(s->memblockq) ||
- (previous_missing < (int) minreq && previous_missing + (int) m >= (int) minreq))
+ if (pa_atomic_add(&s->missing, (int) m) <= 0)
pa_asyncmsgq_post(pa_thread_mq_get()->outq, PA_MSGOBJECT(s), PLAYBACK_STREAM_MESSAGE_REQUEST_DATA, NULL, 0, NULL, NULL);
}
More information about the pulseaudio-commits
mailing list