Skip to content

Commit 19807a0

Browse files
YLouWashUfacebook-github-bot
authored andcommitted
{CUDA Decoding} Destroy existing NVDEC decoder before recreating on sequence re-signal
Summary: `NvDecoder::HandleVideoSequence` is the NVDEC parser's sequence callback and, as its own header doc notes, can fire again mid-stream on a new sequence header or format change. The body unconditionally called `cuvidCreateDecoder(&_decoder, ...)`, so on any re-invocation it overwrote `_decoder` with a fresh handle without destroying the previous one — leaking the old `CUvideodecoder` and leaving the parser driving a stale/duplicated decoder. This is the "returning stale decoder" issue raised in review on D103253728. Fix: guard the create call. When `_decoder` is already non-null, `cuvidDestroyDecoder` it (and null it, so a subsequent create failure can't double-free in the destructor) before creating the replacement. Destroy-before-recreate is chosen over `cuvidReconfigureDecoder` for correctness and simplicity: Aria streams have constant format so re-signal is rare, making the recreate cost negligible; reconfigure (an in-place perf optimization bounded by the original ulMaxWidth/Height) can be a later change if a re-signaling workload ever needs it. Follow-up to D103253728. Reviewed By: georges-berenger Differential Revision: D113848493
1 parent a5ffa3b commit 19807a0

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

xprs/nvDecoder.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ int NvDecoder::HandleVideoSequence(CUVIDEOFORMAT* vdeo_format) {
210210
}
211211
}
212212

213+
// HandleVideoSequence can fire again mid-stream on a new sequence header or
214+
// format change (see header). Never overwrite a live decoder handle: that
215+
// leaks the previous CUvideodecoder and leaves the parser driving a stale one.
216+
// Destroy the existing decoder before creating its replacement.
217+
if (_decoder != nullptr) {
218+
CUDA_API_CALL(
219+
_nvcodec_context._cuvid_functions->cuvidDestroyDecoder(_decoder),
220+
_nvcodec_context._cuda_functions,
221+
DO_NOT_THROW);
222+
_decoder = nullptr;
223+
}
224+
213225
CUDA_API_CALL(
214226
_nvcodec_context._cuvid_functions->cuvidCreateDecoder(&_decoder, &video_decode_create_info),
215227
_nvcodec_context._cuda_functions,

0 commit comments

Comments
 (0)