diff options
Diffstat (limited to 'src/encoder/video/vaapi.c')
-rw-r--r-- | src/encoder/video/vaapi.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/encoder/video/vaapi.c b/src/encoder/video/vaapi.c index 39531de..2b4d1ba 100644 --- a/src/encoder/video/vaapi.c +++ b/src/encoder/video/vaapi.c @@ -17,6 +17,7 @@ typedef struct { unsigned int target_textures[2]; + AVBufferRef *device_ctx; VADisplay va_dpy; VADRMPRIMESurfaceDescriptor prime; } gsr_video_encoder_vaapi; @@ -28,16 +29,15 @@ static bool gsr_video_encoder_vaapi_setup_context(gsr_video_encoder_vaapi *self, return false; } - AVBufferRef *device_ctx; - if(av_hwdevice_ctx_create(&device_ctx, AV_HWDEVICE_TYPE_VAAPI, render_path, NULL, 0) < 0) { + if(av_hwdevice_ctx_create(&self->device_ctx, AV_HWDEVICE_TYPE_VAAPI, render_path, NULL, 0) < 0) { fprintf(stderr, "gsr error: gsr_video_encoder_vaapi_setup_context: failed to create hardware device context\n"); return false; } - AVBufferRef *frame_context = av_hwframe_ctx_alloc(device_ctx); + AVBufferRef *frame_context = av_hwframe_ctx_alloc(self->device_ctx); if(!frame_context) { fprintf(stderr, "gsr error: gsr_video_encoder_vaapi_setup_context: failed to create hwframe context\n"); - av_buffer_unref(&device_ctx); + av_buffer_unref(&self->device_ctx); return false; } @@ -47,23 +47,22 @@ static bool gsr_video_encoder_vaapi_setup_context(gsr_video_encoder_vaapi *self, hw_frame_context->height = video_codec_context->height; hw_frame_context->sw_format = self->params.color_depth == GSR_COLOR_DEPTH_10_BITS ? AV_PIX_FMT_P010LE : AV_PIX_FMT_NV12; hw_frame_context->format = video_codec_context->pix_fmt; - hw_frame_context->device_ref = device_ctx; - hw_frame_context->device_ctx = (AVHWDeviceContext*)device_ctx->data; + hw_frame_context->device_ref = self->device_ctx; + hw_frame_context->device_ctx = (AVHWDeviceContext*)self->device_ctx->data; //hw_frame_context->initial_pool_size = 20; - AVVAAPIDeviceContext *vactx =((AVHWDeviceContext*)device_ctx->data)->hwctx; + AVVAAPIDeviceContext *vactx =((AVHWDeviceContext*)self->device_ctx->data)->hwctx; self->va_dpy = vactx->display; if (av_hwframe_ctx_init(frame_context) < 0) { fprintf(stderr, "gsr error: gsr_video_encoder_vaapi_setup_context: failed to initialize hardware frame context " "(note: ffmpeg version needs to be > 4.0)\n"); - av_buffer_unref(&device_ctx); + av_buffer_unref(&self->device_ctx); //av_buffer_unref(&frame_context); return false; } - video_codec_context->hw_device_ctx = av_buffer_ref(device_ctx); video_codec_context->hw_frames_ctx = av_buffer_ref(frame_context); return true; } @@ -373,10 +372,10 @@ void gsr_video_encoder_vaapi_stop(gsr_video_encoder_vaapi *self, AVCodecContext self->target_textures[0] = 0; self->target_textures[1] = 0; - if(video_codec_context->hw_device_ctx) - av_buffer_unref(&video_codec_context->hw_device_ctx); if(video_codec_context->hw_frames_ctx) av_buffer_unref(&video_codec_context->hw_frames_ctx); + if(self->device_ctx) + av_buffer_unref(&self->device_ctx); for(uint32_t i = 0; i < self->prime.num_objects; ++i) { if(self->prime.objects[i].fd > 0) { |