Skip to content

Commit

Permalink
feat(mediaplayer): support not render video when frame callback is set
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 4, 2020
1 parent c4cf862 commit 5983d82
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 66 deletions.
11 changes: 11 additions & 0 deletions cmdline/cicadaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ static void onError(int64_t errorCode, const void *errorMsg, void *userData)
}
}

static bool CicadaOnRenderFrame(void *userData, IAFFrame *frame)
{
if (frame == nullptr) return false;
if (frame->getType() != IAFFrame::FrameTypeVideo) {
return false;
}
// AF_LOGD("render a video frame %lld\n", frame->getInfo().pts);
return false;
}

int main(int argc, char *argv[])
{
string url;
Expand Down Expand Up @@ -123,6 +133,7 @@ int main(int argc, char *argv[])
player->SetFastStart(true);
player->Prepare();
player->SelectTrack(-1);
player->SetOnRenderFrameCallback(CicadaOnRenderFrame, nullptr);
bool quite = false;

while (!quite && !cicada.error) {
Expand Down
120 changes: 54 additions & 66 deletions mediaPlayer/SuperMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,10 +2116,6 @@ namespace Cicada {
}
}

if (mFrameCb) {
mFrameCb(mFrameCbUserData, videoFrame.get());
}

if (render) {
SendVideoFrameToRender(move(videoFrame));

Expand All @@ -2138,8 +2134,12 @@ namespace Cicada {
}
} else {
AF_LOGW("drop frame,master played time is %lld,video pts is %lld\n", masterPlayedTime, videoPts);
VideoRenderCallback(this, videoPts, nullptr);
videoFrame->setDiscard(true);

if (mFrameCb) {
mFrameCb(mFrameCbUserData, videoFrame.get());
}
VideoRenderCallback(this, videoPts, nullptr);
}

mPlayedVideoPts = videoPts;
Expand Down Expand Up @@ -2231,15 +2231,13 @@ namespace Cicada {

void SuperMediaPlayer::SendVideoFrameToRender(unique_ptr<IAFFrame> frame, bool valid)
{
//#ifdef WIN32
//
// if (mVideoDecodeType == AlivcVideoCodecHardware) {
// m_dxva2Render.RenderFrame(frame->getFrame()->GetData());
// //delete pFrame;
// return;
// }
//
//#endif
if (mFrameCb) {
bool rendered = mFrameCb(mFrameCbUserData, frame.get());
if (rendered) {
VideoRenderCallback(this, frame->getInfo().pts, nullptr);
return;
}
}
if (mVideoRender) {
int ret = mVideoRender->renderFrame(frame);

Expand Down Expand Up @@ -2400,7 +2398,7 @@ namespace Cicada {
}
}

if (mCurrentVideoIndex >= 0 && mVideoDecoder == nullptr) {
if (mCurrentVideoIndex >= 0) {
int ret = SetUpVideoPath();

if (ret < 0) {
Expand Down Expand Up @@ -3024,7 +3022,7 @@ namespace Cicada {

int SuperMediaPlayer::SetUpVideoPath()
{
if (mVideoDecoder) {
if (mVideoDecoder && mVideoRender) {
return 0;
}

Expand All @@ -3042,7 +3040,7 @@ namespace Cicada {
mPNotifier->NotifyVideoSizeChanged(mVideoWidth, mVideoHeight);
}

if (mSet.mView == nullptr) {
if (mSet.mView == nullptr && mFrameCb == nullptr) {
return 0;
}

Expand All @@ -3052,49 +3050,31 @@ namespace Cicada {
}

int ret = 0;
bool bHW = false;
AF_LOGD("SetUpVideoPath start");

if (mSet.bEnableHwVideoDecode) {
switch (meta->codec) {
case AF_CODEC_ID_H264: {
string value = getProperty("ro.video.dec.h264");
bHW = !(value == "OFF");
break;
}

default:
bHW = true;
break;
}

if (mAppStatus == APP_BACKGROUND) {
AF_LOGW("create video render in background");
}
}

if (meta->interlaced == InterlacedType_UNKNOWN) {
meta->interlaced = mVideoInterlaced;
}

if (!mSet.bEnableTunnelRender) {
if (!mSet.bEnableTunnelRender && mSet.mView != nullptr && mVideoRender == nullptr) {
if (mAppStatus == APP_BACKGROUND) {
AF_LOGW("create video render in background");
}
AF_LOGD("SetUpVideoRender start");
CreateVideoRender();
}

if (mVideoRender) {
IVideoRender::Rotate finalRotate = IVideoRender::Rotate::Rotate_None;
if (mVideoRender) {
IVideoRender::Rotate finalRotate = IVideoRender::Rotate::Rotate_None;

if (meta->rotate == 0) {
finalRotate = IVideoRender::Rotate::Rotate_None;
} else if (meta->rotate == 90) {
finalRotate = IVideoRender::Rotate::Rotate_90;
} else if (meta->rotate == 180) {
finalRotate = IVideoRender::Rotate::Rotate_180;
} else if (meta->rotate == 270) {
finalRotate = IVideoRender::Rotate::Rotate_270;
}

if (meta->rotate == 0) {
finalRotate = IVideoRender::Rotate::Rotate_None;
} else if (meta->rotate == 90) {
finalRotate = IVideoRender::Rotate::Rotate_90;
} else if (meta->rotate == 180) {
finalRotate = IVideoRender::Rotate::Rotate_180;
} else if (meta->rotate == 270) {
finalRotate = IVideoRender::Rotate::Rotate_270;
mVideoRender->setVideoRotate(finalRotate);
}

mVideoRender->setVideoRotate(finalRotate);
}

//re set view in case for not set view before
Expand All @@ -3104,6 +3084,27 @@ namespace Cicada {
}
}

if (mVideoDecoder != nullptr) {
return 0;
}

AF_LOGD("SetUpVideoDecoder start");

bool bHW = false;
if (mSet.bEnableHwVideoDecode) {
switch (meta->codec) {
case AF_CODEC_ID_H264: {
string value = getProperty("ro.video.dec.h264");
bHW = !(value == "OFF");
break;
}

default:
bHW = true;
break;
}
}

ret = CreateVideoDecoder(bHW, *meta);

if (ret < 0) {
Expand Down Expand Up @@ -3131,19 +3132,6 @@ namespace Cicada {
}
}

//
//#ifdef WIN32
//
// if (mVideoDecodeType == AlivcVideoCodecHardware) {
// if (meta.width >= 7680 && meta.height >= 4320) {
// mVideoDecoder->enable_skip_frame(true, 60.0);
// }
//
// m_dxva2Render.InitRender(mSet.mView, mVideoDecoder->get_video_device(), meta.width, meta.height);
// }
//
//#endif

if (meta->duration > mDuration) {
mDuration = meta->duration;
}
Expand Down

0 comments on commit 5983d82

Please sign in to comment.