class UsbState

Defined at line 81 of file ../../src/camera/drivers/usb_video/usb_state.h

UsbState handles the state machine for interacting with the usb camera.

It handles the validation and communication with the USB device

when selecting an available stream, and starting and stopping that stream.

UsbState communicates with the device through a banjo interface to parent usb device.

Since the parent device may operate on a separate dispatcher, UsbState may exhibit one

asynchronous behavior: the request callback passed as an argument to StartStreaming may

be called using a different dispatcher than the one that called StartStreaming.

All other functions of UsbState operate synchronously.

The SetFormat function must be called successfully before a stream may be started or stopped.

In this case, a "stream" is defined as a series of calls to the request callback provided

by the StartStreaming function. Each call contains a usb_request_t, which points at a vmo with a

blob of data. Concatenated together, these data blobs make up the data portion of a single

video frame. The usb_header included in the usb_request_t contains information to indicate which

video frame is being filled.

State machine for UsbState:

STOPPED ---

<SetFormat

> ---> READY

<

------

| STOPPING (temporary)

<StartStreaming

> |

|

<StopStreaming

>

\

|/ |

STREAMING -------^

Here are the allowed state transitions.

Cells marked with ERROR will return an error if attempted, but

will not result in a state transition.

Initial State

| STOPPED | READY | STREAMING | STOPPING

SetFormat | READY | READY | Error! | Error!

StartStreaming| Error! | STREAMING | Error! | Error!

StopStreaming | Error! | Error! | STOPPING | Error!

The STOPPING state is a temporary state that transitions to

READY when stopping is complete.

Public Methods

const std::vector<UvcFormat> & GetUvcFormats ()

Defined at line 103 of file ../../src/camera/drivers/usb_video/usb_state.h

uint32_t ClockFrequencyHz ()

Defined at line 105 of file ../../src/camera/drivers/usb_video/usb_state.h

uint32_t MaxFrameSize ()

These functions can only be called when a format has been set:

Defined at line 108 of file ../../src/camera/drivers/usb_video/usb_state.h

uint64_t RequestSize ()

The number of bytes to request in a USB request to a streaming endpoint.

This should be equal or less than allocated_req_size_.

Can only be called after format has been set

Defined at line 117 of file ../../src/camera/drivers/usb_video/usb_state.h

uint32_t MaxPayloadTransferSize ()

Can only be called after format has been set

Defined at line 124 of file ../../src/camera/drivers/usb_video/usb_state.h

uint32_t EndpointType ()

Can only be called after format has been set

Defined at line 131 of file ../../src/camera/drivers/usb_video/usb_state.h

uint64_t GetHostSOF ()

Defined at line 137 of file ../../src/camera/drivers/usb_video/usb_state.h

void UsbState (usb_protocol_t usb, StreamingSetting settings)

Defined at line 199 of file ../../src/camera/drivers/usb_video/usb_state.cc

zx_status_t SetFormat (fuchsia::camera::VideoFormat video_format)

Requests the device use the given format and frame descriptor,

then finds a streaming setting that supports the required

data throughput.

If successful, sets the initial state of the stream configuration

related fields, and reallocates usb requests if necessary.

Otherwise an error will be returned and the caller should try

again with a different set of inputs.

frame_desc may be NULL for non frame based formats.

Return: on success, returns the configuration that has been set.

Defined at line 339 of file ../../src/camera/drivers/usb_video/usb_state.cc

zx_status_t StartStreaming (fit::function<void (usb_request_t *)> req_callback)

Defined at line 214 of file ../../src/camera/drivers/usb_video/usb_state.cc

zx_status_t StopStreaming ()

Defined at line 243 of file ../../src/camera/drivers/usb_video/usb_state.cc

const UsbDeviceInfo GetDeviceInfo ()

Defined at line 175 of file ../../src/camera/drivers/usb_video/usb_state.cc

void ~UsbState ()

Defined at line 282 of file ../../src/camera/drivers/usb_video/usb_state.cc