mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-13 03:28:19 +00:00
try to solve the problem that video not fluent caused by previous commits
This commit is contained in:
parent
d45b66938d
commit
483885b6b1
|
@ -2518,10 +2518,9 @@ void CClient::Update()
|
||||||
if (m_DemoPlayer.IsPlaying() && IVideo::Current())
|
if (m_DemoPlayer.IsPlaying() && IVideo::Current())
|
||||||
{
|
{
|
||||||
if (IVideo::Current()->frameRendered())
|
if (IVideo::Current()->frameRendered())
|
||||||
{
|
|
||||||
IVideo::Current()->nextVideoFrame();
|
IVideo::Current()->nextVideoFrame();
|
||||||
}
|
if (IVideo::Current()->aframeRendered())
|
||||||
IVideo::Current()->nextAudioFrame_timeline();
|
IVideo::Current()->nextAudioFrame_timeline();
|
||||||
}
|
}
|
||||||
else if(m_ButtonRender)
|
else if(m_ButtonRender)
|
||||||
Disconnect();
|
Disconnect();
|
||||||
|
|
|
@ -287,6 +287,8 @@ static void SdlCallback(void *pUnused, Uint8 *pStream, int Len)
|
||||||
#if defined(CONF_VIDEORECORDER)
|
#if defined(CONF_VIDEORECORDER)
|
||||||
if (!(IVideo::Current() && g_Config.m_ClVideoSndEnable))
|
if (!(IVideo::Current() && g_Config.m_ClVideoSndEnable))
|
||||||
Mix((short *)pStream, Len/2/2);
|
Mix((short *)pStream, Len/2/2);
|
||||||
|
else
|
||||||
|
IVideo::Current()->nextAudioFrame(Mix);
|
||||||
#else
|
#else
|
||||||
Mix((short *)pStream, Len/2/2);
|
Mix((short *)pStream, Len/2/2);
|
||||||
#endif
|
#endif
|
||||||
|
@ -357,11 +359,10 @@ int CSound::Update()
|
||||||
m_SoundVolume = WantedVolume;
|
m_SoundVolume = WantedVolume;
|
||||||
lock_unlock(m_SoundLock);
|
lock_unlock(m_SoundLock);
|
||||||
}
|
}
|
||||||
#if defined(CONF_VIDEORECORDER)
|
//#if defined(CONF_VIDEORECORDER)
|
||||||
if(IVideo::Current() && g_Config.m_ClVideoSndEnable)
|
// if(IVideo::Current() && g_Config.m_ClVideoSndEnable)
|
||||||
IVideo::Current()->nextAudioFrame(Mix);
|
// IVideo::Current()->nextAudioFrame(Mix);
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */
|
#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */
|
||||||
|
|
||||||
const size_t format_nchannels = 3;
|
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) :
|
CVideo::CVideo(CGraphics_Threaded* pGraphics, IStorage* pStorage, IConsole *pConsole, int width, int height, const char *name) :
|
||||||
m_pGraphics(pGraphics),
|
m_pGraphics(pGraphics),
|
||||||
|
@ -52,11 +53,13 @@ CVideo::CVideo(CGraphics_Threaded* pGraphics, IStorage* pStorage, IConsole *pCon
|
||||||
|
|
||||||
ms_TickTime = time_freq() / m_FPS;
|
ms_TickTime = time_freq() / m_FPS;
|
||||||
ms_pCurrentVideo = this;
|
ms_pCurrentVideo = this;
|
||||||
|
m_WriteLock = lock_create();
|
||||||
}
|
}
|
||||||
|
|
||||||
CVideo::~CVideo()
|
CVideo::~CVideo()
|
||||||
{
|
{
|
||||||
ms_pCurrentVideo = 0;
|
ms_pCurrentVideo = 0;
|
||||||
|
lock_destroy(m_WriteLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVideo::start()
|
void CVideo::start()
|
||||||
|
@ -204,8 +207,6 @@ void CVideo::nextVideoFrame_thread()
|
||||||
{
|
{
|
||||||
if (m_NextFrame && m_Recording)
|
if (m_NextFrame && m_Recording)
|
||||||
{
|
{
|
||||||
while(m_ProcessingAudioFrame)
|
|
||||||
continue;
|
|
||||||
// #ifdef CONF_PLATFORM_MACOSX
|
// #ifdef CONF_PLATFORM_MACOSX
|
||||||
// CAutoreleasePool AutoreleasePool;
|
// CAutoreleasePool AutoreleasePool;
|
||||||
// #endif
|
// #endif
|
||||||
|
@ -252,7 +253,7 @@ void CVideo::nextVideoFrame()
|
||||||
|
|
||||||
void CVideo::nextAudioFrame_timeline()
|
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_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)
|
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)
|
if (m_NextaFrame && m_Recording && m_HasAudio)
|
||||||
{
|
{
|
||||||
while(m_ProcessingVideoFrame)
|
|
||||||
continue;
|
|
||||||
m_ProcessingAudioFrame = true;
|
m_ProcessingAudioFrame = true;
|
||||||
//dbg_msg("video recorder", "video_frame: %lf", (double)(m_vframe/m_FPS));
|
//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)
|
//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);
|
av_packet_rescale_ts(&Packet, pStream->enc->time_base, pStream->st->time_base);
|
||||||
Packet.stream_index = pStream->st->index;
|
Packet.stream_index = pStream->st->index;
|
||||||
|
|
||||||
|
lock_wait(m_WriteLock);
|
||||||
if (int ret = av_interleaved_write_frame(m_pFormatContext, &Packet))
|
if (int ret = av_interleaved_write_frame(m_pFormatContext, &Packet))
|
||||||
{
|
{
|
||||||
char aBuf[AV_ERROR_MAX_STRING_SIZE];
|
char aBuf[AV_ERROR_MAX_STRING_SIZE];
|
||||||
av_strerror(ret, aBuf, sizeof(aBuf));
|
av_strerror(ret, aBuf, sizeof(aBuf));
|
||||||
dbg_msg("video_recorder", "Error while writing video frame: %s", aBuf);
|
dbg_msg("video_recorder", "Error while writing video frame: %s", aBuf);
|
||||||
}
|
}
|
||||||
|
lock_unlock(m_WriteLock);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -66,6 +66,7 @@ public:
|
||||||
|
|
||||||
virtual void nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames));
|
virtual void nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames));
|
||||||
virtual void nextAudioFrame_timeline();
|
virtual void nextAudioFrame_timeline();
|
||||||
|
virtual bool aframeRendered() { return !m_NextaFrame; }
|
||||||
|
|
||||||
static IVideo* Current() { return IVideo::ms_pCurrentVideo; }
|
static IVideo* Current() { return IVideo::ms_pCurrentVideo; }
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ public:
|
||||||
virtual void nextVideoFrame_thread() = 0;
|
virtual void nextVideoFrame_thread() = 0;
|
||||||
|
|
||||||
virtual void nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames)) = 0;
|
virtual void nextAudioFrame(void (*Mix)(short *pFinalOut, unsigned Frames)) = 0;
|
||||||
|
virtual bool aframeRendered() = 0;
|
||||||
virtual void nextAudioFrame_timeline() = 0;
|
virtual void nextAudioFrame_timeline() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue