Skip to content
Snippets Groups Projects
Commit dcd30f9b authored by Silas Della Contrada's avatar Silas Della Contrada
Browse files

Zero-Copy rendering is working for VAAPI with both P010 and NV12

 - Solved stretched video by setting glViewport to correctly scaled values
 - Code cleanup required
 - Running on X11 crashes with error: "Invalid EGL display"
parent d3ecc741
No related branches found
No related tags found
No related merge requests found
...@@ -183,6 +183,6 @@ if (WIN32) ...@@ -183,6 +183,6 @@ if (WIN32)
target_link_libraries(AVQt opengl32 OpenAL32) target_link_libraries(AVQt opengl32 OpenAL32)
target_link_libraries(AVQtStatic opengl32 OpenAL32) target_link_libraries(AVQtStatic opengl32 OpenAL32)
else () else ()
target_link_libraries(AVQt GL openal) target_link_libraries(AVQt GL openal EGL GLU)
target_link_libraries(AVQtStatic GL openal) target_link_libraries(AVQtStatic GL openal EGL GLU)
endif () endif ()
\ No newline at end of file
This diff is collapsed.
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <QtOpenGL> #include <QtOpenGL>
#include <input/IFrameSource.h> #include <input/IFrameSource.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "HidingNonVirtualFunction"
extern "C" { extern "C" {
#include <libavutil/rational.h> #include <libavutil/rational.h>
} }
...@@ -20,14 +22,14 @@ namespace AVQt { ...@@ -20,14 +22,14 @@ namespace AVQt {
class RenderClock; class RenderClock;
class OpenGLRenderer : public QOpenGLWindow, public IFrameSink { class OpenGLRenderer : public QOpenGLWidget, public IFrameSink {
Q_OBJECT Q_OBJECT
// Q_INTERFACES(AVQt::IFrameSink) // Q_INTERFACES(AVQt::IFrameSink)
Q_DECLARE_PRIVATE(AVQt::OpenGLRenderer) Q_DECLARE_PRIVATE(AVQt::OpenGLRenderer)
public: public:
explicit OpenGLRenderer(QWindow *parent = nullptr); explicit OpenGLRenderer(QWidget *parent = nullptr);
OpenGLRenderer(OpenGLRenderer &&other) noexcept; OpenGLRenderer(OpenGLRenderer &&other) noexcept;
...@@ -35,7 +37,7 @@ namespace AVQt { ...@@ -35,7 +37,7 @@ namespace AVQt {
void operator=(const OpenGLRenderer &) = delete; void operator=(const OpenGLRenderer &) = delete;
~OpenGLRenderer() noexcept; ~OpenGLRenderer() noexcept Q_DECL_OVERRIDE;
bool isPaused() Q_DECL_OVERRIDE; bool isPaused() Q_DECL_OVERRIDE;
...@@ -111,9 +113,12 @@ namespace AVQt { ...@@ -111,9 +113,12 @@ namespace AVQt {
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
OpenGLRendererPrivate *d_ptr; OpenGLRendererPrivate *d_ptr;
}; };
} }
#endif //LIBAVQT_OPENGLRENDERER_H #endif //LIBAVQT_OPENGLRENDERER_H
\ No newline at end of file #pragma clang diagnostic pop
\ No newline at end of file
...@@ -2,11 +2,23 @@ ...@@ -2,11 +2,23 @@
* \private * \private
* \internal * \internal
*/ */
#include <QtCore>
#include <QtOpenGL>
#include "../RenderClock.h" #include "../RenderClock.h"
#include "../OpenGLRenderer.h" #include "../OpenGLRenderer.h"
#include <QtCore>
#include <QtOpenGL>
#include <va/va.h>
#include <va/va_x11.h>
#include <va/va_drmcommon.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
extern "C" {
#include <libavutil/hwcontext_vaapi.h>
}
#ifndef LIBAVQT_OPENGLRENDERER_P_H #ifndef LIBAVQT_OPENGLRENDERER_P_H
#define LIBAVQT_OPENGLRENDERER_P_H #define LIBAVQT_OPENGLRENDERER_P_H
...@@ -42,6 +54,7 @@ namespace AVQt { ...@@ -42,6 +54,7 @@ namespace AVQt {
OpenGLRenderer *q_ptr{nullptr}; OpenGLRenderer *q_ptr{nullptr};
QMutex m_onFrameMutex{};
QMutex m_renderQueueMutex{}; QMutex m_renderQueueMutex{};
QQueue<QPair<AVFrame *, int64_t>> m_renderQueue{}; QQueue<QPair<AVFrame *, int64_t>> m_renderQueue{};
...@@ -56,6 +69,8 @@ namespace AVQt { ...@@ -56,6 +69,8 @@ namespace AVQt {
QMutex m_currentFrameMutex{}; QMutex m_currentFrameMutex{};
AVFrame *m_currentFrame{nullptr}; AVFrame *m_currentFrame{nullptr};
//OpenGL stuff
QOpenGLVertexArrayObject m_vao{}; QOpenGLVertexArrayObject m_vao{};
QOpenGLBuffer m_vbo{}, m_ibo{}; QOpenGLBuffer m_vbo{}, m_ibo{};
QOpenGLShaderProgram *m_program{nullptr}; QOpenGLShaderProgram *m_program{nullptr};
...@@ -64,6 +79,15 @@ namespace AVQt { ...@@ -64,6 +79,15 @@ namespace AVQt {
static constexpr uint PROGRAM_VERTEX_ATTRIBUTE{0}; static constexpr uint PROGRAM_VERTEX_ATTRIBUTE{0};
static constexpr uint PROGRAM_TEXCOORD_ATTRIBUTE{1}; static constexpr uint PROGRAM_TEXCOORD_ATTRIBUTE{1};
// VAAPI stuff
VADisplay m_VADisplay{nullptr};
AVVAAPIDeviceContext *m_pVAContext{nullptr};
EGLDisplay m_EGLDisplay{nullptr};
EGLSurface m_EGLSurface{nullptr};
EGLContext m_EGLContext{nullptr};
EGLImage m_EGLImages[2]{};
GLuint m_textures[2]{};
friend class OpenGLRenderer; friend class OpenGLRenderer;
}; };
} }
......
...@@ -16,7 +16,7 @@ add_executable(Player main.cpp) ...@@ -16,7 +16,7 @@ add_executable(Player main.cpp)
target_link_libraries(Player Qt5::Core Qt5::Gui Qt5::Concurrent Qt5::Widgets Qt5::OpenGL avformat avfilter avutil avcodec avdevice swscale swresample AVQt) target_link_libraries(Player Qt5::Core Qt5::Gui Qt5::Concurrent Qt5::Widgets Qt5::OpenGL avformat avfilter avutil avcodec avdevice swscale swresample AVQt)
if (LINUX) if (LINUX)
target_link_libraries(Player openal GL) target_link_libraries(Player openal GL EGL GLU)
elseif (WIN32) elseif (WIN32)
target_link_libraries(Player OpenAL32 opengl32) target_link_libraries(Player OpenAL32 opengl32)
endif () endif ()
\ No newline at end of file
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
constexpr auto LOGFILE_LOCATION = "libAVQt.log"; constexpr auto LOGFILE_LOCATION = "libAVQt.log";
QApplication *app = nullptr; QApplication *app = nullptr;
std::chrono::time_point<std::chrono::system_clock> start; std::chrono::time_point<std::chrono::system_clock> start; // NOLINT(cert-err58-cpp)
void signalHandler(int sigNum) { void signalHandler(int sigNum) {
Q_UNUSED(sigNum) Q_UNUSED(sigNum)
...@@ -40,6 +40,7 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt ...@@ -40,6 +40,7 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);
app = new QApplication(argc, argv); app = new QApplication(argc, argv);
signal(SIGINT, &signalHandler); signal(SIGINT, &signalHandler);
signal(SIGTERM, &signalHandler); signal(SIGTERM, &signalHandler);
...@@ -82,7 +83,7 @@ int main(int argc, char *argv[]) { ...@@ -82,7 +83,7 @@ int main(int argc, char *argv[]) {
AVQt::OpenGLRenderer renderer; AVQt::OpenGLRenderer renderer;
demuxer.registerCallback(videoDecoder, AVQt::IPacketSource::CB_VIDEO); demuxer.registerCallback(videoDecoder, AVQt::IPacketSource::CB_VIDEO);
videoDecoder->registerCallback(videoEncoder); // videoDecoder->registerCallback(videoEncoder);
QFile outputFile("output.mp4"); QFile outputFile("output.mp4");
outputFile.open(QIODevice::ReadWrite | QIODevice::Truncate); outputFile.open(QIODevice::ReadWrite | QIODevice::Truncate);
...@@ -109,7 +110,7 @@ int main(int argc, char *argv[]) { ...@@ -109,7 +110,7 @@ int main(int argc, char *argv[]) {
QObject::connect(app, &QApplication::aboutToQuit, [&] { QObject::connect(app, &QApplication::aboutToQuit, [&] {
demuxer.deinit(); demuxer.deinit();
// delete videoEncoder; delete videoEncoder;
delete videoDecoder; delete videoDecoder;
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment