Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
  • Loading branch information
slimsag committed Oct 4, 2024
1 parent a1e6a2e commit 776e518
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 167 deletions.
98 changes: 15 additions & 83 deletions core_media_manual.zig
Original file line number Diff line number Diff line change
@@ -1,103 +1,35 @@
// const ca = @import("quartz_core.zig");
// const cf = @import("core_foundation.zig");
// const pid_t = @import("std").os.posix.pid_t;
// const size_t = usize;
// const ns = @import("foundation.zig");
// const cg = @import("core_graphics.zig");
// const objc = @import("objc.zig");
const cv = @import("core_video.zig");

// ------------------------------------------------------------------------------------------------
// Types

pub const TimeValue = i64;
pub const TimeScale = i32;
pub const TimeEpoch = u32;
pub const CMClockRef = *opaque {};

pub const CVPixelBufferRef = *CVPixelBuffer;
pub const CVPixelBuffer = opaque {
extern fn CVPixelBufferGetBaseAddress(CVPixelBufferRef) ?*anyopaque;
pub inline fn getBaseAddress(pxl: CVPixelBufferRef) ?*anyopaque {
return CVPixelBufferGetBaseAddress(pxl);
}

extern fn CVPixelBufferGetBaseAddressOfPlane(CVPixelBufferRef) ?*anyopaque;
pub inline fn getBaseAddressOfPlane(pxl: CVPixelBufferRef) ?*anyopaque {
return CVPixelBufferGetBaseAddressOfPlane(pxl);
}
};

pub const CVImageBufferRef = *CVImageBuffer;
pub const CVImageBuffer = opaque {};
pub const BlockBufferRef = *BlockBuffer;
pub const BlockBuffer = opaque {};

pub const CMBlockBufferRef = *CMBlockBuffer;
pub const CMBlockBuffer = opaque {};

pub const CMSampleBufferRef = *CMSampleBuffer;
pub const CMSampleBuffer = opaque {
extern fn CMSampleBufferGetDataBuffer(CMSampleBufferRef) callconv(.C) ?CMBlockBufferRef;
pub inline fn getDataBuffer(sbuf: *CMSampleBuffer) ?CMBlockBufferRef {
pub const SampleBufferRef = *SampleBuffer;
pub const SampleBuffer = opaque {
extern fn CMSampleBufferGetDataBuffer(SampleBufferRef) callconv(.C) ?BlockBufferRef;
pub inline fn getDataBuffer(sbuf: *SampleBuffer) ?BlockBufferRef {
return CMSampleBufferGetDataBuffer(sbuf);
}

extern fn CMSampleBufferGetImageBuffer(CMSampleBufferRef) callconv(.C) ?CVImageBufferRef;
pub inline fn getImageBuffer(sbuf: *CMSampleBuffer) ?CVImageBufferRef {
extern fn CMSampleBufferGetImageBuffer(SampleBufferRef) callconv(.C) ?cv.ImageBufferRef;
pub inline fn getImageBuffer(sbuf: *SampleBuffer) ?cv.ImageBufferRef {
return CMSampleBufferGetImageBuffer(sbuf);
}
};

pub const Time = extern struct {
value: TimeValue,
timescale: TimeScale,
// TODO: need to figure out why the generator doesn't remove "CM" prefix here.
flags: CMTimeFlags,
epoch: TimeEpoch,
};

pub const ClockRef = extern struct {};

// pub const applicationMain = NSApplicationMain;
// extern fn NSApplicationMain(argc: c_int, argv: [*]*c_char) c_int;

// // ------------------------------------------------------------------------------------------------
// // Shared

// pub const ErrorDomain = ns.ErrorDomain;
// pub const ErrorUserInfoKey = ns.ErrorUserInfoKey;
// pub const Integer = ns.Integer;
// pub const NotificationName = ns.NotificationName;
// pub const TimeInterval = ns.TimeInterval;
// pub const UInteger = ns.UInteger;
// pub const unichar = ns.unichar;
// pub const Range = ns.Range;
// pub const StringEncoding = ns.StringEncoding;
// pub const StringTransform = ns.StringTransform;
// pub const StringEncodingDetectionOptionsKey = ns.StringEncodingDetectionOptionsKey;
// pub const Array = ns.Array;
// pub const String = ns.String;

// // ------------------------------------------------------------------------------------------------
// // Types

// pub const ModalResponse = *String;
// pub const PasteboardType = *String;
// pub const AboutPanelOptionKey = *String;
// pub const ModalSession = *opaque {};
// pub const PrintInfoAttributeKey = *String;
// pub const Rect = cg.Rect;
// pub const Point = cg.Point;
// pub const Size = cg.Size;
// pub const RunLoopMode = *String;
// pub const PrinterPaperName = *String;
// pub const PrintJobDispositionValue = *String;
// pub const InterfaceStyle = UInteger;
// pub const TouchBarItemIdentifier = *String;
// pub const TouchBarCustomizationIdentifier = *String;
// pub const TouchBarItemPriority = f32;
// pub const DeviceDescriptionKey = *String;
// pub const PrinterTypeName = *String;
// pub const PrintInfoSettingKey = *String;
// pub const AccessibilityActionName = *String;
// pub const AccessibilityAttributeName = *String;
// pub const ExceptionName = *String;
// pub const ImageName = *String;
// pub const NibName = *String;
// pub const WindowFrameAutosaveName = *String;
// pub const AccessibilityParameterizedAttributeName = *String;
// pub const UserInterfaceItemIdentifier = *String;
pub const ClockRef = *OpaqueCMClock;
pub const OpaqueCMClock = extern struct {};
18 changes: 18 additions & 0 deletions core_video_manual.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// ------------------------------------------------------------------------------------------------
// Types

pub const PixelBufferRef = *PixelBuffer;
pub const PixelBuffer = opaque {
extern fn CVPixelBufferGetBaseAddress(PixelBufferRef) ?*anyopaque;
pub inline fn getBaseAddress(pxl: PixelBufferRef) ?*anyopaque {
return CVPixelBufferGetBaseAddress(pxl);
}

extern fn CVPixelBufferGetBaseAddressOfPlane(PixelBufferRef) ?*anyopaque;
pub inline fn getBaseAddressOfPlane(pxl: PixelBufferRef) ?*anyopaque {
return CVPixelBufferGetBaseAddressOfPlane(pxl);
}
};

pub const ImageBufferRef = *ImageBuffer;
pub const ImageBuffer = opaque {};
8 changes: 8 additions & 0 deletions generator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,11 @@ fn generateCoreMedia(generator: anytype) !void {
try generator.addEnum("CMTimeFlags");
}

fn generateCoreVideo(generator: anytype) !void {
generator.namespace = "CV";
generator.allow_methods = &.{};
}

fn usage() void {
std.log.warn(
\\mach-objc-generator [options]
Expand All @@ -2215,6 +2220,7 @@ const Framework = enum {
app_kit,
screen_capture_kit,
core_media,
core_video,
};

pub fn main() anyerror!void {
Expand Down Expand Up @@ -2242,6 +2248,7 @@ pub fn main() anyerror!void {
if (std.mem.eql(u8, args[i], "AppKit")) break :blk .app_kit;
if (std.mem.eql(u8, args[i], "ScreenCaptureKit")) break :blk .screen_capture_kit;
if (std.mem.eql(u8, args[i], "CoreMedia")) break :blk .core_media;
if (std.mem.eql(u8, args[i], "CoreVideo")) break :blk .core_video;
usage();
std.process.exit(1);
};
Expand Down Expand Up @@ -2295,6 +2302,7 @@ pub fn main() anyerror!void {
.app_kit => try generateAppKit(&generator),
.screen_capture_kit => try generateScreenCaptureKit(&generator),
.core_media => try generateCoreMedia(&generator),
.core_video => try generateCoreVideo(&generator),
}
try generator.generate();
}
Expand Down
98 changes: 15 additions & 83 deletions src/core_media.zig
Original file line number Diff line number Diff line change
@@ -1,106 +1,38 @@
// const ca = @import("quartz_core.zig");
// const cf = @import("core_foundation.zig");
// const pid_t = @import("std").os.posix.pid_t;
// const size_t = usize;
// const ns = @import("foundation.zig");
// const cg = @import("core_graphics.zig");
// const objc = @import("objc.zig");
const cv = @import("core_video.zig");

// ------------------------------------------------------------------------------------------------
// Types

pub const TimeValue = i64;
pub const TimeScale = i32;
pub const TimeEpoch = u32;
pub const CMClockRef = *opaque {};

pub const CVPixelBufferRef = *CVPixelBuffer;
pub const CVPixelBuffer = opaque {
extern fn CVPixelBufferGetBaseAddress(CVPixelBufferRef) ?*anyopaque;
pub inline fn getBaseAddress(pxl: CVPixelBufferRef) ?*anyopaque {
return CVPixelBufferGetBaseAddress(pxl);
}

extern fn CVPixelBufferGetBaseAddressOfPlane(CVPixelBufferRef) ?*anyopaque;
pub inline fn getBaseAddressOfPlane(pxl: CVPixelBufferRef) ?*anyopaque {
return CVPixelBufferGetBaseAddressOfPlane(pxl);
}
};

pub const CVImageBufferRef = *CVImageBuffer;
pub const CVImageBuffer = opaque {};
pub const BlockBufferRef = *BlockBuffer;
pub const BlockBuffer = opaque {};

pub const CMBlockBufferRef = *CMBlockBuffer;
pub const CMBlockBuffer = opaque {};

pub const CMSampleBufferRef = *CMSampleBuffer;
pub const CMSampleBuffer = opaque {
extern fn CMSampleBufferGetDataBuffer(CMSampleBufferRef) callconv(.C) ?CMBlockBufferRef;
pub inline fn getDataBuffer(sbuf: *CMSampleBuffer) ?CMBlockBufferRef {
pub const SampleBufferRef = *SampleBuffer;
pub const SampleBuffer = opaque {
extern fn CMSampleBufferGetDataBuffer(SampleBufferRef) callconv(.C) ?BlockBufferRef;
pub inline fn getDataBuffer(sbuf: *SampleBuffer) ?BlockBufferRef {
return CMSampleBufferGetDataBuffer(sbuf);
}

extern fn CMSampleBufferGetImageBuffer(CMSampleBufferRef) callconv(.C) ?CVImageBufferRef;
pub inline fn getImageBuffer(sbuf: *CMSampleBuffer) ?CVImageBufferRef {
extern fn CMSampleBufferGetImageBuffer(SampleBufferRef) callconv(.C) ?cv.ImageBufferRef;
pub inline fn getImageBuffer(sbuf: *SampleBuffer) ?cv.ImageBufferRef {
return CMSampleBufferGetImageBuffer(sbuf);
}
};

pub const Time = extern struct {
value: TimeValue,
timescale: TimeScale,
// TODO: need to figure out why the generator doesn't remove "CM" prefix here.
flags: CMTimeFlags,
epoch: TimeEpoch,
};

pub const ClockRef = extern struct {};

// pub const applicationMain = NSApplicationMain;
// extern fn NSApplicationMain(argc: c_int, argv: [*]*c_char) c_int;

// // ------------------------------------------------------------------------------------------------
// // Shared

// pub const ErrorDomain = ns.ErrorDomain;
// pub const ErrorUserInfoKey = ns.ErrorUserInfoKey;
// pub const Integer = ns.Integer;
// pub const NotificationName = ns.NotificationName;
// pub const TimeInterval = ns.TimeInterval;
// pub const UInteger = ns.UInteger;
// pub const unichar = ns.unichar;
// pub const Range = ns.Range;
// pub const StringEncoding = ns.StringEncoding;
// pub const StringTransform = ns.StringTransform;
// pub const StringEncodingDetectionOptionsKey = ns.StringEncodingDetectionOptionsKey;
// pub const Array = ns.Array;
// pub const String = ns.String;

// // ------------------------------------------------------------------------------------------------
// // Types

// pub const ModalResponse = *String;
// pub const PasteboardType = *String;
// pub const AboutPanelOptionKey = *String;
// pub const ModalSession = *opaque {};
// pub const PrintInfoAttributeKey = *String;
// pub const Rect = cg.Rect;
// pub const Point = cg.Point;
// pub const Size = cg.Size;
// pub const RunLoopMode = *String;
// pub const PrinterPaperName = *String;
// pub const PrintJobDispositionValue = *String;
// pub const InterfaceStyle = UInteger;
// pub const TouchBarItemIdentifier = *String;
// pub const TouchBarCustomizationIdentifier = *String;
// pub const TouchBarItemPriority = f32;
// pub const DeviceDescriptionKey = *String;
// pub const PrinterTypeName = *String;
// pub const PrintInfoSettingKey = *String;
// pub const AccessibilityActionName = *String;
// pub const AccessibilityAttributeName = *String;
// pub const ExceptionName = *String;
// pub const ImageName = *String;
// pub const NibName = *String;
// pub const WindowFrameAutosaveName = *String;
// pub const AccessibilityParameterizedAttributeName = *String;
// pub const UserInterfaceItemIdentifier = *String;
pub const ClockRef = *OpaqueCMClock;
pub const OpaqueCMClock = extern struct {};

pub const CMTimeFlags = u32;
pub const kCMTimeFlags_Valid: CMTimeFlags = 1;
Expand Down
18 changes: 18 additions & 0 deletions src/core_video.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// ------------------------------------------------------------------------------------------------
// Types

pub const PixelBufferRef = *PixelBuffer;
pub const PixelBuffer = opaque {
extern fn CVPixelBufferGetBaseAddress(PixelBufferRef) ?*anyopaque;
pub inline fn getBaseAddress(pxl: PixelBufferRef) ?*anyopaque {
return CVPixelBufferGetBaseAddress(pxl);
}

extern fn CVPixelBufferGetBaseAddressOfPlane(PixelBufferRef) ?*anyopaque;
pub inline fn getBaseAddressOfPlane(pxl: PixelBufferRef) ?*anyopaque {
return CVPixelBufferGetBaseAddressOfPlane(pxl);
}
};

pub const ImageBufferRef = *ImageBuffer;
pub const ImageBuffer = opaque {};
1 change: 1 addition & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub const avf_audio = @import("avf_audio.zig");
pub const core_foundation = @import("core_foundation.zig");
pub const core_graphics = @import("core_graphics.zig");
pub const core_media = @import("core_media.zig");
pub const core_video = @import("core_video.zig");
pub const foundation = @import("foundation.zig");
pub const metal = @import("metal.zig");
pub const quartz_core = @import("quartz_core.zig");
Expand Down
12 changes: 12 additions & 0 deletions src/screen_capture_kit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ pub const SCContentFilter = opaque {
pub fn contentRect(self_: *@This()) cg.Rect {
return objc.msgSend(self_, "contentRect", cg.Rect, .{});
}
pub fn includeMenuBar(self_: *@This()) bool {
return objc.msgSend(self_, "includeMenuBar", bool, .{});
}
pub fn setIncludeMenuBar(self_: *@This(), includeMenuBar_: bool) void {
return objc.msgSend(self_, "setIncludeMenuBar:", void, .{includeMenuBar_});
}
};

pub const SCStreamConfiguration = opaque {
Expand Down Expand Up @@ -349,6 +355,12 @@ pub const SCStreamConfiguration = opaque {
pub fn setPresenterOverlayPrivacyAlertSetting(self_: *@This(), presenterOverlayPrivacyAlertSetting_: SCPresenterOverlayAlertSetting) void {
return objc.msgSend(self_, "setPresenterOverlayPrivacyAlertSetting:", void, .{presenterOverlayPrivacyAlertSetting_});
}
pub fn includeChildWindows(self_: *@This()) bool {
return objc.msgSend(self_, "includeChildWindows", bool, .{});
}
pub fn setIncludeChildWindows(self_: *@This(), includeChildWindows_: bool) void {
return objc.msgSend(self_, "setIncludeChildWindows:", void, .{includeChildWindows_});
}
};

pub const SCStream = opaque {
Expand Down
12 changes: 11 additions & 1 deletion update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ git_clone_rev() {
popd
}

# git_clone_rev https://github.com/hexops/xcode-frameworks 3d1d9613c39bfc2ebfa2551626e87b7f38e0a29f xcode-frameworks
# git_clone_rev https://github.com/hexops/xcode-frameworks b4970fd7d71e1827e104fcddc0556d2fcf44345b xcode-frameworks

zig build -Doptimize=ReleaseFast

Expand Down Expand Up @@ -80,6 +80,16 @@ cat core_media_manual.zig > src/core_media.zig
./zig-out/bin/generator --framework CoreMedia >> src/core_media.zig
rm headers.json headers.m

rm -f src/core_video.zig
echo "Generating CoreVideo"
echo "
#include <CoreVideo/CoreVideo.h>
" > headers.m
clang headers.m -F ./xcode-frameworks/Frameworks -Xclang -ast-dump=json -fsyntax-only -Wno-deprecated-declarations -Wno-availability > headers.json
cat core_video_manual.zig > src/core_video.zig
./zig-out/bin/generator --framework CoreVideo >> src/core_video.zig
rm headers.json headers.m

zig fmt .

# TODO: generate src/foundation/ns.zig
Expand Down

0 comments on commit 776e518

Please sign in to comment.