Skip to content

Commit

Permalink
Fix H.264 video decode error when seeking/looping
Browse files Browse the repository at this point in the history
  • Loading branch information
thesword53 committed Jan 9, 2025
1 parent 7ddbe04 commit d3afb4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/vabackend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1050,17 +1050,17 @@ static VAStatus nvCreateContext(
if (num_render_targets) {
// Update the decoder configuration to match the passed in surfaces.
NVSurface *surface = (NVSurface *) getObjectPtr(drv, render_targets[0]);
if (!surface) {
return VA_STATUS_ERROR_INVALID_PARAMETER;
}
cfg->surfaceFormat = surface->format;
cfg->chromaFormat = surface->chromaFormat;
cfg->bitDepth = surface->bitDepth;
}

if (drv->surfaceCount <= 1 && num_render_targets == 0) {
LOG("0/1 surfaces have been passed to vaCreateContext, this might cause errors. Setting surface count to 32");
num_render_targets = 32;
}
// Setting to maximun value if num_render_targets == 0 to prevent picture index overflow as additional surfaces can be created after calling nvCreateContext
int surfaceCount = num_render_targets > 0 ? num_render_targets : 32;

int surfaceCount = drv->surfaceCount > 1 ? drv->surfaceCount : num_render_targets;
if (surfaceCount > 32) {
LOG("Application requested %d surface(s), limiting to 32. This may cause issues.", surfaceCount);
surfaceCount = 32;
Expand Down Expand Up @@ -1104,6 +1104,7 @@ static VAStatus nvCreateContext(
nvCtx->width = picture_width;
nvCtx->height = picture_height;
nvCtx->codec = selectedCodec;
nvCtx->surfaceCount = surfaceCount;

pthread_mutexattr_t attrib;
pthread_mutexattr_init(&attrib);
Expand Down Expand Up @@ -1281,6 +1282,9 @@ static VAStatus nvBeginPicture(

//if this surface hasn't been used before, give it a new picture index
if (surface->pictureIdx == -1) {
if (nvCtx->currentPictureId == nvCtx->surfaceCount) {
return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
}
surface->pictureIdx = nvCtx->currentPictureId++;
}

Expand Down
1 change: 1 addition & 0 deletions src/vabackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ typedef struct _NVContext
int surfaceQueueWriteIdx;
bool exiting;
pthread_mutex_t surfaceCreationMutex;
int surfaceCount;
} NVContext;

typedef struct
Expand Down

0 comments on commit d3afb4f

Please sign in to comment.