Skip to content

Commit

Permalink
encoder/vp9: Request finer RateControl from VAAPI
Browse files Browse the repository at this point in the history
This change submits additional parameters from VAAPI backend using
VAEncMiscParameterRateControl. With this change VP9 VAAPI encoder
responds to tuning request
  • Loading branch information
bgrzesik committed May 6, 2024
1 parent d74ae54 commit 6a33fa8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/encoder/stateless/vp9/predictor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use crate::encoder::FrameMetadata;
use crate::encoder::RateControl;
use crate::encoder::Tunings;

pub(crate) const MIN_Q_IDX: u8 = 0;
pub(crate) const MAX_Q_IDX: u8 = 255;

pub(crate) struct LowDelayVP9Delegate {
config: EncoderConfig,
}
Expand Down
9 changes: 9 additions & 0 deletions src/encoder/stateless/vp9/vaapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use libva::VAProfile::VAProfileVP9Profile2;
use libva::VP9EncPicFlags;
use libva::VP9EncRefFlags;

use crate::backend::vaapi::encoder::tunings_to_libva_rc;
use crate::backend::vaapi::encoder::CodedOutputPromise;
use crate::backend::vaapi::encoder::Reconstructed;
use crate::backend::vaapi::encoder::VaapiBackend;
Expand All @@ -32,6 +33,8 @@ use crate::codec::vp9::parser::ALTREF_FRAME;
use crate::codec::vp9::parser::GOLDEN_FRAME;
use crate::codec::vp9::parser::LAST_FRAME;
use crate::codec::vp9::parser::NUM_REF_FRAMES;
use crate::encoder::stateless::vp9::predictor::MAX_Q_IDX;
use crate::encoder::stateless::vp9::predictor::MIN_Q_IDX;
use crate::encoder::stateless::vp9::BackendRequest;
use crate::encoder::stateless::vp9::EncoderConfig;
use crate::encoder::stateless::vp9::ReferenceUse;
Expand Down Expand Up @@ -226,6 +229,11 @@ where
),
));

let rc_param =
tunings_to_libva_rc::<{ MIN_Q_IDX as u32 }, { MAX_Q_IDX as u32 }>(&request.tunings)?;
let rc_param =
libva::BufferType::EncMiscParameter(libva::EncMiscParameter::RateControl(rc_param));

let mut picture = Picture::new(
request.input_meta.timestamp,
Rc::clone(self.context()),
Expand All @@ -234,6 +242,7 @@ where

picture.add_buffer(self.context().create_buffer(seq_param)?);
picture.add_buffer(self.context().create_buffer(pic_param)?);
picture.add_buffer(self.context().create_buffer(rc_param)?);

// Start processing the picture encoding
let picture = picture.begin().context("picture begin")?;
Expand Down

0 comments on commit 6a33fa8

Please sign in to comment.