summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2013-11-02 19:11:14 +0000
committerTim Angus <tim@ngus.net>2014-06-17 17:43:35 +0100
commit2fee3c939af105c5a75696702f58ef267da7bf49 (patch)
treeb939556ab131ff3288361389d85f417ce45db7d5
parent43c7250cfde2d4b79896919833a0435275cb8be3 (diff)
Fix video recording sync drift (patch refactored but original author unknown)
-rw-r--r--src/client/cl_main.c10
-rw-r--r--src/client/client.h3
-rw-r--r--src/client/snd_dma.c8
3 files changed, 15 insertions, 6 deletions
diff --git a/src/client/cl_main.c b/src/client/cl_main.c
index d597e29a..564c5406 100644
--- a/src/client/cl_main.c
+++ b/src/client/cl_main.c
@@ -3009,13 +3009,13 @@ void CL_Frame ( int msec ) {
if ( CL_VideoRecording( ) && cl_aviFrameRate->integer && msec) {
// save the current screen
if ( clc.state == CA_ACTIVE || cl_forceavidemo->integer) {
+ float fps = MIN(cl_aviFrameRate->value * com_timescale->value, 1000.0f);
+ float frameDuration = MAX(1000.0f / fps, 1.0f) + clc.aviVideoFrameRemainder;
+
CL_TakeVideoFrame( );
- // fixed time for next frame'
- msec = (int)ceil( (1000.0f / cl_aviFrameRate->value) * com_timescale->value );
- if (msec == 0) {
- msec = 1;
- }
+ msec = (int)frameDuration;
+ clc.aviVideoFrameRemainder = frameDuration - msec;
}
}
diff --git a/src/client/client.h b/src/client/client.h
index a875f9dd..541dca40 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -236,6 +236,9 @@ typedef struct {
int timeDemoMaxDuration; // maximum frame duration
unsigned char timeDemoDurations[ MAX_TIMEDEMO_DURATIONS ]; // log of frame durations
+ float aviVideoFrameRemainder;
+ float aviSoundFrameRemainder;
+
#ifdef USE_VOIP
qboolean voipEnabled;
qboolean speexInitialized;
diff --git a/src/client/snd_dma.c b/src/client/snd_dma.c
index 369c9388..081319ca 100644
--- a/src/client/snd_dma.c
+++ b/src/client/snd_dma.c
@@ -1258,7 +1258,13 @@ void S_GetSoundtime(void)
if( CL_VideoRecording( ) )
{
- s_soundtime += (int)ceil( dma.speed / cl_aviFrameRate->value );
+ float fps = MIN(cl_aviFrameRate->value, 1000.0f);
+ float frameDuration = MAX(dma.speed / fps, 1.0f) + clc.aviSoundFrameRemainder;
+
+ int msec = (int)frameDuration;
+ s_soundtime += msec;
+ clc.aviSoundFrameRemainder = frameDuration - msec;
+
return;
}