diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index cab1028e2c..93aa0ce5b3 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -257,7 +257,7 @@ int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, static const uint8_t startcode_prefix[3] = { 0x0, 0x0, 0x1 }; const size_t startcode_len = add_startcode ? sizeof(startcode_prefix) : 0; - const int nb = *nb_slices; + const int nb = nb_slices ? *nb_slices : 0; uint8_t *slices; uint32_t *slice_off; FFVkBuffer *vkbuf; @@ -266,13 +266,16 @@ int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, ctx->caps.minBitstreamBufferSizeAlignment; new_size = FFALIGN(new_size, ctx->caps.minBitstreamBufferSizeAlignment); - slice_off = av_fast_realloc(dec->slice_off, &dec->slice_off_max, - (nb + 1)*sizeof(slice_off)); - if (!slice_off) - return AVERROR(ENOMEM); + if (offsets) { + slice_off = av_fast_realloc(dec->slice_off, &dec->slice_off_max, + (nb + 1)*sizeof(slice_off)); + if (!slice_off) + return AVERROR(ENOMEM); - *offsets = dec->slice_off = slice_off; - slice_off[nb] = vp->slices_size; + *offsets = dec->slice_off = slice_off; + + slice_off[nb] = vp->slices_size; + } vkbuf = vp->slices_buf ? (FFVkBuffer *)vp->slices_buf->data : NULL; if (!vkbuf || vkbuf->size < new_size) { @@ -318,7 +321,9 @@ int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, /* Slice data */ memcpy(slices + vp->slices_size + startcode_len, data, size); - *nb_slices = nb + 1; + if (nb_slices) + *nb_slices = nb + 1; + vp->slices_size += startcode_len + size; return 0;