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 | |
4 | #include "qffmpegthread_p.h" |
5 | |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | using namespace QFFmpeg; |
10 | |
11 | void ConsumerThread::stopAndDelete() |
12 | { |
13 | { |
14 | QMutexLocker locker(&m_loopDataMutex); |
15 | m_exit = true; |
16 | } |
17 | dataReady(); |
18 | wait(); |
19 | delete this; |
20 | } |
21 | |
22 | void ConsumerThread::dataReady() |
23 | { |
24 | m_condition.wakeAll(); |
25 | } |
26 | |
27 | void ConsumerThread::run() |
28 | { |
29 | if (!init()) |
30 | return; |
31 | |
32 | while (true) { |
33 | |
34 | { |
35 | QMutexLocker locker(&m_loopDataMutex); |
36 | while (!hasData() && !m_exit) |
37 | m_condition.wait(lockedMutex: &m_loopDataMutex); |
38 | |
39 | if (m_exit) |
40 | break; |
41 | } |
42 | |
43 | processOne(); |
44 | } |
45 | |
46 | cleanup(); |
47 | } |
48 | |
49 | QMutexLocker<QMutex> ConsumerThread::lockLoopData() const |
50 | { |
51 | return QMutexLocker(&m_loopDataMutex); |
52 | } |
53 | |
54 | QT_END_NAMESPACE |
55 |