mirror of
https://repo.dec05eba.com/gpu-screen-recorder
synced 2026-05-06 15:00:43 +09:00
Move amix to separate thread
This commit is contained in:
49
src/main.cpp
49
src/main.cpp
@@ -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.
|
std::thread amix_thread;
|
||||||
const double update_fps = fps + 190;
|
if(uses_amix) {
|
||||||
bool should_stop_error = false;
|
amix_thread = std::thread([&]() {
|
||||||
|
|
||||||
AVFrame *aframe = av_frame_alloc();
|
AVFrame *aframe = av_frame_alloc();
|
||||||
|
|
||||||
int64_t video_pts_counter = 0;
|
|
||||||
int64_t video_prev_pts = 0;
|
|
||||||
|
|
||||||
bool hdr_metadata_set = false;
|
|
||||||
|
|
||||||
while(running) {
|
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);
|
std::lock_guard<std::mutex> lock(audio_filter_mutex);
|
||||||
for(AudioTrack &audio_track : audio_tracks) {
|
for(AudioTrack &audio_track : audio_tracks) {
|
||||||
if(!audio_track.sink)
|
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);
|
const bool damaged = !capture->is_damaged || capture->is_damaged(capture);
|
||||||
if(damaged) {
|
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) {
|
if (replay_buffer_size_secs == -1 && av_write_trailer(av_format_context) != 0) {
|
||||||
fprintf(stderr, "Failed to write trailer\n");
|
fprintf(stderr, "Failed to write trailer\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user