this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CoreAudio: Some initial code for AFAVFormatComponent

+384
+94
src/CoreAudio/AFAVFormatComponent/AVFormatFileObject.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + #include "AVFormatFileObject.h" 20 + #include <sstream> 21 + #include "AudioFileFormatMP3.h" 22 + 23 + extern "C" { 24 + #include <libavformat/avformat.h> 25 + } 26 + 27 + #pragma GCC visibility push(default) 28 + AUDIOCOMPONENT_ENTRY(AudioFileComponentFactory, AVFormatFileObject); 29 + #pragma GCC visibility pop 30 + 31 + AVFormatFileObject::AVFormatFileObject(AudioComponentInstance inInstance) 32 + : AudioFileObjectComponentBase(inInstance) 33 + { 34 + 35 + } 36 + 37 + // Analyze mAudioFileObject and return an AudioFileFormat based on that 38 + AudioFileFormat* AVFormatFileObject::GetAudioFormat() const 39 + { 40 + uint8_t buffer[1024 + AVPROBE_PADDING_SIZE]; 41 + AVProbeData probeData; 42 + 43 + probeData.filename = ""; 44 + probeData.buf = buffer; 45 + probeData.buf_size = 1024; 46 + 47 + if (mAudioFileObject->ReadBytes(false, 0, (UInt32*)&probeData.buf_size, probeData.buf) != noErr) 48 + return nullptr; 49 + 50 + AVInputFormat* fmt = av_probe_input_format(&probeData, true); 51 + if (!fmt) 52 + return nullptr; 53 + 54 + std::istringstream ss(fmt->name); 55 + std::string formatName; 56 + 57 + while (std::getline(ss, formatName, ',')) 58 + { 59 + if (formatName == "aac") // Raw AAC 60 + { 61 + 62 + } 63 + else if (formatName == "ac3") 64 + { 65 + 66 + } 67 + else if (formatName == "aiff") 68 + { 69 + 70 + } 71 + else if (formatName == "caff") 72 + { 73 + 74 + } 75 + else if (formatName == "mp3") 76 + { 77 + return AudioFileFormatMP3::instance(); 78 + } 79 + else if (formatName == "mov" || formatName == "mp4") 80 + { 81 + 82 + } 83 + else if (formatName == "au") 84 + { 85 + 86 + } 87 + else if (formatName == "wav") 88 + { 89 + 90 + } 91 + } 92 + 93 + return nullptr; 94 + }
+31
src/CoreAudio/AFAVFormatComponent/AVFormatFileObject.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef _AV_FORMAT_FILE_OBJECT_H 21 + #define _AV_FORMAT_FILE_OBJECT_H 22 + #include "AudioFileComponentBase.h" 23 + 24 + class AVFormatFileObject : public AudioFileObjectComponentBase 25 + { 26 + public: 27 + AVFormatFileObject(AudioComponentInstance inInstance); 28 + AudioFileFormat* GetAudioFormat() const override; 29 + }; 30 + 31 + #endif
+118
src/CoreAudio/AFAVFormatComponent/AudioFileFormatGeneric.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + #include "AudioFileFormatGeneric.h" 20 + #include <cstring> 21 + #include <CoreServices/MacErrors.h> 22 + 23 + extern "C" { 24 + #include <libavformat/avformat.h> 25 + } 26 + 27 + AudioFileFormatGeneric::AudioFileFormatGeneric(UInt32 inFileType, const char* avformatShortName) 28 + : AudioFileFormat(inFileType), m_avformatShortName(avformatShortName) 29 + { 30 + } 31 + 32 + Boolean AudioFileFormatGeneric::ExtensionIsThisFormat(CFStringRef inExtension) 33 + { 34 + const char* inStr = CFStringGetCStringPtr(inExtension, kCFStringEncodingUTF8); 35 + const Description& desc = description(); 36 + 37 + for (const char* ext : desc.extensions) 38 + { 39 + if (::strcasecmp(ext, inStr) == 0) 40 + return true; 41 + } 42 + 43 + return false; 44 + } 45 + 46 + void AudioFileFormatGeneric::GetExtensions(CFArrayRef *outArray) 47 + { 48 + *outArray = toCFArray(description().extensions); 49 + } 50 + 51 + CFArrayRef AudioFileFormatGeneric::toCFArray(const std::vector<const char*>& array) 52 + { 53 + std::vector<CFStringRef> strings; 54 + strings.reserve(array.size()); 55 + 56 + for (const char* str : array) 57 + strings.push_back(CFStringCreateWithCString(nullptr, str, kCFStringEncodingUTF8)); 58 + 59 + CFArrayRef rv = CFArrayCreate(nullptr, (const void**) strings.data(), array.size(), &kCFTypeArrayCallBacks); 60 + 61 + for (CFStringRef str : strings) 62 + CFRelease(str); 63 + 64 + return rv; 65 + } 66 + 67 + void AudioFileFormatGeneric::GetUTIs(CFArrayRef *outArray) 68 + { 69 + *outArray = toCFArray(description().utis); 70 + } 71 + 72 + void AudioFileFormatGeneric::GetMIMETypes(CFArrayRef *outArray) 73 + { 74 + *outArray = toCFArray(description().mimeTypes); 75 + } 76 + 77 + void AudioFileFormatGeneric::GetFileTypeName(CFStringRef *outName) 78 + { 79 + *outName = CFStringCreateWithCString(nullptr, description().name, kCFStringEncodingUTF8); 80 + } 81 + 82 + UncertainResult AudioFileFormatGeneric::FileDataIsThisFormat(UInt32 inDataByteSize, const void* inData) 83 + { 84 + AVInputFormat* fmt = av_find_input_format(m_avformatShortName); 85 + if (!fmt) 86 + return false; 87 + 88 + std::vector<uint8_t> buf; 89 + AVProbeData probeData; 90 + 91 + buf.reserve(inDataByteSize + AVPROBE_PADDING_SIZE); 92 + buf.insert(buf.end(), static_cast<const uint8_t*>(inData), static_cast<const uint8_t*>(inData) + inDataByteSize); 93 + buf.resize(inDataByteSize + AVPROBE_PADDING_SIZE); 94 + 95 + probeData.filename = ""; 96 + probeData.buf = buf.data(); 97 + probeData.buf_size = inDataByteSize; 98 + 99 + return fmt->read_probe(&probeData) ? kTrue : kFalse; 100 + } 101 + 102 + AudioFileObject* AudioFileFormatGeneric::New() 103 + { 104 + // TODO 105 + return nullptr; 106 + } 107 + 108 + OSStatus AudioFileFormatGeneric::GetAvailableFormatIDs(UInt32* ioDataSize, void* outPropertyData) 109 + { 110 + // TODO 111 + return unimpErr; 112 + } 113 + 114 + OSStatus AudioFileFormatGeneric::GetAvailableStreamDescriptions(UInt32 inFormatID, UInt32* ioDataSize, void* outPropertyData) 115 + { 116 + // TODO 117 + return unimpErr; 118 + }
+55
src/CoreAudio/AFAVFormatComponent/AudioFileFormatGeneric.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef _AUDIO_FILE_FORMAT_GENERIC_H 21 + #define _AUDIO_FILE_FORMAT_GENERIC_H 22 + #include "AudioFileFormat.h" 23 + 24 + class AudioFileFormatGeneric : public AudioFileFormat 25 + { 26 + public: 27 + AudioFileFormatGeneric(UInt32 inFileType, const char* avformatShortName); 28 + Boolean ExtensionIsThisFormat(CFStringRef inExtension) override; 29 + void GetExtensions(CFArrayRef *outArray) override; 30 + void GetUTIs(CFArrayRef *outArray) override; 31 + void GetMIMETypes(CFArrayRef *outArray) override; 32 + void GetFileTypeName(CFStringRef *outName) override; 33 + UncertainResult FileDataIsThisFormat(UInt32 inDataByteSize, const void* inData) override; 34 + 35 + AudioFileObject* New() override; 36 + AudioFileStreamObject* NewStream() override { return NULL; } 37 + OSStatus GetAvailableFormatIDs(UInt32* ioDataSize, void* outPropertyData) override; 38 + OSStatus GetAvailableStreamDescriptions(UInt32 inFormatID, UInt32* ioDataSize, void* outPropertyData) override; 39 + private: 40 + static CFArrayRef toCFArray(const std::vector<const char*>& array); 41 + protected: 42 + struct Description 43 + { 44 + const char* name; 45 + std::vector<const char*> extensions; 46 + std::vector<const char*> utis; 47 + std::vector<const char*> mimeTypes; 48 + }; 49 + virtual const Description& description() const = 0; 50 + private: 51 + const char* m_avformatShortName; 52 + }; 53 + 54 + #endif 55 +
+42
src/CoreAudio/AFAVFormatComponent/AudioFileFormatMP3.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include "AudioFileFormatMP3.h" 21 + 22 + AudioFileFormatMP3::AudioFileFormatMP3() 23 + : AudioFileFormatGeneric('.mp3', "mp3") 24 + { 25 + } 26 + 27 + AudioFileFormatMP3* AudioFileFormatMP3::instance() 28 + { 29 + static AudioFileFormatMP3 inst; 30 + return &inst; 31 + } 32 + 33 + const AudioFileFormatMP3::Description& AudioFileFormatMP3::description() const 34 + { 35 + static const Description d = { 36 + .name = "MPEG Layer 3", 37 + .extensions = { "mp3" }, 38 + .utis = { "public.mp3", "public.audio", "public.data" }, 39 + .mimeTypes = { "audio/mpeg" }, 40 + }; 41 + return d; 42 + }
+35
src/CoreAudio/AFAVFormatComponent/AudioFileFormatMP3.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2020 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef _AUDIO_FILE_FORMAT_MP3_H 21 + #define _AUDIO_FILE_FORMAT_MP3_H 22 + #include "AudioFileFormatGeneric.h" 23 + 24 + class AudioFileFormatMP3 : public AudioFileFormatGeneric 25 + { 26 + private: 27 + AudioFileFormatMP3(); 28 + public: 29 + static AudioFileFormatMP3* instance(); 30 + protected: 31 + const Description& description() const override; 32 + }; 33 + 34 + #endif 35 +
+3
src/CoreAudio/AFAVFormatComponent/CMakeLists.txt
··· 17 17 AFPublic/DataSource.cpp 18 18 AUPublic/AUBase/ComponentBase.cpp 19 19 PublicUtility/CACFDictionary.cpp 20 + AVFormatFileObject.cpp 21 + AudioFileFormatGeneric.cpp 22 + AudioFileFormatMP3.cpp 20 23 ) 21 24 22 25 add_darling_bundle(AFAVFormatComponent "" ${component_sources})
+6
src/CoreAudio/AFAVFormatComponent/README
··· 1 + This is a file format component built on top of AVFormat. 2 + 3 + The area of macOS surrounding AudioFileComponents is very badly documented, especially with regard to where this component belongs etc. 4 + This project may serve as an example: https://sourceforge.net/projects/coreaudio-flac/ 5 + 6 + The goal is to support formats specified here: https://developer.apple.com/library/archive/documentation/MusicAudio/Conceptual/CoreAudioOverview/SupportedAudioFormatsMacOSX/SupportedAudioFormatsMacOSX.html