FFmpeg
uuid.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Pierre-Anthony Lemieux <pal@palemieux.com>
3  * Zane van Iperen <zane@zanevaniperen.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /*
23  * Copyright (C) 1996, 1997 Theodore Ts'o.
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions
27  * are met:
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, and the entire permission notice in its entirety,
30  * including the disclaimer of warranties.
31  * 2. Redistributions in binary form must reproduce the above copyright
32  * notice, this list of conditions and the following disclaimer in the
33  * documentation and/or other materials provided with the distribution.
34  * 3. The name of the author may not be used to endorse or promote
35  * products derived from this software without specific prior
36  * written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
41  * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
42  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
43  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
44  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
45  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
46  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
48  * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
49  * DAMAGE.
50  */
51 
52 /**
53  * @file
54  * UUID parsing and serialization utilities.
55  * The library treat the UUID as an opaque sequence of 16 unsigned bytes,
56  * i.e. ignoring the internal layout of the UUID, which depends on the type
57  * of the UUID.
58  *
59  * @author Pierre-Anthony Lemieux <pal@palemieux.com>
60  * @author Zane van Iperen <zane@zanevaniperen.com>
61  */
62 
63 #include "attributes_internal.h"
64 #include "uuid.h"
65 #include "error.h"
66 #include "avstring.h"
67 
68 int av_uuid_parse(const char *in, AVUUID uu)
69 {
70  if (strlen(in) != 36)
71  return AVERROR(EINVAL);
72 
73  return av_uuid_parse_range(in, in + 36, uu);
74 }
75 
76 static int xdigit_to_int(char c)
77 {
78  c = av_tolower(c);
79 
80  if (c >= 'a' && c <= 'f')
81  return c - 'a' + 10;
82 
83  if (c >= '0' && c <= '9')
84  return c - '0';
85 
86  return -1;
87 }
88 
89 int av_uuid_parse_range(const char *in_start, const char *in_end, AVUUID uu)
90 {
91  int i;
92  const char *cp;
93 
94  if ((in_end - in_start) != 36)
95  return AVERROR(EINVAL);
96 
97  for (i = 0, cp = in_start; i < 16; i++) {
98  int hi;
99  int lo;
100 
101  if (i == 4 || i == 6 || i == 8 || i == 10)
102  cp++;
103 
104  hi = xdigit_to_int(*cp++);
105  lo = xdigit_to_int(*cp++);
106 
107  if (hi == -1 || lo == -1)
108  return AVERROR(EINVAL);
109 
110  uu[i] = (hi << 4) + lo;
111  }
112 
113  return 0;
114 }
115 
116 static attribute_nonstring const char hexdigits_lower[16] = "0123456789abcdef";
117 
118 void av_uuid_unparse(const AVUUID uuid, char *out)
119 {
120  char *p = out;
121 
122  for (int i = 0; i < 16; i++) {
123  uint8_t tmp;
124 
125  if (i == 4 || i == 6 || i == 8 || i == 10)
126  *p++ = '-';
127 
128  tmp = uuid[i];
129  *p++ = hexdigits_lower[tmp >> 4];
130  *p++ = hexdigits_lower[tmp & 15];
131  }
132 
133  *p = '\0';
134 }
135 
136 int av_uuid_urn_parse(const char *in, AVUUID uu)
137 {
138  if (av_stristr(in, "urn:uuid:") != in)
139  return AVERROR(EINVAL);
140 
141  return av_uuid_parse(in + 9, uu);
142 }
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVUUID
uint8_t AVUUID[AV_UUID_LEN]
Definition: uuid.h:60
out
static FILE * out
Definition: movenc.c:55
av_stristr
char * av_stristr(const char *s1, const char *s2)
Locate the first case-independent occurrence in the string haystack of the string needle.
Definition: avstring.c:58
attribute_nonstring
#define attribute_nonstring
Definition: attributes_internal.h:42
hexdigits_lower
static const attribute_nonstring char hexdigits_lower[16]
Definition: uuid.c:116
av_uuid_unparse
void av_uuid_unparse(const AVUUID uuid, char *out)
Serializes a AVUUID into a string representation according to IETF RFC 4122.
Definition: uuid.c:118
attributes_internal.h
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
error.h
av_uuid_parse
int av_uuid_parse(const char *in, AVUUID uu)
Parses a string representation of a UUID formatted according to IETF RFC 4122 into an AVUUID.
Definition: uuid.c:68
uuid.h
xdigit_to_int
static int xdigit_to_int(char c)
Definition: uuid.c:76
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
av_uuid_parse_range
int av_uuid_parse_range(const char *in_start, const char *in_end, AVUUID uu)
Parses a string representation of a UUID formatted according to IETF RFC 4122 into an AVUUID.
Definition: uuid.c:89
avstring.h
av_tolower
static av_const int av_tolower(int c)
Locale-independent conversion of ASCII characters to lowercase.
Definition: avstring.h:237
av_uuid_urn_parse
int av_uuid_urn_parse(const char *in, AVUUID uu)
Parses a URN representation of a UUID, as specified at IETF RFC 4122, into an AVUUID.
Definition: uuid.c:136