Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Reduce decoder latency by 2 frames #332

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions PyNvCodec/TC/inc/NvDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@ class DllExport NvDecoder {
int ReconfigureDecoder(CUVIDEOFORMAT *pVideoFormat);

struct NvDecoderImpl *p_impl;
bool setEndOfPicture = false;
};
10 changes: 10 additions & 0 deletions PyNvCodec/TC/src/NvDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ static int GetChromaPlaneCount(cudaVideoChromaFormat eChromaFormat)
unsigned long GetNumDecodeSurfaces(cudaVideoCodec eCodec, unsigned int nWidth,
unsigned int nHeight)
{
const char *num_decode_surfaces_str = getenv("NV_NUM_DECODE_SURFACES");
if (num_decode_surfaces_str) {
return atoi(num_decode_surfaces_str);
}

if (eCodec == cudaVideoCodec_VP9) {
return 12;
}
Expand Down Expand Up @@ -614,6 +619,10 @@ NvDecoder::NvDecoder(CUstream cuStream, CUcontext cuContext,
cudaVideoCodec eCodec, bool bLowLatency, int maxWidth,
int maxHeight)
{
int lowLatency = getenv("NV_LOW_LATENCY") ? atoi(getenv("NV_LOW_LATENCY")) : 0;
if (lowLatency&1) setEndOfPicture = true;
if (lowLatency&2) bLowLatency = true;

p_impl = new NvDecoderImpl();
p_impl->m_cuvidStream = cuStream;
p_impl->m_cuContext = cuContext;
Expand Down Expand Up @@ -716,6 +725,7 @@ bool NvDecoder::DecodeLockSurface(Buffer const* encFrame,
encFrame ? encFrame->GetDataAs<const unsigned char>() : nullptr;
packet.payload_size = encFrame ? encFrame->GetRawMemSize() : 0U;
packet.flags = CUVID_PKT_TIMESTAMP;
if (setEndOfPicture) packet.flags |= CUVID_PKT_ENDOFPICTURE;
packet.timestamp = pdata.pts;
if (!decCtx.no_eos &&
(nullptr == packet.payload || 0 == packet.payload_size)) {
Expand Down