uvcsink: configfs.{c,h}: add helper function to parse by videodev

- add helper function video_find_config_name
- add helper function configfs_parse_uvc_videodev

With these helper functions it is possible to parse the
configfs entry corresponding to the used videodev.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1304>
This commit is contained in:
Michael Grzeschik 2023-05-09 00:50:41 +02:00 committed by GStreamer Marge Bot
parent 079fc8216c
commit 6ef14df09b
2 changed files with 52 additions and 0 deletions

View file

@ -945,3 +945,52 @@ done:
return fc;
}
static char *
video_find_config_name (const char *video)
{
char *vpath;
glob_t globbuf;
char *config;
int ret;
ret = asprintf (&vpath,
"/sys/class/udc/*/device/gadget*/video4linux/%s", video ? video : "*");
if (!ret)
return NULL;
glob (vpath, 0, NULL, &globbuf);
free (vpath);
if (globbuf.gl_pathc != 1)
return NULL;
config = attribute_read_str (globbuf.gl_pathv[0], "function_name");
globfree (&globbuf);
return config;
}
struct uvc_function_config *
configfs_parse_uvc_videodev (int fd, const char *video)
{
struct uvc_function_config *fc;
char *function = NULL;
char rpath[PATH_MAX];
char *res;
res = realpath (video, rpath);
if (!res)
return NULL;
function = video_find_config_name (basename (rpath));
if (!function)
return NULL;
fc = configfs_parse_uvc_function (function);
free (function);
return fc;
}

View file

@ -113,4 +113,7 @@ struct uvc_function_config
struct uvc_function_config *configfs_parse_uvc_function (const char *function);
void configfs_free_uvc_function (struct uvc_function_config *fc);
struct uvc_function_config *configfs_parse_uvc_videodev (int fd,
const char *video);
#endif