From 1a7e004368f4f5221e91bf53e17a8c0f7e1ceeb8 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 21 May 2020 11:38:22 +0200 Subject: [PATCH] Move VADisplayWithCleanup into its own header file, in shared/. This is the first step on trying to unify the initialization code a bit between Nageru and Futatabi. --- futatabi/vaapi_jpeg_decoder.cpp | 13 ------------- nageru/mixer.cpp | 2 +- nageru/mjpeg_encoder.cpp | 2 +- nageru/pbo_frame_allocator.cpp | 2 +- nageru/quicksync_encoder.cpp | 13 ------------- nageru/quicksync_encoder_impl.h | 2 +- shared/meson.build | 6 ++++-- shared/va_display.cpp | 16 ++++++++++++++++ .../va_display.h | 9 +++++---- 9 files changed, 29 insertions(+), 36 deletions(-) create mode 100644 shared/va_display.cpp rename nageru/va_display_with_cleanup.h => shared/va_display.h (65%) diff --git a/futatabi/vaapi_jpeg_decoder.cpp b/futatabi/vaapi_jpeg_decoder.cpp index 0441514..452e61c 100644 --- a/futatabi/vaapi_jpeg_decoder.cpp +++ b/futatabi/vaapi_jpeg_decoder.cpp @@ -138,19 +138,6 @@ private: bool committed = false; }; -VADisplayWithCleanup::~VADisplayWithCleanup() -{ - if (va_dpy != nullptr) { - vaTerminate(va_dpy); - } - if (x11_display != nullptr) { - XCloseDisplay(x11_display); - } - if (drm_fd != -1) { - close(drm_fd); - } -} - unique_ptr va_open_display(const string &va_display) { if (va_display.empty() || va_display[0] != '/') { // An X display. diff --git a/nageru/mixer.cpp b/nageru/mixer.cpp index ba1f334..a5206c9 100644 --- a/nageru/mixer.cpp +++ b/nageru/mixer.cpp @@ -48,6 +48,7 @@ #include "image_input.h" #include "input_mapping.h" #include "shared/metrics.h" +#include "shared/va_display.h" #include "mjpeg_encoder.h" #include "pbo_frame_allocator.h" #include "shared/ref_counted_gl_sync.h" @@ -55,7 +56,6 @@ #include "shared/timebase.h" #include "timecode_renderer.h" #include "v210_converter.h" -#include "va_display_with_cleanup.h" #include "video_encoder.h" #undef Status diff --git a/nageru/mjpeg_encoder.cpp b/nageru/mjpeg_encoder.cpp index 03afac9..857346d 100644 --- a/nageru/mjpeg_encoder.cpp +++ b/nageru/mjpeg_encoder.cpp @@ -20,7 +20,7 @@ extern "C" { #include "shared/metrics.h" #include "pbo_frame_allocator.h" #include "shared/timebase.h" -#include "va_display_with_cleanup.h" +#include "shared/va_display.h" #include diff --git a/nageru/pbo_frame_allocator.cpp b/nageru/pbo_frame_allocator.cpp index ba53226..d7cd818 100644 --- a/nageru/pbo_frame_allocator.cpp +++ b/nageru/pbo_frame_allocator.cpp @@ -10,7 +10,7 @@ #include "flags.h" #include "mjpeg_encoder.h" #include "v210_converter.h" -#include "va_display_with_cleanup.h" +#include "shared/va_display.h" using namespace std; diff --git a/nageru/quicksync_encoder.cpp b/nageru/quicksync_encoder.cpp index 70bf800..7ec9f71 100644 --- a/nageru/quicksync_encoder.cpp +++ b/nageru/quicksync_encoder.cpp @@ -728,19 +728,6 @@ void QuickSyncEncoderImpl::enable_zerocopy_if_possible() global_flags.use_zerocopy = use_zerocopy; } -VADisplayWithCleanup::~VADisplayWithCleanup() -{ - if (va_dpy != nullptr) { - vaTerminate(va_dpy); - } - if (x11_display != nullptr) { - XCloseDisplay(x11_display); - } - if (drm_fd != -1) { - close(drm_fd); - } -} - unique_ptr va_open_display(const string &va_display) { if (va_display.empty() || va_display[0] != '/') { // An X display. diff --git a/nageru/quicksync_encoder_impl.h b/nageru/quicksync_encoder_impl.h index 0800c59..53f88ec 100644 --- a/nageru/quicksync_encoder_impl.h +++ b/nageru/quicksync_encoder_impl.h @@ -20,7 +20,7 @@ #include "shared/timebase.h" #include "print_latency.h" #include "shared/ref_counted_gl_sync.h" -#include "va_display_with_cleanup.h" +#include "shared/va_display.h" #include "v4l_output.h" #define SURFACE_NUM 16 /* 16 surfaces for source YUV */ diff --git a/shared/meson.build b/shared/meson.build index c7ef06c..28586c6 100644 --- a/shared/meson.build +++ b/shared/meson.build @@ -4,6 +4,8 @@ libmicrohttpddep = dependency('libmicrohttpd') protobufdep = dependency('protobuf') alsadep = dependency('alsa') movitdep = dependency('movit') +vadrmdep = dependency('libva-drm') +vax11dep = dependency('libva-x11') # Preprocess Qt as needed. qt_files = qt5.preprocess( @@ -19,14 +21,14 @@ proto_generated = gen.process(['midi_mapping.proto']) protobuf_lib = static_library('protobufs', proto_generated, dependencies: [protobufdep]) protobuf_hdrs = declare_dependency(sources: proto_generated) -srcs = ['memcpy_interleaved.cpp', 'metacube2.cpp', 'ffmpeg_raii.cpp', 'mux.cpp', 'metrics.cpp', 'context.cpp', 'httpd.cpp', 'disk_space_estimator.cpp', 'read_file.cpp', 'text_proto.cpp', 'midi_device.cpp', 'ref_counted_texture.cpp'] +srcs = ['memcpy_interleaved.cpp', 'metacube2.cpp', 'ffmpeg_raii.cpp', 'mux.cpp', 'metrics.cpp', 'context.cpp', 'httpd.cpp', 'disk_space_estimator.cpp', 'read_file.cpp', 'text_proto.cpp', 'midi_device.cpp', 'ref_counted_texture.cpp', 'va_display.cpp'] srcs += proto_generated # Qt objects. srcs += qt_files srcs += ['aboutdialog.cpp'] -shared = static_library('shared', srcs, include_directories: top_include, dependencies: [shared_qt5deps, libmicrohttpddep, protobufdep, alsadep, movitdep]) +shared = static_library('shared', srcs, include_directories: top_include, dependencies: [shared_qt5deps, libmicrohttpddep, protobufdep, alsadep, movitdep, vadrmdep, vax11dep]) shareddep = declare_dependency( sources: proto_generated, include_directories: top_include, diff --git a/shared/va_display.cpp b/shared/va_display.cpp new file mode 100644 index 0000000..36c8f17 --- /dev/null +++ b/shared/va_display.cpp @@ -0,0 +1,16 @@ +#include "shared/va_display.h" +#include + +VADisplayWithCleanup::~VADisplayWithCleanup() +{ + if (va_dpy != nullptr) { + vaTerminate(va_dpy); + } + if (x11_display != nullptr) { + XCloseDisplay(x11_display); + } + if (drm_fd != -1) { + close(drm_fd); + } +} + diff --git a/nageru/va_display_with_cleanup.h b/shared/va_display.h similarity index 65% rename from nageru/va_display_with_cleanup.h rename to shared/va_display.h index 3f9b1c5..395ecbb 100644 --- a/nageru/va_display_with_cleanup.h +++ b/shared/va_display.h @@ -1,19 +1,20 @@ -#ifndef _VA_DISPLAY_WITH_CLEANUP -#define _VA_DISPLAY_WITH_CLEANUP 1 +#ifndef _VA_DISPLAY_H +#define _VA_DISPLAY _H1 #include #include #include +#include struct VADisplayWithCleanup { ~VADisplayWithCleanup(); VADisplay va_dpy; Display *x11_display = nullptr; - bool can_use_zerocopy = true; + bool can_use_zerocopy = true; // For H.264 encoding in Nageru. int drm_fd = -1; }; std::unique_ptr va_open_display(const std::string &va_display); // Can return nullptr on failure. -#endif // !defined(_VA_DISPLAY_WITH_CLEANUP) +#endif // !defined(_VA_DISPLAY_H) -- 2.39.2