mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 20:43:02 +01:00
Progress on video call windows using X11
This commit is contained in:
parent
2369b5e9e2
commit
c8ea02376e
@ -1,37 +1,89 @@
|
||||
#include "toxic.h"
|
||||
#include "windows.h"
|
||||
#include "video_call.h"
|
||||
#include "video_device.h"
|
||||
#include "chat_commands.h"
|
||||
#include "global_commands.h"
|
||||
#include "line_info.h"
|
||||
#include "notify.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xos.h>
|
||||
|
||||
#include "assert.h"
|
||||
|
||||
void receive_video_frame_cb( ToxAV *av, uint32_t friend_number,
|
||||
uint16_t width, uint16_t height,
|
||||
uint8_t const *y, uint8_t const *u, uint8_t const *v, uint8_t const *a,
|
||||
int32_t ystride, int32_t ustride, int32_t vstride, int32_t astride,
|
||||
void *user_data );
|
||||
void video_bit_rate_status_cb( ToxAV *av, uint32_t friend_number,
|
||||
bool stable, uint32_t bit_rate, void *user_data);
|
||||
|
||||
static void print_err (ToxWindow *self, const char *error_str)
|
||||
{
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", error_str);
|
||||
}
|
||||
|
||||
ToxAV *init_video(ToxWindow *self, Tox *tox, ToxAV *av, CallControl *user_data)
|
||||
{
|
||||
XInitThreads();
|
||||
|
||||
Display *display;
|
||||
if ((display = XOpenDisplay(NULL)) == NULL) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open X11 display");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int screen;
|
||||
screen = DefaultScreen(display);
|
||||
|
||||
Window win;
|
||||
if ((win = XCreateSimpleWindow(display, RootWindow(display, screen), 400, 400, 800, 600, 0,
|
||||
BlackPixel(display, screen), WhitePixel(display, screen))) == NULL) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create X11 window");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XSelectInput(display, win, ExposureMask|ButtonPressMask|KeyPressMask);
|
||||
|
||||
GC default_gc;
|
||||
if ((default_gc = DefaultGC(display, screen)) == NULL) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to create X11 graphics context");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XMapWindow(display, win);
|
||||
XClearWindow(display, win);
|
||||
XMapRaised(display, win);
|
||||
XFlush(display);
|
||||
|
||||
user_data->video_enabled = true;
|
||||
|
||||
//toxav_callback_video_receive_frame(CallContrl.av, receive_video_frame_cb, &CallContrl);
|
||||
//toxav_callback_video_bit_rate_status(CallContrl.av, video_bit_rate_status_cb, &CallContrl);
|
||||
if ( !user_data->av ) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Video failed to init ToxAV");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( init_video_devices(user_data->av) == vde_InternalError ) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init video devices");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
toxav_callback_video_receive_frame(user_data->av, receive_video_frame_cb, &user_data);
|
||||
toxav_callback_video_bit_rate_status(user_data->av, video_bit_rate_status_cb, &user_data);
|
||||
|
||||
return av;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
|
||||
uint16_t width, uint16_t height,
|
||||
uint8_t const *y, uint8_t const *u, uint8_t const *v, uint8_t const *a,
|
||||
int32_t ystride, int32_t ustride, int32_t vstride, int32_t astride,
|
||||
void *user_data)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void video_bit_rate_status_cb(ToxAV *av, uint32_t friend_number,
|
||||
bool stable, uint32_t bit_rate, void *user_data)
|
||||
@ -41,3 +93,34 @@ void video_bit_rate_status_cb(ToxAV *av, uint32_t friend_number,
|
||||
if ( stable )
|
||||
cc->video_bit_rate = bit_rate;
|
||||
}
|
||||
|
||||
void cmd_list_video_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char *error_str;
|
||||
|
||||
if ( argc != 1 ) {
|
||||
if ( argc < 1 ) error_str = "Type must be specified!";
|
||||
else error_str = "Only one argument allowed!";
|
||||
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
DeviceType type;
|
||||
|
||||
if ( strcasecmp(argv[1], "in") == 0 ) /* Input devices */
|
||||
type = input;
|
||||
|
||||
else if ( strcasecmp(argv[1], "out") == 0 ) /* Output devices */
|
||||
type = output;
|
||||
|
||||
else {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid type: %s", argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
print_video_devices(self, type);
|
||||
|
||||
return;
|
||||
on_error:
|
||||
print_err (self, error_str);
|
||||
}
|
@ -26,6 +26,7 @@
|
||||
#include <tox/toxav.h>
|
||||
|
||||
#include "audio_call.h"
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
typedef enum _VideoError {
|
||||
|
@ -57,7 +57,7 @@ struct VideoBuffer {
|
||||
|
||||
typedef struct VideoDevice {
|
||||
int fd; /* File descriptor of video device selected/opened */
|
||||
DataHandleCallback cb; /* Use this to handle data from input device usually */
|
||||
VideoDataHandleCallback cb; /* Use this to handle data from input device usually */
|
||||
void* cb_data; /* Data to be passed to callback */
|
||||
int32_t friend_number; /* ToxAV friend number */
|
||||
|
||||
@ -110,7 +110,7 @@ VideoDeviceError init_video_devices(ToxAV* av_)
|
||||
VideoDeviceError init_video_devices()
|
||||
#endif /* VIDEO */
|
||||
{
|
||||
size[input] = 0;
|
||||
size[vdt_input] = 0;
|
||||
|
||||
#ifdef __linux__
|
||||
for(int i = 0; i <= MAX_DEVICES; ++i) {
|
||||
@ -122,11 +122,11 @@ VideoDeviceError init_video_devices()
|
||||
if (fd == -1)
|
||||
break;
|
||||
else {
|
||||
video_devices_names[input][i] = cap.card;
|
||||
video_devices_names[vdt_input][i] = cap.card;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
size[input] = i;
|
||||
size[vdt_input] = i;
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
/* TODO: Add OSX implementation for listing input video devices */
|
||||
@ -211,7 +211,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint
|
||||
return vde_InternalError;
|
||||
}
|
||||
|
||||
if (type == input) {
|
||||
if (type == vdt_input) {
|
||||
char device_address[] = "/dev/videoXX";
|
||||
snprintf(device_address + 10 , sizeof(device_address) - 10, "%i", selection);
|
||||
|
||||
@ -223,7 +223,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint
|
||||
|
||||
}
|
||||
|
||||
if (type == input) {
|
||||
if (type == vdt_input) {
|
||||
#ifdef __linux__
|
||||
/* Obtain video device capabilities */
|
||||
struct v4l2_capability cap;
|
||||
@ -329,12 +329,12 @@ void* video_thread_poll (void* arg) // TODO: maybe use thread for every input so
|
||||
if (video_thread_paused) usleep(10000); /* Wait for unpause. */
|
||||
else
|
||||
{
|
||||
for (i = 0; i < size[input]; ++i)
|
||||
for (i = 0; i < size[vdt_input]; ++i)
|
||||
{
|
||||
lock;
|
||||
if (video_devices_running[input][i] != NULL)
|
||||
if (video_devices_running[vdt_input][i] != NULL)
|
||||
{
|
||||
VideoDevice* device = video_devices_running[input][i];
|
||||
VideoDevice* device = video_devices_running[vdt_input][i];
|
||||
struct v4l2_buffer buf;
|
||||
memset(&(buf), 0, sizeof(buf));
|
||||
|
||||
@ -385,7 +385,7 @@ VideoDeviceError close_video_device(VideoDeviceType type, uint32_t device_idx)
|
||||
|
||||
if ( !device->ref_count ) {
|
||||
|
||||
if (type == input) {
|
||||
if (type == vdt_input) {
|
||||
int i;
|
||||
for(i = 0; i < device->n_buffers; ++i) {
|
||||
if (-1 == munmap(device->buffers[i].start, device->buffers[i].length)) {}
|
||||
@ -427,3 +427,13 @@ void yuv422to420(uint8_t *plane_y, uint8_t *plane_u, uint8_t *plane_v, uint8_t *
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void print_video_devices(ToxWindow* self, VideoDeviceType type)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size[type]; ++i)
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%d: %s", i, video_devices_names[type][i]);
|
||||
|
||||
return;
|
||||
}
|
@ -28,8 +28,8 @@
|
||||
#include "windows.h"
|
||||
|
||||
typedef enum VideoDeviceType {
|
||||
input,
|
||||
output,
|
||||
vdt_input,
|
||||
vdt_output,
|
||||
} VideoDeviceType;
|
||||
|
||||
typedef enum VideoDeviceError {
|
||||
@ -45,7 +45,7 @@ typedef enum VideoDeviceError {
|
||||
vde_CaptureError = -9,
|
||||
} VideoDeviceError;
|
||||
|
||||
typedef void (*DataHandleCallback) (int16_t width, int16_t height, const uint8_t* y, const uint8_t* u, const uint8_t* v, void* data);
|
||||
typedef void (*VideoDataHandleCallback) (int16_t width, int16_t height, const uint8_t* y, const uint8_t* u, const uint8_t* v, void* data);
|
||||
|
||||
|
||||
#ifdef VIDEO
|
||||
@ -57,7 +57,7 @@ VideoDeviceError init_video_devices();
|
||||
VideoDeviceError terminate_video_devices();
|
||||
|
||||
/* Callback handles ready data from INPUT device */
|
||||
VideoDeviceError register_video_device_callback(int32_t call_idx, uint32_t device_idx, DataHandleCallback callback, void* data);
|
||||
VideoDeviceError register_video_device_callback(int32_t call_idx, uint32_t device_idx, VideoDataHandleCallback callback, void* data);
|
||||
void* get_video_device_callback_data(uint32_t device_idx);
|
||||
|
||||
VideoDeviceError set_primary_video_device(VideoDeviceType type, int32_t selection);
|
||||
@ -68,10 +68,10 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint
|
||||
VideoDeviceError close_video_device(VideoDeviceType type, uint32_t device_idx);
|
||||
|
||||
/* Write data to device */
|
||||
VideoDeviceError write_out(uint32_t device_idx, const int16_t* data, uint32_t length, uint8_t channels);
|
||||
VideoDeviceError write_video_out(uint32_t device_idx, const int16_t* data, uint32_t length, uint8_t channels);
|
||||
|
||||
void print_video_devices(ToxWindow* self, VideoDeviceType type);
|
||||
void get_primary_video_device_name(VideoDeviceType type, char *buf, int size);
|
||||
|
||||
VideoDeviceError selection_valid(VideoDeviceType type, int32_t selection);
|
||||
VideoDeviceError video_selection_valid(VideoDeviceType type, int32_t selection);
|
||||
#endif /* VIDEO_DEVICE_H */
|
Loading…
Reference in New Issue
Block a user