Change the slice/parameter buffers to be allocated dynamically.
Unified · Split
| @@ -36,13 +36,17 @@ static int vaapi_encode_make_packed_header(AVCodecContext *avctx, · 35 unmodified lines | ||
| 36 | 36 | VAAPIEncodeContext *ctx = avctx->priv_data; |
| 37 | 37 | VAStatus vas; |
| 38 | 38 | VABufferID param_buffer, data_buffer; |
| 39 | + VABufferID *tmp; | |
| 39 | 40 | VAEncPackedHeaderParameterBuffer params = { |
| 40 | 41 | .type = type, |
| 41 | 42 | .bit_length = bit_len, |
| 42 | 43 | .has_emulation_bytes = 1, |
| 43 | 44 | }; |
| 44 | 45 | |
| 45 | − av_assert0(pic->nb_param_buffers + 2 <= MAX_PARAM_BUFFERS); | |
| 46 | + tmp = av_realloc_array(pic->param_buffers, sizeof(*tmp), pic->nb_param_buffers + 2); | |
| 47 | + if (!tmp) | |
| 48 | + return AVERROR(ENOMEM); | |
| 49 | + pic->param_buffers = tmp; | |
| 46 | 50 | |
| 47 | 51 | vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, |
| 48 | 52 | VAEncPackedHeaderParameterBufferType, |
| @@ -77,9 +81,13 @@ static int vaapi_encode_make_param_buffer(AVCodecContext *avctx, · 28 unmodified lines | ||
| 77 | 81 | { |
| 78 | 82 | VAAPIEncodeContext *ctx = avctx->priv_data; |
| 79 | 83 | VAStatus vas; |
| 84 | + VABufferID *tmp; | |
| 80 | 85 | VABufferID buffer; |
| 81 | 86 | |
| 82 | − av_assert0(pic->nb_param_buffers + 1 <= MAX_PARAM_BUFFERS); | |
| 87 | + tmp = av_realloc_array(pic->param_buffers, sizeof(*tmp), pic->nb_param_buffers + 1); | |
| 88 | + if (!tmp) | |
| 89 | + return AVERROR(ENOMEM); | |
| 90 | + pic->param_buffers = tmp; | |
| 83 | 91 | |
| 84 | 92 | vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, |
| 85 | 93 | type, len, 1, data, &buffer); |
| @@ -313,15 +321,14 @@ static int vaapi_encode_issue(AVCodecContext *avctx, · 227 unmodified lines | ||
| 313 | 321 | } |
| 314 | 322 | } |
| 315 | 323 | |
| 316 | − av_assert0(pic->nb_slices <= MAX_PICTURE_SLICES); | |
| 324 | + pic->slices = av_mallocz_array(pic->nb_slices, sizeof(*pic->slices)); | |
| 325 | + if (!pic->slices) { | |
| 326 | + err = AVERROR(ENOMEM); | |
| 327 | + goto fail; | |
| 328 | + } | |
| 317 | 329 | for (i = 0; i < pic->nb_slices; i++) { |
| 318 | − slice = av_mallocz(sizeof(*slice)); | |
| 319 | − if (!slice) { | |
| 320 | − err = AVERROR(ENOMEM); | |
| 321 | − goto fail; | |
| 322 | − } | |
| 330 | + slice = &pic->slices[i]; | |
| 323 | 331 | slice->index = i; |
| 324 | − pic->slices[i] = slice; | |
| 325 | 332 | |
| 326 | 333 | if (ctx->codec->slice_params_size > 0) { |
| 327 | 334 | slice->codec_slice_params = av_mallocz(ctx->codec->slice_params_size); |
| @@ -425,8 +432,16 @@ fail_with_picture: · 97 unmodified lines | ||
| 425 | 432 | fail: |
| 426 | 433 | for(i = 0; i < pic->nb_param_buffers; i++) |
| 427 | 434 | vaDestroyBuffer(ctx->hwctx->display, pic->param_buffers[i]); |
| 435 | + for (i = 0; i < pic->nb_slices; i++) { | |
| 436 | + if (pic->slices) { | |
| 437 | + av_freep(&pic->slices[i].priv_data); | |
| 438 | + av_freep(&pic->slices[i].codec_slice_params); | |
| 439 | + } | |
| 440 | + } | |
| 428 | 441 | fail_at_end: |
| 429 | 442 | av_freep(&pic->codec_picture_params); |
| 443 | + av_freep(&pic->param_buffers); | |
| 444 | + av_freep(&pic->slices); | |
| 430 | 445 | av_frame_free(&pic->recon_image); |
| 431 | 446 | av_buffer_unref(&pic->output_buffer_ref); |
| 432 | 447 | pic->output_buffer = VA_INVALID_ID; |
| @@ -535,15 +550,18 @@ static int vaapi_encode_free(AVCodecContext *avctx, · 102 unmodified lines | ||
| 535 | 550 | vaapi_encode_discard(avctx, pic); |
| 536 | 551 | |
| 537 | 552 | for (i = 0; i < pic->nb_slices; i++) { |
| 538 | − av_freep(&pic->slices[i]->priv_data); | |
| 539 | − av_freep(&pic->slices[i]->codec_slice_params); | |
| 540 | − av_freep(&pic->slices[i]); | |
| 553 | + if (pic->slices) { | |
| 554 | + av_freep(&pic->slices[i].priv_data); | |
| 555 | + av_freep(&pic->slices[i].codec_slice_params); | |
| 556 | + } | |
| 541 | 557 | } |
| 542 | 558 | av_freep(&pic->codec_picture_params); |
| 543 | 559 | |
| 544 | 560 | av_frame_free(&pic->input_image); |
| 545 | 561 | av_frame_free(&pic->recon_image); |
| 546 | 562 | |
| 563 | + av_freep(&pic->param_buffers); | |
| 564 | + av_freep(&pic->slices); | |
| 547 | 565 | // Output buffer should already be destroyed. |
| 548 | 566 | av_assert0(pic->output_buffer == VA_INVALID_ID); |
| 549 | 567 | |
| @@ -35,8 +35,6 @@ enum { · 34 unmodified lines | ||
| 35 | 35 | MAX_CONFIG_ATTRIBUTES = 4, |
| 36 | 36 | MAX_GLOBAL_PARAMS = 4, |
| 37 | 37 | MAX_PICTURE_REFERENCES = 2, |
| 38 | − MAX_PICTURE_SLICES = 112, | |
| 39 | − MAX_PARAM_BUFFERS = 128, | |
| 40 | 38 | MAX_REORDER_DELAY = 16, |
| 41 | 39 | MAX_PARAM_BUFFER_SIZE = 1024, |
| 42 | 40 | }; |
| @@ -73,7 +71,7 @@ typedef struct VAAPIEncodePicture { · 30 unmodified lines | ||
| 73 | 71 | VASurfaceID recon_surface; |
| 74 | 72 | |
| 75 | 73 | int nb_param_buffers; |
| 76 | − VABufferID param_buffers[MAX_PARAM_BUFFERS]; | |
| 74 | + VABufferID *param_buffers; | |
| 77 | 75 | |
| 78 | 76 | AVBufferRef *output_buffer_ref; |
| 79 | 77 | VABufferID output_buffer; |
| @@ -85,7 +83,7 @@ typedef struct VAAPIEncodePicture { · 5 unmodified lines | ||
| 85 | 83 | struct VAAPIEncodePicture *refs[MAX_PICTURE_REFERENCES]; |
| 86 | 84 | |
| 87 | 85 | int nb_slices; |
| 88 | − VAAPIEncodeSlice *slices[MAX_PICTURE_SLICES]; | |
| 86 | + VAAPIEncodeSlice *slices; | |
| 89 | 87 | } VAAPIEncodePicture; |
| 90 | 88 | |
| 91 | 89 | typedef struct VAAPIEncodeContext { |