yolobs-studio/plugins/coreaudio-encoder/windows-imports.h

477 lines
17 KiB
C
Raw Permalink Normal View History

2016-02-23 23:16:51 +00:00
#define NO_MIN_MAX 1
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ShlObj.h>
#include <util/dstr.h>
2019-09-22 21:19:10 +00:00
typedef unsigned long UInt32;
typedef signed long SInt32;
typedef signed long long SInt64;
typedef double Float64;
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
typedef SInt32 OSStatus;
typedef unsigned char Boolean;
2016-02-23 23:16:51 +00:00
typedef UInt32 AudioFormatPropertyID;
2019-09-22 21:19:10 +00:00
enum { kVariableLengthArray = 1,
2016-02-23 23:16:51 +00:00
};
struct OpaqueAudioConverter;
typedef struct OpaqueAudioConverter *AudioConverterRef;
typedef UInt32 AudioConverterPropertyID;
struct AudioValueRange {
Float64 mMinimum;
Float64 mMaximum;
};
typedef struct AudioValueRange AudioValueRange;
struct AudioBuffer {
2019-09-22 21:19:10 +00:00
UInt32 mNumberChannels;
UInt32 mDataByteSize;
void *mData;
2016-02-23 23:16:51 +00:00
};
typedef struct AudioBuffer AudioBuffer;
struct AudioBufferList {
2019-09-22 21:19:10 +00:00
UInt32 mNumberBuffers;
2016-02-23 23:16:51 +00:00
AudioBuffer mBuffers[kVariableLengthArray];
};
typedef struct AudioBufferList AudioBufferList;
struct AudioStreamBasicDescription {
Float64 mSampleRate;
2019-09-22 21:19:10 +00:00
UInt32 mFormatID;
UInt32 mFormatFlags;
UInt32 mBytesPerPacket;
UInt32 mFramesPerPacket;
UInt32 mBytesPerFrame;
UInt32 mChannelsPerFrame;
UInt32 mBitsPerChannel;
UInt32 mReserved;
2016-02-23 23:16:51 +00:00
};
typedef struct AudioStreamBasicDescription AudioStreamBasicDescription;
struct AudioStreamPacketDescription {
2019-09-22 21:19:10 +00:00
SInt64 mStartOffset;
UInt32 mVariableFramesInPacket;
UInt32 mDataByteSize;
2016-02-23 23:16:51 +00:00
};
typedef struct AudioStreamPacketDescription AudioStreamPacketDescription;
2020-10-01 20:15:25 +00:00
typedef UInt32 AudioChannelLabel;
typedef UInt32 AudioChannelLayoutTag;
struct AudioChannelDescription {
AudioChannelLabel mChannelLabel;
UInt32 mChannelFlags;
float mCoordinates[3];
};
typedef struct AudioChannelDescription AudioChannelDescription;
struct AudioChannelLayout {
AudioChannelLayoutTag mChannelLayoutTag;
UInt32 mChannelBitmap;
UInt32 mNumberChannelDescriptions;
AudioChannelDescription mChannelDescriptions[kVariableLengthArray];
};
typedef struct AudioChannelLayout AudioChannelLayout;
2019-09-22 21:19:10 +00:00
typedef OSStatus (*AudioConverterComplexInputDataProc)(
AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets,
AudioBufferList *ioData,
AudioStreamPacketDescription **outDataPacketDescription,
void *inUserData);
enum { kAudioCodecPropertyNameCFString = 'lnam',
kAudioCodecPropertyManufacturerCFString = 'lmak',
kAudioCodecPropertyFormatCFString = 'lfor',
//kAudioCodecPropertyHasVariablePacketByteSizes = 'vpk?',
kAudioCodecPropertySupportedInputFormats = 'ifm#',
kAudioCodecPropertySupportedOutputFormats = 'ofm#',
kAudioCodecPropertyAvailableInputSampleRates = 'aisr',
kAudioCodecPropertyAvailableOutputSampleRates = 'aosr',
kAudioCodecPropertyAvailableBitRateRange = 'abrt',
kAudioCodecPropertyMinimumNumberInputPackets = 'mnip',
kAudioCodecPropertyMinimumNumberOutputPackets = 'mnop',
kAudioCodecPropertyAvailableNumberChannels = 'cmnc',
kAudioCodecPropertyDoesSampleRateConversion = 'lmrc',
kAudioCodecPropertyAvailableInputChannelLayoutTags = 'aicl',
kAudioCodecPropertyAvailableOutputChannelLayoutTags = 'aocl',
kAudioCodecPropertyInputFormatsForOutputFormat = 'if4o',
kAudioCodecPropertyOutputFormatsForInputFormat = 'of4i',
kAudioCodecPropertyFormatInfo = 'acfi',
2016-02-23 23:16:51 +00:00
};
2019-09-22 21:19:10 +00:00
enum { kAudioCodecPropertyInputBufferSize = 'tbuf',
kAudioCodecPropertyPacketFrameSize = 'pakf',
kAudioCodecPropertyMaximumPacketByteSize = 'pakb',
kAudioCodecPropertyCurrentInputFormat = 'ifmt',
kAudioCodecPropertyCurrentOutputFormat = 'ofmt',
kAudioCodecPropertyMagicCookie = 'kuki',
kAudioCodecPropertyUsedInputBufferSize = 'ubuf',
kAudioCodecPropertyIsInitialized = 'init',
kAudioCodecPropertyCurrentTargetBitRate = 'brat',
kAudioCodecPropertyCurrentInputSampleRate = 'cisr',
kAudioCodecPropertyCurrentOutputSampleRate = 'cosr',
kAudioCodecPropertyQualitySetting = 'srcq',
kAudioCodecPropertyApplicableBitRateRange = 'brta',
kAudioCodecPropertyApplicableInputSampleRates = 'isra',
kAudioCodecPropertyApplicableOutputSampleRates = 'osra',
kAudioCodecPropertyPaddedZeros = 'pad0',
kAudioCodecPropertyPrimeMethod = 'prmm',
kAudioCodecPropertyPrimeInfo = 'prim',
kAudioCodecPropertyCurrentInputChannelLayout = 'icl ',
kAudioCodecPropertyCurrentOutputChannelLayout = 'ocl ',
kAudioCodecPropertySettings = 'acs ',
kAudioCodecPropertyFormatList = 'acfl',
kAudioCodecPropertyBitRateControlMode = 'acbf',
kAudioCodecPropertySoundQualityForVBR = 'vbrq',
kAudioCodecPropertyMinimumDelayMode = 'mdel' };
enum { kAudioCodecBitRateControlMode_Constant = 0,
kAudioCodecBitRateControlMode_LongTermAverage = 1,
kAudioCodecBitRateControlMode_VariableConstrained = 2,
kAudioCodecBitRateControlMode_Variable = 3,
2016-02-23 23:16:51 +00:00
};
2019-09-22 21:19:10 +00:00
enum { kAudioFormatLinearPCM = 'lpcm',
kAudioFormatAC3 = 'ac-3',
kAudioFormat60958AC3 = 'cac3',
kAudioFormatAppleIMA4 = 'ima4',
kAudioFormatMPEG4AAC = 'aac ',
kAudioFormatMPEG4CELP = 'celp',
kAudioFormatMPEG4HVXC = 'hvxc',
kAudioFormatMPEG4TwinVQ = 'twvq',
kAudioFormatMACE3 = 'MAC3',
kAudioFormatMACE6 = 'MAC6',
kAudioFormatULaw = 'ulaw',
kAudioFormatALaw = 'alaw',
kAudioFormatQDesign = 'QDMC',
kAudioFormatQDesign2 = 'QDM2',
kAudioFormatQUALCOMM = 'Qclp',
kAudioFormatMPEGLayer1 = '.mp1',
kAudioFormatMPEGLayer2 = '.mp2',
kAudioFormatMPEGLayer3 = '.mp3',
kAudioFormatTimeCode = 'time',
kAudioFormatMIDIStream = 'midi',
kAudioFormatParameterValueStream = 'apvs',
kAudioFormatAppleLossless = 'alac',
kAudioFormatMPEG4AAC_HE = 'aach',
kAudioFormatMPEG4AAC_LD = 'aacl',
kAudioFormatMPEG4AAC_ELD = 'aace',
kAudioFormatMPEG4AAC_ELD_SBR = 'aacf',
kAudioFormatMPEG4AAC_ELD_V2 = 'aacg',
kAudioFormatMPEG4AAC_HE_V2 = 'aacp',
kAudioFormatMPEG4AAC_Spatial = 'aacs',
kAudioFormatAMR = 'samr',
kAudioFormatAudible = 'AUDB',
kAudioFormatiLBC = 'ilbc',
kAudioFormatDVIIntelIMA = 0x6D730011,
kAudioFormatMicrosoftGSM = 0x6D730031,
kAudioFormatAES3 = 'aes3',
2016-02-23 23:16:51 +00:00
};
2019-09-22 21:19:10 +00:00
enum { kAudioFormatFlagIsFloat = (1L << 0),
kAudioFormatFlagIsBigEndian = (1L << 1),
kAudioFormatFlagIsSignedInteger = (1L << 2),
kAudioFormatFlagIsPacked = (1L << 3),
kAudioFormatFlagIsAlignedHigh = (1L << 4),
kAudioFormatFlagIsNonInterleaved = (1L << 5),
kAudioFormatFlagIsNonMixable = (1L << 6),
kAudioFormatFlagsAreAllClear = (1L << 31),
kLinearPCMFormatFlagIsFloat = kAudioFormatFlagIsFloat,
kLinearPCMFormatFlagIsBigEndian = kAudioFormatFlagIsBigEndian,
kLinearPCMFormatFlagIsSignedInteger = kAudioFormatFlagIsSignedInteger,
kLinearPCMFormatFlagIsPacked = kAudioFormatFlagIsPacked,
kLinearPCMFormatFlagIsAlignedHigh = kAudioFormatFlagIsAlignedHigh,
kLinearPCMFormatFlagIsNonInterleaved = kAudioFormatFlagIsNonInterleaved,
kLinearPCMFormatFlagIsNonMixable = kAudioFormatFlagIsNonMixable,
kLinearPCMFormatFlagsAreAllClear = kAudioFormatFlagsAreAllClear,
kAppleLosslessFormatFlag_16BitSourceData = 1,
kAppleLosslessFormatFlag_20BitSourceData = 2,
kAppleLosslessFormatFlag_24BitSourceData = 3,
kAppleLosslessFormatFlag_32BitSourceData = 4,
2016-02-23 23:16:51 +00:00
};
2019-09-22 21:19:10 +00:00
enum { kAudioFormatFlagsNativeEndian = 0 };
2016-02-23 23:16:51 +00:00
enum {
// AudioStreamBasicDescription structure properties
2019-09-22 21:19:10 +00:00
kAudioFormatProperty_FormatInfo = 'fmti',
kAudioFormatProperty_FormatName = 'fnam',
kAudioFormatProperty_EncodeFormatIDs = 'acof',
kAudioFormatProperty_DecodeFormatIDs = 'acif',
kAudioFormatProperty_FormatList = 'flst',
kAudioFormatProperty_ASBDFromESDS = 'essd',
kAudioFormatProperty_ChannelLayoutFromESDS = 'escl',
kAudioFormatProperty_OutputFormatList = 'ofls',
kAudioFormatProperty_Encoders = 'aven',
kAudioFormatProperty_Decoders = 'avde',
kAudioFormatProperty_FormatIsVBR = 'fvbr',
kAudioFormatProperty_FormatIsExternallyFramed = 'fexf',
kAudioFormatProperty_AvailableEncodeBitRates = 'aebr',
kAudioFormatProperty_AvailableEncodeSampleRates = 'aesr',
2016-02-23 23:16:51 +00:00
kAudioFormatProperty_AvailableEncodeChannelLayoutTags = 'aecl',
2019-09-22 21:19:10 +00:00
kAudioFormatProperty_AvailableEncodeNumberChannels = 'avnc',
kAudioFormatProperty_ASBDFromMPEGPacket = 'admp',
2016-02-23 23:16:51 +00:00
//
// AudioChannelLayout structure properties
2019-09-22 21:19:10 +00:00
kAudioFormatProperty_BitmapForLayoutTag = 'bmtg',
kAudioFormatProperty_MatrixMixMap = 'mmap',
kAudioFormatProperty_ChannelMap = 'chmp',
kAudioFormatProperty_NumberOfChannelsForLayout = 'nchm',
kAudioFormatProperty_ValidateChannelLayout = 'vacl',
kAudioFormatProperty_ChannelLayoutForTag = 'cmpl',
kAudioFormatProperty_TagForChannelLayout = 'cmpt',
kAudioFormatProperty_ChannelLayoutName = 'lonm',
kAudioFormatProperty_ChannelLayoutSimpleName = 'lsnm',
kAudioFormatProperty_ChannelLayoutForBitmap = 'cmpb',
kAudioFormatProperty_ChannelName = 'cnam',
kAudioFormatProperty_ChannelShortName = 'csnm',
kAudioFormatProperty_TagsForNumberOfChannels = 'tagc',
kAudioFormatProperty_PanningMatrix = 'panm',
kAudioFormatProperty_BalanceFade = 'balf',
2016-02-23 23:16:51 +00:00
//
// ID3 tag (MP3 metadata) properties
2019-09-22 21:19:10 +00:00
kAudioFormatProperty_ID3TagSize = 'id3s',
kAudioFormatProperty_ID3TagToDictionary = 'id3d',
2016-02-23 23:16:51 +00:00
};
2019-09-22 21:19:10 +00:00
enum { kAudioConverterPropertyMinimumInputBufferSize = 'mibs',
kAudioConverterPropertyMinimumOutputBufferSize = 'mobs',
kAudioConverterPropertyMaximumInputBufferSize = 'xibs',
kAudioConverterPropertyMaximumInputPacketSize = 'xips',
kAudioConverterPropertyMaximumOutputPacketSize = 'xops',
kAudioConverterPropertyCalculateInputBufferSize = 'cibs',
kAudioConverterPropertyCalculateOutputBufferSize = 'cobs',
kAudioConverterPropertyInputCodecParameters = 'icdp',
kAudioConverterPropertyOutputCodecParameters = 'ocdp',
kAudioConverterSampleRateConverterAlgorithm = 'srci',
kAudioConverterSampleRateConverterComplexity = 'srca',
kAudioConverterSampleRateConverterQuality = 'srcq',
kAudioConverterSampleRateConverterInitialPhase = 'srcp',
kAudioConverterCodecQuality = 'cdqu',
kAudioConverterPrimeMethod = 'prmm',
kAudioConverterPrimeInfo = 'prim',
kAudioConverterChannelMap = 'chmp',
kAudioConverterDecompressionMagicCookie = 'dmgc',
kAudioConverterCompressionMagicCookie = 'cmgc',
kAudioConverterEncodeBitRate = 'brat',
kAudioConverterEncodeAdjustableSampleRate = 'ajsr',
kAudioConverterInputChannelLayout = 'icl ',
kAudioConverterOutputChannelLayout = 'ocl ',
kAudioConverterApplicableEncodeBitRates = 'aebr',
kAudioConverterAvailableEncodeBitRates = 'vebr',
kAudioConverterApplicableEncodeSampleRates = 'aesr',
kAudioConverterAvailableEncodeSampleRates = 'vesr',
kAudioConverterAvailableEncodeChannelLayoutTags = 'aecl',
kAudioConverterCurrentOutputStreamDescription = 'acod',
kAudioConverterCurrentInputStreamDescription = 'acid',
kAudioConverterPropertySettings = 'acps',
kAudioConverterPropertyBitDepthHint = 'acbd',
kAudioConverterPropertyFormatList = 'flst',
2016-02-23 23:16:51 +00:00
};
2019-09-22 21:19:10 +00:00
enum { kAudioConverterQuality_Max = 0x7F,
kAudioConverterQuality_High = 0x60,
kAudioConverterQuality_Medium = 0x40,
kAudioConverterQuality_Low = 0x20,
kAudioConverterQuality_Min = 0,
2016-02-23 23:16:51 +00:00
};
2019-09-22 21:19:10 +00:00
enum { kAudio_UnimplementedError = -4,
kAudio_FileNotFoundError = -43,
kAudio_FilePermissionError = -54,
kAudio_TooManyFilesOpenError = -42,
kAudio_BadFilePathError = '!pth', // 0x21707468, 561017960
kAudio_ParamError = -50,
kAudio_MemFullError = -108,
kAudioConverterErr_FormatNotSupported = 'fmt?',
kAudioConverterErr_OperationNotSupported = 0x6F703F3F,
// 'op??', integer used because of trigraph
kAudioConverterErr_PropertyNotSupported = 'prop',
kAudioConverterErr_InvalidInputSize = 'insz',
kAudioConverterErr_InvalidOutputSize = 'otsz',
// e.g. byte size is not a multiple of the frame size
kAudioConverterErr_UnspecifiedError = 'what',
kAudioConverterErr_BadPropertySizeError = '!siz',
kAudioConverterErr_RequiresPacketDescriptionsError = '!pkd',
kAudioConverterErr_InputSampleRateOutOfRange = '!isr',
kAudioConverterErr_OutputSampleRateOutOfRange = '!osr',
2016-02-23 23:16:51 +00:00
};
2019-09-22 21:19:10 +00:00
typedef OSStatus (*AudioConverterNew_t)(
2016-02-23 23:16:51 +00:00
const AudioStreamBasicDescription *inSourceFormat,
const AudioStreamBasicDescription *inDestinationFormat,
2019-09-22 21:19:10 +00:00
AudioConverterRef *outAudioConverter);
typedef OSStatus (*AudioConverterDispose_t)(AudioConverterRef inAudioConverter);
typedef OSStatus (*AudioConverterReset_t)(AudioConverterRef inAudioConverter);
typedef OSStatus (*AudioConverterGetProperty_t)(
AudioConverterRef inAudioConverter,
AudioConverterPropertyID inPropertyID, UInt32 *ioPropertyDataSize,
void *outPropertyData);
typedef OSStatus (*AudioConverterGetPropertyInfo_t)(
AudioConverterRef inAudioConverter,
AudioConverterPropertyID inPropertyID, UInt32 *outSize,
Boolean *outWritable);
typedef OSStatus (*AudioConverterSetProperty_t)(
AudioConverterRef inAudioConverter,
AudioConverterPropertyID inPropertyID, UInt32 inPropertyDataSize,
const void *inPropertyData);
typedef OSStatus (*AudioConverterFillComplexBuffer_t)(
AudioConverterRef inAudioConverter,
2016-02-23 23:16:51 +00:00
AudioConverterComplexInputDataProc inInputDataProc,
2019-09-22 21:19:10 +00:00
void *inInputDataProcUserData, UInt32 *ioOutputDataPacketSize,
AudioBufferList *outOutputData,
AudioStreamPacketDescription *outPacketDescription);
typedef OSStatus (*AudioFormatGetProperty_t)(AudioFormatPropertyID inPropertyID,
UInt32 inSpecifierSize,
const void *inSpecifier,
UInt32 *ioPropertyDataSize,
void *outPropertyData);
typedef OSStatus (*AudioFormatGetPropertyInfo_t)(
AudioFormatPropertyID inPropertyID, UInt32 inSpecifierSize,
const void *inSpecifier, UInt32 *outPropertyDataSize);
2016-02-23 23:16:51 +00:00
static AudioConverterNew_t AudioConverterNew = NULL;
static AudioConverterDispose_t AudioConverterDispose = NULL;
static AudioConverterReset_t AudioConverterReset = NULL;
static AudioConverterGetProperty_t AudioConverterGetProperty = NULL;
static AudioConverterGetPropertyInfo_t AudioConverterGetPropertyInfo = NULL;
static AudioConverterSetProperty_t AudioConverterSetProperty = NULL;
static AudioConverterFillComplexBuffer_t AudioConverterFillComplexBuffer = NULL;
static AudioFormatGetProperty_t AudioFormatGetProperty = NULL;
static AudioFormatGetPropertyInfo_t AudioFormatGetPropertyInfo = NULL;
static HMODULE audio_toolbox = NULL;
static void release_lib(void)
{
2020-10-12 20:28:36 +00:00
if (audio_toolbox) {
FreeLibrary(audio_toolbox);
audio_toolbox = NULL;
2016-02-23 23:16:51 +00:00
}
}
2020-10-12 20:28:36 +00:00
static bool load_from_shell_path(REFKNOWNFOLDERID rfid, const wchar_t *subpath)
2016-02-23 23:16:51 +00:00
{
2020-10-12 20:28:36 +00:00
wchar_t *sh_path;
if (SHGetKnownFolderPath(rfid, 0, NULL, &sh_path) != S_OK) {
CA_LOG(LOG_WARNING, "Could not retrieve shell path");
2016-02-23 23:16:51 +00:00
return false;
}
2020-10-12 20:28:36 +00:00
wchar_t path[MAX_PATH];
_snwprintf(path, MAX_PATH, L"%s\\%s", sh_path, subpath);
CoTaskMemFree(sh_path);
2016-02-23 23:16:51 +00:00
2020-10-12 20:28:36 +00:00
SetDllDirectory(path);
audio_toolbox = LoadLibraryW(L"CoreAudioToolbox.dll");
SetDllDirectory(nullptr);
2016-02-23 23:16:51 +00:00
2020-10-12 20:28:36 +00:00
return !!audio_toolbox;
}
2016-02-23 23:16:51 +00:00
2020-10-12 20:28:36 +00:00
static bool load_lib(void)
{
/* -------------------------------------------- */
/* attempt to load from path */
2016-02-23 23:16:51 +00:00
2020-10-12 20:28:36 +00:00
audio_toolbox = LoadLibraryW(L"CoreAudioToolbox.dll");
if (!!audio_toolbox)
return true;
2016-02-23 23:16:51 +00:00
2020-10-12 20:28:36 +00:00
/* -------------------------------------------- */
/* attempt to load from known install locations */
2016-02-23 23:16:51 +00:00
2020-10-12 20:28:36 +00:00
struct path_list_t {
REFKNOWNFOLDERID rfid;
const wchar_t *subpath;
};
path_list_t path_list[] = {
{FOLDERID_ProgramFilesCommon,
L"Apple\\Apple Application Support"},
{FOLDERID_ProgramFiles, L"iTunes"},
};
for (auto &val : path_list) {
if (load_from_shell_path(val.rfid, val.subpath)) {
return true;
}
}
2016-02-23 23:16:51 +00:00
return false;
}
static void unload_core_audio(void)
{
AudioConverterNew = NULL;
AudioConverterDispose = NULL;
AudioConverterReset = NULL;
AudioConverterGetProperty = NULL;
AudioConverterGetPropertyInfo = NULL;
AudioConverterSetProperty = NULL;
AudioConverterFillComplexBuffer = NULL;
AudioFormatGetProperty = NULL;
AudioFormatGetPropertyInfo = NULL;
release_lib();
}
#ifdef _MSC_VER
#pragma warning(push)
2019-09-22 21:19:10 +00:00
#pragma warning(disable : 4706)
2016-02-23 23:16:51 +00:00
#endif
static bool load_core_audio(void)
{
if (!load_lib())
return false;
2019-09-22 21:19:10 +00:00
#define LOAD_SYM_FROM_LIB(sym, lib, dll) \
if (!(sym = (sym##_t)GetProcAddress(lib, #sym))) { \
DWORD err = GetLastError(); \
CA_LOG(LOG_ERROR, \
"Couldn't load " #sym " from " dll ": %lu (0x%lx)", \
err, err); \
goto unload_everything; \
2016-02-23 23:16:51 +00:00
}
#define LOAD_SYM(sym) \
LOAD_SYM_FROM_LIB(sym, audio_toolbox, "CoreAudioToolbox.dll")
LOAD_SYM(AudioConverterNew);
LOAD_SYM(AudioConverterDispose);
LOAD_SYM(AudioConverterReset);
LOAD_SYM(AudioConverterGetProperty);
LOAD_SYM(AudioConverterGetPropertyInfo);
LOAD_SYM(AudioConverterSetProperty);
LOAD_SYM(AudioConverterFillComplexBuffer);
LOAD_SYM(AudioFormatGetProperty);
LOAD_SYM(AudioFormatGetPropertyInfo);
#undef LOAD_SYM
return true;
unload_everything:
unload_core_audio();
return false;
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif