bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
pi_camera_line_following::MJPEG_HTTPCameraBackend Class Referencefinal

Receives the frames of an MJPEG stream over HTTP, the multipart/x-mixed-replace response that many cameras and camera servers give, for example example 31's FastAPI server on a Raspberry Pi. More...

#include <mjpeg_http_camera_backend.h>

Inheritance diagram for pi_camera_line_following::MJPEG_HTTPCameraBackend:
Collaboration diagram for pi_camera_line_following::MJPEG_HTTPCameraBackend:

Classes

struct  Config
 Settings of the backend. More...

Public Member Functions

 MJPEG_HTTPCameraBackend (const Config &config)
 MJPEG_HTTPCameraBackend (const MJPEG_HTTPCameraBackend &)=delete
 ~MJPEG_HTTPCameraBackend () override
MJPEG_HTTPCameraBackend & operator= (const MJPEG_HTTPCameraBackend &)=delete
void connect () override
 Start receiving frames.
void disconnect () override
 Stop receiving frames.
std::optional< CameraFrame > latest_frame () const override
 The latest frame, if one has been received.
bool is_alive () const override
 Whether frames are arriving.
bool wait_for_frame (real_t timeout) const
 Wait until the first frame arrives.
real_t frame_rate () const
 The frame rate of the stream, averaged over the last frames [frames/s]. Zero before two frames have arrived.
uint_t n_reconnects () const noexcept
 How many times the stream had to be opened again.
const Config & config () const noexcept
Public Member Functions inherited from bitsim::sensors::backends::CameraBackendBase
virtual ~CameraBackendBase ()=default
const std::string & backend_type_str () const noexcept
 The type of the backend.

Static Public Member Functions

static bool can_read_streams ()
 Whether this OpenCV can read HTTP streams at all. The backend reads them with OpenCV's FFmpeg backend, which an OpenCV built without FFmpeg does not have; the backend then never receives a frame.

Static Public Attributes

static const std::string BACKEND_TYPE = "MJPEG_HTTP"
 The backend type.

Additional Inherited Members

Protected Member Functions inherited from bitsim::sensors::backends::CameraBackendBase
 CameraBackendBase (const std::string &backend_type)

Detailed Description

Receives the frames of an MJPEG stream over HTTP, the multipart/x-mixed-replace response that many cameras and camera servers give, for example example 31's FastAPI server on a Raspberry Pi.

A thread of its own reads the stream and keeps only the latest frame, so a slow reader never falls behind the camera. If the stream breaks it reconnects. It uses OpenCV's FFmpeg backend to read the stream.

Constructor & Destructor Documentation

◆ MJPEG_HTTPCameraBackend() [1/2]

◆ MJPEG_HTTPCameraBackend() [2/2]

◆ ~MJPEG_HTTPCameraBackend()

Member Function Documentation

◆ can_read_streams()

Whether this OpenCV can read HTTP streams at all. The backend reads them with OpenCV's FFmpeg backend, which an OpenCV built without FFmpeg does not have; the backend then never receives a frame.

◆ config()

◆ connect()

◆ disconnect()

◆ frame_rate()

The frame rate of the stream, averaged over the last frames [frames/s]. Zero before two frames have arrived.

◆ is_alive()

Whether frames are arriving.

Implements bitsim::sensors::backends::CameraBackendBase.

◆ latest_frame()

The latest frame, if one has been received.

Implements bitsim::sensors::backends::CameraBackendBase.

◆ n_reconnects()

How many times the stream had to be opened again.

◆ operator=()

MJPEG_HTTPCameraBackend & bitsim::sensors::backends::MJPEG_HTTPCameraBackend::operator= ( const MJPEG_HTTPCameraBackend & )
delete

◆ wait_for_frame()

Wait until the first frame arrives.

Parameters
timeoutHow long to wait at most [s]
Returns
Whether a frame arrived

Member Data Documentation

◆ BACKEND_TYPE

The backend type.


The documentation for this class was generated from the following files: