1+ /* This file is part of YUView - The YUV player with advanced analytics toolset
2+ * <https://github.com/IENT/YUView>
3+ * Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * In addition, as a special exception, the copyright holders give
11+ * permission to link the code of portions of this program with the
12+ * OpenSSL library under certain conditions as described in each
13+ * individual source file, and distribute linked combinations including
14+ * the two.
15+ *
16+ * You must obey the GNU General Public License in all respects for all
17+ * of the code used other than OpenSSL. If you modify file(s) with this
18+ * exception, you may extend this exception to your version of the
19+ * file(s), but you are not obligated to do so. If you do not wish to do
20+ * so, delete this exception statement from your version. If you delete
21+ * this exception statement from all source files in the program, then
22+ * also delete it here.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ */
32+
33+ #include " LoadingWorker.h"
34+
35+ namespace video
36+ {
37+
38+ #define LOADINGWORKER_DEBUG_LOADING 0
39+ #if LOADINGWORKER_DEBUG_LOADING && !NDEBUG
40+ #define DEBUG_WORKER qDebug
41+ #else
42+ #define DEBUG_WORKER (fmt, ...) ((void )0 )
43+ #endif
44+
45+ LoadingWorker::LoadingWorker (QObject *parent) : QObject(parent)
46+ {
47+ static int idCounter = 0 ;
48+ id = idCounter++;
49+ }
50+
51+ QString LoadingWorker::getStatus ()
52+ {
53+ return QString (" T%1: %2" ).arg (id).arg (this ->working ? QString::number (this ->currentFrame )
54+ : QString (" -" ));
55+ }
56+
57+ void LoadingWorker::setJob (playlistItem *item, int frame, bool test)
58+ {
59+ Q_ASSERT_X (item != nullptr , Q_FUNC_INFO, " Given item is nullptr" );
60+ Q_ASSERT_X (
61+ frame >= 0 || !item->properties ().isIndexedByFrame (), Q_FUNC_INFO, " Given frame index invalid" );
62+ this ->currentCacheItem = item;
63+ this ->currentFrame = frame;
64+ this ->testMode = test;
65+ }
66+
67+ void LoadingWorker::processCacheJob ()
68+ {
69+ DEBUG_WORKER (" LoadingWorker::processCacheJob invoke processCacheJobInternal" );
70+ QMetaObject::invokeMethod (this , " processCacheJobInternal" );
71+ }
72+
73+ void LoadingWorker::processLoadingJob (bool playing, bool loadRawData)
74+ {
75+ DEBUG_WORKER (" LoadingWorker::processLoadingJob invoke processLoadingJobInternal" );
76+ QMetaObject::invokeMethod (
77+ this , " processLoadingJobInternal" , Q_ARG (bool , playing), Q_ARG (bool , loadRawData));
78+ }
79+
80+ void LoadingWorker::processCacheJobInternal ()
81+ {
82+ Q_ASSERT_X (this ->currentCacheItem != nullptr , Q_FUNC_INFO, " Invalid Job - Item is nullptr" );
83+ Q_ASSERT_X (this ->currentFrame >= 0 || !this ->currentCacheItem ->properties ().isIndexedByFrame (),
84+ Q_FUNC_INFO,
85+ " Given frame index invalid" );
86+ DEBUG_WORKER (" LoadingWorker::processCacheJobInternal" );
87+
88+ // Just cache the frame that was given to us.
89+ // This is performed in the thread that this worker is currently placed in.
90+ this ->currentCacheItem ->cacheFrame (currentFrame, testMode);
91+
92+ this ->currentCacheItem = nullptr ;
93+ DEBUG_WORKER (" LoadingWorker::processCacheJobInternal emit loadingFinished" );
94+ emit loadingFinished ();
95+ }
96+
97+ void LoadingWorker::processLoadingJobInternal (bool playing, bool loadRawData)
98+ {
99+ Q_ASSERT_X (this ->currentCacheItem != nullptr , Q_FUNC_INFO, " The set job is nullptr" );
100+ Q_ASSERT_X ((!this ->currentCacheItem ->properties ().isIndexedByFrame () || currentFrame >= 0 ),
101+ Q_FUNC_INFO,
102+ " The set frame index is invalid" );
103+ Q_ASSERT_X (!this ->currentCacheItem ->taggedForDeletion (),
104+ Q_FUNC_INFO,
105+ " The set job was tagged for deletion" );
106+ DEBUG_WORKER (Q_FUNC_INFO);
107+
108+ // Load the frame of the item that was given to us.
109+ // This is performed in the thread (the loading thread with higher priority.
110+ this ->currentCacheItem ->loadFrame (currentFrame, playing, loadRawData);
111+
112+ this ->currentCacheItem = nullptr ;
113+ emit loadingFinished ();
114+ DEBUG_WORKER (" LoadingWorker::processLoadingJobInternal emit loadingFinished" );
115+ }
116+
117+ } // namespace video
0 commit comments