Expose default devices
[media-ctl.git] / src / mediactl.c
index 304e185..4da334a 100644 (file)
@@ -111,9 +111,53 @@ unsigned int media_get_entities_count(struct media_device *media)
        return media->entities_count;
 }
 
-struct media_entity *media_get_entities(struct media_device *media)
+struct media_entity *media_get_entity(struct media_device *media, unsigned int index)
 {
-       return media->entities;
+       if (index >= media->entities_count)
+               return NULL;
+
+       return &media->entities[index];
+}
+
+const struct media_pad *media_entity_get_pad(struct media_entity *entity, unsigned int index)
+{
+       if (index >= entity->info.pads)
+               return NULL;
+
+       return &entity->pads[index];
+}
+
+unsigned int media_entity_get_links_count(struct media_entity *entity)
+{
+       return entity->num_links;
+}
+
+const struct media_link *media_entity_get_link(struct media_entity *entity, unsigned int index)
+{
+       if (index >= entity->num_links)
+               return NULL;
+
+       return &entity->links[index];
+}
+
+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)
@@ -126,6 +170,11 @@ const char *media_get_devnode(struct media_device *media)
        return media->devnode;
 }
 
+const struct media_entity_desc *media_entity_get_info(struct media_entity *entity)
+{
+       return &entity->info;
+}
+
 /* -----------------------------------------------------------------------------
  * Open/close
  */
@@ -485,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)