EHS/include/ehs/io/audio/AudioDevice_PW.h

68 lines
1.5 KiB
C
Raw Permalink Normal View History

2024-02-05 22:25:30 -08:00
#pragma once
#include "ehs/EHS.h"
#include "BaseAudioDevice.h"
2024-09-03 05:37:23 -07:00
#include <pipewire/pipewire.h>
#include <pipewire/loop.h>
#include <pipewire/context.h>
#include <pipewire/stream.h>
2024-09-16 16:18:49 -07:00
#include <spa/param/audio/format-utils.h>
2024-02-05 22:25:30 -08:00
namespace ehs
{
2024-09-16 16:18:49 -07:00
class EHS_LIB_IO AudioDevice final : public BaseAudioDevice
2024-02-05 22:25:30 -08:00
{
private:
2024-09-03 05:37:23 -07:00
static Array<AudioDevice> devices;
static AudioDevice defOut;
static AudioDevice defIn;
UInt_32 id;
Str_8 name;
pw_loop *loop;
pw_context *context;
pw_core *core;
2024-09-16 16:18:49 -07:00
pw_stream *input;
pw_stream *output;
2024-09-03 05:37:23 -07:00
2024-09-16 16:18:49 -07:00
static void RegistryEventGlobal(void *data, UInt_32 id, UInt_32 permissions, const char *type, UInt_32 version, const spa_dict *props);
2024-09-03 05:37:23 -07:00
2024-09-16 16:18:49 -07:00
static void RegistryEventGlobalRemove(void *data, UInt_32 id);
static void OnParamChanged(void *data, UInt_32 id, const spa_pod *param);
2024-02-05 22:25:30 -08:00
public:
~AudioDevice() override;
AudioDevice();
AudioDevice(AudioDevice&& device) noexcept;
AudioDevice(const AudioDevice& device);
AudioDevice& operator=(AudioDevice&& device) noexcept;
AudioDevice& operator=(const AudioDevice& device);
void OpenStream() override;
void CloseStream() override;
2024-09-16 16:18:49 -07:00
UInt_64 SendStream(const void *data, UInt_64 size) override;
UInt_64 ReceiveStream(void *data, UInt_64 size) override;
bool IsStreaming() const override;
2024-02-05 22:25:30 -08:00
bool IsValid() const override;
2024-09-03 05:37:23 -07:00
static AudioDevice GetDefault(AudioDeviceType type);
2024-02-05 22:25:30 -08:00
2024-09-03 05:37:23 -07:00
static Array<AudioDevice> Get(AudioDeviceType type, AudioDeviceState state);
2024-09-16 16:18:49 -07:00
private:
Str_8 GetCategory() const;
2024-02-05 22:25:30 -08:00
};
}