Overview
VSourceLibCamera C++ library provides video capture and video source control functions based on Libcamera API. The library inherits its interface from the open-source VSource interface class. VSource.h file contains data structures: VSourceParams class (contains video source params and provides methods for serialization/deserialization of params), VSourceCommand enum (describes video source action commands) and VSourceParam enum (describes video source params). VSourceLibCamera depends on: Libcamera API, VSource interface class (provides interface for video sources, source code included, Apache 2.0 license) and open-source Logger library (provides methods to write logs, source code included, Apache 2.0 license). The library provides auto-detection of supported resolution, format and FPS. If a particular device doesn’t support the requested pixel format, resolution or FPS, the library will set the most appropriate parameters. The library supports C++17 standard.
Documentation
Documentation: GO TO DOCUMENTATION
Simple interface
namespace cr
{
namespace video
{
/// Video source implementation class.
class VSourceLibCameraImpl;
/// Video source class based on libcamera API.
class VSourceLibCamera : public VSource
{
public:
/**
* @brief Class constructor.
*/
VSourceLibCamera();
/// Class destructor.
~VSourceLibCamera();
/// Get string of current library version.
static std::string getVersion();
/// Open video source.
bool openVSource(std::string& initString) override;
/// Init video source.
bool initVSource(VSourceParams& params) override;
/// Get open status.
bool isVSourceOpen() override;
/// Close video source.
void closeVSource() override;
/// Get new video frame.
bool getFrame(Frame& frame, int32_t timeoutMsec = 0) override;
/// Set video source param.
bool setParam(VSourceParam id, float value) override;
/// Get video source param value.
float getParam(VSourceParam id) override;
/// Get video source params structure.
void getParams(VSourceParams& params) override;
/// Execute command.
bool executeCommand(VSourceCommand id) override;
/// Decode and execute command.
bool decodeAndExecuteCommand(uint8_t* data, int size) override;
};
}
}
Simple example
#include <iostream>
#include "VSourceLibCamera.h"
int main(void)
{
// Init video source.
cr::video::VSource* source = new cr::video::VSourceLibCamera();
std::string initString = "0;1280;720;30;NV12";
if (!source->openVSource(initString))
return -1;
// Main loop.
cr::video::Frame frame;
while (true)
{
// Wait new frame 1 sec.
if (!source->getFrame(frame, 1000))
continue;
std::cout << "New frame " << frame.frameId <<
" (" << frame.width << "x" << frame.height << ") cycle time : " <<
(int)source->getParam(cr::video::VSourceParam::CYCLE_TIME_MKS) <<
" mksec" << std::endl;
}
return 1;
}

