/*
This file is part of Darling.
Copyright (C) 2020 Lubos Dolezel
Darling is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Darling 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Darling. If not, see .
*/
#ifndef _AUDIO_FILE_FORMAT_MANAGER_H
#define _AUDIO_FILE_FORMAT_MANAGER_H
#include
#include
#include
#include
#include
#include
#include
class __attribute__((visibility("hidden"))) AudioFileFormatManager
{
public:
static AudioFileFormatManager* instance();
std::set availableFormatIDs(UInt32 fileType) const;
struct ComponentInfo
{
AudioComponentDescription acd;
UInt32 fileType; // container type
std::string name;
std::vector utis, extensions, mimeTypes;
// codec type
std::unordered_map> formatDescriptions;
bool canRead, canWrite;
};
const ComponentInfo* fileType(UInt32 type) const;
std::set types(bool writableTypes) const;
std::set typesForMIME(const char* mime) const;
std::set typesForUTI(const char* uti) const;
std::set typesForExtension(const char* ext) const;
std::set allMIMEs() const;
std::set allUTIs() const;
std::set allExtensions() const;
private:
AudioFileFormatManager();
void buildDatabase();
void analyzeAudioFileComponent(AudioFileComponent component);
void registerComponent(const ComponentInfo& ci);
static void addToMap(std::unordered_map>& map, const std::string& key, ComponentInfo* ci);
static std::set findTypes(const std::unordered_map>& map, const char* key);
template
std::set allKeys(const std::unordered_map& map) const
{
std::set rv;
for (auto const& [k, v] : map)
rv.insert(k);
return rv;
}
private:
std::list m_components;
std::unordered_map m_fileTypeMap;
std::unordered_map> m_mimeMap, m_utiMap, m_extensionMap;
};
#endif