diff options
Diffstat (limited to 'toxav/codec.c')
-rw-r--r-- | toxav/codec.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/toxav/codec.c b/toxav/codec.c index ed0c8e54..595c0359 100644 --- a/toxav/codec.c +++ b/toxav/codec.c | |||
@@ -217,6 +217,9 @@ int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_ | |||
217 | if (cfg.g_w == width && cfg.g_h == height) | 217 | if (cfg.g_w == width && cfg.g_h == height) |
218 | return 0; | 218 | return 0; |
219 | 219 | ||
220 | if (width * height > cs->max_width * cs->max_height) | ||
221 | return -1; | ||
222 | |||
220 | LOGGER_DEBUG("New video resolution: %u %u", width, height); | 223 | LOGGER_DEBUG("New video resolution: %u %u", width, height); |
221 | cfg.g_w = width; | 224 | cfg.g_w = width; |
222 | cfg.g_h = height; | 225 | cfg.g_h = height; |
@@ -249,7 +252,7 @@ int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate) | |||
249 | return 0; | 252 | return 0; |
250 | } | 253 | } |
251 | 254 | ||
252 | int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) | 255 | int init_video_encoder(CodecState *cs, uint16_t max_width, uint16_t max_height, uint32_t video_bitrate) |
253 | { | 256 | { |
254 | vpx_codec_enc_cfg_t cfg; | 257 | vpx_codec_enc_cfg_t cfg; |
255 | int rc = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); | 258 | int rc = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0); |
@@ -260,13 +263,18 @@ int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t | |||
260 | } | 263 | } |
261 | 264 | ||
262 | cfg.rc_target_bitrate = video_bitrate; | 265 | cfg.rc_target_bitrate = video_bitrate; |
263 | cfg.g_w = 8192; | 266 | cfg.g_w = max_width; |
264 | cfg.g_h = 8192; | 267 | cfg.g_h = max_height; |
265 | cfg.g_pass = VPX_RC_ONE_PASS; | 268 | cfg.g_pass = VPX_RC_ONE_PASS; |
266 | cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT | VPX_ERROR_RESILIENT_PARTITIONS; | 269 | cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT | VPX_ERROR_RESILIENT_PARTITIONS; |
267 | cfg.g_lag_in_frames = 0; | 270 | cfg.g_lag_in_frames = 0; |
268 | cfg.kf_min_dist = 0; | 271 | cfg.kf_min_dist = 0; |
269 | cfg.kf_max_dist = 300; | 272 | cfg.kf_max_dist = 300; |
273 | cfg.kf_mode = VPX_KF_AUTO; | ||
274 | |||
275 | cs->max_width = max_width; | ||
276 | cs->max_height = max_height; | ||
277 | cs->bitrate = video_bitrate; | ||
270 | 278 | ||
271 | rc = vpx_codec_enc_init_ver(&cs->v_encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0, VPX_ENCODER_ABI_VERSION); | 279 | rc = vpx_codec_enc_init_ver(&cs->v_encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0, VPX_ENCODER_ABI_VERSION); |
272 | 280 | ||
@@ -282,9 +290,6 @@ int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t | |||
282 | return -1; | 290 | return -1; |
283 | } | 291 | } |
284 | 292 | ||
285 | if (reconfigure_video_encoder_resolution(cs, width, height) != 0) | ||
286 | return -1; | ||
287 | |||
288 | return 0; | 293 | return 0; |
289 | } | 294 | } |
290 | 295 | ||
@@ -322,8 +327,8 @@ CodecState *codec_init_session ( uint32_t audio_bitrate, | |||
322 | uint32_t audio_sample_rate, | 327 | uint32_t audio_sample_rate, |
323 | uint32_t audio_channels, | 328 | uint32_t audio_channels, |
324 | uint32_t audio_VAD_tolerance_ms, | 329 | uint32_t audio_VAD_tolerance_ms, |
325 | uint16_t video_width, | 330 | uint16_t max_video_width, |
326 | uint16_t video_height, | 331 | uint16_t max_video_height, |
327 | uint32_t video_bitrate ) | 332 | uint32_t video_bitrate ) |
328 | { | 333 | { |
329 | CodecState *retu = calloc(sizeof(CodecState), 1); | 334 | CodecState *retu = calloc(sizeof(CodecState), 1); |
@@ -334,11 +339,11 @@ CodecState *codec_init_session ( uint32_t audio_bitrate, | |||
334 | retu->audio_sample_rate = audio_sample_rate; | 339 | retu->audio_sample_rate = audio_sample_rate; |
335 | 340 | ||
336 | /* Encoders */ | 341 | /* Encoders */ |
337 | if (!video_width || !video_height) { /* Disable video */ | 342 | if (!max_video_width || !max_video_height) { /* Disable video */ |
338 | /*video_width = 320; | 343 | /*video_width = 320; |
339 | video_height = 240; */ | 344 | video_height = 240; */ |
340 | } else { | 345 | } else { |
341 | retu->capabilities |= ( 0 == init_video_encoder(retu, video_width, video_height, video_bitrate) ) ? v_encoding : 0; | 346 | retu->capabilities |= ( 0 == init_video_encoder(retu, max_video_width, max_video_height, video_bitrate) ) ? v_encoding : 0; |
342 | retu->capabilities |= ( 0 == init_video_decoder(retu) ) ? v_decoding : 0; | 347 | retu->capabilities |= ( 0 == init_video_decoder(retu) ) ? v_decoding : 0; |
343 | } | 348 | } |
344 | 349 | ||