History

lavc/vaapi_encode: Change the slice/parameter buffers to dynamic alloc.

Change the slice/parameter buffers to be allocated dynamically.

Jun Zhao committed 9 years ago

Commit e4a6eb71 parent 385cafb2 files · +32 −16Browse files

Unified · Split

2 files
  1. libavcodec/vaapi_encode.c +30 −12
  2. libavcodec/vaapi_encode.h +2 −4
libavcodec/vaapi_encode.c+30−12
@@ -36,13 +36,17 @@ static int vaapi_encode_make_packed_header(AVCodecContext *avctx, · 35 unmodified lines
3636 VAAPIEncodeContext *ctx = avctx->priv_data;
3737 VAStatus vas;
3838 VABufferID param_buffer, data_buffer;
39+ VABufferID *tmp;
3940 VAEncPackedHeaderParameterBuffer params = {
4041 .type = type,
4142 .bit_length = bit_len,
4243 .has_emulation_bytes = 1,
4344 };
4445
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;
4650
4751 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
4852 VAEncPackedHeaderParameterBufferType,
@@ -77,9 +81,13 @@ static int vaapi_encode_make_param_buffer(AVCodecContext *avctx, · 28 unmodified lines
7781 {
7882 VAAPIEncodeContext *ctx = avctx->priv_data;
7983 VAStatus vas;
84+ VABufferID *tmp;
8085 VABufferID buffer;
8186
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;
8391
8492 vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context,
8593 type, len, 1, data, &buffer);
@@ -313,15 +321,14 @@ static int vaapi_encode_issue(AVCodecContext *avctx, · 227 unmodified lines
313321 }
314322 }
315323
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+ }
317329 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];
323331 slice->index = i;
324− pic->slices[i] = slice;
325332
326333 if (ctx->codec->slice_params_size > 0) {
327334 slice->codec_slice_params = av_mallocz(ctx->codec->slice_params_size);
@@ -425,8 +432,16 @@ fail_with_picture: · 97 unmodified lines
425432 fail:
426433 for(i = 0; i < pic->nb_param_buffers; i++)
427434 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+ }
428441 fail_at_end:
429442 av_freep(&pic->codec_picture_params);
443+ av_freep(&pic->param_buffers);
444+ av_freep(&pic->slices);
430445 av_frame_free(&pic->recon_image);
431446 av_buffer_unref(&pic->output_buffer_ref);
432447 pic->output_buffer = VA_INVALID_ID;
@@ -535,15 +550,18 @@ static int vaapi_encode_free(AVCodecContext *avctx, · 102 unmodified lines
535550 vaapi_encode_discard(avctx, pic);
536551
537552 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+ }
541557 }
542558 av_freep(&pic->codec_picture_params);
543559
544560 av_frame_free(&pic->input_image);
545561 av_frame_free(&pic->recon_image);
546562
563+ av_freep(&pic->param_buffers);
564+ av_freep(&pic->slices);
547565 // Output buffer should already be destroyed.
548566 av_assert0(pic->output_buffer == VA_INVALID_ID);
549567
libavcodec/vaapi_encode.h+2−4
@@ -35,8 +35,6 @@ enum { · 34 unmodified lines
3535 MAX_CONFIG_ATTRIBUTES = 4,
3636 MAX_GLOBAL_PARAMS = 4,
3737 MAX_PICTURE_REFERENCES = 2,
38− MAX_PICTURE_SLICES = 112,
39− MAX_PARAM_BUFFERS = 128,
4038 MAX_REORDER_DELAY = 16,
4139 MAX_PARAM_BUFFER_SIZE = 1024,
4240 };
@@ -73,7 +71,7 @@ typedef struct VAAPIEncodePicture { · 30 unmodified lines
7371 VASurfaceID recon_surface;
7472
7573 int nb_param_buffers;
76− VABufferID param_buffers[MAX_PARAM_BUFFERS];
74+ VABufferID *param_buffers;
7775
7876 AVBufferRef *output_buffer_ref;
7977 VABufferID output_buffer;
@@ -85,7 +83,7 @@ typedef struct VAAPIEncodePicture { · 5 unmodified lines
8583 struct VAAPIEncodePicture *refs[MAX_PICTURE_REFERENCES];
8684
8785 int nb_slices;
88− VAAPIEncodeSlice *slices[MAX_PICTURE_SLICES];
86+ VAAPIEncodeSlice *slices;
8987 } VAAPIEncodePicture;
9088
9189 typedef struct VAAPIEncodeContext {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t