Skip to content

Commit

Permalink
Continue looping until packet buffers are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
torarin committed Jul 24, 2012
1 parent ec4e7bc commit 764877a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 40 deletions.
11 changes: 1 addition & 10 deletions OMXPlayerAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ void OMXPlayerAudio::Process()
m_packets.pop_front();
}
UnLock();

LockDecoder();
if(m_flush && omx_pkt)
{
Expand Down Expand Up @@ -679,17 +679,8 @@ void OMXPlayerAudio::WaitCompletion()
if(!m_decoder)
return;

struct timespec starttime, endtime;

while(true)
{
clock_gettime(CLOCK_REALTIME, &endtime);
if((endtime.tv_sec - starttime.tv_sec) > 2)
{
CLog::Log(LOGERROR, "OMXPlayerAudio::WaitCompletion - wait for eos timed out\n");
break;
}

Lock();
if(m_packets.empty())
{
Expand Down
9 changes: 8 additions & 1 deletion OMXPlayerAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ class OMXPlayerAudio : public CThread
double GetCacheTime();
double GetCurrentPTS() { return m_iCurrentPts; };
void WaitCompletion();
unsigned int GetCached() { return m_cached_size; };
unsigned int GetCached()
{
Lock();
unsigned int cached_size = m_cached_size;
UnLock();
return cached_size;

};
void RegisterAudioCallback(IAudioCallback* pCallback);
void UnRegisterAudioCallback();
void DoAudioWork();
Expand Down
7 changes: 6 additions & 1 deletion OMXReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,16 @@ bool OMXReader::SeekTime(int64_t seek_ms, int seek_flags, double *startpts)
{
m_eof = true;
UnLock();
return false;
return true;
}

int ret = m_dllAvFormat.av_seek_frame(m_pFormatContext, -1, seek_pts, seek_flags ? AVSEEK_FLAG_BACKWARD : 0);

if(ret >= 0)
{
UpdateCurrentPTS();
m_eof = false;
}

if(m_iCurrentPts == DVD_NOPTS_VALUE)
{
Expand Down Expand Up @@ -416,6 +419,8 @@ AVMediaType OMXReader::PacketType(OMXPacket *pkt)

OMXPacket *OMXReader::Read()
{
assert(!IsEof());

AVPacket pkt;
OMXPacket *m_omx_pkt = NULL;
int result = -1;
Expand Down
66 changes: 38 additions & 28 deletions omxplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,44 @@ int main(int argc, char *argv[])
goto do_exit;
}

/* player got in an error state */
if(m_player_audio.Error())
{
printf("audio player error. emergency exit!!!\n");
goto do_exit;
}

std::string strSubTitle = m_player_video.GetText();
if(strSubTitle.length() && m_show_subtitle)
{
if(last_sub != strSubTitle)
{
last_sub = strSubTitle;
printf("Text : %s\n", strSubTitle.c_str());
}
}

if(m_stats)
{
printf("V : %8.02f %8d %8d A : %8.02f %8.02f Cv : %8d Ca : %8d \r",
m_player_video.GetCurrentPTS() / DVD_TIME_BASE, m_player_video.GetDecoderBufferSize(),
m_player_video.GetDecoderFreeSpace(), m_player_audio.GetCurrentPTS() / DVD_TIME_BASE,
m_player_audio.GetDelay(), m_player_video.GetCached(), m_player_audio.GetCached());
}

if(m_omx_reader.IsEof() && !m_omx_pkt)
{
if (!m_player_audio.GetCached() && !m_player_video.GetCached())
break;

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

OMXClock::OMXSleep(10);
continue;
}

/* when the audio buffer runs under 0.1 seconds we buffer up */
if(m_has_audio)
{
Expand Down Expand Up @@ -684,34 +722,6 @@ int main(int argc, char *argv[])
m_omx_pkt = NULL;
}
}

/* player got in an error state */
if(m_player_audio.Error())
{
printf("audio player error. emergency exit!!!\n");
goto do_exit;
}

std::string strSubTitle = m_player_video.GetText();
if(strSubTitle.length() && m_show_subtitle)
{
if(last_sub != strSubTitle)
{
last_sub = strSubTitle;
printf("Text : %s\n", strSubTitle.c_str());
}
}

if(m_stats)
{
printf("V : %8.02f %8d %8d A : %8.02f %8.02f Cv : %8d Ca : %8d \r",
m_player_video.GetCurrentPTS() / DVD_TIME_BASE, m_player_video.GetDecoderBufferSize(),
m_player_video.GetDecoderFreeSpace(), m_player_audio.GetCurrentPTS() / DVD_TIME_BASE,
m_player_audio.GetDelay(), m_player_video.GetCached(), m_player_audio.GetCached());
}
if(m_omx_reader.IsEof())
break;

}

do_exit:
Expand Down

0 comments on commit 764877a

Please sign in to comment.