1 /******************************************************************************
2     QtAV:  Multimedia framework based on Qt and FFmpeg
3     Copyright (C) 2012-2018 Wang Bin <wbsecg1@gmail.com>
4 
5 *   This file is part of QtAV
6 
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Lesser General Public License for more details.
16 
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 ******************************************************************************/
21 
22 
23 #ifndef QTAV_GLOBAL_H
24 #define QTAV_GLOBAL_H
25 
26 #include <stdarg.h>
27 #include <QtCore/QMetaType>
28 #include <QtCore/QByteArray> //QByteArrayLiteral check
29 #include <QtCore/qglobal.h>
30 #include <QtAV/dptr.h>
31 
32 #ifdef BUILD_QTAV_STATIC
33 #define Q_AV_EXPORT
34 #else
35 #if defined(BUILD_QTAV_LIB)
36 #  undef Q_AV_EXPORT
37 #  define Q_AV_EXPORT Q_DECL_EXPORT
38 #else
39 #  undef Q_AV_EXPORT
40 #  define Q_AV_EXPORT Q_DECL_IMPORT //only for vc?
41 #endif
42 #endif //BUILD_QTAV_STATIC
43 #define Q_AV_PRIVATE_EXPORT Q_AV_EXPORT
44 
45 /* runtime version. used to compare with compile time version */
46 Q_AV_EXPORT unsigned QtAV_Version();
47 Q_AV_EXPORT QString QtAV_Version_String();
48 Q_AV_EXPORT QString QtAV_Version_String_Long();
49 namespace QtAV {
50 enum LogLevel {
51     LogOff,
52     LogDebug, // log all
53     LogWarning, // log warning, critical, fatal
54     LogCritical, // log critical, fatal
55     LogFatal, // log fatal
56     LogAll
57 };
58 Q_AV_EXPORT QString aboutFFmpeg_PlainText();
59 Q_AV_EXPORT QString aboutFFmpeg_HTML();
60 Q_AV_EXPORT QString aboutQtAV_PlainText();
61 Q_AV_EXPORT QString aboutQtAV_HTML();
62 /*!
63  * Default value: LogOff for release build. LogAll for debug build.
64  * The level can also be changed at runtime by setting the QTAV_LOG_LEVEL or QTAV_LOG environment variable;
65  * QTAV_LOG_LEVEL can be: off, debug, warning, critical, fatal, all. Or use their enum values
66  * if both setLogLevel() is called and QTAV_LOG_LEVEL is set, the environment variable takes preceden.
67 */
68 Q_AV_EXPORT void setLogLevel(LogLevel value);
69 Q_AV_EXPORT LogLevel logLevel();
70 /// Default handler is qt message logger. Set environment QTAV_FFMPEG_LOG=0 or setFFmpegLogHandler(0) to disable.
71 Q_AV_EXPORT void setFFmpegLogHandler(void(*)(void *, int, const char *, va_list));
72 /*!
73  * \brief setFFmpegLogLevel
74  * \param level can be: quiet, panic, fatal, error, warn, info, verbose, debug, trace
75  */
76 Q_AV_EXPORT void setFFmpegLogLevel(const QByteArray& level);
77 
78 /// query the common options of avformat/avcodec that can be used by AVPlayer::setOptionsForXXX. Format/codec specified options are also included
79 Q_AV_EXPORT QString avformatOptions();
80 Q_AV_EXPORT QString avcodecOptions();
81 
82 ////////////Types/////////////
83 enum MediaStatus
84 {
85     UnknownMediaStatus,
86     NoMedia,
87     LoadingMedia, // when source is set
88     LoadedMedia, // if auto load and source is set. player is stopped state
89     StalledMedia, // insufficient buffering or other interruptions (timeout, user interrupt)
90     BufferingMedia, // NOT IMPLEMENTED
91     BufferedMedia, // when playing //NOT IMPLEMENTED
92     EndOfMedia, // Playback has reached the end of the current media. The player is in the StoppedState.
93     InvalidMedia // what if loop > 0 or stopPosition() is not mediaStopPosition()?
94 };
95 
96 enum BufferMode {
97     BufferTime,
98     BufferBytes,
99     BufferPackets
100 };
101 
102 enum MediaEndActionFlag {
103     MediaEndAction_Default, /// stop playback (if loop end) and clear video renderer
104     MediaEndAction_KeepDisplay = 1, /// stop playback but video renderer keeps the last frame
105     MediaEndAction_Pause = 1 << 1 /// pause playback. Currently AVPlayer repeat mode will not work if this flag is set
106 };
107 Q_DECLARE_FLAGS(MediaEndAction, MediaEndActionFlag)
108 
109 enum SeekUnit {
110     SeekByTime, // only this is supported now
111     SeekByByte,
112     SeekByFrame
113 };
114 enum SeekType {
115     AccurateSeek, // slow
116     KeyFrameSeek, // fast
117     AnyFrameSeek
118 };
119 
120 //http://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.709-5-200204-I!!PDF-E.pdf
121 // TODO: other color spaces (yuv itu.xxxx, XYZ, ...)
122 enum ColorSpace {
123     ColorSpace_Unknown,
124     ColorSpace_RGB,
125     ColorSpace_GBR, // for planar gbr format(e.g. video from x264) used in glsl
126     ColorSpace_BT601,
127     ColorSpace_BT709,
128     ColorSpace_XYZ
129 };
130 
131 /*!
132  * \brief The ColorRange enum
133  * YUV or RGB color range
134  */
135 enum ColorRange {
136     ColorRange_Unknown,
137     ColorRange_Limited, // TV, MPEG
138     ColorRange_Full     // PC, JPEG
139 };
140 
141 /*!
142  * \brief The SurfaceType enum
143  * HostMemorySurface:
144  * Map the decoded frame to host memory
145  * GLTextureSurface:
146  * Map the decoded frame as an OpenGL texture
147  * SourceSurface:
148  * get the original surface from decoder, for example VASurfaceID for va-api, CUdeviceptr for CUDA and IDirect3DSurface9* for DXVA.
149  * Zero copy mode is required.
150  * UserSurface:
151  * Do your own magic mapping with it
152  */
153 enum SurfaceType {
154     HostMemorySurface,
155     GLTextureSurface,
156     SourceSurface,
157     UserSurface = 0xffff
158 };
159 } //namespace QtAV
160 
161 Q_DECLARE_METATYPE(QtAV::MediaStatus)
162 Q_DECLARE_METATYPE(QtAV::MediaEndAction)
163 
164 // TODO: internal use. move to a private header
165 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
166 #define QStringLiteral(X) QString::fromUtf8(X)
167 #endif //QT_VERSION
168 #ifndef QByteArrayLiteral
169 #define QByteArrayLiteral(str) QByteArray(str, sizeof(str) - 1)
170 #endif
171 
172 // TODO: internal use. move to a private header
173 #define QTAV_HAVE(FEATURE) (QTAV_HAVE_##FEATURE+0)
174 
175 #ifndef Q_DECL_OVERRIDE
176 #define Q_DECL_OVERRIDE
177 #endif
178 #ifndef Q_DECL_FINAL
179 #define Q_DECL_FINAL
180 #endif
181 
182 #if defined(BUILD_QTAV_LIB)
183 #define QTAV_DEPRECATED
184 #else
185 #define QTAV_DEPRECATED Q_DECL_DEPRECATED
186 #endif
187 #endif // QTAV_GLOBAL_H
188 
189