summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-07-04 17:41:02 -0400
committerirungentoo <irungentoo@gmail.com>2014-07-04 17:41:02 -0400
commit9f164b45634d380bb6fb15e2e5719547323ab461 (patch)
tree2569990bf21babf5fbabda1acc4d76054d3faf37
parent705fceb2e02e953f9bcb86b4177935326d65f6ae (diff)
Resolution of video can now be changed during call by passing it
frames with a different resolution. Added function to change bitrate of video for later use.
-rw-r--r--toxav/codec.c38
-rw-r--r--toxav/codec.h5
-rw-r--r--toxav/toxav.c1
3 files changed, 44 insertions, 0 deletions
diff --git a/toxav/codec.c b/toxav/codec.c
index 3e6de803..3664ddd0 100644
--- a/toxav/codec.c
+++ b/toxav/codec.c
@@ -206,6 +206,44 @@ int init_audio_decoder(CodecState *cs, uint32_t audio_channels)
206 return 0; 206 return 0;
207} 207}
208 208
209int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height)
210{
211 vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc;
212
213 if (cfg.g_w == width && cfg.g_h == height)
214 return 0;
215
216 LOGGER_DEBUG("New video resolution: %u %u", width, height);
217 cfg.g_w = width;
218 cfg.g_h = height;
219 int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg);
220
221 if ( rc != VPX_CODEC_OK) {
222 LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc));
223 return -1;
224 }
225
226 return 0;
227}
228
229int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate)
230{
231 vpx_codec_enc_cfg_t cfg = *cs->v_encoder.config.enc;
232
233 if (cfg.rc_target_bitrate == video_bitrate)
234 return 0;
235
236 LOGGER_DEBUG("New video bitrate: %u", video_bitrate);
237 cfg.rc_target_bitrate = video_bitrate;
238 int rc = vpx_codec_enc_config_set(&cs->v_encoder, &cfg);
239
240 if ( rc != VPX_CODEC_OK) {
241 LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc));
242 return -1;
243 }
244
245 return 0;
246}
209 247
210int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate) 248int init_video_encoder(CodecState *cs, uint16_t width, uint16_t height, uint32_t video_bitrate)
211{ 249{
diff --git a/toxav/codec.h b/toxav/codec.h
index 7ddf2943..d8e9f1a7 100644
--- a/toxav/codec.h
+++ b/toxav/codec.h
@@ -102,6 +102,11 @@ CodecState *codec_init_session ( uint32_t audio_bitrate,
102 102
103void codec_terminate_session(CodecState *cs); 103void codec_terminate_session(CodecState *cs);
104 104
105/* Reconfigure video encoder
106 return 0 on success.
107 return -1 on failure. */
108int reconfigure_video_encoder_resolution(CodecState *cs, uint16_t width, uint16_t height);
109int reconfigure_video_encoder_bitrate(CodecState *cs, uint32_t video_bitrate);
105 110
106/* Calculate energy and return 1 if has voice, 0 if not */ 111/* Calculate energy and return 1 if has voice, 0 if not */
107int energy_VAD(CodecState *cs, int16_t *PCM, uint16_t frame_size, float energy); 112int energy_VAD(CodecState *cs, int16_t *PCM, uint16_t frame_size, float energy);
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 82385b95..b97f84ea 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -640,6 +640,7 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d
640 640
641 641
642 CallSpecific *call = &av->calls[call_index]; 642 CallSpecific *call = &av->calls[call_index];
643 reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h);
643 644
644 int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); 645 int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US);
645 646