summaryrefslogtreecommitdiffstats
path: root/framecache.h
blob: 867eda75f6e3da10a67ade0421ad0885bb9fd063 (plain)
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
/*
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version
  2 of the License, or (at your option) any later version.
*/

#ifndef FRAMECACHE_H
#define FRAMECACHE_H

#include <QThread>
#include <QPair>
#include <QHash>
#include <QPair>
#include <QQueue>
#include <QString>

class QSemaphore;
class QMutex;
class FrameCacheGenerator;

class FrameCache : public QObject {
    Q_OBJECT
    public:
        explicit FrameCache(QObject *parent = 0);
        ~FrameCache();
        const QPixmap entry(const QString &sourcePath, const QString &when = QString());
        const QString entryPath(const QString &sourcePath, const QString &when);

    public slots:
        void rebuild();

    private:
        QHash<QPair<QString, QString>, QString> *mFrameCache;
        QQueue<QPair<QString, QString> > *mDataQueue;
        QString mCacheFile;
        qint32 mMagic;
        QSemaphore *mSemFree;
        QSemaphore *mSemUsed;
        QMutex *mCacheMx;
        FrameCacheGenerator *mGenerator;
        QString mWhen;
};

class FrameCacheGenerator : public QThread {
    Q_OBJECT
    public:
        explicit FrameCacheGenerator(QObject *parent = 0);
        void init(QSemaphore *set, QSemaphore *get, QMutex *cachemx, QQueue<QPair<QString, QString> > *data, QHash<QPair<QString, QString>, QString> *cache);
        const QString cacheFile() const { return mCacheFile; }
        const QString cacheDir() const { return mCacheDir; }
        void readConfig();

    public slots:
        void run();

    private:
        bool grabFrame(const QString &sourceFile, QString when);
        QSemaphore *mSemFree;
        QSemaphore *mSemUsed;
        QMutex *mCacheMx;
        QQueue<QPair<QString, QString> > *mDataQueue;
        QHash<QPair<QString, QString>, QString> *mFrameCache;
        QString mCacheDir;
        QString mCacheFile;
        QString mFfMpegPath;
        const QString mCacheSubDir;
        const QString mCacheFileName;

};

#endif // FRAMECACHE_H