Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 148b684

Browse files
luoying1234U1X6WK
authored andcommitted
Fix mismatch issue in catch up path in android player.
Signed-off-by: Luo, Ying <ying2.luo@intel.com>
1 parent 9897d1f commit 148b684

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

src/OmafDashAccess/OmafMediaStream.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,13 +812,14 @@ int32_t OmafMediaStream::TaskRun(OmafTilesStitch *stitch, std::pair<uint64_t, st
812812
uint64_t optStartPTS = startPTSofCurrSeg;
813813
//1.1 choose opt pts
814814
// LOG(INFO) <<"Trigger PTS " << triggerPTS << "Start PTS " << startPTSofCurrSeg << endl;
815+
#ifndef _ANDROID_NDK_OPTION_
815816
if (m_gopSize > 0 && triggerPTS > startPTSofCurrSeg) {
816817
uint32_t offset_num = triggerPTS / m_gopSize;
817818
uint32_t remain_pts = triggerPTS % m_gopSize;
818819
optStartPTS = remain_pts > m_gopSize - thresholdFrameNum ? (offset_num + 1) * m_gopSize : offset_num * m_gopSize;
819820
OMAF_LOG(LOG_INFO, "Start pts from %lld, video id %d\n", optStartPTS, video_id);
820821
}
821-
822+
#endif
822823
//2. get samples num (indicate that segment parsed)
823824
uint32_t samplesNumPerSeg = 0;
824825
if (m_pStreamInfo != nullptr && m_pStreamInfo->framerate_den != 0) {

src/player/app/android/app/src/main/java/com/vcd/immersive/omafplayer/MediaLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class MediaLoader {
6868

6969
public static final String MEDIA_FORMAT_KEY = "stereoFormat";
7070
private static final int MAX_SURFACE_NUM = 5;
71-
private static final int MAX_CATCHUP_SURFACE_NUM = 2;
71+
private static final int MAX_CATCHUP_SURFACE_NUM = 1;
7272

7373
/** A spherical mesh for video should be large enough that there are no stereo artifacts. */
7474
private static final int SPHERE_RADIUS_METERS = 50;

src/player/app/android/app/src/main/java/com/vcd/immersive/omafplayer/MonoscopicView.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,13 @@ public void onDrawFrame(GL10 gl) {
318318
// Combine touch & sensor data.
319319
// Orientation = pitch * sensor * yaw since that is closest to what most users expect the
320320
// behavior to be.
321-
synchronized (this) {
322-
Matrix.multiplyMM(tempMatrix, 0, deviceOrientationMatrix, 0, touchYawMatrix, 0);
323-
Matrix.multiplyMM(viewMatrix, 0, touchPitchMatrix, 0, tempMatrix, 0);
324-
}
325-
326-
Matrix.multiplyMM(viewProjectionMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
327321
if (mediaLoader.mediaPlayer != null && mediaLoader.mediaPlayer.GetStatus() == mediaLoader.mediaPlayer.PLAY) {
322+
synchronized (this) {
323+
Log.i(TAG, "onDrawFrame");
324+
Matrix.multiplyMM(tempMatrix, 0, deviceOrientationMatrix, 0, touchYawMatrix, 0);
325+
Matrix.multiplyMM(viewMatrix, 0, touchPitchMatrix, 0, tempMatrix, 0);
326+
}
327+
Matrix.multiplyMM(viewProjectionMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
328328
scene.glDrawFrame(viewProjectionMatrix, Type.MONOCULAR, screenWidth, screenHeight);
329329
}
330330
}

src/player/app/android/app/src/main/java/com/vcd/immersive/omafplayer/Rendering/SceneRenderer.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public final class SceneRenderer {
4141
private static final String TAG = "SceneRenderer";
4242
private static final long Interval = 33;
4343
private static final int MULTI_DECODER_MAX_NUM = 5;
44-
private static final int MAX_CATCHUP_SURFACE_NUM = 2;
44+
private static final int MAX_CATCHUP_SURFACE_NUM = 1;
4545
// This is the primary interface between the Media Player and the GL Scene.
4646
private Surface[] decodeSurface = new Surface[MULTI_DECODER_MAX_NUM + MAX_CATCHUP_SURFACE_NUM];
4747
private Surface displaySurface;
@@ -68,6 +68,8 @@ public final class SceneRenderer {
6868

6969
private int renderCount = 0;
7070

71+
private boolean isWrittenCatchup = false;
72+
7173
private int cnt = 0;
7274

7375
public boolean decode_surface_ready = false;
@@ -309,6 +311,7 @@ public void glDrawFrame(float[] viewProjectionMatrix, int eyeType, int width, in
309311
for (int i = MULTI_DECODER_MAX_NUM; i < MULTI_DECODER_MAX_NUM + MAX_CATCHUP_SURFACE_NUM; i++){
310312
decodeTexture[i].updateTexImage();
311313
}
314+
isWrittenCatchup = true;
312315
Log.i(TAG, "update catch up tex image at pts " + cnt);
313316
}
314317
if (frameAvailable.compareAndSet(true, false))
@@ -324,7 +327,17 @@ public void glDrawFrame(float[] viewProjectionMatrix, int eyeType, int width, in
324327
int ret = 0;
325328

326329
ret = mediaPlayer.UpdateDisplayTex(renderCount);
327-
if (ret == 0) renderCount++;
330+
if (ret == 0) {
331+
Log.i(TAG, "update display tex at pts " + renderCount);
332+
renderCount++;
333+
if (isWrittenCatchup) {
334+
for (int i = MULTI_DECODER_MAX_NUM; i < MULTI_DECODER_MAX_NUM + MAX_CATCHUP_SURFACE_NUM; i++) {
335+
decodeTexture[i].releaseTexImage();
336+
isWrittenCatchup = false;
337+
Log.i(TAG, "release catch up tex image at pts " + renderCount);
338+
}
339+
}
340+
}
328341
checkGlError();
329342
if (ret == 0 && !hasTransformTypeSent) {
330343
transformType = mediaPlayer.GetTransformType();

src/player/player_lib/Decoder/VideoDecoder_hw.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ RenderStatus VideoDecoder_hw::DecodeFrame(DashPacket *pkt, uint32_t video_id)
347347
frame->video_id = video_id;
348348
frame->bEOS = false;
349349
frame->bCatchup = data->bCatchup;
350-
mDecCtx->push_frame(frame);
350+
while (frame->bCatchup && frame->pts > mNextInputPts) {
351+
ANDROID_LOGD("check frame pts %ld is greater than input pts %d, wait!", frame->pts, mNextInputPts);
352+
usleep(5);
353+
}
351354
ANDROID_LOGD("PTS: %d, frame rwpk num: %d, one rrwpk w: %d, h: %d, l: %d, t: %d", data->pts, data->rwpk->numRegions, data->rwpk->rectRegionPacking[0].projRegWidth,
352355
data->rwpk->rectRegionPacking[0].projRegHeight, data->rwpk->rectRegionPacking[0].projRegLeft, data->rwpk->rectRegionPacking[0].projRegTop);
353356
SAFE_DELETE(data);
@@ -374,12 +377,11 @@ RenderStatus VideoDecoder_hw::DecodeFrame(DashPacket *pkt, uint32_t video_id)
374377
ANDROID_LOGD("CHANGE: successfully decode one catch up frame at pts %ld", frame->pts);
375378
else
376379
ANDROID_LOGD("CHANGE: successfully decode one frame at pts %ld video id %d", frame->pts, mVideoId);
380+
377381
ANDROID_LOGD("mNextInputPts %d", mNextInputPts);
382+
mDecCtx->push_frame(frame);
378383
//swift deocde when needing drop frame, and for wait and normal situation, do as follows.
379384
if (frame->pts >= mNextInputPts) {
380-
while (frame->bCatchup && frame->pts > mNextInputPts) {
381-
usleep(5);
382-
}
383385
ANDROID_LOGD("Input pts %lld, frame pts %lld video id %d", mNextInputPts, frame->pts, mVideoId);
384386
std::mutex mtx;
385387
std::unique_lock<std::mutex> lck(mtx);
@@ -460,13 +462,17 @@ RenderStatus VideoDecoder_hw::FlushDecoder(uint32_t video_id)
460462
frame->video_id = video_id;
461463
frame->bEOS = false;
462464
frame->bCatchup = data->bCatchup;
463-
mDecCtx->push_frame(frame);
465+
while (frame->bCatchup && frame->pts > mNextInputPts) {
466+
ANDROID_LOGD("check frame pts %ld is greater than input pts %d, wait!", frame->pts, mNextInputPts);
467+
usleep(5);
468+
}
464469
ANDROID_LOGD("PTS: %d, frame rwpk num: %d, one rrwpk w: %d, h: %d, l: %d, t: %d", data->pts, data->rwpk->numRegions, data->rwpk->rectRegionPacking[0].projRegWidth,
465470
data->rwpk->rectRegionPacking[0].projRegHeight, data->rwpk->rectRegionPacking[0].projRegLeft, data->rwpk->rectRegionPacking[0].projRegTop);
466471
// 2. release output buffer
467472
if (out_buf_idx > 0) ANDROID_LOGD("frame info size is greater than zero!");
468473
if (IS_DUMPED != 1){
469474
bool render = (buf_info.size != 0) && (frame->pts == mNextInputPts || mNextInputPts == 0);
475+
ANDROID_LOGD("is render %d, pts %ld, video id %d", render, frame->pts, mVideoId);
470476
AMediaCodec_releaseOutputBuffer(mDecCtx->mMediaCodec, out_buf_idx, render);
471477
}
472478
else
@@ -486,12 +492,11 @@ RenderStatus VideoDecoder_hw::FlushDecoder(uint32_t video_id)
486492
ANDROID_LOGD("CHANGE: successfully decode one catch up frame at pts %ld", frame->pts);
487493
else
488494
ANDROID_LOGD("CHANGE: successfully decode one frame at pts %ld video id %d", frame->pts, mVideoId);
489-
ANDROID_LOGD("mNextInputPts %d, video id ", mNextInputPts, mVideoId);
495+
496+
ANDROID_LOGD("mNextInputPts %d, video id %d", mNextInputPts, mVideoId);
497+
mDecCtx->push_frame(frame);
490498
//swift deocde when needing drop frame, and for wait and normal situation, do as follows.
491499
if (frame->pts >= mNextInputPts) {
492-
while (frame->bCatchup && frame->pts > mNextInputPts) {//wait
493-
usleep(5);
494-
}
495500
std::mutex mtx;
496501
std::unique_lock<std::mutex> lck(mtx);
497502
m_cv.wait(lck);
@@ -584,7 +589,9 @@ void VideoDecoder_hw::Run()
584589
bool isCatchup = pkt_info->bCatchup;
585590
if (pkt_info->pkt) {//catch up eos last frame
586591
LOG(INFO) << "Decoded frame is pts " << pkt_info->pts << endl;
592+
do {
587593
ret = DecodeFrame(pkt_info->pkt, pkt_info->video_id);
594+
} while (ret == RENDER_NULL_PACKET);// ensure that send packet is right
588595
if(RENDER_STATUS_OK != ret){
589596
LOG(INFO)<<"Video "<< mVideoId <<": failed to decoder one frame"<<std::endl;
590597
}
@@ -594,7 +601,9 @@ void VideoDecoder_hw::Run()
594601
SAFE_DELETE(pkt_info);
595602
}
596603
ANDROID_LOGD("Finish to decode last eos frame, video id %d", mVideoId);
604+
do {
597605
ret = FlushDecoder(mVideoId);
606+
} while (ret == RENDER_NULL_PACKET);// ensure that send packet is right
598607
if(RENDER_STATUS_OK != ret){
599608
LOG(INFO)<<"Video "<< mVideoId <<": failed to flush decoder when EOS"<<std::endl;
600609
}

src/player/player_lib/MediaSource/DashMediaSource.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ void DashMediaSource::ProcessVideoPacket() {
373373
if (currentWaitTime > WAIT_PACKET_TIME_OUT) // wait 5s but get packet failed
374374
{
375375
m_status = STATUS_TIMEOUT;
376-
// ANDROID_LOGD("Wait too long to get packet from Omaf Dash Access library! Force to quit!");
376+
#ifdef _ANDROID_OS_
377+
ANDROID_LOGD("Wait too long to get packet from Omaf Dash Access library! Force to quit!");
378+
#endif
377379
LOG(ERROR) << " Wait too long to get packet from Omaf Dash Access library! Force to quit! " << std::endl;
378380
}
379381
return;

0 commit comments

Comments
 (0)