Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qffmpegthread_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QFFMPEGTHREAD_P_H
4#define QFFMPEGTHREAD_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtMultimedia/private/qtmultimediaglobal_p.h>
18
19#include <qmutex.h>
20#include <qwaitcondition.h>
21#include <qthread.h>
22
24
25class QAudioSink;
26
27namespace QFFmpeg
28{
29
30/*!
31 FFmpeg thread that is used to implement a consumer pattern.
32
33 This thread processes work items until no more data is available.
34 When no more data is available, it sleeps until it is notified about
35 more available data.
36 */
37class ConsumerThread : public QThread
38{
39public:
40 struct Deleter
41 {
42 void operator()(ConsumerThread *thread) const { thread->stopAndDelete(); }
43 };
44
45protected:
46 /*!
47 Stops the thread and deletes this object
48 */
49 void stopAndDelete();
50
51 /*!
52 Called on this thread when thread starts
53 */
54 virtual bool init() = 0;
55
56 /*!
57 Called on this thread before thread exits
58 */
59 virtual void cleanup() = 0;
60
61 /*!
62 Process one work item. Called repeatedly until hasData() returns
63 false, in which case the thread sleeps until the next dataReady()
64 notification.
65
66 Note: processOne() should never block.
67 */
68 virtual void processOne() = 0;
69
70 /*!
71 Wake thread from sleep and process data until
72 hasData() returns false. The method is supposed to be invoked
73 right after the scope of QMutexLocker that lockLoopData returns.
74 */
75 void dataReady();
76
77 /*!
78 Must return true when data is available for processing
79 */
80 virtual bool hasData() const = 0;
81
82 /*!
83 Locks the loop data mutex. It must be used to protect loop data
84 like a queue of video frames.
85 */
86 QMutexLocker<QMutex> lockLoopData() const;
87
88private:
89 void run() final;
90
91 mutable QMutex m_loopDataMutex;
92 QWaitCondition m_condition;
93 bool m_exit = false;
94};
95
96template <typename T>
97using ConsumerThreadUPtr = std::unique_ptr<T, ConsumerThread::Deleter>;
98} // namespace QFFmpeg
99
100QT_END_NAMESPACE
101
102#endif
FFmpeg thread that is used to implement a consumer pattern.
virtual bool init()=0
Called on this thread when thread starts.
virtual bool hasData() const =0
Must return true when data is available for processing.
void stopAndDelete()
Stops the thread and deletes this object.
QMutexLocker< QMutex > lockLoopData() const
Locks the loop data mutex.
void dataReady()
Wake thread from sleep and process data until hasData() returns false.
virtual void cleanup()=0
Called on this thread before thread exits.
virtual void processOne()=0
Process one work item.
\inmodule QtCore
Definition qmutex.h:332
Combined button and popup list for selecting options.
void operator()(ConsumerThread *thread) const