AudioToolbox compiling again

This commit is contained in:
Lubos Dolezel 2020-03-05 10:50:04 +01:00
parent afdd68ee6f
commit 31d468bd53
25 changed files with 202 additions and 86 deletions

View File

@ -2,14 +2,12 @@
#include "AUComponent.h"
#include "AudioUnitALSA.h"
#include "AudioUnitPA.h"
#include <util/debug.h>
#include <alsa/asoundlib.h>
#include <CoreServices/MacErrors.h>
#include "stub.h"
AudioComponent AudioComponentFindNext(AudioComponent inAComponent, AudioComponentDescription *inDesc)
{
TRACE2(inAComponent, inDesc);
int index = -1;
if (inDesc->componentType != kAudioUnitType_Output && inDesc->componentType != kAudioUnitType_Mixer)
@ -18,8 +16,10 @@ AudioComponent AudioComponentFindNext(AudioComponent inAComponent, AudioComponen
if (inAComponent != nullptr)
index = GetComponentIndex(inAComponent);
#if defined(ENABLE_ALSA)
if (snd_card_next(&index) || index == -1)
return nullptr;
#endif
return CreateComponent(kComponentTypeAudioUnit, index);
}
@ -48,8 +48,6 @@ Boolean AudioComponentInstanceCanDo(AudioComponentInstance inInstance, SInt16 in
OSStatus AudioComponentInstanceDispose(AudioComponentInstance inInstance)
{
TRACE1(inInstance);
delete inInstance;
return noErr;
}
@ -61,8 +59,6 @@ AudioComponent AudioComponentInstanceGetComponent(AudioComponentInstance inInsta
OSStatus AudioComponentInstanceNew(AudioComponent inComponent, AudioComponentInstance *outInstance)
{
TRACE1(inComponent);
#if defined(ENABLE_PULSEAUDIO)
*outInstance = new AudioUnitPA;
#elif defined(ENABLE_ALSA)
@ -82,8 +78,12 @@ OSStatus AudioComponentCopyName(AudioComponent inComponent, CFStringRef *outName
if (!outName)
return paramErr;
#if defined(ENABLE_ALSA)
if (snd_card_get_longname(index, &name))
return paramErr;
#elif defined(ENABLE_PULSEAUDIO)
name = strdup("PulseAudio");
#endif
*outName = CFStringCreateWithCString(nullptr, name, kCFStringEncodingUTF8);
free(name);
@ -94,6 +94,8 @@ OSStatus AudioComponentCopyName(AudioComponent inComponent, CFStringRef *outName
UInt32 AudioComponentCount(AudioComponentDescription *inDesc)
{
UInt32 count = 0;
#if defined(ENABLE_ALSA)
int index = -1;
// Is there a better way?
@ -104,6 +106,9 @@ UInt32 AudioComponentCount(AudioComponentDescription *inDesc)
count++;
}
while (index != -1);
#elif defined(ENABLE_PULSEAUDIO)
count = 1;
#endif
return count;
}

View File

@ -1,7 +1,6 @@
#include "AudioConverter.h"
#include "AudioConverterImpl.h"
#include <CoreServices/MacErrors.h>
#include <util/debug.h>
#include <stdexcept>
#include <cstring>

View File

@ -1,8 +1,10 @@
#include "AudioConverterImpl.h"
#include <CoreServices/MacErrors.h>
#include <util/debug.h>
#include <stdexcept>
#include <cstring>
#include <cassert>
#include <iostream>
#include "stub.h"
extern "C" {
#include <libavcodec/avcodec.h>
@ -49,7 +51,7 @@ OSStatus AudioConverter::create(const AudioStreamBasicDescription* inSourceForma
if (idIn == AV_CODEC_ID_NONE || idOut == AV_CODEC_ID_NONE)
{
LOG << "AudioConverter::create(): Unsupported codec, format in = " << std::hex << inSourceFormat->mFormatID << ", out = " << inDestinationFormat->mFormatID << std::dec << std::endl;
// LOG << "AudioConverter::create(): Unsupported codec, format in = " << std::hex << inSourceFormat->mFormatID << ", out = " << inDestinationFormat->mFormatID << std::dec << std::endl;
return paramErr;
}
@ -58,7 +60,7 @@ OSStatus AudioConverter::create(const AudioStreamBasicDescription* inSourceForma
if (!codecIn || !codecOut)
{
LOG << "AudioConverter::create(): avcodec_find_*() failed, format in = " << std::hex << inSourceFormat->mFormatID << ", out = " << inDestinationFormat->mFormatID << std::dec << std::endl;
// LOG << "AudioConverter::create(): avcodec_find_*() failed, format in = " << std::hex << inSourceFormat->mFormatID << ", out = " << inDestinationFormat->mFormatID << std::dec << std::endl;
return paramErr;
}
@ -71,13 +73,13 @@ OSStatus AudioConverter::create(const AudioStreamBasicDescription* inSourceForma
cIn->channels = inSourceFormat->mChannelsPerFrame;
cIn->sample_rate = inSourceFormat->mSampleRate;
LOG << "Converting from PCM with " << cIn->channels << " channels at " << cIn->sample_rate << " Hz\n";
// LOG << "Converting from PCM with " << cIn->channels << " channels at " << cIn->sample_rate << " Hz\n";
}
if (avcodec_open2((*out)->m_decoder, codecIn, nullptr) < 0)
{
delete *out;
LOG << "AudioConverter::create(): avcodec_open() failed, format in = " << std::hex << inSourceFormat->mFormatID << ", out = " << inDestinationFormat->mFormatID << std::dec << std::endl;
// LOG << "AudioConverter::create(): avcodec_open() failed, format in = " << std::hex << inSourceFormat->mFormatID << ", out = " << inDestinationFormat->mFormatID << std::dec << std::endl;
return paramErr;
}
@ -130,14 +132,14 @@ void AudioConverter::allocateBuffers()
if (!audioSampleBuffer)
{
ERROR() << "Failed to allocate sample buffer";
std::cerr << "AudioConverter::allocateBuffers(): Failed to allocate sample buffer\n";
//return paramErr; // TODO
}
// Setup the data pointers in the AVFrame
if (avcodec_fill_audio_frame(m_audioFrame, m_encoder->channels, m_encoder->sample_fmt, (const uint8_t*) audioSampleBuffer, audioSampleBuffer_size, 0 ) < 0)
{
ERROR() << "Could not set up audio frame";
std::cerr << "AudioConverter::allocateBuffers(): Could not set up audio frame\n";
//return paramErr; // TODO
}
}
@ -261,7 +263,7 @@ OSStatus AudioConverter::feedInput(AudioConverterComplexInputDataProc dataProc,
m_avpkt.size = bufferList.mBuffers[0].mDataByteSize;
m_avpkt.data = (uint8_t*) bufferList.mBuffers[0].mData;
LOG << "dataProc() returned " << m_avpkt.size << " bytes of data\n";
// LOG << "dataProc() returned " << m_avpkt.size << " bytes of data\n";
return noErr;
}
@ -314,7 +316,7 @@ OSStatus AudioConverter::fillComplex(AudioConverterComplexInputDataProc dataProc
{
if (m_avpktOutUsed < m_avpktOut.size)
{
LOG << "case 1 (used " << m_avpktOutUsed << " from " << m_avpktOut.size << ")\n";
// LOG << "case 1 (used " << m_avpktOutUsed << " from " << m_avpktOut.size << ")\n";
// Feed output from previous conversion
while (m_avpktOutUsed < m_avpktOut.size && newSize < origSize)
{
@ -333,14 +335,14 @@ OSStatus AudioConverter::fillComplex(AudioConverterComplexInputDataProc dataProc
}
else if (!m_resampler || avresample_available(m_resampler) == 0)
{
LOG << "case 2\n";
// LOG << "case 2\n";
feedDecoder(dataProc, opaque, srcaudio);
if (avresample_available(m_resampler) == 0)
goto end;
}
else
{
LOG << "case 3\n";
// LOG << "case 3\n";
feedEncoder();
}
}
@ -355,7 +357,7 @@ end:
}
catch (const std::exception& e)
{
ERROR() << "Exception: " << e.what();
// ERROR() << "Exception: " << e.what();
#ifdef HAVE_AV_FRAME_ALLOC
av_frame_free(&srcaudio);
#else
@ -364,7 +366,7 @@ end:
}
catch (OSStatus err)
{
ERROR() << "OSStatus error: " << err;
// ERROR() << "OSStatus error: " << err;
#ifdef HAVE_AV_FRAME_ALLOC
av_frame_free(&srcaudio);
#else
@ -441,7 +443,7 @@ void AudioConverter::feedEncoder()
m_avpktOut.size = 0;
m_avpktOutUsed = 0;
LOG << "Got " << avail << " samples\n";
// LOG << "Got " << avail << " samples\n";
err = avcodec_fill_audio_frame(m_audioFrame, m_encoder->channels,
m_encoder->sample_fmt, output, avail * m_destinationFormat.mChannelsPerFrame * (m_destinationFormat.mBitsPerChannel / 8),
m_destinationFormat.mChannelsPerFrame * (m_destinationFormat.mBitsPerChannel / 8));

View File

@ -1,5 +1,5 @@
#include "AudioQueueBase.h"
#include <util/debug.h>
#include "stub.h"
#include <CoreServices/MacErrors.h>
AudioQueue::AudioQueue(const AudioStreamBasicDescription* format, void* userData,

View File

@ -1,5 +1,5 @@
#include "AudioQueueOutput.h"
#include <util/debug.h>
#include "stub.h"
#include <CoreServices/MacErrors.h>
AudioQueueOutput::AudioQueueOutput(const AudioStreamBasicDescription *inFormat,

View File

@ -2,29 +2,27 @@
#include "AudioUnit.h"
#include "AudioOutputUnitComponent.h"
#include "AudioUnitALSA.h"
#include <log.h>
#include <trace.h>
#include <alsa/asoundlib.h>
#include "stub.h"
#include <CoreServices/MacErrors.h>
OSStatus AudioUnitInitialize(AudioUnit inUnit)
{
return inUnit->init();
return ((AudioUnitComponent*)inUnit)->init();
}
OSStatus AudioUnitUninitialize(AudioUnit inUnit)
{
return inUnit->deinit();
return ((AudioUnitComponent*)inUnit)->deinit();
}
OSStatus AudioUnitAddRenderNotify(AudioUnit inUnit, AURenderCallback inProc, void* opaque)
{
return inUnit->addRenderNotify(inProc, opaque);
return ((AudioUnitComponent*)inUnit)->addRenderNotify(inProc, opaque);
}
OSStatus AudioUnitRemoveRenderNotify(AudioUnit inUnit, AURenderCallback inProc, void* opaque)
{
return inUnit->removeRenderNotify(inProc, opaque);
return ((AudioUnitComponent*)inUnit)->removeRenderNotify(inProc, opaque);
}
OSStatus AudioUnitRender(AudioUnit inUnit, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inOutputBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
@ -35,39 +33,39 @@ OSStatus AudioUnitRender(AudioUnit inUnit, AudioUnitRenderActionFlags *ioActionF
return paramErr;
*ioActionFlags |= kAudioUnitRenderAction_PreRender;
status = inUnit->notifyListeners(ioActionFlags, inTimeStamp, inOutputBusNumber, inNumberFrames, ioData);
status = ((AudioUnitComponent*)inUnit)->notifyListeners(ioActionFlags, inTimeStamp, inOutputBusNumber, inNumberFrames, ioData);
if (status != noErr)
return status;
*ioActionFlags &= ~kAudioUnitRenderAction_PreRender;
status = inUnit->render(ioActionFlags, inTimeStamp, inOutputBusNumber, inNumberFrames, ioData);
status = ((AudioUnitComponent*)inUnit)->render(ioActionFlags, inTimeStamp, inOutputBusNumber, inNumberFrames, ioData);
if (status != noErr)
*ioActionFlags |= kAudioUnitRenderAction_PostRenderError;
*ioActionFlags |= kAudioUnitRenderAction_PostRender;
return inUnit->notifyListeners(ioActionFlags, inTimeStamp, inOutputBusNumber, inNumberFrames, ioData);
return ((AudioUnitComponent*)inUnit)->notifyListeners(ioActionFlags, inTimeStamp, inOutputBusNumber, inNumberFrames, ioData);
}
OSStatus AudioUnitReset(AudioUnit inUnit, AudioUnitScope inScope, AudioUnitElement inElement)
{
return inUnit->reset(inScope, inElement);
return ((AudioUnitComponent*)inUnit)->reset(inScope, inElement);
}
OSStatus AudioUnitGetProperty(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, void* outData, UInt32 *ioDataSize)
{
return inUnit->getProperty(inID, inScope, inElement, outData, ioDataSize);
return ((AudioUnitComponent*)inUnit)->getProperty(inID, inScope, inElement, outData, ioDataSize);
}
OSStatus AudioUnitGetPropertyInfo(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, UInt32 *outDataSize, Boolean *outWritable)
{
return inUnit->getPropertyInfo(inID, inScope, inElement, outDataSize, outWritable);
return ((AudioUnitComponent*)inUnit)->getPropertyInfo(inID, inScope, inElement, outDataSize, outWritable);
}
OSStatus AudioUnitSetProperty(AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, const void *inData, UInt32 inDataSize)
{
return inUnit->setProperty(inID, inScope, inElement, inData, inDataSize);
return ((AudioUnitComponent*)inUnit)->setProperty(inID, inScope, inElement, inData, inDataSize);
}
OSStatus AudioOutputUnitStart(AudioUnit inUnit)

View File

@ -1,8 +1,8 @@
#include "darling-config.h"
#include <iostream>
#include "AudioUnitALSA.h"
#include "AudioUnitProperties.h"
#include <CoreServices/MacErrors.h>
#include <util/debug.h>
#include "stub.h"
#include <sstream>
#include <stdexcept>
#include <memory>
@ -18,7 +18,7 @@ AudioUnitALSA::AudioUnitALSA(int cardIndex, char* cardName)
{
static dispatch_once_t pred;
dispatch_once(&pred, ^{
g_audioQueue = dispatch_queue_create("org.darlinghw.audiounit", nullptr);
g_audioQueue = dispatch_queue_create("org.darlinghq.audiounit", nullptr);
});
}
@ -145,7 +145,7 @@ void AudioUnitALSA::initOutput()
if (err < 0)
throwAlsaError("Failed to set sample rate", err);
LOG << "Channel count: " << int(alsaConfig.mChannelsPerFrame) << std::endl;
// LOG << "Channel count: " << int(alsaConfig.mChannelsPerFrame) << std::endl;
err = snd_pcm_hw_params_set_channels(m_pcmOutput, hw_params, alsaConfig.mChannelsPerFrame);
if (err < 0)
throwAlsaError("Failed to set channel count", err);
@ -237,7 +237,7 @@ OSStatus AudioUnitALSA::init()
}
catch (const std::exception& e)
{
ERROR() << e.what();
// ERROR() << e.what();
deinit();
return kAudioUnitErr_FailedInitialization;
@ -272,8 +272,8 @@ void AudioUnitALSA::processAudioEvent(struct pollfd origPoll, int event)
pfd.revents = event;
err = snd_pcm_poll_descriptors_revents(m_pcmOutput, &pfd, 1, &revents);
if (err < 0)
ERROR() << "snd_pcm_poll_descriptors_revents() failed: " << snd_strerror(err);
// if (err < 0)
// ERROR() << "snd_pcm_poll_descriptors_revents() failed: " << snd_strerror(err);
if (revents & POLLIN)
pushDataFromInput();
@ -294,7 +294,7 @@ void AudioUnitALSA::requestDataForPlayback()
const AudioStreamBasicDescription& config = m_config[kOutputBus].first;
UInt32 cc = config.mChannelsPerFrame;
TRACE();
// TRACE();
memset(&ts, 0, sizeof(ts));
@ -358,7 +358,7 @@ void AudioUnitALSA::requestDataForPlayback()
if (err != noErr)
{
ERROR() << "Render callback failed with error " << err;
// ERROR() << "Render callback failed with error " << err;
// Fill with silence, the error may be temporary
UInt32 bytes = config.mBytesPerFrame * SAMPLE_PERIOD;
@ -488,7 +488,7 @@ OSStatus AudioUnitALSA::renderInterleavedOutput(AudioUnitRenderActionFlags *ioAc
for (UInt32 i = 0; i < ioData->mNumberBuffers; i++)
{
LOG << "Writing " << ioData->mBuffers[i].mDataByteSize << " bytes into sound card\n";
// LOG << "Writing " << ioData->mBuffers[i].mDataByteSize << " bytes into sound card\n";
sampleCount = std::min<UInt32>(ioData->mBuffers[i].mDataByteSize / config.mBytesPerFrame, inNumberFrames - framesSoFar);
framesSoFar += sampleCount;
@ -502,18 +502,18 @@ do_write:
{
if (wr == -EINTR || wr == -EPIPE)
{
LOG << "Recovering PCM\n";
// LOG << "Recovering PCM\n";
snd_pcm_recover(m_pcmOutput, wr, false);
goto do_write;
}
else
{
ERROR() << "snd_pcm_writei() failed: " << snd_strerror(wr);
// ERROR() << "snd_pcm_writei() failed: " << snd_strerror(wr);
return kAudioUnitErr_NoConnection;
}
}
else if (wr < sampleCount)
ERROR() << "snd_pcm_writei(): not all data written?";
;// ERROR() << "snd_pcm_writei(): not all data written?";
}
return noErr;
@ -527,7 +527,7 @@ OSStatus AudioUnitALSA::renderPlanarOutput(AudioUnitRenderActionFlags *ioActionF
if (ioData->mNumberBuffers != config.mChannelsPerFrame)
{
ERROR() << "Incorrect buffer count for planar audio, only " << ioData->mNumberBuffers;
// ERROR() << "Incorrect buffer count for planar audio, only " << ioData->mNumberBuffers;
return paramErr;
}
@ -536,7 +536,7 @@ OSStatus AudioUnitALSA::renderPlanarOutput(AudioUnitRenderActionFlags *ioActionF
{
if (size != ioData->mBuffers[i].mDataByteSize)
{
ERROR() << "Bad buffer size in buffer " << i;
// ERROR() << "Bad buffer size in buffer " << i;
return paramErr;
}
}
@ -552,18 +552,18 @@ do_write:
{
if (wr == -EINTR || wr == -EPIPE)
{
LOG << "Recovering PCM\n";
// LOG << "Recovering PCM\n";
snd_pcm_recover(m_pcmOutput, wr, false);
goto do_write;
}
else
{
ERROR() << "snd_pcm_writen() failed: " << snd_strerror(wr);
// ERROR() << "snd_pcm_writen() failed: " << snd_strerror(wr);
return kAudioUnitErr_NoConnection;
}
}
else if (wr < sampleCount)
ERROR() << "snd_pcm_writen(): not all data written?";
;// ERROR() << "snd_pcm_writen(): not all data written?";
return noErr;
}
@ -586,7 +586,7 @@ OSStatus AudioUnitALSA::renderInterleavedInput(AudioUnitRenderActionFlags *ioAct
for (UInt32 i = 0; i < ioData->mNumberBuffers; i++)
{
LOG << "Reading up to " << ioData->mBuffers[i].mDataByteSize << " bytes from sound card\n";
// LOG << "Reading up to " << ioData->mBuffers[i].mDataByteSize << " bytes from sound card\n";
sampleCount = ioData->mBuffers[i].mDataByteSize / config.mBytesPerFrame;
@ -601,7 +601,7 @@ do_write:
}
else
{
ERROR() << "snd_pcm_writei() failed: " << snd_strerror(wr);
// ERROR() << "snd_pcm_writei() failed: " << snd_strerror(wr);
return kAudioUnitErr_NoConnection;
}
}
@ -620,7 +620,7 @@ OSStatus AudioUnitALSA::renderPlanarInput(AudioUnitRenderActionFlags *ioActionFl
if (ioData->mNumberBuffers != config.mChannelsPerFrame)
{
ERROR() << "Incorrect buffer count for planar audio, only " << ioData->mNumberBuffers;
// ERROR() << "Incorrect buffer count for planar audio, only " << ioData->mNumberBuffers;
return paramErr;
}
@ -629,7 +629,7 @@ OSStatus AudioUnitALSA::renderPlanarInput(AudioUnitRenderActionFlags *ioActionFl
{
if (size != ioData->mBuffers[i].mDataByteSize)
{
ERROR() << "Bad buffer size in buffer " << i;
// ERROR() << "Bad buffer size in buffer " << i;
return paramErr;
}
}
@ -650,7 +650,7 @@ do_write:
}
else
{
ERROR() << "snd_pcm_writen() failed: " << snd_strerror(wr);
// ERROR() << "snd_pcm_writen() failed: " << snd_strerror(wr);
return kAudioUnitErr_NoConnection;
}
}
@ -679,7 +679,7 @@ void AudioUnitALSA::startOutput()
if (snd_pcm_poll_descriptors(m_pcmOutput, pollfds.get(), count) != count)
throw std::runtime_error("snd_pcm_poll_descriptors() failed");
LOG << "ALSA descriptor count: " << count << std::endl;
// LOG << "ALSA descriptor count: " << count << std::endl;
startDescriptors(pollfds.get(), count);
}
@ -728,7 +728,7 @@ OSStatus AudioUnitALSA::start()
{
int err;
TRACE();
// TRACE();
try
{
@ -746,7 +746,7 @@ OSStatus AudioUnitALSA::start()
if (m_pcmOutput)
snd_pcm_drop(m_pcmOutput);
ERROR() << e.what();
// ERROR() << e.what();
return kAudioUnitErr_FailedInitialization;
}

View File

@ -2,7 +2,7 @@
#define AUCOMPONENTINTERNAL_H
#include "AudioUnit.h"
#include <CoreServices/ComponentsInternal.h>
#include <asoundlib.h>
#include <alsa/asoundlib.h>
#include <dispatch/dispatch.h>
#include <vector>
#include "AudioOutputUnitComponent.h"

View File

@ -2,7 +2,7 @@
#include "AudioUnitProperties.h"
#include "AudioUnitRenderer.h"
#include <CoreServices/MacErrors.h>
#include <util/debug.h>
#include "stub.h"
#include <cstring>
AudioUnitComponent::AudioUnitComponent(std::initializer_list<CFStringRef> elements)
@ -80,7 +80,7 @@ OSStatus AudioUnitComponent::getPropertyInfo(AudioUnitPropertyID prop, AudioUnit
OSStatus AudioUnitComponent::setProperty(AudioUnitPropertyID prop, AudioUnitScope scope, AudioUnitElement elem, const void* data, UInt32 dataSize)
{
TRACE5(prop, scope, elem, data, dataSize);
// TRACE5(prop, scope, elem, data, dataSize);
switch (prop)
{
@ -177,7 +177,7 @@ OSStatus AudioUnitComponent::setProperty(AudioUnitPropertyID prop, AudioUnitScop
OSStatus AudioUnitComponent::getProperty(AudioUnitPropertyID prop, AudioUnitScope scope, AudioUnitElement elem, void* data, UInt32* dataSize)
{
TRACE5(prop, scope, elem, data, dataSize);
// TRACE5(prop, scope, elem, data, dataSize);
switch (prop)
{

View File

@ -7,7 +7,7 @@
#include <sstream>
#include <memory>
#include <cstring>
#include <util/debug.h>
#include "stub.h"
#include <objc/runtime.h>
extern "C" char*** _NSGetArgv(void);
@ -71,7 +71,7 @@ OSStatus AudioUnitPA::initOutput()
if (m_stream == nullptr)
{
ERROR() << "pa_stream_new() failed";
// ERROR() << "pa_stream_new() failed";
return kAudioUnitErr_FailedInitialization;
}
@ -93,15 +93,15 @@ int AudioUnitPA::cardIndex() const
void AudioUnitPA::paStreamStateCB(pa_stream* s, void*)
{
int state = pa_stream_get_state(s);
TRACE() << "state=" << state;
//TRACE() << "state=" << state;
switch (state)
{
case PA_STREAM_FAILED:
ERROR() << "PA stream error: " << pa_strerror(pa_context_errno(pa_stream_get_context(s)));
//ERROR() << "PA stream error: " << pa_strerror(pa_context_errno(pa_stream_get_context(s)));
break;
case PA_STREAM_READY:
LOG << "PA stream is ready\n";
//LOG << "PA stream is ready\n";
break;
}
}
@ -124,11 +124,11 @@ void AudioUnitPA::requestDataForPlayback(size_t length)
if (!m_stream)
{
std::cerr << "No stream?!\n";
// std::cerr << "No stream?!\n";
return;
}
TRACE() << "m_started=" << m_started;
//TRACE() << "m_started=" << m_started;
if (!m_started)
{
@ -210,7 +210,7 @@ void AudioUnitPA::requestDataForPlayback(size_t length)
if (err != noErr || bufs->mBuffers[0].mDataByteSize == 0)
{
ERROR() << "Render callback failed with error " << err;
// ERROR() << "Render callback failed with error " << err;
// Fill with silence, the error may be temporary
UInt32 bytes = length;
@ -244,7 +244,7 @@ void AudioUnitPA::requestDataForPlayback(size_t length)
}
}
LOG << "Rendering...\n";
//LOG << "Rendering...\n";
m_lastRenderError = AudioUnitRender(this, &flags, &ts, kOutputBus, length / config.mBytesPerFrame, bufs);
operator delete(bufs);
@ -280,7 +280,7 @@ OSStatus AudioUnitPA::renderInterleavedOutput(AudioUnitRenderActionFlags *ioActi
if (!bytes)
break;
LOG << "AudioUnitPA::renderInterleavedOutput(): data=" << ioData->mBuffers[i].mData << ", bytes=" << bytes << std::endl;
//LOG << "AudioUnitPA::renderInterleavedOutput(): data=" << ioData->mBuffers[i].mData << ", bytes=" << bytes << std::endl;
pa_stream_write(m_stream, ((char*) ioData->mBuffers[i].mData) + framesSoFar * config.mBytesPerFrame, bytes,
nullptr, 0, PA_SEEK_RELATIVE);
@ -468,7 +468,7 @@ void AudioUnitPA::initializePA()
pa_mainloop_free(m_mainloop);
m_mainloop = nullptr;
ERROR() << e.what();
// ERROR() << e.what();
}
}
@ -519,7 +519,7 @@ void AudioUnitPA::paContextStateCB(pa_context* c, void* priv)
{
Completion* comp = static_cast<Completion*>(priv);
TRACE() << pa_context_get_state(c);
// TRACE() << pa_context_get_state(c);
switch (pa_context_get_state(c))
{
case PA_CONTEXT_READY:

View File

@ -0,0 +1,50 @@
project(AudioToolbox)
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/libcxx/include ${CMAKE_CURRENT_BINARY_DIR})
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../include/AudioToolbox
)
add_definitions(-DENABLE_PULSEAUDIO=1)
set(audiotoolbox_sources
AUComponent.cpp
AudioConverter.cpp
AudioConverterImpl.cpp
AudioFile.cpp
AudioOutputUnitComponent.cpp
AudioQueueBase.cpp
AudioQueue.cpp
AudioQueueOutput.cpp
# AudioUnitALSA.cpp
AudioUnitBase.cpp
AudioUnit.cpp
AudioUnitPA.cpp
AudioUnitRenderer.cpp
AUGraph.cpp
)
add_framework(AudioToolbox
FAT
CURRENT_VERSION
VERSION "A"
SOURCES
${audiotoolbox_sources}
DEPENDENCIES
system
cxx
CoreFoundation
CoreAudio
CoreServices
objc
avformat
avresample
avcodec
avutil
pulse # This should go away in favor of abstraction inside CoreAudio
)
# TODO: Add AudioUnit.framework

View File

@ -0,0 +1,14 @@
#ifndef AT_STUB_H
#define AT_STUB_H
#include <stdio.h>
#ifndef STUB
# define STUB() fprintf(stderr, "AudioToolbox STUB: %s called\n", __FUNCTION__)
#endif
#define TRACE()
#define TRACE1(...)
#define TRACE2(...)
#endif

View File

@ -1,4 +1,23 @@
project(CoreAudio_root)
include(wrap_elf)
add_definitions(-DENABLE_PULSEAUDIO)
find_package(FFmpeg REQUIRED)
find_package(PulseAudio REQUIRED)
include_directories(
${FFMPEG_INCLUDE_DIR}
${PULSEAUDIO_INCLUDE_DIRS}
)
add_definitions(-DHAVE_AV_FRAME_ALLOC=1)
wrap_elf(avresample libavresample.so)
wrap_elf(avcodec libavcodec.so)
wrap_elf(avformat libavformat.so)
wrap_elf(avutil libavutil.so)
#wrap_elf(asound libasound.so)
wrap_elf(pulse libpulse.so)
add_subdirectory(CoreAudio)
#add_subdirectory(AudioToolbox)
add_subdirectory(AudioToolbox)

View File

@ -21,6 +21,7 @@ along with Darling. If not, see <http://www.gnu.org/licenses/>.
#include "AudioHardwareImpl.h"
#include <CoreServices/MacErrors.h>
#include <memory>
#include "stub.h"
static std::unique_ptr<AudioHardwareImpl> g_systemObject;
@ -60,7 +61,7 @@ Boolean AudioObjectHasProperty(AudioObjectID inObjectID,
{
AudioHardwareImpl* obj = GetObject(inObjectID);
if (!obj)
return kAudioHardwareBadObjectError;
return 0;
return obj->hasProperty(inAddress);
}
@ -141,6 +142,7 @@ OSStatus AudioHardwareUnload(void)
OSStatus AudioHardwareCreateAggregateDevice(CFDictionaryRef, AudioObjectID* outDeviceID)
{
STUB();
if (outDeviceID)
*outDeviceID = 0;
@ -149,11 +151,19 @@ OSStatus AudioHardwareCreateAggregateDevice(CFDictionaryRef, AudioObjectID* outD
OSStatus AudioHardwareDestroyAggregateDevice(AudioObjectID inDeviceID)
{
STUB();
return unimpErr;
}
OSStatus AudioHardwareGetProperty(AudioHardwarePropertyID inPropId, UInt32* ioPropertyDataSize, void* outPropertyData)
{
STUB();
return unimpErr;
}
OSStatus AudioHardwareGetPropertyInfo(AudioHardwarePropertyID inPropertyID, UInt32 *outSize, Boolean *outWritable)
{
STUB();
return unimpErr;
}

View File

@ -8,7 +8,7 @@ set(coreaudio_sources
AudioHardwareStream.cpp
)
add_framework(
add_framework(CoreAudio
FAT
CURRENT_VERSION
VERSION "A"

View File

@ -0,0 +1,10 @@
#ifndef CA_STUB_H
#define CA_STUB_H
#include <stdio.h>
#ifndef STUB
# define STUB() fprintf(stderr, "CoreAudio STUB: %s called\n", __FUNCTION__)
#endif
#endif

View File

@ -3,13 +3,21 @@
#include <MacTypes.h>
#include <CoreServices/Components.h>
#include <CoreFoundation/CFString.h>
#include <AudioToolbox/AUGraph.h>
//#include <AudioToolbox/AUGraph.h>
class AudioUnitComponent;
// class AudioUnitComponent;
typedef Component AudioComponent;
typedef ComponentInstance AudioComponentInstance;
typedef ComponentDescription AudioComponentDescription;
// typedef ComponentDescription AudioComponentDescription;
typedef struct AudioComponentDescription {
OSType componentType;
OSType componentSubType;
OSType componentManufacturer;
UInt32 componentFlags;
UInt32 componentFlagsMask;
} AudioComponentDescription;
enum
{

View File

@ -2,6 +2,7 @@
#define AUGRAPH_H
#include <AudioToolbox/AudioUnit.h>
#include <AudioToolbox/AudioUnitProperties.h>
#include <AudioToolbox/AUComponent.h>
#ifdef __cplusplus
extern "C" {