Skip to main content

NvfbcSession

Struct NvfbcSession 

Source
struct NvfbcSession {
    _lib: Library,
    funcs: NVFBC_API_FUNCTION_LIST,
    handle: u64,
    capture_open: bool,
    region: NVFBC_BOX,
    size: NVFBC_SIZE,
    with_cursor: bool,
}
Expand description

A live NvFBC capture: the loaded library, the driver’s function table, the client handle, and the capture session bound to it.

The handle owns an OpenGL and a CUDA context that the driver binds to the thread that created it, and the captured device pointer belongs to whichever CUDA context was current at setup — which is why the whole object is built, used, and dropped on one thread, with NVENC’s own primary context pushed current. Sharing that context is what makes the capture zero-copy: the pointer the driver hands back is one NVENC can register directly.

Fields§

§_lib: Library§funcs: NVFBC_API_FUNCTION_LIST§handle: u64§capture_open: bool§region: NVFBC_BOX

The region of the framebuffer being captured, and the frame size it is delivered at.

§size: NVFBC_SIZE§with_cursor: bool

Implementations§

Source§

impl NvfbcSession

Source

fn load() -> Result<(Library, NVFBC_API_FUNCTION_LIST), String>

Load libnvidia-fbc.so.1 and fill the driver’s function table, erroring when the library is absent (no NVIDIA driver, or a container without the video capability) or too old to answer for this API version.

Source

fn last_error(&self) -> String

The driver’s message for the last failure on this handle, for a log line that says what went wrong rather than only that something did.

Source

fn fail(&self, what: &str, status: u32) -> NvfbcError

Turn a driver status into an error carrying both the code and the driver’s own message.

Source

fn open() -> Result<Self, String>

Open a client handle on the X server named by the environment, letting NvFBC create and manage the OpenGL context it captures through.

The server is asked for NVIDIA_GLX first, over a connection of our own: it is what the library looks up here too, and where it is missing the library’s own lookup is the call that never returns.

The handle is bound to the calling thread, and every later call has to come from it.

Source

fn status(&self) -> Result<NVFBC_GET_STATUS_PARAMS, NvfbcError>

Ask the driver whether capture is possible here and how large the framebuffer is.

Source

fn start( &mut self, region: NVFBC_BOX, size: NVFBC_SIZE, with_cursor: bool, ) -> Result<(), NvfbcError>

Start capturing region of the framebuffer into video memory, delivered at size.

The session is programmed for latency rather than for throughput smoothing: push model, so the driver generates a frame when an application damages the screen instead of polling on a timer; direct capture allowed, so a fullscreen unoccluded application presents into the capture buffer without going through the X server (which the driver takes up only when the cursor is not composited); and the native BGRA format, which needs no conversion pass and so no extra copy. Modeset recovery is left to the driver, which rebuilds the session and resumes on its own.

Source

fn stop(&mut self)

End the capture session, leaving the handle open for another start.

Source

fn grab(&mut self, timeout: Duration) -> Result<GrabbedFrame, NvfbcError>

Take the next frame, waiting at most timeout for the driver to produce one.

A frame the client has not seen yet is returned without waiting at all; otherwise the call blocks until one is rendered or the timeout expires, and then returns the frame already in the buffer with is_new false. Nothing is copied either way: the device pointer addresses the driver’s own capture buffer, which stays valid until the next grab.

Source

fn grab_with( &mut self, flags: u32, timeout: Duration, ) -> Result<GrabbedFrame, NvfbcError>

The grab above, with the driver’s wait behavior named explicitly.

Trait Implementations§

Source§

impl Drop for NvfbcSession

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more