Skip to content

Commit

Permalink
Replace @ptrToInt to @intFromPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsu-koba committed Jun 22, 2023
1 parent 7b06c9d commit f762d41
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,5 @@ pub fn main() !void {
}
}
const duration = time.milliTimestamp() - start_time;
log.info("{d}:duration {d}ms, frame_count {d}, {d:.2}fps", .{ time.milliTimestamp(), duration, frame_count, @intToFloat(f32, frame_count) / @intToFloat(f32, duration) * 1000 });
log.info("{d}:duration {d}ms, frame_count {d}, {d:.2}fps", .{ time.milliTimestamp(), duration, frame_count, @floatFromInt(f32, frame_count) / @floatFromInt(f32, duration) * 1000 });
}
24 changes: 12 additions & 12 deletions src/v4l2capture.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub const Capturer = struct {

fn capDevice(self: *Self) !void {
var cap: c.struct_v4l2_capability = undefined;
try self.xioctl(c.VIDIOC_QUERYCAP, @ptrToInt(&cap));
try self.xioctl(c.VIDIOC_QUERYCAP, @intFromPtr(&cap));
if (0 == cap.capabilities & c.V4L2_CAP_VIDEO_CAPTURE) {
log.err("no video capture\n", .{});
unreachable;
Expand All @@ -110,10 +110,10 @@ pub const Capturer = struct {
fmt.fmt.pix.height = self.height;
fmt.fmt.pix.pixelformat = self.pixelformat;
fmt.fmt.pix.field = c.V4L2_FIELD_ANY;
try self.xioctl(c.VIDIOC_S_FMT, @ptrToInt(&fmt));
try self.xioctl(c.VIDIOC_S_FMT, @intFromPtr(&fmt));
@memset(@ptrCast([*]u8, &fmt)[0..@sizeOf(c.struct_v4l2_format)], 0);
fmt.type = c.V4L2_BUF_TYPE_VIDEO_CAPTURE;
try self.xioctl(c.VIDIOC_G_FMT, @ptrToInt(&fmt));
try self.xioctl(c.VIDIOC_G_FMT, @intFromPtr(&fmt));
if (fmt.fmt.pix.pixelformat != self.pixelformat) {
const p = self.pixelformat;
log.err("pixelformat {c}{c}{c}{c} is not supported\n", .{ @truncate(u8, p), @truncate(u8, p >> 8), @truncate(u8, p >> 16), @truncate(u8, p >> 24) });
Expand All @@ -135,14 +135,14 @@ pub const Capturer = struct {
var streamparm: c.struct_v4l2_streamparm = undefined;
@memset(@ptrCast([*]u8, &streamparm)[0..@sizeOf(c.struct_v4l2_streamparm)], 0);
streamparm.type = c.V4L2_BUF_TYPE_VIDEO_CAPTURE;
try self.xioctl(c.VIDIOC_G_PARM, @ptrToInt(&streamparm));
try self.xioctl(c.VIDIOC_G_PARM, @intFromPtr(&streamparm));
if (streamparm.parm.capture.capability & c.V4L2_CAP_TIMEPERFRAME != 0) {
streamparm.parm.capture.timeperframe.numerator = 1;
streamparm.parm.capture.timeperframe.denominator = self.framerate;
try self.xioctl(c.VIDIOC_S_PARM, @ptrToInt(&streamparm));
try self.xioctl(c.VIDIOC_S_PARM, @intFromPtr(&streamparm));
@memset(@ptrCast([*]u8, &streamparm)[0..@sizeOf(c.struct_v4l2_streamparm)], 0);
streamparm.type = c.V4L2_BUF_TYPE_VIDEO_CAPTURE;
try self.xioctl(c.VIDIOC_G_PARM, @ptrToInt(&streamparm));
try self.xioctl(c.VIDIOC_G_PARM, @intFromPtr(&streamparm));
const r = streamparm.parm.capture.timeperframe.denominator;
if (r != self.framerate) {
log.warn("Requested framerate is {d} but set to {d}.", .{ self.framerate, r });
Expand All @@ -159,7 +159,7 @@ pub const Capturer = struct {
req.count = Capturer.MIN_BUFFERS;
req.type = c.V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = c.V4L2_MEMORY_MMAP;
try self.xioctl(c.VIDIOC_REQBUFS, @ptrToInt(&req));
try self.xioctl(c.VIDIOC_REQBUFS, @intFromPtr(&req));
if (req.count < MIN_BUFFERS) {
log.err("Insufficient buffer memory on camera\n", .{});
unreachable;
Expand All @@ -171,7 +171,7 @@ pub const Capturer = struct {
buff.type = c.V4L2_BUF_TYPE_VIDEO_CAPTURE;
buff.memory = c.V4L2_MEMORY_MMAP;
buff.index = @truncate(c_uint, i);
try self.xioctl(c.VIDIOC_QUERYBUF, @ptrToInt(&buff));
try self.xioctl(c.VIDIOC_QUERYBUF, @intFromPtr(&buff));
self.buffers[i].length = buff.length;
self.buffers[i].start = try os.mmap(null, buff.length, os.PROT.READ | os.PROT.WRITE, os.MAP.SHARED, self.fd, buff.m.offset);
}
Expand All @@ -183,7 +183,7 @@ pub const Capturer = struct {
buf.type = c.V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = c.V4L2_MEMORY_MMAP;
buf.index = @truncate(c_uint, index);
try self.xioctl(c.VIDIOC_QBUF, @ptrToInt(&buf));
try self.xioctl(c.VIDIOC_QBUF, @intFromPtr(&buf));
}

fn enqueueBuffers(self: *Self) !void {
Expand All @@ -194,12 +194,12 @@ pub const Capturer = struct {

fn streamStart(self: *Self) !void {
const t: c.enum_v4l2_buf_type = c.V4L2_BUF_TYPE_VIDEO_CAPTURE;
try self.xioctl(c.VIDIOC_STREAMON, @ptrToInt(&t));
try self.xioctl(c.VIDIOC_STREAMON, @intFromPtr(&t));
}

fn streamStop(self: *Self) !void {
const t: c.enum_v4l2_buf_type = c.V4L2_BUF_TYPE_VIDEO_CAPTURE;
try self.xioctl(c.VIDIOC_STREAMOFF, @ptrToInt(&t));
try self.xioctl(c.VIDIOC_STREAMOFF, @intFromPtr(&t));
}

fn munmapBuffer(self: *Self) void {
Expand Down Expand Up @@ -230,7 +230,7 @@ pub const Capturer = struct {
buf.type = c.V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = c.V4L2_MEMORY_MMAP;

try self.xioctl(c.VIDIOC_DQBUF, @ptrToInt(&buf));
try self.xioctl(c.VIDIOC_DQBUF, @intFromPtr(&buf));
const b = self.buffers[buf.index];
frameHandler(self, b.start[0..b.length]);
try self.enqueueBuffer(buf.index);
Expand Down
2 changes: 1 addition & 1 deletion src/vmsplice.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn vmspliceSingleBuffer(buf: []const u8, fd: os.fd_t) !void {
//std.log.info("vmsplice: return value mismatch: n={d}, iov_len={d}", .{ n, iov.iov_len });
const un = @bitCast(usize, n);
iov.iov_len -= un;
iov.iov_base = @intToPtr(?*anyopaque, @ptrToInt(iov.iov_base) + un);
iov.iov_base = @ptrFromInt(?*anyopaque, @intFromPtr(iov.iov_base) + un);
continue;
}
return error.Vmsplice;
Expand Down

0 comments on commit f762d41

Please sign in to comment.