[pulseaudio-discuss] [PATCH 1/2] memblockq: remove pa_memblockq_missing()

Tanu Kaskinen tanuk at iki.fi
Fri Dec 30 15:52:35 UTC 2016


The function isn't used anywhere else than memblockq-test. Also, the
function is confusing, because it defines "missing" differently than
pa_memblockq_pop_missing(). pa_memblockq_missing() calculated the
missing amount like this:

    missing = tlength - length,

where "length" is the current queue length. pa_memblockq_pop_missing(),
on the other hand, calculates the missing amount like this:

    missing = tlength - length - requested,

where "requested" is an internal variable that keeps track of how much
the server has requested data from the client and how much of the
requests are yet to be fulfilled by the client.

memblockq-test is broken at the moment, because it assumes that
pa_memblockq_pop_missing() calculates "missing" the same way that
pa_memblockq_missing() used to calculate it. A patch for fixing that
will follow.
---
 src/pulsecore/memblockq.c  | 12 ------------
 src/pulsecore/memblockq.h  |  5 +----
 src/tests/memblockq-test.c | 22 +---------------------
 3 files changed, 2 insertions(+), 37 deletions(-)

diff --git a/src/pulsecore/memblockq.c b/src/pulsecore/memblockq.c
index f660ffa..b132dd3 100644
--- a/src/pulsecore/memblockq.c
+++ b/src/pulsecore/memblockq.c
@@ -680,18 +680,6 @@ size_t pa_memblockq_get_length(pa_memblockq *bq) {
     return (size_t) (bq->write_index - bq->read_index);
 }
 
-size_t pa_memblockq_missing(pa_memblockq *bq) {
-    size_t l;
-    pa_assert(bq);
-
-    if ((l = pa_memblockq_get_length(bq)) >= bq->tlength)
-        return 0;
-
-    l = bq->tlength - l;
-
-    return l >= bq->minreq ? l : 0;
-}
-
 void pa_memblockq_seek(pa_memblockq *bq, int64_t offset, pa_seek_mode_t seek, bool account) {
     int64_t old;
     pa_assert(bq);
diff --git a/src/pulsecore/memblockq.h b/src/pulsecore/memblockq.h
index 301bb21..69dcebc 100644
--- a/src/pulsecore/memblockq.h
+++ b/src/pulsecore/memblockq.h
@@ -56,7 +56,7 @@ typedef struct pa_memblockq pa_memblockq;
                 if no data is in the queue and will never fail. Pass
                 (size_t) -1 for the default.
 
-   - minreq:    pa_memblockq_missing() will only return values greater
+   - minreq:    pa_memblockq_pop_missing() will only return values greater
                 than this value. Pass 0 for the default.
 
    - maxrewind: how many bytes of history to keep in the queue
@@ -112,9 +112,6 @@ bool pa_memblockq_is_readable(pa_memblockq *bq);
 /* Return the length of the queue in bytes */
 size_t pa_memblockq_get_length(pa_memblockq *bq);
 
-/* Return how many bytes are missing in queue to the specified fill amount */
-size_t pa_memblockq_missing(pa_memblockq *bq);
-
 /* Return the number of bytes that are missing since the last call to
  * this function, reset the internal counter to 0. */
 size_t pa_memblockq_pop_missing(pa_memblockq *bq);
diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c
index 1404c78..fc83d99 100644
--- a/src/tests/memblockq-test.c
+++ b/src/tests/memblockq-test.c
@@ -124,7 +124,6 @@ static void check_queue_invariants(pa_memblockq *bq) {
     size_t minreq = pa_memblockq_get_minreq(bq);
     size_t prebuf = pa_memblockq_get_prebuf(bq);
     size_t length = pa_memblockq_get_length(bq);
-    size_t missing = pa_memblockq_missing(bq);
 
     /* base > zero */
     ck_assert_int_gt(base, 0);
@@ -161,15 +160,6 @@ static void check_queue_invariants(pa_memblockq *bq) {
      * length <= maxlength */
     ck_assert_int_ge(length, 0);
     ck_assert_int_le(length, maxlength);
-
-    /* missing >= 0
-     * missing <= tlength
-     * minimum reported amount of missing data is minreq
-     * reported amount of missing data is target length minus actual length */
-    ck_assert_int_ge(missing, 0);
-    ck_assert_int_le(missing, tlength);
-    ck_assert((missing == 0) || (missing >= minreq));
-    ck_assert((missing == 0) || (missing == tlength - length));
 }
 
 START_TEST (memchunk_from_str_test) {
@@ -218,7 +208,6 @@ START_TEST (memblockq_test_initial_properties) {
     /* check initial properties */
     ck_assert_int_eq(pa_memblockq_is_readable(bq), false);
     ck_assert_int_eq(pa_memblockq_get_length(bq), 0);
-    ck_assert_int_eq(pa_memblockq_missing(bq), tlength);
     ck_assert_int_eq(pa_memblockq_get_maxlength(bq), maxlength);
     ck_assert_int_eq(pa_memblockq_get_tlength(bq), tlength);
     ck_assert_int_eq(pa_memblockq_get_prebuf(bq), prebuf);
@@ -379,7 +368,6 @@ START_TEST (memblockq_test_length_changes) {
 
     /* check state */
     ck_assert_int_eq(pa_memblockq_get_length(bq), 32);
-    ck_assert_int_eq(pa_memblockq_missing(bq), 0);
 
     /* adjust maximum length
      * This might modify tlength, prebuf, minreq, too. */
@@ -434,7 +422,6 @@ START_TEST (memblockq_test_pop_missing) {
     fail_unless(bq != NULL);
 
     /* initially, the whole target length of bytes is missing */
-    ck_assert_int_eq(pa_memblockq_missing(bq), tlength);
     ck_assert_int_eq(pa_memblockq_pop_missing(bq), tlength);
 
     /* add 20 bytes of data */
@@ -442,8 +429,7 @@ START_TEST (memblockq_test_pop_missing) {
         ck_assert_int_eq(pa_memblockq_push(bq, &data), 0);
     check_queue_invariants(bq);
 
-    /* the missing bytes are reduced, but no new missing data is reported */
-    ck_assert_int_eq(pa_memblockq_missing(bq), tlength - 20);
+    /* no new missing data is reported */
     ck_assert_int_eq(pa_memblockq_pop_missing(bq), 0);
 
     /* fill up to 100 bytes of data */
@@ -452,7 +438,6 @@ START_TEST (memblockq_test_pop_missing) {
     check_queue_invariants(bq);
 
     /* queue fill level is at target level now */
-    ck_assert_int_eq(pa_memblockq_missing(bq), 0);
     ck_assert_int_eq(pa_memblockq_pop_missing(bq), 0);
 
     /* pop 40 bytes of data, down to 60 bytes fill level */
@@ -464,7 +449,6 @@ START_TEST (memblockq_test_pop_missing) {
 
     /* queue fill level is 40 bytes under target length
      * This is less than minreq, so no missing data is reported */
-    ck_assert_int_eq(pa_memblockq_missing(bq), 0);
     ck_assert_int_eq(pa_memblockq_pop_missing(bq), 0);
 
     /* add 30 bytes of data, up to 90 bytes fill level */
@@ -474,7 +458,6 @@ START_TEST (memblockq_test_pop_missing) {
 
     /* queue fill level is 10 bytes under target length
      * This is less than minreq, so no missing data is reported. */
-    ck_assert_int_eq(pa_memblockq_missing(bq), 0);
     ck_assert_int_eq(pa_memblockq_pop_missing(bq), 0);
 
     /* pop 20 bytes of data, down to 70 bytes of data */
@@ -486,7 +469,6 @@ START_TEST (memblockq_test_pop_missing) {
 
     /* queue fill level is 30 bytes under target length
      * This is less than minreq, so no missing data is reported */
-    ck_assert_int_eq(pa_memblockq_missing(bq), 0);
     ck_assert_int_eq(pa_memblockq_pop_missing(bq), 0);
 
     /* add 50 bytes of data, up to 120 bytes fill level */
@@ -495,7 +477,6 @@ START_TEST (memblockq_test_pop_missing) {
     check_queue_invariants(bq);
 
     /* queue fill level is above target level, so no missing data is reported. */
-    ck_assert_int_eq(pa_memblockq_missing(bq), 0);
     ck_assert_int_eq(pa_memblockq_pop_missing(bq), 0);
 
     /* pop 20 bytes of data, down the target level */
@@ -507,7 +488,6 @@ START_TEST (memblockq_test_pop_missing) {
 
     /* queue fill level is at target level now
      * No missing data should be reported. */
-    ck_assert_int_eq(pa_memblockq_missing(bq), 0);
     ck_assert_int_eq(pa_memblockq_pop_missing(bq), 0);
 
     /* cleanup */
-- 
2.10.2



More information about the pulseaudio-discuss mailing list