PiImageStreamer
Loading...
Searching...
No Matches
SWE4211RPi::CompressedImageCapturer Class Reference

#include <CompressedImageCapturer.h>

Inheritance diagram for SWE4211RPi::CompressedImageCapturer:
Collaboration diagram for SWE4211RPi::CompressedImageCapturer:

Public Member Functions

 CompressedImageCapturer (SWE4211RPi::NewCamera &referencedCamera, AbstractImageTransmitter &trans, int width, int height, std::string threadName, uint32_t period)
 
virtual ~CompressedImageCapturer ()
 
virtual void taskMethod ()
 
- Public Member Functions inherited from SWE4211RPi::AbstractImageCapturer
void printVideoStreamMetrics ()
 
void addOverlay (std::shared_ptr< AbstractImageOverlay > overlay)
 
void removeOverlay (std::shared_ptr< AbstractImageOverlay > overlay)
 
- Public Member Functions inherited from SWE4211RPi::PeriodicTask
 PeriodicTask (std::string threadName, uint32_t period, int priority=1)
 
virtual ~PeriodicTask ()
 
virtual void setTaskPeriod (uint32_t period) final
 
virtual uint32_t getTaskPeriod () final
 
void run () final
 
virtual void printInformation ()
 
virtual double getCPUUsageInfo ()
 
virtual void resetThreadDiagnostics ()
 
- Public Member Functions inherited from SWE4211RPi::RunnableClass
 RunnableClass (std::string threadName, int priority=0)
 
virtual ~RunnableClass ()
 
virtual pid_t getThreadID ()
 
virtual void start () final
 
virtual void setPriority (int priority) final
 
virtual int getPriority () final
 
virtual bool isShutdown () final
 
virtual bool isStarted () final
 
virtual void stopThreadExecution ()
 
virtual void waitForShutdown ()
 

Additional Inherited Members

- Static Public Member Functions inherited from SWE4211RPi::RunnableClass
static void printThreads ()
 
static void resetAllThreadInformation ()
 
- Protected Member Functions inherited from SWE4211RPi::AbstractImageCapturer
 AbstractImageCapturer (SWE4211RPi::NewCamera &referencedCamera, AbstractImageTransmitter &trans, int width, int height, std::string threadName, uint32_t period)
 
virtual ~AbstractImageCapturer ()
 
void printFrameTiming ()
 
void resetMetricsOnNewConnection ()
 
void applyOverlays (cv::Mat *image)
 
- Protected Member Functions inherited from SWE4211RPi::PeriodicTask
virtual void startChildRunnables () final
 
virtual void stopChildRunnables () final
 
virtual void startChildTasks ()
 
virtual void stopChildTasks ()
 
- Static Protected Member Functions inherited from SWE4211RPi::AbstractImageCapturer
static std::chrono::microseconds getThreadCpuTime ()
 
- Protected Attributes inherited from SWE4211RPi::AbstractImageCapturer
SWE4211RPi::NewCamera & myCamera
 
AbstractImageTransmitter & myTrans
 
int imageWidth
 
int imageHeight
 
cv::Size * size
 
cv::Mat resizedImage
 
int count = 0
 
int xmitTimeDeadlineMissCount =0
 
std::chrono::microseconds totalGrab {0}
 
std::chrono::microseconds totalResize {0}
 
std::chrono::microseconds totalTransmit {0}
 
long framesTransmitted = 0
 
std::chrono::microseconds grabTime {0}
 
std::chrono::microseconds resizeTime {0}
 
std::chrono::microseconds transmitTime {0}
 
std::chrono::microseconds delayTime {0}
 
int lastConnectionNumber = 0
 
std::list< std::shared_ptr< AbstractImageOverlay > > overlays
 
- Protected Attributes inherited from SWE4211RPi::PeriodicTask
uint32_t taskPeriod = 100000
 
- Protected Attributes inherited from SWE4211RPi::RunnableClass
std::thread * myThread = NULL
 
pthread_t executingThread = 0
 
pid_t myOSThreadID = 0
 
std::string myName
 
std::atomic< bool > keepGoing {true}
 
std::atomic< bool > runCompleted {false}
 
std::atomic< bool > runStarted {false}
 
int priority = -1
 
- Static Protected Attributes inherited from SWE4211RPi::RunnableClass
static std::list< RunnableClass * > runningThreads
 

Detailed Description

This class is the image capturer used with the compressed image transmitter.

Constructor & Destructor Documentation

◆ CompressedImageCapturer()

CompressedImageCapturer::CompressedImageCapturer ( SWE4211RPi::NewCamera &  referencedCamera,
AbstractImageTransmitter &  trans,
int  width,
int  height,
std::string  threadName,
uint32_t  period 
)

Construct a new instance of the image capturer.

Parameters
referencedCameraThis is the camera that is referenced.
transThis is the image transmitter that is to send the given image across the network.
widthThis is the width of the image that is to be sent in pixels.
heightThis is the height of the image that is to be sent in pixels.
threadNameThis is the name of the thread that is to execute.
periodThis is the period for the task, given in microseconds.

◆ ~CompressedImageCapturer()

CompressedImageCapturer::~CompressedImageCapturer ( )
virtual

This is the destructor for the class.

This is the destructor.

Member Function Documentation

◆ taskMethod()

void CompressedImageCapturer::taskMethod ( )
virtual

This is the taskMethod that will run once each period. It will capture, process, and transmit one image.

This is the virtual task method. It will capture, process, and transmit one image. It will execute once each task period. The algorithm is as follows:

  1. Obtain the current time from the steady clock. The steady clock acts as a stopwatch: unlike the system clock, it is never adjusted, so the difference between two readings is always the true elapsed (wall) time. This is only used to determine the delay until the next period.
  2. Obtain the CPU time used so far by this thread. This is used to measure how much CPU time each step takes, excluding any time this thread spends preempted or blocked.

  3. Take the picture from the camera. This returns a newly allocated copy of the camera's most recent frame.

  4. If the image is not empty,

    1. Apply the overlays to the image.

    2. Obtain the CPU time used so far by this thread.

    3. Resize the image according to the desired size, if a resize needs to occur. The resized image is written into the fixed resizedImage buffer rather than back into the original image, which would force a new image to be allocated every frame. The image to send is then the resized image. If no resize is needed, the original image is sent.

    4. Obtain the CPU time used so far by this thread.

    5. Stream the image to the remote device.

    6. Obtain the CPU time used so far by this thread, and the current time from the steady clock.

    7. Record the CPU time it took to grab the picture (including applying the overlays), resize the picture, and transmit the picture in us. Microseconds are used so that steps taking less than 1 ms are not rounded down to 0. The transmit CPU time includes encoding the image and the kernel's work sending each datagram out through the network stack, but not any time spent blocked waiting for the network.
    8. Add the specific values to the running totals as is applicable.

    9. Calculate the delay time until the next frame needs to be sent, which is the task period minus the wall time used thus far. Wall time is used here because the period is measured in real time, including any time spent preempted or blocked.
    10. If the time is negative

      1. increment the missed deadline count by 1.

    11. Increment the count of frames transmitted.

    12. Print the timing for this frame and the running averages to the console.

  5. Delete the image returned by the camera.

Implements SWE4211RPi::AbstractImageCapturer.

Here is the call graph for this function:

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