From 5d751cc0b289282d354f7701a1ff896cc0778be8 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 31 Jul 2012 15:31:55 +0200 Subject: Expose default devices Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus Acked-by: Hans Verkuil --- src/mediactl-priv.h | 7 +++++++ src/mediactl.c | 32 ++++++++++++++++++++++++++++++++ src/mediactl.h | 19 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/mediactl-priv.h b/src/mediactl-priv.h index 37e60aa..4644165 100644 --- a/src/mediactl-priv.h +++ b/src/mediactl-priv.h @@ -49,6 +49,13 @@ struct media_device { void (*debug_handler)(void *, ...); void *debug_priv; + + struct { + struct media_entity *v4l; + struct media_entity *fb; + struct media_entity *alsa; + struct media_entity *dvb; + } def; }; #define media_dbg(media, ...) \ diff --git a/src/mediactl.c b/src/mediactl.c index dd5bd57..4da334a 100644 --- a/src/mediactl.c +++ b/src/mediactl.c @@ -145,6 +145,21 @@ const char *media_entity_get_devname(struct media_entity *entity) return entity->devname[0] ? entity->devname : NULL; } +struct media_entity *media_get_default_entity(struct media_device *media, + unsigned int type) +{ + switch (type) { + case MEDIA_ENT_T_DEVNODE_V4L: + return media->def.v4l; + case MEDIA_ENT_T_DEVNODE_FB: + return media->def.fb; + case MEDIA_ENT_T_DEVNODE_ALSA: + return media->def.alsa; + case MEDIA_ENT_T_DEVNODE_DVB: + return media->def.dvb; + } +} + const struct media_device_info *media_get_info(struct media_device *media) { return &media->info; @@ -519,6 +534,23 @@ static int media_enum_entities(struct media_device *media) media->entities_count++; + if (entity->info.flags & MEDIA_ENT_FL_DEFAULT) { + switch (entity->info.type) { + case MEDIA_ENT_T_DEVNODE_V4L: + media->def.v4l = entity; + break; + case MEDIA_ENT_T_DEVNODE_FB: + media->def.fb = entity; + break; + case MEDIA_ENT_T_DEVNODE_ALSA: + media->def.alsa = entity; + break; + case MEDIA_ENT_T_DEVNODE_DVB: + media->def.dvb = entity; + break; + } + } + /* Find the corresponding device name. */ if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE && media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV) diff --git a/src/mediactl.h b/src/mediactl.h index e2c93b8..b74be0b 100644 --- a/src/mediactl.h +++ b/src/mediactl.h @@ -243,6 +243,25 @@ unsigned int media_get_entities_count(struct media_device *media); */ struct media_entity *media_get_entity(struct media_device *media, unsigned int index); +/** + * @brief Get the default entity for a given type + * @param media - media device. + * @param type - entity type. + * + * This function returns the default entity of the requested type. @a type must + * be one of + * + * MEDIA_ENT_T_DEVNODE_V4L + * MEDIA_ENT_T_DEVNODE_FB + * MEDIA_ENT_T_DEVNODE_ALSA + * MEDIA_ENT_T_DEVNODE_DVB + * + * @return A pointer to the default entity for the type if it exists, or NULL + * otherwise. + */ +struct media_entity *media_get_default_entity(struct media_device *media, + unsigned int type); + /** * @brief Get the media device information * @param media - media device. -- cgit v1.2.3