diff options
author | mannol <eniz_vukovic@hotmail.com> | 2015-03-01 18:45:04 +0100 |
---|---|---|
committer | mannol <eniz_vukovic@hotmail.com> | 2015-03-01 18:45:04 +0100 |
commit | 45e8807c1e693c105b97784d15b7eb19bcc87918 (patch) | |
tree | c75497dcacf65552c3fc3cbb0cacf759b7fe5c67 /toxav/codec.c | |
parent | 9e65cd533735f1acc638241ed58400bf7029b1ef (diff) |
Make toxav thread safe
Diffstat (limited to 'toxav/codec.c')
-rw-r--r-- | toxav/codec.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/toxav/codec.c b/toxav/codec.c index e44387df..645f7188 100644 --- a/toxav/codec.c +++ b/toxav/codec.c | |||
@@ -343,21 +343,17 @@ CSSession *cs_new(uint32_t peer_video_frame_piece_size) | |||
343 | return NULL; | 343 | return NULL; |
344 | } | 344 | } |
345 | 345 | ||
346 | cs->peer_video_frame_piece_size = peer_video_frame_piece_size; | ||
347 | |||
348 | return cs; | ||
349 | 346 | ||
350 | FAILURE: | 347 | if (create_recursive_mutex(cs->queue_mutex) != 0) { |
351 | LOGGER_WARNING("Error initializing codec session! Application might misbehave!"); | 348 | LOGGER_WARNING("Failed to create recursive mutex!"); |
349 | free(cs); | ||
350 | return NULL; | ||
351 | } | ||
352 | 352 | ||
353 | cs_disable_audio_sending(cs); | ||
354 | cs_disable_audio_receiving(cs); | ||
355 | cs_disable_video_sending(cs); | ||
356 | cs_disable_video_receiving(cs); | ||
357 | 353 | ||
358 | free(cs); | 354 | cs->peer_video_frame_piece_size = peer_video_frame_piece_size; |
359 | 355 | ||
360 | return NULL; | 356 | return cs; |
361 | } | 357 | } |
362 | 358 | ||
363 | void cs_kill(CSSession *cs) | 359 | void cs_kill(CSSession *cs) |
@@ -374,6 +370,8 @@ void cs_kill(CSSession *cs) | |||
374 | cs_disable_video_sending(cs); | 370 | cs_disable_video_sending(cs); |
375 | cs_disable_video_receiving(cs); | 371 | cs_disable_video_receiving(cs); |
376 | 372 | ||
373 | pthread_mutex_destroy(cs->queue_mutex); | ||
374 | |||
377 | LOGGER_DEBUG("Terminated codec state: %p", cs); | 375 | LOGGER_DEBUG("Terminated codec state: %p", cs); |
378 | free(cs); | 376 | free(cs); |
379 | } | 377 | } |
@@ -536,19 +534,12 @@ int cs_enable_video_receiving(CSSession* cs) | |||
536 | { | 534 | { |
537 | if (cs->v_decoding) | 535 | if (cs->v_decoding) |
538 | return 0; | 536 | return 0; |
539 | 537 | ||
540 | if (create_recursive_mutex(cs->queue_mutex) != 0) { | ||
541 | LOGGER_WARNING("Failed to create recursive mutex!"); | ||
542 | return -1; | ||
543 | } | ||
544 | |||
545 | int rc = vpx_codec_dec_init_ver(cs->v_decoder, VIDEO_CODEC_DECODER_INTERFACE, | 538 | int rc = vpx_codec_dec_init_ver(cs->v_decoder, VIDEO_CODEC_DECODER_INTERFACE, |
546 | NULL, 0, VPX_DECODER_ABI_VERSION); | 539 | NULL, 0, VPX_DECODER_ABI_VERSION); |
547 | 540 | ||
548 | if ( rc != VPX_CODEC_OK) { | 541 | if ( rc != VPX_CODEC_OK) { |
549 | LOGGER_ERROR("Init video_decoder failed: %s", vpx_codec_err_to_string(rc)); | 542 | LOGGER_ERROR("Init video_decoder failed: %s", vpx_codec_err_to_string(rc)); |
550 | |||
551 | pthread_mutex_destroy(cs->queue_mutex); | ||
552 | return -1; | 543 | return -1; |
553 | } | 544 | } |
554 | 545 | ||
@@ -591,7 +582,6 @@ void cs_disable_video_receiving(CSSession* cs) | |||
591 | cs->frame_buf = NULL; | 582 | cs->frame_buf = NULL; |
592 | 583 | ||
593 | vpx_codec_destroy(cs->v_decoder); | 584 | vpx_codec_destroy(cs->v_decoder); |
594 | pthread_mutex_destroy(cs->queue_mutex); | ||
595 | } | 585 | } |
596 | } | 586 | } |
597 | 587 | ||