AVAudioSessionManager availableInputs "Unknown selected data source for port iPhone Microphone"

StackOverflow https://stackoverflow.com/questions/21116216

  •  28-09-2022
  •  | 
  •  

Question

I've noticed this error in my console log for a while. Though it does not affect the execution of my application, I find it really annoying. Thus, I started to trace where this error came from. It turns out when I call availableInputs

NSArray *inputs = [[AVAudioSession sharedInstance] availableInputs];

It will give me the log message:

ERROR:     [0x3d61318c] AVAudioSessionPortImpl.mm:50: ValidateRequiredFields: Unknown selected data source for Port iPhone Microphone (type: MicrophoneBuiltIn)

I tried to print out the inputs..

Printing description of inputs:
<__NSArrayI 0x188c4610>(
<AVAudioSessionPortDescription: 0x188c4580, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = (null)>,
<AVAudioSessionPortDescription: 0x18835d90, type = BluetoothHFP; name = Valore-BTi22; UID = 00:23:01:10:38:77-tsco; selectedDataSource = (null)>

So selectedDataSource is (null). I don't know what should I do to make it not null? iPhone Microphone is a built-in input... I suppose it's set by Apple already?

Was it helpful?

Solution

This problem seems not just happen to me... I will just share my understanding here..

My situation is.. I'm using pjsip library, which has a lower level control of audio resources. I've noticed that, the sound device has been closed before I call [[AVAudioSession sharedInstance] availableInputs];

Thus, (I guess) AVAudioSession, as a higher level control, couldn't find corresponding audio data source for its input - as the error indicated...

To further investigate the problem, you'd better check somewhere in your code that modify the audio source.. and make sure the audio source is activated before you call AVAudioSession

I can only go this far for now... Deeper understanding and better explanation of audio control is always appreciated!!

OTHER TIPS

Regarding the error in your console, I can also confirm that I sometimes receive this message when using my iPhone 5S, but I've never seen it on my 4S. It could just be some core audio dump, but it doesn't seem to affect actual performance (at least for me).

Regarding the available inputs, what your actually printing out is the available input ports and their descriptions. This bit is more confusing and I don't understand why the selectedDataSource field is null for each one.

I will say that the iPhone is definitely defaulting to one of those sources (probably the Built-in Mic) regardless of what the selectedDataSource is saying.

Now if you wanted to explicitly select one of the port descriptions you could do something like this:

NSArray *availableInputs = [[AVAudioSession sharedInstance] availableInputs];
AVAudioSessionPortDescription *port = [availableInputs objectAtIndex:0];  //built in mic for your case
NSError *portErr = nil;
[[AVAudioSession sharedInstance] setPreferredInput:port error:&portErr];

and I would check portErr afterwards to make sure there's no error in setting the preferredInput.

Its worth noting that you can also cycle through the available dataSources for a particular Port Description as well and select one using

[port setPreferredDataSource:source error:&sourceErr];

then follow that with:

[[AVAudioSession sharedInstance] setPreferredInput:port error:&portErr];

These are some handy iOS7 only features that take advantage of hardware with multiple built-in mice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top