-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCoverArtCache.h
74 lines (59 loc) · 2.05 KB
/
CoverArtCache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef COVERARTCACHE_H
#define COVERARTCACHE_H
#include <QImage>
#include <QHash>
#include <QFutureWatcher>
#include <CoverArtBackend.h>
#include <deadbeef/deadbeef.h>
#define COVERARTCACHE_P(X) (static_cast<CoverArtCache *>(X))
typedef struct coverSearch_s {
QString path;
QSize size;
} coverSearch;
class CoverArtCache : public QObject {
Q_OBJECT
public:
CoverArtCache(QObject *parent = nullptr, DB_functions_t *funcs = nullptr);
~CoverArtCache();
// check if track already cached (full size or specific size)
bool isCoverArtAvailable(DB_playItem_t *it, QSize size = QSize());
// QFuture pointer for cover loading
QFuture<QImage *> requestCoverArt(DB_playItem_t *, QSize size);
// load cached cover art
QImage * getCoverArt(DB_playItem_t *, QSize size = QSize());
// get coverart path
QString getCoverArtPath(DB_playItem_t *it);
// get default cover art
QImage * getCoverArtDefault();
// backend, either CoverArtLegacy or CoverArtNew (artwork2)
CoverArtBackend *backend = nullptr;
QImage *default_image = nullptr;
// functions to be called from thread
void cacheCoverArt(coverSearch, QImage *img);
void cachePath(ddb_playItem_t *it, QString);
// cache ref/unref
void cacheRef(QImage *img);
void cacheUnref(QImage *img, bool force_unref = false);
void cacheUnrefTrack(DB_playItem_t *it);
static coverSearch coverSearchValue(QString path, QSize size = QSize()) {
coverSearch s;
s.path = path;
s. size = size;
return s;
}
protected:
// Threaded static functions
static QImage *cover_art_load(CoverArtCache *, DB_playItem_t *, QSize size);
static QImage *cover_art(QImage *cover);
// Hashed covers (path and size links to QImage)
QHash<coverSearch, QImage *> cache;
// a playitem links to path
QHash<ddb_playItem_t *, QString> cache_path;
// QImage links to refc
QHash<QImage *, int> cache_refc;
// mutex
QMutex cmut_refc;
QMutex cmut_cache;
QMutex cmut_path;
};
#endif // COVERARTCACHE_H