diff --git a/mediaPlayer/MediaPlayer.cpp b/mediaPlayer/MediaPlayer.cpp index cb83eb4d1..863726505 100644 --- a/mediaPlayer/MediaPlayer.cpp +++ b/mediaPlayer/MediaPlayer.cpp @@ -96,6 +96,7 @@ namespace Cicada { listener.Completion = completionCallback; listener.FirstFrameShow = firstFrameCallback; listener.VideoSizeChanged = videoSizeChangedCallback; + listener.VideoRendered = videoRenderedCallback; listener.PositionUpdate = currentPostionCallback; listener.BufferPositionUpdate = bufferPostionCallback; listener.LoadingStart = loadingStartCallback; @@ -436,8 +437,8 @@ namespace Cicada { playerConfig.highBufferDuration = playerConfig.maxDelayTime; } - if (playerConfig.startBufferDuration > playerConfig.highBufferDuration) { - playerConfig.startBufferDuration = playerConfig.highBufferDuration; + if (playerConfig.startBufferDuration > playerConfig.maxBufferDuration) { + playerConfig.startBufferDuration = playerConfig.maxBufferDuration; } //must @@ -761,6 +762,13 @@ namespace Cicada { } } + void MediaPlayer::videoRenderedCallback(int64_t timeMs, int64_t pts, void *userData) + { + GET_MEDIA_PLAYER + player->mListener.VideoRendered(timeMs, pts, player->mListener.userData); + } + + void MediaPlayer::currentPostionCallback(int64_t position, void *userData) { GET_MEDIA_PLAYER @@ -1035,16 +1043,18 @@ namespace Cicada { mPlayUrlChangedCallback = urlChangedCallbak; } - void MediaPlayer::onMediaFrameCallback(void *arg, const unique_ptr& frame, StreamType type) + void MediaPlayer::onMediaFrameCallback(void *arg, const unique_ptr &frame, StreamType type) { MediaPlayer *player = (MediaPlayer *)arg; + if (nullptr == player) { return; } + player->mediaFrameCallback(frame, type); } - void MediaPlayer::mediaFrameCallback(const unique_ptr& frame, StreamType type) + void MediaPlayer::mediaFrameCallback(const unique_ptr &frame, StreamType type) { if (mCacheManager) { mCacheManager->sendMediaFrame(frame, type); @@ -1054,4 +1064,11 @@ namespace Cicada { mMediaFrameFunc(mMediaFrameArg, frame, type); } } + + + void MediaPlayer::EnableVideoRenderedCallback(bool enable) + { + GET_PLAYER_HANDLE; + CicadaSetOption(handle, "enableVRC", enable ? "1" : "0"); + } } diff --git a/mediaPlayer/MediaPlayer.h b/mediaPlayer/MediaPlayer.h index dc51fff78..6ff111f97 100644 --- a/mediaPlayer/MediaPlayer.h +++ b/mediaPlayer/MediaPlayer.h @@ -58,6 +58,9 @@ namespace Cicada { } public: + + void EnableVideoRenderedCallback(bool enable); + /* * set player listener */ @@ -323,6 +326,8 @@ namespace Cicada { static void videoSizeChangedCallback(int64_t width, int64_t height, void *userData); + static void videoRenderedCallback(int64_t timeMs, int64_t pts, void *userData); + static void currentPostionCallback(int64_t position, void *userData); static void bufferPostionCallback(int64_t position, void *userData); diff --git a/mediaPlayer/SuperMediaPlayer.cpp b/mediaPlayer/SuperMediaPlayer.cpp index 34d30249c..4b7cd86b8 100644 --- a/mediaPlayer/SuperMediaPlayer.cpp +++ b/mediaPlayer/SuperMediaPlayer.cpp @@ -550,6 +550,8 @@ namespace Cicada { } else if (theKey == "description") { mSet.mOptions.set(theKey, value, options::REPLACE); return 0; + } else if (theKey == "enableVRC") { + mSet.bEnableVRC = (atoi(value) != 0); } return 0; @@ -578,6 +580,9 @@ namespace Cicada { snprintf(value, MAX_OPT_VALUE_LENGTH, "%" PRId64 "", size); } else if (theKey == "description") { snprintf(value, MAX_OPT_VALUE_LENGTH, "%s", mSet.mOptions.get("description").c_str()); + } else if ( theKey == "renderFps") { + float renderFps = GetVideoRenderFps(); + snprintf(value, MAX_OPT_VALUE_LENGTH, "%f", renderFps); } return; @@ -2586,7 +2591,7 @@ namespace Cicada { //flush frame queue while (!mVideoFrameQue.empty()) { - ProcessVideoRenderedMsg(mVideoFrameQue.front()->getInfo().pts, nullptr); + ProcessVideoRenderedMsg(mVideoFrameQue.front()->getInfo().pts, af_getsteady_ms(), nullptr); mVideoFrameQue.pop(); } @@ -3674,6 +3679,7 @@ namespace Cicada { pHandle->mUtil.render(pts); MsgParam param; param.videoRenderedParam.pts = pts; + param.videoRenderedParam.timeMs = af_getsteady_ms(); param.videoRenderedParam.userData = userData; pHandle->putMsg(MSG_INTERNAL_VIDEO_RENDERED, param, false); } @@ -3688,7 +3694,7 @@ namespace Cicada { } } - void SuperMediaPlayer::ProcessVideoRenderedMsg(int64_t pts, void *picUserData) + void SuperMediaPlayer::ProcessVideoRenderedMsg(int64_t pts, int64_t timeMs, void *picUserData) { checkFirstRender(); @@ -3707,6 +3713,11 @@ namespace Cicada { } mDemuxerService->SetOption("FRAME_RENDERED", pts); + + if (mSet.bEnableVRC) { + mPNotifier->NotifyVideoRendered(timeMs, pts); + } + //TODO packetGotTime } @@ -3960,7 +3971,7 @@ namespace Cicada { { while (!mVideoFrameQue.empty()) { int64_t pts = mVideoFrameQue.front()->getInfo().pts; - ProcessVideoRenderedMsg(pts, nullptr); + ProcessVideoRenderedMsg(pts, af_getsteady_ms(), nullptr); mVideoFrameQue.pop(); } diff --git a/mediaPlayer/SuperMediaPlayer.h b/mediaPlayer/SuperMediaPlayer.h index 18be8aff7..780ef2b2b 100644 --- a/mediaPlayer/SuperMediaPlayer.h +++ b/mediaPlayer/SuperMediaPlayer.h @@ -346,7 +346,7 @@ namespace Cicada { void ProcessSwitchStreamMsg(int index) final; - void ProcessVideoRenderedMsg(int64_t pts, void *picUserData) final; + void ProcessVideoRenderedMsg(int64_t pts, int64_t timeMs , void *picUserData) final; void ProcessVideoCleanFrameMsg() final; diff --git a/mediaPlayer/native_cicada_player_def.h b/mediaPlayer/native_cicada_player_def.h index 0ac2c1dfd..83a7b6fbd 100644 --- a/mediaPlayer/native_cicada_player_def.h +++ b/mediaPlayer/native_cicada_player_def.h @@ -90,6 +90,7 @@ typedef struct playerListener_t { playerType12Callback VideoSizeChanged; playerType12Callback StatusChanged; + playerType12Callback VideoRendered; playerType13Callback ErrorCallback; diff --git a/mediaPlayer/player_msg_control.cpp b/mediaPlayer/player_msg_control.cpp index 3181a9455..5eeca91d7 100644 --- a/mediaPlayer/player_msg_control.cpp +++ b/mediaPlayer/player_msg_control.cpp @@ -256,6 +256,7 @@ namespace Cicada { case MSG_INTERNAL_VIDEO_RENDERED: mProcessor.ProcessVideoRenderedMsg(msgContent.videoRenderedParam.pts, + msgContent.videoRenderedParam.timeMs, msgContent.videoRenderedParam.userData); break; diff --git a/mediaPlayer/player_msg_control.h b/mediaPlayer/player_msg_control.h index 3b1c5ab9a..f497f5b15 100644 --- a/mediaPlayer/player_msg_control.h +++ b/mediaPlayer/player_msg_control.h @@ -73,6 +73,7 @@ namespace Cicada { typedef struct _MsgVideoRenderedParam { int64_t pts; + int64_t timeMs; void *userData; } MsgVideoRenderedParam; @@ -131,7 +132,7 @@ namespace Cicada { virtual void ProcessSwitchStreamMsg(int index) = 0; - virtual void ProcessVideoRenderedMsg(int64_t pts, void *picUserData) = 0; + virtual void ProcessVideoRenderedMsg(int64_t pts, int64_t timeMs , void *picUserData) = 0; virtual void ProcessVideoCleanFrameMsg() = 0; diff --git a/mediaPlayer/player_notifier.cpp b/mediaPlayer/player_notifier.cpp index ccb2b8e06..e32ce4836 100644 --- a/mediaPlayer/player_notifier.cpp +++ b/mediaPlayer/player_notifier.cpp @@ -210,6 +210,16 @@ namespace Cicada { pushEvent(event); } + void PlayerNotifier::NotifyVideoRendered(int64_t timeMs, int64_t pts) + { + if (!mEnable || mListener.VideoRendered == nullptr) { + return; + } + + auto *event = new player_event(timeMs, pts, mListener.VideoRendered); + pushEvent(event); + } + void PlayerNotifier::NotifyFirstFrame() { if (!mEnable || mListener.FirstFrameShow == nullptr) { diff --git a/mediaPlayer/player_notifier.h b/mediaPlayer/player_notifier.h index 7036a8c99..fbf00d0ec 100644 --- a/mediaPlayer/player_notifier.h +++ b/mediaPlayer/player_notifier.h @@ -76,6 +76,7 @@ namespace Cicada { void NotifyAutoPlayStart(); + void NotifyVideoRendered(int64_t timeMs, int64_t pts); private: void NotifyVoidEvent(playerVoidCallback listener); diff --git a/mediaPlayer/player_types.cpp b/mediaPlayer/player_types.cpp index b20d218d7..8a9329200 100644 --- a/mediaPlayer/player_types.cpp +++ b/mediaPlayer/player_types.cpp @@ -47,6 +47,8 @@ namespace Cicada { clearShowWhenStop = false; bEnableTunnelRender = false; bEnableHwVideoDecode = true; + // don't need reset for each playback +// bEnableVRC = false; #if TARGET_OS_IPHONE lowMemSize = 50 * 1024 * 1024;// 50M #else diff --git a/mediaPlayer/player_types.h b/mediaPlayer/player_types.h index d08423cb5..9f6575b76 100644 --- a/mediaPlayer/player_types.h +++ b/mediaPlayer/player_types.h @@ -56,6 +56,9 @@ namespace Cicada { int64_t AnalyticsID = -1; int mDefaultBandWidth = 0; playerOptions mOptions; + + + bool bEnableVRC = false; }; }