sysaudio: move DeviceChaneFn to Context and rename ConnectError to InitError

This commit is contained in:
Ali Chraghi 2023-01-20 14:03:30 +03:30 committed by Stephen Gutekanst
parent 192cacb85d
commit ee84f6ab70
5 changed files with 16 additions and 14 deletions

View file

@ -12,7 +12,7 @@ pub const Context = struct {
watcher: ?Watcher,
const Watcher = struct {
deviceChangeFn: main.DeviceChangeFn,
deviceChangeFn: main.Context.DeviceChangeFn,
user_data: ?*anyopaque,
thread: std.Thread,
aborted: std.atomic.Atomic(bool),

View file

@ -11,7 +11,7 @@ pub const Context = struct {
watcher: ?Watcher,
const Watcher = struct {
deviceChangeFn: main.DeviceChangeFn,
deviceChangeFn: main.Context.DeviceChangeFn,
user_data: ?*anyopaque,
};

View file

@ -3,21 +3,14 @@ const std = @import("std");
const util = @import("util.zig");
const backends = @import("backends.zig");
pub const Backend = backends.Backend;
pub const default_sample_rate = 44_100; // Hz
pub const default_latency = 500 * std.time.us_per_ms; // μs
pub const min_sample_rate = 8_000; // 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 DeviceChangeFn = *const fn (self: ?*anyopaque) void;
pub const Options = struct {
app_name: [:0]const u8 = "Mach Game",
deviceChangeFn: ?DeviceChangeFn = null,
@ -26,7 +19,16 @@ pub const Context = struct {
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: {
if (backend) |b| {
break :blk try @typeInfo(

View file

@ -38,7 +38,7 @@ pub const Context = struct {
// watcher: ?Watcher,
const Watcher = struct {
deviceChangeFn: main.DeviceChangeFn,
deviceChangeFn: main.Context.DeviceChangeFn,
user_data: ?*anyopaque,
thread: *c.pw_thread_loop,
aborted: std.atomic.Atomic(bool),

View file

@ -12,7 +12,7 @@ pub const Context = struct {
is_wine: bool,
const Watcher = struct {
deviceChangeFn: main.DeviceChangeFn,
deviceChangeFn: main.Context.DeviceChangeFn,
user_data: ?*anyopaque,
notif_client: win32.IMMNotificationClient,
};