/ src / CoreAudio / AFAVFormatComponent / AudioFileFormatGeneric.h
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  
38  	// File format -> data formats
39  	// https://developer.apple.com/library/archive/documentation/MusicAudio/Conceptual/CoreAudioOverview/SupportedAudioFormatsMacOSX/SupportedAudioFormatsMacOSX.html
40  	OSStatus GetAvailableFormatIDs(UInt32* ioDataSize, void* outPropertyData) override;
41  
42  	OSStatus GetAvailableStreamDescriptions(UInt32 inFormatID, UInt32* ioDataSize, void* outPropertyData) override;
43  private:
44  	static CFArrayRef toCFArray(const std::vector<const char*>& array);
45  protected:
46  	struct Format : public AudioStreamBasicDescription
47  	{
48  		Format(UInt32 formatID) { mFormatID = formatID; }
49  		Format(UInt32 formatID, UInt32 formatFlags, UInt32 bitsPerChannel) { mFormatID = formatID; mFormatFlags = formatFlags; mBitsPerChannel = bitsPerChannel; }
50  		Format() {}
51  	};
52  	struct Description
53  	{
54  		const char* name;
55  		std::vector<const char*> extensions;
56  		std::vector<const char*> utis;
57  		std::vector<const char*> mimeTypes;
58  		std::vector<Format> formats;
59  	};
60  	virtual const Description& description() const = 0;
61  private:
62  	const char* m_avformatShortName;
63  };
64  
65  #endif
66