summaryrefslogtreecommitdiffstats
path: root/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2022-02-17 22:31:50 +0100
committerLars Knoll <lars.knoll@qt.io>2022-03-25 15:46:22 +0100
commit70c9971ad0aa2970d9db298915597cba3057f032 (patch)
tree571b3d3d166a3d89f23778e2f3e6735776172d1a /src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp
parentefd2203c5a3bf6a65df5cea7d9003cad51b4abc8 (diff)
Restructure the HW codec support
Disentangle HW codec support from the conversion into RHI compatible textures. Move the latter to a new TextureConverter class that controlled by the video sink, and only set on the video buffer when it passes through the sink. Properly create a HW context for the camera and add some preliminary support to the encoder on macOS. Adjust the VAAPI code to the new structure. Change-Id: I21ecf67fd276dfaa3ee7e04c80fe2304a3d536be Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Piotr Srebrny <piotr.srebrny@qt.io>
Diffstat (limited to 'src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp')
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp
index c1000b8aa..fe946efdc 100644
--- a/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp
+++ b/src/plugins/multimedia/ffmpeg/qffmpeghwaccel_vaapi.cpp
@@ -43,6 +43,8 @@
#error "Configuration error"
#endif
+#include <va/va.h>
+
#include <qvideoframeformat.h>
#include "qffmpegvideobuffer_p.h"
#include "private/qvideotexturehelper_p.h"
@@ -196,22 +198,16 @@ public:
};
-VAAPIAccel::VAAPIAccel(AVBufferRef *hwContext)
- : HWAccelBackend(hwContext)
+VAAPITextureConverter::VAAPITextureConverter(QRhi *rhi)
+ : TextureConverterBackend(nullptr)
{
qDebug() << ">>>> Creating VAAPI HW accelerator";
-}
-
-VAAPIAccel::~VAAPIAccel()
-{
-}
-
-void VAAPIAccel::setRhi(QRhi *rhi)
-{
- qDebug() << ">>>> Initializing VAAPI zero copy";
- if (!rhi || rhi->backend() != QRhi::OpenGLES2)
+ if (!rhi || rhi->backend() != QRhi::OpenGLES2) {
+ qWarning() << "VAAPITextureConverter: No rhi or non openGL based RHI";
+ this->rhi = nullptr;
return;
+ }
auto *nativeHandles = static_cast<const QRhiGles2NativeHandles *>(rhi->nativeHandles());
glContext = nativeHandles->context;
@@ -233,20 +229,17 @@ void VAAPIAccel::setRhi(QRhi *rhi)
qDebug() << " no eglImageTargetTexture2D, disabling";
return;
}
- auto *ctx = (AVHWDeviceContext *)hwContext->data;
- auto *vaCtx = (AVVAAPIDeviceContext *)ctx->hwctx;
- vaDisplay = vaCtx->display;
- if (!vaDisplay) {
- qDebug() << " no VADisplay, disabling";
- return;
- }
// everything ok, indicate that we can do zero copy
this->rhi = rhi;
}
+VAAPITextureConverter::~VAAPITextureConverter()
+{
+}
+
//#define VA_EXPORT_USE_LAYERS
-TextureSet *VAAPIAccel::getTextures(AVFrame *frame)
+TextureSet *VAAPITextureConverter::getTextures(AVFrame *frame)
{
// qDebug() << "VAAPIAccel::getTextures";
if (frame->format != AV_PIX_FMT_VAAPI || !eglDisplay) {
@@ -254,6 +247,21 @@ TextureSet *VAAPIAccel::getTextures(AVFrame *frame)
return nullptr;
}
+ if (!frame->hw_frames_ctx)
+ return nullptr;
+
+ auto *fCtx = (AVHWFramesContext *)frame->hw_frames_ctx->data;
+ auto *ctx = fCtx->device_ctx;
+ if (!ctx)
+ return nullptr;
+
+ auto *vaCtx = (AVVAAPIDeviceContext *)ctx->hwctx;
+ auto vaDisplay = vaCtx->display;
+ if (!vaDisplay) {
+ qDebug() << " no VADisplay, disabling";
+ return nullptr;
+ }
+
VASurfaceID vaSurface = (uintptr_t)frame->data[3];
VADRMPRIMESurfaceDescriptor prime;