diff options
author | irungentoo <irungentoo@gmail.com> | 2014-12-16 13:10:28 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-12-16 13:10:28 -0500 |
commit | 82ba83e52643ff76962b24abb6ca22ba343c1fbb (patch) | |
tree | 48829e3302700b3d1303b76ee6ecbea39e648f21 /toxav/codec.c | |
parent | d6da08fe9d86fa5f03d0a2fe74960d62bc0c00fc (diff) |
cs_set_video_encoder_resolution improvements.
Diffstat (limited to 'toxav/codec.c')
-rw-r--r-- | toxav/codec.c | 21 |
1 files changed, 16 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 | ||