Skip to content

Commit

Permalink
More care with going into and out of buffering.
Browse files Browse the repository at this point in the history
Try to wait for GPU fifos to be full before resuming from buffering.
Use pre-roll mecahnism from clock.
  • Loading branch information
popcornmix committed Mar 25, 2013
1 parent 730ca65 commit aec02f4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
9 changes: 0 additions & 9 deletions OMXAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,6 @@ void COMXAudio::WaitCompletion()

OMX_ERRORTYPE omx_err = OMX_ErrorNone;
OMX_BUFFERHEADERTYPE *omx_buffer = m_omx_decoder.GetInputBuffer();
struct timespec starttime, endtime;

if(omx_buffer == NULL)
{
Expand All @@ -1206,18 +1205,10 @@ void COMXAudio::WaitCompletion()
return;
}

// clock_gettime(CLOCK_REALTIME, &starttime);

while(true)
{
if(m_omx_render.IsEOS())
break;
// clock_gettime(CLOCK_REALTIME, &endtime);
// if((endtime.tv_sec - starttime.tv_sec) > 2)
// {
// CLog::Log(LOGERROR, "%s::%s - wait for eos timed out\n", CLASSNAME, __func__);
// break;
// }
OMXClock::OMXSleep(50);
}

Expand Down
9 changes: 8 additions & 1 deletion OMXClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include "OMXClock.h"

#define OMX_PRE_ROLL 200

int64_t OMXClock::m_systemOffset;
int64_t OMXClock::m_systemFrequency;
bool OMXClock::m_ismasterclock;
Expand Down Expand Up @@ -281,10 +283,12 @@ bool OMXClock::OMXInitialize(bool has_video, bool has_audio)
if(!m_omx_clock.Initialize(componentName, OMX_IndexParamOtherInit))
return false;

#if 0
OMX_TIME_CONFIG_CLOCKSTATETYPE clock;
OMX_INIT_STRUCTURE(clock);

clock.eState = OMX_TIME_ClockStateWaitingForStartTime;
clock.nOffset = ToOMXTime(-1000LL * OMX_PRE_ROLL);

if(m_has_audio)
{
Expand All @@ -302,7 +306,7 @@ bool OMXClock::OMXInitialize(bool has_video, bool has_audio)
CLog::Log(LOGERROR, "OMXClock::Initialize error setting OMX_IndexConfigTimeClockState\n");
return false;
}

#endif
OMX_TIME_CONFIG_ACTIVEREFCLOCKTYPE refClock;
OMX_INIT_STRUCTURE(refClock);

Expand Down Expand Up @@ -487,6 +491,8 @@ bool OMXClock::OMXReset(bool lock /* = true */)
OMXStop(false);

clock.eState = OMX_TIME_ClockStateWaitingForStartTime;
clock.nOffset = ToOMXTime(-1000LL * OMX_PRE_ROLL);

if(m_has_audio)
{
clock.nWaitMask |= OMX_CLOCKPORT0;
Expand Down Expand Up @@ -705,6 +711,7 @@ bool OMXClock::OMXWaitStart(double pts, bool lock /* = true */)
else
{
clock.eState = OMX_TIME_ClockStateWaitingForStartTime;
clock.nOffset = ToOMXTime(-1000LL * OMX_PRE_ROLL);

if(m_has_audio)
{
Expand Down
7 changes: 7 additions & 0 deletions OMXPlayerVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,12 @@ void OMXPlayerVideo::Output(double pts)
m_FlipTimeStamp += max(0.0, iSleepTime);
m_FlipTimeStamp += iFrameDuration;

#if 0
while(m_av_clock->GetAbsoluteClock(false) < (iCurrentClock + iSleepTime + DVD_MSEC_TO_TIME(500)) )
{
OMXClock::OMXSleep(10);
}
#endif

/*
printf("iPlayingClock %f iCurrentClock %f iClockSleep %f iFrameSleep %f iFrameDuration %f WaitAbsolut %f m_FlipTimeStamp %f pts %f\n",
Expand All @@ -271,7 +273,9 @@ void OMXPlayerVideo::Output(double pts)

//g_renderManager.FlipPage(CThread::m_bStop, (iCurrentClock + iSleepTime) / DVD_TIME_BASE, -1, mDisplayField);

#if 0
m_av_clock->WaitAbsoluteClock((iCurrentClock + iSleepTime));
#endif

// guess next frame pts. iDuration is always valid
if (m_speed != 0)
Expand Down Expand Up @@ -379,6 +383,9 @@ bool OMXPlayerVideo::Decode(OMXPacket *pkt)

ret = true;
}
else
// video fifo is full, allow other tasks to run
OMXClock::OMXSleep(10);

return ret;
}
Expand Down
27 changes: 14 additions & 13 deletions omxplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ bool m_Pause = false;
OMXReader m_omx_reader;
int m_audio_index_use = -1;
int m_seek_pos = 0;
bool m_buffer_empty = true;
bool m_thread_player = false;
OMXClock *m_av_clock = NULL;
COMXStreamInfo m_hints_audio;
Expand Down Expand Up @@ -119,7 +118,7 @@ static void restore_fl()

void sig_handler(int s)
{
printf("strg-c catched\n");
printf("strg-c caught\n");
signal(SIGINT, SIG_DFL);
g_abort = true;
}
Expand Down Expand Up @@ -1028,7 +1027,7 @@ int main(int argc, char *argv[])
break;

// Abort audio buffering, now we're on our own
if (m_buffer_empty)
if (m_av_clock->OMXIsPaused())
m_av_clock->OMXResume();

OMXClock::OMXSleep(10);
Expand All @@ -1038,35 +1037,31 @@ int main(int argc, char *argv[])
/* when the audio buffer runs under 0.1 seconds we buffer up */
if(m_has_audio)
{
if(m_player_audio.GetDelay() < min(0.1f, 0.1f*(audio_fifo_size ? 2.0f:audio_fifo_size)) && !m_buffer_empty)
if(m_player_audio.GetDelay() < min(0.1f, 0.1f*(audio_fifo_size ? 2.0f:audio_fifo_size)))
{
if(!m_av_clock->OMXIsPaused())
{
m_av_clock->OMXPause();
//printf("buffering start\n");
m_buffer_empty = true;
clock_gettime(CLOCK_REALTIME, &starttime);
}
}
if(m_player_audio.GetDelay() > m_player_audio.GetCacheTotal() * 0.75f && m_buffer_empty)
if(m_player_audio.GetDelay() > m_player_audio.GetCacheTotal() * 0.75f)
{
if(m_av_clock->OMXIsPaused())
{
m_av_clock->OMXResume();
//printf("buffering end\n");
m_buffer_empty = false;
}
}
if(m_buffer_empty)
#if 1 // not sure this happens
if(m_av_clock->OMXIsPaused())
{
clock_gettime(CLOCK_REALTIME, &endtime);
if((endtime.tv_sec - starttime.tv_sec) > 1)
if((endtime.tv_sec - starttime.tv_sec) > max(2, (int)audio_fifo_size))
{
m_buffer_empty = false;
m_av_clock->OMXResume();
//printf("buffering timed out\n");
}
}
#endif
}

if(!m_omx_pkt)
Expand All @@ -1077,7 +1072,13 @@ int main(int argc, char *argv[])
if(m_player_video.AddPacket(m_omx_pkt))
m_omx_pkt = NULL;
else
{
if(m_av_clock->OMXIsPaused())
{
m_av_clock->OMXResume();
}
OMXClock::OMXSleep(10);
}

if(m_tv_show_info)
{
Expand Down

0 comments on commit aec02f4

Please sign in to comment.