Move functionality to libraries, debug changes
cover Move functionality to libraries, debug changes
Hi,
This patchset moves the string parsing functionality to libraries from the test program, making the libraries much more useful.
Printing informative messages is also left to debug handler; the libraries won't print anything anymore. Error messages are also printed by media-ctl.
Regards,
Signature · 2 lines
Sakari Ailus e-mail: [email protected] jabber/XMPP/Gmail: [email protected]
PATCH 1/7 Rename files to match the names of the libraries
Rename media.* to mediactl.* and subdev.* v4l2subdev.*.
--- src/Makefile.am | 6 +- src/main.c | 4 +- src/media.c | 475 ------------------------------------------------------ src/media.h | 161 ------------------ src/mediactl.c | 475 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/mediactl.h | 161 ++++++++++++++++++ src/subdev.c | 188 --------------------- src/subdev.h | 162 ------------------- src/v4l2subdev.c | 188 +++++++++++++++++++++ src/v4l2subdev.h | 162 +++++++++++++++++++ 10 files changed, 991 insertions(+), 991 deletions(-) delete mode 100644 src/media.c delete mode 100644 src/media.h create mode 100644 src/mediactl.c create mode 100644 src/mediactl.h delete mode 100644 src/subdev.c delete mode 100644 src/subdev.h create mode 100644 src/v4l2subdev.c create mode 100644 src/v4l2subdev.h
src/Makefile.am +3 -3
@@ -1,8 +1,8 @@ lib_LTLIBRARIES = libmediactl.la libv4l2subdev.la -libmediactl_la_SOURCES = media.c -libv4l2subdev_la_SOURCES = subdev.c +libmediactl_la_SOURCES = mediactl.c +libv4l2subdev_la_SOURCES = v4l2subdev.c mediactl_includedir=$(includedir)/mediactl -mediactl_include_HEADERS = media.h subdev.h +mediactl_include_HEADERS = mediactl.h v4l2subdev.h bin_PROGRAMS = media-ctl media_ctl_CFLAGS = $(LIBUDEV_CFLAGS)
src/main.c +2 -2
@@ -36,9 +36,9 @@#include <linux/v4l2-subdev.h> #include <linux/videodev2.h> -#include "media.h" +#include "mediactl.h" #include "options.h" -#include "subdev.h" +#include "v4l2subdev.h" #include "tools.h" /* -----------------------------------------------------------------------------
src/media.c deleted +0 -475
475 lines not on this page · raw message
src/media.h deleted +0 -161
161 lines not on this page · raw message
src/mediactl.c new file +475 -0
475 lines not on this page · raw message
src/mediactl.h new file +161 -0
161 lines not on this page · raw message
src/subdev.c deleted +0 -188
188 lines not on this page · raw message
src/subdev.h deleted +0 -162
162 lines not on this page · raw message
src/v4l2subdev.c new file +188 -0
188 lines not on this page · raw message
src/v4l2subdev.h new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [media-ctl PATCH 1/7] Rename files to match the names of the libraries
Applied :-)
Signature · 3 lines
Regards, Laurent Pinchart
Re: [media-ctl PATCH 1/7] Rename files to match the names of the libraries
Quoted 1 line · Laurent Pinchart
Applied :-)
Thanks!
Signature · 2 lines
Sakari Ailus e-mail: [email protected] jabber/XMPP/Gmail: [email protected]
PATCH 2/7 Move link parsing from main.c to media.c, making it part of libmediactl
In reply to Sakari AilusThis makes it possible to benefit from the link parsing code anywhere the library is being used.
dprintf macro will later be replaced with proper debug support.
Also fix a case where -1 was returned on error and the user was expected to check the value of errno. Negative error codes are now returned consistently.
--- src/main.c | 139 +--------------------------------------------- src/mediactl.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++----- src/mediactl.h | 57 +++++++++++++++++++- 3 files changed, 212 insertions(+), 151 deletions(-)
src/main.c +4 -135
@@ -335,137 +335,6 @@ void media_print_topology(struct media_device *media, int dot) }/* ----------------------------------------------------------------------------- -* Links setup -*/ - -static struct media_pad *parse_pad (struct media_device *media,const char *p,char **endp) -{ -unsigned int entity_id, pad; -struct media_entity *entity; -char *end; - -for (;isspace (*p); ++p); - -if (*p =='"' ) { -for (end = (char *)p +1 ; *end && *end !='"' ; ++end); -if (*end !='"' ) -return NULL ; - - entity =media_get_entity_by_name (media, p +1 , end - p -1 ); -if (entity ==NULL ) -return NULL ; - - ++end; - }else { - entity_id =strtoul (p, &end,10 ); - entity =media_get_entity_by_id (media, entity_id); -if (entity ==NULL ) -return NULL ; - } -for (;isspace (*end); ++end); - -if (*end !=':' ) -return NULL ; -for (p = end +1 ;isspace (*p); ++p); - - pad =strtoul (p, &end,10 ); -for (p = end;isspace (*p); ++p); - -if (pad >= entity->info.pads) -return NULL ; - -for (p = end;isspace (*p); ++p); -if (endp) - *endp = (char *)p; - -return &entity->pads[pad]; -} - -static struct media_link *parse_link (struct media_device *media,const char *p,char **endp) -{ -struct media_link *link; -struct media_pad *source; -struct media_pad *sink; -unsigned int i; -char *end; - - source =parse_pad (media, p, &end); -if (source ==NULL ) -return NULL ; - -if (end[0 ] !='-' || end[1 ] !='>' ) -return NULL ; - p = end +2 ; - - sink =parse_pad (media, p, &end); -if (sink ==NULL ) -return NULL ; - - *endp = end; - -for (i =0 ; i < source->entity->num_links; i++) { - link = &source->entity->links[i]; - -if (link->source == source && link->sink == sink) -return link; - } - -return NULL ; -} - -static int setup_link (struct media_device *media,const char *p,char **endp) -{ -struct media_link *link; -__u32 flags; -char *end; - - link =parse_link (media, p, &end); -if (link ==NULL ) { -printf ("Unable to parse link\n" ); -return -EINVAL ; - } - - p = end; -if (*p++ !='[' ) { -printf ("Unable to parse link flags\n" ); -return -EINVAL ; - } - - flags =strtoul (p, &end,10 ); -for (p = end;isspace (*p); p++); -if (*p++ !=']' ) { -printf ("Unable to parse link flags\n" ); -return -EINVAL ; - } - -for (;isspace (*p); p++); - *endp = (char *)p; - -printf ("Setting up link %u:%u -> %u:%u [%u]\n" , - link->source->entity->info.id, link->source->index, - link->sink->entity->info.id, link->sink->index, - flags); - -return media_setup_link (media, link->source, link->sink, flags); -} - -static int setup_links (struct media_device *media,const char *p) -{ -char *end; -int ret; - -do { - ret =setup_link (media, p, &end); -if (ret <0 ) -return ret; - - p = end +1 ; - }while (*end ==',' ); - -return *end ? -EINVAL :0 ; -} - -/* ----------------------------------------------------------------------------- * Formats setup */
@@ -558,7 +427,7 @@ static struct media_pad *parse_pad_format(struct media_device *media,for (;isspace (*p); ++p); - pad =parse_pad (media, p, &end); + pad =media_parse_pad (media, p, &end);if (pad ==NULL )return NULL ;
@@ -775,7 +644,7 @@ int main(int argc, char **argv)if (media_opts.pad) {struct media_pad *pad; - pad =parse_pad (media, media_opts.pad,NULL ); + pad =media_parse_pad (media, media_opts.pad,NULL );if (pad ==NULL ) {printf ("Pad '%s' not found\n" , media_opts.pad); goto out;
@@ -797,7 +666,7 @@ int main(int argc, char **argv) }if (media_opts.links) -setup_links (media, media_opts.links); +media_parse_setup_links (media, media_opts.links);if (media_opts.formats)setup_formats (media, media_opts.formats);
@@ -814,7 +683,7 @@ int main(int argc, char **argv)if (buffer[0 ] =='\n' )break ; -setup_link (media, buffer, &end); +media_parse_setup_link (media, buffer, &end); } }
src/mediactl.c +152 -15
232 lines not on this page · raw message
src/mediactl.h +56 -1
68 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH 3/7 Move V4L2 subdev format parsing from main.c to subdev.c
In reply to Sakari AilusThis makes format parsing a part of the libv4l2subdev and thus available on all who use the library.
--- src/main.c | 340 +----------------------------------------------------- src/v4l2subdev.c | 343 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/v4l2subdev.h | 37 ++++++ 3 files changed, 382 insertions(+), 338 deletions(-)
src/main.c +2 -338
@@ -45,61 +45,6 @@* Printing */ -static struct { -const char *name; -enum v4l2_mbus_pixelcode code; -} mbus_formats[] = { - {"Y8" ,V4L2_MBUS_FMT_Y8_1X8 }, - {"Y10" ,V4L2_MBUS_FMT_Y10_1X10 }, - {"Y12" ,V4L2_MBUS_FMT_Y12_1X12 }, - {"YUYV" ,V4L2_MBUS_FMT_YUYV8_1X16 }, - {"UYVY" ,V4L2_MBUS_FMT_UYVY8_1X16 }, - {"SBGGR8" ,V4L2_MBUS_FMT_SBGGR8_1X8 }, - {"SGBRG8" ,V4L2_MBUS_FMT_SGBRG8_1X8 }, - {"SGRBG8" ,V4L2_MBUS_FMT_SGRBG8_1X8 }, - {"SRGGB8" ,V4L2_MBUS_FMT_SRGGB8_1X8 }, - {"SBGGR10" ,V4L2_MBUS_FMT_SBGGR10_1X10 }, - {"SGBRG10" ,V4L2_MBUS_FMT_SGBRG10_1X10 }, - {"SGRBG10" ,V4L2_MBUS_FMT_SGRBG10_1X10 }, - {"SRGGB10" ,V4L2_MBUS_FMT_SRGGB10_1X10 }, - {"SBGGR10_DPCM8" ,V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8 }, - {"SGBRG10_DPCM8" ,V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8 }, - {"SGRBG10_DPCM8" ,V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8 }, - {"SRGGB10_DPCM8" ,V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8 }, - {"SBGGR12" ,V4L2_MBUS_FMT_SBGGR12_1X12 }, - {"SGBRG12" ,V4L2_MBUS_FMT_SGBRG12_1X12 }, - {"SGRBG12" ,V4L2_MBUS_FMT_SGRBG12_1X12 }, - {"SRGGB12" ,V4L2_MBUS_FMT_SRGGB12_1X12 }, -}; - -static const char *pixelcode_to_string (enum v4l2_mbus_pixelcode code) -{ -unsigned int i; - -for (i =0 ; i <ARRAY_SIZE (mbus_formats); ++i) { -if (mbus_formats[i].code == code) -return mbus_formats[i].name; - } - -return "unknown" ; -} - -static enum v4l2_mbus_pixelcode string_to_pixelcode (const char *string, -unsigned int length) -{ -unsigned int i; - -for (i =0 ; i <ARRAY_SIZE (mbus_formats); ++i) { -if (strncmp (mbus_formats[i].name, string, length) ==0 ) -break ; - } - -if (i ==ARRAY_SIZE (mbus_formats)) -return (enum v4l2_mbus_pixelcode )-1 ; - -return mbus_formats[i].code; -} -static void v4l2_subdev_print_format (struct media_entity *entity,unsigned int pad,enum v4l2_subdev_format_whence which) {
@@ -111,7 +56,7 @@ static void v4l2_subdev_print_format(struct media_entity *entity,if (ret !=0 )return ; -printf ("[%s %ux%u" ,pixelcode_to_string (format.code), +printf ("[%s %ux%u" ,v4l2_subdev_pixelcode_to_string (format.code), format.width, format.height); ret =v4l2_subdev_get_crop (entity, &rect, pad, which);
@@ -334,287 +279,6 @@ void media_print_topology(struct media_device *media, int dot)media_print_topology_text (media); } -/* ----------------------------------------------------------------------------- -* Formats setup -*/ - -static int parse_format (struct v4l2_mbus_framefmt *format,const char *p,char **endp) -{ -enum v4l2_mbus_pixelcode code; -unsigned int width, height; -char *end; - -for (;isspace (*p); ++p); -for (end = (char *)p; !isspace (*end) && *end !='\0' ; ++end); - - code =string_to_pixelcode (p, end - p); -if (code == (enum v4l2_mbus_pixelcode )-1 ) -return -EINVAL ; - -for (p = end;isspace (*p); ++p); - width =strtoul (p, &end,10 ); -if (*end !='x' ) -return -EINVAL ; - - p = end +1 ; - height =strtoul (p, &end,10 ); - *endp = end; - -memset (format,0 ,sizeof (*format)); - format->width = width; - format->height = height; - format->code = code; - -return 0 ; -} - -static int parse_crop (struct v4l2_rect *crop,const char *p,char **endp) -{ -char *end; - -if (*p++ !='(' ) -return -EINVAL ; - - crop->left =strtoul (p, &end,10 ); -if (*end !=',' ) -return -EINVAL ; - - p = end +1 ; - crop->top =strtoul (p, &end,10 ); -if (*end++ !=')' ) -return -EINVAL ; -if (*end !='/' ) -return -EINVAL ; - - p = end +1 ; - crop->width =strtoul (p, &end,10 ); -if (*end !='x' ) -return -EINVAL ; - - p = end +1 ; - crop->height =strtoul (p, &end,10 ); - *endp = end; - -return 0 ; -} - -static int parse_frame_interval (struct v4l2_fract *interval,const char *p,char **endp) -{ -char *end; - -for (;isspace (*p); ++p); - - interval->numerator =strtoul (p, &end,10 ); - -for (p = end;isspace (*p); ++p); -if (*p++ !='/' ) -return -EINVAL ; - -for (;isspace (*p); ++p); - interval->denominator =strtoul (p, &end,10 ); - - *endp = end; -return 0 ; -} - -static struct media_pad *parse_pad_format (struct media_device *media, -struct v4l2_mbus_framefmt *format,struct v4l2_rect *crop, -struct v4l2_fract *interval,const char *p,char **endp) -{ -struct media_pad *pad; -char *end; -int ret; - -for (;isspace (*p); ++p); - - pad =media_parse_pad (media, p, &end); -if (pad ==NULL ) -return NULL ; - -for (p = end;isspace (*p); ++p); -if (*p++ !='[' ) -return NULL ; - -for (;isspace (*p); ++p); - -if (isalnum (*p)) { - ret =parse_format (format, p, &end); -if (ret <0 ) -return NULL ; - -for (p = end;isspace (*p); p++); - } - -if (*p =='(' ) { - ret =parse_crop (crop, p, &end); -if (ret <0 ) -return NULL ; - -for (p = end;isspace (*p); p++); - } - -if (*p =='@' ) { - ret =parse_frame_interval (interval, ++p, &end); -if (ret <0 ) -return NULL ; - -for (p = end;isspace (*p); p++); - } - -if (*p !=']' ) -return NULL ; - - *endp = (char *)p +1 ; -return pad; -} - -static int set_format (struct media_pad *pad,struct v4l2_mbus_framefmt *format) -{ -int ret; - -if (format->width ==0 || format->height ==0 ) -return 0 ; - -printf ("Setting up format %s %ux%u on pad %s/%u\n" , -pixelcode_to_string (format->code), format->width, format->height, - pad->entity->info.name, pad->index); - - ret =v4l2_subdev_set_format (pad->entity, format, pad->index, -V4L2_SUBDEV_FORMAT_ACTIVE ); -if (ret <0 ) { -printf ("Unable to set format: %s (%d)\n" ,strerror (-ret), ret); -return ret; - } - -printf ("Format set: %s %ux%u\n" , -pixelcode_to_string (format->code), format->width, format->height); - -return 0 ; -} - -static int set_crop (struct media_pad *pad,struct v4l2_rect *crop) -{ -int ret; - -if (crop->left ==-1 || crop->top ==-1 ) -return 0 ; - -printf ("Setting up crop rectangle (%u,%u)/%ux%u on pad %s/%u\n" , - crop->left, crop->top, crop->width, crop->height, - pad->entity->info.name, pad->index); - - ret =v4l2_subdev_set_crop (pad->entity, crop, pad->index, -V4L2_SUBDEV_FORMAT_ACTIVE ); -if (ret <0 ) { -printf ("Unable to set crop rectangle: %s (%d)\n" ,strerror (-ret), ret); -return ret; - } - -printf ("Crop rectangle set: (%u,%u)/%ux%u\n" , - crop->left, crop->top, crop->width, crop->height); - -return 0 ; -} - -static int set_frame_interval (struct media_entity *entity,struct v4l2_fract *interval) -{ -int ret; - -if (interval->numerator ==0 ) -return 0 ; - -printf ("Setting up frame interval %u/%u on entity %s\n" , - interval->numerator, interval->denominator, entity->info.name); - - ret =v4l2_subdev_set_frame_interval (entity, interval); -if (ret <0 ) { -printf ("Unable to set frame interval: %s (%d)" ,strerror (-ret), ret); -return ret; - } - -printf ("Frame interval set: %u/%u\n" , - interval->numerator, interval->denominator); - -return 0 ; -} - - -static int setup_format (struct media_device *media,const char *p,char **endp) -{ -struct v4l2_mbus_framefmt format = {0 ,0 ,0 }; -struct media_pad *pad; -struct v4l2_rect crop = {-1 ,-1 ,-1 ,-1 }; -struct v4l2_fract interval = {0 ,0 }; -unsigned int i; -char *end; -int ret; - - pad =parse_pad_format (media, &format, &crop, &interval, p, &end); -if (pad ==NULL ) { -printf ("Unable to parse format\n" ); -return -EINVAL ; - } - -if (pad->flags &MEDIA_PAD_FL_SOURCE ) { - ret =set_crop (pad, &crop); -if (ret <0 ) -return ret; - } - - ret =set_format (pad, &format); -if (ret <0 ) -return ret; - -if (pad->flags &MEDIA_PAD_FL_SINK ) { - ret =set_crop (pad, &crop); -if (ret <0 ) -return ret; - } - - ret =set_frame_interval (pad->entity, &interval); -if (ret <0 ) -return ret; - - -/* If the pad is an output pad, automatically set the same format on -* the remote subdev input pads, if any. -*/ -if (pad->flags &MEDIA_PAD_FL_SOURCE ) { -for (i =0 ; i < pad->entity->num_links; ++i) { -struct media_link *link = &pad->entity->links[i]; -struct v4l2_mbus_framefmt remote_format; - -if (!(link->flags &MEDIA_LNK_FL_ENABLED )) -continue ; - -if (link->source == pad && - link->sink->entity->info.type ==MEDIA_ENT_T_V4L2_SUBDEV ) { - remote_format = format; -set_format (link->sink, &remote_format); - } - } - } - - *endp = end; -return 0 ; -} - -static int setup_formats (struct media_device *media,const char *p) -{ -char *end; -int ret; - -do { - ret =setup_format (media, p, &end); -if (ret <0 ) -return ret; - - p = end +1 ; - }while (*end ==',' ); - -return *end ? -EINVAL :0 ; -} -int main (int argc,char **argv) {struct media_device *media;
@@ -669,7 +333,7 @@ int main(int argc, char **argv)media_parse_setup_links (media, media_opts.links);if (media_opts.formats) -setup_formats (media, media_opts.formats); +v4l2_subdev_parse_setup_formats (media, media_opts.formats);if (media_opts.interactive) {while (1 ) {
src/v4l2subdev.c +343 -0
346 lines not on this page · raw message
src/v4l2subdev.h +37 -0
@@ -158,5 +158,42 @@ int v4l2_subdev_get_frame_interval(struct media_entity *entity,int v4l2_subdev_set_frame_interval (struct media_entity *entity,struct v4l2_fract *interval); +/** +* @brief Parse a string and apply format, crop and frame interval settings. +* @param media - media device. +* @param p - input string +* @param endp - pointer to string p where parsing ended (return) +* +* Parse string @a p and apply format, crop and frame interval settings to a +* subdev pad specified in @a p. @a endp will be written a pointer where +* parsing of @a p ended. +* +* Format strings are separeted by commas (,). +* +* @return 0 on success, or a negative error code on failure. +*/ +int v4l2_subdev_parse_setup_formats (struct media_device *media,const char *p); + +/** +* @brief Convert media bus pixel code to string. +* @param code - input string +* +* Convert media bus pixel code @a code to a human-readable string. +* +* @return A pointer to a string on success, NULL on failure. +*/ +const char *v4l2_subdev_pixelcode_to_string (enum v4l2_mbus_pixelcode code); + +/** +* @brief Parse string to media bus pixel code. +* @param string - input string +* @param lenght - length of the string +* +* Parse human readable string @a string to an media bus pixel code. +* +* @return media bus pixelcode on success, -1 on failure. +*/ +enum v4l2_mbus_pixelcode v4l2_subdev_string_to_pixelcode (const char *string, +unsigned int length);#endif
Signature · 1 line
1.7.2.5
PATCH 4/7 libv4l2subdev and libmediactl are not test programs
In reply to Sakari AilusCall the libraries libraries rather than test programs.
--- src/mediactl.c | 2 +- src/mediactl.h | 2 +- src/v4l2subdev.c | 2 +- src/v4l2subdev.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
src/mediactl.c +1 -1
@@ -1,5 +1,5 @@/* -* Media controller test application +* Media controller interface library * * Copyright (C) 2010 Ideas on board SPRL <[email protected]> *
src/mediactl.h +1 -1
@@ -1,5 +1,5 @@/* -* Media controller test application +* Media controller interface library * * Copyright (C) 2010 Ideas on board SPRL <[email protected]> *
src/v4l2subdev.c +1 -1
@@ -1,5 +1,5 @@/* -* Media controller test application +* V4L2 subdev interface library * * Copyright (C) 2010 Ideas on board SPRL <[email protected]> *
src/v4l2subdev.h +1 -1
@@ -1,5 +1,5 @@/* -* Media controller test application +* V4L2 subdev interface library * * Copyright (C) 2010 Ideas on board SPRL <[email protected]> *
Signature · 1 line
1.7.2.5
PATCH 5/7 Add link to media_device from the media_entity
In reply to Sakari AilusThis makes it possible to obtain the media device an entity belongs to.
--- src/mediactl.c | 1 + src/mediactl.h | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
src/mediactl.c +1 -0
@@ -372,6 +372,7 @@ static int media_enum_entities(struct media_device *media, int verbose)memset (entity,0 ,sizeof (*entity)); entity->fd =-1 ; entity->info.id = id |MEDIA_ENT_ID_FLAG_NEXT ; + entity->media = media; ret =ioctl (media->fd,MEDIA_IOC_ENUM_ENTITIES , &entity->info);if (ret <0 ) {
src/mediactl.h +1 -0
@@ -38,6 +38,7 @@ struct media_pad { };struct media_entity { +struct media_device *media;struct media_entity_desc info;struct media_pad *pads;struct media_link *links;
Signature · 1 line
1.7.2.5
PATCH 6/7 Add debugging handler
In reply to Sakari AilusAdd debugging handler to media_device that may be used to redirect all debug formatting to user-supplied function. fprintf will do, and that's what media-ctl test program will use.
--- src/main.c | 3 +- src/mediactl.c | 105 +++++++++++++++++++++++++++++++++--------------------- src/mediactl.h | 41 +++++++++++++++++++++ src/v4l2subdev.c | 57 ++++++++++++++++++----------- 4 files changed, 142 insertions(+), 64 deletions(-)
src/main.c +2 -1
@@ -288,7 +288,8 @@ int main(int argc, char **argv)return EXIT_FAILURE ;/* Open the media device and enumerate entities, pads and links. */ - media =media_open (media_opts.devname, media_opts.verbose); + media =media_open_debug (media_opts.devname, media_opts.verbose, + (void (*)(void *, ...))fprintf, stdout);if (media ==NULL ) goto out;
src/mediactl.c +64 -41
210 lines not on this page · raw message
src/mediactl.h +41 -0
50 lines not on this page · raw message
src/v4l2subdev.c +35 -22
107 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH 7/7 Remove extra verbosity
In reply to Sakari AilusRemove extra verbosity by default; "-v" option brings back what used to be there. The error messages are now being printed by main.c with the possibly helpful error code attached.
--- src/main.c | 48 ++++++++++++++++++++++++++++++++++++++---------- src/mediactl.c | 21 ++++++++++----------- src/mediactl.h | 6 ++---- 3 files changed, 50 insertions(+), 25 deletions(-)
src/main.c +38 -10
@@ -288,10 +288,16 @@ int main(int argc, char **argv)return EXIT_FAILURE ;/* Open the media device and enumerate entities, pads and links. */ - media =media_open_debug (media_opts.devname, media_opts.verbose, - (void (*)(void *, ...))fprintf, stdout); -if (media ==NULL ) +if (media_opts.verbose) + media =media_open_debug ( + media_opts.devname, + (void (*)(void *, ...))fprintf, stdout); +else + media =media_open (media_opts.devname); +if (media ==NULL ) { +printf ("Failed to open %s\n" , media_opts.devname); goto out; + }if (media_opts.entity) {struct media_entity *entity;
@@ -326,15 +332,34 @@ int main(int argc, char **argv) }if (media_opts.reset) { -printf ("Resetting all links to inactive\n" ); -media_reset_links (media); +if (media_opts.verbose) +printf ("Resetting all links to inactive\n" ); + ret =media_reset_links (media); +if (ret) { +printf ("Unable to reset links: %s (%d)\n" , +strerror (-ret), -ret); + goto out; + } } -if (media_opts.links) -media_parse_setup_links (media, media_opts.links); +if (media_opts.links) { + ret =media_parse_setup_links (media, media_opts.links); +if (ret) { +printf ("Unable to parse link: %s (%d)\n" , +strerror (-ret), -ret); + goto out; + } + } -if (media_opts.formats) -v4l2_subdev_parse_setup_formats (media, media_opts.formats); +if (media_opts.formats) { + ret =v4l2_subdev_parse_setup_formats (media, + media_opts.formats); +if (ret) { +printf ("Unable to parse format: %s (%d)\n" , +strerror (-ret), -ret); + goto out; + } + }if (media_opts.interactive) {while (1 ) {
@@ -348,7 +373,10 @@ int main(int argc, char **argv)if (buffer[0 ] =='\n' )break ; -media_parse_setup_link (media, buffer, &end); + ret =media_parse_setup_link (media, buffer, &end); +if (ret) +printf ("Unable to parse link: %s (%d)\n" , +strerror (-ret), -ret); } }
src/mediactl.c +10 -11
@@ -270,7 +270,7 @@ static inline void media_udev_close(struct udev *udev) }static int media_get_devname_udev (struct udev *udev, -struct media_entity *entity,int verbose) +struct media_entity *entity) {struct udev_device *device;dev_t devnum;
@@ -281,9 +281,8 @@ static int media_get_devname_udev(struct udev *udev,return -EINVAL ; devnum =makedev (entity->info.v4l.major, entity->info.v4l.minor); -if (verbose) -media_dbg (entity->media,"looking up device: %u:%u\n" , -major (devnum),minor (devnum)); +media_dbg (entity->media,"looking up device: %u:%u\n" , +major (devnum),minor (devnum)); device =udev_device_new_from_devnum (udev,'c' , devnum);if (device) { p =udev_device_get_devnode (device);
@@ -308,7 +307,7 @@ static inline int media_udev_open(struct udev **udev) { return 0; }static inline void media_udev_close (struct udev *udev) { }static inline int media_get_devname_udev (struct udev *udev, -struct media_entity *entity,int verbose) +struct media_entity *entity) {return -ENOTSUP ; }
@@ -351,7 +350,7 @@ static int media_get_devname_sysfs(struct media_entity *entity)return 0 ; } -static int media_enum_entities (struct media_device *media,int verbose) +static int media_enum_entities (struct media_device *media) {struct media_entity *entity;struct udev *udev;
@@ -400,7 +399,7 @@ static int media_enum_entities(struct media_device *media, int verbose)continue ;/* Try to get the device name via udev */ -if (!media_get_devname_udev (udev, entity, verbose)) +if (!media_get_devname_udev (udev, entity))continue ;/* Fall back to get the device name via sysfs */
@@ -429,7 +428,7 @@ void media_debug_set_handler(struct media_device *media, }struct media_device *media_open_debug ( -const char *name,int verbose,void (*debug_handler)(void *, ...), +const char *name,void (*debug_handler)(void *, ...),void *debug_priv) {struct media_device *media;
@@ -453,7 +452,7 @@ struct media_device *media_open_debug(media_dbg (media,"Enumerating entities\n" ); - ret =media_enum_entities (media, verbose); + ret =media_enum_entities (media);if (ret <0 ) { media_dbg(media,
@@ -478,9 +477,9 @@ struct media_device *media_open_debug(return media; } -struct media_device *media_open (const char *name,int verbose) +struct media_device *media_open (const char *name) { -return media_open_debug (name, verbose,NULL ,NULL ); +return media_open_debug (name,NULL ,NULL ); }void media_close (struct media_device *media)
src/mediactl.h +2 -4
@@ -79,7 +79,6 @@ void media_debug_set_handler(/** * @brief Open a media device with debugging enabled. * @param name - name (including path) of the device node. -* @param verbose - whether to print verbose information on the standard output. * @param debug_handler - debug message handler * @param debug_priv - first argument to debug message handler *
@@ -95,13 +94,12 @@ void media_debug_set_handler(* media_close when the device isn't needed anymore. */ struct media_device *media_open_debug ( -const char *name,int verbose,void (*debug_handler)(void *, ...), +const char *name,void (*debug_handler)(void *, ...),void *debug_priv);/** * @brief Open a media device. * @param name - name (including path) of the device node. -* @param verbose - whether to print verbose information on the standard output. * * Open the media device referenced by @a name and enumerate entities, pads and * links.
@@ -110,7 +108,7 @@ struct media_device *media_open_debug(* success and NULL on failure. The returned pointer must be freed with * media_close when the device isn't needed anymore. */ -struct media_device *media_open (const char *name,int verbose); +struct media_device *media_open (const char *name);/** * @brief Close a media device.
Signature · 1 line
1.7.2.5