{"action":"created","issue":{"url":"https://api.github.com/repos/BelledonneCommunications/linphone-iphone/issues/331","repository_url":"https://api.github.com/repos/BelledonneCommunications/linphone-iphone","labels_url":"https://api.github.com/repos/BelledonneCommunications/linphone-iphone/issues/331/labels{/name}","comments_url":"https://api.github.com/repos/BelledonneCommunications/linphone-iphone/issues/331/comments","events_url":"https://api.github.com/repos/BelledonneCommunications/linphone-iphone/issues/331/events","html_url":"https://github.com/BelledonneCommunications/linphone-iphone/issues/331","id":265469419,"number":331,"title":"Audio Session related issue in CallKit","user":{"login":"StarTeleLogic","id":2115518,"avatar_url":"https://avatars0.githubusercontent.com/u/2115518?v=4","gravatar_id":"","url":"https://api.github.com/users/StarTeleLogic","html_url":"https://github.com/StarTeleLogic","followers_url":"https://api.github.com/users/StarTeleLogic/followers","following_url":"https://api.github.com/users/StarTeleLogic/following{/other_user}","gists_url":"https://api.github.com/users/StarTeleLogic/gists{/gist_id}","starred_url":"https://api.github.com/users/StarTeleLogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StarTeleLogic/subscriptions","organizations_url":"https://api.github.com/users/StarTeleLogic/orgs","repos_url":"https://api.github.com/users/StarTeleLogic/repos","events_url":"https://api.github.com/users/StarTeleLogic/events{/privacy}","received_events_url":"https://api.github.com/users/StarTeleLogic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-10-14T06:38:26Z","updated_at":"2017-10-16T05:36:28Z","closed_at":null,"author_association":"NONE","body":"I am facing issue in CallKit integration. Actually issue is coming after updating OS version to iOS 11.01.\r\nI have implemented CallKit as per Apple guided in their SpeakerBox example step by step.\r\n\r\nVery first time It works fine but in subsequent runs It fails to give voice in earphone. The exact issue is that there is an inconsistency related to audio session means I am not able to use mic to catch voice and the user on other end not able to listen my voice.\r\n\r\nAll the delegates provided in Provider Class are calling very well. Audio Class instance is also available each time I run. Only issue seems with the creation of Audio session using It's shared instance. I notices that It fires AVAudioSessionRouteChangeNotification frequently and switch-case goes in the case of AVAudioSessionRouteChangeReasonCategoryChange. When I print category type- It gives right selected category named AVAudioSessionCategoryPlayAndRecord.\r\n\r\nLet you know that If I put break point in switch-case then It works fine. May be at that point It got enough time to create Audio Session to catch the voice through mic.\r\n\r\nSharing the code where I am setting up audio session:\r\n\r\n- (void)setupAudioSession\r\n{\r\n    try {\r\n        // Configure the audio session\r\n        AVAudioSession *sessionInstance = [AVAudioSession sharedInstance];\r\n        // we are going to play and record so we pick that category\r\n        NSError *error = nil;\r\n        [sessionInstance setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];\r\n        XThrowIfError((OSStatus)error.code, \"couldn't set session's audio category\");\r\n\r\n        // set the mode to voice chat\r\n        [sessionInstance setMode:AVAudioSessionModeVoiceChat error:&error];\r\n        XThrowIfError((OSStatus)error.code, \"couldn't set session's audio mode\");\r\n\r\n        // set the buffer duration to 5 ms\r\n        NSTimeInterval bufferDuration = .005;\r\n        [sessionInstance setPreferredIOBufferDuration:bufferDuration error:&error];\r\n        XThrowIfError((OSStatus)error.code, \"couldn't set session's I/O buffer duration\");\r\n\r\n        // set the session's sample rate\r\n        [sessionInstance setPreferredSampleRate:44100 error:&error];\r\n        XThrowIfError((OSStatus)error.code, \"couldn't set session's preferred sample rate\");\r\n\r\n        // add interruption handler\r\n        [[NSNotificationCenter defaultCenter] addObserver:self\r\n                                                 selector:@selector(handleInterruption:)\r\n                                                     name:AVAudioSessionInterruptionNotification\r\n                                                   object:sessionInstance];\r\n\r\n        // we don't do anything special in the route change notification\r\n        [[NSNotificationCenter defaultCenter] addObserver:self\r\n                                                 selector:@selector(handleRouteChange:)\r\n                                                     name:AVAudioSessionRouteChangeNotification\r\n                                                   object:sessionInstance];\r\n\r\n        // if media services are reset, we need to rebuild our audio chain\r\n        [[NSNotificationCenter defaultCenter]   addObserver:    self\r\n                                                 selector:      @selector(handleMediaServerReset:)\r\n                                                     name:      AVAudioSessionMediaServicesWereResetNotification\r\n                                                   object:      sessionInstance];\r\n    }\r\n\r\n    catch (CAXException &e) {\r\n        NSLog(@\"Error returned from setupAudioSession: %d: %s\", (int)e.mError, e.mOperation);\r\n    }\r\n    catch (...) {\r\n        NSLog(@\"Unknown error returned from setupAudioSession\");\r\n    }\r\n\r\n    return;\r\n}\r\n\r\n\r\nBelow are the method with switch-cases which gets called in case of notification name :AVAudioSessionRouteChangeNotification is fired:\r\n\r\n- (void)handleRouteChange:(NSNotification *)notification\r\n{\r\n    UInt8 reasonValue = [[notification.userInfo valueForKey:AVAudioSessionRouteChangeReasonKey] intValue];\r\n    AVAudioSessionRouteDescription *routeDescription = [notification.userInfo valueForKey:AVAudioSessionRouteChangePreviousRouteKey];\r\n\r\n    NSLog(@\"Route change:\");\r\n    switch (reasonValue) {\r\n        case AVAudioSessionRouteChangeReasonNewDeviceAvailable:\r\n            NSLog(@\"     NewDeviceAvailable\");\r\n            break;\r\n        case AVAudioSessionRouteChangeReasonOldDeviceUnavailable:\r\n            NSLog(@\"     OldDeviceUnavailable\");\r\n            break;\r\n        case AVAudioSessionRouteChangeReasonCategoryChange:\r\n            NSLog(@\"     CategoryChange\");\r\n            NSLog(@\" New Category: %@\", [[AVAudioSession sharedInstance] category]);\r\n            [self setupAudioSession];\r\n            break;\r\n        case AVAudioSessionRouteChangeReasonOverride:\r\n            NSLog(@\"     Override\");\r\n            break;\r\n        case AVAudioSessionRouteChangeReasonWakeFromSleep:\r\n            NSLog(@\"     WakeFromSleep\");\r\n            break;\r\n        case AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory:\r\n            NSLog(@\"     NoSuitableRouteForCategory\");\r\n            break;\r\n        default:\r\n            NSLog(@\"     ReasonUnknown\");\r\n    }\r\n\r\n    NSLog(@\"Previous route:\\n\");\r\n    NSLog(@\"%@\", routeDescription);\r\n}\r\n\r\nPLEASE NOTE THAT EVERY THING WORKS FINE IF I PUT BREAK POINT IN ABOVE METHOD'S CASE- AVAudioSessionRouteChangeReasonCategoryChange !!!"},"comment":{"url":"https://api.github.com/repos/BelledonneCommunications/linphone-iphone/issues/comments/336785090","html_url":"https://github.com/BelledonneCommunications/linphone-iphone/issues/331#issuecomment-336785090","issue_url":"https://api.github.com/repos/BelledonneCommunications/linphone-iphone/issues/331","id":336785090,"user":{"login":"alqa-dash","id":26222875,"avatar_url":"https://avatars1.githubusercontent.com/u/26222875?v=4","gravatar_id":"","url":"https://api.github.com/users/alqa-dash","html_url":"https://github.com/alqa-dash","followers_url":"https://api.github.com/users/alqa-dash/followers","following_url":"https://api.github.com/users/alqa-dash/following{/other_user}","gists_url":"https://api.github.com/users/alqa-dash/gists{/gist_id}","starred_url":"https://api.github.com/users/alqa-dash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alqa-dash/subscriptions","organizations_url":"https://api.github.com/users/alqa-dash/orgs","repos_url":"https://api.github.com/users/alqa-dash/repos","events_url":"https://api.github.com/users/alqa-dash/events{/privacy}","received_events_url":"https://api.github.com/users/alqa-dash/received_events","type":"User","site_admin":false},"created_at":"2017-10-16T05:36:28Z","updated_at":"2017-10-16T05:36:28Z","author_association":"NONE","body":"Looks like this problem is connected to AirPlay 2 functionality in iOS 11. The only thing I found is when I use setCategory(_:mode:routeSharingPolicy:options:) sometimes I can hear sound in first call after app restart but definitely not in second and following calls. In app log I saw following:\r\n\r\n2017-10-15 22:54:04.482293  [aurioc] 892: failed: '!pri' (enable 3, outf< 1 ch,   8000 Hz, Int16> inf< 1 ch,   8000 Hz, Int16>)\r\n2017-10-15 22:54:04:482 ortp-error-Cannot start audioUnit because [!pri]\r\n2017-10-15 22:54:04:482 ortp-error-AudioUnit error for AudioUnitInitialize(card->io_unit): ret=unknown error (561017449) \r\n\r\nUnfortunately I don't know how to handle this error. May be someone can help here?"}}
{"actor":{"display_login":"alqa-dash"}}