Expose default devices
[media-ctl.git] / src / mediactl.c
index 2b054e9..4da334a 100644 (file)
 #include <linux/videodev2.h>
 
 #include "mediactl.h"
+#include "mediactl-priv.h"
 #include "tools.h"
 
+/* -----------------------------------------------------------------------------
+ * Graph access
+ */
+
 struct media_pad *media_entity_remote_source(struct media_pad *pad)
 {
        unsigned int i;
@@ -101,6 +106,75 @@ struct media_entity *media_get_entity_by_id(struct media_device *media,
        return NULL;
 }
 
+unsigned int media_get_entities_count(struct media_device *media)
+{
+       return media->entities_count;
+}
+
+struct media_entity *media_get_entity(struct media_device *media, unsigned int index)
+{
+       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)
+{
+       return &media->info;
+}
+
+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
  */
@@ -222,6 +296,10 @@ int media_reset_links(struct media_device *media)
        return 0;
 }
 
+/* -----------------------------------------------------------------------------
+ * Entities, pads and links enumeration
+ */
+
 static struct media_link *media_entity_add_link(struct media_entity *entity)
 {
        if (entity->num_links >= entity->max_links) {
@@ -456,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)