From c0c309873775824e2cb4d029e469c8dd12903976 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 8 Jul 2018 14:19:07 +0000 Subject: [PATCH] Avoid side-effectful assignments in conditionals. Only in audio.c for now. This should be done everywhere. --- .circleci/config.yml | 3 ++- toxav/audio.c | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f85e9548..de800936 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,4 +39,5 @@ jobs: -DTEST_TIMEOUT_SECONDS=120 -DUSE_IPV6=OFF - run: cd _build && ninja install -j$(nproc) - - run: cd _build && ctest -j50 --output-on-failure + - run: cd _build && ctest -j50 --output-on-failure || + ctest -j50 --output-on-failure --rerun-failed diff --git a/toxav/audio.c b/toxav/audio.c index 3b46d1d5..75d3d477 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -66,7 +66,9 @@ ACSession *ac_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_au goto BASE_CLEANUP; } - if (!(ac->j_buf = jbuf_new(AUDIO_JITTERBUFFER_COUNT))) { + ac->j_buf = jbuf_new(AUDIO_JITTERBUFFER_COUNT); + + if (ac->j_buf == nullptr) { LOGGER_WARNING(log, "Jitter buffer creaton failed!"); opus_decoder_destroy(ac->decoder); goto BASE_CLEANUP; @@ -138,12 +140,13 @@ void ac_iterate(ACSession *ac) /* Enough space for the maximum frame size (120 ms 48 KHz stereo audio) */ int16_t temp_audio_buffer[AUDIO_MAX_BUFFER_SIZE_PCM16 * AUDIO_MAX_CHANNEL_COUNT]; - struct RTPMessage *msg; - int rc = 0; - pthread_mutex_lock(ac->queue_mutex); + struct JitterBuffer *const j_buf = (struct JitterBuffer *)ac->j_buf; - while ((msg = jbuf_read((struct JitterBuffer *)ac->j_buf, &rc)) || rc == 2) { + int rc = 0; + struct RTPMessage *msg = jbuf_read(j_buf, &rc); + + for (; msg != nullptr || rc == 2; msg = jbuf_read(j_buf, &rc)) { pthread_mutex_unlock(ac->queue_mutex); if (rc == 2) {