]> git.sesse.net Git - kdenlive/blob - src/kthumb.h
Fix audio thumbs runtime warning
[kdenlive] / src / kthumb.h
1 /***************************************************************************
2                          kthumb.h  -  description
3                             -------------------
4    begin                : Fri Nov 22 2002
5    copyright            : (C) 2002 by Jason Wood
6    email                : jasonwood@blueyonder.co.uk
7 ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #ifndef KTHUMB_H
19 #define KTHUMB_H
20
21 #include <QPixmap>
22 #include <QFile>
23 #include <QDomElement>
24 #include <QFuture>
25
26 #include <KUrl>
27 #include <kdeversion.h>
28
29 #include <mlt++/Mlt.h>
30
31
32 /**KRender encapsulates the client side of the interface to a renderer.
33 From Kdenlive's point of view, you treat the KRender object as the
34 renderer, and simply use it as if it was local. Calls are asyncrhonous -
35 you send a call out, and then receive the return value through the
36 relevant signal that get's emitted once the call completes.
37   *@author Jason Wood
38   */
39
40
41 namespace Mlt
42 {
43 class Miracle;
44 class Consumer;
45 class Producer;
46 class Frame;
47 class Profile;
48 };
49
50 class ClipManager;
51
52 typedef QMap <int, QMap <int, QByteArray> > audioByteArray;
53
54 class KThumb: public QObject
55 {
56 Q_OBJECT public:
57
58
59     KThumb(ClipManager *clipManager, KUrl url, const QString &id, const QString &hash, QObject * parent = 0, const char *name = 0);
60     ~KThumb();
61     void setProducer(Mlt::Producer *producer);
62     void askForAudioThumbs(const QString &id);
63     bool hasProducer() const;
64     void clearProducer();
65     void updateThumbUrl(const QString &hash);
66     void extractImage(int frame, int frame2);
67     QPixmap extractImage(int frame, int width, int height);
68 #if KDE_IS_VERSION(4,5,0)
69     /** @brief Request thumbnails for the frame range. */
70     void queryIntraThumbs(QList <int> missingFrames);
71     /** @brief Query cached thumbnail. */
72     QImage findCachedThumb(const QString path);
73 #endif
74
75 public slots:
76     void updateClipUrl(KUrl url, const QString &hash);
77     static QPixmap getImage(KUrl url, int width, int height);
78 //    static QPixmap getImage(QDomElement xml, int frame, int width, int height);
79     /* void getImage(KUrl url, int frame, int width, int height);
80      void getThumbs(KUrl url, int startframe, int endframe, int width, int height);*/
81     void stopAudioThumbs();
82     void removeAudioThumb();
83     void getAudioThumbs(int channel, double frame, double frameLength, int arrayWidth);
84     static QPixmap getImage(KUrl url, int frame, int width, int height);
85     static QImage getFrame(Mlt::Producer *producer, int framepos, int frameWidth, int displayWidth, int height);
86     static QImage getFrame(Mlt::Frame *frame, int frameWidth, int displayWidth, int height);
87     /** @brief Calculates image variance, useful to know if a thumbnail is interesting. 
88      *  @return an integer between 0 and 100. 0 means no variance, eg. black image while bigger values mean contrasted image
89      * */
90     static uint imageVariance(QImage image);
91
92 private slots:
93     void slotAudioThumbOver();
94     void slotCreateAudioThumbs();
95 #if KDE_IS_VERSION(4,5,0)
96     /** @brief Fetch all requested frames. */ 
97     void slotGetIntraThumbs();
98 #endif
99
100 private:
101     QFuture<void> m_audioThumbProducer;
102     KUrl m_url;
103     QString m_thumbFile;
104     double m_dar;
105     double m_ratio;
106     Mlt::Producer *m_producer;
107     ClipManager *m_clipManager;
108     QString m_id;
109     QList <int> m_requestedThumbs;
110     /** @brief Controls the thumbnails process. */
111     QFuture<void> m_future;
112     /** @brief Controls the intra frames thumbnails process (cached thumbnails). */
113     QFuture<void> m_intra;
114     QFile m_audioThumbFile;
115     bool m_stopAudioThumbs;
116     double m_frame;
117     double m_frameLength;
118     int m_frequency;
119     int m_channels;
120     int m_arrayWidth;
121     /** @brief List of frame numbers from which we want to extract thumbnails. */
122     QList <int> m_intraFramesQueue;
123     QMutex m_mutex;
124     void doGetThumbs();
125
126 signals:
127     void thumbReady(int, QImage);
128     void mainThumbReady(const QString &, QPixmap);
129     void audioThumbReady(const audioByteArray&);
130     /** @brief We have finished caching all requested thumbs. */
131     void thumbsCached();
132 };
133
134 #endif