Move amix to separate thread

This commit is contained in:
dec05eba
2024-09-07 14:09:04 +02:00
parent 8158a809b7
commit 992792fb1f

View File

@@ -3266,29 +3266,11 @@ int main(int argc, char **argv) {
}
}
// Set update_fps to 24 to test if duplicate/delayed frames cause video/audio desync or too fast/slow video.
const double update_fps = fps + 190;
bool should_stop_error = false;
std::thread amix_thread;
if(uses_amix) {
amix_thread = std::thread([&]() {
AVFrame *aframe = av_frame_alloc();
int64_t video_pts_counter = 0;
int64_t video_prev_pts = 0;
bool hdr_metadata_set = false;
while(running) {
double frame_start = clock_get_monotonic_seconds();
gsr_capture_tick(capture, video_codec_context);
should_stop_error = false;
if(gsr_capture_should_stop(capture, &should_stop_error)) {
running = 0;
break;
}
// TODO: Move to another thread, since this shouldn't be locked to video encoding fps
{
std::lock_guard<std::mutex> lock(audio_filter_mutex);
for(AudioTrack &audio_track : audio_tracks) {
if(!audio_track.sink)
@@ -3309,6 +3291,28 @@ int main(int argc, char **argv) {
}
}
}
av_frame_free(&aframe);
});
}
// Set update_fps to 24 to test if duplicate/delayed frames cause video/audio desync or too fast/slow video.
const double update_fps = fps + 190;
bool should_stop_error = false;
int64_t video_pts_counter = 0;
int64_t video_prev_pts = 0;
bool hdr_metadata_set = false;
while(running) {
double frame_start = clock_get_monotonic_seconds();
gsr_capture_tick(capture, video_codec_context);
should_stop_error = false;
if(gsr_capture_should_stop(capture, &should_stop_error)) {
running = 0;
break;
}
const bool damaged = !capture->is_damaged || capture->is_damaged(capture);
if(damaged) {
@@ -3431,7 +3435,8 @@ int main(int argc, char **argv) {
}
}
av_frame_free(&aframe);
if(amix_thread.joinable())
amix_thread.join();
if (replay_buffer_size_secs == -1 && av_write_trailer(av_format_context) != 0) {
fprintf(stderr, "Failed to write trailer\n");