mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-12 17:38:19 +00:00
[client] audio: refactor audio
to playback
and add record
funcs
This commit is contained in:
parent
34e5f7e968
commit
e6bd36ec7c
@ -264,9 +264,12 @@ struct LG_AudioDevOps LGAD_PipeWire =
|
||||
.name = "PipeWire",
|
||||
.init = pipewire_init,
|
||||
.free = pipewire_free,
|
||||
.start = pipewire_start,
|
||||
.play = pipewire_play,
|
||||
.stop = pipewire_stop,
|
||||
.volume = pipewire_volume,
|
||||
.mute = pipewire_mute
|
||||
.playback =
|
||||
{
|
||||
.start = pipewire_start,
|
||||
.play = pipewire_play,
|
||||
.stop = pipewire_stop,
|
||||
.volume = pipewire_volume,
|
||||
.mute = pipewire_mute
|
||||
}
|
||||
};
|
||||
|
@ -346,9 +346,12 @@ struct LG_AudioDevOps LGAD_PulseAudio =
|
||||
.name = "PulseAudio",
|
||||
.init = pulseaudio_init,
|
||||
.free = pulseaudio_free,
|
||||
.start = pulseaudio_start,
|
||||
.play = pulseaudio_play,
|
||||
.stop = pulseaudio_stop,
|
||||
.volume = pulseaudio_volume,
|
||||
.mute = pulseaudio_mute
|
||||
.playback =
|
||||
{
|
||||
.start = pulseaudio_start,
|
||||
.play = pulseaudio_play,
|
||||
.stop = pulseaudio_stop,
|
||||
.volume = pulseaudio_volume,
|
||||
.mute = pulseaudio_mute
|
||||
}
|
||||
};
|
||||
|
@ -38,32 +38,47 @@ struct LG_AudioDevOps
|
||||
/* final free */
|
||||
void (*free)(void);
|
||||
|
||||
/* setup the playback audio stream
|
||||
* Note: currently SPICE only supports S16 samples so always assume so
|
||||
*/
|
||||
void (*start)(int channels, int sampleRate);
|
||||
struct
|
||||
{
|
||||
/* start the playback audio stream
|
||||
* Note: currently SPICE only supports S16 samples so always assume so
|
||||
*/
|
||||
void (*start)(int channels, int sampleRate);
|
||||
|
||||
/* called for each packet of output audio to play
|
||||
* Note: size is the size of data in bytes, not frames/samples
|
||||
*/
|
||||
void (*play)(uint8_t * data, int size);
|
||||
/* called for each packet of output audio to play
|
||||
* Note: size is the size of data in bytes, not frames/samples
|
||||
*/
|
||||
void (*play)(uint8_t * data, int size);
|
||||
|
||||
/* called when SPICE reports the audio stream has stopped */
|
||||
void (*stop)(void);
|
||||
/* 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 the volume of the channels */
|
||||
void (*volume)(int channels, const uint16_t volume[]);
|
||||
|
||||
/* [optional] called to set muting of the output */
|
||||
void (*mute)(bool mute);
|
||||
/* [optional] called to set muting of the output */
|
||||
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
|
||||
|
@ -765,7 +765,7 @@ int main_frameThread(void * unused)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void audioStart(int channels, int sampleRate, PSAudioFormat format,
|
||||
void playbackStart(int channels, int sampleRate, PSAudioFormat format,
|
||||
uint32_t time)
|
||||
{
|
||||
/*
|
||||
@ -795,46 +795,46 @@ void audioStart(int channels, int sampleRate, PSAudioFormat format,
|
||||
static int lastChannels = 0;
|
||||
static int lastSampleRate = 0;
|
||||
|
||||
if (g_state.audioStarted)
|
||||
if (g_state.playbackStarted)
|
||||
{
|
||||
if (channels != lastChannels || sampleRate != lastSampleRate)
|
||||
g_state.audioDev->stop();
|
||||
g_state.audioDev->playback.stop();
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
lastChannels = channels;
|
||||
lastSampleRate = sampleRate;
|
||||
g_state.audioStarted = true;
|
||||
g_state.playbackStarted = true;
|
||||
|
||||
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)
|
||||
g_state.audioDev->stop();
|
||||
g_state.audioStarted = false;
|
||||
g_state.audioDev->playback.stop();
|
||||
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)
|
||||
g_state.audioDev->volume(channels, volume);
|
||||
if (g_state.audioDev && g_state.audioDev->playback.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)
|
||||
g_state.audioDev->mute(mute);
|
||||
if (g_state.audioDev && g_state.audioDev->playback.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)
|
||||
g_state.audioDev->play(data, size);
|
||||
g_state.audioDev->playback.play(data, size);
|
||||
}
|
||||
|
||||
static void checkUUID(void)
|
||||
@ -900,11 +900,11 @@ int spiceThread(void * arg)
|
||||
.playback =
|
||||
{
|
||||
.enable = g_params.useSpiceAudio,
|
||||
.start = audioStart,
|
||||
.volume = audioVolume,
|
||||
.mute = audioMute,
|
||||
.stop = audioStop,
|
||||
.data = audioData
|
||||
.start = playbackStart,
|
||||
.volume = playbackVolume,
|
||||
.mute = playbackMute,
|
||||
.stop = playbackStop,
|
||||
.data = playbackData
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -141,7 +141,7 @@ struct AppState
|
||||
bool autoIdleInhibitState;
|
||||
|
||||
struct LG_AudioDevOps * audioDev;
|
||||
bool audioStarted;
|
||||
bool playbackStarted;
|
||||
};
|
||||
|
||||
struct AppParams
|
||||
|
Loading…
Reference in New Issue
Block a user