diff options
Diffstat (limited to 'tinyDAV/src/codecs')
-rwxr-xr-x | tinyDAV/src/codecs/h264/tdav_codec_h264_cisco.cxx | 29 | ||||
-rwxr-xr-x | tinyDAV/src/codecs/vpx/tdav_codec_vp8.c | 11 |
2 files changed, 38 insertions, 2 deletions
diff --git a/tinyDAV/src/codecs/h264/tdav_codec_h264_cisco.cxx b/tinyDAV/src/codecs/h264/tdav_codec_h264_cisco.cxx index 4973089..3cf2540 100755 --- a/tinyDAV/src/codecs/h264/tdav_codec_h264_cisco.cxx +++ b/tinyDAV/src/codecs/h264/tdav_codec_h264_cisco.cxx @@ -170,6 +170,33 @@ static int tdav_codec_h264_cisco_set(tmedia_codec_t* self, const tmedia_param_t* } return 0; } + else if (tsk_striequals(param->key, "out-size")) { + int ret; + uint32_t new_size = *((uint32_t*)param->value); + uint16_t new_width = (new_size & 0xFFFF); + uint16_t new_height = (new_size >> 16) & 0xFFFF; + if (self->opened) { + // It's up to the caller to lock the codec or make sure no other code will code encode() function. + // We must not call lock/unlock(encoder.mutex) here because close() will free the mutex + // close encoder + if ((ret = tdav_codec_h264_cisco_close_encoder(h264, kResetRotationFalse))) { + return ret; + } + // update size + h264->encoder.neg_width = TMEDIA_CODEC_VIDEO(h264)->out.width = new_width; + h264->encoder.neg_height = TMEDIA_CODEC_VIDEO(h264)->out.height = new_height; + // re-open encoder + if ((ret = tdav_codec_h264_cisco_open_encoder(h264))) { + return ret; + } + } + else { + // update size + h264->encoder.neg_width = TMEDIA_CODEC_VIDEO(h264)->out.width = new_width; + h264->encoder.neg_height = TMEDIA_CODEC_VIDEO(h264)->out.height = new_height; + } + return 0; + } } if (reconf) { @@ -642,7 +669,7 @@ static int tdav_codec_h264_cisco_open_encoder(tdav_codec_h264_cisco_t* self) self->encoder.neg_height = (self->encoder.rotation == 90 || self->encoder.rotation == 270) ? TMEDIA_CODEC_VIDEO(self)->out.width : TMEDIA_CODEC_VIDEO(self)->out.height; self->encoder.neg_fps = TMEDIA_CODEC_VIDEO(self)->out.fps; max_bw_kpbs = TSK_CLAMP( - 0, + 1, tmedia_get_video_bandwidth_kbps_2(self->encoder.neg_width, self->encoder.neg_height, self->encoder.neg_fps), TMEDIA_CODEC(self)->bandwidth_max_upload ); diff --git a/tinyDAV/src/codecs/vpx/tdav_codec_vp8.c b/tinyDAV/src/codecs/vpx/tdav_codec_vp8.c index 25434c8..754d2cc 100755 --- a/tinyDAV/src/codecs/vpx/tdav_codec_vp8.c +++ b/tinyDAV/src/codecs/vpx/tdav_codec_vp8.c @@ -180,6 +180,15 @@ static int tdav_codec_vp8_set(tmedia_codec_t* self, const tmedia_param_t* param) reconf = tsk_true; } } + else if (tsk_striequals(param->key, "out-size")) { + // It's up to the caller to lock the codec or make sure no other code will code encode() function. + uint32_t new_size = *((uint32_t*)param->value); + TMEDIA_CODEC_VIDEO(vp8)->out.width = (new_size & 0xFFFF); + TMEDIA_CODEC_VIDEO(vp8)->out.height = (new_size >> 16) & 0xFFFF; + vp8->encoder.cfg.g_w = (vp8->encoder.rotation == 90 || vp8->encoder.rotation == 270) ? TMEDIA_CODEC_VIDEO(vp8)->out.height : TMEDIA_CODEC_VIDEO(self)->out.width; + vp8->encoder.cfg.g_h = (vp8->encoder.rotation == 90 || vp8->encoder.rotation == 270) ? TMEDIA_CODEC_VIDEO(vp8)->out.width : TMEDIA_CODEC_VIDEO(self)->out.height; + reconf = tsk_true; + } } if (reconf) { @@ -709,7 +718,7 @@ int tdav_codec_vp8_open_encoder(tdav_codec_vp8_t* self) self->encoder.cfg.g_timebase.num = 1; self->encoder.cfg.g_timebase.den = TMEDIA_CODEC_VIDEO(self)->out.fps; self->encoder.cfg.rc_target_bitrate = TSK_CLAMP( - 0, + 1, tmedia_get_video_bandwidth_kbps_2(TMEDIA_CODEC_VIDEO(self)->out.width, TMEDIA_CODEC_VIDEO(self)->out.height, TMEDIA_CODEC_VIDEO(self)->out.fps), TMEDIA_CODEC(self)->bandwidth_max_upload ); |