1

I'm using Linphone SDK for a VoIP iOS app. And I found the proximity sensor (the one that will dim your screen when you put the phone close to ear) affects the incoming voice badly.

I found The inBusNumber for input render callback will increase to 1024 when the proximity is covered, normally it's 256. When it happens it also cause about 180ms time gap that Audio Unit doesn't trigger this callback, which destroy Linphone's buffer strategy.

setup render callback:

AURenderCallbackStruct renderCallbackStruct;
renderCallbackStruct.inputProc       = au_write_cb;
renderCallbackStruct.inputProcRefCon = card;
auresult=AudioUnitSetProperty (
                               card->io_unit,
                               kAudioUnitProperty_SetRenderCallback,
                               kAudioUnitScope_Input,
                               outputBus,
                               &renderCallbackStruct,
                               sizeof (renderCallbackStruct)
                               );

In the render callback:

static OSStatus au_write_cb (
                          void                        *inRefCon,
                          AudioUnitRenderActionFlags  *ioActionFlags,
                          const AudioTimeStamp        *inTimeStamp,
                          UInt32                      inBusNumber,
                          //it changes to 1024 when proximity sensor is triggered
                          UInt32                      inNumberFrames,
                          AudioBufferList             *ioData
                         ) {}

In my understanding the inNumberFrames will only change in circumstance of switching playback devices (such as switching earphone to bluetooth). Is there any way that I can fix this figure when the proximity sensor is triggered?

I also try to set kAudioUnitProperty_MaximumFramesPerSlice to 256 and setPreferredIOBufferDuration of audio session, but both don't work.

I download Apple official demo named Speakerbox, and I found their render callback's inNumberFrames persists to 256 no matter how I trigger the proximity sensor. I compared the Apple's code and mine but I can't find any difference that may cause this. Appreciate any help, thank you.

steven
  • 1,237
  • 2
  • 11
  • 13

1 Answers1

2

Your understanding is incorrect. iOS can change inNumberFrames for other reasons, such as for currently running app life cycle state(s), and for power management changes. An app's audio unit buffer management strategy needs to tolerate such changes in buffer size, such as by audio dropout/error concealment or resynchronization.

As for differences in iOS buffer size behavior, those might be modified by the app's choice of audio unit, audio session type and options, and background mode options.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • 1
    Thank you for your reply. I have already found a way to make it less aggressive (which is done on apple official demo), by limiting the Preferred Hardware IO Buffer Duration to 20ms. Now it is not affected by proximity sensor or app's background state XD. – steven May 11 '18 at 09:50