Direct mix when recording audio now, and seems solve the stuck problem when

DDNet is not the focusing window
This commit is contained in:
sirius 2019-11-02 16:09:00 +08:00
parent f2ffa996c2
commit e910fe404f
6 changed files with 39 additions and 43 deletions

View file

@ -2522,6 +2522,7 @@ void CClient::Update()
if (IVideo::Current()->frameRendered())
{
IVideo::Current()->nextVideoFrame();
IVideo::Current()->nextAudioFrame_timeline();
}
}
else if(m_ButtonRender)
@ -3356,10 +3357,7 @@ void CClient::StartVideo(IConsole::IResult *pResult, void *pUserData, const char
void CClient::Con_StopVideo(IConsole::IResult *pResult, void *pUserData)
{
if (IVideo::Current())
{
IVideo::Current()->stop();
delete IVideo::Current();
}
}
#endif

View file

@ -240,11 +240,6 @@ static void Mix(short *pFinalOut, unsigned Frames)
pInR += Step;
v->m_Tick++;
}
#if defined(CONF_VIDEORECORDER)
if(IVideo::Current())
if(m_LastBreak > IVideo::Current()->GetBreak())
v->m_Tick -= End;
#endif
// free voice if not used any more
if(v->m_Tick == v->m_pSample->m_NumFrames)
@ -284,27 +279,16 @@ static void Mix(short *pFinalOut, unsigned Frames)
swap_endian(pFinalOut, sizeof(short), Frames * 2);
#endif
#if defined(CONF_VIDEORECORDER)
if (IVideo::Current())
{
if(m_LastBreak <= IVideo::Current()->GetBreak())
{
if(!IVideo::Current()->GetSync())
IVideo::Current()->nextAudioFrame(pFinalOut);
m_LastBreak += 1;
}
}
#endif
}
static void SdlCallback(void *pUnused, Uint8 *pStream, int Len)
{
(void)pUnused;
Mix((short *)pStream, Len/2/2);
#if defined(CONF_VIDEORECORDER)
if (IVideo::Current())
memset(pStream, 0, Len);
if (!(IVideo::Current() && g_Config.m_ClVideoSndEnable))
Mix((short *)pStream, Len/2/2);
#else
Mix((short *)pStream, Len/2/2);
#endif
}
@ -373,6 +357,10 @@ int CSound::Update()
m_SoundVolume = WantedVolume;
lock_unlock(m_SoundLock);
}
#if defined(CONF_VIDEORECORDER)
if(IVideo::Current() && g_Config.m_ClVideoSndEnable)
IVideo::Current()->nextAudioFrame(Mix);
#endif
return 0;
}

View file

@ -182,12 +182,16 @@ void CVideo::stop()
if (m_pPixels)
free(m_pPixels);
if (ms_pCurrentVideo)
delete ms_pCurrentVideo;
}
void CVideo::nextVideoFrame_thread()
{
if (m_NextFrame)
{
m_ProcessingVideoFrame = true;
// #ifdef CONF_PLATFORM_MACOSX
// CAutoreleasePool AutoreleasePool;
// #endif
@ -221,7 +225,6 @@ void CVideo::nextVideoFrame()
ms_Time += ms_TickTime;
ms_LocalTime = (ms_Time-ms_LocalStartTime)/(float)time_freq();
m_ProcessingVideoFrame = true;
m_NextFrame = true;
m_vframe += 1;
@ -232,18 +235,26 @@ void CVideo::nextVideoFrame()
}
}
void CVideo::nextAudioFrame(short* pData)
void CVideo::nextAudioFrame_timeline()
{
if (m_Recording && m_HasAudio)
if (m_Recording && m_HasAudio && !m_ProcessingAudioFrame)
{
if ((double)(m_vframe/m_FPS) >= m_AudioStream.enc->frame_number*m_AudioStream.enc->frame_size/m_AudioStream.enc->sample_rate)
{
m_NextaFrame = true;
}
}
}
void CVideo::nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames))
{
if (m_NextaFrame)
{
m_ProcessingAudioFrame = true;
//dbg_msg("video recorder", "video_frame: %lf", (double)(m_vframe/m_FPS));
//if((double)(m_vframe/m_FPS) < m_AudioStream.enc->frame_number*m_AudioStream.enc->frame_size/m_AudioStream.enc->sample_rate)
//return;
m_aseq += 1;
mem_copy(m_aBuffer+(m_aseq%2)*1024, pData, sizeof(short)*1024);
if(!(m_aseq % 2) || m_aseq < 4) // jump first two audio frames
return;
m_ProcessingAudioFrame = true;
Mix(m_aBuffer, ALEN);
//m_AudioStream.frame->pts = m_AudioStream.enc->frame_number;
dbg_msg("video_recorder", "aframe: %d", m_AudioStream.enc->frame_number);
@ -308,6 +319,7 @@ void CVideo::nextAudioFrame(short* pData)
write_frame(&m_AudioStream);
m_ProcessingAudioFrame = false;
m_NextaFrame = false;
}
}

View file

@ -32,6 +32,7 @@ extern "C"
#include <engine/shared/video.h>
#include <engine/shared/demo.h>
#define ALEN 2048
// a wrapper around a single output AVStream
@ -61,15 +62,16 @@ public:
virtual void nextVideoFrame();
virtual void nextVideoFrame_thread();
virtual bool frameRendered() { return !m_NextFrame; };
virtual bool frameRendered() { return !m_NextFrame; }
virtual void nextAudioFrame(short* pData);
virtual void nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames));
virtual void nextAudioFrame_timeline();
static IVideo* Current() { return IVideo::ms_pCurrentVideo; }
static void Init() { av_log_set_level(AV_LOG_DEBUG); avcodec_register_all(); av_register_all(); }
bool GetSync() { if(m_Recording) return (double)(m_vframe/m_FPS) < m_AudioStream.enc->frame_number*m_AudioStream.enc->frame_size/m_AudioStream.enc->sample_rate; }
bool GetSync() { if(m_Recording) return (double)(m_vframe/m_FPS) <= m_AudioStream.enc->frame_number*m_AudioStream.enc->frame_size/m_AudioStream.enc->sample_rate; }
private:
void fill_video_frame();
@ -98,7 +100,7 @@ private:
//FILE *m_dbgfile;
int m_aseq;
int m_vseq;
short m_aBuffer[2048];
short m_aBuffer[ALEN];
int m_vframe;
int m_FPS;
@ -110,6 +112,7 @@ private:
bool m_ProcessingAudioFrame;
bool m_NextFrame;
bool m_NextaFrame;
bool m_HasAudio;

View file

@ -548,10 +548,7 @@ void CDemoPlayer::DoTick()
m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "demo_player", "end of file");
#if defined(CONF_VIDEORECORDER)
if (IVideo::Current())
{
IVideo::Current()->stop();
delete IVideo::Current();
}
Stop();
#endif
if(m_Info.m_PreviousTick == -1)
{
@ -975,10 +972,7 @@ int CDemoPlayer::Stop()
{
#if defined(CONF_VIDEORECORDER)
if (IVideo::Current())
{
IVideo::Current()->stop();
delete IVideo::Current();
}
#endif
if(!m_File)

View file

@ -15,7 +15,8 @@ public:
virtual bool frameRendered() = 0;
virtual void nextVideoFrame_thread() = 0;
virtual void nextAudioFrame(short* pData) = 0;
virtual void nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames)) = 0;
virtual void nextAudioFrame_timeline() = 0;
virtual bool GetSync() = 0;