forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioDecoder.cpp
95 lines (81 loc) · 2.68 KB
/
AudioDecoder.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
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 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/AudioDecoder.h"
#include "QtAV/private/AVDecoder_p.h"
#include "QtAV/private/AVCompat.h"
#include "QtAV/AudioResampler.h"
#include "QtAV/private/factory.h"
#include "utils/Logger.h"
namespace QtAV {
FACTORY_DEFINE(AudioDecoder)
// TODO: why vc can not declare extern func in a class member? resolved as &func@@YAXXZ
extern bool RegisterAudioDecoderFFmpeg_Man();
void AudioDecoder::registerAll() {
static bool done = false;
if (done)
return;
done = true;
RegisterAudioDecoderFFmpeg_Man();
}
QStringList AudioDecoder::supportedCodecs()
{
static QStringList codecs;
if (!codecs.isEmpty())
return codecs;
avcodec_register_all();
AVCodec* c = NULL;
while ((c=av_codec_next(c))) {
if (!av_codec_is_decoder(c) || c->type != AVMEDIA_TYPE_AUDIO)
continue;
codecs.append(QString::fromLatin1(c->name));
}
return codecs;
}
AudioDecoderPrivate::AudioDecoderPrivate()
: AVDecoderPrivate()
, resampler(0)
{
resampler = AudioResampler::create(AudioResamplerId_FF);
if (!resampler)
resampler = AudioResampler::create(AudioResamplerId_Libav);
if (resampler)
resampler->setOutSampleFormat(AV_SAMPLE_FMT_FLT);
}
AudioDecoderPrivate::~AudioDecoderPrivate()
{
if (resampler) {
delete resampler;
resampler = 0;
}
}
AudioDecoder::AudioDecoder(AudioDecoderPrivate &d):
AVDecoder(d)
{
}
QString AudioDecoder::name() const
{
return QLatin1String(AudioDecoder::name(id()));
}
QByteArray AudioDecoder::data() const
{
return d_func().decoded;
}
AudioResampler* AudioDecoder::resampler()
{
return d_func().resampler;
}
} //namespace QtAV