diff options
Diffstat (limited to 'toxav')
-rw-r--r-- | toxav/codec.c | 38 | ||||
-rw-r--r-- | toxav/codec.h | 5 | ||||
-rw-r--r-- | toxav/toxav.c | 1 |
3 files changed, 44 insertions, 0 deletions
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) | |||
206 | return 0; | 206 | return 0; |
207 | } | 207 | } |
208 | 208 | ||
209 | int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height) | ||
210 | { | ||
211 | vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc; | ||
212 | |||
213 | if (cfg.g_w == width && cfg.g_h == height) | ||
214 | return 0; | ||
215 | |||
216 | LOGGER_DEBUG("New video resolution: %u %u", width, height); | ||
217 | cfg.g_w = width; | ||
218 | cfg.g_h = height; | ||
219 | int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg); | ||
220 | |||
221 | if ( rc != VPX_CODEC_OK) { | ||
222 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | ||
223 | return -1; | ||
224 | } | ||
225 | |||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate) | ||
230 | { | ||
231 | vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc; | ||
232 | |||
233 | if (cfg.rc_target_bitrate == video_bitrate) | ||
234 | return 0; | ||
235 | |||
236 | LOGGER_DEBUG("New video bitrate: %u", video_bitrate); | ||
237 | cfg.rc_target_bitrate = video_bitrate; | ||
238 | int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg); | ||
239 | |||
240 | if ( rc != VPX_CODEC_OK) { | ||
241 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | ||
242 | return -1; | ||
243 | } | ||
244 | |||
245 | return 0; | ||
246 | } | ||
209 | 247 | ||
210 | int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) | 248 | int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) |
211 | { | 249 | { |
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, | |||
102 | 102 | ||
103 | void codec_terminate_session(CodecState *cs); | 103 | void codec_terminate_session(CodecState *cs); |
104 | 104 | ||
105 | /* Reconfigure video encoder | ||
106 | return 0 on success. | ||
107 | return -1 on failure. */ | ||
108 | int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height); | ||
109 | int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate); | ||
105 | 110 | ||
106 | /* Calculate energy and return 1 if has voice, 0 if not */ | 111 | /* Calculate energy and return 1 if has voice, 0 if not */ |
107 | int energy_VAD(CodecState *cs, int16_t *PCM, uint16_t frame_size, float energy); | 112 | 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 | |||
640 | 640 | ||
641 | 641 | ||
642 | CallSpecific *call = &av->calls[call_index]; | 642 | CallSpecific *call = &av->calls[call_index]; |
643 | reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h); | ||
643 | 644 | ||
644 | int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); | 645 | int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); |
645 | 646 | ||