diff options
Diffstat (limited to 'toxav/codec.c')
-rw-r--r-- | toxav/codec.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/toxav/codec.c b/toxav/codec.c index 020cde81..776ca940 100644 --- a/toxav/codec.c +++ b/toxav/codec.c | |||
@@ -362,21 +362,22 @@ void cs_do(CSSession *cs) | |||
362 | { | 362 | { |
363 | /* Codec session should always be protected by call mutex so no need to check for cs validity | 363 | /* Codec session should always be protected by call mutex so no need to check for cs validity |
364 | */ | 364 | */ |
365 | 365 | ||
366 | if (!cs) return; | 366 | if (!cs) return; |
367 | 367 | ||
368 | Payload *p; | 368 | Payload *p; |
369 | int rc; | 369 | int rc; |
370 | 370 | ||
371 | pthread_mutex_lock(cs->queue_mutex); | 371 | pthread_mutex_lock(cs->queue_mutex); |
372 | |||
372 | if (cs->abuf_raw && !buffer_empty(cs->abuf_raw)) { | 373 | if (cs->abuf_raw && !buffer_empty(cs->abuf_raw)) { |
373 | /* Decode audio */ | 374 | /* Decode audio */ |
374 | buffer_read(cs->abuf_raw, &p); | 375 | buffer_read(cs->abuf_raw, &p); |
375 | 376 | ||
376 | /* Leave space for (possibly) other thread to queue more data after we read it here */ | 377 | /* Leave space for (possibly) other thread to queue more data after we read it here */ |
377 | pthread_mutex_unlock(cs->queue_mutex); | 378 | pthread_mutex_unlock(cs->queue_mutex); |
378 | 379 | ||
379 | 380 | ||
380 | uint16_t fsize = (cs->audio_decoder_channels * | 381 | uint16_t fsize = (cs->audio_decoder_channels * |
381 | (cs->audio_decoder_sample_rate * cs->audio_decoder_frame_duration) / 1000); | 382 | (cs->audio_decoder_sample_rate * cs->audio_decoder_frame_duration) / 1000); |
382 | int16_t tmp[fsize]; | 383 | int16_t tmp[fsize]; |
@@ -389,17 +390,17 @@ void cs_do(CSSession *cs) | |||
389 | else if (cs->acb.first) | 390 | else if (cs->acb.first) |
390 | /* Play */ | 391 | /* Play */ |
391 | cs->acb.first(cs->agent, cs->call_idx, tmp, rc, cs->acb.second); | 392 | cs->acb.first(cs->agent, cs->call_idx, tmp, rc, cs->acb.second); |
392 | 393 | ||
393 | pthread_mutex_lock(cs->queue_mutex); | 394 | pthread_mutex_lock(cs->queue_mutex); |
394 | } | 395 | } |
395 | 396 | ||
396 | if (cs->vbuf_raw && !buffer_empty(cs->vbuf_raw)) { | 397 | if (cs->vbuf_raw && !buffer_empty(cs->vbuf_raw)) { |
397 | /* Decode video */ | 398 | /* Decode video */ |
398 | buffer_read(cs->vbuf_raw, &p); | 399 | buffer_read(cs->vbuf_raw, &p); |
399 | 400 | ||
400 | /* Leave space for (possibly) other thread to queue more data after we read it here */ | 401 | /* Leave space for (possibly) other thread to queue more data after we read it here */ |
401 | pthread_mutex_unlock(cs->queue_mutex); | 402 | pthread_mutex_unlock(cs->queue_mutex); |
402 | 403 | ||
403 | rc = vpx_codec_decode(&cs->v_decoder, p->data, p->size, NULL, MAX_DECODE_TIME_US); | 404 | rc = vpx_codec_decode(&cs->v_decoder, p->data, p->size, NULL, MAX_DECODE_TIME_US); |
404 | free(p); | 405 | free(p); |
405 | 406 | ||
@@ -413,9 +414,11 @@ void cs_do(CSSession *cs) | |||
413 | for (; dest; dest = vpx_codec_get_frame(&cs->v_decoder, &iter)) { | 414 | for (; dest; dest = vpx_codec_get_frame(&cs->v_decoder, &iter)) { |
414 | if (cs->vcb.first) | 415 | if (cs->vcb.first) |
415 | cs->vcb.first(cs->agent, cs->call_idx, dest, cs->vcb.second); | 416 | cs->vcb.first(cs->agent, cs->call_idx, dest, cs->vcb.second); |
417 | |||
416 | vpx_img_free(dest); | 418 | vpx_img_free(dest); |
417 | } | 419 | } |
418 | } | 420 | } |
421 | |||
419 | return; | 422 | return; |
420 | } | 423 | } |
421 | 424 | ||
@@ -477,7 +480,7 @@ CSSession *cs_new(const ToxAvCSettings *cs_self, const ToxAvCSettings *cs_peer, | |||
477 | LOGGER_WARNING("Failed to create recursive mutex!"); | 480 | LOGGER_WARNING("Failed to create recursive mutex!"); |
478 | return NULL; | 481 | return NULL; |
479 | } | 482 | } |
480 | 483 | ||
481 | if ( !(cs->j_buf = jbuf_new(jbuf_size)) ) { | 484 | if ( !(cs->j_buf = jbuf_new(jbuf_size)) ) { |
482 | LOGGER_WARNING("Jitter buffer creaton failed!"); | 485 | LOGGER_WARNING("Jitter buffer creaton failed!"); |
483 | goto error; | 486 | goto error; |
@@ -518,14 +521,14 @@ CSSession *cs_new(const ToxAvCSettings *cs_self, const ToxAvCSettings *cs_peer, | |||
518 | 521 | ||
519 | if ( !(cs->vbuf_raw = buffer_new(VIDEO_DECODE_BUFFER_SIZE)) ) goto error; | 522 | if ( !(cs->vbuf_raw = buffer_new(VIDEO_DECODE_BUFFER_SIZE)) ) goto error; |
520 | } | 523 | } |
521 | 524 | ||
522 | return cs; | 525 | return cs; |
523 | 526 | ||
524 | error: | 527 | error: |
525 | LOGGER_WARNING("Error initializing codec session! Application might misbehave!"); | 528 | LOGGER_WARNING("Error initializing codec session! Application might misbehave!"); |
526 | 529 | ||
527 | pthread_mutex_destroy(cs->queue_mutex); | 530 | pthread_mutex_destroy(cs->queue_mutex); |
528 | 531 | ||
529 | buffer_free(cs->abuf_raw); | 532 | buffer_free(cs->abuf_raw); |
530 | 533 | ||
531 | if ( cs->audio_encoder ) opus_encoder_destroy(cs->audio_encoder); | 534 | if ( cs->audio_encoder ) opus_encoder_destroy(cs->audio_encoder); |