From 9f164b45634d380bb6fb15e2e5719547323ab461 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 4 Jul 2014 17:41:02 -0400 Subject: Resolution of video can now be changed during call by passing it frames with a different resolution. Added function to change bitrate of video for later use. --- toxav/codec.c | 38 ++++++++++++++++++++++++++++++++++++++ toxav/codec.h | 5 +++++ toxav/toxav.c | 1 + 3 files changed, 44 insertions(+) diff --git a/toxav/codec.c b/toxav/codec.c index 3e6de803..3664ddd0 100644 --- a/toxav/codec.c +++ b/toxav/codec.c @@ -206,6 +206,44 @@ int init_audio_decoder(CodecState *cs, uint32_t audio_channels) return 0; } +int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height) +{ + vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc; + + if (cfg.g_w == width && cfg.g_h == height) + return 0; + + LOGGER_DEBUG("New video resolution: %u %u", width, height); + cfg.g_w = width; + cfg.g_h = height; + int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg); + + if ( rc != VPX_CODEC_OK) { + LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); + return -1; + } + + return 0; +} + +int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate) +{ + vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc; + + if (cfg.rc_target_bitrate == video_bitrate) + return 0; + + LOGGER_DEBUG("New video bitrate: %u", video_bitrate); + cfg.rc_target_bitrate = video_bitrate; + int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg); + + if ( rc != VPX_CODEC_OK) { + LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); + return -1; + } + + return 0; +} int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) { diff --git a/toxav/codec.h b/toxav/codec.h index 7ddf2943..d8e9f1a7 100644 --- a/toxav/codec.h +++ b/toxav/codec.h @@ -102,6 +102,11 @@ CodecState *codec_init_session ( uint32_t audio_bitrate, void codec_terminate_session(CodecState *cs); +/* Reconfigure video encoder + return 0 on success. + return -1 on failure. */ +int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height); +int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate); /* Calculate energy and return 1 if has voice, 0 if not */ int energy_VAD(CodecState *cs, int16_t *PCM, uint16_t frame_size, float energy); diff --git a/toxav/toxav.c b/toxav/toxav.c index 82385b95..b97f84ea 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -640,6 +640,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d CallSpecific *call = &av->calls[call_index]; + reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h); int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); -- cgit v1.2.3