diff --git a/meson.build b/meson.build index 33e5155..1a2d211 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('gpu-screen-recorder', ['c', 'cpp'], version : '5.10.0', default_options : ['warning_level=2']) +project('gpu-screen-recorder', ['c', 'cpp'], version : '5.10.1', default_options : ['warning_level=2']) add_project_arguments('-Wshadow', language : ['c', 'cpp']) if get_option('buildtype') == 'debug' diff --git a/project.conf b/project.conf index 14f5f25..7a8e69e 100644 --- a/project.conf +++ b/project.conf @@ -1,7 +1,7 @@ [package] name = "gpu-screen-recorder" type = "executable" -version = "5.10.0" +version = "5.10.1" platforms = ["posix"] [config] diff --git a/src/main.cpp b/src/main.cpp index 583072c..8329877 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3552,7 +3552,7 @@ int main(int argc, char **argv) { while(running) { void *sound_buffer; int sound_buffer_size = -1; - //const double time_before_read_seconds = clock_get_monotonic_seconds(); + const double time_before_read_seconds = clock_get_monotonic_seconds(); if(audio_device.sound_device.handle) { // TODO: use this instead of calculating time to read. But this can fluctuate and we dont want to go back in time, // also it's 0.0 for some users??? @@ -3562,8 +3562,6 @@ int main(int argc, char **argv) { const bool got_audio_data = sound_buffer_size >= 0; //fprintf(stderr, "got audio data: %s\n", got_audio_data ? "yes" : "no"); - //const double time_after_read_seconds = clock_get_monotonic_seconds(); - //const double time_to_read_seconds = time_after_read_seconds - time_before_read_seconds; //fprintf(stderr, "time to read: %f, %s, %f\n", time_to_read_seconds, got_audio_data ? "yes" : "no", timeout_sec); const double this_audio_frame_time = clock_get_monotonic_seconds() - paused_time_offset; @@ -3632,10 +3630,9 @@ int main(int argc, char **argv) { } } - if(!audio_device.sound_device.handle) + if(!audio_device.sound_device.handle) { av_usleep(timeout_ms * 1000); - - if(got_audio_data) { + } else if(got_audio_data) { // TODO: Instead of converting audio, get float audio from alsa. Or does alsa do conversion internally to get this format? if(needs_audio_conversion) swr_convert(swr, &audio_device.frame->data[0], audio_track.codec_context->frame_size, (const uint8_t**)&sound_buffer, audio_track.codec_context->frame_size); @@ -3663,6 +3660,12 @@ int main(int argc, char **argv) { audio_device.frame->pts += audio_track.codec_context->frame_size; num_received_frames++; + } else { + const double time_after_read_seconds = clock_get_monotonic_seconds(); + const double time_to_read_seconds = time_after_read_seconds - time_before_read_seconds; + const double time_to_sleep_until_next_frame = timeout_sec - time_to_read_seconds; + if(time_to_sleep_until_next_frame > 0.0) + av_usleep(time_to_sleep_until_next_frame * 1000ULL * 1000ULL); } } diff --git a/src/sound.cpp b/src/sound.cpp index 69ad1e6..1be3aed 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -312,10 +312,9 @@ static int pa_sound_device_read(pa_handle *p, double timeout_seconds) { if(!pa_sound_device_handle_reconnect(p, device_name, sizeof(device_name), start_time)) goto fail; - if(pa_stream_get_state(p->stream) != PA_STREAM_READY) { - pa_mainloop_iterate(p->mainloop, 0, NULL); + pa_mainloop_iterate(p->mainloop, 0, NULL); + if(pa_stream_get_state(p->stream) != PA_STREAM_READY) goto fail; - } CHECK_DEAD_GOTO(p, rerror, fail);