sysaudio: move DeviceChaneFn to Context and rename ConnectError to InitError
This commit is contained in:
parent
192cacb85d
commit
ee84f6ab70
5 changed files with 16 additions and 14 deletions
|
|
@ -12,7 +12,7 @@ pub const Context = struct {
|
||||||
watcher: ?Watcher,
|
watcher: ?Watcher,
|
||||||
|
|
||||||
const Watcher = struct {
|
const Watcher = struct {
|
||||||
deviceChangeFn: main.DeviceChangeFn,
|
deviceChangeFn: main.Context.DeviceChangeFn,
|
||||||
user_data: ?*anyopaque,
|
user_data: ?*anyopaque,
|
||||||
thread: std.Thread,
|
thread: std.Thread,
|
||||||
aborted: std.atomic.Atomic(bool),
|
aborted: std.atomic.Atomic(bool),
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ pub const Context = struct {
|
||||||
watcher: ?Watcher,
|
watcher: ?Watcher,
|
||||||
|
|
||||||
const Watcher = struct {
|
const Watcher = struct {
|
||||||
deviceChangeFn: main.DeviceChangeFn,
|
deviceChangeFn: main.Context.DeviceChangeFn,
|
||||||
user_data: ?*anyopaque,
|
user_data: ?*anyopaque,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,14 @@ const std = @import("std");
|
||||||
const util = @import("util.zig");
|
const util = @import("util.zig");
|
||||||
const backends = @import("backends.zig");
|
const backends = @import("backends.zig");
|
||||||
|
|
||||||
|
pub const Backend = backends.Backend;
|
||||||
pub const default_sample_rate = 44_100; // Hz
|
pub const default_sample_rate = 44_100; // Hz
|
||||||
pub const default_latency = 500 * std.time.us_per_ms; // μs
|
pub const default_latency = 500 * std.time.us_per_ms; // μs
|
||||||
pub const min_sample_rate = 8_000; // Hz
|
pub const min_sample_rate = 8_000; // Hz
|
||||||
pub const max_sample_rate = 5_644_800; // Hz
|
pub const max_sample_rate = 5_644_800; // Hz
|
||||||
|
|
||||||
pub const Backend = backends.Backend;
|
|
||||||
pub const DeviceChangeFn = *const fn (self: ?*anyopaque) void;
|
|
||||||
pub const ConnectError = error{
|
|
||||||
OutOfMemory,
|
|
||||||
AccessDenied,
|
|
||||||
SystemResources,
|
|
||||||
ConnectionRefused,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Context = struct {
|
pub const Context = struct {
|
||||||
|
pub const DeviceChangeFn = *const fn (self: ?*anyopaque) void;
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
app_name: [:0]const u8 = "Mach Game",
|
app_name: [:0]const u8 = "Mach Game",
|
||||||
deviceChangeFn: ?DeviceChangeFn = null,
|
deviceChangeFn: ?DeviceChangeFn = null,
|
||||||
|
|
@ -26,7 +19,16 @@ pub const Context = struct {
|
||||||
|
|
||||||
data: backends.BackendContext,
|
data: backends.BackendContext,
|
||||||
|
|
||||||
pub fn init(comptime backend: ?Backend, allocator: std.mem.Allocator, options: Options) ConnectError!Context {
|
pub const InitError = error{
|
||||||
|
OutOfMemory,
|
||||||
|
AccessDenied,
|
||||||
|
LibraryNotFound,
|
||||||
|
SymbolLookup,
|
||||||
|
SystemResources,
|
||||||
|
ConnectionRefused,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn init(comptime backend: ?Backend, allocator: std.mem.Allocator, options: Options) InitError!Context {
|
||||||
var data: backends.BackendContext = blk: {
|
var data: backends.BackendContext = blk: {
|
||||||
if (backend) |b| {
|
if (backend) |b| {
|
||||||
break :blk try @typeInfo(
|
break :blk try @typeInfo(
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ pub const Context = struct {
|
||||||
// watcher: ?Watcher,
|
// watcher: ?Watcher,
|
||||||
|
|
||||||
const Watcher = struct {
|
const Watcher = struct {
|
||||||
deviceChangeFn: main.DeviceChangeFn,
|
deviceChangeFn: main.Context.DeviceChangeFn,
|
||||||
user_data: ?*anyopaque,
|
user_data: ?*anyopaque,
|
||||||
thread: *c.pw_thread_loop,
|
thread: *c.pw_thread_loop,
|
||||||
aborted: std.atomic.Atomic(bool),
|
aborted: std.atomic.Atomic(bool),
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ pub const Context = struct {
|
||||||
is_wine: bool,
|
is_wine: bool,
|
||||||
|
|
||||||
const Watcher = struct {
|
const Watcher = struct {
|
||||||
deviceChangeFn: main.DeviceChangeFn,
|
deviceChangeFn: main.Context.DeviceChangeFn,
|
||||||
user_data: ?*anyopaque,
|
user_data: ?*anyopaque,
|
||||||
notif_client: win32.IMMNotificationClient,
|
notif_client: win32.IMMNotificationClient,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue