| 1 |
/* |
| 2 |
* Copyright (C) 2024 Piotr BrzeziĆski <[email protected]> |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Library General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Library General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Library General Public |
| 15 |
* License along with this library; if not, write to the |
| 16 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 17 |
* Boston, MA 02110-1301, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "gstiosaudiosession.h" |
| 21 |
#include <AVFAudio/AVFAudio.h> |
| 22 |
|
| 23 |
// Default according to: https://developer.apple.com/documentation/avfaudio/avaudiosessioncategorysoloambient |
| 24 |
#define DEFAULT_CAT AVAudioSessionCategorySoloAmbient |
| 25 |
|
| 26 |
void |
| 27 |
gst_ios_audio_session_setup (gboolean is_src) |
| 28 |
{ |
| 29 |
AVAudioSession *session = [AVAudioSession sharedInstance]; |
| 30 |
|
| 31 |
/* This is just a quick best effort setup. |
| 32 |
* In any serious applications, you should disable configure-session |
| 33 |
* and handle AVAudioSession setup yourself. */ |
| 34 |
|
| 35 |
if (is_src) { |
| 36 |
/* For mic capture, let's use PlayAndRecord as that allows simultaneous playback and recording |
| 37 |
* We don't have to check if a sink (output) already set a category, as the behaviour will not |
| 38 |
* change in PlayAndRecord. */ |
| 39 |
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:NULL]; |
| 40 |
} else if ([session category] == DEFAULT_CAT) { |
| 41 |
/* For output, let's just use Playback, but only if a src element didn't set things up first */ |
| 42 |
[session setCategory:AVAudioSessionCategoryPlayback error:NULL]; |
| 43 |
} |
| 44 |
|
| 45 |
[session setActive:YES error:NULL]; |
| 46 |
} |