hw encoder: set_bitrate and apply_bitrate based on Param (#38095)

* initial codex

* remove ISP delay from encode ms

* try something simpler

* not allowing increase bug

* decrease bitrate increase rate

* upsample only on consecutive good checks

* rearrange

* clean

* Revert frame timing processing time change

* clean

* remove bitrate option and just do it on --stream

* make set_bitrate a lot more simple

* clean default impl

* further cleaning

* struct for bitrate to pass ci

* refactor a bit

* add comment

* small clean

* add init()

* increase bitrate

* update ffmpeg message

* remove unnecessary include

* modify set_bitrate

* change to Param

* remove getInt helper; add back in diff pr

* reword unclear error message

* move webrtcd change to new branch
This commit is contained in:
stef
2026-05-29 18:00:47 -07:00
committed by GitHub
parent 9f59a4a5ca
commit ad522f8444
8 changed files with 54 additions and 4 deletions
+21
View File
@@ -155,6 +155,8 @@ V4LEncoder::V4LEncoder(const EncoderInfo &encoder_info, int in_width, int in_hei
assert(strcmp((const char *)cap.card, "msm_vidc_venc") == 0);
EncoderSettings encoder_settings = encoder_info.get_settings(in_width);
current_bitrate = encoder_settings.bitrate;
adaptive_bitrate = encoder_info.adaptive_bitrate;
bool is_h265 = encoder_settings.encode_type == cereal::EncodeIndex::Type::FULL_H_E_V_C;
struct v4l2_format fmt_out = {
@@ -304,6 +306,25 @@ void V4LEncoder::encoder_close() {
this->is_open = false;
}
void V4LEncoder::set_bitrate(int bitrate) {
if (!adaptive_bitrate || bitrate == current_bitrate) return;
if (bitrate <= 0) {
LOGE("invalid livestream encoder bitrate %d", bitrate);
return;
}
struct v4l2_control ctrl = {
.id = V4L2_CID_MPEG_VIDEO_BITRATE,
.value = bitrate,
};
if (util::safe_ioctl(fd, VIDIOC_S_CTRL, &ctrl) == -1) {
LOGE("failed to update %s bitrate to %d", encoder_info.publish_name, bitrate);
return;
}
current_bitrate = bitrate;
}
V4LEncoder::~V4LEncoder() {
encoder_close();
v4l2_buf_type buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;