我想使用 将 AUGraph 的输出编码为 AAC(在 iOS 5.1 上)。图的基本拓扑如下所示:
inputs --> MixerUnit --> pcm2aac --> aac2pcm --> RemoteIO
我想在通过 PostRenderCallback 播放时获取 AAC 编码的数据,pcm2aac
然后通过 UDP 将其发送到我们的服务器应用程序。
据我了解,此用例的首选 AudioUnit 是kAudioUnitType_FormatConverter
,但是当我想为 aac2pcm 设置 ASBD 输入属性时,AudioUnitSetProperty 失败并显示 -10868(当我设置 pcm2acc 的输出时它也会失败,并出现相同的错误)。
AudioComponentDescription converterUnitDescription;
converterUnitDescription.componentType = kAudioUnitType_FormatConverter;
converterUnitDescription.componentSubType = kAudioUnitSubType_AUConverter;
converterUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
converterUnitDescription.componentFlags = 0;
converterUnitDescription.componentFlagsMask = 0;
//...
AUNode pcm2aacNode;
AUNode aac2pcmNode;
//...
result = AUGraphAddNode (
processingGraph,
&converterUnitDescription,
&aac2pcmNode
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Converter unit" withStatus: result]; return;}
//...
result = AUGraphOpen (processingGraph);
if (noErr != result) {[self printErrorMessage: @"AUGraphOpen" withStatus: result]; return;}
//...
AudioUnit aac2pcmUnit;
AudioUnit pcm2aacUnit;
//...
result = AUGraphNodeInfo (
processingGraph,
aac2pcmNode,
NULL,
&aac2pcmUnit
);
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo (aac2pcm)" withStatus: result]; return;}
//...
NSLog (@"Setting stream format for input aac2pcm bus");
result = AudioUnitSetProperty (aac2pcmUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
0,
&aacStreamFormat,
sizeof (aacStreamFormat)
);
if (noErr != result) {[self printErrorMessage: @"AudioUnitSetProperty (input aac2pcm stream format)" withStatus: result];return;}
// returns -10868
aacStreamFormat
在哪里
memset(&aacStreamFormat, 0, sizeof(aacStreamFormat));/
UInt32 size = sizeof(aacStreamFormat);
aacStreamFormat.mFormatID = kAudioFormatMPEG4AAC;
aacStreamFormat.mChannelsPerFrame = 2;
aacStreamFormat.mFormatFlags = kMPEG4Object_AAC_Main;
aacStreamFormat.mSampleRate = graphSampleRate; //44100
AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &size, &aacStreamFormat);
AUGraph 甚至可以进行这种转换,还是我必须使用其他方法进行实时转换?