Skip to content

Commit

Permalink
encoder/vp9: Pass Tunings instead of RateControl to backends
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrzesik committed Mar 29, 2024
1 parent 44e7ba0 commit 7e99821
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/encoder/stateless/vp9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::encoder::stateless::StatelessCodec;
use crate::encoder::stateless::StatelessEncoderExecute;
use crate::encoder::stateless::StatelessVideoEncoderBackend;
use crate::encoder::FrameMetadata;
use crate::encoder::RateControl;
use crate::encoder::Tunings;
use crate::BlockingMode;
use crate::Resolution;
Expand Down Expand Up @@ -71,8 +70,8 @@ pub struct BackendRequest<P, R> {
golden_frame_ref: Option<(Rc<R>, ReferenceUse)>,
altref_frame_ref: Option<(Rc<R>, ReferenceUse)>,

/// Current expected bitrate
rate_control: RateControl,
/// [`Tunings`] for the frame
tunings: Tunings,

/// Container for the request output. [`StatelessVP9EncoderBackend`] impl shall move it and
/// append the slice data to it. This prevents unnecessary copying of bitstream around.
Expand Down
4 changes: 2 additions & 2 deletions src/encoder/stateless/vp9/predictor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<Picture, Reference> LowDelayDelegate<Picture, Reference, BackendRequest<Pic
last_frame_ref: None,
golden_frame_ref: None,
altref_frame_ref: None,
rate_control: self.tunings.rate_control.clone(),
tunings: self.tunings.clone(),
coded_output: Vec::new(),
};

Expand All @@ -122,7 +122,7 @@ impl<Picture, Reference> LowDelayDelegate<Picture, Reference, BackendRequest<Pic
last_frame_ref: Some((ref_frame, ReferenceUse::Single)),
golden_frame_ref: None,
altref_frame_ref: None,
rate_control: self.tunings.rate_control.clone(),
tunings: self.tunings.clone(),
coded_output: Vec::new(),
};

Expand Down
8 changes: 6 additions & 2 deletions src/encoder/stateless/vp9/vaapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ where
const DEFAULT_CODED_SIZE: usize = 1_500_000;

let coded_size = request
.tunings
.rate_control
.bitrate_target()
.map(|e| e as usize * CODED_SIZE_MUL)
Expand All @@ -85,7 +86,7 @@ where
let recon = self.new_scratch_picture()?;

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

let seq_param = BufferType::EncSequenceParameter(EncSequenceParameter::VP9(
EncSequenceParameterBufferVP9::new(
Expand Down Expand Up @@ -431,7 +432,10 @@ pub(super) mod tests {
last_frame_ref: None,
golden_frame_ref: None,
altref_frame_ref: None,
rate_control: RateControl::ConstantBitrate(30_000),
tunings: Tunings {
rate_control: RateControl::ConstantBitrate(30_000),
..Default::default()
},
coded_output: Vec::new(),
};

Expand Down

0 comments on commit 7e99821

Please sign in to comment.