Path: blob/main/devices/src/virtio/video/encoder/backend/mod.rs
5394 views
// Copyright 2020 The ChromiumOS Authors1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.34#[cfg(feature = "ffmpeg")]5pub mod ffmpeg;6#[cfg(feature = "libvda")]7pub mod vda;89use base::AsRawDescriptor;1011use super::EncoderCapabilities;12use super::EncoderEvent;13use super::InputBufferId;14use super::OutputBufferId;15use super::SessionConfig;16use crate::virtio::video::error::VideoResult;17use crate::virtio::video::format::Bitrate;18use crate::virtio::video::resource::GuestResource;19use crate::virtio::video::resource::GuestResourceHandle;2021pub trait EncoderSession {22/// Encodes the frame provided by `resource`.23/// `force_keyframe` forces the frame to be encoded as a keyframe.24/// When the buffer has been successfully processed, a `ProcessedInputBuffer` event will25/// be readable from the event pipe, with the same `InputBufferId` as returned by this26/// function.27/// When the corresponding encoded data is ready, `ProcessedOutputBuffer` events will be28/// readable from the event pipe, with the same timestamp as provided `timestamp`.29fn encode(30&mut self,31resource: GuestResource,32timestamp: u64,33force_keyframe: bool,34) -> VideoResult<InputBufferId>;3536/// Provides an output `resource` to store encoded output, where `offset` and `size` define the37/// region of memory to use.38/// When the buffer has been filled with encoded output, a `ProcessedOutputBuffer` event will be39/// readable from the event pipe, with the same `OutputBufferId` as returned by this function.40fn use_output_buffer(41&mut self,42resource: GuestResourceHandle,43offset: u32,44size: u32,45) -> VideoResult<OutputBufferId>;4647/// Requests the encoder to flush. When completed, an `EncoderEvent::FlushResponse` event will48/// be readable from the event pipe.49fn flush(&mut self) -> VideoResult<()>;5051/// Requests the encoder to use new encoding parameters provided by `bitrate` and `framerate`.52fn request_encoding_params_change(53&mut self,54bitrate: Bitrate,55framerate: u32,56) -> VideoResult<()>;5758/// Returns the event pipe on which the availability of events will be signaled. Note that the59/// returned value is borrowed and only valid as long as the session is alive.60fn event_pipe(&self) -> &dyn AsRawDescriptor;6162/// Performs a blocking read for an encoder event. This function should only be called when63/// the file descriptor returned by `event_pipe` is readable.64fn read_event(&mut self) -> VideoResult<EncoderEvent>;65}6667pub trait Encoder {68type Session: EncoderSession;6970fn query_capabilities(&self) -> VideoResult<EncoderCapabilities>;71fn start_session(&mut self, config: SessionConfig) -> VideoResult<Self::Session>;72fn stop_session(&mut self, session: Self::Session) -> VideoResult<()>;73}747576