| Webcam Library Reference Documentation | ![]() |
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <limits.h>
#include <ctype.h>
#include <unistd.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <linux/videodev.h>
#include <errno.h>
#include <iconv.h>
#include "webcam.h"
#include "libwebcam.h"
#include "uvcvideo.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
Data Structures | |
| struct | _Constant |
| Constant read from the XML configuration file. More... | |
| struct | _UVCXUControl |
| UVC extension unit control for use with UVCIOC_CTRL_ADD. More... | |
| struct | _ParseContext |
| Helper structure that contains handles and information useful during the XML parsing process. More... | |
Defines | |
| #define | GUID_SIZE 16 |
| Size of a GUID in bytes. | |
| #define | GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" |
| Format string to print a GUID byte array with printf. | |
| #define | GUID_ARGS(guid) |
| Argument macro to print a GUID byte array with printf. | |
| #define | HEX_DECODE_CHAR(c) ((c) >= '0' && (c) <= '9' ? (c) - '0' : (tolower(c)) - 'a' + 0xA) |
| Convert a single hex character into its numeric value. | |
| #define | HEX_DECODE_BYTE(cc) ((HEX_DECODE_CHAR((cc)[0]) << 4) + HEX_DECODE_CHAR((cc)[1])) |
| Convert two hex characters into their byte value. | |
| #define | UNICODE_TO_ASCII(s) (unicode_to_ascii(s, ctx)) |
| Helper macro to convert the UTF-8 strings used by libxml2 into ASCII. | |
| #define | UNICODE_TO_NORM_ASCII(s) (unicode_to_normalized_ascii(s, ctx)) |
| Helper macro to convert the UTF-8 strings used by libxml2 into whitespace normalized ASCII. | |
Typedefs | |
| typedef enum _ConstantType | ConstantType |
| Type of constants that are allowed in the XML configuration file. | |
| typedef _Constant | Constant |
| Constant read from the XML configuration file. | |
| typedef _UVCXUControl | UVCXUControl |
| UVC extension unit control for use with UVCIOC_CTRL_ADD. | |
| typedef _ParseContext | ParseContext |
| Helper structure that contains handles and information useful during the XML parsing process. | |
Enumerations | |
| enum | _ConstantType { CT_INVALID = 0, CT_INTEGER, CT_GUID } |
| Type of constants that are allowed in the XML configuration file. More... | |
Functions | |
| static void | guid_to_byte_array (const char *guid, __u8 *array) |
| Converts a GUID string into a GUID byte array. | |
| static int | is_valid_integer_string (const char *string, int *value) |
| Checks whether a given string contains a valid integer value. | |
| static int | is_valid_size (int value, int max) |
| Checks whether a given value represents a valid size. | |
| static int | is_valid_size_string (const char *string, int *value, int max) |
| Checks whether a given string represents a valid size. | |
| static int | is_valid_guid (const char *string) |
| Checks whether a given string represents a valid GUID. | |
| static int | string_to_version (const char *string, unsigned int *major, unsigned int *minor) |
| Converts a string to a version consisting of major and minor version. | |
| static __u32 | get_uvc_request_by_name (const xmlChar *name) |
| Converts the name of a UVC request into its corresponding constant. | |
| static enum uvc_control_data_type | get_uvc_ctrl_type_by_name (const xmlChar *name) |
| Converts the name of a UVC data type constant into its corresponding numerical value. | |
| static enum v4l2_ctrl_type | get_v4l2_ctrl_type_by_name (const xmlChar *name) |
| Converts the name of a V4L2 data type constant into its corresponding numerical value. | |
| static char * | normalize_string (const char *input) |
| Normalizes a string in terms of whitespace. | |
| static char * | unicode_to_ascii (const xmlChar *unicode, ParseContext *ctx) |
| Converts a UTF-8 string to ASCII. | |
| static char * | unicode_to_normalized_ascii (const xmlChar *unicode, ParseContext *ctx) |
| Converts a UTF-8 string to ASCII and then normalizes the string's whitespace. | |
| static const xmlChar * | xml_get_node_text (const xmlNode *node) |
| Returns the text content of the given node. | |
| static xmlNode * | xml_get_first_child_by_name (const xmlNode *node, const char *name) |
| Returns the first child node with a given name. | |
| static xmlNode * | xml_get_next_sibling_by_name (const xmlNode *node, const char *name) |
| Returns the next sibling node with a given name. | |
| static Constant * | lookup_constant (const char *find_name, ConstantType find_type, ParseContext *ctx) |
| Look up a constant by its name. | |
| static CResult | lookup_or_convert_to_integer (const xmlChar *text, int *value, ParseContext *ctx) |
| Convert the given string to an integer or look up a constant with the given name. | |
| static CResult | lookup_or_convert_to_guid (const xmlChar *text, __u8 *guid, ParseContext *ctx) |
| Convert the given string to a GUID or look up a constant with the given name. | |
| static UVCXUControl * | lookup_control (const xmlChar *name, ParseContext *ctx) |
| Lookup a UVC extension unit control with the given name. | |
| static CResult | resize_message_buffer (ParseContext *ctx, CDynctrlMessage *msg) |
| Reorganize the buffer that is used to store the messages that are logged during parsing. | |
| static CResult | add_message_v (ParseContext *ctx, int line, int col, CDynctrlMessageSeverity severity, const char *format, va_list va) |
| Adds a new message to the message list. | |
| static CResult | add_message (ParseContext *ctx, int line, int col, CDynctrlMessageSeverity severity, const char *format,...) |
| Adds a new message to the message list. | |
| static CResult | add_info (ParseContext *ctx, const char *format,...) |
| Adds a new informational message to the message list. | |
| static CResult | add_error (ParseContext *ctx, const char *format,...) |
| Adds a new error message to the message list. | |
| static CResult | add_error_at_node (ParseContext *ctx, const xmlNode *node, const char *format,...) |
| Adds a new error message concerning a given xmlNode to the message list. | |
| static CResult | parse_dynctrl_file (const char *file_name, xmlDoc **xml_doc, ParseContext *ctx) |
| Parse a dynamic controls configuration XML file and return an XML document tree. | |
| static CResult | process_mapping (const xmlNode *node_mapping, ParseContext *ctx) |
Process a mapping node and add the contained mapping to the UVC driver. | |
| static CResult | process_mappings (const xmlNode *node_mappings, ParseContext *ctx) |
Process a mappings node. | |
| static CResult | process_control (xmlNode *node_control, ParseContext *ctx) |
Process a control node by adding the contained control to the UVC driver. | |
| static CResult | process_controls (const xmlNode *node_controls, ParseContext *ctx) |
Process a controls node. | |
| static CResult | process_device (const xmlNode *node_device, ParseContext *ctx) |
Process a device node. | |
| static CResult | process_devices (const xmlNode *node_devices, ParseContext *ctx) |
Process a devices node. | |
| static CResult | process_constant (xmlNode *node_constant, ParseContext *ctx) |
Process a constant node by adding the contained constant to an internal list. | |
| static CResult | process_constants (const xmlNode *node_constants, ParseContext *ctx) |
Process a constants node. | |
| static CResult | process_meta (const xmlNode *node_meta, ParseContext *ctx) |
Process a meta node by filling in the corresponding info structure. | |
| static CResult | process_dynctrl_doc (xmlDoc *xml_doc, ParseContext *ctx) |
| Process an XML document tree representing a dynamic controls configuration file. | |
| static CResult | device_supports_dynctrl (ParseContext *ctx) |
| Checks whether the driver behind the current device supports dynamic controls. | |
| static CResult | add_control_mappings (xmlDoc *xml_doc, ParseContext *ctx) |
| Adds controls and control mappings contained in the given XML tree to the UVC driver. | |
| CResult | c_add_control_mappings_from_file (const char *file_name, CDynctrlInfo *info) |
| Parses a dynamic controls configuration file and adds the contained controls and control mappings to the UVC driver. | |
|
|
Value: (guid)[3], (guid)[2], (guid)[1], (guid)[0], \
(guid)[5], (guid)[4], \
(guid)[7], (guid)[6], \
(guid)[8], (guid)[9], \
(guid)[10], (guid)[11], (guid)[12], \
(guid)[13], (guid)[14], (guid)[15]
|
|
|
Type of constants that are allowed in the XML configuration file.
|
|
||||||||||||
|
Adds controls and control mappings contained in the given XML tree to the UVC driver.
|
|
||||||||||||||||||||
|
Adds a new error message concerning a given xmlNode to the message list. The node is used to extract the line number. |
|
||||||||||||||||||||||||||||
|
Adds a new message to the message list.
|
|
||||||||||||||||||||||||||||
|
Adds a new message to the message list. This function works like add_message() but takes a va_list argument instead of a parameter list. |
|
||||||||||||
|
Parses a dynamic controls configuration file and adds the contained controls and control mappings to the UVC driver. Notes:
|
|
|
Checks whether the driver behind the current device supports dynamic controls. The check is done by redefining the brightness control which is hardcoded in the UVC driver. If the driver supports dynamic controls, it will return EEXIST. If the driver does not support dynamic controls, the ioctl will fail with EINVAL.
|
|
|
Converts the name of a UVC data type constant into its corresponding numerical value.
|
|
|
Converts the name of a UVC request into its corresponding constant.
|
|
|
Converts the name of a V4L2 data type constant into its corresponding numerical value. Note that not all V4L2 data types are recognized. Only the ones relevant for libwebcam and allowed by the schema are considered valid.
|
|
||||||||||||
|
Converts a GUID string into a GUID byte array. This function assumes that guid is a valid GUID string. No validation is performed. |
|
||||||||||||
|
Checks whether a given string contains a valid integer value. This function considers all integers recognized by strtol() as valid. This includes hexadecimal numbers with a '0x' prefix and octal numbers with a leading zero.
|
|
||||||||||||
|
Checks whether a given value represents a valid size. Only positive numbers are considered valid size values. In addition, an upper threshold can be specified, above which values will be considered invalid.
|
|
||||||||||||||||
|
Checks whether a given string represents a valid size. This function works just like is_valid_size() but accepts an input string and a buffer to store the converted value. |
|
||||||||||||||||
|
Look up a constant by its name.
|
|
||||||||||||||||
|
Convert the given string to a GUID or look up a constant with the given name. This function works like lookup_or_convert_to_integer() except that it looks for GUIDs instead of integers. |
|
||||||||||||||||
|
Convert the given string to an integer or look up a constant with the given name. The function first tries to convert the given string to an integer. If successful, the converted value is returned. If the conversion fails, the string is interpreted as a name and a constant with that name is looked up. If the lookup is successful, the value of the constant is returned.
|
|
|
Normalizes a string in terms of whitespace. The function returns a copy of the input string with leading and trailing whitespace removed and all internal whitespace reduced to simple spaces. Examples: " text " => "text" " Multi\nline text" => "Multi line text" This function allocates a new buffer that needs to be freed by the caller.
|
|
||||||||||||||||
|
Parse a dynamic controls configuration XML file and return an XML document tree. Note that the pointer stored in *xml_doc must be freed using xmlFreeDoc() if the return value of this functino is C_SUCCESS.
|
|
||||||||||||
|
Process a
Note that the contained |
|
||||||||||||
|
Reorganize the buffer that is used to store the messages that are logged during parsing. The buffer that is used to store the messages is completely self-contained. It consists of an array of CDynctrlMessage structures and an area for "dynamics" which stores dynamic data like strings. All string pointers in the array point to strings in the dynamics area, so for clean up only a single buffer needs to be freed. Every time a new array element is added, the buffer has to be enlarged, and a new array element has to be inserted between the current last element and the dynamics area. The dynamics area is moved by sizeof(CDynctrlMessage) bytes and all pointers to it are updated to point to the new direction.
|
|
||||||||||||||||
|
Converts a string to a version consisting of major and minor version. Accepted formats are "x.y" and "x" where x is the major and y the minor version.
|
|
||||||||||||
|
Converts a UTF-8 string to ASCII. The function may convert some characters in a non-reversible way.
|
|
||||||||||||
|
Converts a UTF-8 string to ASCII and then normalizes the string's whitespace. This function is effectively a combination of unicode_to_ascii() and normalize_string(). Note that the caller must free the returned string. |
|
||||||||||||
|
Returns the first child node with a given name.
|
|
||||||||||||
|
Returns the next sibling node with a given name.
|
|
|
Returns the text content of the given node.
|