Skip to content

Commit

Permalink
refactor(decoder): reduce memory for recover iOS playback
Browse files Browse the repository at this point in the history
(cherry picked from commit b96a691)
  • Loading branch information
skufly authored and pingkai committed Feb 24, 2020
1 parent 80887fd commit ddcce48
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
3 changes: 2 additions & 1 deletion framework/codec/ActiveDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ int ActiveDecoder::thread_send_packet(unique_ptr<IAFPacket> &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 {
Expand Down
2 changes: 1 addition & 1 deletion framework/codec/ActiveDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ActiveDecoder : public Cicada::IDecoder {
std::condition_variable mSleepCondition{};
std::queue<std::unique_ptr<IAFPacket>> mInputQueue{};
std::queue<std::unique_ptr<IAFFrame>> mOutputQueue{};
int maxOutQueueSize = 16;
int maxOutQueueSize = 2;
std::mutex mMutex{};
std::mutex mSleepMutex{};
#endif
Expand Down
19 changes: 13 additions & 6 deletions framework/codec/Apple/AppleVideoToolBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "AppleVideoToolBox.h"
#include "codec/utils_ios.h"
#include "utils/errors/framework_error.h"
#include "utils/timer.h"
#include <cinttypes>

#include "video_tool_box_utils.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -459,7 +466,7 @@ namespace Cicada {
// // AF_TRACE;
// return -EAGAIN;
// }
if (pPacket->getInfo().flags) {
if (pPacket->getInfo().flags & AF_PKT_FLAG_KEY) {
mThrowPacket = false;
}

Expand Down Expand Up @@ -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();
}
Expand Down
10 changes: 5 additions & 5 deletions mediaPlayer/SuperMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -2024,7 +2024,7 @@ namespace Cicada {
}

if (dropLateVideoFrames) {
if (videoLateUs > 0) {
if (videoLateUs > 10 * 1000) {
render = false;
} else {
dropLateVideoFrames = false;
Expand Down
1 change: 0 additions & 1 deletion mediaPlayer/SuperMediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ namespace Cicada {
typedef enum APP_STATUS {
APP_FOREGROUND,
APP_BACKGROUND,
APP_FOREGROUND_CATCHUP,
} APP_STATUS;


Expand Down

0 comments on commit ddcce48

Please sign in to comment.