[Bugfix][Multimodal] Invalidate retained PyNvVideoCodec decoder after failure (#51139)
Signed-off-by: Dat Mai <dmai@nvidia.com>
This commit is contained in:
@@ -261,8 +261,13 @@ class PyNvVideoCodecDecoderSlot:
|
||||
self.decoder = None
|
||||
self.source_path: str | None = None
|
||||
|
||||
def invalidate(self) -> None:
|
||||
self.decoder = None
|
||||
self.source_path = None
|
||||
|
||||
def _construct(self, file_path: str, nvc, device_index: int) -> None:
|
||||
self.decoder = nvc.SimpleDecoder(
|
||||
self.invalidate()
|
||||
decoder = nvc.SimpleDecoder(
|
||||
file_path,
|
||||
output_color_type=nvc.OutputColorType.RGB,
|
||||
use_device_memory=True,
|
||||
@@ -271,6 +276,7 @@ class PyNvVideoCodecDecoderSlot:
|
||||
cuda_stream=self.stream.cuda_stream,
|
||||
decoder_cache_size=PYNVVIDEOCODEC_DECODER_CACHE_SIZE,
|
||||
)
|
||||
self.decoder = decoder
|
||||
self.source_path = file_path
|
||||
|
||||
def get_decoder(self, file_path: str, nvc, device_index: int):
|
||||
@@ -747,9 +753,13 @@ class PyNvVideoCodecVideoBackendMixin:
|
||||
cls._decoder_slot_cond.notify()
|
||||
raise
|
||||
|
||||
borrow_succeeded = False
|
||||
try:
|
||||
yield slot
|
||||
borrow_succeeded = True
|
||||
finally:
|
||||
if not borrow_succeeded:
|
||||
slot.invalidate()
|
||||
with cls._decoder_slot_cond:
|
||||
cls._decoder_slots.append(slot)
|
||||
cls._decoder_slot_cond.notify()
|
||||
|
||||
Reference in New Issue
Block a user