Skip to content

Commit

Permalink
feat(mediaplayer): add api to set fast start mode
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai authored and I-m-SuperMan committed Jun 2, 2020
1 parent 87b3942 commit 02c495f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cmdline/cicadaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ static void onEOS(void *userData)
cont->receiver->push(std::unique_ptr<IEvent>(new IEvent(IEvent::TYPE_EXIT)));
}
}
static void onPrepared(void *userData)
{
auto *cont = static_cast<cicadaCont *>(userData);
// af_msleep(10000);
cont->player->Start();
}

static void onEvent(int64_t errorCode, const void *errorMsg, void *userData)
{
Expand Down Expand Up @@ -98,6 +104,7 @@ int main(int argc, char *argv[])
pListener.Completion = onEOS;
pListener.EventCallback = onEvent;
pListener.ErrorCallback = onError;
pListener.Prepared = onPrepared;
cicadaEventListener eListener(player.get());
#ifdef ENABLE_SDL
SDLEventReceiver receiver(eListener);
Expand All @@ -113,6 +120,7 @@ int main(int argc, char *argv[])
player->SetAutoPlay(true);
player->SetLoop(true);
player->SetIPResolveType(IpResolveWhatEver);
player->SetFastStart(true);
player->Prepare();
player->SelectTrack(-1);
bool quite = false;
Expand Down
6 changes: 6 additions & 0 deletions mediaPlayer/MediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,4 +1127,10 @@ namespace Cicada {
GET_PLAYER_HANDLE;
CicadaSetOption(handle, "IPResolveType", to_string(type).c_str());
}
void MediaPlayer::SetFastStart(bool mode)
{
GET_PLAYER_HANDLE;
int value = mode;
CicadaSetOption(handle, "fastStart", to_string(value).c_str());
}
}
2 changes: 2 additions & 0 deletions mediaPlayer/MediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace Cicada {

void SetIPResolveType(IpResolveType type);

void SetFastStart(bool mode);

/*
* set player listener
*/
Expand Down
11 changes: 10 additions & 1 deletion mediaPlayer/SuperMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ namespace Cicada {
} else if (theKey == "IPResolveType") {
uint64_t type = atoll(value);
mSet.mIpType = static_cast<IpResolveType>(type);
} else if (theKey == "fastStart") {
mSet.mFastStart = atol(value) != 0;
}

return 0;
Expand Down Expand Up @@ -1339,7 +1341,9 @@ namespace Cicada {
}

if (mPlayStatus == PLAYER_PREPARING) {
if ((cur_buffer_duration >= HighBufferDur && (!HAVE_VIDEO || videoDecoderFull || APP_BACKGROUND == mAppStatus)) || (mEof)) {
if ((cur_buffer_duration >= HighBufferDur &&
(!HAVE_VIDEO || videoDecoderFull || APP_BACKGROUND == mAppStatus || !mSet.mFastStart)) ||
(mEof)) {
//open stream failed
if (mEof && getPlayerBufferDuration(true) <= 0) {
ChangePlayerStatus(PLAYER_ERROR);
Expand Down Expand Up @@ -2379,6 +2383,11 @@ namespace Cicada {
return;
}

if (!mSet.mFastStart && mPlayStatus < PLAYER_PLAYING) {
AF_LOGI("not fast start mode\n");
return;
}

if (mCurrentAudioIndex >= 0 && mAudioDecoder == nullptr) {
AF_LOGD("SetUpAudioPath start");
int ret = SetUpAudioPath();
Expand Down
1 change: 1 addition & 0 deletions mediaPlayer/player_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace Cicada {
mOptions.reset();
maxASeekDelta = 21 * 1000 * 1000;
maxVideoRecoverSize = 300;
mFastStart = true;
}
}

1 change: 1 addition & 0 deletions mediaPlayer/player_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace Cicada {
int maxASeekDelta = 21 * 1000 * 1000;//us

int maxVideoRecoverSize;
bool mFastStart{true};
};
}

Expand Down

0 comments on commit 02c495f

Please sign in to comment.