forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoDecoderFFmpeg.cpp
278 lines (240 loc) · 7.69 KB
/
VideoDecoderFFmpeg.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
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013-2014 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/VideoDecoder.h"
#include "QtAV/private/VideoDecoder_p.h"
#include <QtAV/Packet.h>
#include <QtAV/QtAV_Compat.h>
#include "QtAV/prepost.h"
/*!
* options (properties) are from libavcodec/options_table.h
* enum name here must convert to lower case to fit the names in avcodec. done in AVDecoder.setOptions()
* Don't use lower case here because the value name may be "default" in avcodec which is a keyword of C++
*/
namespace QtAV {
class VideoDecoderFFmpegPrivate;
class VideoDecoderFFmpeg : public VideoDecoder
{
Q_OBJECT
DPTR_DECLARE_PRIVATE(VideoDecoderFFmpeg)
Q_PROPERTY(bool skip_loop_filter READ skipLoopFilter WRITE setSkipLoopFilter)
Q_PROPERTY(bool skip_idct READ skipIDCT WRITE setSkipIDCT)
Q_PROPERTY(StrictType strict READ strict WRITE setStrict)
Q_PROPERTY(SkipFrameType skip_frame READ skipFrameType WRITE setSkipFrameType)
Q_PROPERTY(int threads READ threads WRITE setThreads) // 0 is auto
Q_PROPERTY(ThreadFlags thread_type READ threadFlags WRITE setThreadFlags)
Q_PROPERTY(MotionVectorVisFlags vismv READ motionVectorVisFlags WRITE setMotionVectorVisFlags)
Q_PROPERTY(BugFlags bug READ bugFlags WRITE setBugFlags)
Q_ENUMS(StrictType)
Q_ENUMS(SkipFrameType)
Q_ENUMS(ThreadFlag)
Q_FLAGS(ThreadFlags)
Q_ENUMS(MotionVectorVisFlag)
Q_FLAGS(MotionVectorVisFlags)
Q_ENUMS(BugFlag)
Q_FLAGS(BugFlags)
public:
enum StrictType {
Very = FF_COMPLIANCE_VERY_STRICT,
Strict = FF_COMPLIANCE_STRICT,
Normal = FF_COMPLIANCE_NORMAL, //default
Unofficial = FF_COMPLIANCE_UNOFFICIAL,
Experimental = FF_COMPLIANCE_EXPERIMENTAL
};
enum SkipFrameType {
None = AVDISCARD_NONE,
Default = AVDISCARD_DEFAULT, //default
NoRef = AVDISCARD_NONREF,
Bidir = AVDISCARD_BIDIR,
NoKey = AVDISCARD_NONKEY,
All = AVDISCARD_ALL
};
enum ThreadFlag {
DefaultType = FF_THREAD_SLICE | FF_THREAD_FRAME,//default
Slice = FF_THREAD_SLICE,
Frame = FF_THREAD_FRAME
};
Q_DECLARE_FLAGS(ThreadFlags, ThreadFlag)
// flags. visualize motion vectors (MVs)
enum MotionVectorVisFlag {
No = 0, //default
PF = FF_DEBUG_VIS_MV_P_FOR,
BF = FF_DEBUG_VIS_MV_B_FOR,
BB = FF_DEBUG_VIS_MV_B_BACK
};
Q_DECLARE_FLAGS(MotionVectorVisFlags, MotionVectorVisFlag)
enum BugFlag {
autodetect = FF_BUG_AUTODETECT, //default
#if FF_API_OLD_MSMPEG4
old_msmpeg4 = FF_BUG_OLD_MSMPEG4,
#endif
xvid_ilace = FF_BUG_XVID_ILACE,
ump4 = FF_BUG_UMP4,
no_padding = FF_BUG_NO_PADDING,
amv = FF_BUG_AMV,
#if FF_API_AC_VLC
ac_vlc = FF_BUG_AC_VLC,
#endif
qpel_chroma = FF_BUG_QPEL_CHROMA,
std_qpel = FF_BUG_QPEL_CHROMA2,
direct_blocksize = FF_BUG_DIRECT_BLOCKSIZE,
edge = FF_BUG_EDGE,
hpel_chroma = FF_BUG_HPEL_CHROMA,
dc_clip = FF_BUG_DC_CLIP,
ms = FF_BUG_MS,
trunc = FF_BUG_TRUNCATED
};
Q_DECLARE_FLAGS(BugFlags, BugFlag)
VideoDecoderFFmpeg();
virtual VideoDecoderId id() const;
//virtual bool prepare();
// TODO: av_opt_set in setter
void setSkipLoopFilter(bool y);
bool skipLoopFilter() const;
void setSkipIDCT(bool y);
bool skipIDCT() const;
void setStrict(StrictType s);
StrictType strict() const;
void setSkipFrameType(SkipFrameType s);
SkipFrameType skipFrameType() const;
void setThreads(int t);
int threads() const;
void setThreadFlags(ThreadFlags tt);
ThreadFlags threadFlags() const;
void setMotionVectorVisFlags(MotionVectorVisFlags mv);
MotionVectorVisFlags motionVectorVisFlags() const;
void setBugFlags(BugFlags b);
BugFlags bugFlags() const;
};
extern VideoDecoderId VideoDecoderId_FFmpeg;
FACTORY_REGISTER_ID_AUTO(VideoDecoder, FFmpeg, "FFmpeg")
void RegisterVideoDecoderFFmpeg_Man()
{
FACTORY_REGISTER_ID_MAN(VideoDecoder, FFmpeg, "FFmpeg")
}
class VideoDecoderFFmpegPrivate : public VideoDecoderPrivate
{
public:
VideoDecoderFFmpegPrivate():
VideoDecoderPrivate()
, skip_loop_filter(AVDISCARD_DEFAULT)
, skip_idct(AVDISCARD_DEFAULT)
, strict(VideoDecoderFFmpeg::Normal)
, skip_frame(VideoDecoderFFmpeg::Default)
, thread_type(VideoDecoderFFmpeg::DefaultType)
, threads(0)
, debug_mv(VideoDecoderFFmpeg::No)
, bug(VideoDecoderFFmpeg::autodetect)
{}
bool skip_loop_filter;
bool skip_idct;
int strict;
int skip_frame;
int thread_type;
int threads;
int debug_mv;
int bug;
};
VideoDecoderFFmpeg::VideoDecoderFFmpeg():
VideoDecoder(*new VideoDecoderFFmpegPrivate())
{
}
VideoDecoderId VideoDecoderFFmpeg::id() const
{
return VideoDecoderId_FFmpeg;
}
void VideoDecoderFFmpeg::setSkipLoopFilter(bool y)
{
DPTR_D(VideoDecoderFFmpeg);
d.skip_loop_filter = y;
//av_opt_set_int
}
bool VideoDecoderFFmpeg::skipLoopFilter() const
{
return d_func().skip_loop_filter;
}
void VideoDecoderFFmpeg::setSkipIDCT(bool y)
{
DPTR_D(VideoDecoderFFmpeg);
d.skip_idct = y;
//av_opt_set_int
}
bool VideoDecoderFFmpeg::skipIDCT() const
{
return d_func().skip_idct;
}
void VideoDecoderFFmpeg::setStrict(StrictType s)
{
DPTR_D(VideoDecoderFFmpeg);
d.strict = (int)s;
//av_opt_set_int(d.codec_ctx, "strict", )
}
VideoDecoderFFmpeg::StrictType VideoDecoderFFmpeg::strict() const
{
return (StrictType)d_func().strict;
}
void VideoDecoderFFmpeg::setSkipFrameType(SkipFrameType s)
{
DPTR_D(VideoDecoderFFmpeg);
d.skip_frame = (int)s;
//av_opt_set_int
}
VideoDecoderFFmpeg::SkipFrameType VideoDecoderFFmpeg::skipFrameType() const
{
return (SkipFrameType)d_func().skip_frame;
}
void VideoDecoderFFmpeg::setThreads(int t)
{
DPTR_D(VideoDecoderFFmpeg);
d.threads = t;
//av_opt_set_int
}
int VideoDecoderFFmpeg::threads() const
{
return d_func().threads;
}
void VideoDecoderFFmpeg::setThreadFlags(ThreadFlags tt)
{
DPTR_D(VideoDecoderFFmpeg);
d.thread_type = (int)tt;
//av_opt_set_int
}
VideoDecoderFFmpeg::ThreadFlags VideoDecoderFFmpeg::threadFlags() const
{
return (ThreadFlags)d_func().thread_type;
}
void VideoDecoderFFmpeg::setMotionVectorVisFlags(MotionVectorVisFlags mv)
{
DPTR_D(VideoDecoderFFmpeg);
d.debug_mv = (int)mv;
//av_opt_set_int
}
VideoDecoderFFmpeg::MotionVectorVisFlags VideoDecoderFFmpeg::motionVectorVisFlags() const
{
return (MotionVectorVisFlags)d_func().debug_mv;
}
void VideoDecoderFFmpeg::setBugFlags(BugFlags b)
{
DPTR_D(VideoDecoderFFmpeg);
d.bug = (int)b;
//av_opt_set_int
}
VideoDecoderFFmpeg::BugFlags VideoDecoderFFmpeg::bugFlags() const
{
return (BugFlags)d_func().bug;
}
} //namespace QtAV
#include "VideoDecoderFFmpeg.moc"