mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed audio bug and added reason when terminating call
This commit is contained in:
parent
0a91084011
commit
faaaa05206
|
@ -354,7 +354,7 @@ void *encode_video_thread(void *arg)
|
|||
cs->webcam_decoder_ctx->pix_fmt, cs->webcam_decoder_ctx->width, cs->webcam_decoder_ctx->height, PIX_FMT_YUV420P,
|
||||
SWS_BILINEAR, NULL, NULL, NULL);
|
||||
|
||||
while (!cs->quit && cs->send_video) {
|
||||
while (cs->send_video) {
|
||||
|
||||
if (av_read_frame(cs->video_format_ctx, packet) < 0) {
|
||||
printf("error reading frame\n");
|
||||
|
@ -412,14 +412,14 @@ void *encode_video_thread(void *arg)
|
|||
}
|
||||
|
||||
/* clean up codecs */
|
||||
pthread_mutex_lock(&cs->avcodec_mutex_lock);
|
||||
pthread_mutex_lock(&cs->ctrl_mutex);
|
||||
av_free(buffer);
|
||||
av_free(webcam_frame);
|
||||
av_free(s_video_frame);
|
||||
sws_freeContext(_phone->sws_ctx);
|
||||
avcodec_close(cs->webcam_decoder_ctx);
|
||||
avcodec_close(cs->video_encoder_ctx);
|
||||
pthread_mutex_unlock(&cs->avcodec_mutex_lock);
|
||||
pthread_mutex_unlock(&cs->ctrl_mutex);
|
||||
pthread_exit ( NULL );
|
||||
}
|
||||
|
||||
|
@ -436,7 +436,7 @@ void *encode_audio_thread(void *arg)
|
|||
ALint sample = 0;
|
||||
alcCaptureStart((ALCdevice*)_phone->audio_capture_device);
|
||||
|
||||
while (!cs->quit && cs->send_audio) {
|
||||
while (cs->send_audio) {
|
||||
alcGetIntegerv((ALCdevice*)_phone->audio_capture_device, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &sample);
|
||||
|
||||
if (sample >= frame_size) {
|
||||
|
@ -454,11 +454,10 @@ void *encode_audio_thread(void *arg)
|
|||
}
|
||||
|
||||
/* clean up codecs */
|
||||
pthread_mutex_lock(&cs->avcodec_mutex_lock);
|
||||
pthread_mutex_lock(&cs->ctrl_mutex);
|
||||
alcCaptureStop((ALCdevice*)_phone->audio_capture_device);
|
||||
alcCaptureCloseDevice((ALCdevice*)_phone->audio_capture_device);
|
||||
|
||||
pthread_mutex_unlock(&cs->avcodec_mutex_lock);
|
||||
pthread_mutex_unlock(&cs->ctrl_mutex);
|
||||
pthread_exit ( NULL );
|
||||
}
|
||||
|
||||
|
@ -478,7 +477,7 @@ void *decode_video_thread(void *arg)
|
|||
int width = 0;
|
||||
int height = 0;
|
||||
|
||||
while (!cs->quit && cs->receive_video) {
|
||||
while (cs->receive_video) {
|
||||
r_msg = rtp_recv_msg ( _phone->_rtp_video );
|
||||
|
||||
if (r_msg) {
|
||||
|
@ -508,10 +507,10 @@ void *decode_video_thread(void *arg)
|
|||
|
||||
printf("vend\n");
|
||||
/* clean up codecs */
|
||||
pthread_mutex_lock(&cs->avcodec_mutex_lock);
|
||||
pthread_mutex_lock(&cs->ctrl_mutex);
|
||||
av_free(r_video_frame);
|
||||
avcodec_close(cs->video_decoder_ctx);
|
||||
pthread_mutex_unlock(&cs->avcodec_mutex_lock);
|
||||
pthread_mutex_unlock(&cs->ctrl_mutex);
|
||||
pthread_exit ( NULL );
|
||||
}
|
||||
|
||||
|
@ -544,6 +543,7 @@ void *decode_audio_thread(void *arg)
|
|||
|
||||
uint16_t zeros[frame_size];
|
||||
memset(zeros, 0, frame_size);
|
||||
opus_int16 PCM[frame_size];
|
||||
|
||||
int i;
|
||||
for (i = 0; i < openal_buffers; ++i) {
|
||||
|
@ -555,7 +555,7 @@ void *decode_audio_thread(void *arg)
|
|||
|
||||
if (alGetError() != AL_NO_ERROR) {
|
||||
fprintf(stderr, "Error starting audio\n");
|
||||
cs->quit = 1;
|
||||
goto ending;
|
||||
}
|
||||
|
||||
struct jitter_buffer *j_buf = NULL;
|
||||
|
@ -566,9 +566,8 @@ void *decode_audio_thread(void *arg)
|
|||
|
||||
int dec_frame_len = 0;
|
||||
|
||||
opus_int16 PCM[frame_size];
|
||||
|
||||
while (!cs->quit && cs->receive_audio) {
|
||||
while (cs->receive_audio) {
|
||||
|
||||
r_msg = rtp_recv_msg ( _phone->_rtp_audio );
|
||||
|
||||
|
@ -633,16 +632,18 @@ void *decode_audio_thread(void *arg)
|
|||
usleep(1000);
|
||||
}
|
||||
|
||||
/* clean up codecs */
|
||||
pthread_mutex_lock(&cs->avcodec_mutex_lock);
|
||||
|
||||
/* clean up openal */
|
||||
ending:
|
||||
/* clean up codecs */
|
||||
pthread_mutex_lock(&cs->ctrl_mutex);
|
||||
|
||||
alDeleteSources(1, &source);
|
||||
alDeleteBuffers(openal_buffers, buffers);
|
||||
alcMakeContextCurrent(NULL);
|
||||
alcDestroyContext(ctx);
|
||||
alcCloseDevice(dev);
|
||||
pthread_mutex_unlock(&cs->avcodec_mutex_lock);
|
||||
|
||||
pthread_mutex_unlock(&cs->ctrl_mutex);
|
||||
pthread_exit ( NULL );
|
||||
}
|
||||
|
||||
|
@ -676,8 +677,6 @@ int phone_startmedia_loop ( av_session_t* _phone )
|
|||
_phone->_msi->call->nonce_local
|
||||
);
|
||||
|
||||
_phone->cs->quit = 0;
|
||||
|
||||
init_encoder(_phone->cs);
|
||||
init_decoder(_phone->cs);
|
||||
|
||||
|
@ -699,6 +698,7 @@ int phone_startmedia_loop ( av_session_t* _phone )
|
|||
return -1;
|
||||
}
|
||||
|
||||
/* Only checks for last peer */
|
||||
if ( _phone->_msi->call->type_peer[0] == type_video && 0 > event.rise(decode_video_thread, _phone) )
|
||||
{
|
||||
INFO("Error while starting decode_video_thread()");
|
||||
|
@ -913,18 +913,18 @@ av_session_t* av_init_session()
|
|||
_retu->_msi->agent_handler = _retu;
|
||||
|
||||
/* ------------------ */
|
||||
msi_register_callback(callback_call_started, cb_onstart);
|
||||
msi_register_callback(callback_call_canceled, cb_oncancel);
|
||||
msi_register_callback(callback_call_rejected, cb_onreject);
|
||||
msi_register_callback(callback_call_ended, cb_onend);
|
||||
msi_register_callback(callback_recv_invite, cb_oninvite);
|
||||
msi_register_callback(callback_call_started, MSI_OnStart);
|
||||
msi_register_callback(callback_call_canceled, MSI_OnCancel);
|
||||
msi_register_callback(callback_call_rejected, MSI_OnReject);
|
||||
msi_register_callback(callback_call_ended, MSI_OnEnd);
|
||||
msi_register_callback(callback_recv_invite, MSI_OnInvite);
|
||||
|
||||
msi_register_callback(callback_recv_ringing, cb_ringing);
|
||||
msi_register_callback(callback_recv_starting, cb_starting);
|
||||
msi_register_callback(callback_recv_ending, cb_ending);
|
||||
msi_register_callback(callback_recv_ringing, MSI_OnRinging);
|
||||
msi_register_callback(callback_recv_starting, MSI_OnStarting);
|
||||
msi_register_callback(callback_recv_ending, MSI_OnEnding);
|
||||
|
||||
msi_register_callback(callback_recv_error, cb_error);
|
||||
msi_register_callback(callback_requ_timeout, cb_timeout);
|
||||
msi_register_callback(callback_recv_error, MSI_OnError);
|
||||
msi_register_callback(callback_requ_timeout, MSI_OnTimeout);
|
||||
/* ------------------ */
|
||||
|
||||
return _retu;
|
||||
|
@ -1114,7 +1114,7 @@ void do_phone ( av_session_t* _phone )
|
|||
break;
|
||||
}
|
||||
|
||||
msi_reject(_phone->_msi);
|
||||
msi_reject(_phone->_msi, NULL);
|
||||
|
||||
INFO("Call Rejected...");
|
||||
|
||||
|
|
|
@ -345,8 +345,6 @@ int init_send_audio(codec_state *cs)
|
|||
err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10));
|
||||
err = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE));
|
||||
|
||||
opus_encoder_init(cs->audio_encoder, AUDIO_SAMPLE_RATE, 1, OPUS_APPLICATION_VOIP);
|
||||
|
||||
int nfo;
|
||||
err = opus_encoder_ctl(cs->audio_encoder, OPUS_GET_LOOKAHEAD(&nfo));
|
||||
/* printf("Encoder lookahead delay : %d\n", nfo); */
|
||||
|
@ -362,8 +360,7 @@ int init_encoder(codec_state *cs)
|
|||
avdevice_register_all();
|
||||
av_register_all();
|
||||
|
||||
pthread_mutex_init(&cs->rtp_msg_mutex_lock, NULL);
|
||||
pthread_mutex_init(&cs->avcodec_mutex_lock, NULL);
|
||||
pthread_mutex_init(&cs->ctrl_mutex, NULL);
|
||||
|
||||
cs->support_send_video = init_send_video(cs);
|
||||
cs->support_send_audio = init_send_audio(cs);
|
||||
|
|
|
@ -108,10 +108,8 @@ typedef struct {
|
|||
|
||||
uint8_t req_video_refresh;
|
||||
|
||||
pthread_mutex_t rtp_msg_mutex_lock;
|
||||
pthread_mutex_t avcodec_mutex_lock;
|
||||
pthread_mutex_t ctrl_mutex;
|
||||
|
||||
uint8_t quit;
|
||||
|
||||
uint32_t frame_rate;
|
||||
|
||||
|
|
|
@ -633,7 +633,7 @@ int handle_error ( MSISession* session, MSICallError errid, uint32_t to ) {
|
|||
session->last_error_id = errid;
|
||||
session->last_error_str = stringify_error ( errid );
|
||||
|
||||
event.rise ( callbacks[cb_error], session );
|
||||
event.rise ( callbacks[MSI_OnError], session );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -688,8 +688,8 @@ void* handle_timeout ( void* arg )
|
|||
|
||||
}
|
||||
|
||||
( *callbacks[cb_timeout] ) ( arg );
|
||||
( *callbacks[cb_ending ] ) ( arg );
|
||||
( *callbacks[MSI_OnTimeout] ) ( arg );
|
||||
( *callbacks[MSI_OnEnding ] ) ( arg );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -821,7 +821,7 @@ int handle_recv_invite ( MSISession* session, MSIMessage* msg ) {
|
|||
send_message ( session, _msg_ringing, msg->friend_id );
|
||||
free_message ( _msg_ringing );
|
||||
|
||||
event.rise ( callbacks[cb_oninvite], session );
|
||||
event.rise ( callbacks[MSI_OnInvite], session );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -844,7 +844,7 @@ int handle_recv_start ( MSISession* session, MSIMessage* msg ) {
|
|||
|
||||
flush_peer_type ( session, msg, 0 );
|
||||
|
||||
event.rise ( callbacks[cb_onstart], session );
|
||||
event.rise ( callbacks[MSI_OnStart], session );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -860,7 +860,7 @@ int handle_recv_reject ( MSISession* session, MSIMessage* msg ) {
|
|||
free_message ( _msg_end );
|
||||
|
||||
event.timer_release ( session->call->request_timer_id );
|
||||
event.rise ( callbacks[cb_onreject], session );
|
||||
event.rise ( callbacks[MSI_OnReject], session );
|
||||
session->call->request_timer_id = event.timer_alloc ( handle_timeout, session, m_deftout );
|
||||
|
||||
return 1;
|
||||
|
@ -874,7 +874,7 @@ int handle_recv_cancel ( MSISession* session, MSIMessage* msg ) {
|
|||
|
||||
terminate_call ( session );
|
||||
|
||||
event.rise ( callbacks[cb_oncancel], session );
|
||||
event.rise ( callbacks[MSI_OnCancel], session );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -891,7 +891,7 @@ int handle_recv_end ( MSISession* session, MSIMessage* msg ) {
|
|||
|
||||
terminate_call ( session );
|
||||
|
||||
event.rise ( callbacks[cb_onend], session );
|
||||
event.rise ( callbacks[MSI_OnEnd], session );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -904,7 +904,7 @@ int handle_recv_ringing ( MSISession* session, MSIMessage* msg ) {
|
|||
return 0;
|
||||
|
||||
session->call->ringing_timer_id = event.timer_alloc ( handle_timeout, session, session->call->ringing_tout_ms );
|
||||
event.rise ( callbacks[cb_ringing], session );
|
||||
event.rise ( callbacks[MSI_OnRinging], session );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -942,7 +942,7 @@ int handle_recv_starting ( MSISession* session, MSIMessage* msg ) {
|
|||
|
||||
flush_peer_type ( session, msg, 0 );
|
||||
|
||||
event.rise ( callbacks[cb_starting], session );
|
||||
event.rise ( callbacks[MSI_OnStarting], session );
|
||||
event.timer_release ( session->call->ringing_timer_id );
|
||||
|
||||
return 1;
|
||||
|
@ -956,7 +956,7 @@ int handle_recv_ending ( MSISession* session, MSIMessage* msg ) {
|
|||
|
||||
terminate_call ( session );
|
||||
|
||||
event.rise ( callbacks[cb_ending], session );
|
||||
event.rise ( callbacks[MSI_OnEnding], session );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -972,7 +972,7 @@ int handle_recv_error ( MSISession* session, MSIMessage* msg ) {
|
|||
|
||||
terminate_call ( session );
|
||||
|
||||
event.rise ( callbacks[cb_ending], session );
|
||||
event.rise ( callbacks[MSI_OnEnding], session );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1165,6 +1165,8 @@ int msi_terminate_session ( MSISession* session ) {
|
|||
int _status = 0;
|
||||
|
||||
terminate_call ( session );
|
||||
m_callback_msi_packet((struct Messenger*) session->messenger_handle, NULL, NULL);
|
||||
|
||||
|
||||
/* TODO: Clean it up more? */
|
||||
|
||||
|
@ -1311,10 +1313,13 @@ int msi_cancel ( MSISession* session, int friend_id ) {
|
|||
* @param session Control session.
|
||||
* @return int
|
||||
*/
|
||||
int msi_reject ( MSISession* session ) {
|
||||
int msi_reject ( MSISession* session, const uint8_t* reason ) {
|
||||
assert ( session );
|
||||
|
||||
MSIMessage* _msg_reject = msi_new_message ( TYPE_REQUEST, stringify_request ( reject ) );
|
||||
|
||||
if ( reason ) msi_msg_set_reason(_msg_reject, reason, strlen((const char*)reason) + 1);
|
||||
|
||||
send_message ( session, _msg_reject, session->call->peers[session->call->peer_count - 1] );
|
||||
free_message ( _msg_reject );
|
||||
|
||||
|
|
|
@ -120,20 +120,20 @@ typedef struct _MSISession {
|
|||
*/
|
||||
typedef enum {
|
||||
/* Requests */
|
||||
cb_oninvite,
|
||||
cb_onstart,
|
||||
cb_oncancel,
|
||||
cb_onreject,
|
||||
cb_onend,
|
||||
MSI_OnInvite,
|
||||
MSI_OnStart,
|
||||
MSI_OnCancel,
|
||||
MSI_OnReject,
|
||||
MSI_OnEnd,
|
||||
|
||||
/* Responses */
|
||||
cb_ringing,
|
||||
cb_starting,
|
||||
cb_ending,
|
||||
MSI_OnRinging,
|
||||
MSI_OnStarting,
|
||||
MSI_OnEnding,
|
||||
|
||||
/* Protocol */
|
||||
cb_error,
|
||||
cb_timeout
|
||||
MSI_OnError,
|
||||
MSI_OnTimeout
|
||||
|
||||
} MSICallbackID;
|
||||
|
||||
|
@ -215,9 +215,10 @@ int msi_cancel ( MSISession* session, int friend_id );
|
|||
* @brief Reject request.
|
||||
*
|
||||
* @param session Control session.
|
||||
* @param reason Set optional reason header. Pass NULL if none.
|
||||
* @return int
|
||||
*/
|
||||
int msi_reject ( MSISession* session );
|
||||
int msi_reject ( MSISession* session, const uint8_t* reason );
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user