From 46513017e39bd6b35481bdf8a3250895d99607f7 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 30 Mar 2020 13:35:34 +0100 Subject: [PATCH] Half-hearted attempt at making toxic work on osx. Video has no chance without X11 for now. --- BUILD.bazel | 26 ++++++++++++++++++-------- src/audio_device.c | 5 ----- src/video_device.c | 44 ++++++++++++++++++++++---------------------- src/xtra.c | 4 ++++ 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 074eb05..380c197 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -5,17 +5,25 @@ project() cc_binary( name = "toxic", - srcs = glob([ - "src/*.c", - "src/*.h", - ]), + srcs = glob( + [ + "src/*.c", + "src/*.h", + ], + exclude = ["src/video*"], + ) + select({ + "//tools/config:linux": glob(["src/video*"]), + "//tools/config:osx": [], + }), copts = [ "-DAUDIO", "-DPACKAGE_DATADIR='\"data\"'", "-DPYTHON", "-DQRCODE", - "-DVIDEO", - ], + ] + select({ + "//tools/config:linux": ["-DVIDEO"], + "//tools/config:osx": [], + }), deps = [ "//c-toxcore", "@curl", @@ -25,6 +33,8 @@ cc_binary( "@ncurses", "@openal", "@python3//:python", - "@x11", - ], + ] + select({ + "//tools/config:linux": ["@x11"], + "//tools/config:osx": [], + }), ) diff --git a/src/audio_device.c b/src/audio_device.c index c4b55e1..dbbfbaf 100644 --- a/src/audio_device.c +++ b/src/audio_device.c @@ -29,17 +29,12 @@ #include "line_info.h" #include "settings.h" -#ifdef __APPLE__ -#include -#include -#else #include #include /* compatibility with older versions of OpenAL */ #ifndef ALC_ALL_DEVICES_SPECIFIER #include #endif /* ALC_ALL_DEVICES_SPECIFIER */ -#endif /* __APPLE__ */ #include #include diff --git a/src/video_device.c b/src/video_device.c index 23bd368..4ccdce0 100644 --- a/src/video_device.c +++ b/src/video_device.c @@ -24,15 +24,15 @@ #include "video_call.h" #include -#include -#include -#include #include -#if defined(__OSX__) +#if defined(__OSX__) || defined(__APPLE__) #import "osx_video.h" #else +#include +#include +#include #include #include #include @@ -42,7 +42,7 @@ #else #include #endif /* defined(__OpenBSD__) || defined(__NetBSD__) */ -#endif /* __OSX__ */ +#endif /* __OSX__ || __APPLE__ */ #include "line_info.h" #include "settings.h" @@ -72,7 +72,7 @@ typedef struct VideoDevice { void *cb_data; /* Data to be passed to callback */ int32_t friend_number; /* ToxAV friend number */ -#if !defined(__OSX__) +#if !(defined(__OSX__) || defined(__APPLE__)) int fd; /* File descriptor of video device selected/opened */ struct v4l2_format fmt; struct VideoBuffer *buffers; @@ -137,7 +137,7 @@ static void yuv420tobgr(uint16_t width, uint16_t height, const uint8_t *y, } } -#if !defined(__OSX__) +#if !(defined(__OSX__) || defined(__APPLE__)) static void yuv422to420(uint8_t *plane_y, uint8_t *plane_u, uint8_t *plane_v, uint8_t *input, uint16_t width, uint16_t height) { @@ -186,13 +186,13 @@ VideoDeviceError init_video_devices() { size[vdt_input] = 0; -#if defined(__OSX__) +#if defined(__OSX__) || defined(__APPLE__) if (osx_video_init((char **)video_devices_names[vdt_input], &size[vdt_input]) != 0) { return vde_InternalError; } -#else /* not __OSX__*/ +#else /* not __OSX__ || __APPLE__ */ for (; size[vdt_input] <= MAX_DEVICES; ++size[vdt_input]) { int fd; @@ -270,9 +270,9 @@ VideoDeviceError terminate_video_devices(void) return (VideoDeviceError) vde_InternalError; } -#ifdef __OSX__ +#if defined(__OSX__) || defined(__APPLE__) osx_video_release(); -#endif /* __OSX__ */ +#endif /* __OSX__ || __APPLE__ */ return (VideoDeviceError) vde_None; } @@ -280,13 +280,13 @@ VideoDeviceError terminate_video_devices(void) VideoDeviceError register_video_device_callback(int32_t friend_number, uint32_t device_idx, VideoDataHandleCallback callback, void *data) { -#if defined(__OSX__) +#if defined(__OSX__) || defined(__APPLE__) if (size[vdt_input] <= device_idx || !video_devices_running[vdt_input][device_idx]) { return vde_InvalidSelection; } -#else /* not __OSX__ */ +#else /* not __OSX__ || __APPLE__ */ if (size[vdt_input] <= device_idx || !video_devices_running[vdt_input][device_idx] || !video_devices_running[vdt_input][device_idx]->fd) { @@ -370,7 +370,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint if (type == vdt_input) { video_thread_paused = true; -#if defined(__OSX__) +#if defined(__OSX__) || defined(__APPLE__) if (osx_video_open_device(selection, &device->video_width, &device->video_height) != 0) { free(device); @@ -378,7 +378,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint return vde_FailedStart; } -#else /* not __OSX__*/ +#else /* not __OSX__ || __APPLE__ */ /* Open selected device */ char device_address[] = "/dev/videoXX"; snprintf(device_address + 10, sizeof(device_address) - 10, "%i", selection); @@ -690,14 +690,14 @@ void *video_thread_poll(void *arg) // TODO: maybe use thread for every input so uint8_t *u = device->input.planes[1]; uint8_t *v = device->input.planes[2]; -#if defined(__OSX__) +#if defined(__OSX__) || defined(__APPLE__) if (osx_video_read_device(y, u, v, &video_width, &video_height) != 0) { unlock; continue; } -#else /* not __OSX__*/ +#else /* not __OSX__ || __APPLE__ */ struct v4l2_buffer buf; memset(&(buf), 0, sizeof(buf)); @@ -751,7 +751,7 @@ void *video_thread_poll(void *arg) // TODO: maybe use thread for every input so XFlush(device->x_display); free(img_data); -#if !defined(__OSX__) +#if !(defined(__OSX__) || defined(__APPLE__)) if (-1 == xioctl(device->fd, VIDIOC_QBUF, &buf)) { unlock; @@ -792,10 +792,10 @@ VideoDeviceError close_video_device(VideoDeviceType type, uint32_t device_idx) if (!device->ref_count) { if (type == vdt_input) { -#if defined(__OSX__) +#if defined(__OSX__) || defined(__APPLE__) osx_video_close_device(device_idx); -#else /* not __OSX__ */ +#else /* not __OSX__ || __APPLE__ */ enum v4l2_buf_type buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == xioctl(device->fd, VIDIOC_STREAMOFF, &buf_type)) {} @@ -816,9 +816,9 @@ VideoDeviceError close_video_device(VideoDeviceType type, uint32_t device_idx) XCloseDisplay(device->x_display); pthread_mutex_destroy(device->mutex); -#if !defined(__OSX__) +#if !(defined(__OSX__) || defined(__APPLE__)) free(device->buffers); -#endif /* not __OSX__ */ +#endif /* not __OSX__ || __APPLE__ */ free(device); } else { diff --git a/src/xtra.c b/src/xtra.c index 7e18b82..6cb1f75 100644 --- a/src/xtra.c +++ b/src/xtra.c @@ -23,6 +23,8 @@ #include "xtra.h" #include "misc_tools.h" +#ifndef __APPLE__ + #include #include @@ -419,3 +421,5 @@ void terminate_xtra(void) while (Xtra.display); /* Wait for termination */ } + +#endif /* !__APPLE__ */