mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 01:23:03 +01:00
Modified header files structuring
This commit is contained in:
parent
8f28f1d748
commit
2369b5e9e2
@ -51,8 +51,6 @@
|
|||||||
|
|
||||||
#define cbend pthread_exit(NULL)
|
#define cbend pthread_exit(NULL)
|
||||||
|
|
||||||
#define MAX_CALLS 10
|
|
||||||
|
|
||||||
#define frame_size (CallContrl.audio_sample_rate * CallContrl.audio_frame_duration / 1000)
|
#define frame_size (CallContrl.audio_sample_rate * CallContrl.audio_frame_duration / 1000)
|
||||||
|
|
||||||
static int set_call(Call* call, bool start)
|
static int set_call(Call* call, bool start)
|
||||||
@ -75,29 +73,6 @@ static int set_call(Call* call, bool start)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct CallControl {
|
|
||||||
AudioError errors;
|
|
||||||
|
|
||||||
ToxAV *av;
|
|
||||||
ToxWindow *window;
|
|
||||||
|
|
||||||
Call calls[MAX_CALLS];
|
|
||||||
bool pending_call;
|
|
||||||
uint32_t call_state;
|
|
||||||
|
|
||||||
bool audio_enabled;
|
|
||||||
bool video_enabled;
|
|
||||||
uint32_t audio_bit_rate;
|
|
||||||
uint32_t video_bit_rate;
|
|
||||||
uint32_t audio_sample_rate;
|
|
||||||
uint32_t video_sample_rate;
|
|
||||||
int32_t audio_frame_duration;
|
|
||||||
int32_t video_frame_duration;
|
|
||||||
|
|
||||||
uint8_t audio_channels;
|
|
||||||
|
|
||||||
} CallControl;
|
|
||||||
|
|
||||||
CallControl CallContrl;
|
CallControl CallContrl;
|
||||||
|
|
||||||
void call_cb( ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data );
|
void call_cb( ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data );
|
||||||
@ -140,22 +115,30 @@ ToxAV *init_audio(ToxWindow *self, Tox *tox)
|
|||||||
CallContrl.errors = ae_None;
|
CallContrl.errors = ae_None;
|
||||||
CallContrl.window = self;
|
CallContrl.window = self;
|
||||||
|
|
||||||
CallContrl.audio_enabled = true;
|
|
||||||
CallContrl.video_enabled = false;
|
|
||||||
CallContrl.audio_bit_rate = 48;
|
|
||||||
CallContrl.video_bit_rate = 0;
|
|
||||||
CallContrl.audio_sample_rate = 48000;
|
|
||||||
CallContrl.video_sample_rate = 0;
|
|
||||||
CallContrl.audio_frame_duration = 10;
|
|
||||||
CallContrl.video_frame_duration = 0;
|
|
||||||
CallContrl.audio_channels = 1;
|
|
||||||
|
|
||||||
memset(CallContrl.calls, 0, sizeof(CallContrl.calls));
|
|
||||||
|
|
||||||
/* Streaming stuff from core */
|
|
||||||
|
|
||||||
CallContrl.av = toxav_new(tox, &error);
|
CallContrl.av = toxav_new(tox, &error);
|
||||||
|
|
||||||
|
CallContrl.audio_enabled = true;
|
||||||
|
CallContrl.audio_bit_rate = 48;
|
||||||
|
CallContrl.audio_sample_rate = 48000;
|
||||||
|
CallContrl.audio_frame_duration = 10;
|
||||||
|
CallContrl.audio_channels = 1;
|
||||||
|
|
||||||
|
#ifdef VIDEO
|
||||||
|
if ( !init_video(self, tox, CallContrl.av, &CallContrl) ) {
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init video");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (CallContrl.video_enabled == true) {
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Video enabled");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
CallContrl.video_enabled = false;
|
||||||
|
CallContrl.video_bit_rate = 0;
|
||||||
|
CallContrl.video_sample_rate = 0;
|
||||||
|
CallContrl.video_frame_duration = 0;
|
||||||
|
#endif /* VIDEO */
|
||||||
|
|
||||||
|
memset(CallContrl.calls, 0, sizeof(CallContrl.calls));
|
||||||
|
|
||||||
if ( !CallContrl.av ) {
|
if ( !CallContrl.av ) {
|
||||||
CallContrl.errors |= ae_StartingCoreAudio;
|
CallContrl.errors |= ae_StartingCoreAudio;
|
||||||
@ -343,25 +326,6 @@ void audio_bit_rate_status_cb(ToxAV *av, uint32_t friend_number,
|
|||||||
cc->audio_bit_rate = bit_rate;
|
cc->audio_bit_rate = bit_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
CallControl* cc = user_data;
|
|
||||||
|
|
||||||
if ( stable )
|
|
||||||
cc->video_bit_rate = bit_rate;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define CB_BODY(friend_number, Arg, onFunc) do { ToxWindow* windows = (Arg); int i;\
|
#define CB_BODY(friend_number, Arg, onFunc) do { ToxWindow* windows = (Arg); int i;\
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) if (windows[i].onFunc != NULL) windows[i].onFunc(&windows[i], CallContrl.av, friend_number); } while (0)
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i) if (windows[i].onFunc != NULL) windows[i].onFunc(&windows[i], CallContrl.av, friend_number); } while (0)
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include "audio_device.h"
|
#include "audio_device.h"
|
||||||
|
|
||||||
|
#define MAX_CALLS 10
|
||||||
|
|
||||||
typedef enum _AudioError {
|
typedef enum _AudioError {
|
||||||
ae_None = 0,
|
ae_None = 0,
|
||||||
ae_StartingCaptureDevice = 1 << 0,
|
ae_StartingCaptureDevice = 1 << 0,
|
||||||
@ -41,6 +43,29 @@ typedef struct Call {
|
|||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
} Call;
|
} Call;
|
||||||
|
|
||||||
|
typedef struct CallControl {
|
||||||
|
AudioError errors;
|
||||||
|
|
||||||
|
ToxAV *av;
|
||||||
|
ToxWindow *window;
|
||||||
|
|
||||||
|
Call calls[MAX_CALLS];
|
||||||
|
bool pending_call;
|
||||||
|
uint32_t call_state;
|
||||||
|
|
||||||
|
bool audio_enabled;
|
||||||
|
bool video_enabled;
|
||||||
|
uint32_t audio_bit_rate;
|
||||||
|
uint32_t video_bit_rate;
|
||||||
|
uint32_t audio_sample_rate;
|
||||||
|
uint32_t video_sample_rate;
|
||||||
|
int32_t audio_frame_duration;
|
||||||
|
int32_t video_frame_duration;
|
||||||
|
|
||||||
|
uint8_t audio_channels;
|
||||||
|
|
||||||
|
} CallControl;
|
||||||
|
|
||||||
/* You will have to pass pointer to first member of 'windows' declared in windows.c */
|
/* You will have to pass pointer to first member of 'windows' declared in windows.c */
|
||||||
ToxAV *init_audio(ToxWindow *self, Tox *tox);
|
ToxAV *init_audio(ToxWindow *self, Tox *tox);
|
||||||
void terminate_audio();
|
void terminate_audio();
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
#include "toxic.h"
|
||||||
|
#include "windows.h"
|
||||||
|
#include "video_call.h"
|
||||||
|
#include "chat_commands.h"
|
||||||
|
#include "global_commands.h"
|
||||||
|
#include "line_info.h"
|
||||||
|
#include "notify.h"
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
ToxAV *init_video(ToxWindow *self, Tox *tox, ToxAV *av, CallControl *user_data)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
CallControl* cc = user_data;
|
||||||
|
|
||||||
|
if ( stable )
|
||||||
|
cc->video_bit_rate = bit_rate;
|
||||||
|
}
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <tox/toxav.h>
|
#include <tox/toxav.h>
|
||||||
|
|
||||||
|
#include "audio_call.h"
|
||||||
#include "video_device.h"
|
#include "video_device.h"
|
||||||
|
|
||||||
typedef enum _VideoError {
|
typedef enum _VideoError {
|
||||||
@ -35,7 +36,7 @@ typedef enum _VideoError {
|
|||||||
} VideoError;
|
} VideoError;
|
||||||
|
|
||||||
/* You will have to pass pointer to first member of 'windows' declared in windows.c */
|
/* You will have to pass pointer to first member of 'windows' declared in windows.c */
|
||||||
ToxAV *init_video(ToxWindow *self, Tox *tox);
|
ToxAV *init_video(ToxWindow *self, Tox *tox, ToxAV *av, CallControl *user_data);
|
||||||
void terminate_video();
|
void terminate_video();
|
||||||
//int start_video_transmission(ToxWindow *self, Call *call);
|
//int start_video_transmission(ToxWindow *self, Call *call);
|
||||||
//int stop_video_transmission(Call *call, int friend_number);
|
//int stop_video_transmission(Call *call, int friend_number);
|
||||||
|
@ -72,11 +72,11 @@ typedef struct VideoDevice {
|
|||||||
uint16_t video_height;
|
uint16_t video_height;
|
||||||
} VideoDevice;
|
} VideoDevice;
|
||||||
|
|
||||||
const char *ddevice_names[2]; /* Default device */
|
const char *dvideo_device_names[2]; /* Default device */
|
||||||
const char *devices_names[2][MAX_DEVICES]; /* Container of available devices */
|
const char *video_devices_names[2][MAX_DEVICES]; /* Container of available devices */
|
||||||
static int size[2]; /* Size of above containers */
|
static int size[2]; /* Size of above containers */
|
||||||
VideoDevice *running[2][MAX_DEVICES] = {{NULL}}; /* Running devices */
|
VideoDevice *video_devices_running[2][MAX_DEVICES] = {{NULL}}; /* Running devices */
|
||||||
uint32_t primary_device[2]; /* Primary device */
|
uint32_t primary_video_device[2]; /* Primary device */
|
||||||
|
|
||||||
#ifdef VIDEO
|
#ifdef VIDEO
|
||||||
static ToxAV* av = NULL;
|
static ToxAV* av = NULL;
|
||||||
@ -87,10 +87,10 @@ static ToxAV* av = NULL;
|
|||||||
#define unlock pthread_mutex_unlock(&mutex);
|
#define unlock pthread_mutex_unlock(&mutex);
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
|
||||||
bool thread_running = true,
|
bool video_thread_running = true,
|
||||||
thread_paused = true; /* Thread control */
|
video_thread_paused = true; /* Thread control */
|
||||||
|
|
||||||
void* thread_poll(void*);
|
void* video_thread_poll(void*);
|
||||||
|
|
||||||
static int xioctl(int fh, unsigned long request, void *arg)
|
static int xioctl(int fh, unsigned long request, void *arg)
|
||||||
{
|
{
|
||||||
@ -122,7 +122,7 @@ VideoDeviceError init_video_devices()
|
|||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
break;
|
break;
|
||||||
else {
|
else {
|
||||||
devices_names[input][i] = cap.card;
|
video_devices_names[input][i] = cap.card;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -139,7 +139,7 @@ VideoDeviceError init_video_devices()
|
|||||||
return vde_InternalError;
|
return vde_InternalError;
|
||||||
|
|
||||||
pthread_t thread_id;
|
pthread_t thread_id;
|
||||||
if ( pthread_create(&thread_id, NULL, thread_poll, NULL) != 0 || pthread_detach(thread_id) != 0)
|
if ( pthread_create(&thread_id, NULL, video_thread_poll, NULL) != 0 || pthread_detach(thread_id) != 0)
|
||||||
return vde_InternalError;
|
return vde_InternalError;
|
||||||
|
|
||||||
#ifdef VIDEO
|
#ifdef VIDEO
|
||||||
@ -152,7 +152,7 @@ VideoDeviceError init_video_devices()
|
|||||||
VideoDeviceError terminate_video_devices()
|
VideoDeviceError terminate_video_devices()
|
||||||
{
|
{
|
||||||
/* Cleanup if needed */
|
/* Cleanup if needed */
|
||||||
thread_running = false;
|
video_thread_running = false;
|
||||||
usleep(20000);
|
usleep(20000);
|
||||||
|
|
||||||
if (pthread_mutex_destroy(&mutex) != 0)
|
if (pthread_mutex_destroy(&mutex) != 0)
|
||||||
@ -164,19 +164,19 @@ VideoDeviceError terminate_video_devices()
|
|||||||
VideoDeviceError set_primary_video_device(VideoDeviceType type, int32_t selection)
|
VideoDeviceError set_primary_video_device(VideoDeviceType type, int32_t selection)
|
||||||
{
|
{
|
||||||
if (size[type] <= selection || selection < 0) return vde_InvalidSelection;
|
if (size[type] <= selection || selection < 0) return vde_InvalidSelection;
|
||||||
primary_device[type] = selection;
|
primary_video_device[type] = selection;
|
||||||
|
|
||||||
return vde_None;
|
return vde_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoDeviceError open_primary_video_device(VideoDeviceType type, uint32_t* device_idx)
|
VideoDeviceError open_primary_video_device(VideoDeviceType type, uint32_t* device_idx)
|
||||||
{
|
{
|
||||||
return open_video_device(type, primary_device[type], device_idx);
|
return open_video_device(type, primary_video_device[type], device_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_primary_device_name(VideoDeviceType type, char *buf, int size)
|
void get_primary_video_device_name(VideoDeviceType type, char *buf, int size)
|
||||||
{
|
{
|
||||||
memcpy(buf, ddevice_names[type], size);
|
memcpy(buf, dvideo_device_names[type], size);
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint32_t* device_idx)
|
VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint32_t* device_idx)
|
||||||
@ -186,23 +186,23 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint
|
|||||||
lock;
|
lock;
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
for (i = 0; i < MAX_DEVICES && running[type][i] != NULL; ++i);
|
for (i = 0; i < MAX_DEVICES && video_devices_running[type][i] != NULL; ++i);
|
||||||
|
|
||||||
if (i == MAX_DEVICES) { unlock; return vde_AllDevicesBusy; }
|
if (i == MAX_DEVICES) { unlock; return vde_AllDevicesBusy; }
|
||||||
else *device_idx = i;
|
else *device_idx = i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_DEVICES; i ++) { /* Check if any device has the same selection */
|
for (i = 0; i < MAX_DEVICES; i ++) { /* Check if any device has the same selection */
|
||||||
if ( running[type][i] && running[type][i]->selection == selection ) {
|
if ( video_devices_running[type][i] && video_devices_running[type][i]->selection == selection ) {
|
||||||
|
|
||||||
running[type][*device_idx] = running[type][i];
|
video_devices_running[type][*device_idx] = video_devices_running[type][i];
|
||||||
running[type][i]->ref_count ++;
|
video_devices_running[type][i]->ref_count ++;
|
||||||
|
|
||||||
unlock;
|
unlock;
|
||||||
return vde_None;
|
return vde_None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoDevice* device = running[type][*device_idx] = calloc(1, sizeof(VideoDevice));
|
VideoDevice* device = video_devices_running[type][*device_idx] = calloc(1, sizeof(VideoDevice));
|
||||||
device->selection = selection;
|
device->selection = selection;
|
||||||
|
|
||||||
if (pthread_mutex_init(device->mutex, NULL) != 0) {
|
if (pthread_mutex_init(device->mutex, NULL) != 0) {
|
||||||
@ -308,14 +308,14 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint
|
|||||||
|
|
||||||
/*TODO: Add OSX implementation of opening video devices */
|
/*TODO: Add OSX implementation of opening video devices */
|
||||||
|
|
||||||
thread_paused = false;
|
video_thread_paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock;
|
unlock;
|
||||||
return vde_None;
|
return vde_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* thread_poll (void* arg) // TODO: maybe use thread for every input source
|
void* video_thread_poll (void* arg) // TODO: maybe use thread for every input source
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* NOTE: We only need to poll input devices for data.
|
* NOTE: We only need to poll input devices for data.
|
||||||
@ -324,17 +324,17 @@ void* thread_poll (void* arg) // TODO: maybe use thread for every input source
|
|||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
|
|
||||||
while (thread_running)
|
while (video_thread_running)
|
||||||
{
|
{
|
||||||
if (thread_paused) usleep(10000); /* Wait for unpause. */
|
if (video_thread_paused) usleep(10000); /* Wait for unpause. */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = 0; i < size[input]; ++i)
|
for (i = 0; i < size[input]; ++i)
|
||||||
{
|
{
|
||||||
lock;
|
lock;
|
||||||
if (running[input][i] != NULL)
|
if (video_devices_running[input][i] != NULL)
|
||||||
{
|
{
|
||||||
VideoDevice* device = running[input][i];
|
VideoDevice* device = video_devices_running[input][i];
|
||||||
struct v4l2_buffer buf;
|
struct v4l2_buffer buf;
|
||||||
memset(&(buf), 0, sizeof(buf));
|
memset(&(buf), 0, sizeof(buf));
|
||||||
|
|
||||||
@ -373,7 +373,7 @@ VideoDeviceError close_video_device(VideoDeviceType type, uint32_t device_idx)
|
|||||||
if (device_idx >= MAX_DEVICES) return vde_InvalidSelection;
|
if (device_idx >= MAX_DEVICES) return vde_InvalidSelection;
|
||||||
|
|
||||||
lock;
|
lock;
|
||||||
VideoDevice* device = running[type][device_idx];
|
VideoDevice* device = video_devices_running[type][device_idx];
|
||||||
VideoDeviceError rc = vde_None;
|
VideoDeviceError rc = vde_None;
|
||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
@ -381,7 +381,7 @@ VideoDeviceError close_video_device(VideoDeviceType type, uint32_t device_idx)
|
|||||||
return vde_DeviceNotActive;
|
return vde_DeviceNotActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
running[type][device_idx] = NULL;
|
video_devices_running[type][device_idx] = NULL;
|
||||||
|
|
||||||
if ( !device->ref_count ) {
|
if ( !device->ref_count ) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user