Skip to content

Commit

Permalink
Half-hearted attempt at making toxic work on osx.
Browse files Browse the repository at this point in the history
Video has no chance without X11 for now.
  • Loading branch information
iphydf committed Mar 30, 2020
1 parent 98cb7f5 commit 4651301
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 35 deletions.
26 changes: 18 additions & 8 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -25,6 +33,8 @@ cc_binary(
"@ncurses",
"@openal",
"@python3//:python",
"@x11",
],
] + select({
"//tools/config:linux": ["@x11"],
"//tools/config:osx": [],
}),
)
5 changes: 0 additions & 5 deletions src/audio_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,12 @@
#include "line_info.h"
#include "settings.h"

#ifdef __APPLE__
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
/* compatibility with older versions of OpenAL */
#ifndef ALC_ALL_DEVICES_SPECIFIER
#include <AL/alext.h>
#endif /* ALC_ALL_DEVICES_SPECIFIER */
#endif /* __APPLE__ */

#include <stdbool.h>
#include <string.h>
Expand Down
44 changes: 22 additions & 22 deletions src/video_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
#include "video_call.h"

#include <sys/ioctl.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>

#include <vpx/vpx_image.h>

#if defined(__OSX__)
#if defined(__OSX__) || defined(__APPLE__)
#import "osx_video.h"
#else
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
Expand All @@ -42,7 +42,7 @@
#else
#include <linux/videodev2.h>
#endif /* defined(__OpenBSD__) || defined(__NetBSD__) */
#endif /* __OSX__ */
#endif /* __OSX__ || __APPLE__ */

#include "line_info.h"
#include "settings.h"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -270,23 +270,23 @@ 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;
}

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) {
Expand Down Expand Up @@ -370,15 +370,15 @@ 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);
unlock;
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);
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {}
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/xtra.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "xtra.h"
#include "misc_tools.h"

#ifndef __APPLE__

#include <X11/Xlib.h>
#include <X11/Xatom.h>

Expand Down Expand Up @@ -419,3 +421,5 @@ void terminate_xtra(void)

while (Xtra.display); /* Wait for termination */
}

#endif /* !__APPLE__ */

0 comments on commit 4651301

Please sign in to comment.