@@ -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 }
0 commit comments