1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 15:03:27 +01:00

Fix a few A/V race conditions

This commit is contained in:
Jfreegman 2016-09-22 18:00:14 -04:00
parent 38ec96e96a
commit c24e1bd2b8
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
4 changed files with 35 additions and 20 deletions

View File

@ -321,9 +321,6 @@ DeviceError close_device(DeviceType type, uint32_t device_idx)
running[type][device_idx] = NULL; running[type][device_idx] = NULL;
if ( !device->ref_count ) { if ( !device->ref_count ) {
// printf("Closed device ");
if (type == input) { if (type == input) {
if ( !alcCaptureCloseDevice(device->dhndl) ) rc = de_AlError; if ( !alcCaptureCloseDevice(device->dhndl) ) rc = de_AlError;
} }
@ -414,23 +411,26 @@ void* thread_poll (void* arg) // TODO: maybe use thread for every input source
int32_t sample = 0; int32_t sample = 0;
while (true) while (1)
{ {
lock; lock;
if (!thread_running) { if (!thread_running) {
unlock; unlock;
break; break;
} }
bool paused = thread_paused;
unlock; unlock;
if (thread_paused) usleep(10000); /* Wait for unpause. */ /* Wait for unpause. */
else if (paused) {
{ usleep(10000);
for (i = 0; i < size[input]; ++i) }
{
else {
for (i = 0; i < size[input]; ++i) {
lock; lock;
if (running[input][i] != NULL) if (running[input][i] != NULL) {
{
alcGetIntegerv(running[input][i]->dhndl, ALC_CAPTURE_SAMPLES, sizeof(int32_t), &sample); alcGetIntegerv(running[input][i]->dhndl, ALC_CAPTURE_SAMPLES, sizeof(int32_t), &sample);
int f_size = (running[input][i]->sample_rate * running[input][i]->frame_duration / 1000); int f_size = (running[input][i]->sample_rate * running[input][i]->frame_duration / 1000);

View File

@ -79,7 +79,7 @@ extern struct Winthread Winthread;
#define MAX_NODELIST_SIZE (MAX_RECV_CURL_DATA_SIZE) #define MAX_NODELIST_SIZE (MAX_RECV_CURL_DATA_SIZE)
struct Thread_Data { static struct Thread_Data {
pthread_t tid; pthread_t tid;
pthread_attr_t attr; pthread_attr_t attr;
pthread_mutex_t lock; pthread_mutex_t lock;

View File

@ -683,7 +683,9 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y2 - CHATBOX_HEIGHT); mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y2 - CHATBOX_HEIGHT);
mvwaddch(ctx->sidebar, y2 - CHATBOX_HEIGHT, 0, ACS_BTEE); mvwaddch(ctx->sidebar, y2 - CHATBOX_HEIGHT, 0, ACS_BTEE);
pthread_mutex_lock(&Winthread.lock);
int num_peers = groupchats[self->num].num_peers; int num_peers = groupchats[self->num].num_peers;
pthread_mutex_unlock(&Winthread.lock);
wmove(ctx->sidebar, 0, 1); wmove(ctx->sidebar, 0, 1);
wattron(ctx->sidebar, A_BOLD); wattron(ctx->sidebar, A_BOLD);
@ -698,12 +700,19 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
for (i = 0; i < num_peers && i < maxlines; ++i) { for (i = 0; i < num_peers && i < maxlines; ++i) {
wmove(ctx->sidebar, i + 2, 1); wmove(ctx->sidebar, i + 2, 1);
pthread_mutex_lock(&Winthread.lock);
int peer = i + groupchats[self->num].side_pos; int peer = i + groupchats[self->num].side_pos;
pthread_mutex_unlock(&Winthread.lock);
/* truncate nick to fit in side panel without modifying list */ /* truncate nick to fit in side panel without modifying list */
char tmpnck[TOX_MAX_NAME_LENGTH]; char tmpnck[TOX_MAX_NAME_LENGTH];
int maxlen = SIDEBAR_WIDTH - 2; int maxlen = SIDEBAR_WIDTH - 2;
pthread_mutex_lock(&Winthread.lock);
memcpy(tmpnck, &groupchats[self->num].peer_names[peer * TOX_MAX_NAME_LENGTH], maxlen); memcpy(tmpnck, &groupchats[self->num].peer_names[peer * TOX_MAX_NAME_LENGTH], maxlen);
pthread_mutex_unlock(&Winthread.lock);
tmpnck[maxlen] = '\0'; tmpnck[maxlen] = '\0';
wprintw(ctx->sidebar, "%s\n", tmpnck); wprintw(ctx->sidebar, "%s\n", tmpnck);

View File

@ -236,7 +236,10 @@ VideoDeviceError init_video_devices()
VideoDeviceError terminate_video_devices() VideoDeviceError terminate_video_devices()
{ {
/* Cleanup if needed */ /* Cleanup if needed */
lock;
video_thread_running = false; video_thread_running = false;
unlock;
usleep(20000); usleep(20000);
int i; int i;
@ -614,16 +617,19 @@ void* video_thread_poll (void* arg) // TODO: maybe use thread for every input so
(void)arg; (void)arg;
uint32_t i; uint32_t i;
while (video_thread_running) while (1) {
{ lock;
if (!video_thread_running) {
unlock;
break;
}
unlock;
if ( video_thread_paused ) usleep(10000); /* Wait for unpause. */ if ( video_thread_paused ) usleep(10000); /* Wait for unpause. */
else else {
{ for (i = 0; i < size[vdt_input]; ++i) {
for (i = 0; i < size[vdt_input]; ++i)
{
lock; lock;
if ( video_devices_running[vdt_input][i] != NULL ) if ( video_devices_running[vdt_input][i] != NULL ) {
{
/* Obtain frame image data from device buffers */ /* Obtain frame image data from device buffers */
VideoDevice* device = video_devices_running[vdt_input][i]; VideoDevice* device = video_devices_running[vdt_input][i];
uint16_t video_width = device->video_width; uint16_t video_width = device->video_width;