diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2010-06-14 22:57:45 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2010-06-14 22:57:45 +0200 |
commit | 0c4da2bb2f4d7d3cd2cdea1369374d5b4f7e3b29 (patch) | |
tree | a55b8de0b6c5271062733cb0377732487918ac44 | |
parent | 25ed35b7c2705f53471118437a538bc9a60701be (diff) |
Enumerate entities using MEDIA_ENTITY_ID_FLAG_NEXT
Entity IDs don't have to be contiguous. Use the new flag-based
enumeration system instead of looping over consecutive IDs.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r-- | main.c | 7 | ||||
-rw-r--r-- | media.c | 42 | ||||
-rw-r--r-- | media.h | 2 |
3 files changed, 37 insertions, 14 deletions
@@ -63,11 +63,10 @@ static struct media_entity_pad *parse_pad(struct media_device *media, const char for (++end; isspace(*end); ++end); } else { - entity_id = strtoul(p, &end, 10) - 1; - if (entity_id >= media->entities_count) + entity_id = strtoul(p, &end, 10); + entity = media_get_entity_by_id(media, entity_id); + if (entity == NULL) return NULL; - - entity = &media->entities[entity_id]; } if (*end != ':') @@ -130,7 +130,7 @@ struct media_entity_pad *media_entity_remote_pad(struct media_entity_pad *pad) } /* - * media_entity_by_name - + * media_get_entity_by_name - */ struct media_entity *media_get_entity_by_name(struct media_device *media, const char *name, size_t length) @@ -148,6 +148,24 @@ struct media_entity *media_get_entity_by_name(struct media_device *media, } /* + * media_get_entity_by_id - + */ +struct media_entity *media_get_entity_by_id(struct media_device *media, + __u32 id) +{ + unsigned int i; + + for (i = 0; i < media->entities_count; ++i) { + struct media_entity *entity = &media->entities[i]; + + if (entity->info.id == id) + return entity; + } + + return NULL; +} + +/* * media_setup_link - */ int media_setup_link(struct media_device *media, @@ -393,16 +411,16 @@ static int media_enum_links(struct media_device *media) struct media_entity *source; struct media_entity *sink; - if (link->source.entity > media->entities_count || - link->sink.entity > media->entities_count) { + source = media_get_entity_by_id(media, link->source.entity); + sink = media_get_entity_by_id(media, link->sink.entity); + + if (source == NULL || sink == NULL) { printf("WARNING entity %u link %u from %u/%u to %u/%u is invalid!\n", id, i, link->source.entity, link->source.index, link->sink.entity, link->sink.index); ret = -EINVAL; } - source = &media->entities[link->source.entity - 1]; - sink = &media->entities[link->sink.entity - 1]; entity->links[i].source = &source->pads[link->source.index]; entity->links[i].sink = &sink->pads[link->sink.index]; entity->links[i].flags = links.links[i].flags; @@ -420,17 +438,19 @@ static int media_enum_entities(struct media_device *media) struct media_entity *entity; struct stat devstat; char devname[32]; + unsigned int size; unsigned int i; __u32 id; int ret; - for (id = 1; ; id++) { - media->entities = - realloc(media->entities, id * sizeof(*media->entities)); - entity = &media->entities[id - 1]; + for (id = 0; ; id = entity->info.id) { + size = (media->entities_count + 1) * sizeof(*media->entities); + media->entities = realloc(media->entities, size); + + entity = &media->entities[media->entities_count]; memset(entity, 0, sizeof(*entity)); entity->fd = -1; - entity->info.id = id; + entity->info.id = id | MEDIA_ENTITY_ID_FLAG_NEXT; ret = ioctl(media->fd, MEDIA_IOC_ENUM_ENTITIES, &entity->info); if (ret < 0) { @@ -468,6 +488,8 @@ static int media_enum_entities(struct media_device *media) break; } } + + id = entity->info.id; } return 0; @@ -56,6 +56,8 @@ struct media_entity_pad *media_entity_remote_pad(struct media_entity_pad *pad); struct media_entity *media_get_entity_by_name(struct media_device *media, const char *name, size_t length); +struct media_entity *media_get_entity_by_id(struct media_device *media, + __u32 id); void media_print_topology(struct media_device *media, int dot); int media_setup_link(struct media_device *media, struct media_entity_pad *source, struct media_entity_pad *sink, |