diff options
Diffstat (limited to 'toxav/codec.c')
-rw-r--r-- | toxav/codec.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/toxav/codec.c b/toxav/codec.c index 4abb7f8c..fbf78d69 100644 --- a/toxav/codec.c +++ b/toxav/codec.c | |||
@@ -210,6 +210,44 @@ int init_audio_decoder(CodecState *cs, uint32_t audio_channels) | |||
210 | return 0; | 210 | return 0; |
211 | } | 211 | } |
212 | 212 | ||
213 | int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height) | ||
214 | { | ||
215 | vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc; | ||
216 | |||
217 | if (cfg.g_w == width && cfg.g_h == height) | ||
218 | return 0; | ||
219 | |||
220 | LOGGER_DEBUG("New video resolution: %u %u", width, height); | ||
221 | cfg.g_w = width; | ||
222 | cfg.g_h = height; | ||
223 | int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg); | ||
224 | |||
225 | if ( rc != VPX_CODEC_OK) { | ||
226 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | ||
227 | return -1; | ||
228 | } | ||
229 | |||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate) | ||
234 | { | ||
235 | vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc; | ||
236 | |||
237 | if (cfg.rc_target_bitrate == video_bitrate) | ||
238 | return 0; | ||
239 | |||
240 | LOGGER_DEBUG("New video bitrate: %u", video_bitrate); | ||
241 | cfg.rc_target_bitrate = video_bitrate; | ||
242 | int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg); | ||
243 | |||
244 | if ( rc != VPX_CODEC_OK) { | ||
245 | LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc)); | ||
246 | return -1; | ||
247 | } | ||
248 | |||
249 | return 0; | ||
250 | } | ||
213 | 251 | ||
214 | int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) | 252 | int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) |
215 | { | 253 | { |
@@ -222,8 +260,8 @@ int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t | |||
222 | } | 260 | } |
223 | 261 | ||
224 | cfg.rc_target_bitrate = video_bitrate; | 262 | cfg.rc_target_bitrate = video_bitrate; |
225 | cfg.g_w = width; | 263 | cfg.g_w = 8192; |
226 | cfg.g_h = height; | 264 | cfg.g_h = 8192; |
227 | cfg.g_pass = VPX_RC_ONE_PASS; | 265 | cfg.g_pass = VPX_RC_ONE_PASS; |
228 | cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT | VPX_ERROR_RESILIENT_PARTITIONS; | 266 | cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT | VPX_ERROR_RESILIENT_PARTITIONS; |
229 | cfg.g_lag_in_frames = 0; | 267 | cfg.g_lag_in_frames = 0; |
@@ -244,6 +282,9 @@ int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t | |||
244 | return -1; | 282 | return -1; |
245 | } | 283 | } |
246 | 284 | ||
285 | if (reconfigure_video_encoder_resolution(cs, width, height) != 0) | ||
286 | return -1; | ||
287 | |||
247 | return 0; | 288 | return 0; |
248 | } | 289 | } |
249 | 290 | ||