Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion codec/decoder/plus/src/welsDecoderExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,10 +1065,10 @@ void CWelsDecoder::ReleaseBufferedReadyPictureReorder (PWelsDecoderContext pCtx,
// BufferingReadyPicture() publication on the shared m_sPictInfoList /
// m_sReoderingStatus queue state.
if (m_iThreadCount >= 1) WelsMutexLock (&m_csDecoder);
PPicBuff pPicBuff = pCtx ? pCtx->pPicBuff : m_pPicBuff;
if (pCtx == NULL && m_iThreadCount <= 1) {
pCtx = m_pDecThrCtx[0].pCtx;
}
PPicBuff pPicBuff = pCtx ? pCtx->pPicBuff : m_pPicBuff;
if (m_sReoderingStatus.iNumOfPicts > 0) {
m_sReoderingStatus.iMinPOC = IMinInt32;
int32_t firstValidIdx = -1;
Expand Down Expand Up @@ -1140,6 +1140,9 @@ void CWelsDecoder::ReleaseBufferedReadyPictureNoReorder(PWelsDecoderContext pCtx
// BufferingReadyPicture() publication on the shared m_sPictInfoList /
// m_sReoderingStatus queue state.
if (m_iThreadCount >= 1) WelsMutexLock (&m_csDecoder);
if (pCtx == NULL && m_iThreadCount <= 1) {
pCtx = m_pDecThrCtx[0].pCtx;
}
int32_t firstValidIdx = -1;
uint32_t uiDecodingTimeStamp = 0;
for (int32_t i = 0; i <= m_sReoderingStatus.iLargestBufferedPicIndex; ++i) {
Expand Down
Binary file added res/High_POC_step2_32x32_30frames.264
Binary file not shown.
46 changes: 46 additions & 0 deletions test/api/decode_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,3 +1391,49 @@ TEST (DecoderDpbGrowthStability, BFrameDecodeIsConsistentAcrossReinit) {
}
}


// A High profile stream without B-frames whose picture order count steps by
// two, as some hardware encoders write it: the decoder holds each picture back,
// and a low-latency caller takes it with FlushFrame. Each flush has to return
// the picture's buffer, or the pool runs dry after a few pictures.
TEST (DecoderFlushFrame, FlushAfterEachAccessUnitKeepsDecoding) {
std::ifstream f ("res/High_POC_step2_32x32_30frames.264", std::ios::binary);
ASSERT_TRUE (f.is_open());
std::vector<uint8_t> bs ((std::istreambuf_iterator<char> (f)), {});
std::vector<size_t> starts;
for (size_t i = 0; i + 4 <= bs.size(); ++i) {
if (bs[i] == 0 && bs[i + 1] == 0 && bs[i + 2] == 0 && bs[i + 3] == 1)
starts.push_back (i);
}
starts.push_back (bs.size());

ISVCDecoder* dec = nullptr;
ASSERT_EQ (WelsCreateDecoder (&dec), 0);
SDecodingParam param;
memset (&param, 0, sizeof (param));
param.uiTargetDqLayer = UCHAR_MAX;
ASSERT_EQ (dec->Initialize (&param), 0);

int32_t units = 0, pictures = 0;
size_t unit = 0;
for (size_t k = 0; k + 1 < starts.size(); ++k) {
const int32_t type = bs[starts[k] + 4] & 0x1f;
if (type != 1 && type != 5)
continue;
uint8_t* dst[3] = {nullptr, nullptr, nullptr};
SBufferInfo info;
memset (&info, 0, sizeof (info));
int32_t state = dec->DecodeFrameNoDelay (bs.data() + unit, static_cast<int32_t> (starts[k + 1] - unit), dst, &info);
if (info.iBufferStatus != 1)
state |= dec->FlushFrame (dst, &info);
EXPECT_EQ (state, dsErrorFree) << "access unit " << units;
EXPECT_EQ (info.iBufferStatus, 1) << "access unit " << units;
pictures += info.iBufferStatus == 1;
++units;
unit = starts[k + 1];
}
dec->Uninitialize();
WelsDestroyDecoder (dec);
EXPECT_EQ (units, 30);
EXPECT_EQ (pictures, units);
}