status: extend to provide all camera options and properties in JSON payload

- control: add `device_option_is_equal`
- libcamera: provide human readable configurable options
- v4l2: include camera control values
- libcamera: store all applied controls
- libcamera: use `device_option_is_equal`
This commit is contained in:
Kamil Trzcinski
2023-06-01 23:42:18 +02:00
parent 8df8dcf2e5
commit 899f2c5e62
18 changed files with 800 additions and 163 deletions

View File

@ -38,8 +38,8 @@ camera_options_t camera_options = {
"video_bitrate=2000000" OPTION_VALUE_LIST_SEP
"repeat_sequence_header=5000000" OPTION_VALUE_LIST_SEP
"h264_i_frame_period=30" OPTION_VALUE_LIST_SEP
"h264_level=11" OPTION_VALUE_LIST_SEP
"h264_profile=4" OPTION_VALUE_LIST_SEP
"h264_level=4" OPTION_VALUE_LIST_SEP
"h264_profile=high" OPTION_VALUE_LIST_SEP
"h264_minimum_qp_value=16" OPTION_VALUE_LIST_SEP
"h264_maximum_qp_value=32"
}

View File

@ -2,12 +2,14 @@ extern "C" {
#include "util/http/http.h"
#include "util/opts/fourcc.h"
#include "util/opts/control.h"
#include "device/buffer_list.h"
#include "device/buffer_lock.h"
#include "device/camera/camera.h"
#include "output/rtsp/rtsp.h"
#include "output/webrtc/webrtc.h"
#include "output/output.h"
#include "version.h"
extern camera_t *camera;
extern http_server_options_t http_options;
@ -17,6 +19,7 @@ extern webrtc_options_t webrtc_options;
};
#include <nlohmann/json.hpp>
#include "third_party/magic_enum/include/magic_enum.hpp"
static nlohmann::json serialize_buf_list(buffer_list_t *buf_list)
{
@ -53,6 +56,48 @@ static nlohmann::json serialize_buf_lock(buffer_lock_t *buf_lock)
return output;
}
static const char *strip_prefix(const char *str, const char *prefix)
{
if (strstr(str, prefix) == str) {
return str + strlen(prefix);
}
return str;
}
static std::string std_device_option_normalize(std::string key)
{
key.resize(device_option_normalize_name(key.data(), key.data()));
return key;
}
static int device_options_callback(device_option_t *option, void *opaque)
{
auto key = std_device_option_normalize(option->name);
nlohmann::json &device = *(nlohmann::json*)opaque;
nlohmann::json &node = option->flags.read_only ?
device["properties"][key] :
device["options"][key];
node["name"] = option->name;
node["type"] = strip_prefix(
std::string(magic_enum::enum_name(option->type)).c_str(),
"device_option_type_");
if (option->elems > 0)
node["elems"] = option->elems;
if (option->description[0])
node["description"] = option->description;
if (option->value[0])
node["value"] = option->value;
for (int i = 0; i < option->menu_items; i++) {
char buf[64];
sprintf(buf, "%d", option->menu[i].id);
node["menu"][buf] = option->menu[i].name;
}
return 0;
}
static nlohmann::json devices_status_json()
{
nlohmann::json devices;
@ -70,6 +115,8 @@ static nlohmann::json devices_status_json()
for (int j = 0; j < device->n_capture_list; j++) {
device_json["captures"][j] = serialize_buf_list(device->capture_lists[j]);
}
device_dump_options2(device, device_options_callback, &device_json);
devices += device_json;
}
@ -122,6 +169,9 @@ extern "C" void camera_status_json(http_worker_t *worker, FILE *stream)
{
nlohmann::json message;
message["version"] = GIT_VERSION;
message["revision"] = GIT_REVISION;
message["outputs"]["snapshot"] = serialize_buf_lock(&snapshot_lock);
message["outputs"]["stream"] = serialize_buf_lock(&stream_lock);
message["outputs"]["video"] = serialize_buf_lock(&video_lock);