Skip to content

Commit

Permalink
refactor(mediaPlayer): async start rendering
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <[email protected]>
  • Loading branch information
pingkai committed Feb 25, 2020
1 parent 9499c20 commit 7dfddfe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
40 changes: 30 additions & 10 deletions mediaPlayer/SuperMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ namespace Cicada {

AF_TRACE;
mAudioRender = nullptr;
mBRendingStart = false;
AF_TRACE;
{
std::lock_guard<std::mutex> uMutex(mCreateMutex);
Expand Down Expand Up @@ -1105,6 +1106,14 @@ namespace Cicada {
}

doDeCode();

if (!mBRendingStart && mPlayStatus == PLAYER_PLAYING && !mBufferingFlag) {
if ((!HAVE_VIDEO || !mVideoFrameQue.empty())
&& (!HAVE_AUDIO || !mAudioFrameQue.empty())) {
startRendering(true);
}
}

doRender();
checkEOS();
curTime = af_gettime_relative() / 1000;
Expand Down Expand Up @@ -3155,6 +3164,7 @@ namespace Cicada {
mCurrentVideoMeta = nullptr;
mAdaptiveVideo = false;
dropLateVideoFrames = false;
mBRendingStart = false;

if (mVideoRender) {
mVideoRender->setSpeed(1);
Expand Down Expand Up @@ -3658,11 +3668,6 @@ namespace Cicada {
}

ChangePlayerStatus(PLAYER_PLAYING);
mMasterClock.start();

if (mAudioRender) {
mAudioRender->pause(false);
}
}
}

Expand All @@ -3673,11 +3678,7 @@ namespace Cicada {
}

ChangePlayerStatus(PLAYER_PAUSED);
mMasterClock.pause();

if (mAudioRender) {
mAudioRender->pause(true);
}
startRendering(false);
}

void SuperMediaPlayer::VideoRenderCallback(void *arg, int64_t pts, void *userData)
Expand Down Expand Up @@ -4031,4 +4032,23 @@ namespace Cicada {
mMasterClock.SetScale(speed);
}
}

void SuperMediaPlayer::startRendering(bool start)
{
if (start == mBRendingStart) {
return;
}

mBRendingStart = start;

if (start) {
mMasterClock.start();
} else {
mMasterClock.pause();
}

if (mAudioRender) {
mAudioRender->pause(!start);
}
}
}//namespace Cicada
3 changes: 3 additions & 0 deletions mediaPlayer/SuperMediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ namespace Cicada {

bool dropLateVideoFrames = false;
bool waitingForStart = false;
bool mBRendingStart {false};
private:

bool mAutoPlay = false;
Expand All @@ -494,6 +495,8 @@ namespace Cicada {
void printTimePosition(int64_t time) const;

void setUpAVPath();

void startRendering(bool start);
};
}// namespace Cicada
#endif // CICADA_PLAYER_SERVICE_H
Expand Down

0 comments on commit 7dfddfe

Please sign in to comment.