mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-26 12:58:47 +02:00
list output devices on macos
This commit is contained in:
parent
331e965a4e
commit
52c5d21da4
4 changed files with 62 additions and 2 deletions
|
@ -70,7 +70,7 @@ else ifeq ($(TARGET), MACOS)
|
||||||
CXX = g++
|
CXX = g++
|
||||||
STRIP = strip
|
STRIP = strip
|
||||||
CXXFLAGS += -DHAS_OGG -DHAS_COREAUDIO -DFREEBSD -DHAS_BONJOUR -DHAS_DAEMON -I/usr/local/include -Wno-unused-local-typedef -Wno-deprecated
|
CXXFLAGS += -DHAS_OGG -DHAS_COREAUDIO -DFREEBSD -DHAS_BONJOUR -DHAS_DAEMON -I/usr/local/include -Wno-unused-local-typedef -Wno-deprecated
|
||||||
LDFLAGS += -lvorbis -lFLAC -L/usr/local/lib -framework AudioToolbox -framework CoreFoundation -framework IOKit
|
LDFLAGS += -lvorbis -lFLAC -L/usr/local/lib -framework AudioToolbox -framework CoreAudio -framework CoreFoundation -framework IOKit
|
||||||
OBJ += ../common/daemon.o player/coreAudioPlayer.o browseZeroConf/browseBonjour.o
|
OBJ += ../common/daemon.o player/coreAudioPlayer.o browseZeroConf/browseBonjour.o
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
***/
|
***/
|
||||||
|
|
||||||
|
//#include <CoreServices/CoreServices.h>
|
||||||
|
#include <CoreAudio/CoreAudio.h>
|
||||||
#include "coreAudioPlayer.h"
|
#include "coreAudioPlayer.h"
|
||||||
|
|
||||||
#define NUM_BUFFERS 2
|
#define NUM_BUFFERS 2
|
||||||
|
@ -44,6 +46,54 @@ CoreAudioPlayer::~CoreAudioPlayer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// TODO: experimental. No output device can be configured yet.
|
||||||
|
std::vector<PcmDevice> CoreAudioPlayer::pcm_list(void)
|
||||||
|
{
|
||||||
|
UInt32 propsize;
|
||||||
|
|
||||||
|
AudioObjectPropertyAddress theAddress = { kAudioHardwarePropertyDevices,
|
||||||
|
kAudioObjectPropertyScopeGlobal,
|
||||||
|
kAudioObjectPropertyElementMaster };
|
||||||
|
|
||||||
|
AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &theAddress, 0, NULL, &propsize);
|
||||||
|
int nDevices = propsize / sizeof(AudioDeviceID);
|
||||||
|
AudioDeviceID *devids = new AudioDeviceID[nDevices];
|
||||||
|
AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &propsize, devids);
|
||||||
|
|
||||||
|
std::vector<PcmDevice> result;
|
||||||
|
for (int i = 0; i < nDevices; ++i)
|
||||||
|
{
|
||||||
|
if (devids[i] == kAudioDeviceUnknown)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
UInt32 propSize;
|
||||||
|
AudioObjectPropertyAddress theAddress = { kAudioDevicePropertyStreamConfiguration, kAudioDevicePropertyScopeOutput, 0 };
|
||||||
|
if (AudioObjectGetPropertyDataSize(devids[i], &theAddress, 0, NULL, &propSize))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
AudioBufferList *buflist = (AudioBufferList *)malloc(propSize);
|
||||||
|
if (AudioObjectGetPropertyData(devids[i], &theAddress, 0, NULL, &propSize, buflist))
|
||||||
|
continue;
|
||||||
|
int channels = 0;
|
||||||
|
for (UInt32 i = 0; i < buflist->mNumberBuffers; ++i)
|
||||||
|
channels += buflist->mBuffers[i].mNumberChannels;
|
||||||
|
free(buflist);
|
||||||
|
if (channels == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
UInt32 maxlen = 1024;
|
||||||
|
char buf[maxlen];
|
||||||
|
theAddress = { kAudioDevicePropertyDeviceName, kAudioDevicePropertyScopeOutput, 0 };
|
||||||
|
AudioObjectGetPropertyData(devids[i], &theAddress, 0, NULL, &maxlen, buf);
|
||||||
|
LOG(DEBUG) << "device: " << i << ", name: " << buf << ", channels: " << channels << "\n";
|
||||||
|
|
||||||
|
result.push_back(PcmDevice(i, buf));
|
||||||
|
}
|
||||||
|
delete[] devids;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CoreAudioPlayer::playerCallback(AudioQueueRef queue, AudioQueueBufferRef bufferRef)
|
void CoreAudioPlayer::playerCallback(AudioQueueRef queue, AudioQueueBufferRef bufferRef)
|
||||||
{
|
{
|
||||||
/// Estimate the playout delay by checking the number of frames left in the buffer
|
/// Estimate the playout delay by checking the number of frames left in the buffer
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
virtual ~CoreAudioPlayer();
|
virtual ~CoreAudioPlayer();
|
||||||
|
|
||||||
void playerCallback(AudioQueueRef queue, AudioQueueBufferRef bufferRef);
|
void playerCallback(AudioQueueRef queue, AudioQueueBufferRef bufferRef);
|
||||||
|
static std::vector<PcmDevice> pcm_list(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void worker();
|
virtual void worker();
|
||||||
|
|
|
@ -24,7 +24,16 @@
|
||||||
|
|
||||||
struct PcmDevice
|
struct PcmDevice
|
||||||
{
|
{
|
||||||
PcmDevice() : idx(-1){};
|
PcmDevice() :
|
||||||
|
idx(-1)
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
PcmDevice(int idx, const std::string& name, const std::string& description = "") :
|
||||||
|
idx(idx), name(name), description(description)
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
int idx;
|
int idx;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string description;
|
std::string description;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue