forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQtAV_Global.cpp
330 lines (305 loc) · 10.5 KB
/
QtAV_Global.cpp
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2015 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include "QtAV/QtAV_Global.h"
#include <QtCore/QObject>
#include <QtCore/QRegExp>
#include "QtAV/version.h"
#include "QtAV/private/AVCompat.h"
#include "utils/Logger.h"
unsigned QtAV_Version()
{
return QTAV_VERSION;
}
QString QtAV_Version_String()
{
return QTAV_VERSION_STR;
}
#define QTAV_VERSION_STR_LONG QTAV_VERSION_STR "(" __DATE__ ", " __TIME__ ")"
QString QtAV_Version_String_Long()
{
return QTAV_VERSION_STR_LONG;
}
namespace QtAV {
namespace Internal {
// disable logging for release. you can manually enable it.
#ifdef QT_NO_DEBUG
static QtAV::LogLevel gLogLevel = QtAV::LogOff;
#else
static QtAV::LogLevel gLogLevel = QtAV::LogAll;
#endif
static bool gLogLevelSet = false;
bool isLogLevelSet() { return gLogLevelSet;}
} //namespace Internal
//TODO: auto add new depend libraries information
QString aboutFFmpeg_PlainText()
{
return aboutFFmpeg_HTML().remove(QRegExp("<[^>]*>"));
}
namespace Internal {
typedef struct ff_component {
const char* lib;
unsigned build_version;
unsigned rt_version;
const char *config;
const char *license;
} ffmpeg_component_info;
static const ffmpeg_component_info* get_ffmpeg_component_info(const ffmpeg_component_info* info = 0)
{
static const ffmpeg_component_info components[] = {
//TODO: auto check loaded libraries
#define FF_COMPONENT(name, NAME) #name, LIB##NAME##_VERSION_INT, name##_version(), name##_configuration(), name##_license()
{ FF_COMPONENT(avutil, AVUTIL) },
{ FF_COMPONENT(avcodec, AVCODEC) },
{ FF_COMPONENT(avformat, AVFORMAT) },
#if QTAV_HAVE(AVFILTER)
{ FF_COMPONENT(avfilter, AVFILTER) },
#endif //QTAV_HAVE(AVFILTER)
#if QTAV_HAVE(AVDEVICE)
{ FF_COMPONENT(avdevice, AVDEVICE) },
#endif //QTAV_HAVE(AVDEVICE)
#if QTAV_HAVE(AVRESAMPLE)
{ FF_COMPONENT(avresample, AVRESAMPLE) },
#endif //QTAV_HAVE(AVRESAMPLE)
#if QTAV_HAVE(SWRESAMPLE)
{ FF_COMPONENT(swresample, SWRESAMPLE) },
#endif //QTAV_HAVE(SWRESAMPLE)
{ FF_COMPONENT(swscale, SWSCALE) },
#undef FF_COMPONENT
{ 0, 0, 0, 0, 0 }
};
if (!info)
return &components[0];
// invalid input ptr
if (((ptrdiff_t)info - (ptrdiff_t)(&components[0]))%sizeof(ffmpeg_component_info))
return 0;
const ffmpeg_component_info *next = info;
next++;
if (!next->lib)
return 0;
return next;
}
void print_library_info()
{
qDebug() << aboutQtAV_PlainText();
const ffmpeg_component_info* info = Internal::get_ffmpeg_component_info(0);
while (info) {
qDebug("Build with lib%s-%u.%u.%u"
, info->lib
, QTAV_VERSION_MAJOR(info->build_version)
, QTAV_VERSION_MINOR(info->build_version)
, QTAV_VERSION_PATCH(info->build_version)
);
unsigned rt_version = info->rt_version;
if (info->build_version != rt_version) {
qWarning("Warning: %s runtime version %u.%u.%u mismatch!"
, info->lib
, QTAV_VERSION_MAJOR(rt_version)
, QTAV_VERSION_MINOR(rt_version)
, QTAV_VERSION_PATCH(rt_version)
);
}
info = Internal::get_ffmpeg_component_info(info);
}
}
} //namespace Internal
QString aboutFFmpeg_HTML()
{
QString text = "<h3>FFmpeg/Libav</h3>\n";
const Internal::ffmpeg_component_info* info = Internal::get_ffmpeg_component_info(0);
while (info) {
text += "<h4>" + QObject::tr("Build version")
+ QString(": lib%1-%2.%3.%4</h4>\n")
.arg(info->lib)
.arg(QTAV_VERSION_MAJOR(info->build_version))
.arg(QTAV_VERSION_MINOR(info->build_version))
.arg(QTAV_VERSION_PATCH(info->build_version))
;
unsigned rt_version = info->rt_version;
if (info->build_version != rt_version) {
text += "<h4 style='color:#ff0000;'>" + QString(QObject::tr("Runtime version"))
+ QString(": %1.%2.%3</h4>\n")
.arg(QTAV_VERSION_MAJOR(rt_version))
.arg(QTAV_VERSION_MINOR(rt_version))
.arg(QTAV_VERSION_PATCH(rt_version))
;
}
text += "<p>" + QString(info->config) + "</p>\n"
"<p>" + QString(info->license) + "</p>\n";
info = Internal::get_ffmpeg_component_info(info);
}
return text;
}
QString aboutQtAV_PlainText()
{
return aboutQtAV_HTML().remove(QRegExp("<[^>]*>"));
}
QString aboutQtAV_HTML()
{
static QString about = "<h3>QtAV " QTAV_VERSION_STR_LONG "</h3>\n"
"<p>" + QObject::tr("A media playing library base on Qt and FFmpeg.\n") + "</p>"
"<p>" + QObject::tr("Distributed under the terms of LGPLv2.1 or later.\n") + "</p>"
"<p>Copyright (C) 2012-2014 Wang Bin (aka. Lucas Wang) <a href='mailto:[email protected]'>[email protected]</a></p>\n"
"<p>" + QObject::tr("Shanghai University->S3 Graphics->Deepin, Shanghai, China") + "</p>\n"
"<p>" + QObject::tr("Donate") + ": <a href='http://www.qtav.org#donate'>http://www.qtav.org#donate</a></p>\n"
"<p>" + QObject::tr("Source") + ": <a href='https://github.com/wang-bin/QtAV'>https://github.com/wang-bin/QtAV</a></p>\n"
"<p>" + QObject::tr("Home page") + ": <a href='http://www.qtav.org'>http://www.qtav.org</a></p>";
return about;
}
void setLogLevel(LogLevel value)
{
Internal::gLogLevelSet = true;
Internal::gLogLevel = value;
}
LogLevel logLevel()
{
return (LogLevel)Internal::gLogLevel;
}
void setFFmpegLogHandler(void (*callback)(void *, int, const char *, va_list))
{
// libav does not check null callback
if (!callback)
callback = av_log_default_callback;
av_log_set_callback(callback);
}
static void qtav_ffmpeg_log_callback(void* ctx, int level,const char* fmt, va_list vl)
{
AVClass *c = ctx ? *(AVClass**)ctx : 0;
QString qmsg = QString().sprintf("[FFmpeg:%s] ", c ? c->item_name(ctx) : "?") + QString().vsprintf(fmt, vl);
qmsg = qmsg.trimmed();
if (level > AV_LOG_WARNING)
qDebug() << qmsg;
else if (level > AV_LOG_PANIC)
qWarning() << qmsg;
}
#if 0
const QStringList& supportedInputMimeTypes()
{
static QStringList mimes;
if (!mimes.isEmpty())
return mimes;
av_register_all(); // MUST register all input/output formats
AVOutputFormat *i = av_oformat_next(NULL);
QStringList list;
while (i) {
list << QString(i->mime_type).split(QChar(','), QString::SkipEmptyParts);
i = av_oformat_next(i);
}
foreach (const QString& v, list) {
mimes.append(v.trimmed());
}
mimes.removeDuplicates();
return mimes;
}
static QStringList s_audio_mimes, s_video_mimes, s_subtitle_mimes;
static void init_supported_codec_info() {
const AVCodecDescriptor* cd = avcodec_descriptor_next(NULL);
while (cd) {
QStringList list;
if (cd->mime_types) {
for (int i = 0; cd->mime_types[i]; ++i) {
list.append(QString(cd->mime_types[i]).trimmed());
}
}
switch (cd->type) {
case AVMEDIA_TYPE_AUDIO:
s_audio_mimes << list;
break;
case AVMEDIA_TYPE_VIDEO:
s_video_mimes << list;
case AVMEDIA_TYPE_SUBTITLE:
s_subtitle_mimes << list;
default:
break;
}
cd = avcodec_descriptor_next(cd);
}
s_audio_mimes.removeDuplicates();
s_video_mimes.removeDuplicates();
s_subtitle_mimes.removeDuplicates();
}
const QStringList& supportedAudioMimeTypes()
{
if (s_audio_mimes.isEmpty())
init_supported_codec_info();
return s_audio_mimes;
}
const QStringList& supportedVideoMimeTypes()
{
if (s_video_mimes.isEmpty())
init_supported_codec_info();
return s_video_mimes;
}
// TODO: subtitleprocessor support
const QStringList& supportedSubtitleMimeTypes()
{
if (s_subtitle_mimes.isEmpty())
init_supported_codec_info();
return s_subtitle_mimes;
}
const QStringList& supportedInputExtensions()
{
static QStringList exts;
if (!exts.isEmpty())
return exts;
av_register_all(); // MUST register all input/output formats
AVInputFormat *i = av_iformat_next(NULL);
QStringList list;
while (i) {
list << QString(i->extensions).split(QChar(','), QString::SkipEmptyParts);
i = av_iformat_next(i);
}
foreach (const QString& v, list) {
exts.append(v.trimmed());
}
exts.removeDuplicates();
return exts;
}
#endif
// TODO: static link. move all into 1
namespace {
class InitFFmpegLog {
public:
InitFFmpegLog() {
setFFmpegLogHandler(qtav_ffmpeg_log_callback);
const QByteArray env = qgetenv("QTAV_FFMPEG_LOG").toLower();
if (env.isEmpty())
return;
bool ok = false;
const int level = env.toInt(&ok);
if ((ok && level == 0) || env == "off" || env == "quiet") {
av_log_set_level(AV_LOG_QUIET);
setFFmpegLogHandler(0);
}
else if (env == "panic")
av_log_set_level(AV_LOG_PANIC);
else if (env == "fatal")
av_log_set_level(AV_LOG_FATAL);
else if (env == "error")
av_log_set_level(AV_LOG_ERROR);
else if (env.startsWith("warn"))
av_log_set_level(AV_LOG_WARNING);
else if (env == "info")
av_log_set_level(AV_LOG_INFO);
else if (env == "verbose")
av_log_set_level(AV_LOG_VERBOSE);
else if (env == "debug")
av_log_set_level(AV_LOG_DEBUG);
}
};
InitFFmpegLog fflog;
}
}