forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AVThread.h
121 lines (98 loc) · 3.76 KB
/
AVThread.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#ifndef QTAV_AVTHREAD_H
#define QTAV_AVTHREAD_H
#include <QtCore/QRunnable>
#include <QtCore/QScopedPointer>
#include <QtCore/QThread>
#include "PacketBuffer.h"
//TODO: pause functions. AVOutput may be null, use AVThread's pause state
namespace QtAV {
class AVDecoder;
class AVThreadPrivate;
class AVOutput;
class AVClock;
class Filter;
class Statistics;
class OutputSet;
class AVThread : public QThread
{
Q_OBJECT
DPTR_DECLARE_PRIVATE(AVThread)
public:
explicit AVThread(QObject *parent = 0);
virtual ~AVThread();
//used for changing some components when running
Q_DECL_DEPRECATED void lock();
Q_DECL_DEPRECATED void unlock();
void setClock(AVClock *clock);
AVClock* clock() const;
PacketBuffer* packetQueue() const;
void setDecoder(AVDecoder *decoder);
AVDecoder *decoder() const;
void setOutput(AVOutput *out); //Q_DECL_DEPRECATED
AVOutput* output() const; //Q_DECL_DEPRECATED
void setOutputSet(OutputSet *set);
OutputSet* outputSet() const;
void setDemuxEnded(bool ended);
bool isPaused() const;
bool waitForStarted(int msec = -1);
bool installFilter(Filter *filter, int index = 0x7FFFFFFF, bool lock = true);
bool uninstallFilter(Filter *filter, bool lock = true);
const QList<Filter *> &filters() const;
// TODO: resample, resize task etc.
void scheduleTask(QRunnable *task);
void requestSeek();
void scheduleFrameDrop(bool value = true);
qreal previousHistoryPts() const; //move to statistics?
qreal decodeFrameRate() const; //move to statistics?
void setDropFrameOnSeek(bool value);
void resetState();
public slots:
virtual void stop();
/*change pause state. the pause/continue action will do in the next loop*/
void pause(bool p); //processEvents when waiting?
void nextAndPause(); //process 1 frame and pause
Q_SIGNALS:
void frameDelivered();
/*!
* \brief seekFinished
* \param timestamp the frame pts after seek
*/
void seekFinished(qint64 timestamp);
void eofDecoded();
private Q_SLOTS:
void onStarted();
void onFinished();
protected:
AVThread(AVThreadPrivate& d, QObject *parent = 0);
/*
* If the pause state is true setted by pause(true), then block the thread and wait for pause state changed, i.e. pause(false)
* and return true. Otherwise, return false immediatly.
*/
// has timeout so that the pending tasks can be processed
bool tryPause(unsigned long timeout = 100);
bool processNextTask(); //in AVThread
// pts > 0: compare pts and clock when waiting
void waitAndCheck(ulong value, qreal pts);
DPTR_DECLARE(AVThread)
private:
void setStatistics(Statistics* statistics);
friend class AVPlayer;
};
}
#endif // QTAV_AVTHREAD_H