diff options
Diffstat (limited to 'toxav/codec.c')
-rw-r--r-- | toxav/codec.c | 57 |
1 files changed, 16 insertions, 41 deletions
diff --git a/toxav/codec.c b/toxav/codec.c index 9fc14071..e44387df 100644 --- a/toxav/codec.c +++ b/toxav/codec.c | |||
@@ -44,9 +44,7 @@ | |||
44 | #define MAX_ENCODE_TIME_US VPX_DL_GOOD_QUALITY | 44 | #define MAX_ENCODE_TIME_US VPX_DL_GOOD_QUALITY |
45 | #define MAX_DECODE_TIME_US 0 | 45 | #define MAX_DECODE_TIME_US 0 |
46 | 46 | ||
47 | // TODO this has to be exchanged in msi | ||
48 | #define MAX_VIDEOFRAME_SIZE 0x40000 /* 256KiB */ | 47 | #define MAX_VIDEOFRAME_SIZE 0x40000 /* 256KiB */ |
49 | #define VIDEOFRAME_PIECE_SIZE 0x500 /* 1.25 KiB*/ | ||
50 | #define VIDEOFRAME_HEADER_SIZE 0x2 | 48 | #define VIDEOFRAME_HEADER_SIZE 0x2 |
51 | 49 | ||
52 | /* FIXME: Might not be enough */ | 50 | /* FIXME: Might not be enough */ |
@@ -296,7 +294,7 @@ void cs_do(CSSession *cs) | |||
296 | LOGGER_WARNING("Decoding error: %s", opus_strerror(rc)); | 294 | LOGGER_WARNING("Decoding error: %s", opus_strerror(rc)); |
297 | } else if (cs->acb.first) { | 295 | } else if (cs->acb.first) { |
298 | /* Play */ | 296 | /* Play */ |
299 | cs->acb.first(cs->agent, cs->friend_number, tmp, rc, | 297 | cs->acb.first(cs->agent, cs->friend_id, tmp, rc, |
300 | cs->last_pack_channels, cs->last_packet_sampling_rate, cs->acb.second); | 298 | cs->last_pack_channels, cs->last_packet_sampling_rate, cs->acb.second); |
301 | } | 299 | } |
302 | 300 | ||
@@ -323,7 +321,7 @@ void cs_do(CSSession *cs) | |||
323 | /* Play decoded images */ | 321 | /* Play decoded images */ |
324 | for (; dest; dest = vpx_codec_get_frame(cs->v_decoder, &iter)) { | 322 | for (; dest; dest = vpx_codec_get_frame(cs->v_decoder, &iter)) { |
325 | if (cs->vcb.first) | 323 | if (cs->vcb.first) |
326 | cs->vcb.first(cs->agent, cs->call_idx, dest->d_w, dest->d_h, | 324 | cs->vcb.first(cs->agent, cs->friend_id, dest->d_w, dest->d_h, |
327 | (const uint8_t**)dest->planes, dest->stride, cs->vcb.second); | 325 | (const uint8_t**)dest->planes, dest->stride, cs->vcb.second); |
328 | 326 | ||
329 | vpx_img_free(dest); | 327 | vpx_img_free(dest); |
@@ -336,7 +334,7 @@ void cs_do(CSSession *cs) | |||
336 | pthread_mutex_unlock(cs->queue_mutex); | 334 | pthread_mutex_unlock(cs->queue_mutex); |
337 | } | 335 | } |
338 | 336 | ||
339 | CSSession *cs_new(uint32_t s_audio_b, uint32_t p_audio_b, uint32_t s_video_b, uint32_t p_video_b) | 337 | CSSession *cs_new(uint32_t peer_video_frame_piece_size) |
340 | { | 338 | { |
341 | CSSession *cs = calloc(sizeof(CSSession), 1); | 339 | CSSession *cs = calloc(sizeof(CSSession), 1); |
342 | 340 | ||
@@ -345,29 +343,7 @@ CSSession *cs_new(uint32_t s_audio_b, uint32_t p_audio_b, uint32_t s_video_b, ui | |||
345 | return NULL; | 343 | return NULL; |
346 | } | 344 | } |
347 | 345 | ||
348 | /* TODO this has to be exchanged in msi */ | 346 | cs->peer_video_frame_piece_size = peer_video_frame_piece_size; |
349 | cs->max_video_frame_size = MAX_VIDEOFRAME_SIZE; | ||
350 | cs->video_frame_piece_size = VIDEOFRAME_PIECE_SIZE; | ||
351 | |||
352 | if (s_audio_b > 0 && 0 != cs_enable_audio_sending(cs, s_audio_b, 2)) { /* Sending audio enabled */ | ||
353 | LOGGER_WARNING("Failed to enable audio sending!"); | ||
354 | goto FAILURE; | ||
355 | } | ||
356 | |||
357 | if (p_audio_b > 0 && 0 != cs_enable_audio_receiving(cs)) { /* Receiving audio enabled */ | ||
358 | LOGGER_WARNING("Failed to enable audio receiving!"); | ||
359 | goto FAILURE; | ||
360 | } | ||
361 | |||
362 | if (s_video_b > 0 && 0 != cs_enable_video_sending(cs, s_video_b)) { /* Sending video enabled */ | ||
363 | LOGGER_WARNING("Failed to enable video sending!"); | ||
364 | goto FAILURE; | ||
365 | } | ||
366 | |||
367 | if (p_video_b > 0 && 0 != cs_enable_video_receiving(cs)) { /* Receiving video enabled */ | ||
368 | LOGGER_WARNING("Failed to enable video receiving!"); | ||
369 | goto FAILURE; | ||
370 | } | ||
371 | 347 | ||
372 | return cs; | 348 | return cs; |
373 | 349 | ||
@@ -415,22 +391,22 @@ int cs_update_video_splitter_cycle(CSSession *cs, const uint8_t *payload, uint16 | |||
415 | cs->processing_video_frame = payload; | 391 | cs->processing_video_frame = payload; |
416 | cs->processing_video_frame_size = length; | 392 | cs->processing_video_frame_size = length; |
417 | 393 | ||
418 | return ((length - 1) / cs->video_frame_piece_size) + 1; | 394 | return ((length - 1) / VIDEOFRAME_PIECE_SIZE) + 1; |
419 | } | 395 | } |
420 | 396 | ||
421 | const uint8_t *cs_iterate_split_video_frame(CSSession *cs, uint16_t *size) | 397 | const uint8_t *cs_iterate_split_video_frame(CSSession *cs, uint16_t *size) |
422 | { | 398 | { |
423 | if (!cs || !size) return NULL; | 399 | if (!cs || !size) return NULL; |
424 | 400 | ||
425 | if (cs->processing_video_frame_size > cs->video_frame_piece_size) { | 401 | if (cs->processing_video_frame_size > VIDEOFRAME_PIECE_SIZE) { |
426 | memcpy(cs->split_video_frame + VIDEOFRAME_HEADER_SIZE, | 402 | memcpy(cs->split_video_frame + VIDEOFRAME_HEADER_SIZE, |
427 | cs->processing_video_frame, | 403 | cs->processing_video_frame, |
428 | cs->video_frame_piece_size); | 404 | VIDEOFRAME_PIECE_SIZE); |
429 | 405 | ||
430 | cs->processing_video_frame += cs->video_frame_piece_size; | 406 | cs->processing_video_frame += VIDEOFRAME_PIECE_SIZE; |
431 | cs->processing_video_frame_size -= cs->video_frame_piece_size; | 407 | cs->processing_video_frame_size -= VIDEOFRAME_PIECE_SIZE; |
432 | 408 | ||
433 | *size = cs->video_frame_piece_size + VIDEOFRAME_HEADER_SIZE; | 409 | *size = VIDEOFRAME_PIECE_SIZE + VIDEOFRAME_HEADER_SIZE; |
434 | } else { | 410 | } else { |
435 | memcpy(cs->split_video_frame + VIDEOFRAME_HEADER_SIZE, | 411 | memcpy(cs->split_video_frame + VIDEOFRAME_HEADER_SIZE, |
436 | cs->processing_video_frame, | 412 | cs->processing_video_frame, |
@@ -492,7 +468,7 @@ int cs_set_sending_video_bitrate(CSSession *cs, uint32_t bitrate) | |||
492 | if (cfg.rc_target_bitrate == bitrate) | 468 | if (cfg.rc_target_bitrate == bitrate) |
493 | return 0; | 469 | return 0; |
494 | 470 | ||
495 | LOGGER_DEBUG("New video bitrate: %u", video_bitrate); | 471 | LOGGER_DEBUG("New video bitrate: %u", bitrate); |
496 | cfg.rc_target_bitrate = bitrate; | 472 | cfg.rc_target_bitrate = bitrate; |
497 | 473 | ||
498 | int rc = vpx_codec_enc_config_set(cs->v_encoder, &cfg); | 474 | int rc = vpx_codec_enc_config_set(cs->v_encoder, &cfg); |
@@ -528,7 +504,7 @@ int cs_enable_video_sending(CSSession* cs, uint32_t bitrate) | |||
528 | /* So that we can use cs_disable_video_sending to clean up */ | 504 | /* So that we can use cs_disable_video_sending to clean up */ |
529 | cs->v_encoding = true; | 505 | cs->v_encoding = true; |
530 | 506 | ||
531 | if ( !(cs->split_video_frame = calloc(cs->video_frame_piece_size + VIDEOFRAME_HEADER_SIZE, 1)) ) | 507 | if ( !(cs->split_video_frame = calloc(VIDEOFRAME_PIECE_SIZE + VIDEOFRAME_HEADER_SIZE, 1)) ) |
532 | goto FAILURE; | 508 | goto FAILURE; |
533 | 509 | ||
534 | cfg.rc_target_bitrate = bitrate; | 510 | cfg.rc_target_bitrate = bitrate; |
@@ -579,7 +555,7 @@ int cs_enable_video_receiving(CSSession* cs) | |||
579 | /* So that we can use cs_disable_video_sending to clean up */ | 555 | /* So that we can use cs_disable_video_sending to clean up */ |
580 | cs->v_decoding = true; | 556 | cs->v_decoding = true; |
581 | 557 | ||
582 | if ( !(cs->frame_buf = calloc(cs->max_video_frame_size, 1)) ) | 558 | if ( !(cs->frame_buf = calloc(MAX_VIDEOFRAME_SIZE, 1)) ) |
583 | goto FAILURE; | 559 | goto FAILURE; |
584 | 560 | ||
585 | if ( !(cs->vbuf_raw = buffer_new(VIDEO_DECODE_BUFFER_SIZE)) ) | 561 | if ( !(cs->vbuf_raw = buffer_new(VIDEO_DECODE_BUFFER_SIZE)) ) |
@@ -837,10 +813,10 @@ void queue_message(RTPSession *session, RTPMessage *msg) | |||
837 | 813 | ||
838 | uint8_t piece_number = packet[1]; | 814 | uint8_t piece_number = packet[1]; |
839 | 815 | ||
840 | uint32_t length_before_piece = ((piece_number - 1) * cs->video_frame_piece_size); | 816 | uint32_t length_before_piece = ((piece_number - 1) * cs->peer_video_frame_piece_size); |
841 | uint32_t framebuf_new_length = length_before_piece + (packet_size - VIDEOFRAME_HEADER_SIZE); | 817 | uint32_t framebuf_new_length = length_before_piece + (packet_size - VIDEOFRAME_HEADER_SIZE); |
842 | 818 | ||
843 | if (framebuf_new_length > cs->max_video_frame_size) { | 819 | if (framebuf_new_length > MAX_VIDEOFRAME_SIZE) { |
844 | goto end; | 820 | goto end; |
845 | } | 821 | } |
846 | 822 | ||
@@ -851,9 +827,8 @@ void queue_message(RTPSession *session, RTPMessage *msg) | |||
851 | packet + VIDEOFRAME_HEADER_SIZE, | 827 | packet + VIDEOFRAME_HEADER_SIZE, |
852 | packet_size - VIDEOFRAME_HEADER_SIZE); | 828 | packet_size - VIDEOFRAME_HEADER_SIZE); |
853 | 829 | ||
854 | if (framebuf_new_length > cs->frame_size) { | 830 | if (framebuf_new_length > cs->frame_size) |
855 | cs->frame_size = framebuf_new_length; | 831 | cs->frame_size = framebuf_new_length; |
856 | } | ||
857 | 832 | ||
858 | end: | 833 | end: |
859 | rtp_free_msg(NULL, msg); | 834 | rtp_free_msg(NULL, msg); |