[client] audio: allow microphone recording to be toggled after dialog

This commit is contained in:
Quantum 2022-05-21 23:52:56 -04:00 committed by Geoffrey McRae
parent 146d9a2a53
commit 7e8849180d
3 changed files with 55 additions and 7 deletions

View File

@ -118,12 +118,16 @@ typedef struct
struct
{
bool requested;
bool started;
int volumeChannels;
uint16_t volume[8];
bool mute;
int stride;
uint32_t time;
int lastChannels;
int lastSampleRate;
PSAudioFormat lastFormat;
MsgBoxHandle confirmHandle;
int confirmChannels;
int confirmSampleRate;
@ -803,8 +807,10 @@ void audio_recordStart(int channels, int sampleRate, PSAudioFormat format)
return;
}
lastChannels = channels;
lastSampleRate = sampleRate;
audio.record.requested = true;
audio.record.lastChannels = channels;
audio.record.lastSampleRate = sampleRate;
audio.record.lastFormat = format;
if (audio.record.started)
realRecordStart(channels, sampleRate, format);
@ -830,12 +836,8 @@ void audio_recordStart(int channels, int sampleRate, PSAudioFormat format)
}
}
void audio_recordStop(void)
static void realRecordStop(void)
{
if (!audio.audioDev || !audio.record.started)
return;
DEBUG_INFO("Microphone recording stopped");
audio.audioDev->record.stop();
audio.record.started = false;
@ -843,6 +845,43 @@ void audio_recordStop(void)
app_showRecord(false);
}
void audio_recordStop(void)
{
audio.record.requested = false;
if (!audio.audioDev || !audio.record.started)
return;
DEBUG_INFO("Microphone recording stopped");
realRecordStop();
}
void audio_recordToggleKeybind(int sc, void * opaque)
{
if (!audio.audioDev)
return;
if (!audio.record.requested)
{
app_alert(LG_ALERT_WARNING,
"No application is requesting microphone access.");
return;
}
if (audio.record.started)
{
app_alert(LG_ALERT_INFO, "Microphone disabled");
DEBUG_INFO("Microphone recording stopped by user");
realRecordStop();
}
else
{
app_alert(LG_ALERT_INFO, "Microphone enabled");
DEBUG_INFO("Microphone recording started by user");
realRecordStart(audio.record.lastChannels, audio.record.lastSampleRate,
audio.record.lastFormat);
}
}
void audio_recordVolume(int channels, const uint16_t volume[])
{
if (!audio.audioDev || !audio.audioDev->record.volume)

View File

@ -36,6 +36,7 @@ void audio_playbackData(uint8_t * data, size_t size);
bool audio_supportsRecord(void);
void audio_recordStart(int channels, int sampleRate, PSAudioFormat format);
void audio_recordToggleKeybind(int sc, void * opaque);
void audio_recordStop(void);
void audio_recordVolume(int channels, const uint16_t volume[]);
void audio_recordMute(bool mute);

View File

@ -22,6 +22,7 @@
#include "main.h"
#include "app.h"
#include "audio.h"
#include "core.h"
#include "kb.h"
@ -174,6 +175,13 @@ void keybind_spiceRegister(void)
app_releaseKeybind(&handles[i]);
handleCount = 0;
#if ENABLE_AUDIO
if (audio_supportsRecord())
{
app_registerKeybind(KEY_E, audio_recordToggleKeybind, NULL,
"Toggle audio recording");
}
#endif
/* register OS based keybinds */
if (app_guestIsLinux())