Skip to content

Commit

Permalink
Fix video recording sync drift (patch refactored but original author …
Browse files Browse the repository at this point in the history
…unknown)
  • Loading branch information
timangus committed Nov 2, 2013
1 parent ae0e09a commit 7ae49cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions code/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2940,13 +2940,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;
}
}

Expand Down
3 changes: 3 additions & 0 deletions code/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,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;
Expand Down
8 changes: 7 additions & 1 deletion code/client/snd_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,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;
}

Expand Down

1 comment on commit 7ae49cc

@entdark
Copy link

@entdark entdark commented on 7ae49cc Nov 2, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Author is either CaNaBiS or HMage (I bet it was CaNaBiS) and it's taken from q3mme: http://sourceforge.net/p/quake3mme/code/HEAD/tree/trunk/code/client/cl_main.c#l2023

Please sign in to comment.