2 * Media controller test application
4 * Copyright (C) 2010 Ideas on board SPRL <laurent.pinchart@ideasonboard.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
23 #include <linux/media.h>
26 struct media_pad *source;
27 struct media_pad *sink;
28 struct media_link *twin;
34 struct media_entity *entity;
41 struct media_entity_desc info;
42 struct media_pad *pads;
43 struct media_link *links;
44 unsigned int max_links;
45 unsigned int num_links;
54 struct media_entity *entities;
55 unsigned int entities_count;
60 * @brief Open a media device.
61 * @param name - name (including path) of the device node.
62 * @param verbose - whether to print verbose information on the standard output.
64 * Open the media device referenced by @a name and enumerate entities, pads and
67 * @return A pointer to a newly allocated media_device structure instance on
68 * success and NULL on failure. The returned pointer must be freed with
69 * media_close when the device isn't needed anymore.
71 struct media_device *media_open(const char *name, int verbose);
74 * @brief Close a media device.
75 * @param media - device instance.
77 * Close the @a media device instance and free allocated resources. Access to the
78 * device instance is forbidden after this function returns.
80 void media_close(struct media_device *media);
83 * @brief Locate the pad at the other end of a link.
84 * @param pad - sink pad at one end of the link.
86 * Locate the source pad connected to @a pad through an enabled link. As only one
87 * link connected to a sink pad can be enabled at a time, the connected source
88 * pad is guaranteed to be unique.
90 * @return A pointer to the connected source pad, or NULL if all links connected
91 * to @a pad are disabled. Return NULL also if @a pad is not a sink pad.
93 struct media_pad *media_entity_remote_source(struct media_pad *pad);
96 * @brief Get the type of an entity.
97 * @param entity - the entity.
99 * @return The type of @a entity.
101 static inline unsigned int media_entity_type(struct media_entity *entity)
103 return entity->info.type & MEDIA_ENT_TYPE_MASK;
107 * @brief Find an entity by its name.
108 * @param media - media device.
109 * @param name - entity name.
110 * @param length - size of @a name.
112 * Search for an entity with a name equal to @a name.
114 * @return A pointer to the entity if found, or NULL otherwise.
116 struct media_entity *media_get_entity_by_name(struct media_device *media,
117 const char *name, size_t length);
120 * @brief Find an entity by its ID.
121 * @param media - media device.
122 * @param id - entity ID.
124 * Search for an entity with an ID equal to @a id.
126 * @return A pointer to the entity if found, or NULL otherwise.
128 struct media_entity *media_get_entity_by_id(struct media_device *media,
132 * @brief Configure a link.
133 * @param media - media device.
134 * @param source - source pad at the link origin.
135 * @param sink - sink pad at the link target.
136 * @param flags - configuration flags.
138 * Locate the link between @a source and @a sink, and configure it by applying
141 * Only the MEDIA_LINK_FLAG_ENABLED flag is writable.
143 * @return 0 on success, -1 on failure:
144 * -ENOENT: link not found
145 * - other error codes returned by MEDIA_IOC_SETUP_LINK
147 int media_setup_link(struct media_device *media,
148 struct media_pad *source, struct media_pad *sink,
152 * @brief Reset all links to the disabled state.
153 * @param media - media device.
155 * Disable all links in the media device. This function is usually used after
156 * opening a media device to reset all links to a known state.
158 * @return 0 on success, or a negative error code on failure.
160 int media_reset_links(struct media_device *media);
163 * @brief Parse string to a pad on the media device.
164 * @param media - media device.
165 * @param p - input string
166 * @param endp - pointer to string where parsing ended
168 * Parse NULL terminated string describing a pad and return its struct
169 * media_pad instance.
171 * @return Pointer to struct media_pad on success, NULL on failure.
173 struct media_pad *media_parse_pad(struct media_device *media,
174 const char *p, char **endp);
177 * @brief Parse string to a link on the media device.
178 * @param media - media device.
179 * @param p - input string
180 * @param endp - pointer to p where parsing ended
182 * Parse NULL terminated string p describing a link and return its struct
183 * media_link instance.
185 * @return Pointer to struct media_link on success, NULL on failure.
187 struct media_link *media_parse_link(struct media_device *media,
188 const char *p, char **endp);
191 * @brief Parse string to a link on the media device and set it up.
192 * @param media - media device.
193 * @param p - input string
195 * Parse NULL terminated string p describing a link and its configuration
196 * and configure the link.
198 * @return 0 on success, or a negative error code on failure.
200 int media_parse_setup_link(struct media_device *media,
201 const char *p, char **endp);
204 * @brief Parse string to link(s) on the media device and set it up.
205 * @param media - media device.
206 * @param p - input string
208 * Parse NULL terminated string p describing link(s) separated by
209 * commas (,) and configure the link(s).
211 * @return 0 on success, or a negative error code on failure.
213 int media_parse_setup_links(struct media_device *media, const char *p);