diff options
author | Lars Sutterud <lars.sutterud@qt.io> | 2024-04-25 10:25:10 +0200 |
---|---|---|
committer | Lars Sutterud <lars.sutterud@qt.io> | 2024-04-30 11:01:56 +0200 |
commit | 1833c46205d6c764362416c1aed372ee4462c2ba (patch) | |
tree | 351704a9eb63d80e5f8e3498f3eba3ed5e68620f | |
parent | 780071628b00b4d2f66daeb87af6840c3eef2aeb (diff) |
FFmpeg VAAPI: Fix not closing fd's when returning from getTextures()
Added a QScopeGuard to make sure we close all file descriptors in the
VADRMPRIMESurfaceDescriptor struct after calling vaExportSurfaceHandle()
There are multiple return points in VAAPITextureConverter::getTextures()
and the QScopeGuard will iterate through the struct and close all fd's
upon destruction.
Change-Id: I34037d5ca30bdeb27ec73beaabd559595a509910
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
-rw-r--r-- | src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp index 81eef89ef..09ffaaf71 100644 --- a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp +++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp @@ -231,7 +231,7 @@ TextureSet *VAAPITextureConverter::getTextures(AVFrame *frame) VASurfaceID vaSurface = (uintptr_t)frame->data[3]; - VADRMPRIMESurfaceDescriptor prime; + VADRMPRIMESurfaceDescriptor prime = {}; if (vaExportSurfaceHandle(vaDisplay, vaSurface, VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2, VA_EXPORT_SURFACE_READ_ONLY | @@ -245,6 +245,13 @@ TextureSet *VAAPITextureConverter::getTextures(AVFrame *frame) qWarning() << "vaExportSurfaceHandle failed"; return nullptr; } + + // Make sure all fd's in 'prime' are closed when we return from this function + QScopeGuard closeObjectsGuard([&prime]() { + for (uint32_t i = 0; i < prime.num_objects; ++i) + close(prime.objects[i].fd); + }); + // ### Check that prime.fourcc is what we expect vaSyncSurface(vaDisplay, vaSurface); @@ -325,9 +332,6 @@ TextureSet *VAAPITextureConverter::getTextures(AVFrame *frame) qWarning() << "eglImageTargetTexture2D failed with error code" << error; } - for (int i = 0; i < (int)prime.num_objects; ++i) - close(prime.objects[i].fd); - for (int i = 0; i < nPlanes; ++i) { functions.glActiveTexture(GL_TEXTURE0 + i); functions.glBindTexture(GL_TEXTURE_2D, 0); |