Milestone 2
This commit is contained in:
parent
14e3afdd7b
commit
866f0419ad
19 changed files with 2006 additions and 23 deletions
178
include/warppipe/warppipe.hpp
Normal file
178
include/warppipe/warppipe.hpp
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace warppipe {
|
||||
|
||||
enum class StatusCode : uint8_t {
|
||||
kOk = 0,
|
||||
kInvalidArgument,
|
||||
kNotFound,
|
||||
kUnavailable,
|
||||
kPermissionDenied,
|
||||
kTimeout,
|
||||
kInternal,
|
||||
kNotImplemented,
|
||||
};
|
||||
|
||||
struct Status {
|
||||
StatusCode code = StatusCode::kOk;
|
||||
std::string message;
|
||||
|
||||
static Status Ok();
|
||||
static Status Error(StatusCode code, std::string message);
|
||||
bool ok() const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Result {
|
||||
Status status;
|
||||
T value{};
|
||||
|
||||
bool ok() const { return status.ok(); }
|
||||
};
|
||||
|
||||
enum class ThreadingMode : uint8_t {
|
||||
kCallerThread = 0,
|
||||
kThreadLoop,
|
||||
};
|
||||
|
||||
struct ConnectionOptions {
|
||||
ThreadingMode threading = ThreadingMode::kThreadLoop;
|
||||
bool autoconnect = true;
|
||||
std::string application_name = "warppipe";
|
||||
std::optional<std::string> remote_name;
|
||||
};
|
||||
|
||||
struct AudioFormat {
|
||||
uint32_t rate = 48000;
|
||||
uint32_t channels = 2;
|
||||
};
|
||||
|
||||
enum class VirtualBehavior : uint8_t {
|
||||
kNull = 0,
|
||||
kLoopback,
|
||||
};
|
||||
|
||||
struct VirtualNodeOptions {
|
||||
AudioFormat format{};
|
||||
VirtualBehavior behavior = VirtualBehavior::kNull;
|
||||
std::optional<std::string> target_node;
|
||||
std::optional<std::string> media_class_override;
|
||||
std::string display_name;
|
||||
std::string group;
|
||||
};
|
||||
|
||||
struct NodeId {
|
||||
uint32_t value = 0;
|
||||
};
|
||||
|
||||
struct PortId {
|
||||
uint32_t value = 0;
|
||||
};
|
||||
|
||||
struct LinkId {
|
||||
uint32_t value = 0;
|
||||
};
|
||||
|
||||
struct RuleId {
|
||||
uint32_t value = 0;
|
||||
};
|
||||
|
||||
struct NodeInfo {
|
||||
NodeId id;
|
||||
std::string name;
|
||||
std::string media_class;
|
||||
};
|
||||
|
||||
struct PortInfo {
|
||||
PortId id;
|
||||
NodeId node;
|
||||
std::string name;
|
||||
bool is_input = false;
|
||||
};
|
||||
|
||||
struct VirtualSink {
|
||||
NodeId node;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct VirtualSource {
|
||||
NodeId node;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
struct Link {
|
||||
LinkId id;
|
||||
PortId output_port;
|
||||
PortId input_port;
|
||||
};
|
||||
|
||||
struct LinkOptions {
|
||||
bool passive = false;
|
||||
bool linger = false;
|
||||
};
|
||||
|
||||
struct RuleMatch {
|
||||
std::string application_name;
|
||||
std::string process_binary;
|
||||
std::string media_role;
|
||||
};
|
||||
|
||||
struct RouteRule {
|
||||
RuleMatch match;
|
||||
std::string target_node;
|
||||
};
|
||||
|
||||
class Client {
|
||||
public:
|
||||
Client(const Client&) = delete;
|
||||
Client& operator=(const Client&) = delete;
|
||||
Client(Client&&) noexcept;
|
||||
Client& operator=(Client&&) noexcept;
|
||||
~Client();
|
||||
|
||||
static Result<std::unique_ptr<Client>> Create(const ConnectionOptions& options);
|
||||
|
||||
Status Shutdown();
|
||||
|
||||
Result<std::vector<NodeInfo>> ListNodes();
|
||||
Result<std::vector<PortInfo>> ListPorts(NodeId node);
|
||||
Result<std::vector<Link>> ListLinks();
|
||||
|
||||
Result<VirtualSink> CreateVirtualSink(std::string_view name,
|
||||
const VirtualNodeOptions& options = VirtualNodeOptions{});
|
||||
Result<VirtualSource> CreateVirtualSource(std::string_view name,
|
||||
const VirtualNodeOptions& options = VirtualNodeOptions{});
|
||||
Status RemoveNode(NodeId node);
|
||||
|
||||
Result<Link> CreateLink(PortId output, PortId input, const LinkOptions& options);
|
||||
Status RemoveLink(LinkId link);
|
||||
|
||||
Result<RuleId> AddRouteRule(const RouteRule& rule);
|
||||
Status RemoveRouteRule(RuleId id);
|
||||
|
||||
Status SaveConfig(std::string_view path);
|
||||
Status LoadConfig(std::string_view path);
|
||||
|
||||
#ifdef WARPPIPE_TESTING
|
||||
Status Test_InsertNode(const NodeInfo& node);
|
||||
Status Test_InsertPort(const PortInfo& port);
|
||||
Status Test_InsertLink(const Link& link);
|
||||
Status Test_RemoveGlobal(uint32_t id);
|
||||
Status Test_ForceDisconnect();
|
||||
#endif
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
explicit Client(std::unique_ptr<Impl> impl);
|
||||
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace warppipe
|
||||
Loading…
Add table
Add a link
Reference in a new issue