[client] audio: refactor audio to playback and add record funcs

This commit is contained in:
Geoffrey McRae 2022-01-06 22:47:22 +11:00
parent 34e5f7e968
commit e6bd36ec7c
5 changed files with 75 additions and 54 deletions

View File

@ -264,9 +264,12 @@ struct LG_AudioDevOps LGAD_PipeWire =
.name = "PipeWire", .name = "PipeWire",
.init = pipewire_init, .init = pipewire_init,
.free = pipewire_free, .free = pipewire_free,
.playback =
{
.start = pipewire_start, .start = pipewire_start,
.play = pipewire_play, .play = pipewire_play,
.stop = pipewire_stop, .stop = pipewire_stop,
.volume = pipewire_volume, .volume = pipewire_volume,
.mute = pipewire_mute .mute = pipewire_mute
}
}; };

View File

@ -346,9 +346,12 @@ struct LG_AudioDevOps LGAD_PulseAudio =
.name = "PulseAudio", .name = "PulseAudio",
.init = pulseaudio_init, .init = pulseaudio_init,
.free = pulseaudio_free, .free = pulseaudio_free,
.playback =
{
.start = pulseaudio_start, .start = pulseaudio_start,
.play = pulseaudio_play, .play = pulseaudio_play,
.stop = pulseaudio_stop, .stop = pulseaudio_stop,
.volume = pulseaudio_volume, .volume = pulseaudio_volume,
.mute = pulseaudio_mute .mute = pulseaudio_mute
}
}; };

View File

@ -38,7 +38,9 @@ struct LG_AudioDevOps
/* final free */ /* final free */
void (*free)(void); void (*free)(void);
/* setup the playback audio stream struct
{
/* start the playback audio stream
* Note: currently SPICE only supports S16 samples so always assume so * Note: currently SPICE only supports S16 samples so always assume so
*/ */
void (*start)(int channels, int sampleRate); void (*start)(int channels, int sampleRate);
@ -56,14 +58,27 @@ struct LG_AudioDevOps
/* [optional] called to set muting of the output */ /* [optional] called to set muting of the output */
void (*mute)(bool mute); void (*mute)(bool mute);
}
playback;
struct
{
/* start the record stream
* Note: currently SPICE only supports S16 samples so always assume so
*/
void (*start)(int channels, int sampleRate,
void (*dataFn)(uint8_t * data, int size));
/* called when SPICE reports the audio stream has stopped */
void (*stop)(void);
/* [optional] called to set the volume of the channels */
void (*volume)(int channels, const uint16_t volume[]);
/* [optional] called to set muting of the input */
void (*mute)(bool mute);
}
record;
}; };
#define ASSERT_LG_AUDIODEV_VALID(x) \
DEBUG_ASSERT((x)->name ); \
DEBUG_ASSERT((x)->init ); \
DEBUG_ASSERT((x)->free ); \
DEBUG_ASSERT((x)->start ); \
DEBUG_ASSERT((x)->play ); \
DEBUG_ASSERT((x)->stop );
#endif #endif

View File

@ -765,7 +765,7 @@ int main_frameThread(void * unused)
return 0; return 0;
} }
void audioStart(int channels, int sampleRate, PSAudioFormat format, void playbackStart(int channels, int sampleRate, PSAudioFormat format,
uint32_t time) uint32_t time)
{ {
/* /*
@ -795,46 +795,46 @@ void audioStart(int channels, int sampleRate, PSAudioFormat format,
static int lastChannels = 0; static int lastChannels = 0;
static int lastSampleRate = 0; static int lastSampleRate = 0;
if (g_state.audioStarted) if (g_state.playbackStarted)
{ {
if (channels != lastChannels || sampleRate != lastSampleRate) if (channels != lastChannels || sampleRate != lastSampleRate)
g_state.audioDev->stop(); g_state.audioDev->playback.stop();
else else
return; return;
} }
lastChannels = channels; lastChannels = channels;
lastSampleRate = sampleRate; lastSampleRate = sampleRate;
g_state.audioStarted = true; g_state.playbackStarted = true;
DEBUG_INFO("%d channels @ %dHz", channels, sampleRate); DEBUG_INFO("%d channels @ %dHz", channels, sampleRate);
g_state.audioDev->start(channels, sampleRate); g_state.audioDev->playback.start(channels, sampleRate);
} }
} }
static void audioStop(void) static void playbackStop(void)
{ {
if (g_state.audioDev) if (g_state.audioDev)
g_state.audioDev->stop(); g_state.audioDev->playback.stop();
g_state.audioStarted = false; g_state.playbackStarted = false;
} }
static void audioVolume(int channels, const uint16_t volume[]) static void playbackVolume(int channels, const uint16_t volume[])
{ {
if (g_state.audioDev && g_state.audioDev->volume) if (g_state.audioDev && g_state.audioDev->playback.volume)
g_state.audioDev->volume(channels, volume); g_state.audioDev->playback.volume(channels, volume);
} }
static void audioMute(bool mute) static void playbackMute(bool mute)
{ {
if (g_state.audioDev && g_state.audioDev->mute) if (g_state.audioDev && g_state.audioDev->playback.mute)
g_state.audioDev->mute(mute); g_state.audioDev->playback.mute(mute);
} }
static void audioData(uint8_t * data, size_t size) static void playbackData(uint8_t * data, size_t size)
{ {
if (g_state.audioDev) if (g_state.audioDev)
g_state.audioDev->play(data, size); g_state.audioDev->playback.play(data, size);
} }
static void checkUUID(void) static void checkUUID(void)
@ -900,11 +900,11 @@ int spiceThread(void * arg)
.playback = .playback =
{ {
.enable = g_params.useSpiceAudio, .enable = g_params.useSpiceAudio,
.start = audioStart, .start = playbackStart,
.volume = audioVolume, .volume = playbackVolume,
.mute = audioMute, .mute = playbackMute,
.stop = audioStop, .stop = playbackStop,
.data = audioData .data = playbackData
} }
}; };

View File

@ -141,7 +141,7 @@ struct AppState
bool autoIdleInhibitState; bool autoIdleInhibitState;
struct LG_AudioDevOps * audioDev; struct LG_AudioDevOps * audioDev;
bool audioStarted; bool playbackStarted;
}; };
struct AppParams struct AppParams