feat: add wallpaper transitions, store crop in database per-wallpaper, move CUDA context creation to async thread

This commit is contained in:
2026-10-29 17:44:19 +01:00
parent 906b15b092
commit 3792e9d73f
26 changed files with 2338 additions and 210 deletions
+31 -11
View File
@@ -184,9 +184,13 @@ void VideoPlayer::closeDecoder() {
m_streamIndex = -1;
}
void VideoPlayer::decodeLoop(const QString& path) {
void VideoPlayer::decodeLoop(const QString& path, uint32_t generation) {
if (!m_threadRunning.load(std::memory_order_acquire) ||
m_generation.load(std::memory_order_acquire) != generation)
return;
if (!openDecoder(path)) {
m_threadRunning = false;
m_threadRunning.store(false);
return;
}
@@ -198,13 +202,14 @@ void VideoPlayer::decodeLoop(const QString& path) {
AVFrame* frame = av_frame_alloc();
if (!frame) {
m_threadRunning = false;
m_threadRunning.store(false);
return;
}
AVPacket pkt{};
while (m_threadRunning) {
while (m_threadRunning.load(std::memory_order_acquire) &&
m_generation.load(std::memory_order_acquire) == generation) {
int ret = av_read_frame(m_fmt, &pkt);
if (ret == AVERROR_EOF) {
if (avformat_seek_file(
@@ -230,7 +235,9 @@ void VideoPlayer::decodeLoop(const QString& path) {
}
av_packet_unref(&pkt);
while (m_threadRunning && avcodec_receive_frame(m_codec, frame) == 0) {
while (m_threadRunning.load(std::memory_order_acquire) &&
m_generation.load(std::memory_order_acquire) == generation &&
avcodec_receive_frame(m_codec, frame) == 0) {
bool wasEmpty = false;
{
std::lock_guard<std::mutex> lock(m_mtx);
@@ -251,21 +258,34 @@ void VideoPlayer::decodeLoop(const QString& path) {
av_frame_free(&frame);
closeDecoder();
m_threadRunning = false;
m_threadRunning.store(false);
}
bool VideoPlayer::start(const QString& path) {
stop();
const uint32_t generation =
m_generation.fetch_add(1, std::memory_order_acq_rel) + 1;
m_threadRunning.store(true);
if (!ensureCudaContext()) return false;
std::thread previous = std::move(m_thread);
m_thread = std::thread(
[this, path, generation, previous = std::move(previous)]() mutable {
if (previous.joinable()) previous.join();
closeDecoder();
if (!ensureCudaContext()) {
m_threadRunning.store(false);
return;
}
decodeLoop(path, generation);
});
m_threadRunning = true;
m_thread = std::thread([this, path]() { decodeLoop(path); });
return true;
}
void VideoPlayer::stop() {
m_threadRunning = false;
m_generation.fetch_add(1, std::memory_order_acq_rel);
m_threadRunning.store(false);
if (m_thread.joinable()) m_thread.join();
closeDecoder();