summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2020-07-12 11:14:30 -0700
committerVito Caputo <vcaputo@pengaru.com>2020-07-12 11:14:30 -0700
commit193a1e77bf798ef2ce2a1546d845f3bfe6ab3928 (patch)
tree5bc2701279b1fd3fdd4d3054270d7a003e23e708
parent99bc91a3c939e07f2d754a67dce60a55d509b3c1 (diff)
*: standardize sleeps on nanosleep()
usleep() is deprecated by posix in favor of nanosleep(), nanosleep doesn't dick with signals so it's generally better anyways.
-rw-r--r--src/rmd_capture_sound.c3
-rw-r--r--src/rmd_flush_to_ogg.c4
-rw-r--r--src/rmd_threads.c7
-rw-r--r--src/rmd_timer.c13
4 files changed, 14 insertions, 13 deletions
diff --git a/src/rmd_capture_sound.c b/src/rmd_capture_sound.c
index 2719c60..76ccd4b 100644
--- a/src/rmd_capture_sound.c
+++ b/src/rmd_capture_sound.c
@@ -38,6 +38,7 @@
#include <sys/uio.h>
#include <unistd.h>
#include <stdlib.h>
+#include <time.h>
void *rmdCaptureSound(ProgData *pdata) {
@@ -46,7 +47,7 @@ void *rmdCaptureSound(ProgData *pdata) {
int frames = pdata->periodsize;
#endif
//start capturing only after first frame is taken
- usleep(pdata->frametime);
+ nanosleep(&(struct timespec){ .tv_nsec = pdata->frametime * 1000 }, NULL);
while (pdata->running) {
int sret = 0;
diff --git a/src/rmd_flush_to_ogg.c b/src/rmd_flush_to_ogg.c
index d2e7f44..4a9fb71 100644
--- a/src/rmd_flush_to_ogg.c
+++ b/src/rmd_flush_to_ogg.c
@@ -37,10 +37,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
+#include <time.h>
#include <unistd.h>
-
//we copy the page because the next call to ogg_stream_pageout
//will invalidate it. But we must have pages from
//both streams at every time in
@@ -162,7 +162,7 @@ void *rmdFlushToOgg(ProgData *pdata) {
audioflag=0;
#endif
if ((!audioflag && !v_st_fin && !pdata->args.nosound) || (!videoflag && !th_st_fin)) {
- usleep(10000);
+ nanosleep(&(struct timespec){ .tv_nsec = 10000000 }, NULL);
continue;
}
diff --git a/src/rmd_threads.c b/src/rmd_threads.c
index 69b98bf..88a4bbc 100644
--- a/src/rmd_threads.c
+++ b/src/rmd_threads.c
@@ -44,6 +44,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/prctl.h>
+#include <time.h>
#include <unistd.h>
void rmdThreads(ProgData *pdata) {
@@ -58,7 +59,7 @@ void rmdThreads(ProgData *pdata) {
if (pdata->args.delay > 0) {
fprintf(stderr, "Will sleep for %d seconds now.\n", pdata->args.delay);
- sleep(pdata->args.delay);
+ nanosleep(&(struct timespec){ .tv_sec = pdata->args.delay }, NULL);
}
/*start threads*/
@@ -125,7 +126,7 @@ void rmdThreads(ProgData *pdata) {
puts("waiting for th_enc");
pthread_cond_signal(&pdata->image_buffer_ready);
pthread_mutex_unlock(&pdata->theora_lib_mutex);
- usleep(10000);
+ nanosleep(&(struct timespec){ .tv_nsec = 10000000 }, NULL);
pthread_mutex_lock(&pdata->theora_lib_mutex);
}
pthread_mutex_unlock(&pdata->theora_lib_mutex);
@@ -150,7 +151,7 @@ void rmdThreads(ProgData *pdata) {
puts("waiting for v_enc");
pthread_cond_signal(&pdata->sound_data_read);
pthread_mutex_unlock(&pdata->vorbis_lib_mutex);
- usleep(10000);
+ nanosleep(&(struct timespec){ .tv_nsec = 10000000 }, NULL);
pthread_mutex_lock(&pdata->vorbis_lib_mutex);
}
pthread_mutex_unlock(&pdata->vorbis_lib_mutex);
diff --git a/src/rmd_timer.c b/src/rmd_timer.c
index b8161ca..6c3e483 100644
--- a/src/rmd_timer.c
+++ b/src/rmd_timer.c
@@ -34,12 +34,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
+#include <time.h>
#include <unistd.h>
void *rmdTimer(ProgData *pdata){
- long unsigned int secs_tw=1/pdata->args.fps;
- long unsigned int usecs_tw=(1000000)/pdata->args.fps- secs_tw*1000000;
+ struct timespec delay;
+
+ delay.tv_sec = 1.f / pdata->args.fps;
+ delay.tv_nsec = 1000000000.f / pdata->args.fps - delay.tv_sec * 1000000000.f;
while (pdata->timer_alive) {
@@ -70,11 +73,7 @@ void *rmdTimer(ProgData *pdata){
pthread_mutex_unlock(&pdata->time_mutex);
pthread_cond_signal(&pdata->time_cond);
- /* FIXME use nanosleep */
- if (secs_tw)
- sleep(secs_tw);
-
- usleep(usecs_tw);
+ nanosleep(&delay, NULL);
}
pthread_exit(&errno);
© All Rights Reserved