Skip to content

Commit

Permalink
fix(cache): stop cache when seek in cache
Browse files Browse the repository at this point in the history
  • Loading branch information
I-m-SuperMan authored and pingkai committed Apr 13, 2020
1 parent 35d4f06 commit fecf86a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
18 changes: 12 additions & 6 deletions mediaPlayer/MediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace Cicada {
listener.LoadingStart = loadingStartCallback;
listener.LoadingEnd = loadingEndCallback;
listener.LoadingProgress = loadingProgressCallback;
listener.Seeking = PlayerSeeking;
listener.SeekEnd = PlayerSeekEnd;
listener.SubtitleShow = subtitleShowCallback;
listener.SubtitleHide = subtitleHideCallback;
Expand Down Expand Up @@ -893,6 +894,17 @@ namespace Cicada {
}
}

void MediaPlayer::PlayerSeeking(int64_t seekInCache, void *userData)
{
GET_MEDIA_PLAYER
#ifdef ENABLE_CACHE_MODULE
if (player->mCacheManager != nullptr && seekInCache == 0) {
//not seek in cache
player->mCacheManager->stop("cache stopped by seek");
}
#endif
}

void MediaPlayer::PlayerSeekEnd(int64_t seekInCache, void *userData)
{
GET_MEDIA_PLAYER
Expand All @@ -904,12 +916,6 @@ namespace Cicada {
//when seek, reset and open abrmanager
player->mAbrManager->Reset();
player->mAbrManager->Start();
#ifdef ENABLE_CACHE_MODULE
if (player->mCacheManager != nullptr && seekInCache == 0) {
//not seek in cache
player->mCacheManager->stop("cache stopped by seek");
}
#endif
if (player->mCollector) {
player->mCollector->ReportSeekEnd();
}
Expand Down
2 changes: 2 additions & 0 deletions mediaPlayer/MediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ namespace Cicada {

static void streamChangedSucCallback(int64_t type, const void *Info, void *userData);

static void PlayerSeeking(int64_t seekInCache, void *userData);

static void PlayerSeekEnd(int64_t seekInCache, void *userData);

static void PlayerStatusChanged(int64_t oldStatus, int64_t newStatus, void *userData);
Expand Down
2 changes: 2 additions & 0 deletions mediaPlayer/SuperMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3873,6 +3873,8 @@ namespace Cicada {
//flush packet queue
mSeekInCache = SeekInCache(seekPos);

mPNotifier->NotifySeeking(mSeekInCache);

if (mSeekNeedCatch && !HAVE_VIDEO) {
mSeekNeedCatch = false;
}
Expand Down
1 change: 1 addition & 0 deletions mediaPlayer/native_cicada_player_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ typedef struct playerListener_t {
playerVoidCallback LoadingEnd;
playerVoidCallback AutoPlayStart;

playerType1Callback Seeking;
playerType1Callback SeekEnd;
playerType1Callback PositionUpdate;
playerType1Callback BufferPositionUpdate;
Expand Down
9 changes: 9 additions & 0 deletions mediaPlayer/player_notifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ namespace Cicada {
pushEvent(event);
}

void PlayerNotifier::NotifySeeking(bool seekInCache) {
if (!mEnable) {
return;
}

auto *event = new player_event(seekInCache ? 1 : 0 , mListener.Seeking);
pushEvent(event);
}

void PlayerNotifier::NotifySeekEnd(bool seekInCache)
{
if (!mEnable || mListener.SeekEnd == nullptr) {
Expand Down
3 changes: 3 additions & 0 deletions mediaPlayer/player_notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ namespace Cicada {
void NotifyAutoPlayStart();

void NotifyVideoRendered(int64_t timeMs, int64_t pts);

void NotifySeeking(bool seekInCache);

private:

void NotifyVoidEvent(playerVoidCallback listener);
Expand Down

0 comments on commit fecf86a

Please sign in to comment.