diff options
Diffstat (limited to 'toxav')
-rw-r--r-- | toxav/codec.c | 21 | ||||
-rw-r--r-- | toxav/codec.h | 1 |
2 files changed, 17 insertions, 5 deletions
diff --git a/toxav/codec.c b/toxav/codec.c index 2c15cb4d..dae35d54 100644 --- a/toxav/codec.c +++ b/toxav/codec.c | |||
@@ -270,9 +270,6 @@ static int init_video_encoder(CSSession *cs, uint16_t max_width, uint16_t max_he | |||
270 | cfg.kf_max_dist = 48; | 270 | cfg.kf_max_dist = 48; |
271 | cfg.kf_mode = VPX_KF_AUTO; | 271 | cfg.kf_mode = VPX_KF_AUTO; |
272 | 272 | ||
273 | cs->max_width = max_width; | ||
274 | cs->max_height = max_height; | ||
275 | |||
276 | rc = vpx_codec_enc_init_ver(&cs->v_encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0, VPX_ENCODER_ABI_VERSION); | 273 | rc = vpx_codec_enc_init_ver(&cs->v_encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0, VPX_ENCODER_ABI_VERSION); |
277 | 274 | ||
278 | if ( rc != VPX_CODEC_OK) { | 275 | if ( rc != VPX_CODEC_OK) { |
@@ -287,6 +284,10 @@ static int init_video_encoder(CSSession *cs, uint16_t max_width, uint16_t max_he | |||
287 | return -1; | 284 | return -1; |
288 | } | 285 | } |
289 | 286 | ||
287 | cs->max_width = max_width; | ||
288 | cs->max_height = max_height; | ||
289 | cs->video_bitrate = video_bitrate; | ||
290 | |||
290 | return 0; | 291 | return 0; |
291 | } | 292 | } |
292 | 293 | ||
@@ -436,8 +437,17 @@ int cs_set_video_encoder_resolution(CSSession *cs, uint16_t width, uint16_t heig | |||
436 | if (cfg.g_w == width && cfg.g_h == height) | 437 | if (cfg.g_w == width && cfg.g_h == height) |
437 | return 0; | 438 | return 0; |
438 | 439 | ||
439 | if (width * height > cs->max_width * cs->max_height) | 440 | if (width * height > cs->max_width * cs->max_height) { |
440 | return cs_ErrorSettingVideoResolution; | 441 | vpx_codec_ctx_t v_encoder = cs->v_encoder; |
442 | |||
443 | if (init_video_encoder(cs, width, height, cs->video_bitrate) == -1) { | ||
444 | cs->v_encoder = v_encoder; | ||
445 | return cs_ErrorSettingVideoResolution; | ||
446 | } | ||
447 | |||
448 | vpx_codec_destroy(&v_encoder); | ||
449 | return 0; | ||
450 | } | ||
441 | 451 | ||
442 | LOGGER_DEBUG("New video resolution: %u %u", width, height); | 452 | LOGGER_DEBUG("New video resolution: %u %u", width, height); |
443 | cfg.g_w = width; | 453 | cfg.g_w = width; |
@@ -468,6 +478,7 @@ int cs_set_video_encoder_bitrate(CSSession *cs, uint32_t video_bitrate) | |||
468 | return cs_ErrorSettingVideoBitrate; | 478 | return cs_ErrorSettingVideoBitrate; |
469 | } | 479 | } |
470 | 480 | ||
481 | cs->video_bitrate = video_bitrate; | ||
471 | return 0; | 482 | return 0; |
472 | } | 483 | } |
473 | 484 | ||
diff --git a/toxav/codec.h b/toxav/codec.h index 1ee0a4ff..6018e5df 100644 --- a/toxav/codec.h +++ b/toxav/codec.h | |||
@@ -85,6 +85,7 @@ typedef struct _CSSession { | |||
85 | vpx_codec_ctx_t v_decoder; | 85 | vpx_codec_ctx_t v_decoder; |
86 | int max_width; | 86 | int max_width; |
87 | int max_height; | 87 | int max_height; |
88 | unsigned int video_bitrate; | ||
88 | 89 | ||
89 | 90 | ||
90 | /* Data handling */ | 91 | /* Data handling */ |