mirror of
https://github.com/iDescriptor/iDescriptor.git
synced 2026-06-21 19:35:49 +08:00
update singleton logic and disable thumbnail for videos for now
This commit is contained in:
@@ -3,28 +3,17 @@
|
||||
#include <QDebug>
|
||||
#include <QMutexLocker>
|
||||
|
||||
// TODO: update singleton implementation
|
||||
// Static member definitions
|
||||
MediaStreamerManager *MediaStreamerManager::s_instance = nullptr;
|
||||
QMutex MediaStreamerManager::s_instanceMutex;
|
||||
|
||||
MediaStreamerManager::MediaStreamerManager(QObject *parent) : QObject(parent) {}
|
||||
|
||||
MediaStreamerManager::~MediaStreamerManager() { cleanup(); }
|
||||
|
||||
MediaStreamerManager *MediaStreamerManager::sharedInstance()
|
||||
{
|
||||
QMutexLocker locker(&s_instanceMutex);
|
||||
if (!s_instance) {
|
||||
s_instance = new MediaStreamerManager();
|
||||
}
|
||||
return s_instance;
|
||||
static MediaStreamerManager instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
QUrl MediaStreamerManager::getStreamUrl(iDescriptorDevice *device,
|
||||
const QString &filePath)
|
||||
{
|
||||
QMutexLocker locker(&m_streamersMutex);
|
||||
|
||||
// Check if we already have a streamer for this file
|
||||
auto it = m_streamers.find(filePath);
|
||||
@@ -74,7 +63,6 @@ QUrl MediaStreamerManager::getStreamUrl(iDescriptorDevice *device,
|
||||
|
||||
void MediaStreamerManager::releaseStreamer(const QString &filePath)
|
||||
{
|
||||
QMutexLocker locker(&m_streamersMutex);
|
||||
|
||||
auto it = m_streamers.find(filePath);
|
||||
if (it != m_streamers.end()) {
|
||||
@@ -93,7 +81,6 @@ void MediaStreamerManager::releaseStreamer(const QString &filePath)
|
||||
|
||||
void MediaStreamerManager::cleanup()
|
||||
{
|
||||
QMutexLocker locker(&m_streamersMutex);
|
||||
|
||||
auto it = m_streamers.begin();
|
||||
while (it != m_streamers.end()) {
|
||||
@@ -112,8 +99,6 @@ void MediaStreamerManager::cleanup()
|
||||
|
||||
void MediaStreamerManager::onStreamerDestroyed()
|
||||
{
|
||||
QMutexLocker locker(&m_streamersMutex);
|
||||
|
||||
// Find and remove the destroyed streamer
|
||||
auto it = m_streamers.begin();
|
||||
while (it != m_streamers.end()) {
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
#define MEDIASTREAMERMANAGER_H
|
||||
|
||||
#include "iDescriptor.h"
|
||||
#include "mediastreamer.h"
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
class MediaStreamer;
|
||||
|
||||
/**
|
||||
* @brief Singleton manager for MediaStreamer instances
|
||||
*
|
||||
@@ -47,13 +46,8 @@ public:
|
||||
void cleanup();
|
||||
|
||||
private:
|
||||
explicit MediaStreamerManager(QObject *parent = nullptr);
|
||||
~MediaStreamerManager();
|
||||
|
||||
// Disable copy constructor and assignment operator
|
||||
MediaStreamerManager(const MediaStreamerManager &) = delete;
|
||||
MediaStreamerManager &operator=(const MediaStreamerManager &) = delete;
|
||||
|
||||
private slots:
|
||||
void onStreamerDestroyed();
|
||||
|
||||
|
||||
+22
-21
@@ -277,29 +277,30 @@ void PhotoModel::requestThumbnail(int index)
|
||||
// Load video thumbnail asynchronously
|
||||
future = QtConcurrent::run([=]() {
|
||||
// Check disk cache first
|
||||
if (QFile::exists(cachePath)) {
|
||||
QPixmap cached(cachePath);
|
||||
if (!cached.isNull() && cached.size() == m_thumbnailSize) {
|
||||
qDebug() << "Video disk cache HIT for:"
|
||||
<< QFileInfo(info.filePath).fileName();
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
// if (QFile::exists(cachePath)) {
|
||||
// QPixmap cached(cachePath);
|
||||
// if (!cached.isNull() && cached.size() == m_thumbnailSize) {
|
||||
// qDebug() << "Video disk cache HIT for:"
|
||||
// << QFileInfo(info.filePath).fileName();
|
||||
// return cached;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Generate video thumbnail
|
||||
QPixmap thumbnail = generateVideoThumbnail(m_device, info.filePath,
|
||||
m_thumbnailSize);
|
||||
// // Generate video thumbnail
|
||||
// QPixmap thumbnail = generateVideoThumbnail(m_device,
|
||||
// info.filePath,
|
||||
// m_thumbnailSize);
|
||||
|
||||
// Save to disk cache if successful
|
||||
if (!thumbnail.isNull()) {
|
||||
QDir().mkpath(QFileInfo(cachePath).absolutePath());
|
||||
if (thumbnail.save(cachePath, "JPG", 85)) {
|
||||
qDebug() << "Saved video thumbnail to disk cache:"
|
||||
<< QFileInfo(info.filePath).fileName();
|
||||
}
|
||||
}
|
||||
|
||||
return thumbnail;
|
||||
// // Save to disk cache if successful
|
||||
// if (!thumbnail.isNull()) {
|
||||
// QDir().mkpath(QFileInfo(cachePath).absolutePath());
|
||||
// if (thumbnail.save(cachePath, "JPG", 85)) {
|
||||
// qDebug() << "Saved video thumbnail to disk cache:"
|
||||
// << QFileInfo(info.filePath).fileName();
|
||||
// }
|
||||
// }
|
||||
return QIcon::fromTheme("video-x-generic").pixmap(m_thumbnailSize);
|
||||
// return thumbnail;
|
||||
});
|
||||
} else {
|
||||
// Load image thumbnail asynchronously (existing logic)
|
||||
|
||||
Reference in New Issue
Block a user