summaryrefslogtreecommitdiffstats
path: root/src/plugins/multimedia/ffmpeg/qffmpegthread_p.h
blob: a7c5b09274f849b46c132f12b8ecece871da2a77 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QFFMPEGTHREAD_P_H
#define QFFMPEGTHREAD_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <private/qtmultimediaglobal_p.h>

#include <qmutex.h>
#include <qwaitcondition.h>
#include <qthread.h>

QT_BEGIN_NAMESPACE

class QAudioSink;

namespace QFFmpeg
{

/*!
    FFmpeg thread that is used to implement a consumer pattern.

    This thread processes work items until no more data is available.
    When no more data is available, it sleeps until it is notified about
    more available data.
 */
class ConsumerThread : public QThread
{
public:
    /*!
        Stops the thread and deletes this object
     */
    void stopAndDelete();

protected:

    /*!
        Called on this thread when thread starts
     */
    virtual void init() = 0;

    /*!
        Called on this thread before thread exits
     */
    virtual void cleanup() = 0;

    /*!
        Process one work item. Called repeatedly until hasData() returns
        false, in which case the thread sleeps until the next dataReady()
        notification.

        Note: processOne() should never block.
     */
    virtual void processOne() = 0;

    /*!
        Wake thread from sleep and process data until
        hasData() returns false. The method is supposed to be invoked
        right after the scope of QMutexLocker that lockLoopData returns.
    */
    void dataReady();

    /*!
        Must return true when data is available for processing
     */
    virtual bool hasData() const = 0;

    /*!
        Locks the loop data mutex. It must be used to protect loop data
        like a queue of video frames.
     */
    QMutexLocker<QMutex> lockLoopData() const;

private:
    void run() final;

    mutable QMutex m_loopDataMutex;
    QWaitCondition m_condition;
    bool m_exit = false;
};

}

QT_END_NAMESPACE

#endif