Add common, media_ctrl and v4l2_ctrl modules with CLI drivers and docs

Modules (src/modules/):
- common/error: App_Error struct with structured detail union, error codes,
  app_error_print(); designed for future upgrade to preprocessor-generated
  location codes
- media_ctrl: media device enumeration, topology query (entities/pads/links),
  link enable/disable via Media Controller API (/dev/media*)
- v4l2_ctrl: control enumeration (with menu item fetching), get/set via
  V4L2 ext controls API, device discovery (/dev/video*)

All modules use -std=c11 -D_GNU_SOURCE, build artifacts go to build/ only.
Kernel-version-dependent constants guarded with #ifdef + #warning.

CLI drivers (dev/cli/):
- media_ctrl_cli: list, info, topology, set-link subcommands
- v4l2_ctrl_cli: list, controls, get, set subcommands

Docs (docs/cli/):
- media_ctrl_cli.md and v4l2_ctrl_cli.md with usage, examples, and
  context within the video routing system

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-25 21:40:37 +00:00
parent bf18054a2c
commit a29c556851
17 changed files with 1650 additions and 1 deletions

90
include/media_ctrl.h Normal file
View File

@@ -0,0 +1,90 @@
#pragma once
#include <stdint.h>
#include "error.h"
/* Opaque handle — defined in media_ctrl.c */
struct Media_Ctrl;
struct Media_Device_Info {
char driver[16];
char model[32];
char serial[40];
char bus_info[32];
uint32_t media_version;
uint32_t hw_revision;
uint32_t driver_version;
};
struct Media_Entity {
uint32_t id;
char name[32];
uint32_t type; /* MEDIA_ENT_F_* value from kernel */
uint32_t flags;
uint16_t pad_count;
uint16_t link_count;
uint32_t dev_major; /* associated device node major, 0 if none */
uint32_t dev_minor;
};
struct Media_Pad {
uint32_t entity_id;
uint16_t index;
uint32_t flags; /* MEDIA_PAD_FL_SINK / MEDIA_PAD_FL_SOURCE */
};
struct Media_Link {
struct Media_Pad source;
struct Media_Pad sink;
uint32_t flags; /* MEDIA_LNK_FL_ENABLED, MEDIA_LNK_FL_IMMUTABLE */
};
/*
* Enumerate all /dev/media* device nodes present on the system.
* Calls callback once per device path found.
*/
struct App_Error media_ctrl_find_devices(
void (*callback)(const char *device_path, void *userdata),
void *userdata);
struct App_Error media_ctrl_open(const char *device_path, struct Media_Ctrl **out);
void media_ctrl_close(struct Media_Ctrl *ctrl);
struct App_Error media_ctrl_get_info(
struct Media_Ctrl *ctrl,
struct Media_Device_Info *out);
/*
* Enumerate all entities in the media graph.
*/
struct App_Error media_ctrl_enum_entities(
struct Media_Ctrl *ctrl,
void (*callback)(const struct Media_Entity *entity, void *userdata),
void *userdata);
/*
* Enumerate pads and links for a specific entity.
* Pass the entity struct obtained from media_ctrl_enum_entities —
* the pad and link counts are taken from it.
* Either callback may be NULL if that information is not needed.
*/
struct App_Error media_ctrl_enum_entity_pads_and_links(
struct Media_Ctrl *ctrl,
const struct Media_Entity *entity,
void (*pad_callback)(const struct Media_Pad *pad, void *userdata),
void (*link_callback)(const struct Media_Link *link, void *userdata),
void *userdata);
/*
* Enable or disable a link between two pads.
* Immutable links cannot be changed and will return an error.
*/
struct App_Error media_ctrl_set_link(
struct Media_Ctrl *ctrl,
uint32_t source_entity_id, uint16_t source_pad_index,
uint32_t sink_entity_id, uint16_t sink_pad_index,
int enabled);
/* Human-readable names for display */
const char *media_entity_type_name(uint32_t type);
const char *media_pad_flag_name(uint32_t flags);