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