RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::PiCamera Class Reference

Raspberry Pi camera, recording video (raw .h264 converted to .mp4 on a background thread) and taking pictures. More...

#include <PiCamera.h>

Inheritance diagram for RumPi::PiCamera:
[legend]
Collaboration diagram for RumPi::PiCamera:
[legend]

Public Member Functions

 PiCamera ()
 Builds a Pi camera component. More...
 
 ~PiCamera ()
 Destroys the camera, joining any in-progress video-conversion thread and turning off first. More...
 
virtual void TurnOn () override
 No-op: the camera is driven on demand via RecordVideo/TakePicture, so there is nothing to turn on. More...
 
virtual void TurnOff () override
 No-op: the camera holds no persistent hardware state that needs releasing when turned off. More...
 
virtual void ProcessRawValues () override
 No-op: the camera produces media files on demand, so there are no raw values to process. More...
 
virtual std::string ToString () const override
 Serializes the camera to a string. More...
 
void RecordVideo (const char *fileName, unsigned int durationInSeconds=5U)
 Records video to the given file for a duration, then converts the raw .h264 to .mp4 on a background thread. More...
 
void RecordVideo (const char *fileName, unsigned int durationInSeconds, unsigned int width, unsigned int height, unsigned int fps, unsigned long bitRate)
 Records video with explicit resolution, frame rate, and bit rate, then converts the raw .h264 to .mp4 on a background thread. More...
 
void TakePicture (const char *fileName, unsigned int delayInSeconds=1U)
 Takes a picture and saves it to the given file after a short delay. More...
 
- Public Member Functions inherited from RumPi::BaseComponent
 BaseComponent ()
 Builds a base component with an unknown type and an empty name. More...
 
virtual ~BaseComponent ()
 Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More...
 
virtual void TurnOn ()=0
 Turns the component on (e.g. More...
 
virtual void TurnOff ()=0
 Turns the component off. More...
 
virtual std::string ToString () const =0
 Serializes the component's current readings to a string (usually JSON). More...
 
virtual void ProcessRawValues ()=0
 Reads and processes the component's latest raw values (called once per poll). More...
 
virtual EComponentType GetComponentType () const
 Gets the component's type. More...
 
const std::string & GetName () const
 Gets the component's unique per-instance name. More...
 
void SetName (const std::string &name)
 Sets the component's unique per-instance name. More...
 

Private Member Functions

int SendCameraCommand (const char *programName, const char *fileName, unsigned int timeInSeconds, unsigned int width=0U, unsigned int height=0U, unsigned int fps=0U, unsigned long bitRate=0UL)
 Builds and runs a raspivid/raspistill OS command for the given program, output file, and optional video settings. More...
 

Static Private Member Functions

static void ConvertH264ToMP4 (std::string fileName)
 Converts a raw .h264 video file to .mp4 (via MP4Box) and removes the original .h264 on success. More...
 

Private Attributes

std::thread myConvertThread
 The background thread that converts recorded .h264 video to .mp4. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from RumPi::BaseComponent
static std::string ComponentTypeToString (const EComponentType theComponentTypeToConvert)
 Maps an EComponentType to its string name. More...
 
static EComponentType StringToComponentType (const std::string &theComponentTypeName)
 Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More...
 
- Protected Attributes inherited from RumPi::BaseComponent
EComponentType myComponentType
 The kind of component this is (set by each concrete subclass). More...
 
std::string myName
 A unique per-instance name, assigned when the component is added to the manager. More...
 

Detailed Description

Raspberry Pi camera, recording video (raw .h264 converted to .mp4 on a background thread) and taking pictures.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ PiCamera()

RumPi::PiCamera::PiCamera ( )

Builds a Pi camera component.

Author
Eddie O'Hagan
Date
8/13/2026
PiCamera camera;
PiCamera()
Builds a Pi camera component.
Definition: PiCamera.cpp:16

◆ ~PiCamera()

RumPi::PiCamera::~PiCamera ( )

Destroys the camera, joining any in-progress video-conversion thread and turning off first.

Author
Eddie O'Hagan
Date
8/13/2026
PiCamera* camera = new PiCamera();
delete camera;

Member Function Documentation

◆ ConvertH264ToMP4()

void RumPi::PiCamera::ConvertH264ToMP4 ( std::string  fileName)
staticprivate

Converts a raw .h264 video file to .mp4 (via MP4Box) and removes the original .h264 on success.

Runs on a background thread and takes the file name by value so it owns its own copy.

Author
Eddie O'Hagan
Date
8/13/2026
ConvertH264ToMP4(std::string("clip"));
static void ConvertH264ToMP4(std::string fileName)
Converts a raw .h264 video file to .mp4 (via MP4Box) and removes the original .h264 on success.
Definition: PiCamera.cpp:271
Parameters
[in]fileNameThe file name (without extension) to convert.

◆ ProcessRawValues()

void RumPi::PiCamera::ProcessRawValues ( )
overridevirtual

No-op: the camera produces media files on demand, so there are no raw values to process.

Author
Eddie O'Hagan
Date
8/13/2026
camera.ProcessRawValues();

Implements RumPi::BaseComponent.

◆ RecordVideo() [1/2]

void RumPi::PiCamera::RecordVideo ( const char *  fileName,
unsigned int  durationInSeconds,
unsigned int  width,
unsigned int  height,
unsigned int  fps,
unsigned long  bitRate 
)

Records video with explicit resolution, frame rate, and bit rate, then converts the raw .h264 to .mp4 on a background thread.

Author
Eddie O'Hagan
Date
8/13/2026
camera.RecordVideo("clip", 5U, 1920U, 1080U, 30U, 10000000UL);
Parameters
[in]fileNameThe output file name (without extension).
[in]durationInSecondsHow long to record, in seconds.
[in]widthThe video width, in pixels.
[in]heightThe video height, in pixels.
[in]fpsThe frame rate, in frames per second.
[in]bitRateThe video bit rate.

◆ RecordVideo() [2/2]

void RumPi::PiCamera::RecordVideo ( const char *  fileName,
unsigned int  durationInSeconds = 5U 
)

Records video to the given file for a duration, then converts the raw .h264 to .mp4 on a background thread.

Author
Eddie O'Hagan
Date
8/13/2026
camera.RecordVideo("clip", 5U);
Parameters
[in]fileNameThe output file name (without extension).
[in]durationInSecondsHow long to record, in seconds.

◆ SendCameraCommand()

int RumPi::PiCamera::SendCameraCommand ( const char *  programName,
const char *  fileName,
unsigned int  timeInSeconds,
unsigned int  width = 0U,
unsigned int  height = 0U,
unsigned int  fps = 0U,
unsigned long  bitRate = 0UL 
)
private

Builds and runs a raspivid/raspistill OS command for the given program, output file, and optional video settings.

Author
Eddie O'Hagan
Date
8/13/2026
SendCameraCommand("raspivid", "clip", 5U);
int SendCameraCommand(const char *programName, const char *fileName, unsigned int timeInSeconds, unsigned int width=0U, unsigned int height=0U, unsigned int fps=0U, unsigned long bitRate=0UL)
Builds and runs a raspivid/raspistill OS command for the given program, output file,...
Definition: PiCamera.cpp:217
Parameters
[in]programNameThe camera program to run ("raspivid" or "raspistill").
[in]fileNameThe output file name (without extension).
[in]timeInSecondsThe duration/delay, in seconds (converted to milliseconds internally).
[in]widthThe video width in pixels, or 0 to omit.
[in]heightThe video height in pixels, or 0 to omit.
[in]fpsThe frame rate, or 0 to omit.
[in]bitRateThe video bit rate, or 0 to omit.
Returns
The system() result, or -1 if the arguments were invalid.

◆ TakePicture()

void RumPi::PiCamera::TakePicture ( const char *  fileName,
unsigned int  delayInSeconds = 1U 
)

Takes a picture and saves it to the given file after a short delay.

Author
Eddie O'Hagan
Date
8/13/2026
camera.TakePicture("photo", 1U);
Parameters
[in]fileNameThe output file name (without extension).
[in]delayInSecondsHow long to wait before capturing, in seconds.

◆ ToString()

std::string RumPi::PiCamera::ToString ( ) const
overridevirtual

Serializes the camera to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = camera.ToString();
Returns
A string identifying the camera.

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::PiCamera::TurnOff ( )
overridevirtual

No-op: the camera holds no persistent hardware state that needs releasing when turned off.

Author
Eddie O'Hagan
Date
8/13/2026
camera.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::PiCamera::TurnOn ( )
overridevirtual

No-op: the camera is driven on demand via RecordVideo/TakePicture, so there is nothing to turn on.

Author
Eddie O'Hagan
Date
8/13/2026
camera.TurnOn();

Implements RumPi::BaseComponent.

Member Data Documentation

◆ myConvertThread

std::thread RumPi::PiCamera::myConvertThread
private

The background thread that converts recorded .h264 video to .mp4.


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