File indexing completed on 2024-04-28 04:51:59

0001 /*
0002     SPDX-FileCopyrightText: 2012 Simon Andreas Eugster <simon.eu@gmail.com>
0003     This file is part of kdenlive. See www.kdenlive.org.
0004 
0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #include "audioInfo.h"
0009 
0010 #include "audioStreamInfo.h"
0011 #include <QString>
0012 #include <cstdlib>
0013 
0014 AudioInfo::AudioInfo(const std::shared_ptr<Mlt::Producer> &producer)
0015     : m_list(QList<AudioStreamInfo *>())
0016 {
0017     // Since we already receive an MLT producer, we do not need to initialize MLT:
0018     // Mlt::Factory::init(nullptr);
0019     // Get the number of streams and add the information of each of them if it is an audio stream.
0020     int streams = producer->get_int("meta.media.nb_streams");
0021     for (int i = 0; i < streams; ++i) {
0022         QByteArray propertyName = QStringLiteral("meta.media.%1.stream.type").arg(i).toLocal8Bit();
0023         const char *streamtype = producer->get(propertyName.data());
0024         if ((streamtype != nullptr) && strcmp("audio", streamtype) == 0) {
0025             m_list << new AudioStreamInfo(producer, i);
0026         }
0027     }
0028 }
0029 
0030 AudioInfo::~AudioInfo()
0031 {
0032     for (AudioStreamInfo *info : qAsConst(m_list)) {
0033         delete info;
0034     }
0035 }
0036 
0037 int AudioInfo::size() const
0038 {
0039     return m_list.size();
0040 }
0041 
0042 AudioStreamInfo const *AudioInfo::info(int pos) const
0043 {
0044     Q_ASSERT(pos >= 0);
0045     Q_ASSERT(pos < m_list.size());
0046 
0047     return m_list.at(pos);
0048 }
0049 
0050 void AudioInfo::dumpInfo() const
0051 {
0052     for (AudioStreamInfo *info : m_list) {
0053         info->dumpInfo();
0054     }
0055 }