@@ -347,7 +347,10 @@ RenderStatus VideoDecoder_hw::DecodeFrame(DashPacket *pkt, uint32_t video_id)
347
347
frame->video_id = video_id;
348
348
frame->bEOS = false ;
349
349
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
+ }
351
354
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 ,
352
355
data->rwpk ->rectRegionPacking [0 ].projRegHeight , data->rwpk ->rectRegionPacking [0 ].projRegLeft , data->rwpk ->rectRegionPacking [0 ].projRegTop );
353
356
SAFE_DELETE (data);
@@ -374,12 +377,11 @@ RenderStatus VideoDecoder_hw::DecodeFrame(DashPacket *pkt, uint32_t video_id)
374
377
ANDROID_LOGD (" CHANGE: successfully decode one catch up frame at pts %ld" , frame->pts );
375
378
else
376
379
ANDROID_LOGD (" CHANGE: successfully decode one frame at pts %ld video id %d" , frame->pts , mVideoId );
380
+
377
381
ANDROID_LOGD (" mNextInputPts %d" , mNextInputPts );
382
+ mDecCtx ->push_frame (frame);
378
383
// swift deocde when needing drop frame, and for wait and normal situation, do as follows.
379
384
if (frame->pts >= mNextInputPts ) {
380
- while (frame->bCatchup && frame->pts > mNextInputPts ) {
381
- usleep (5 );
382
- }
383
385
ANDROID_LOGD (" Input pts %lld, frame pts %lld video id %d" , mNextInputPts , frame->pts , mVideoId );
384
386
std::mutex mtx;
385
387
std::unique_lock<std::mutex> lck (mtx);
@@ -460,13 +462,17 @@ RenderStatus VideoDecoder_hw::FlushDecoder(uint32_t video_id)
460
462
frame->video_id = video_id;
461
463
frame->bEOS = false ;
462
464
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
+ }
464
469
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 ,
465
470
data->rwpk ->rectRegionPacking [0 ].projRegHeight , data->rwpk ->rectRegionPacking [0 ].projRegLeft , data->rwpk ->rectRegionPacking [0 ].projRegTop );
466
471
// 2. release output buffer
467
472
if (out_buf_idx > 0 ) ANDROID_LOGD (" frame info size is greater than zero!" );
468
473
if (IS_DUMPED != 1 ){
469
474
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 );
470
476
AMediaCodec_releaseOutputBuffer (mDecCtx ->mMediaCodec , out_buf_idx, render);
471
477
}
472
478
else
@@ -486,12 +492,11 @@ RenderStatus VideoDecoder_hw::FlushDecoder(uint32_t video_id)
486
492
ANDROID_LOGD (" CHANGE: successfully decode one catch up frame at pts %ld" , frame->pts );
487
493
else
488
494
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);
490
498
// swift deocde when needing drop frame, and for wait and normal situation, do as follows.
491
499
if (frame->pts >= mNextInputPts ) {
492
- while (frame->bCatchup && frame->pts > mNextInputPts ) {// wait
493
- usleep (5 );
494
- }
495
500
std::mutex mtx;
496
501
std::unique_lock<std::mutex> lck (mtx);
497
502
m_cv.wait (lck);
@@ -584,7 +589,9 @@ void VideoDecoder_hw::Run()
584
589
bool isCatchup = pkt_info->bCatchup ;
585
590
if (pkt_info->pkt ) {// catch up eos last frame
586
591
LOG (INFO) << " Decoded frame is pts " << pkt_info->pts << endl;
592
+ do {
587
593
ret = DecodeFrame (pkt_info->pkt , pkt_info->video_id );
594
+ } while (ret == RENDER_NULL_PACKET);// ensure that send packet is right
588
595
if (RENDER_STATUS_OK != ret){
589
596
LOG (INFO)<<" Video " << mVideoId <<" : failed to decoder one frame" <<std::endl;
590
597
}
@@ -594,7 +601,9 @@ void VideoDecoder_hw::Run()
594
601
SAFE_DELETE (pkt_info);
595
602
}
596
603
ANDROID_LOGD (" Finish to decode last eos frame, video id %d" , mVideoId );
604
+ do {
597
605
ret = FlushDecoder (mVideoId );
606
+ } while (ret == RENDER_NULL_PACKET);// ensure that send packet is right
598
607
if (RENDER_STATUS_OK != ret){
599
608
LOG (INFO)<<" Video " << mVideoId <<" : failed to flush decoder when EOS" <<std::endl;
600
609
}
0 commit comments