File indexing completed on 2025-01-19 03:57:02

0001 /*********************************************************
0002  * Copyright (C) 2020, Val Doroshchuk <valbok@gmail.com> *
0003  *                                                       *
0004  * This file is part of QtAVPlayer.                      *
0005  * Free Qt Media Player based on FFmpeg.                 *
0006  *********************************************************/
0007 
0008 #include "qavaudiocodec_p.h"
0009 #include "qavcodec_p_p.h"
0010 #include <QDebug>
0011 
0012 extern "C" {
0013 #include <libavcodec/avcodec.h>
0014 }
0015 
0016 QT_BEGIN_NAMESPACE
0017 
0018 QAVAudioCodec::QAVAudioCodec()
0019 {
0020 }
0021 
0022 QAVAudioFormat QAVAudioCodec::audioFormat() const
0023 {
0024     Q_D(const QAVCodec);
0025     QAVAudioFormat format;
0026     if (!d->avctx)
0027         return format;
0028 
0029     auto fmt = AVSampleFormat(d->avctx->sample_fmt);
0030     if (fmt == AV_SAMPLE_FMT_U8)
0031         format.setSampleFormat(QAVAudioFormat::UInt8);
0032     else if (fmt == AV_SAMPLE_FMT_S16)
0033         format.setSampleFormat(QAVAudioFormat::Int16);
0034     else if (fmt == AV_SAMPLE_FMT_S32)
0035         format.setSampleFormat(QAVAudioFormat::Int32);
0036     else if (fmt == AV_SAMPLE_FMT_FLT)
0037         format.setSampleFormat(QAVAudioFormat::Float);
0038 
0039     format.setSampleRate(d->avctx->sample_rate);
0040 #if LIBAVCODEC_VERSION_INT <= AV_VERSION_INT(59, 23, 0)
0041     format.setChannelCount(d->avctx->channels);
0042 #else
0043     format.setChannelCount(d->avctx->ch_layout.nb_channels);
0044 #endif
0045 
0046     return format;
0047 }
0048 
0049 QT_END_NAMESPACE