Files
fmviewer3/project/fm_viewer/fav/AudioDecoder.cpp
2026-02-21 17:11:31 +09:00

96 lines
2.6 KiB
C++

/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
* 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 "AudioDecoder.h"
#include "AVDecoder_p.h"
#include "AVCompat.h"
#include "AudioResampler.h"
#include "factory.h"
#include "Logger.h"
namespace FAV {
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 FAV