Fix MEDIA_LNK_FL_* and MEDIA_PAD_FL_* visibility in CLI translation unit
The CLI is a separate translation unit that doesn't include <linux/media.h>,
so the kernel flag constants were undefined there. Fix by defining our own
public constants in media_ctrl.h:
- MEDIA_LINK_FL_{ENABLED,IMMUTABLE,DYNAMIC} for link flags
- MEDIA_PAD_FLAG_{SINK,SOURCE} for pad flags (distinct names avoid
redefinition conflict with kernel's MEDIA_PAD_FL_* in media_ctrl.c)
media_ctrl.c now translates kernel flags to our constants on the way out.
Added fallback #defines for kernel constants that were missing them.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -91,8 +91,8 @@ static void on_pad(const struct Media_Pad *pad, void *userdata) {
|
||||
|
||||
static void on_link(const struct Media_Link *link, void *userdata) {
|
||||
(void)userdata;
|
||||
const char *enabled = (link->flags & MEDIA_LNK_FL_ENABLED) ? "enabled" : "disabled";
|
||||
const char *mutable = (link->flags & MEDIA_LNK_FL_IMMUTABLE) ? ", immutable" : "";
|
||||
const char *enabled = (link->flags & MEDIA_LINK_FL_ENABLED) ? "enabled" : "disabled";
|
||||
const char *mutable = (link->flags & MEDIA_LINK_FL_IMMUTABLE) ? ", immutable" : "";
|
||||
printf(" link: entity %u pad %u -> entity %u pad %u [%s%s]\n",
|
||||
link->source.entity_id, link->source.index,
|
||||
link->sink.entity_id, link->sink.index,
|
||||
|
||||
@@ -33,10 +33,19 @@ struct Media_Pad {
|
||||
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; /* MEDIA_LNK_FL_ENABLED, MEDIA_LNK_FL_IMMUTABLE */
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -35,18 +35,26 @@
|
||||
|
||||
#ifndef MEDIA_LNK_FL_ENABLED
|
||||
# warning "MEDIA_LNK_FL_ENABLED not defined"
|
||||
# define MEDIA_LNK_FL_ENABLED (1 << 0)
|
||||
#endif
|
||||
|
||||
#ifndef MEDIA_LNK_FL_IMMUTABLE
|
||||
# warning "MEDIA_LNK_FL_IMMUTABLE not defined"
|
||||
# define MEDIA_LNK_FL_IMMUTABLE (1 << 1)
|
||||
#endif
|
||||
|
||||
#ifndef MEDIA_LNK_FL_DYNAMIC
|
||||
# define MEDIA_LNK_FL_DYNAMIC (1 << 2)
|
||||
#endif
|
||||
|
||||
#ifndef MEDIA_PAD_FL_SOURCE
|
||||
# warning "MEDIA_PAD_FL_SOURCE not defined"
|
||||
# warning "MEDIA_PAD_FL_SOURCE not defined — pad direction detection will not work"
|
||||
# define MEDIA_PAD_FL_SOURCE (1 << 1)
|
||||
#endif
|
||||
|
||||
#ifndef MEDIA_PAD_FL_SINK
|
||||
# warning "MEDIA_PAD_FL_SINK not defined"
|
||||
# warning "MEDIA_PAD_FL_SINK not defined — pad direction detection will not work"
|
||||
# define MEDIA_PAD_FL_SINK (1 << 0)
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
@@ -217,7 +225,9 @@ struct App_Error media_ctrl_enum_entity_pads_and_links(
|
||||
struct Media_Pad pad;
|
||||
pad.entity_id = pads[i].entity;
|
||||
pad.index = pads[i].index;
|
||||
pad.flags = pads[i].flags;
|
||||
pad.flags = 0;
|
||||
if (pads[i].flags & MEDIA_PAD_FL_SINK) { pad.flags |= MEDIA_PAD_FLAG_SINK; }
|
||||
if (pads[i].flags & MEDIA_PAD_FL_SOURCE) { pad.flags |= MEDIA_PAD_FLAG_SOURCE; }
|
||||
pad_callback(&pad, userdata);
|
||||
}
|
||||
}
|
||||
@@ -231,7 +241,11 @@ struct App_Error media_ctrl_enum_entity_pads_and_links(
|
||||
link.sink.entity_id = links[i].sink.entity;
|
||||
link.sink.index = links[i].sink.index;
|
||||
link.sink.flags = links[i].sink.flags;
|
||||
link.flags = links[i].flags;
|
||||
/* Translate kernel flags to our own constants */
|
||||
link.flags = 0;
|
||||
if (links[i].flags & MEDIA_LNK_FL_ENABLED) { link.flags |= MEDIA_LINK_FL_ENABLED; }
|
||||
if (links[i].flags & MEDIA_LNK_FL_IMMUTABLE) { link.flags |= MEDIA_LINK_FL_IMMUTABLE; }
|
||||
if (links[i].flags & MEDIA_LNK_FL_DYNAMIC) { link.flags |= MEDIA_LINK_FL_DYNAMIC; }
|
||||
link_callback(&link, userdata);
|
||||
}
|
||||
}
|
||||
@@ -255,7 +269,7 @@ struct App_Error media_ctrl_set_link(
|
||||
desc.source.index = source_pad_index;
|
||||
desc.sink.entity = sink_entity_id;
|
||||
desc.sink.index = sink_pad_index;
|
||||
desc.flags = enabled ? MEDIA_LNK_FL_ENABLED : 0;
|
||||
desc.flags = enabled ? MEDIA_LNK_FL_ENABLED : 0; /* kernel constant, internal use only */
|
||||
|
||||
if (ioctl(ctrl->fd, MEDIA_IOC_SETUP_LINK, &desc) < 0) {
|
||||
return APP_SYSCALL_ERROR();
|
||||
@@ -273,10 +287,10 @@ const char *media_entity_type_name(uint32_t type) {
|
||||
}
|
||||
|
||||
const char *media_pad_flag_name(uint32_t flags) {
|
||||
if (flags & MEDIA_PAD_FL_SOURCE) {
|
||||
if (flags & MEDIA_PAD_FLAG_SOURCE) {
|
||||
return "source";
|
||||
}
|
||||
if (flags & MEDIA_PAD_FL_SINK) {
|
||||
if (flags & MEDIA_PAD_FLAG_SINK) {
|
||||
return "sink";
|
||||
}
|
||||
return "unknown";
|
||||
|
||||
Reference in New Issue
Block a user