try to solve the problem that video not fluent caused by previous commits

This commit is contained in:
sirius 2020-01-08 14:25:06 +08:00
parent d45b66938d
commit 483885b6b1
5 changed files with 16 additions and 13 deletions

View file

@ -2518,10 +2518,9 @@ void CClient::Update()
if (m_DemoPlayer.IsPlaying() && IVideo::Current())
{
if (IVideo::Current()->frameRendered())
{
IVideo::Current()->nextVideoFrame();
}
IVideo::Current()->nextAudioFrame_timeline();
if (IVideo::Current()->aframeRendered())
IVideo::Current()->nextAudioFrame_timeline();
}
else if(m_ButtonRender)
Disconnect();

View file

@ -287,6 +287,8 @@ static void SdlCallback(void *pUnused, Uint8 *pStream, int Len)
#if defined(CONF_VIDEORECORDER)
if (!(IVideo::Current() && g_Config.m_ClVideoSndEnable))
Mix((short *)pStream, Len/2/2);
else
IVideo::Current()->nextAudioFrame(Mix);
#else
Mix((short *)pStream, Len/2/2);
#endif
@ -357,11 +359,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
//#if defined(CONF_VIDEORECORDER)
// if(IVideo::Current() && g_Config.m_ClVideoSndEnable)
// IVideo::Current()->nextAudioFrame(Mix);
//#endif
return 0;
}

View file

@ -11,6 +11,7 @@
#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */
const size_t format_nchannels = 3;
static LOCK m_WriteLock = 0;
CVideo::CVideo(CGraphics_Threaded* pGraphics, IStorage* pStorage, IConsole *pConsole, int width, int height, const char *name) :
m_pGraphics(pGraphics),
@ -52,11 +53,13 @@ CVideo::CVideo(CGraphics_Threaded* pGraphics, IStorage* pStorage, IConsole *pCon
ms_TickTime = time_freq() / m_FPS;
ms_pCurrentVideo = this;
m_WriteLock = lock_create();
}
CVideo::~CVideo()
{
ms_pCurrentVideo = 0;
lock_destroy(m_WriteLock);
}
void CVideo::start()
@ -204,8 +207,6 @@ void CVideo::nextVideoFrame_thread()
{
if (m_NextFrame && m_Recording)
{
while(m_ProcessingAudioFrame)
continue;
// #ifdef CONF_PLATFORM_MACOSX
// CAutoreleasePool AutoreleasePool;
// #endif
@ -252,7 +253,7 @@ void CVideo::nextVideoFrame()
void CVideo::nextAudioFrame_timeline()
{
if (m_Recording && m_HasAudio && !m_NextaFrame)
if (m_Recording && m_HasAudio)
{
//if (m_vframe * m_AudioStream.enc->sample_rate / m_FPS >= m_AudioStream.enc->frame_number*m_AudioStream.enc->frame_size)
if (m_VideoStream.enc->frame_number * (double)m_AudioStream.enc->sample_rate / m_FPS >= (double)m_AudioStream.enc->frame_number*m_AudioStream.enc->frame_size)
@ -266,8 +267,6 @@ void CVideo::nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames))
{
if (m_NextaFrame && m_Recording && m_HasAudio)
{
while(m_ProcessingVideoFrame)
continue;
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)
@ -675,12 +674,14 @@ void CVideo::write_frame(OutputStream* pStream)
av_packet_rescale_ts(&Packet, pStream->enc->time_base, pStream->st->time_base);
Packet.stream_index = pStream->st->index;
lock_wait(m_WriteLock);
if (int ret = av_interleaved_write_frame(m_pFormatContext, &Packet))
{
char aBuf[AV_ERROR_MAX_STRING_SIZE];
av_strerror(ret, aBuf, sizeof(aBuf));
dbg_msg("video_recorder", "Error while writing video frame: %s", aBuf);
}
lock_unlock(m_WriteLock);
}
else
break;

View file

@ -66,6 +66,7 @@ public:
virtual void nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames));
virtual void nextAudioFrame_timeline();
virtual bool aframeRendered() { return !m_NextaFrame; }
static IVideo* Current() { return IVideo::ms_pCurrentVideo; }

View file

@ -16,6 +16,7 @@ public:
virtual void nextVideoFrame_thread() = 0;
virtual void nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames)) = 0;
virtual bool aframeRendered() = 0;
virtual void nextAudioFrame_timeline() = 0;