diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-07-15 01:52:27 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-07-15 01:52:27 -0700 |
commit | 19a7c45b7b4adcd13b5481697f5cb82ba378918b (patch) | |
tree | 7e05e6a4ade39f2ebe0ea0b546b72cf65212aa41 /src/rmd_timer.c | |
parent | 63c510aca1de960ee12d2ee5b83b794c50258b44 (diff) |
timer: maintain video side of avd in frame timer
Since the frame timer implements a frame counter, and that frame count
is propagated through the get->encode pipeline for samples that get
through, any missed frames are noticed and dealt with making it not
lossy from the point of the timer down to the encoded stream in terms
of number of frames.
It's certainly lossy in terms of the contents of those frames, but
synchronization is all about the temporal domain and as long as the
frame counts all make it into the stream as frames, we can account
for them at the timer in terms of avd.
This in combination with the other commit moving the audio side of
avd maintenance immediately upon capture into the raw buffer, shrinks
the variable capacitance separating the audio timer and the frame
timer to virtually nil. As a consequence, the frame timer can now
be much more accurate in terms of how much longer/less to sleep or
if a frame should be dropped to get the timer caught up.
When avd was being maintained at points far removed from the actual
things they represented there was too much elastic capacitance in
there for sync_streams() to inform its adjustment accurately.
Diffstat (limited to 'src/rmd_timer.c')
-rw-r--r-- | src/rmd_timer.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/rmd_timer.c b/src/rmd_timer.c index a523166..dd7b26c 100644 --- a/src/rmd_timer.c +++ b/src/rmd_timer.c @@ -51,8 +51,7 @@ static void sync_streams(ProgData *pdata, unsigned int *frame_step, struct times int avd; pthread_mutex_lock(&pdata->avd_mutex); - avd = pdata->avd; - pthread_mutex_unlock(&pdata->avd_mutex); + avd = pdata->avd + pdata->frametime; /* There are two knobs available for keeping the video synchronized with the audio: * 1. frame_step; how many frames to encode from this frame (aka dropping frames if > 1) @@ -72,6 +71,7 @@ static void sync_streams(ProgData *pdata, unsigned int *frame_step, struct times if (frames_behind > 0) { /* more than a whole frame behind, drop frames to catch up */ *frame_step += frames_behind; + avd += frames_behind * pdata->frametime; } else { /* less than a whole frame behind, just sleep less */ *delay = us_to_timespec(pdata->frametime + avd); @@ -82,6 +82,9 @@ static void sync_streams(ProgData *pdata, unsigned int *frame_step, struct times *delay = us_to_timespec(pdata->frametime + avd); } + pdata->avd = avd; + pthread_mutex_unlock(&pdata->avd_mutex); + #if 0 printf("avd: %i frame_step: %u delay: %lu,%lu\n", avd, *frame_step, (*delay).tv_sec, (*delay).tv_nsec); |