2 * Media controller interface library
4 * Copyright (C) 2010-2011 Ideas on board SPRL
6 * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <linux/media.h>
28 struct media_pad *source;
29 struct media_pad *sink;
30 struct media_link *twin;
36 struct media_entity *entity;
43 struct media_device *media;
44 struct media_entity_desc info;
45 struct media_pad *pads;
46 struct media_link *links;
47 unsigned int max_links;
48 unsigned int num_links;
59 struct media_device_info info;
60 struct media_entity *entities;
61 unsigned int entities_count;
62 void (*debug_handler)(void *, ...);
67 #define media_dbg(media, ...) \
68 (media)->debug_handler((media)->debug_priv, __VA_ARGS__)
71 * @brief Create a new media device.
72 * @param devnode - device node path.
74 * Create a media device instance for the given device node and return it. The
75 * device node is not accessed by this function, device node access errors will
76 * not be caught and reported here. The media device needs to be enumerated
77 * before it can be accessed, see media_device_enumerate().
79 * Media devices are reference-counted, see media_device_ref() and
80 * media_device_unref() for more information.
82 * @return A pointer to the new media device or NULL if memory cannot be
85 struct media_device *media_device_new(const char *devnode);
88 * @brief Take a reference to the device.
89 * @param media - device instance.
91 * Media devices are reference-counted. Taking a reference to a device prevents
92 * it from being freed until all references are released. The reference count is
93 * initialized to 1 when the device is created.
95 * @return A pointer to @a media.
97 struct media_device *media_device_ref(struct media_device *media);
100 * @brief Release a reference to the device.
101 * @param media - device instance.
103 * Release a reference to the media device. When the reference count reaches 0
104 * this function frees the device.
106 void media_device_unref(struct media_device *media);
109 * @brief Set a handler for debug messages.
110 * @param media - device instance.
111 * @param debug_handler - debug message handler
112 * @param debug_priv - first argument to debug message handler
114 * Set a handler for debug messages that will be called whenever
115 * debugging information is to be printed. The handler expects an
116 * fprintf-like function.
118 void media_debug_set_handler(
119 struct media_device *media, void (*debug_handler)(void *, ...),
123 * @brief Enumerate the device topology
124 * @param media - device instance.
126 * Enumerate the media device entities, pads and links. Calling this function is
127 * mandatory before accessing the media device contents.
129 * @return Zero on success or a negative error code on failure.
131 int media_device_enumerate(struct media_device *media);
134 * @brief Locate the pad at the other end of a link.
135 * @param pad - sink pad at one end of the link.
137 * Locate the source pad connected to @a pad through an enabled link. As only one
138 * link connected to a sink pad can be enabled at a time, the connected source
139 * pad is guaranteed to be unique.
141 * @return A pointer to the connected source pad, or NULL if all links connected
142 * to @a pad are disabled. Return NULL also if @a pad is not a sink pad.
144 struct media_pad *media_entity_remote_source(struct media_pad *pad);
147 * @brief Get the type of an entity.
148 * @param entity - the entity.
150 * @return The type of @a entity.
152 static inline unsigned int media_entity_type(struct media_entity *entity)
154 return entity->info.type & MEDIA_ENT_TYPE_MASK;
158 * @brief Find an entity by its name.
159 * @param media - media device.
160 * @param name - entity name.
161 * @param length - size of @a name.
163 * Search for an entity with a name equal to @a name.
165 * @return A pointer to the entity if found, or NULL otherwise.
167 struct media_entity *media_get_entity_by_name(struct media_device *media,
168 const char *name, size_t length);
171 * @brief Find an entity by its ID.
172 * @param media - media device.
173 * @param id - entity ID.
175 * This function searches for an entity based on its ID using an exact match or
176 * next ID method based on the given @a id. If @a id is ORed with
177 * MEDIA_ENT_ID_FLAG_NEXT, the function will return the entity with the smallest
178 * ID larger than @a id. Otherwise it will return the entity with an ID equal to
181 * @return A pointer to the entity if found, or NULL otherwise.
183 struct media_entity *media_get_entity_by_id(struct media_device *media,
187 * @brief Configure a link.
188 * @param media - media device.
189 * @param source - source pad at the link origin.
190 * @param sink - sink pad at the link target.
191 * @param flags - configuration flags.
193 * Locate the link between @a source and @a sink, and configure it by applying
196 * Only the MEDIA_LINK_FLAG_ENABLED flag is writable.
198 * @return 0 on success, -1 on failure:
199 * -ENOENT: link not found
200 * - other error codes returned by MEDIA_IOC_SETUP_LINK
202 int media_setup_link(struct media_device *media,
203 struct media_pad *source, struct media_pad *sink,
207 * @brief Reset all links to the disabled state.
208 * @param media - media device.
210 * Disable all links in the media device. This function is usually used after
211 * opening a media device to reset all links to a known state.
213 * @return 0 on success, or a negative error code on failure.
215 int media_reset_links(struct media_device *media);
218 * @brief Parse string to a pad on the media device.
219 * @param media - media device.
220 * @param p - input string
221 * @param endp - pointer to string where parsing ended
223 * Parse NULL terminated string describing a pad and return its struct
224 * media_pad instance.
226 * @return Pointer to struct media_pad on success, NULL on failure.
228 struct media_pad *media_parse_pad(struct media_device *media,
229 const char *p, char **endp);
232 * @brief Parse string to a link on the media device.
233 * @param media - media device.
234 * @param p - input string
235 * @param endp - pointer to p where parsing ended
237 * Parse NULL terminated string p describing a link and return its struct
238 * media_link instance.
240 * @return Pointer to struct media_link on success, NULL on failure.
242 struct media_link *media_parse_link(struct media_device *media,
243 const char *p, char **endp);
246 * @brief Parse string to a link on the media device and set it up.
247 * @param media - media device.
248 * @param p - input string
250 * Parse NULL terminated string p describing a link and its configuration
251 * and configure the link.
253 * @return 0 on success, or a negative error code on failure.
255 int media_parse_setup_link(struct media_device *media,
256 const char *p, char **endp);
259 * @brief Parse string to link(s) on the media device and set it up.
260 * @param media - media device.
261 * @param p - input string
263 * Parse NULL terminated string p describing link(s) separated by
264 * commas (,) and configure the link(s).
266 * @return 0 on success, or a negative error code on failure.
268 int media_parse_setup_links(struct media_device *media, const char *p);