Skip to main content

FrameStream

Struct FrameStream 

Source
pub struct FrameStream { /* private fields */ }
Expand description

Frames from one GVSP stream, assembled by a receive thread of its own.

The thread starts when the stream is created and stops, joined within a few milliseconds, when it is dropped. It reads every datagram as it arrives, whether or not anything is waiting for a frame, and keeps up to sixteen finished frames for next_block or next_block_blocking; when the application falls behind, the oldest is dropped and counted in StreamStats::frames_backpressure.

Only complete frames are delivered unless set_deliver_incomplete asks otherwise; every block is counted either way.

§Example

ⓘ
let raw_stream = StreamBuilder::new(&mut device)
    .iface(iface)
    .build()
    .await?;
let mut frame_stream = FrameStream::new(raw_stream, None);
while let Some(frame) = frame_stream.next_frame().await? {
    println!("Frame {}: {}x{}", frame.block_id, frame.width, frame.height);
}

Implementations§

Source§

impl FrameStream

Source

pub fn new(stream: Stream, time_sync: Option<TimeSync>) -> Self

Start receiving on a configured Stream.

Optionally accepts a TimeSync for mapping device timestamps to host time.

Source

pub fn from_socket( socket: UdpSocket, packet_size: u32, ) -> Result<Self, GenicamError>

Receive GVSP on a socket the caller bound, from a camera configured some other way: another application holds control, or the stream was set up by hand.

packet_size is the camera’s GevSCPSPacketSize, which fixes where each packet’s bytes belong. config is None for such a stream.

Such a stream accepts datagrams from any address until set_source_filter names the camera, and never asks for lost packets unless enable_resend is called. A host that only monitors a stream must not ask: it does not control the camera, and its requests would add traffic to a stream another application configured.

Source

pub fn set_block_timeout(&mut self, timeout: Duration)

How long a block may go without a packet before it is closed as incomplete (default 100 ms).

Counted from the block’s last packet, not its first: a large frame on a slow or paced link takes as long as it takes, and only silence ends it.

Source

pub fn set_payload_size(&mut self, payload_size: Option<usize>)

The camera’s PayloadSize: the exact size of every frame buffer.

Without it each buffer is sized from the leader’s geometry, which cannot know about chunk data or vendor padding. Set it before acquisition starts; blocks already in flight keep their buffers.

Source

pub fn set_deliver_incomplete(&mut self, deliver: bool)

Also deliver frames that did not complete, with their FrameStatus saying how (default: off).

Lost packets’ bytes are zero in the payload. Every incomplete frame is counted in StreamStats::frames_incomplete either way.

Source

pub fn set_source_filter(&mut self, camera: Option<Ipv4Addr>)

Accept GVSP only from camera; None accepts any source.

A stream from StreamBuilder or Camera::open_stream accepts only the camera’s own address. Datagrams from anywhere else are ignored and counted in StreamStats::packets_ignored_foreign; a camera that sends its stream from another address than the one it answers GVCP on needs None.

Source

pub fn source_filter(&self) -> Option<Ipv4Addr>

The only address GVSP is accepted from, if any.

Source

pub fn enable_resend(&mut self, camera: SocketAddrV4, channel: u16)

Ask the camera at camera (its GVCP address, normally port 3956) to send lost packets of stream channel channel again.

Camera::open_stream does this when the camera’s capability register says it supports packet resend. Call it yourself only for a stream this application controls, on a camera that supports resend.

Source

pub fn disable_resend(&mut self)

Stop asking for lost packets.

Source

pub fn resend_enabled(&self) -> bool

Whether the stream asks the camera for lost packets.

Source

pub fn set_resend_delay(&mut self, delay: Duration)

How old a gap in a block’s packets must be before it is asked for (default 2 ms), so a packet that was only overtaken is not.

Source

pub fn set_resend_retry_interval(&mut self, interval: Duration)

How long to wait for a resent packet before asking again (default 20 ms).

Source

pub fn set_resend_max_requests(&mut self, requests: u32)

How many times one range of packets is asked for, the first request included (default 3).

Source

pub fn set_resend_budget(&mut self, share: f64)

The share of a block’s packets its requests may ask for, retries included (default 0.25, rounded up). A block that lost more is not worth flooding the camera for; it closes incomplete.

Source

pub fn set_time_sync(&mut self, time_sync: TimeSync)

Update or set the time synchronization model for timestamp mapping.

Source

pub fn stats_handle(&self) -> StreamStatsAccumulator

Obtain a clone of the statistics accumulator handle.

Source

pub fn stats(&self) -> StreamStats

Snapshot the collected statistics.

Source

pub fn params(&self) -> StreamParams

Access the negotiated stream parameters.

Source

pub fn config(&self) -> Option<&StreamConfig>

The stream configuration, or None for a stream made with from_socket.

Source

pub async fn next_frame(&mut self) -> Result<Option<Frame>, GenicamError>

Receive the next image frame.

This backwards-compatible image API also returns an EVS block as a Frame carrying the raw bytes and its EVT PFNC code. New callers that need to distinguish event data should use next_block.

Source

pub async fn next_block( &mut self, ) -> Result<Option<GenericStreamBlock>, GenicamError>

Receive and classify the next GVSP block.

Ok(None) means the stream has ended. Cancel-safe: dropping the future, as tokio::select! does, loses no block.

Source

pub fn next_block_blocking( &mut self, timeout: Duration, ) -> Result<Option<GenericStreamBlock>, GenicamError>

Wait up to timeout for the next block on the calling thread.

For callers without an async runtime. Ok(None) means the stream has ended; nothing within timeout is GenicamError::Timeout.

Source

pub fn next_frame_blocking( &mut self, timeout: Duration, ) -> Result<Option<Frame>, GenicamError>

next_frame on the calling thread, waiting up to timeout: Ok(None) when the stream has ended, GenicamError::Timeout when nothing arrived.

Trait Implementations§

Source§

impl Drop for FrameStream

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,

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.

§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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