swift
Loading...
Searching...
No Matches
contextaudio.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_CORE_CONTEXT_CONTEXTAUDIO_H
7#define SWIFT_CORE_CONTEXT_CONTEXTAUDIO_H
8
9#include <QCommandLineOption>
10#include <QString>
11
12#include "core/actionbind.h"
16#include "core/corefacade.h"
26#include "misc/identifiable.h"
27#include "misc/identifier.h"
33#include "sound/selcalplayer.h"
34
35// clazy:excludeall=const-signal-or-slot
36
39#define SWIFT_CORE_CONTEXTAUDIO_INTERFACENAME "org.swift_project.swift_core.contextaudio"
40
43#define SWIFT_CORE_CONTEXTAUDIO_OBJECTPATH "/audio"
44
45class QDBusConnection;
46
47namespace swift::misc
48{
49 class CDBusServer;
50}
51namespace swift::core
52{
53 namespace afv::clients
54 {
55 class CAfvClient;
56 }
57 namespace context
58 {
61 {
64
65 friend class swift::core::CCoreFacade;
66
67 public:
69 static const QString &InterfaceName();
70
72 static const QString &ObjectPath();
73
75 QString getPathAndContextId() const override { return this->buildPathAndContextId(ObjectPath()); }
76
78 static IContextAudio *create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode,
79 swift::misc::CDBusServer *server, QDBusConnection &connection);
80
81 // ------------- only use DBus signals here -------------
82 signals:
85
86 public slots:
87 // ------------- DBus ---------------
88
91
94
97
99 virtual void unRegisterDevicesFor(const swift::misc::CIdentifier &identifier) = 0;
100
104 const swift::misc::CIdentifier &identifier) = 0;
105
109 const swift::misc::CIdentifier &identifier) = 0;
110
113 virtual bool hasRegisteredAudioCallsign(const swift::misc::aviation::CCallsign &callsign) const = 0;
114
115 // ------------- DBus ---------------
116
117 protected:
120
123 };
124
127 {
129 friend class swift::core::CCoreFacade;
130
131 protected:
134
135 public:
138
144
150
153
156 void setRxTx(bool rx1, bool tx1, bool rx2, bool tx2);
157 void getRxTx(bool &rx1, bool &tx1, bool &rx2, bool &tx2) const;
159
160 // -------- parts which can run in core and GUI, referring to local voice client ------------
161
168
172
175 const swift::misc::audio::CAudioDeviceInfo &outputDevice);
176
179 void setMasterOutputVolume(int volume);
183 void setOutputMute(bool muted);
184 bool isOutputMuted() const;
186
189
192 bool considerSettings, int volume = -1);
193
196 void enableAudioLoopback(bool enable = true);
199
202
205
208
211
215
217 bool isAudioConnected() const;
218
220 bool isAudioStarted() const;
221
223 bool isAudioEnabled() const { return m_voiceClient != nullptr; }
224
227
229 afv::clients::CAfvClient *afvClient() const { return m_voiceClient; }
230
233
235 static bool isNoAudioSet();
236
238 static void registerHelp()
239 {
240 if (swift::misc::CSimpleCommandParser::registered("swift::core::context::CContextAudioBase"))
241 {
242 return;
243 }
245 swift::misc::CSimpleCommandParser::registerCommand({ ".unmute", "unmute audio" });
246 swift::misc::CSimpleCommandParser::registerCommand({ ".vol volume", "volume 0..100" });
247 }
248
249 // -------- parts which can run in core and GUI, referring to local voice client ------------
250
251 public slots:
252 // ------------- DBus ---------------
253
262 bool parseCommandLine(const QString &commandLine, const swift::misc::CIdentifier &originator) override;
264
265 // ------------- DBus ---------------
266
267 // ------------ local signals -------
268 signals:
271 void changedAudioVolume(int volume);
272
274 void changedOutputMute(bool muted);
275
278
282
285
287 void ptt(bool active, const swift::misc::CIdentifier &identifier);
288
289 // ------------ local signals -------
290
291 private:
293 void initVoiceClient();
294
296 void terminateVoiceClient();
297
299 void setVoiceTransmission(bool enable);
300
302 void changeDeviceSettings();
303
305 void onChangedAudioSettings();
306
309 void audioIncreaseVolume(bool enabled);
310 void audioDecreaseVolume(bool enabled);
311 void audioIncreaseVolumeCom1(bool enabled);
312 void audioDecreaseVolumeCom1(bool enabled);
313 void audioIncreaseVolumeCom2(bool enabled);
314 void audioDecreaseVolumeCom2(bool enabled);
316
318 void xCtxNetworkConnectionStatusChanged(const swift::misc::network::CConnectionStatus &from,
320
322 void onAfvConnectionStatusChanged(int status);
323
325 void onAfvConnectionFailure(const swift::misc::CStatusMessage &msg);
326
327 CActionBind m_actionPtt { swift::misc::input::pttHotkeyAction(), swift::misc::input::pttHotkeyIcon(), this,
328 &CContextAudioBase::setVoiceTransmission };
329 CActionBind m_actionAudioVolumeIncrease { swift::misc::input::audioVolumeIncreaseHotkeyAction(),
330 swift::misc::input::audioVolumeIncreaseHotkeyIcon(), this,
331 &CContextAudioBase::audioIncreaseVolume };
332 CActionBind m_actionAudioVolumeDecrease { swift::misc::input::audioVolumeDecreaseHotkeyAction(),
333 swift::misc::input::audioVolumeDecreaseHotkeyIcon(), this,
334 &CContextAudioBase::audioDecreaseVolume };
335 CActionBind m_actionAudioVolumeIncreaseCom1 { swift::misc::input::audioVolumeIncreaseCom1HotkeyAction(),
336 swift::misc::input::audioVolumeIncreaseHotkeyIcon(), this,
337 &CContextAudioBase::audioIncreaseVolumeCom1 };
338 CActionBind m_actionAudioVolumeDecreaseCom1 { swift::misc::input::audioVolumeDecreaseCom1HotkeyAction(),
339 swift::misc::input::audioVolumeDecreaseHotkeyIcon(), this,
340 &CContextAudioBase::audioDecreaseVolumeCom1 };
341 CActionBind m_actionAudioVolumeIncreaseCom2 { swift::misc::input::audioVolumeIncreaseCom2HotkeyAction(),
342 swift::misc::input::audioVolumeIncreaseHotkeyIcon(), this,
343 &CContextAudioBase::audioIncreaseVolumeCom2 };
344 CActionBind m_actionAudioVolumeDecreaseCom2 { swift::misc::input::audioVolumeDecreaseCom2HotkeyAction(),
345 swift::misc::input::audioVolumeDecreaseHotkeyIcon(), this,
346 &CContextAudioBase::audioDecreaseVolumeCom2 };
347
348 int m_outMasterVolumeBeforeMute = 50;
349 static constexpr int MinUnmuteVolume = 20;
350
352 static bool isRunningWithLocalCore();
353
354 // settings
355 swift::misc::CSetting<swift::misc::audio::TSettings> m_audioSettings {
356 this, &CContextAudioBase::onChangedAudioSettings
357 };
358
359 swift::misc::CSetting<audio::TInputDevice> m_inputDeviceSetting {
360 this, &CContextAudioBase::changeDeviceSettings
361 };
362 swift::misc::CSetting<audio::TOutputDevice> m_outputDeviceSetting {
363 this, &CContextAudioBase::changeDeviceSettings
364 };
365
366 // AFV
367 afv::clients::CAfvClient *m_voiceClient = nullptr;
368 bool m_winCoInitialized = false;
369 swift::misc::audio::CAudioDeviceInfoList m_activeLocalDevices;
370
371 // Players
372 swift::sound::CSelcalPlayer *m_selcalPlayer = nullptr;
373 swift::sound::CNotificationPlayer m_notificationPlayer;
374 };
375 } // namespace context
376} // namespace swift::core
377
378#endif // SWIFT_CORE_CONTEXT_CONTEXTAUDIO_H
CActionBind binds a member function to an action.
Definition actionbind.h:18
ContextMode
How to handle a given context.
The class providing facades (the contexts) for all DBus relevant operations.
Definition corefacade.h:57
bool isAudioLoopbackEnabled() const
Loopback.
void ptt(bool active, const swift::misc::CIdentifier &identifier)
PTT in voice client received.
bool isAudioConnected() const
Is audio connected?
void enableAudioLoopback(bool enable=true)
Loopback.
void gracefulShutdown()
Graceful shutdown.
bool connectAudioWithNetworkCredentials()
Connect to audio with network credentials.
swift::misc::audio::CAudioDeviceInfoList getAudioOutputDevices() const
Audio devices.
bool isAudioStarted() const
Is audio started?
static void registerHelp()
Register the commands.
void setComOutputVolume(swift::misc::aviation::CComSystem::ComUnit comUnit, int volume)
Volume.
bool isTransmittingComUnit(swift::misc::aviation::CComSystem::ComUnit comUnit) const
Is COM unit transmitting?
void changedLocalAudioDevices(const swift::misc::audio::CAudioDeviceInfoList &devices)
Changed audio devices (e.g. device enabled/disable).
swift::misc::audio::CAudioDeviceInfoList getAudioDevices() const
Audio devices.
void changedOutputMute(bool muted)
Output mute changed.
void setCurrentAudioDevices(const swift::misc::audio::CAudioDeviceInfo &inputDevice, const swift::misc::audio::CAudioDeviceInfo &outputDevice)
Set current audio devices.
void setMasterOutputVolume(int volume)
Volume.
QString audioRunsWhereInfo() const
Info string about audio.
void startedAudio(const swift::misc::audio::CAudioDeviceInfo &input, const swift::misc::audio::CAudioDeviceInfo &output)
Audio started with devices.
bool isComUnitIntegrated() const
Integrated with COM unit?
void playSelcalTone(const swift::misc::aviation::CSelcal &selcal)
SELCAL.
swift::misc::audio::CAudioDeviceInfoList getCurrentAudioDevices() const
Get current audio device.
CContextAudioBase & operator=(const CContextAudioBase &)=delete
Copy operations.
afv::clients::CAfvClient * afvClient() const
CContextAudioBase(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime)
Constructor.
int getComOutputVolume(swift::misc::aviation::CComSystem::ComUnit comUnit) const
Volume.
void changedAudioVolume(int volume)
Audio volume changed.
CContextAudioBase & operator=(CContextAudioBase &&)=delete
Move operations.
void setOutputMute(bool muted)
Volume.
bool isAudioEnabled() const
Is audio enabled?
CContextAudioBase(CContextAudioBase &&)=delete
Move operations.
bool isEnabledComUnit(swift::misc::aviation::CComSystem::ComUnit comUnit) const
Is COM unit enabled?
void setRxTx(bool rx1, bool tx1, bool rx2, bool tx2)
Receive/transmit.
const swift::misc::CIdentifier & audioRunsWhere() const
Audio runs where.
void getRxTx(bool &rx1, bool &tx1, bool &rx2, bool &tx2) const
Receive/transmit.
CContextAudioBase(const CContextAudioBase &)=delete
Copy operations.
static const QList< QCommandLineOption > & getCmdLineOptions()
Cmd.line arguments.
void playNotification(swift::misc::audio::CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume=-1)
Notification sounds.
swift::misc::audio::CAudioDeviceInfoList getAudioInputDevices() const
Audio devices.
virtual swift::misc::audio::CAudioDeviceInfoList getRegisteredDevices() const =0
All registered devices.
void onChangedLocalDevices(const swift::misc::audio::CAudioDeviceInfoList &devices)
Devices have been changed.
virtual void unRegisterAudioCallsign(const swift::misc::aviation::CCallsign &callsign, const swift::misc::CIdentifier &identifier)=0
Un-register an audio callsign (used with AFV).
IContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime)
Constructor.
static const QString & InterfaceName()
Interface name.
static const QString & ObjectPath()
Object path.
static IContextAudio * create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode, swift::misc::CDBusServer *server, QDBusConnection &connection)
Factory method.
virtual void registerDevices(const swift::misc::audio::CAudioDeviceInfoList &devices)=0
Register a device on a machine (for core/GUI it will return all known devices on all machines).
virtual void unRegisterDevices(const swift::misc::audio::CAudioDeviceInfoList &devices)=0
Unregister devices.
QString getPathAndContextId() const
Id and path name for round trip protection.
virtual void registerAudioCallsign(const swift::misc::aviation::CCallsign &callsign, const swift::misc::CIdentifier &identifier)=0
Register an audio callsign (used with AFV).
virtual void unRegisterDevicesFor(const swift::misc::CIdentifier &identifier)=0
Remove all devices for identifier (i.e. "a machine").
void voiceClientFailure(const swift::misc::CStatusMessage &msg)
Authentication failed, ....
virtual bool hasRegisteredAudioCallsign(const swift::misc::aviation::CCallsign &callsign) const =0
Un-register an audio callsign (used with AFV).
IContext(CCoreFacadeConfig::ContextMode mode, QObject *parent)
Constructor.
Definition context.cpp:20
QString buildPathAndContextId(const QString &path) const
Path and context id.
Definition context.h:135
Custom DBusServer.
Definition dbusserver.h:34
Base class with a member CIdentifier to be inherited by a class which has an identity in the environm...
const CIdentifier & identifier() const
Get identifier.
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition identifier.h:29
static void registerCommand(const CommandHtmlHelp &command)
Register a command.
static bool registered(const QString &helpContext)
Help already registered.
Streamable status message, e.g.
Value object encapsulating information of a audio device.
Value object encapsulating a list of audio devices.
Value object encapsulating information of a callsign.
Definition callsign.h:30
Value object for SELCAL.
Definition selcal.h:31
Value object encapsulating information about a connection status.
#define SWIFT_CORE_CONTEXTAUDIO_INTERFACENAME
DBus interface for context.
Backend services of the swift project, like dealing with the network or the simulators.
Definition actionbind.cpp:7
Free functions in swift::misc.
Q_CLASSINFO(Name, Value)
Q_OBJECTQ_OBJECT
#define SWIFT_CORE_EXPORT
Export a class or function from the library.