#pragma once #include #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 */ }; /* Link flags for Media_Link.flags */ #define MEDIA_LINK_FL_ENABLED (1u << 0) #define MEDIA_LINK_FL_IMMUTABLE (1u << 1) #define MEDIA_LINK_FL_DYNAMIC (1u << 2) /* Pad flags for Media_Pad.flags */ #define MEDIA_PAD_FLAG_SINK (1u << 0) #define MEDIA_PAD_FLAG_SOURCE (1u << 1) struct Media_Link { struct Media_Pad source; struct Media_Pad sink; uint32_t flags; }; /* * 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);