Skip to content

Commit d3afb4f

Browse files
committed
Fix H.264 video decode error when seeking/looping
1 parent 7ddbe04 commit d3afb4f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/vabackend.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,17 +1050,17 @@ static VAStatus nvCreateContext(
10501050
if (num_render_targets) {
10511051
// Update the decoder configuration to match the passed in surfaces.
10521052
NVSurface *surface = (NVSurface *) getObjectPtr(drv, render_targets[0]);
1053+
if (!surface) {
1054+
return VA_STATUS_ERROR_INVALID_PARAMETER;
1055+
}
10531056
cfg->surfaceFormat = surface->format;
10541057
cfg->chromaFormat = surface->chromaFormat;
10551058
cfg->bitDepth = surface->bitDepth;
10561059
}
10571060

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

1063-
int surfaceCount = drv->surfaceCount > 1 ? drv->surfaceCount : num_render_targets;
10641064
if (surfaceCount > 32) {
10651065
LOG("Application requested %d surface(s), limiting to 32. This may cause issues.", surfaceCount);
10661066
surfaceCount = 32;
@@ -1104,6 +1104,7 @@ static VAStatus nvCreateContext(
11041104
nvCtx->width = picture_width;
11051105
nvCtx->height = picture_height;
11061106
nvCtx->codec = selectedCodec;
1107+
nvCtx->surfaceCount = surfaceCount;
11071108

11081109
pthread_mutexattr_t attrib;
11091110
pthread_mutexattr_init(&attrib);
@@ -1281,6 +1282,9 @@ static VAStatus nvBeginPicture(
12811282

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

src/vabackend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ typedef struct _NVContext
179179
int surfaceQueueWriteIdx;
180180
bool exiting;
181181
pthread_mutex_t surfaceCreationMutex;
182+
int surfaceCount;
182183
} NVContext;
183184

184185
typedef struct

0 commit comments

Comments
 (0)