From 9af7c335e7f198e6ac2ebe7554be2b30ffcbfbb4 Mon Sep 17 00:00:00 2001 From: mannol Date: Sat, 5 Jul 2014 17:36:12 +0200 Subject: [PATCH] This might be causing problems --- toxav/msi.c | 108 +++++++++++++++++++++++++------------------------- toxav/msi.h | 4 +- toxav/toxav.c | 42 ++++++++++---------- 3 files changed, 77 insertions(+), 77 deletions(-) diff --git a/toxav/msi.c b/toxav/msi.c index 71a138d2..999f86b6 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -1082,7 +1082,7 @@ MSICall *init_call ( MSISession *session, int peers, int ringing_timeout ) call->ringing_tout_ms = ringing_timeout; - pthread_mutex_init ( call->mutex, NULL ); + pthread_mutex_init ( &call->mutex, NULL ); LOGGER_DEBUG("Started new call with index: %u", call_idx); return call; @@ -1104,7 +1104,7 @@ int terminate_call ( MSISession *session, MSICall *call ) return -1; } - int rc = pthread_mutex_trylock(session->mutex); /* Lock if not locked */ + int rc = pthread_mutex_trylock(&session->mutex); /* Lock if not locked */ LOGGER_DEBUG("Terminated call id: %d", call->call_idx); /* Check event loop and cancel timed events if there are any @@ -1115,7 +1115,7 @@ int terminate_call ( MSISession *session, MSICall *call ) timer_release ( session->timer_handler, call->ringing_timer_id ); /* Get a handle */ - pthread_mutex_lock ( call->mutex ); + pthread_mutex_lock ( &call->mutex ); session->calls[call->call_idx] = NULL; @@ -1123,14 +1123,14 @@ int terminate_call ( MSISession *session, MSICall *call ) free ( call->peers); /* Release handle */ - pthread_mutex_unlock ( call->mutex ); + pthread_mutex_unlock ( &call->mutex ); - pthread_mutex_destroy ( call->mutex ); + pthread_mutex_destroy ( &call->mutex ); free ( call ); if ( rc != EBUSY ) /* Unlock if locked by this call */ - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } @@ -1174,7 +1174,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg ) { LOGGER_DEBUG("Session: %p Handling 'invite' on call: %s", session, call ? (char *)call->id : "making new"); - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); if ( call ) { @@ -1194,27 +1194,27 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg ) call = init_call ( session, 1, 0 ); if ( !call ) { - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); LOGGER_ERROR("Starting call"); return 0; } } else { - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; /* Wait for ringing from peer */ } } else { send_error ( session, call, error_busy, msg->friend_id ); /* TODO: Ugh*/ terminate_call(session, call); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } } else { call = init_call ( session, 1, 0 ); if ( !call ) { - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); LOGGER_ERROR("Starting call"); return 0; } @@ -1223,7 +1223,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg ) if ( !msg->callid.header_value ) { send_error ( session, call, error_no_callid, msg->friend_id ); terminate_call(session, call); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } @@ -1238,7 +1238,7 @@ int handle_recv_invite ( MSISession *session, MSICall *call, MSIMessage *msg ) send_message ( session, call, _msg_ringing, msg->friend_id ); free_message ( _msg_ringing ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); invoke_callback(call->call_idx, MSI_OnInvite); @@ -1253,13 +1253,13 @@ int handle_recv_start ( MSISession *session, MSICall *call, MSIMessage *msg ) LOGGER_DEBUG("Session: %p Handling 'start' on call: %s, friend id: %d", session, call->id, msg->friend_id ); - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); call->state = call_active; flush_peer_type ( call, msg, 0 ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); invoke_callback(call->call_idx, MSI_OnStart); return 1; @@ -1273,14 +1273,14 @@ int handle_recv_reject ( MSISession *session, MSICall *call, MSIMessage *msg ) LOGGER_DEBUG("Session: %p Handling 'reject' on call: %s", session, call->id); - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) ); send_message ( session, call, _msg_ending, msg->friend_id ); free_message ( _msg_ending ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); invoke_callback(call->call_idx, MSI_OnReject); @@ -1296,11 +1296,11 @@ int handle_recv_cancel ( MSISession *session, MSICall *call, MSIMessage *msg ) LOGGER_DEBUG("Session: %p Handling 'cancel' on call: %s", session, call->id ); - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); /* Act as end message */ - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); invoke_callback(call->call_idx, MSI_OnCancel); terminate_call ( session, call ); @@ -1315,13 +1315,13 @@ int handle_recv_end ( MSISession *session, MSICall *call, MSIMessage *msg ) LOGGER_DEBUG("Session: %p Handling 'end' on call: %s", session, call->id ); - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); MSIMessage *_msg_ending = msi_new_message ( TYPE_RESPONSE, stringify_response ( ending ) ); send_message ( session, call, _msg_ending, msg->friend_id ); free_message ( _msg_ending ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); invoke_callback(call->call_idx, MSI_OnEnd); @@ -1337,11 +1337,11 @@ int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg ) return 0; } - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); if ( call->ringing_timer_id ) { LOGGER_WARNING("Call already ringing"); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } @@ -1349,7 +1349,7 @@ int handle_recv_ringing ( MSISession *session, MSICall *call, MSIMessage *msg ) call->ringing_timer_id = timer_alloc ( session->timer_handler, handle_timeout, call, call->ringing_tout_ms ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); invoke_callback(call->call_idx, MSI_OnRinging); return 1; @@ -1361,7 +1361,7 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg ) return 0; } - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); LOGGER_DEBUG("Session: %p Handling 'starting' on call: %s", session, call->id ); @@ -1375,7 +1375,7 @@ int handle_recv_starting ( MSISession *session, MSICall *call, MSIMessage *msg ) timer_release ( session->timer_handler, call->ringing_timer_id ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); invoke_callback(call->call_idx, MSI_OnStarting); return 1; @@ -1387,14 +1387,14 @@ int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg ) return 0; } - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); LOGGER_DEBUG("Session: %p Handling 'ending' on call: %s", session, call->id ); /* Stop timer */ timer_release ( session->timer_handler, call->request_timer_id ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); invoke_callback(call->call_idx, MSI_OnEnding); @@ -1405,11 +1405,11 @@ int handle_recv_ending ( MSISession *session, MSICall *call, MSIMessage *msg ) } int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg ) { - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); if ( !call ) { LOGGER_WARNING("Handling 'error' on non-existing call!"); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return -1; } @@ -1422,7 +1422,7 @@ int handle_recv_error ( MSISession *session, MSICall *call, MSIMessage *msg ) LOGGER_DEBUG("Error reason: %s", session->last_error_str); } - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); invoke_callback(call->call_idx, MSI_OnEnding); @@ -1631,7 +1631,7 @@ MSISession *msi_init_session ( Messenger *messenger, int32_t max_calls ) /* This is called when remote terminates session */ m_callback_connectionstatus_internal_av(messenger, handle_remote_connection_change, retu); - pthread_mutex_init(retu->mutex, NULL); + pthread_mutex_init(&retu->mutex, NULL); LOGGER_DEBUG("New msi session: %p max calls: %u", retu, max_calls); return retu; @@ -1651,9 +1651,9 @@ int msi_terminate_session ( MSISession *session ) return -1; } - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); m_callback_msi_packet((struct Messenger *) session->messenger_handle, NULL, NULL); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); int _status = 0; @@ -1671,7 +1671,7 @@ int msi_terminate_session ( MSISession *session ) timer_terminate_session(session->timer_handler); - pthread_mutex_destroy(session->mutex); + pthread_mutex_destroy(&session->mutex); LOGGER_DEBUG("Terminated session: %p", session); free ( session ); @@ -1690,7 +1690,7 @@ int msi_terminate_session ( MSISession *session ) */ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type, uint32_t rngsec, uint32_t friend_id ) { - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); LOGGER_DEBUG("Session: %p Inviting friend: %u", session, friend_id); @@ -1698,7 +1698,7 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type MSICall *_call = init_call ( session, 1, rngsec ); /* Just one peer for now */ if ( !_call ) { - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); LOGGER_ERROR("Cannot handle more calls"); return -1; } @@ -1729,7 +1729,7 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type LOGGER_DEBUG("Invite sent"); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } @@ -1746,18 +1746,18 @@ int msi_invite ( MSISession *session, int32_t *call_index, MSICallType call_type */ int msi_hangup ( MSISession *session, int32_t call_index ) { - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); LOGGER_DEBUG("Session: %p Hanging up call: %u", session, call_index); if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { LOGGER_ERROR("Invalid call index!"); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return -1; } if ( !session->calls[call_index] || session->calls[call_index]->state != call_active ) { LOGGER_ERROR("No call with such index or call is not active!"); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return -1; } @@ -1776,7 +1776,7 @@ int msi_hangup ( MSISession *session, int32_t call_index ) session->calls[call_index]->request_timer_id = timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } @@ -1791,12 +1791,12 @@ int msi_hangup ( MSISession *session, int32_t call_index ) */ int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type ) { - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); LOGGER_DEBUG("Session: %p Answering call: %u", session, call_index); if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { LOGGER_ERROR("Invalid call index!"); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return -1; } @@ -1818,7 +1818,7 @@ int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type session->calls[call_index]->state = call_active; - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } @@ -1833,12 +1833,12 @@ int msi_answer ( MSISession *session, int32_t call_index, MSICallType call_type */ int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const char *reason ) { - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); LOGGER_DEBUG("Session: %p Canceling call: %u; reason:", session, call_index, reason ? reason : "Unknown"); if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { LOGGER_ERROR("Invalid call index!"); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return -1; } @@ -1852,7 +1852,7 @@ int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const c /*session->calls[call_index]->state = call_hanged_up; session->calls[call_index]->request_timer_id = timer_alloc ( handle_timeout, session->calls[call_index], m_deftout );*/ terminate_call ( session, session->calls[call_index] ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } @@ -1867,12 +1867,12 @@ int msi_cancel ( MSISession *session, int32_t call_index, uint32_t peer, const c */ int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason ) { - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); LOGGER_DEBUG("Session: %p Rejecting call: %u; reason:", session, call_index, reason ? (char *)reason : "Unknown"); if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { LOGGER_ERROR("Invalid call index!"); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return -1; } @@ -1889,7 +1889,7 @@ int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason session->calls[call_index]->request_timer_id = timer_alloc ( session->timer_handler, handle_timeout, session->calls[call_index], m_deftout ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } @@ -1903,11 +1903,11 @@ int msi_reject ( MSISession *session, int32_t call_index, const uint8_t *reason */ int msi_stopcall ( MSISession *session, int32_t call_index ) { - pthread_mutex_lock(session->mutex); + pthread_mutex_lock(&session->mutex); LOGGER_DEBUG("Session: %p Stopping call index: %u", session, call_index); if ( call_index < 0 || call_index >= session->max_calls || !session->calls[call_index] ) { - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return -1; } @@ -1915,6 +1915,6 @@ int msi_stopcall ( MSISession *session, int32_t call_index ) terminate_call ( session, session->calls[call_index] ); - pthread_mutex_unlock(session->mutex); + pthread_mutex_unlock(&session->mutex); return 0; } diff --git a/toxav/msi.h b/toxav/msi.h index 428f7d9c..0020df4c 100644 --- a/toxav/msi.h +++ b/toxav/msi.h @@ -77,7 +77,7 @@ typedef struct _MSICall { /* Call info structure */ int ringing_timer_id; /* Timer id for ringing timeout */ - pthread_mutex_t mutex[1]; /* */ + pthread_mutex_t mutex; /* */ uint32_t *peers; uint16_t peer_count; @@ -104,7 +104,7 @@ typedef struct _MSISession { uint32_t frequ; uint32_t call_timeout; /* Time of the timeout for some action to end; 0 if infinite */ - pthread_mutex_t mutex[1]; + pthread_mutex_t mutex; void *timer_handler; } MSISession; diff --git a/toxav/toxav.c b/toxav/toxav.c index 6ffef077..36053fd5 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -68,7 +68,7 @@ typedef struct _CallSpecific { void *frame_buf; /* buffer for split video payloads */ _Bool call_active; - pthread_mutex_t mutex[1]; + pthread_mutex_t mutex; } CallSpecific; @@ -354,7 +354,7 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettin codec_settings->video_height, codec_settings->video_bitrate) )) { - if ( pthread_mutex_init(call->mutex, NULL) != 0 ) goto error; + if ( pthread_mutex_init(&call->mutex, NULL) != 0 ) goto error; call->call_active = 1; @@ -388,7 +388,7 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) CallSpecific *call = &av->calls[call_index]; - pthread_mutex_lock(call->mutex); + pthread_mutex_lock(&call->mutex); call->call_active = 0; @@ -397,8 +397,8 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) terminate_queue(call->j_buf); call->j_buf = NULL; codec_terminate_session(call->cs); call->cs = NULL; - pthread_mutex_unlock(call->mutex); - pthread_mutex_destroy(call->mutex); + pthread_mutex_unlock(&call->mutex); + pthread_mutex_destroy(&call->mutex); return ErrorNone; } @@ -534,7 +534,7 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out CallSpecific *call = &av->calls[call_index]; - pthread_mutex_lock(call->mutex); + pthread_mutex_lock(&call->mutex); uint8_t packet [RTP_PAYLOAD_SIZE]; int recved_size; @@ -587,7 +587,7 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out *output = img; - pthread_mutex_unlock(call->mutex); + pthread_mutex_unlock(&call->mutex); return ErrorNone; } @@ -608,9 +608,9 @@ inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *fr } - pthread_mutex_lock(av->calls[call_index].mutex); + pthread_mutex_lock(&av->calls[call_index].mutex); int rc = toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); - pthread_mutex_unlock(av->calls[call_index].mutex); + pthread_mutex_unlock(&av->calls[call_index].mutex); return rc; } @@ -635,7 +635,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d CallSpecific *call = &av->calls[call_index]; - pthread_mutex_lock(call->mutex); + pthread_mutex_lock(&call->mutex); reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h); @@ -643,7 +643,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d if ( rc != VPX_CODEC_OK) { LOGGER_ERROR("Could not encode video frame: %s\n", vpx_codec_err_to_string(rc)); - pthread_mutex_unlock(call->mutex); + pthread_mutex_unlock(&call->mutex); return ErrorInternal; } @@ -656,7 +656,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d while ( (pkt = vpx_codec_get_cx_data(&call->cs->v_encoder, &iter)) ) { if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { if ( copied + pkt->data.frame.sz > dest_max ) { - pthread_mutex_unlock(call->mutex); + pthread_mutex_unlock(&call->mutex); return ErrorPacketTooLarge; } @@ -665,7 +665,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d } } - pthread_mutex_unlock(call->mutex); + pthread_mutex_unlock(&call->mutex); return copied; } @@ -692,7 +692,7 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i CallSpecific *call = &av->calls[call_index]; - pthread_mutex_lock(call->mutex); + pthread_mutex_lock(&call->mutex); uint8_t packet [RTP_PAYLOAD_SIZE]; @@ -701,7 +701,7 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i if ( recved_size == ErrorAudioPacketLost ) { int dec_size = opus_decode(call->cs->audio_decoder, NULL, 0, dest, frame_size, 1); - pthread_mutex_unlock(call->mutex); + pthread_mutex_unlock(&call->mutex); if ( dec_size < 0 ) { LOGGER_WARNING("Decoding error: %s", opus_strerror(dec_size)); @@ -711,14 +711,14 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i } else if ( recved_size ) { int dec_size = opus_decode(call->cs->audio_decoder, packet, recved_size, dest, frame_size, 0); - pthread_mutex_unlock(call->mutex); + pthread_mutex_unlock(&call->mutex); if ( dec_size < 0 ) { LOGGER_WARNING("Decoding error: %s", opus_strerror(dec_size)); return ErrorInternal; } else return dec_size; } else { - pthread_mutex_unlock(call->mutex); + pthread_mutex_unlock(&call->mutex); return 0; /* Nothing received */ } } @@ -742,9 +742,9 @@ inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *fr } - pthread_mutex_lock(av->calls[call_index].mutex); + pthread_mutex_lock(&av->calls[call_index].mutex); int rc = toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); - pthread_mutex_unlock(av->calls[call_index].mutex); + pthread_mutex_unlock(&av->calls[call_index].mutex); return rc; } @@ -770,11 +770,11 @@ inline__ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t } - pthread_mutex_lock(av->calls[call_index].mutex); + pthread_mutex_lock(&av->calls[call_index].mutex); int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max); - pthread_mutex_unlock(av->calls[call_index].mutex); + pthread_mutex_unlock(&av->calls[call_index].mutex); if (rc < 0) { LOGGER_ERROR("Failed to encode payload: %s\n", opus_strerror(rc));