feat: skip two-way copy for cuda devices when decoding video wallpapers + cache wallpapers as blobs in new database
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include <cuda.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/buffer.h>
|
||||
#include <libavutil/frame.h>
|
||||
#include <libavutil/hwcontext.h>
|
||||
#include <libavutil/hwcontext_cuda.h>
|
||||
#include <libavutil/pixfmt.h>
|
||||
#include <libavutil/pixdesc.h>
|
||||
}
|
||||
|
||||
class VideoPlayer {
|
||||
public:
|
||||
explicit VideoPlayer(EGLDisplay display);
|
||||
~VideoPlayer();
|
||||
|
||||
void setReadyCallback(std::function<void()> callback);
|
||||
void setFrameCallback(std::function<void()> callback);
|
||||
|
||||
bool start(const QString& path);
|
||||
void stop();
|
||||
|
||||
|
||||
bool importCurrentFrame();
|
||||
|
||||
void deleteTexture();
|
||||
|
||||
[[nodiscard]] uint32_t textureId() const { return m_texY; }
|
||||
[[nodiscard]] uint32_t chromaTextureId() const { return m_texUV; }
|
||||
[[nodiscard]] int colorMatrix() const { return m_matrix; }
|
||||
[[nodiscard]] int colorRange() const { return m_range; }
|
||||
[[nodiscard]] QSize frameSize() const;
|
||||
|
||||
private:
|
||||
void decodeLoop(const QString& path);
|
||||
bool openDecoder(const QString& path);
|
||||
void closeDecoder();
|
||||
|
||||
bool ensureTextures(unsigned w, unsigned h, int compBytes);
|
||||
|
||||
bool ensureCudaContext();
|
||||
|
||||
EGLDisplay m_eglDisplay;
|
||||
std::function<void()> m_readyCb;
|
||||
std::function<void()> m_frameCb;
|
||||
|
||||
std::thread m_thread;
|
||||
std::atomic<bool> m_threadRunning{false};
|
||||
|
||||
mutable std::mutex m_mtx;
|
||||
AVFrame* m_pending = nullptr;
|
||||
bool m_haveFrame = false;
|
||||
|
||||
AVFrame* m_displayed = nullptr;
|
||||
|
||||
AVFormatContext* m_fmt = nullptr;
|
||||
AVCodecContext* m_codec = nullptr;
|
||||
AVBufferRef* m_hwDeviceCtx = nullptr;
|
||||
int m_streamIndex = -1;
|
||||
|
||||
CUcontext m_cuCtx = nullptr;
|
||||
CUgraphicsResource m_resY = nullptr;
|
||||
CUgraphicsResource m_resUV = nullptr;
|
||||
QSize m_texSize;
|
||||
|
||||
uint32_t m_texY = 0;
|
||||
uint32_t m_texUV = 0;
|
||||
|
||||
int m_matrix = 1;
|
||||
int m_range = 0;
|
||||
int m_texComp = 1;
|
||||
QSize m_size;
|
||||
};
|
||||
Reference in New Issue
Block a user