diff --git a/framework/codec/ActiveDecoder.cpp b/framework/codec/ActiveDecoder.cpp index cb67c1171..0f3da2074 100644 --- a/framework/codec/ActiveDecoder.cpp +++ b/framework/codec/ActiveDecoder.cpp @@ -224,7 +224,8 @@ int ActiveDecoder::thread_send_packet(unique_ptr &packet) return 0; } - if (mInputQueue.size() >= MAX_INPUT_SIZE) { + if ((mInputQueue.size() >= MAX_INPUT_SIZE) + || (mOutputQueue.size() >= maxOutQueueSize)) { // TODO: wait for timeOut us status |= STATUS_RETRY_IN; } else { diff --git a/framework/codec/ActiveDecoder.h b/framework/codec/ActiveDecoder.h index b8e1c19f3..b90097a3b 100644 --- a/framework/codec/ActiveDecoder.h +++ b/framework/codec/ActiveDecoder.h @@ -82,7 +82,7 @@ class ActiveDecoder : public Cicada::IDecoder { std::condition_variable mSleepCondition{}; std::queue> mInputQueue{}; std::queue> mOutputQueue{}; - int maxOutQueueSize = 16; + int maxOutQueueSize = 2; std::mutex mMutex{}; std::mutex mSleepMutex{}; #endif diff --git a/framework/codec/Apple/AppleVideoToolBox.cpp b/framework/codec/Apple/AppleVideoToolBox.cpp index 2dc02022b..4695443ee 100644 --- a/framework/codec/Apple/AppleVideoToolBox.cpp +++ b/framework/codec/Apple/AppleVideoToolBox.cpp @@ -4,6 +4,7 @@ #include "AppleVideoToolBox.h" #include "codec/utils_ios.h" #include "utils/errors/framework_error.h" +#include "utils/timer.h" #include #include "video_tool_box_utils.h" @@ -47,11 +48,11 @@ namespace Cicada { if (codec == AF_CODEC_ID_HEVC) { #if TARGET_OS_IPHONE - if (__builtin_available(iOS 11.0, *)) { + if (__builtin_available(iOS 11.0, *)) #else - - if (__builtin_available(macOS 10.13, *)) { + if (__builtin_available(macOS 10.13, *)) #endif + { return VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC); } else { return false; @@ -356,18 +357,24 @@ namespace Cicada { init_decoder_internal(); } + int64_t startDecodeTime = af_getsteady_ms(); + while (!mRecoveringQueue.empty()) { int ret = enqueue_decoder_internal(mRecoveringQueue.front()); if (ret != -EAGAIN) { mRecoveringQueue.pop(); + } else { + return -EAGAIN; } if (!mRunning) { return -EAGAIN; } - // return -EAGAIN; + if (af_getsteady_ms() - startDecodeTime > 50) { + return -EAGAIN; + } } if (pPacket == nullptr) { @@ -459,7 +466,7 @@ namespace Cicada { // // AF_TRACE; // return -EAGAIN; // } - if (pPacket->getInfo().flags) { + if (pPacket->getInfo().flags & AF_PKT_FLAG_KEY) { mThrowPacket = false; } @@ -690,7 +697,7 @@ namespace Cicada { { pPacket->setDiscard(true); - if (pPacket->getInfo().flags) { + if (pPacket->getInfo().flags & AF_PKT_FLAG_KEY) { while (!mRecoveryQueue.empty()) { mRecoveryQueue.pop(); } diff --git a/mediaPlayer/SuperMediaPlayer.cpp b/mediaPlayer/SuperMediaPlayer.cpp index 492d3acc0..7773ed934 100644 --- a/mediaPlayer/SuperMediaPlayer.cpp +++ b/mediaPlayer/SuperMediaPlayer.cpp @@ -1597,14 +1597,14 @@ namespace Cicada { int ret = DecodeVideoPacket(mVideoPacket); - if (ret == -EAGAIN) { + if (ret & STATUS_RETRY_IN) { break; } - if (af_getsteady_ms() - startDecodeTime > 100) { + if (af_getsteady_ms() - startDecodeTime > 50) { break; } - } while (mSeekNeedCatch); + } while (mSeekNeedCatch || dropLateVideoFrames); } } @@ -1797,7 +1797,7 @@ namespace Cicada { // if send all audio data, try to render again to send more data. if (RENDER_FULL == ret) { - audioRendered = RenderAudio(); + RenderAudio(); } } } @@ -2024,7 +2024,7 @@ namespace Cicada { } if (dropLateVideoFrames) { - if (videoLateUs > 0) { + if (videoLateUs > 10 * 1000) { render = false; } else { dropLateVideoFrames = false; diff --git a/mediaPlayer/SuperMediaPlayer.h b/mediaPlayer/SuperMediaPlayer.h index 3257c7b5f..6d533daf2 100644 --- a/mediaPlayer/SuperMediaPlayer.h +++ b/mediaPlayer/SuperMediaPlayer.h @@ -60,7 +60,6 @@ namespace Cicada { typedef enum APP_STATUS { APP_FOREGROUND, APP_BACKGROUND, - APP_FOREGROUND_CATCHUP, } APP_STATUS;