Skip to content

Commit

Permalink
fix for avi split having a chance of dropping a few frames
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Nov 4, 2011
1 parent a681d2e commit 51e0d25
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions src/wintaser/wintaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ static int LoadMovieFromFile(/*out*/ Movie& movie, const char* filename, bool fo
// and maybe add more specific warning messages, if warranted

bool assumeOK = false;
#if SRCVERSION >= 71 && SRCVERSION <= 77 // a range of definitely sync-compatible versions
#if SRCVERSION >= 71 && SRCVERSION <= 78 // a range of definitely sync-compatible versions
if(version >= 71 && version < SRCVERSION)
assumeOK = true;
#endif
Expand Down Expand Up @@ -3330,11 +3330,13 @@ struct AviFrameQueue
for(int i = 0; i < numSlots; i++)
m_slots[i].slotNum = i;
threadDone = false;
thread = CreateThread(NULL, 0, AviFrameQueue<numSlots>::OutputVideoThreadFunc, (void*)this, 0, NULL);
thread = CreateThread(NULL, 0, AviFrameQueue<numSlots>::OutputVideoThreadFunc, (void*)this, CREATE_SUSPENDED, NULL);
SetThreadPriority(thread, THREAD_PRIORITY_HIGHEST);
threadAudio = CreateThread(NULL, 0, AviFrameQueue<numSlots>::OutputAudioThreadFunc, (void*)this, 0, NULL);
SetThreadPriority(thread, THREAD_PRIORITY_ABOVE_NORMAL);
threadAudio = CreateThread(NULL, 0, AviFrameQueue<numSlots>::OutputAudioThreadFunc, (void*)this, CREATE_SUSPENDED, NULL);
SetThreadPriority(threadAudio, THREAD_PRIORITY_ABOVE_NORMAL);
m_disableFills = false;
ResumeThread(thread);
ResumeThread(threadAudio);
}
~AviFrameQueue()
{
Expand Down Expand Up @@ -3379,6 +3381,15 @@ struct AviFrameQueue
CloseHandle(threadAudio);
}

void Flush()
{
for(int i = 0; i < numSlots; i++)
{
m_slots[i].hasProcessedVideo.WaitUntilFalse();
m_slots[i].hasProcessedAudio.WaitUntilFalse();
}
}

// send a new frame to AVI
void FillFrame(void* remotePixels, int width, int height, int pitch, int bpp,
int rmask, int gmask, int bmask)
Expand Down Expand Up @@ -3785,7 +3796,7 @@ struct AviFrameQueue
if((aviMode & 1) /*&& (framerate <= 0)*/)
{
aviSoundSecondsCount = nextAviSoundSecondsCount;
int prevAviSoundFrameCount = aviSoundFrameCount;
//int prevAviSoundFrameCount = aviSoundFrameCount;
aviSoundFrameCount = (int)(aviSoundSecondsCount * curAviFps);
//if(aviSoundFrameCount <= prevAviSoundFrameCount)
// aviSoundFrameCount = prevAviSoundFrameCount + 1;
Expand Down Expand Up @@ -3893,17 +3904,17 @@ void CloseAVI()
if(aviStream)
oldIsBasicallyEmpty |= (aviFrameCount-aviEmptyFrameCount < 5 && aviSoundFrameCount < 15);

if(aviFrameQueue)
aviFrameQueue->Flush();
AutoCritSect cs1(&s_fqaCS);
AutoCritSect cs2(&s_fqvCS);
delete aviFrameQueue;
aviFrameQueue = NULL;

aviMode = 0;
aviSplitCount = 0;
aviSplitDiscardCount = 0;

{
AutoCritSect cs(&s_fqaCS);
AutoCritSect cs2(&s_fqvCS);
delete aviFrameQueue;
aviFrameQueue = NULL;
}

aviFrameCount = 0;
aviEmptyFrameCount = 0;
aviSoundFrameCount = 0;
Expand Down Expand Up @@ -4317,9 +4328,16 @@ void WriteAVIAudio()
}
}

if(aviCompressedStream && (aviSoundFrameCount < 30 || aviSoundFrameCount+8 < aviFrameCount))
while(aviSoundFrameCount < aviFrameCount/*-aviEmptyFrameCount*/)
aviFrameQueue->FillEmptyAudioFrame(); // in case video started before audio
if(aviCompressedStream && (aviSoundFrameCount < 30 || aviSoundFrameCount+8 < aviFrameCount) && !aviSplitCount)
{
if(aviSoundFrameCount < aviFrameCount/*-aviEmptyFrameCount*/)
{
AutoCritSect cs(&s_fqaCS); // critical section and check again in case we got here while CloseAVI is running
if(aviCompressedStream && (aviSoundFrameCount < 30 || aviSoundFrameCount+8 < aviFrameCount) && !aviSplitCount)
while(aviSoundFrameCount < aviFrameCount/*-aviEmptyFrameCount*/)
aviFrameQueue->FillEmptyAudioFrame(); // in case video started before audio
}
}

aviFrameQueue->FillAudioFrame();

Expand Down Expand Up @@ -4405,6 +4423,7 @@ static void HandleAviSplitRequests()
int oldAviMode = aviMode;
int oldAviSplitDiscardCount = aviSplitDiscardCount;
int oldRequestedAviSplitCount = requestedAviSplitCount;
Sleep(200); // this isn't a fix for anything, the proper waits are in place. but it can't hurt...
CloseAVI();
aviMode = oldAviMode;
aviSplitDiscardCount = oldAviSplitDiscardCount;
Expand Down

0 comments on commit 51e0d25

Please sign in to comment.