-
Notifications
You must be signed in to change notification settings - Fork 417
Expand file tree
/
Copy pathdecoderBase.cpp
More file actions
182 lines (160 loc) · 6.59 KB
/
decoderBase.cpp
File metadata and controls
182 lines (160 loc) · 6.59 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "decoderBase.h"
#include <QCoreApplication>
#include <QDir>
#include <QSettings>
namespace decoder
{
// Debug the decoder ( 0:off 1:interactive decoder only 2:caching decoder only 3:both)
#define DECODERBASE_DEBUG_OUTPUT 0
#if DECODERBASE_DEBUG_OUTPUT && !NDEBUG
#include <QDebug>
#if DECODERBASE_DEBUG_OUTPUT == 1
#define DEBUG_HEVCDECODERBASE \
if (!isCachingDecoder) \
qDebug
#elif DECODERBASE_DEBUG_OUTPUT == 2
#define DEBUG_HEVCDECODERBASE \
if (isCachingDecoder) \
qDebug
#elif DECODERBASE_DEBUG_OUTPUT == 3
#define DEBUG_HEVCDECODERBASE \
if (isCachingDecoder) \
qDebug("c:"); \
else \
qDebug("i:"); \
qDebug
#endif
#else
#define DEBUG_DECODERBASE(fmt, ...) ((void)0)
#endif
decoderBase::decoderBase(bool cachingDecoder)
{
DEBUG_DECODERBASE("decoderBase::decoderBase create base%s", cachingDecoder ? " - caching" : "");
isCachingDecoder = cachingDecoder;
resetDecoder();
}
void decoderBase::resetDecoder()
{
DEBUG_DECODERBASE("decoderBase::resetDecoder");
this->decoderState = DecoderState::NeedsMoreData;
}
bool decoderBase::isSignalDifference(int signalID) const
{
Q_UNUSED(signalID);
return false;
}
void decoderBase::setDecodeSignal(int signalID, bool &decoderResetNeeded)
{
if (signalID >= 0 && signalID < nrSignalsSupported())
this->decodeSignal = signalID;
decoderResetNeeded = false;
}
stats::FrameTypeData decoderBase::getCurrentFrameStatsForType(int typeId) const
{
if (!this->statisticsEnabled())
return {};
return statisticsData->getFrameTypeData(typeId);
}
void decoderBaseSingleLib::loadDecoderLibrary(QString specificLibrary)
{
// Try to load the HM library from the current working directory
// Unfortunately relative paths like this do not work: (at least on windows)
// library.setFileName(".\\libde265");
bool libLoaded = false;
// Try the specific library first
this->library.setFileName(specificLibrary);
this->libraryPath = specificLibrary;
libLoaded = this->library.load();
if (!libLoaded)
{
// Try various paths/names next
// If the file name is not set explicitly, QLibrary will try to open
// the decLibXXX.so file first. Since this has been compiled for linux
// it will fail and not even try to open the decLixXXX.dylib.
// On windows and linux ommitting the extension works
auto libNames = getLibraryNames();
// Get the additional search path from the settings
QSettings settings;
settings.beginGroup("Decoders");
auto searchPath = settings.value("SearchPath", "").toString();
if (!searchPath.endsWith("/"))
searchPath.append("/");
searchPath.append("%1");
settings.endGroup();
auto const libPaths = QStringList()
<< searchPath << QDir::currentPath() + "/%1"
<< QDir::currentPath() + "/decoder/%1"
<< QDir::currentPath() +
"/libde265/%1" // for legacy installations before the decoders were
// moved to the "decoders" folder
<< QCoreApplication::applicationDirPath() + "/%1"
<< QCoreApplication::applicationDirPath() + "/decoder/%1"
<< QCoreApplication::applicationDirPath() + "/libde265/%1"
<< "%1"; // Try the system directories.
for (auto &libName : libNames)
{
for (auto &libPath : libPaths)
{
this->library.setFileName(libPath.arg(libName));
this->libraryPath = libPath.arg(libName);
libLoaded = library.load();
if (libLoaded)
break;
}
if (libLoaded)
break;
}
}
if (!libLoaded)
{
this->libraryPath.clear();
auto error = "Error loading library: " + this->library.errorString() + "\n";
error += "We could not load one of the supported decoder library (";
auto libNames = this->getLibraryNames();
for (int i = 0; i < libNames.count(); i++)
{
if (i == 0)
error += libNames[0];
else
error += ", " + libNames[i];
}
error += ").\n";
error += "\n";
error += "We do not ship all of the decoder libraries.\n";
error += "You can find download links in Help->Downloads.";
return this->setError(error);
}
this->resolveLibraryFunctionPointers();
}
} // namespace decoder