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 Mar 29, 2024
1 parent 6bb9411 commit 33083ba
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 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 @@ -87,6 +90,7 @@ where

// Use bitrate from RateControl or ask driver to ignore
let bits_per_second = request.tunings.rate_control.bitrate_target().unwrap_or(0) as u32;
dbg!(bits_per_second);

let seq_param = BufferType::EncSequenceParameter(EncSequenceParameter::VP9(
EncSequenceParameterBufferVP9::new(
Expand Down Expand Up @@ -241,6 +245,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 @@ -249,6 +258,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 33083ba

Please sign in to comment.