summaryrefslogtreecommitdiff
path: root/src/cam/capture_script.cpp
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2022-09-02 16:54:43 +0200
committerJacopo Mondi <jacopo@jmondi.org>2022-09-20 15:39:50 +0200
commitcf5d0cbb34607a3041dc21364ee79e710e9e304f (patch)
treef0d86ff11556cddcd63dc09af84669138d5e1c70 /src/cam/capture_script.cpp
parent74ab3f778c848b20cbf8fe299170756ff6ebab1a (diff)
cam: capture_script: Introduce 'loop' property
Add support to the capture script for properties that control the script execution. Script properties are specified in the 'properties' section before the actual list of controls specified in the 'frames' section. Define a first 'loop' property that allows repeating the frame list periodically. All the frame ids in the 'frames' section shall be smaller than the loop control. Modify the capture script example to show usage of the 'loop' property and better document the frames list while at it. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/cam/capture_script.cpp')
-rw-r--r--src/cam/capture_script.cpp80
1 files changed, 77 insertions, 3 deletions
diff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp
index 5e85b3ca..5a27361c 100644
--- a/src/cam/capture_script.cpp
+++ b/src/cam/capture_script.cpp
@@ -15,7 +15,7 @@ using namespace libcamera;
CaptureScript::CaptureScript(std::shared_ptr<Camera> camera,
const std::string &fileName)
- : camera_(camera), valid_(false)
+ : camera_(camera), loop_(0), valid_(false)
{
FILE *fh = fopen(fileName.c_str(), "r");
if (!fh) {
@@ -44,8 +44,13 @@ CaptureScript::CaptureScript(std::shared_ptr<Camera> camera,
const ControlList &CaptureScript::frameControls(unsigned int frame)
{
static ControlList controls{};
+ unsigned int idx = frame;
- auto it = frameControls_.find(frame);
+ /* If we loop, repeat the controls every 'loop_' frames. */
+ if (loop_)
+ idx = frame % loop_;
+
+ auto it = frameControls_.find(idx);
if (it == frameControls_.end())
return controls;
@@ -149,7 +154,11 @@ int CaptureScript::parseScript(FILE *script)
std::string section = eventScalarValue(event);
- if (section == "frames") {
+ if (section == "properties") {
+ ret = parseProperties();
+ if (ret)
+ return ret;
+ } else if (section == "frames") {
ret = parseFrames();
if (ret)
return ret;
@@ -161,6 +170,65 @@ int CaptureScript::parseScript(FILE *script)
}
}
+int CaptureScript::parseProperty()
+{
+ EventPtr event = nextEvent(YAML_MAPPING_START_EVENT);
+ if (!event)
+ return -EINVAL;
+
+ std::string prop = parseScalar();
+ if (prop.empty())
+ return -EINVAL;
+
+ if (prop == "loop") {
+ event = nextEvent();
+ if (!event)
+ return -EINVAL;
+
+ std::string value = eventScalarValue(event);
+ if (value.empty())
+ return -EINVAL;
+
+ loop_ = atoi(value.c_str());
+ if (!loop_) {
+ std::cerr << "Invalid loop limit '" << loop_ << "'"
+ << std::endl;
+ return -EINVAL;
+ }
+ } else {
+ std::cerr << "Unsupported property '" << prop << "'" << std::endl;
+ return -EINVAL;
+ }
+
+ event = nextEvent(YAML_MAPPING_END_EVENT);
+ if (!event)
+ return -EINVAL;
+
+ return 0;
+}
+
+int CaptureScript::parseProperties()
+{
+ EventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT);
+ if (!event)
+ return -EINVAL;
+
+ while (1) {
+ if (event->type == YAML_SEQUENCE_END_EVENT)
+ return 0;
+
+ int ret = parseProperty();
+ if (ret)
+ return ret;
+
+ event = nextEvent();
+ if (!event)
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
int CaptureScript::parseFrames()
{
EventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT);
@@ -191,6 +259,12 @@ int CaptureScript::parseFrame(EventPtr event)
return -EINVAL;
unsigned int frameId = atoi(key.c_str());
+ if (loop_ && frameId >= loop_) {
+ std::cerr
+ << "Frame id (" << frameId << ") shall be smaller than"
+ << "loop limit (" << loop_ << ")" << std::endl;
+ return -EINVAL;
+ }
event = nextEvent(YAML_MAPPING_START_EVENT);
if (!event)