forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AVDecoder.cpp
120 lines (96 loc) · 2.8 KB
/
AVDecoder.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
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 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/AVDecoder.h>
#include <private/AVDecoder_p.h>
namespace QtAV {
AVDecoder::AVDecoder()
{
}
AVDecoder::AVDecoder(AVDecoderPrivate &d)
:DPTR_INIT(&d)
{
}
AVDecoder::~AVDecoder()
{
}
void AVDecoder::flush()
{
if (isAvailable())
avcodec_flush_buffers(d_func().codec_ctx);
}
void AVDecoder::setCodecContext(AVCodecContext *codecCtx)
{
DPTR_D(AVDecoder);
d.codec_ctx = codecCtx;
}
AVCodecContext* AVDecoder::codecContext() const
{
return d_func().codec_ctx;
}
void AVDecoder::setLowResolution(int lowres)
{
d_func().low_resolution = lowres;
}
int AVDecoder::lowResolution() const
{
return d_func().low_resolution;
}
void AVDecoder::setDecodeThreads(int threads)
{
DPTR_D(AVDecoder);
d.threads = threads > 0 ? threads : QThread::idealThreadCount();
d.threads = qMax(d.threads, 1);
}
int AVDecoder::decodeThreads() const
{
return d_func().threads;
}
void AVDecoder::setThreadSlice(bool s)
{
d_func().thread_slice = s;
}
bool AVDecoder::isAvailable() const
{
return d_func().codec_ctx != 0;
}
bool AVDecoder::prepare()
{
DPTR_D(AVDecoder);
if (!d.codec_ctx) {
qWarning("call this after AVCodecContext is set!");
return false;
}
qDebug("Decoding threads count: %d", d.threads);
d.codec_ctx->thread_count = d.threads;
if (d.threads > 1)
d.codec_ctx->thread_type = d.thread_slice ? FF_THREAD_SLICE : FF_THREAD_FRAME;
else
d.codec_ctx->thread_type = 0; //FF_THREAD_FRAME:1, FF_THREAD_SLICE:2
//? !CODEC_ID_H264 && !CODEC_ID_VP8
d.codec_ctx->lowres = d.low_resolution;
return true;
}
bool AVDecoder::decode(const QByteArray &encoded)
{
Q_UNUSED(encoded);
return true;
}
QByteArray AVDecoder::data() const
{
return d_func().decoded;
}
} //namespace QtAV