···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2020 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+2020+#include "AudioHardwareImplPA.h"
2121+2222+AudioHardwareImplPA::AudioHardwareImplPA()
2323+{
2424+ m_name = CFSTR("PulseAudio");
2525+ m_manufacturer = CFSTR("PulseAudio");
2626+ m_uid = CFSTR("100");
2727+}
2828+2929+OSStatus AudioHardwareImplPA::getPropertyData(const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize,
3030+ const void* inQualifierData, UInt32* ioDataSize, void* outData)
3131+{
3232+ switch (inAddress->mSelector)
3333+ {
3434+ // BEGIN kAudioObjectSystemObject properties
3535+ case kAudioHardwarePropertyDefaultInputDevice: // returns AudioDeviceID
3636+ if (AudioDeviceID* devId = static_cast<AudioDeviceID*>(outData); devId && *ioDataSize >= sizeof(AudioDeviceID))
3737+ {
3838+ // We're doing a bit of an abuse here, which works only for PA where we have a single virtual device.
3939+ // For ALSA, we could do kAudioObjectSystemObject + INDEX of device.
4040+ *devId = kAudioObjectSystemObject;
4141+ }
4242+ *ioDataSize = sizeof(AudioDeviceID);
4343+ break;
4444+ case kAudioHardwarePropertyDefaultOutputDevice: // returns AudioDeviceID
4545+ if (AudioDeviceID* devId = static_cast<AudioDeviceID*>(outData); devId && *ioDataSize >= sizeof(AudioDeviceID))
4646+ {
4747+ *devId = kAudioObjectSystemObject;
4848+ }
4949+ *ioDataSize = sizeof(AudioDeviceID);
5050+ break;
5151+ case kAudioHardwarePropertyDevices:
5252+ {
5353+ if (AudioDeviceID* devId = static_cast<AudioDeviceID*>(outData); devId && *ioDataSize >= sizeof(AudioDeviceID))
5454+ {
5555+ devId[0] = kAudioObjectSystemObject;
5656+ }
5757+ *ioDataSize = sizeof(AudioDeviceID) * 1;
5858+ break;
5959+ }
6060+ // END kAudioObjectSystemObject properties
6161+6262+ // BEGIN properties of a specific audio device (in case of PA, it is kAudioObjectSystemObject as well)
6363+ case kAudioDevicePropertyStreamConfiguration: // returns AudioBufferList
6464+ {
6565+ const size_t size = sizeof(AudioBufferList) + 1* sizeof(AudioBuffer);
6666+6767+ // Number of returned buffers is the number of channels
6868+ // check inAddress->mScope. If it equals kAudioDevicePropertyScopeInput, the caller cares about input only.
6969+ if (AudioBufferList* abl = static_cast<AudioBufferList*>(outData); abl && *ioDataSize >= size)
7070+ {
7171+ abl->mNumberBuffers = 1;
7272+ abl->mBuffers[0].mNumberChannels = 2;
7373+7474+ // TODO: Is the below stuff ever used? How?
7575+ abl->mBuffers[0].mData = nullptr;
7676+ abl->mBuffers[0].mDataByteSize = 0;
7777+ }
7878+7979+ *ioDataSize = size;
8080+ break;
8181+ }
8282+8383+ }
8484+8585+ return AudioHardwareImpl::getPropertyData(inAddress, inQualifierDataSize, inQualifierData, ioDataSize, outData);
8686+}
8787+8888+OSStatus AudioHardwareImplPA::setPropertyData(const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize,
8989+ const void* inQualifierData, UInt32 inDataSize, const void* inData)
9090+{
9191+ return AudioHardwareImpl::setPropertyData(inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData);
9292+}
9393+9494+AudioHardwareStream* AudioHardwareImplPA::createStream(AudioDeviceIOProcID procID)
9595+{
9696+ // TODO
9797+ return nullptr;
9898+}
+39
src/CoreAudio/CoreAudio/AudioHardwareImplPA.h
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2020 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Darling. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+2020+#ifndef AUDIOHARDWAREIMPLPA_H
2121+#define AUDIOHARDWAREIMPLPA_H
2222+#include "AudioHardwareImpl.h"
2323+2424+class AudioHardwareImplPA : public AudioHardwareImpl
2525+{
2626+public:
2727+ AudioHardwareImplPA();
2828+2929+ OSStatus getPropertyData(const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize,
3030+ const void* inQualifierData, UInt32* ioDataSize, void* outData) override;
3131+3232+ OSStatus setPropertyData(const AudioObjectPropertyAddress* inAddress, UInt32 inQualifierDataSize,
3333+ const void* inQualifierData, UInt32 inDataSize, const void* inData) override;
3434+protected:
3535+ AudioHardwareStream* createStream(AudioDeviceIOProcID procID) override;
3636+};
3737+3838+#endif
3939+