Ring Daemon 16.0.0
Loading...
Searching...
No Matches
osx/corelayer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef CORE_LAYER_H_
19#define CORE_LAYER_H_
20
21#include "audio/audiolayer.h"
22#include <AudioToolbox/AudioToolbox.h>
23
24#define checkErr(err) \
25 if (err) { \
26 OSStatus error = static_cast<OSStatus>(err); \
27 fprintf(stdout, "CoreAudio Error: %ld -> %s: %d\n", (long) error, __FILE__, __LINE__); \
28 fflush(stdout); \
29 }
30
36namespace jami {
37
38class RingBuffer;
39class AudioDevice;
40
41class CoreLayer : public AudioLayer
42{
43public:
46
51 virtual std::vector<std::string> getCaptureDeviceList() const;
52 virtual std::vector<std::string> getPlaybackDeviceList() const;
53
54 virtual int getAudioDeviceIndex(const std::string& name, AudioDeviceType type) const;
55 virtual std::string getAudioDeviceName(int index, AudioDeviceType type) const;
56
61 virtual int getIndexCapture() const { return indexIn_; }
62
67 virtual int getIndexPlayback() const { return indexOut_; }
68
73 virtual int getIndexRingtone() const { return indexRing_; }
74
79
87
89
96
97private:
99
100 void initAudioFormat();
101
102 static OSStatus outputCallback(void* inRefCon,
108
114
115 static OSStatus inputCallback(void* inRefCon,
121 static OSStatus deviceIsAliveCallback(AudioObjectID inObjectID,
124 void* inRefCon);
125 static OSStatus devicesChangedCallback(AudioObjectID inObjectID,
128 void* inRefCon);
129
135
136 virtual void updatePreference(AudioPreference& pref, int index, AudioDeviceType type);
137
141 int indexIn_;
142
146 int indexOut_;
147
151 int indexRing_;
152
153 AudioUnit ioUnit_;
154
155 Float64 inSampleRate_;
156 UInt32 inChannelsPerFrame_;
157 Float64 outSampleRate_;
158 UInt32 outChannelsPerFrame_;
159
160 std::vector<AudioDevice> getDeviceList(bool getCapture) const;
161};
162
163} // namespace jami
164
165#endif // CORE_LAYER_H_
Main sound class.
virtual int getAudioDeviceIndex(const std::string &name, AudioDeviceType type) const
void initAudioLayerIO(AudioDeviceType stream)
Configure the AudioUnit.
virtual std::vector< std::string > getCaptureDeviceList() const
Scan the sound card available on the system.
void destroyAudioLayer()
virtual std::vector< std::string > getPlaybackDeviceList() const
virtual int getIndexCapture() const
Get the index of the audio card for capture.
virtual std::string getAudioDeviceName(int index, AudioDeviceType type) const
virtual void stopStream(AudioDeviceType stream=AudioDeviceType::ALL)
Stop the playback and capture streams.
virtual int getIndexPlayback() const
Get the index of the audio card for playback.
virtual void startStream(AudioDeviceType stream=AudioDeviceType::ALL)
Start the capture stream and prepare the playback stream.
virtual int getIndexRingtone() const
Get the index of the audio card for ringtone (could be differnet from playback)
CoreLayer(const AudioPreference &pref)
void emitSignal(Args... args)
Definition ring_signal.h:64
AudioDeviceType
Definition audiolayer.h:58
#define NON_COPYABLE(ClassName)
Definition noncopyable.h:30