Struct nvidia_video_codec_sdk::safe::Buffer
source · pub struct Buffer<'a> { /* private fields */ }
Expand description
Abstraction around input buffer allocated using the NVIDIA Video Encoder API.
The buffer is automatically destroyed when dropped.
Implementations§
source§impl<'a> Buffer<'a>
impl<'a> Buffer<'a>
sourcepub fn lock<'b>(&'b mut self) -> Result<BufferLock<'b, 'a>, EncodeError>
pub fn lock<'b>(&'b mut self) -> Result<BufferLock<'b, 'a>, EncodeError>
Lock the input buffer.
On a successful lock you get a BufferLock
which can be used to write
data to the input buffer. On drop, BufferLock
will unlock the
buffer.
This function will block until a lock is acquired. For the non-blocking
version see Buffer::try_lock
.
See NVIDIA docs.
Errors
Could error if we run out of memory.
Examples
//* Create encoder. *//
//* Set `encode_guid` and `buffer_format`, and check that H.264 encoding and the ARGB format are supported. *//
//* Begin encoder session. *//
// Create an input buffer.
let mut input_buffer = session
.create_input_buffer()
.unwrap();
unsafe { input_buffer.lock().unwrap().write(&[0; DATA_LEN]) };
sourcepub fn try_lock<'b>(&'b mut self) -> Result<BufferLock<'b, 'a>, EncodeError>
pub fn try_lock<'b>(&'b mut self) -> Result<BufferLock<'b, 'a>, EncodeError>
Non-blocking version of Buffer::lock
. See it for more info.
This function will return an error with
ErrorKind::EncoderBusy
or
ErrorKind::LockBusy
if the lock is being
used. The NVIDIA documentation from the header file is unclear about
this.
Errors
Could error if we run out of memory.
If this returns an error with
ErrorKind::EncoderBusy
or
ErrorKind::LockBusy
then that means the
lock is still busy and the client should retry in a few
milliseconds.