From 65b4c026f4a2aa965f89f28958fe75bceb16475c Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 5 Jul 2014 14:36:19 -0400 Subject: The width and height set during the video encoder initialization is now described as the maximum width and height of images. This is to work around what appears to be a bug in libvpx where the resolution of the stream can be decreased but increasing it above its originally set value introduces memory corruption. --- toxav/codec.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'toxav/codec.c') 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_ if (cfg.g_w == width && cfg.g_h == height) return 0; + if (width * height > cs->max_width * cs->max_height) + return -1; + LOGGER_DEBUG("New video resolution: %u %u", width, height); cfg.g_w = width; cfg.g_h = height; @@ -249,7 +252,7 @@ int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate) return 0; } -int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) +int init_video_encoder(CodecState *cs, uint16_t max_width, uint16_t max_height, uint32_t video_bitrate) { vpx_codec_enc_cfg_t cfg; 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 } cfg.rc_target_bitrate = video_bitrate; - cfg.g_w = 8192; - cfg.g_h = 8192; + cfg.g_w = max_width; + cfg.g_h = max_height; cfg.g_pass = VPX_RC_ONE_PASS; cfg.g_error_resilient = VPX_ERROR_RESILIENT_DEFAULT | VPX_ERROR_RESILIENT_PARTITIONS; cfg.g_lag_in_frames = 0; cfg.kf_min_dist = 0; cfg.kf_max_dist = 300; + cfg.kf_mode = VPX_KF_AUTO; + + cs->max_width = max_width; + cs->max_height = max_height; + cs->bitrate = video_bitrate; rc = vpx_codec_enc_init_ver(&cs->v_encoder, VIDEO_CODEC_ENCODER_INTERFACE, &cfg, 0, VPX_ENCODER_ABI_VERSION); @@ -282,9 +290,6 @@ int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t return -1; } - if (reconfigure_video_encoder_resolution(cs, width, height) != 0) - return -1; - return 0; } @@ -322,8 +327,8 @@ CodecState *codec_init_session ( uint32_t audio_bitrate, uint32_t audio_sample_rate, uint32_t audio_channels, uint32_t audio_VAD_tolerance_ms, - uint16_t video_width, - uint16_t video_height, + uint16_t max_video_width, + uint16_t max_video_height, uint32_t video_bitrate ) { CodecState *retu = calloc(sizeof(CodecState), 1); @@ -334,11 +339,11 @@ CodecState *codec_init_session ( uint32_t audio_bitrate, retu->audio_sample_rate = audio_sample_rate; /* Encoders */ - if (!video_width || !video_height) { /* Disable video */ + if (!max_video_width || !max_video_height) { /* Disable video */ /*video_width = 320; video_height = 240; */ } else { - retu->capabilities |= ( 0 == init_video_encoder(retu, video_width, video_height, video_bitrate) ) ? v_encoding : 0; + retu->capabilities |= ( 0 == init_video_encoder(retu, max_video_width, max_video_height, video_bitrate) ) ? v_encoding : 0; retu->capabilities |= ( 0 == init_video_decoder(retu) ) ? v_decoding : 0; } -- cgit v1.2.3 From 4e85be6a68e83023a200088167336ead0f8f860d Mon Sep 17 00:00:00 2001 From: stal Date: Sat, 19 Jul 2014 19:18:15 -0700 Subject: declare calculate_sum_sq static inline --- toxav/codec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toxav/codec.c') diff --git a/toxav/codec.c b/toxav/codec.c index ae24a976..4a12ffb2 100644 --- a/toxav/codec.c +++ b/toxav/codec.c @@ -383,7 +383,7 @@ void codec_terminate_session ( CodecState *cs ) free(cs); } -inline float calculate_sum_sq (int16_t *n, uint16_t k) +static inline float calculate_sum_sq (int16_t *n, uint16_t k) { float result = 0; uint16_t i = 0; -- cgit v1.2.3 From cc1466ec09e12c7aeb39690a32affbd4cf3b897b Mon Sep 17 00:00:00 2001 From: stal Date: Sat, 19 Jul 2014 19:29:56 -0700 Subject: remove this too --- toxav/codec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'toxav/codec.c') diff --git a/toxav/codec.c b/toxav/codec.c index 4a12ffb2..b7ca2784 100644 --- a/toxav/codec.c +++ b/toxav/codec.c @@ -383,7 +383,7 @@ void codec_terminate_session ( CodecState *cs ) free(cs); } -static inline float calculate_sum_sq (int16_t *n, uint16_t k) +static float calculate_sum_sq (int16_t *n, uint16_t k) { float result = 0; uint16_t i = 0; -- cgit v1.2.3