mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 04:43:25 +01:00
Began implementing video_device.*
This commit is contained in:
parent
c755247434
commit
9863dfc2ae
@ -8,7 +8,7 @@ else
|
||||
endif
|
||||
|
||||
# Variables for video call support
|
||||
VIDEO_LIBS = libtoxav opencv
|
||||
VIDEO_LIBS = libtoxav xlib
|
||||
AUDIO_CFLAGS = -DVIDEO
|
||||
ifneq (, $(findstring video_device.o $(OBJ)))
|
||||
VIDEO_OBJ = video_call.o
|
||||
|
114
src/video_device.c
Normal file
114
src/video_device.c
Normal file
@ -0,0 +1,114 @@
|
||||
/* video_device.c
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2014 Toxic All Rights Reserved.
|
||||
*
|
||||
* This file is part of Toxic.
|
||||
*
|
||||
* Toxic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Toxic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "video_device.h"
|
||||
|
||||
#ifdef VIDEO
|
||||
#include "video_call.h"
|
||||
#endif /* VIDEO */
|
||||
|
||||
#include "line_info.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define inline__ inline __attribute__((always_inline))
|
||||
|
||||
extern struct user_settings *user_settings;
|
||||
|
||||
typedef struct VideoDevice {
|
||||
//ALCdevice *dhndl; /* Handle of device selected/opened */
|
||||
//ALCcontext *ctx; /* Device context */
|
||||
DataHandleCallback 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 */
|
||||
|
||||
uint32_t source, buffers[OPENAL_BUFS]; /* Playback source/buffers */
|
||||
uint32_t ref_count;
|
||||
int32_t selection;
|
||||
pthread_mutex_t mutex[1];
|
||||
uint32_t sample_rate;
|
||||
uint32_t frame_duration;
|
||||
} VideoDevice;
|
||||
|
||||
const char *ddevice_names[2]; /* Default device */
|
||||
const char *devices_names[2][MAX_DEVICES]; /* Container of available devices */
|
||||
static int size[2]; /* Size of above containers */
|
||||
Device *running[2][MAX_DEVICES] = {{NULL}}; /* Running devices */
|
||||
uint32_t primary_device[2]; /* Primary device */
|
||||
|
||||
#ifdef VIDEO
|
||||
static ToxAV* av = NULL;
|
||||
#endif /* VIDEO */
|
||||
|
||||
/* q_mutex */
|
||||
#define lock pthread_mutex_lock(&mutex);
|
||||
#define unlock pthread_mutex_unlock(&mutex);
|
||||
pthread_mutext_t mutex;
|
||||
|
||||
bool thread_running = true,
|
||||
thread_paused = true; /* Thread control */
|
||||
|
||||
void* thread_poll(void*);
|
||||
/* Meet devices */
|
||||
#ifndef VIDEO
|
||||
VideoDeviceError init_video_devices(ToxAV* av_)
|
||||
#else
|
||||
#endif /* VIDEO */
|
||||
{
|
||||
const char *stringed_device_list;
|
||||
|
||||
size[input] = 0;
|
||||
|
||||
size[output] = 0;
|
||||
|
||||
// Start poll thread
|
||||
if (pthread_mutex_init(&mutex, NULL) != 0)
|
||||
return vde_InternalError;
|
||||
|
||||
pthread_t thread_id;
|
||||
if ( pthread_create(&thread_id, NULL, thread_poll, NULL) != 0 || pthread_detatch(thread_id) != 0)
|
||||
return vde_InternalError;
|
||||
|
||||
#ifdef VIDEO
|
||||
av = av_;
|
||||
#endif /* VIDEO */
|
||||
|
||||
return (VideoDeviceError) vde_None;
|
||||
}
|
||||
|
||||
VideoDeviceError terminate_video_devices()
|
||||
{
|
||||
/* Cleanup if needed */
|
||||
thread_running = false;
|
||||
usleep(20000);
|
||||
|
||||
if (pthread_mutex_destroy(&mutex) != 0)
|
||||
return (VideoDeviceError) vde_InternalError;
|
||||
|
||||
return (VideoDeviceError) vde_None;
|
||||
}
|
@ -18,4 +18,60 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef VIDEO_DEVICE_H
|
||||
#define VIDEO_DEVICE_H
|
||||
|
||||
#define MAX_DEVICES 32
|
||||
#include <inttypes.h>
|
||||
#include "windows.h"
|
||||
|
||||
typedef enum VideoDeviceType {
|
||||
input,
|
||||
output,
|
||||
} VideoDeviceType;
|
||||
|
||||
typedef enum VideoDeviceError {
|
||||
vde_None,
|
||||
vde_InternalError = -1,
|
||||
vde_InvalidSelection = -2,
|
||||
vde_FailedStart = -3,
|
||||
vde_Busy = -4,
|
||||
vde_AllDevicesBusy = -5,
|
||||
vde_DeviceNotActive = -6,
|
||||
vde_BufferError = -7,
|
||||
vde_UnsupportedMode = -8,
|
||||
vde_CaptureError = -9,
|
||||
} VideoDeviceError;
|
||||
|
||||
typedef void (*DataHandleCallback) (const int16_t*, uint32_t size, void* data);
|
||||
|
||||
|
||||
#ifdef VIDEO
|
||||
DeviceError init_video_devices(ToxAV* av);
|
||||
#else
|
||||
DeviceError init_video_devices();
|
||||
#endif /* VIDEO */
|
||||
|
||||
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);
|
||||
void* get_video_device_callback_data(uint32_t device_idx);
|
||||
|
||||
VideoDeviceError set_primary_video_device(VideoDeviceType type, int32_t selection);
|
||||
VideoDeviceError open_primary_video_device(VideoDeviceType type, uint32_t* device_idx, uint32_t sample_rate, uint32_t frame_duration, uint8_t channels);
|
||||
/* Start device */
|
||||
VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint32_t* device_idx, uint32_t sample_rate, uint32_t frame_duration, uint8_t channels);
|
||||
/* Stop device */
|
||||
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);
|
||||
|
||||
void print_devices(ToxWindow* self, DeviceType type);
|
||||
void get_primary_device_name(VideoDeviceType type, char *buf, int size);
|
||||
|
||||
VideoDeviceError selection_valid(VideoDeviceType type, int32_t selection);
|
||||
#endif /* VIDEO_DEVICE_H */
|
Loading…
Reference in New Issue
Block a user