Skip to content

Commit

Permalink
encoder: Merge StatelessCodec and StatelessCodecSpecific traits
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrzesik committed Mar 4, 2024
1 parent b03a538 commit 06a50d0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
25 changes: 11 additions & 14 deletions src/encoder/stateless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ pub(super) trait Predictor<Picture, Reference, Request> {
}

/// Generic trait for stateless encoder backends
pub trait StatelessVideoEncoderBackend<Codec>
pub trait StatelessVideoEncoderBackend<Codec>: Sized
where
Codec: StatelessCodec,
Codec: StatelessCodec<Self>,
{
/// Backend's specific representation of the input frame, transformed with [`import_picture`].
/// Might be a wrapper of the input handle with additional backend specific data or a copy of
Expand Down Expand Up @@ -211,7 +211,7 @@ pub trait StatelessEncoderBackendImport<Handle, Picture> {
}

/// Trait helping contain all codec specific and backend specific types
pub trait StatelessCodecSpecific<Backend>: StatelessCodec
pub trait StatelessCodec<Backend>: Sized
where
Backend: StatelessVideoEncoderBackend<Self>,
{
Expand All @@ -231,8 +231,6 @@ where
type ReferencePromise: BackendPromise<Output = Self::Reference>;
}

pub trait StatelessCodec: Sized {}

/// Stateless video encoder interface.
pub trait StatelessVideoEncoder<Handle> {
/// Enqueues the frame for encoding. The implementation will drop the handle after it is no
Expand Down Expand Up @@ -290,21 +288,20 @@ where
/// Helper aliases for codec and backend specific types
type Picture<C, B> = <B as StatelessVideoEncoderBackend<C>>::Picture;

type Reference<C, B> = <C as StatelessCodecSpecific<B>>::Reference;
type Reference<C, B> = <C as StatelessCodec<B>>::Reference;

type Request<C, B> = <C as StatelessCodecSpecific<B>>::Request;
type Request<C, B> = <C as StatelessCodec<B>>::Request;

type CodedPromise<C, B> = <C as StatelessCodecSpecific<B>>::CodedPromise;
type CodedPromise<C, B> = <C as StatelessCodec<B>>::CodedPromise;

type ReferencePromise<C, B> =
<C as StatelessCodecSpecific<B>>::ReferencePromise;
type ReferencePromise<C, B> = <C as StatelessCodec<B>>::ReferencePromise;

type BoxPredictor<C, B> = Box<dyn Predictor<Picture<C, B>, Reference<C, B>, Request<C, B>>>;

pub struct StatelessEncoder<Codec, Handle, Backend>
where
Backend: StatelessVideoEncoderBackend<Codec>,
Codec: StatelessCodec + StatelessCodecSpecific<Backend>,
Codec: StatelessCodec<Backend>,
{
/// Pending frame output promise queue
output_queue: OutputQueue<CodedPromise<Codec, Backend>>,
Expand Down Expand Up @@ -335,14 +332,14 @@ where
pub trait StatelessEncoderExecute<Codec, Handle, Backend>
where
Backend: StatelessVideoEncoderBackend<Codec>,
Codec: StatelessCodec + StatelessCodecSpecific<Backend>,
Codec: StatelessCodec<Backend>,
{
fn execute(&mut self, request: Request<Codec, Backend>) -> EncodeResult<()>;
}

impl<Codec, Handle, Backend> StatelessEncoder<Codec, Handle, Backend>
where
Codec: StatelessCodec + StatelessCodecSpecific<Backend>,
Codec: StatelessCodec<Backend>,
Backend: StatelessVideoEncoderBackend<Codec>,
Self: StatelessEncoderExecute<Codec, Handle, Backend>,
{
Expand Down Expand Up @@ -387,7 +384,7 @@ where
impl<Codec, Handle, Backend> StatelessVideoEncoder<Handle>
for StatelessEncoder<Codec, Handle, Backend>
where
Codec: StatelessCodec + StatelessCodecSpecific<Backend>,
Codec: StatelessCodec<Backend>,
Backend: StatelessVideoEncoderBackend<Codec>,
Backend: StatelessEncoderBackendImport<Handle, Backend::Picture>,
Self: StatelessEncoderExecute<Codec, Handle, Backend>,
Expand Down
5 changes: 1 addition & 4 deletions src/encoder/stateless/h264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::encoder::stateless::FrameMetadata;
use crate::encoder::stateless::Predictor;
use crate::encoder::stateless::StatelessBackendResult;
use crate::encoder::stateless::StatelessCodec;
use crate::encoder::stateless::StatelessCodecSpecific;
use crate::encoder::stateless::StatelessEncoder;
use crate::encoder::stateless::StatelessEncoderBackendImport;
use crate::encoder::stateless::StatelessEncoderExecute;
Expand Down Expand Up @@ -158,7 +157,7 @@ where

pub struct H264;

impl<Backend> StatelessCodecSpecific<Backend> for H264
impl<Backend> StatelessCodec<Backend> for H264
where
Backend: StatelessVideoEncoderBackend<H264>,
{
Expand All @@ -171,8 +170,6 @@ where
type ReferencePromise = ReferencePromise<Backend::ReconPromise>;
}

impl StatelessCodec for H264 {}

/// Trait for stateless encoder backend for H.264
pub trait StatelessH264EncoderBackend: StatelessVideoEncoderBackend<H264> {
/// Submit a [`BackendRequest`] to the backend. This operation returns both a
Expand Down
5 changes: 1 addition & 4 deletions src/encoder/stateless/vp9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::encoder::stateless::EncodeResult;
use crate::encoder::stateless::Predictor;
use crate::encoder::stateless::StatelessBackendResult;
use crate::encoder::stateless::StatelessCodec;
use crate::encoder::stateless::StatelessCodecSpecific;
use crate::encoder::stateless::StatelessEncoder;
use crate::encoder::stateless::StatelessEncoderExecute;
use crate::encoder::stateless::StatelessVideoEncoderBackend;
Expand Down Expand Up @@ -83,7 +82,7 @@ pub struct BackendRequest<P, R> {

pub struct VP9;

impl<Backend> StatelessCodecSpecific<Backend> for VP9
impl<Backend> StatelessCodec<Backend> for VP9
where
Backend: StatelessVideoEncoderBackend<VP9>,
{
Expand All @@ -96,8 +95,6 @@ where
type ReferencePromise = Backend::ReconPromise;
}

impl StatelessCodec for VP9 {}

pub trait StatelessVP9EncoderBackend: StatelessVideoEncoderBackend<VP9> {
fn encode_frame(
&mut self,
Expand Down

0 comments on commit 06a50d0

Please sign in to comment.