Skip to content

Commit

Permalink
Avoid side-effectful assignments in conditionals.
Browse files Browse the repository at this point in the history
Only in audio.c for now. This should be done everywhere.
  • Loading branch information
iphydf committed Jul 8, 2018
1 parent 465c938 commit c0c3098
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 8 additions & 5 deletions toxav/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

int rc = 0;
struct RTPMessage *msg = jbuf_read(j_buf, &rc);

while ((msg = jbuf_read((struct JitterBuffer *)ac->j_buf, &rc)) || rc == 2) {
for (; msg != nullptr || rc == 2; msg = jbuf_read(j_buf, &rc)) {
pthread_mutex_unlock(ac->queue_mutex);

if (rc == 2) {
Expand Down

0 comments on commit c0c3098

Please sign in to comment.