summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2020-07-15 01:48:07 -0700
committerVito Caputo <vcaputo@pengaru.com>2020-07-15 01:48:07 -0700
commit63c510aca1de960ee12d2ee5b83b794c50258b44 (patch)
treeebd6f94ddb0ccf0dce7ad1bbad67b81b1e12ee89
parent79cc627a9acae89d05b4e0c213b97ad4c0aec619 (diff)
sound: move avd maintenance to point of capture
Since the sound capture buffers all sound in newly allocated memory, the "stream time" represented by those buffers can be accounted for immediately upon reading into the buffer. Doing it later in the different threads on the other side of the queue, especially after encoding, is an unnecessary pile of variable capacitance that just makes things less synchronized for zero gain.
-rw-r--r--src/rmd_cache_audio.c4
-rw-r--r--src/rmd_capture_sound.c10
-rw-r--r--src/rmd_encode_sound_buffer.c4
3 files changed, 10 insertions, 8 deletions
diff --git a/src/rmd_cache_audio.c b/src/rmd_cache_audio.c
index 0a3be39..58892b6 100644
--- a/src/rmd_cache_audio.c
+++ b/src/rmd_cache_audio.c
@@ -99,10 +99,6 @@ void *rmdCacheSoundBuffer(ProgData *pdata) {
fwrite(jackbuf, 1, write_size, pdata->cache_data->afp);
#endif
}
-
- pthread_mutex_lock(&pdata->avd_mutex);
- pdata->avd -= pdata->periodtime;
- pthread_mutex_unlock(&pdata->avd_mutex);
}
fclose(pdata->cache_data->afp);
diff --git a/src/rmd_capture_sound.c b/src/rmd_capture_sound.c
index 0c95afa..162ceed 100644
--- a/src/rmd_capture_sound.c
+++ b/src/rmd_capture_sound.c
@@ -146,6 +146,16 @@ void *rmdCaptureSound(ProgData *pdata) {
sret += temp_sret;
} while (sret < (pdata->args.buffsize << 1) * pdata->args.channels);
#endif
+
+ /* Since sound buffers are queued here by allocating buffers, their "stream time"
+ * can be accounted for here instead of after encoding, since encoding isn't lossy
+ * in the time domain there shouldn't be any disparity. Infact, buffer underruns
+ * should get accounted for too FIXME TODO
+ */
+ pthread_mutex_lock(&pdata->avd_mutex);
+ pdata->avd -= pdata->periodtime;
+ pthread_mutex_unlock(&pdata->avd_mutex);
+
//queue the new buffer
pthread_mutex_lock(&pdata->sound_buffer_mutex);
tmp = pdata->sound_buffer;
diff --git a/src/rmd_encode_sound_buffer.c b/src/rmd_encode_sound_buffer.c
index 22e4ddc..8a1d3d4 100644
--- a/src/rmd_encode_sound_buffer.c
+++ b/src/rmd_encode_sound_buffer.c
@@ -127,10 +127,6 @@ void *rmdEncodeSoundBuffer(ProgData *pdata) {
}
}
pthread_mutex_unlock(&pdata->libogg_mutex);
-
- pthread_mutex_lock(&pdata->avd_mutex);
- pdata->avd -= pdata->periodtime;
- pthread_mutex_unlock(&pdata->avd_mutex);
}
pthread_mutex_lock(&pdata->vorbis_lib_mutex);
© All Rights Reserved