From patchwork Thu Jun 2 00:30:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 36037 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp3738891pzj; Wed, 1 Jun 2022 17:30:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyL2iMIdBC63LDs14LzRUxXT/JVbweXl+fMupY75J5mAvU1O0wJZ/nnWuMhBlZJV6VVY1LF X-Received: by 2002:a17:906:b294:b0:6fe:fdb9:5fb4 with SMTP id q20-20020a170906b29400b006fefdb95fb4mr1923904ejz.179.1654129858909; Wed, 01 Jun 2022 17:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654129858; cv=none; d=google.com; s=arc-20160816; b=cRayRrPYao64Js+QtqGh3trmdnW7QKBQbeewlC8GUv4FzFMyVkCXXnEPypGFkBDs/O 3t08dmOxZT/f6MEf7lk/NqE7CvQwY7doOOjDVkPYxWP8LpcJNUAdtSHHQqxb9koi5kaR bv1RXMd/gQ+EzKG63iPh+E8mTbQYHMaj/dRtuhIrhIwfjq14nIyf0NW64yi6BCdTQmd+ DCFi1SLlnF3ePYEmHN9i80M8hhPGOFug43R4HsStDZkdMH6PgEwFysHIJLEd7Ry2nbBX mBrH8nEzxkIIoKa6pg47zuR49vSgLZR2YCiBmNAJWS39ctyiMfE1mF2ZWrd9/h/uopwR W7zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=5f2wKUftTAsLqz4YcdjKdUQQpIbHOSXB5vkug6z19tU=; b=UKtKTF35mLVeOV168xkHE37pLmGmgdUaHjtNOVx+dqgY80oXmhGHcXnxbntl7YLwJp ssSRNLDo0ZCZ/faHAf+3iz+ooIIie61J4F1fnqrUufldzaziuQ9AhhLT2q7j9ligHkmX zbfsW8qgB0RFudLPVqHiqeZXr051hxdBk29IA9MynQbHJyTZWdGNti14taZnmG/J0gtz Oy0UdzFxdLGuCklg+qOFYw1/JMrnayYo7tpoPMZmLhiTeZi5OsMIkgN8QZtawlWM+Yeu 3OvbHULunklxB3jch+AzwxWQjK4typ7NlGj4BG8O1VFfR6Xt7gjBlajlX6vCBKCrHPSS wI5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p9-20020aa7c4c9000000b0042ab868c6fesi2948337edr.74.2022.06.01.17.30.57; Wed, 01 Jun 2022 17:30:58 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F22F468B78C; Thu, 2 Jun 2022 03:30:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D2C0968B6C9 for ; Thu, 2 Jun 2022 03:30:47 +0300 (EEST) Received: by mail-pj1-f52.google.com with SMTP id nn3-20020a17090b38c300b001e0e091cf03so4821713pjb.1 for ; Wed, 01 Jun 2022 17:30:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XBiBjjPpPjrB8aa36HraiIOciuYaJn1wPGkzG29bsNQ=; b=RkZRKodFMZShoT7JswT5O5ty8twX0zMKMOoyws23VrKkBoHam1HAJzeSdZRjplCX3I 0igaflorW3gEBVOpKfMjD5dMV/eHokd84YmGf1s/HpHqkAGfGffVdcWcvcYfCWue3IlM NKw3OtXc/ufCn+lzSC99hzzRc6+h1A21vShS8wsTGs6L0fNsCbfKwiyffzdVtbh+FXgQ QnM5URwvN6iwbXinEj2u88ESCnhE5X6ARFWxMQj+2FkfvXcOU+5thOsI311oSLgeLYYI XYxmsIT58sYCabSXQ8LtZotXsMXW/fQDFIauu5dqnE5lCqa39q9PZEmVF01D2XZPGCM8 t/DQ== X-Gm-Message-State: AOAM531tKCA7dvbUAvXOsr/eO7QA2oCQwX79UIXa1TQ3EUu54bILwZ+Y DWt/R26aMd+ZBgUzatNkdL8wg0Uiiic= X-Received: by 2002:a17:902:a9c9:b0:161:5b73:5ac9 with SMTP id b9-20020a170902a9c900b001615b735ac9mr2100127plr.14.1654129845720; Wed, 01 Jun 2022 17:30:45 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id t11-20020a63460b000000b003f285ba5a9fsm1842355pga.57.2022.06.01.17.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 17:30:45 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Wed, 01 Jun 2022 17:30:39 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Jun 2022 17:30:32 -0700 Message-Id: <20220602003037.24597-1-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 1/6] avutil/uuid: add utility library for manipulating UUIDs as specified in RFC 4122 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zane van Iperen , Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: B2h7g/Ut1m8L From: Zane van Iperen * Addresses review comments Co-authored-by: Pierre-Anthony Lemieux Signed-off-by: Zane van Iperen --- libavutil/Makefile | 2 + libavutil/uuid.c | 141 +++++++++++++++++++++++++++++++++++++++++++ libavutil/uuid.h | 147 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 290 insertions(+) create mode 100644 libavutil/uuid.c create mode 100644 libavutil/uuid.h diff --git a/libavutil/Makefile b/libavutil/Makefile index 234de62a4b..a0c5cacef4 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -82,6 +82,7 @@ HEADERS = adler32.h \ timestamp.h \ tree.h \ twofish.h \ + uuid.h \ version.h \ video_enc_params.h \ xtea.h \ @@ -174,6 +175,7 @@ OBJS = adler32.o \ tx_float.o \ tx_double.o \ tx_int32.o \ + uuid.o \ version.o \ video_enc_params.o \ film_grain_params.o \ diff --git a/libavutil/uuid.c b/libavutil/uuid.c new file mode 100644 index 0000000000..062e28736b --- /dev/null +++ b/libavutil/uuid.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 Pierre-Anthony Lemieux + * Zane van Iperen + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF + * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +/** + * @file + * UUID parsing and serialization utilities. + * The library treat the UUID as an opaque sequence of 16 unsigned bytes, + * i.e. ignoring the internal layout of the UUID, which depends on the type + * of the UUID. + * + * @author Pierre-Anthony Lemieux + * @author Zane van Iperen + */ + +#include "uuid.h" +#include "error.h" +#include "avstring.h" + +int av_uuid_parse(const char *in, AVUUID uu) +{ + if (strlen(in) != 36) + return AVERROR(EINVAL); + + return av_uuid_parse_range(in, in + 36, uu); +} + +static int xdigit_to_int(char c) +{ + c = av_tolower(c); + + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + + if (c >= '0' && c <= '9') + return c - '0'; + + return -1; +} + +int av_uuid_parse_range(const char *in_start, const char *in_end, AVUUID uu) +{ + int i; + const char *cp; + + if ((in_end - in_start) != 36) + return AVERROR(EINVAL); + + for (i = 0, cp = in_start; i < 16; i++) { + int hi; + int lo; + + if (i == 4 || i == 6 || i == 8 || i == 10) + cp++; + + hi = xdigit_to_int(*cp++); + lo = xdigit_to_int(*cp++); + + if (hi == -1 || lo == -1) + return AVERROR(EINVAL); + + uu[i] = (hi << 4) + lo; + } + + return 0; +} + +static const char hexdigits_lower[16] = "0123456789abcdef"; + +void av_uuid_unparse(const AVUUID uuid, char *out) +{ + char *p = out; + + for (int i = 0; i < 16; i++) { + uint8_t tmp; + + if (i == 4 || i == 6 || i == 8 || i == 10) + *p++ = '-'; + + tmp = uuid[i]; + *p++ = hexdigits_lower[tmp >> 4]; + *p++ = hexdigits_lower[tmp & 15]; + } + + *p = '\0'; +} + +int av_uuid_urn_parse(const char *in, AVUUID uu) +{ + if (av_stristr(in, "urn:uuid:") != in) + return AVERROR(EINVAL); + + return av_uuid_parse(in + 9, uu); +} diff --git a/libavutil/uuid.h b/libavutil/uuid.h new file mode 100644 index 0000000000..4b5088911c --- /dev/null +++ b/libavutil/uuid.h @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2022 Pierre-Anthony Lemieux + * Zane van Iperen + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * UUID parsing and serialization utilities. + * The library treats the UUID as an opaque sequence of 16 unsigned bytes, + * i.e. ignoring the internal layout of the UUID, which depends on the type + * of the UUID. + * + * @author Pierre-Anthony Lemieux + * @author Zane van Iperen + */ + +#ifndef AVUTIL_UUID_H +#define AVUTIL_UUID_H + +#include +#include + +#define AV_PRI_UUID \ + "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-" \ + "%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" + +#define AV_PRI_URN_UUID \ + "urn:uuid:%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-" \ + "%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" + +/* AV_UUID_ARG() is used together with AV_PRI_UUID() or AV_PRI_URN_UUID + * to print UUIDs, e.g. + * av_log(NULL, AV_LOG_DEBUG, "UUID: " AV_PRI_UUID, AV_UUID_ARG(uuid)); + */ +#define AV_UUID_ARG(x) \ + (x)[ 0], (x)[ 1], (x)[ 2], (x)[ 3], \ + (x)[ 4], (x)[ 5], (x)[ 6], (x)[ 7], \ + (x)[ 8], (x)[ 9], (x)[10], (x)[11], \ + (x)[12], (x)[13], (x)[14], (x)[15] + +#define AV_UUID_LEN 16 + +/* Binary representation of a UUID */ +typedef uint8_t AVUUID[AV_UUID_LEN]; + +/** + * Parses a string representation of a UUID formatted according to IETF RFC 4122 + * into an AVUUID. The parsing is case-insensitive. The string must be 37 + * characters long, including the terminating NUL character. + * + * Example string representation: "2fceebd0-7017-433d-bafb-d073a7116696" + * + * @param[in] in String representation of a UUID, + * e.g. 2fceebd0-7017-433d-bafb-d073a7116696 + * @param[out] uu AVUUID + * @return A non-zero value in case of an error. + */ +int av_uuid_parse(const char *in, AVUUID uu); + +/** + * Parses a URN representation of a UUID, as specified at IETF RFC 4122, + * into an AVUUID. The parsing is case-insensitive. The string must be 46 + * characters long, including the terminating NUL character. + * + * Example string representation: "urn:uuid:2fceebd0-7017-433d-bafb-d073a7116696" + * + * @param[in] in URN UUID + * @param[out] uu AVUUID + * @return A non-zero value in case of an error. + */ +int av_uuid_urn_parse(const char *in, AVUUID uu); + +/** + * Parses a string representation of a UUID formatted according to IETF RFC 4122 + * into an AVUUID. The parsing is case-insensitive. + * + * @param[in] in_start Pointer to the first character of the string representation + * @param[in] in_end Pointer to the character after the last character of the + * string representation. That memory location is never + * accessed. It is an error if `in_end - in_start != 36`. + * @param[out] uu AVUUID + * @return A non-zero value in case of an error. + */ +int av_uuid_parse_range(const char *in_start, const char *in_end, AVUUID uu); + +/** + * Serializes a AVUUID into a string representation according to IETF RFC 4122. + * The string is lowercase and always 37 characters long, including the + * terminating NUL character. + * + * @param[in] uu AVUUID + * @param[out] out Pointer to an array of no less than 37 characters. + * @return A non-zero value in case of an error. + */ +void av_uuid_unparse(const AVUUID uu, char *out); + +/** + * Compares two UUIDs for equality. + * + * @param[in] uu1 AVUUID + * @param[in] uu2 AVUUID + * @return Nonzero if uu1 and uu2 are identical, 0 otherwise + */ +static inline int av_uuid_equal(const AVUUID uu1, const AVUUID uu2) +{ + return memcmp(uu1, uu2, AV_UUID_LEN) == 0; +} + +/** + * Copies the bytes of src into dest. + * + * @param[out] dest AVUUID + * @param[in] src AVUUID + */ +static inline void av_uuid_copy(AVUUID dest, const AVUUID src) +{ + memcpy(dest, src, AV_UUID_LEN); +} + +/** + * Sets a UUID to the nil UUID, i.e. a UUID with have all + * its 128 bits set to zero. + * + * @param[in,out] uu UUID to be set to the nil UUID + */ +static inline void av_uuid_nil(AVUUID uu) +{ + memset(uu, 0, AV_UUID_LEN); +} + +#endif /* AVUTIL_UUID_H */ From patchwork Thu Jun 2 00:30:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 36038 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp3738983pzj; Wed, 1 Jun 2022 17:31:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznQa+ZWGBdY8l7JQ5fFAnu/lUHFiemSUonISOY/GsXrLCbaBEeJGX8G+We42opTD4feD6A X-Received: by 2002:a05:6402:44e:b0:42a:6266:3f15 with SMTP id p14-20020a056402044e00b0042a62663f15mr2613922edw.418.1654129869512; Wed, 01 Jun 2022 17:31:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654129869; cv=none; d=google.com; s=arc-20160816; b=XDzzxaCAr5vsoaakpCx4oF1Lshf1qEZUXlrghcCUDU2JQdxyVykjwkoEqd+h+4WDuR OFWwpMXQ0V9YO6E3HjgaZdzMeE68zqEdExd2JNEeUxJ5e0M4qefyxjx+mGvlIhek10rV AhHbjoWpkgTFJRe0eRH1Jp8ACOYb+/YlJiqiLt06SiJDjJ72MTGjPVVnnVERM8weJAea IwSr0hM2LRj9hwZ0RFZViH751JdOq4ELYajRmkWdRIO8UqHkrNM91L9XnhbCxoUZelJ1 ZRPI+wmGy1RTDBWt8xaq/lLY3lGHCjjKO68xYudTpLs3zw/qjxUfJAOV+v5KwLjKyNXb MqhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=nDBMqcJRg+8SDbBD38sou3gdimoLeHTgjbRReSGK0ZE=; b=fn3oy6FsDx4a9Y7oh0avA7uMGaudEvro/uF0b5dOUF9ZveqcJPv+NV1ooWJGh1QYVV X5DZCE5DtwtwwrV5pTEirA1cS2MI50xuWncWNrovXQ2yOCuGGBOhipLTcd9w71WG6jMc ib7tJriJI4yToiu54SyG0s2o9yUXhdw+V7THG/NO2oDwanaMNP9zcl8Qg4lggX7fzzFD uPG+j4ARUwKGF6FK1K3oDXD29of2Bmz5/IyTEg0lh/QSHTDtTpF6AYWuf/NIFS/BmyQJ KvT4+JuKYp4K6rkmkDVQuLuuDG0b+Y1msCWBBrB7cQrONQjKwFNQh4ejpSIyE+7buvr6 R3FQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w12-20020a1709062f8c00b006f38560fe61si3191216eji.94.2022.06.01.17.31.09; Wed, 01 Jun 2022 17:31:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 255F768B7B2; Thu, 2 Jun 2022 03:30:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A84B68B60A for ; Thu, 2 Jun 2022 03:30:50 +0300 (EEST) Received: by mail-pj1-f53.google.com with SMTP id a10so3481857pju.3 for ; Wed, 01 Jun 2022 17:30:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fEQhv6FeTKETHnUqKBIak/1OT2JTV4ywf5O6lwGXBIM=; b=nYp2OJFBLmtv/ss5A5byOGihJJcMVAw1UUV6C2ImdFDprgu/CZXGkMxUGmpAx2jRaI 2OE2dmiRqJmjeklG9h7CEr2S9G/I7mos0e09usPBASWxtm6EssLmjulCsx3N0PUuk7lC 9/v34Zvvx8BzNz3PviNxcFgdghZO2aj9pfKnosheOjCZqFwwGWzFhxLIwjEQRFZdXQYI 5h+hEB/eUfbPu2yT/eu2ifFPPVpUoK9xZQo32BcnuzTUex3MGROr+Ttsme4CwlyzxeKB mjuOfDsrhCVu4oF2EZ1ypgZE1s5/QxqvafEyt0PYkRSqPz3iynIfYRp040GBg1aGgPFc BDPg== X-Gm-Message-State: AOAM531oiUUvsDfzEW4hIi97u3b3A0jqBjO853P7Z2tjkPnx6kN6hxSI 133/9SDouqI8CN7aFEqq0Bl1ZcZdW6c= X-Received: by 2002:a17:90b:4b88:b0:1e2:d504:fb22 with SMTP id lr8-20020a17090b4b8800b001e2d504fb22mr2163829pjb.97.1654129848057; Wed, 01 Jun 2022 17:30:48 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id y13-20020a17090a600d00b001d9927ef1desm4407235pji.34.2022.06.01.17.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 17:30:47 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Wed, 01 Jun 2022 17:30:42 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Jun 2022 17:30:33 -0700 Message-Id: <20220602003037.24597-2-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602003037.24597-1-pal@sandflow.com> References: <20220602003037.24597-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 2/6] avutil/tests/uuid: add uuid tests X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /iSvRk/DR5SU From: Pierre-Anthony Lemieux --- libavutil/Makefile | 1 + libavutil/tests/.gitignore | 1 + libavutil/tests/uuid.c | 141 +++++++++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 5 ++ 4 files changed, 148 insertions(+) create mode 100644 libavutil/tests/uuid.c diff --git a/libavutil/Makefile b/libavutil/Makefile index a0c5cacef4..5c2ff319cc 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -261,6 +261,7 @@ TESTPROGS = adler32 \ tree \ twofish \ utf8 \ + uuid \ xtea \ tea \ diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore index 9d90827954..919010e4fc 100644 --- a/libavutil/tests/.gitignore +++ b/libavutil/tests/.gitignore @@ -48,4 +48,5 @@ /tree /twofish /utf8 +/uuid /xtea diff --git a/libavutil/tests/uuid.c b/libavutil/tests/uuid.c new file mode 100644 index 0000000000..ff688be030 --- /dev/null +++ b/libavutil/tests/uuid.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 Pierre-Anthony Lemieux + * Zane van Iperen + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/uuid.h" +#include "libavutil/log.h" + +static const char *UUID_1 = "6021b21e-894e-43ff-8317-1ca891c1c49b"; +static const char *UUID_1_UC = "6021B21E-894E-43FF-8317-1CA891C1C49B"; +static const char *UUID_1_MIXED = "6021b21e-894E-43fF-8317-1CA891C1c49b"; +static const char *UUID_1_URN = "urn:uuid:6021b21e-894e-43ff-8317-1ca891c1c49b"; +static const AVUUID UUID_1_BYTES = {0x60, 0x21, 0xb2, 0x1e, 0x89, 0x4e, 0x43, 0xff, + 0x83, 0x17, 0x1c, 0xa8, 0x91, 0xc1, 0xc4, 0x9b}; + +static const AVUUID UUID_NIL = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +static const char *UUID_BAD_1 = "16a2c9f8-afbc-4767-8621-8cb2b27599"; +static const char *UUID_BAD_2 = "75df62c2999b4bd38c9d8058fcde9123"; +static const char *UUID_BAD_3 = "a1b9a05e-f1d1-464g-a951-1ba0a374f02"; +static const char *UUID_BAD_4 = "279c66d432-7b39-41d5-966f-5e8138265c20"; + +int main(int argc, char **argv) +{ + AVUUID uuid; + AVUUID uuid2 = {0x32, 0xc7, 0x00, 0xc4, 0xd5, 0xd7, 0x42, 0x0, + 0x93, 0xc0, 0x3b, 0x6d, 0xea, 0x1b, 0x20, 0x5b}; + + /* test parsing */ + + if (av_uuid_parse(UUID_1, uuid)) + return 1; + + if (!av_uuid_equal(uuid, UUID_1_BYTES)) + return 1; + + /* test nil */ + + av_uuid_nil(uuid); + + if (!av_uuid_equal(uuid, UUID_NIL)) + return 1; + + /* test equality */ + + if (av_uuid_equal(UUID_1_BYTES, uuid2)) + return 1; + + /* test copy */ + + av_uuid_copy(uuid2, UUID_1_BYTES); + + if (!av_uuid_equal(uuid2, UUID_1_BYTES)) + return 1; + + /* test uppercase parsing */ + + if (av_uuid_parse(UUID_1_UC, uuid)) + return 1; + + if (!av_uuid_equal(uuid, UUID_1_BYTES)) + return 1; + + /* test mixed-case parsing */ + + if (av_uuid_parse(UUID_1_MIXED, uuid)) + return 1; + + if (!av_uuid_equal(uuid, UUID_1_BYTES)) + return 1; + + /* test URN uuid parse */ + + if (av_uuid_urn_parse(UUID_1_URN, uuid)) + return 1; + + if (!av_uuid_equal(uuid, UUID_1_BYTES)) + return 1; + + /* test parse range */ + + if (av_uuid_parse_range(UUID_1_URN + 9, UUID_1_URN + 45, uuid)) + return 1; + + if (!av_uuid_equal(uuid, UUID_1_BYTES)) + return 1; + + /* test bad parse range */ + + if (!av_uuid_parse_range(UUID_1_URN + 9, UUID_1_URN + 44, uuid)) + return 1; + + /* test bad parse range 2 */ + + if (!av_uuid_parse_range(UUID_1_URN + 8, UUID_1_URN + 44, uuid)) + return 1; + + /* test bad parse range 2 */ + + if (!av_uuid_parse_range(UUID_1_URN + 8, UUID_1_URN + 45, uuid)) + return 1; + + /* test bad uuid 1 */ + + if (!av_uuid_parse(UUID_BAD_1, uuid)) + return 1; + + /* test bad uuid 2 */ + + if (!av_uuid_parse(UUID_BAD_2, uuid)) + return 1; + + /* test bad uuid 3 */ + + if (!av_uuid_parse(UUID_BAD_3, uuid)) + return 1; + + /* test bad uuid 4 */ + + if (!av_uuid_parse(UUID_BAD_4, uuid)) + return 1; + + return 0; +} diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index c32cf2e706..80153f4395 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -170,6 +170,11 @@ FATE_LIBAVUTIL += fate-opt fate-opt: libavutil/tests/opt$(EXESUF) fate-opt: CMD = run libavutil/tests/opt$(EXESUF) +FATE_LIBAVUTIL += fate-uuid +fate-uuid: libavutil/tests/uuid$(EXESUF) +fate-uuid: CMD = run libavutil/tests/uuid$(EXESUF) +fate-uuid: CMP = null + FATE_LIBAVUTIL += $(FATE_LIBAVUTIL-yes) FATE-$(CONFIG_AVUTIL) += $(FATE_LIBAVUTIL) fate-libavutil: $(FATE_LIBAVUTIL) From patchwork Thu Jun 2 00:30:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 36039 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp3739059pzj; Wed, 1 Jun 2022 17:31:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzB/eG8kBVy1vQT0+rqsMr6ag+WVBtrVkG4JriDnQAs2cON02N+bRwHLCLHdyWFkeYb2MDe X-Received: by 2002:a17:907:6d10:b0:6fe:c744:43be with SMTP id sa16-20020a1709076d1000b006fec74443bemr1945612ejc.470.1654129878346; Wed, 01 Jun 2022 17:31:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654129878; cv=none; d=google.com; s=arc-20160816; b=QDx3wPxY/SflWF/aIX17gQObDE5EZSk/A8+QuJOt5YNDfo7GZzvT+dKMWhKIkw/cuG m7Ko4udTxbZBdF2zCOdijE9Iv5naUopOr7zaZjY+6UZ2k8SIMqcB8q9b9g4OR4MammjE rxdg7TTno6wh6NDwqcN+nOm2/0dk6pEzxd499Z7UNzSpumER2z+hLnUAwuEr0tpcUfPI bic4vED+oXYvPuJ9OHthwJHlUGfqRoS+dhoSa410+6yvB97fDGhD/ljrCQ0kRbOBtPLq m7fSuEwzeCqIP7idq3UuKDgIkURlfE8Egn/1e/6PAxqNAFGYTkxV6obDDBt9Ghgh/5gL QG0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=tlp/r1Wxu3czjqCEbHkLI/CqSBVWZ3XIHofZOIRHgGo=; b=eJkkYgMqrQjW9f/l31mDBSrWGaicZNuJPrhuthGe08aBrACn8LP9jxmXJDPA8jWY0I Kxc4EcE0ruYxazpavbOaK3DhWvcA3agEslA3/zFeJSCrDT2jzcO9s3kN6isjJ5KD2jnf INNS/zZOG1UPU3JJ+rzj7gvrwOZZ6j/rRJksFdGqR/EHdTA6u1839alrnrpQAqkPTS1j 50yT8zCpGVDWu8HDa/SLW+JkazbOkTFQbPZBuBaj2DFsaXByS91KaTdA3+4Nd0Ys45pe jb48m1Ny9lHI6ICyLk+zYbU5CeikYPbbZK2D1PV1VANR/2aKcLXWNufvsEnRnPyhLhQ5 MH+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g15-20020a1709061c8f00b006ff04ae2168si2943727ejh.245.2022.06.01.17.31.17; Wed, 01 Jun 2022 17:31:18 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 287F568B66C; Thu, 2 Jun 2022 03:30:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 61DED68B70E for ; Thu, 2 Jun 2022 03:30:52 +0300 (EEST) Received: by mail-pg1-f174.google.com with SMTP id u4so377040pgk.11 for ; Wed, 01 Jun 2022 17:30:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=607MiutuA6X5Dja8NNSeYInwJNAgCLiHOCtV+yuJuYA=; b=ut0rq9Pb1oOmrA6FjdIhbS1UhEyg3afz7IjkKN62hJ0P+FufzRhzmmrPNgAYMNpn+P 5aGQ0XUREEDu/mqxG+GWIbFOD3OHiVwwayckTczN9/AugAHLqgJ3TZ73tbtTqCBvoK4F HOw/HbJIeW5Ridk//AtYbRPILZRp432cDCI4VLf44s2k2dMlc3jlrVXcQD6mQfMkcdBQ Pwl3FO0nvpWKwGUpZrE/pnt2BJJQzcTgJN1Tw/Hq7Q6GEb35N5bBFkyQBQFDw+3QB4cI h6SWVKEuvNttkB478f9ZDIC/FVc3qSfenNjsLB2zbDToEY1/03SRIumJDtpUtr0VUNUz 1rQQ== X-Gm-Message-State: AOAM530d+gzmlhHeqfdFefKZ5GGmKnOvRC0EAX/IKrp2Ee/efe8HdnH4 OlmDlNROKQX6cg4UFa6HCNKbHDuK01E= X-Received: by 2002:a63:24c7:0:b0:3fc:5c99:a196 with SMTP id k190-20020a6324c7000000b003fc5c99a196mr1714056pgk.521.1654129850329; Wed, 01 Jun 2022 17:30:50 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id m13-20020a17090a858d00b001e325fbe508sm4311997pjn.25.2022.06.01.17.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 17:30:49 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Wed, 01 Jun 2022 17:30:44 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Jun 2022 17:30:34 -0700 Message-Id: <20220602003037.24597-3-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602003037.24597-1-pal@sandflow.com> References: <20220602003037.24597-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/6] avformat/mov: refactor to use avutil/uuid X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 5cdFzEbOyE63 From: Pierre-Anthony Lemieux --- libavformat/mov.c | 25 +++++++++++++------------ libavformat/movenc.c | 9 +++++---- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index d7be593a86..f8248ab65b 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -47,6 +47,7 @@ #include "libavutil/spherical.h" #include "libavutil/stereo3d.h" #include "libavutil/timecode.h" +#include "libavutil/uuid.h" #include "libavcodec/ac3tab.h" #include "libavcodec/flac.h" #include "libavcodec/hevc.h" @@ -5956,21 +5957,21 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, MOVAtom atom) AVStream *st; MOVStreamContext *sc; int64_t ret; - uint8_t uuid[16]; - static const uint8_t uuid_isml_manifest[] = { + AVUUID uuid; + static const AVUUID uuid_isml_manifest = { 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd, 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 }; - static const uint8_t uuid_xmp[] = { + static const AVUUID uuid_xmp = { 0xbe, 0x7a, 0xcf, 0xcb, 0x97, 0xa9, 0x42, 0xe8, 0x9c, 0x71, 0x99, 0x94, 0x91, 0xe3, 0xaf, 0xac }; - static const uint8_t uuid_spherical[] = { + static const AVUUID uuid_spherical = { 0xff, 0xcc, 0x82, 0x63, 0xf8, 0x55, 0x4a, 0x93, 0x88, 0x14, 0x58, 0x7a, 0x02, 0x52, 0x1f, 0xdd, }; - if (atom.size < sizeof(uuid) || atom.size >= FFMIN(INT_MAX, SIZE_MAX)) + if (atom.size < AV_UUID_LEN || atom.size >= FFMIN(INT_MAX, SIZE_MAX)) return AVERROR_INVALIDDATA; if (c->fc->nb_streams < 1) @@ -5978,13 +5979,13 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, MOVAtom atom) st = c->fc->streams[c->fc->nb_streams - 1]; sc = st->priv_data; - ret = ffio_read_size(pb, uuid, sizeof(uuid)); + ret = ffio_read_size(pb, uuid, AV_UUID_LEN); if (ret < 0) return ret; - if (!memcmp(uuid, uuid_isml_manifest, sizeof(uuid))) { + if (av_uuid_equal(uuid, uuid_isml_manifest)) { uint8_t *buffer, *ptr; char *endptr; - size_t len = atom.size - sizeof(uuid); + size_t len = atom.size - AV_UUID_LEN; if (len < 4) { return AVERROR_INVALIDDATA; @@ -6022,9 +6023,9 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, MOVAtom atom) } av_free(buffer); - } else if (!memcmp(uuid, uuid_xmp, sizeof(uuid))) { + } else if (av_uuid_equal(uuid, uuid_xmp)) { uint8_t *buffer; - size_t len = atom.size - sizeof(uuid); + size_t len = atom.size - AV_UUID_LEN; if (c->export_xmp) { buffer = av_mallocz(len + 1); if (!buffer) { @@ -6044,8 +6045,8 @@ static int mov_read_uuid(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (ret < 0) return ret; } - } else if (!memcmp(uuid, uuid_spherical, sizeof(uuid))) { - size_t len = atom.size - sizeof(uuid); + } else if (av_uuid_equal(uuid, uuid_spherical)) { + size_t len = atom.size - AV_UUID_LEN; ret = mov_parse_uuid_spherical(sc, pb, len); if (ret < 0) return ret; diff --git a/libavformat/movenc.c b/libavformat/movenc.c index de971f94e8..b7b2f46a17 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -57,6 +57,7 @@ #include "libavutil/timecode.h" #include "libavutil/dovi_meta.h" #include "libavutil/color_utils.h" +#include "libavutil/uuid.h" #include "hevc.h" #include "rtpenc.h" #include "mov_chan.h" @@ -4487,14 +4488,14 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov, AVFormat int64_t pos = avio_tell(pb); int i; - static const uint8_t uuid[] = { + static const AVUUID uuid = { 0xa5, 0xd4, 0x0b, 0x30, 0xe8, 0x14, 0x11, 0xdd, 0xba, 0x2f, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 }; avio_wb32(pb, 0); ffio_wfourcc(pb, "uuid"); - avio_write(pb, uuid, sizeof(uuid)); + avio_write(pb, uuid, AV_UUID_LEN); avio_wb32(pb, 0); avio_printf(pb, "\n"); @@ -4753,7 +4754,7 @@ static int mov_write_tfxd_tag(AVIOContext *pb, MOVTrack *track) avio_wb32(pb, 0); /* size placeholder */ ffio_wfourcc(pb, "uuid"); - avio_write(pb, uuid, sizeof(uuid)); + avio_write(pb, uuid, AV_UUID_LEN); avio_w8(pb, 1); avio_wb24(pb, 0); avio_wb64(pb, track->cluster[0].dts + track->cluster[0].cts); @@ -4779,7 +4780,7 @@ static int mov_write_tfrf_tag(AVIOContext *pb, MOVMuxContext *mov, avio_seek(pb, track->frag_info[entry].tfrf_offset, SEEK_SET); avio_wb32(pb, size); ffio_wfourcc(pb, "uuid"); - avio_write(pb, uuid, sizeof(uuid)); + avio_write(pb, uuid, AV_UUID_LEN); avio_w8(pb, 1); avio_wb24(pb, 0); avio_w8(pb, n); From patchwork Thu Jun 2 00:30:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 36040 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp3739120pzj; Wed, 1 Jun 2022 17:31:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsb9FXHqRO0lBG3HKN45i+XcCClWgFS023ajKCbeL6myqsyYQO9+PHETMiwbi73V234wib X-Received: by 2002:a05:6402:34c4:b0:42d:f0b1:6f1f with SMTP id w4-20020a05640234c400b0042df0b16f1fmr2619770edc.208.1654129887891; Wed, 01 Jun 2022 17:31:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654129887; cv=none; d=google.com; s=arc-20160816; b=ubyPnSNrJCT0Ha+U5BSCttS/wkqYaS24uRCA+Gd7UBShbh4hthUk+sjY1l5oi98hAc fWgec5Rh4Q5KICrReA8x27jLJmZWcsVc1fwzr+B+iEn96MbERBVxdUQyS7AHflLC6b0s a1b+rlCO5CzTJIJWIcFAougOhrQ8TEQzoLLtw1+gGN8AxVE8X9AsI7WpNSMHM/2glFIs x9T4JtnJ8JZYhR+pITyBor8fmYYRZXeWfJmIbJDIx+9Kkf5Q5mVbPykwnM/3/wUsMJG2 EaMZk6cvJimVIYREnOc15b2d7mQuEOVsQxKDYBAbXMC9/+WpWS7go9EYLFRsjoktQMq3 Wd0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=te9oryQbOG3zeQUR52dXJK8990S8zzufkcbKFlV+sUI=; b=Wt2dvv59GwTqhxC+anAoGF7N2caDPnn6ndLPs6q0BMv8d4d+lRxbQvMPTPBta8uj0V N5gi/Nh1epXPrsSr+XxVzYTZFqo8QZZ4Ias8XK2Mt9c39jEQ+LoI74A+nU01jIBQXZ0f AM69+snmhHs0+yoXtUKoYHyfregHAaBRaw2vq6z/QrqE5X1hCD90z08MxgBmEiuZWrTW 4ADdm9lyO/HTgO8dq5hJNycrf3EsTt3pdqyAQJLi4IjIQCCVJIUmm+6a5769+nZl20tU PCNh0EBjDBpeokbpYbqGyFoEzaFVHgjUGP8jrELkE/krsSEZ8yQGefMHXmRfLknMaBjC wYGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s9-20020a056402164900b0042ab7a5cabcsi3346298edx.214.2022.06.01.17.31.27; Wed, 01 Jun 2022 17:31:27 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1126468B7D1; Thu, 2 Jun 2022 03:31:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 82BE668B7B9 for ; Thu, 2 Jun 2022 03:30:54 +0300 (EEST) Received: by mail-pj1-f48.google.com with SMTP id l7-20020a17090aaa8700b001dd1a5b9965so3491841pjq.2 for ; Wed, 01 Jun 2022 17:30:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=inOmA3C9ICUbIrIDk7VOwMY3IWzQMQ6mpJixCyln1ns=; b=GPCNFhxTJEUIwenjwOkEroZReC0gaxOgCbdJIKjOgLqrMuW5daQfyjA+o7+FMReWUx UcVeSkZiC99b2w8bQD1KgVVgjhebE0gOx50mS3de7JQkaTXN4FVZFQbjp03B2D07/SFH epwbM+DIPts/QxwXfgkugglV36aoK3g5O1yx5aLZwXpHfO0yyxb/tGi1d3vo0NNhJIx6 FtMlyU71VMDlVWUGn1wMK+snrU1e1CJbT72yApxb0B35jnSqvzYxRBYua2QSio7q3NYv G2iJkdrgW+/QMRDkP4DKmIE/zgW2opFFscmiJL+VXpTImh7v2xC6itZ6bmdx+0zLjz6T LDDw== X-Gm-Message-State: AOAM530D7pKe/Fy0N1hgi6u6qHqcTC58K6MNcR2J73/Ze6wShmfh+QMd on90R9rcGUJQES2DbdAs+L1XQzoO5Fk= X-Received: by 2002:a17:90a:bb0e:b0:1dc:a406:3566 with SMTP id u14-20020a17090abb0e00b001dca4063566mr2162535pjr.135.1654129852595; Wed, 01 Jun 2022 17:30:52 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id u188-20020a6279c5000000b0050dc76281aasm2051375pfc.132.2022.06.01.17.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 17:30:52 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Wed, 01 Jun 2022 17:30:47 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Jun 2022 17:30:35 -0700 Message-Id: <20220602003037.24597-4-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602003037.24597-1-pal@sandflow.com> References: <20220602003037.24597-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 4/6] avformat/smoothstreamingenc: refactor to use avutil/uuid X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UCfKNAIbtFyu From: Pierre-Anthony Lemieux --- libavformat/smoothstreamingenc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c index 1713dd9009..ade6d5723b 100644 --- a/libavformat/smoothstreamingenc.c +++ b/libavformat/smoothstreamingenc.c @@ -34,6 +34,7 @@ #include "libavutil/opt.h" #include "libavutil/avstring.h" #include "libavutil/mathematics.h" +#include "libavutil/uuid.h" typedef struct Fragment { int64_t start_time, duration; @@ -416,13 +417,13 @@ static int parse_fragment(AVFormatContext *s, const char *filename, int64_t *sta if (len < 8 || len >= *moof_size) goto fail; if (tag == MKTAG('u','u','i','d')) { - static const uint8_t tfxd[] = { + static const AVUUID tfxd = { 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6, 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2 }; - uint8_t uuid[16]; + AVUUID uuid; avio_read(in, uuid, 16); - if (!memcmp(uuid, tfxd, 16) && len >= 8 + 16 + 4 + 16) { + if (av_uuid_equal(uuid, tfxd) && len >= 8 + 16 + 4 + 16) { avio_seek(in, 4, SEEK_CUR); *start_ts = avio_rb64(in); *duration = avio_rb64(in); From patchwork Thu Jun 2 00:30:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 36041 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp3739190pzj; Wed, 1 Jun 2022 17:31:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3txdWznydmzqlnl6jlDpLCZeyI0A5IijPGJesx3jw38ipRIOF37do4e/G2YkwdcUvAOt4 X-Received: by 2002:a17:907:7b8c:b0:6fe:d41d:b6a3 with SMTP id ne12-20020a1709077b8c00b006fed41db6a3mr1969234ejc.92.1654129897466; Wed, 01 Jun 2022 17:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654129897; cv=none; d=google.com; s=arc-20160816; b=f1cYu37lYsSezn7v6siHPcMVpUJqGaRZ/Wz/frwePKCsitlm9Z2LiXHiQYnudbzQ4T ig1dEpnAYrPhBm6cdaSrJnNX5wlVnaC0SX/zhBPVAkWFtXd9WUnYDWyvWxU+uZ7oEySU tC7AdlOTkNlzdaBfpy5GKfMmmhLT8mlk3xYQ1opiQDDGeNZl3XHRgqLo5WsGRaCOx5RJ 0R+8Qj0zghmIIqpPoEQThTM5EdCpb0qF3rO52LJzlpc6XcILmba98EvLYfUBSoq/97IW PW9UygVdrXV5n80FF5jpsbRE9D3dCsB5nqrwhTC420IPES7G/8saqQvWM2T+mf0XwaCN TcQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=BUyNQgO2x2aTk2Wyu7FZbsYN5s+GI4HJoV2gf1hmaI8=; b=D8L5vTgD/J7iny10EUnp0yLfqG8qPVtT6+KEJbaTbWOue/3EzwcSHrontuhDmxGhcB d1dZpU64orVnkRd56nG496QGhvvacQNKLSLDMlPp+EDudJUAtsiype4dEoE+Boqk6/kS hWw3T03UHJu4fPDqyy7L5D0XejJRu3wxHjc9vGFKANaRyw7C6x30M0/4ecj0cOzsvGKR q8aMw485eSHQ8P9iyyoWy8vfXfHJ4Sd5EsvFlZkhDwm9f/SrxPoCjAcRXRJWXh/6oZ0Z vT+zw5t+Pvd7Le2j1LOv0VZ7K4/77lLo2S5ERgo4tt+/BZZnczGt+L/zi9hGIY6D1rRh AvhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dd9-20020a1709069b8900b006fe6cfe74b7si2483441ejc.849.2022.06.01.17.31.37; Wed, 01 Jun 2022 17:31:37 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 27DB968B7BA; Thu, 2 Jun 2022 03:31:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD1EA68B7B9 for ; Thu, 2 Jun 2022 03:30:56 +0300 (EEST) Received: by mail-pg1-f178.google.com with SMTP id 137so3342727pgb.5 for ; Wed, 01 Jun 2022 17:30:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qv+KORmniv2beaT7E14dtiGpnszzlT1hvThaongm3bE=; b=bs7Af5kgjJfVdRlXS4uGoFEIruxGnzBoFDiRG5p0mOayK8pomsmk+sPy9Bdt+orGjx Ze2GS543Hwr+zGEeueha4eFh29+Pj4XQp6678yDkXC0CwmOsTn6UZRhLmexyirb5S5NB ldGxCFYubRp0/J+oEf1LxutjX2d6An8SYGA5aPn5etgT4+JamEpd+UOuHfJ9fZ72Hu0n afOuGozYRF0VqOkv5EctmTxGQ3kQO2f9sivx/CaZ2gdVqnGL2dUqwcQvG4LUIryuZ6UN 8crxZ5S0SD8n9g2h1VHhX86duRmYtRUOpKc7L1lZgI7JLmq1aCKxYPQJkzEm4CKvH3jn lU4g== X-Gm-Message-State: AOAM531tmTYeud5MT5BOk1a/OiOMicC04NvmrYeAbhfkGCMVa7Q0HzN5 G30hC8ffdthLflLJi81ORMkC7YBMq5o= X-Received: by 2002:a63:e603:0:b0:3fb:c191:9b65 with SMTP id g3-20020a63e603000000b003fbc1919b65mr1779006pgh.12.1654129854848; Wed, 01 Jun 2022 17:30:54 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id u1-20020a170902714100b0015e8d4eb1dfsm2149160plm.41.2022.06.01.17.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 17:30:54 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Wed, 01 Jun 2022 17:30:49 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Jun 2022 17:30:36 -0700 Message-Id: <20220602003037.24597-5-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602003037.24597-1-pal@sandflow.com> References: <20220602003037.24597-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 5/6] avformat/imf: refactor to use avutil/uuid X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ORKd8TNShCpN From: Pierre-Anthony Lemieux --- libavformat/imf.h | 18 ++++--------- libavformat/imf_cpl.c | 60 +++++++++++++++-------------------------- libavformat/imfdec.c | 34 +++++++++++------------ libavformat/tests/imf.c | 18 ++++++------- 4 files changed, 52 insertions(+), 78 deletions(-) diff --git a/libavformat/imf.h b/libavformat/imf.h index 62c4468ce9..4271cd9582 100644 --- a/libavformat/imf.h +++ b/libavformat/imf.h @@ -58,17 +58,9 @@ #include "avformat.h" #include "libavformat/avio.h" #include "libavutil/rational.h" +#include "libavutil/uuid.h" #include -#define FF_IMF_UUID_FORMAT \ - "urn:uuid:%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-" \ - "%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" - -/** - * UUID as defined in IETF RFC 422 - */ -typedef uint8_t FFIMFUUID[16]; - /** * IMF Composition Playlist Base Resource */ @@ -84,7 +76,7 @@ typedef struct FFIMFBaseResource { */ typedef struct FFIMFTrackFileResource { FFIMFBaseResource base; - FFIMFUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */ + AVUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */ } FFIMFTrackFileResource; /** @@ -109,7 +101,7 @@ typedef struct FFIMFMarkerResource { * IMF Composition Playlist Virtual Track */ typedef struct FFIMFBaseVirtualTrack { - FFIMFUUID id_uuid; /**< TrackId associated with the Virtual Track */ + AVUUID id_uuid; /**< TrackId associated with the Virtual Track */ } FFIMFBaseVirtualTrack; /** @@ -135,7 +127,7 @@ typedef struct FFIMFMarkerVirtualTrack { * IMF Composition Playlist */ typedef struct FFIMFCPL { - FFIMFUUID id_uuid; /**< CompositionPlaylist/Id element */ + AVUUID id_uuid; /**< CompositionPlaylist/Id element */ xmlChar *content_title_utf8; /**< CompositionPlaylist/ContentTitle element */ AVRational edit_rate; /**< CompositionPlaylist/EditRate element */ FFIMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual Track */ @@ -196,7 +188,7 @@ int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational); * Reads a UUID from an XML element * @return 0 on success, < 0 AVERROR code on error. */ -int ff_imf_xml_read_uuid(xmlNodePtr element, uint8_t uuid[16]); +int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid); /** * Returns the first child element with the specified local name diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c index 102a6b4549..4acc20feee 100644 --- a/libavformat/imf_cpl.c +++ b/libavformat/imf_cpl.c @@ -70,32 +70,14 @@ xmlNodePtr ff_imf_xml_get_child_element_by_name(xmlNodePtr parent, const char *n return NULL; } -int ff_imf_xml_read_uuid(xmlNodePtr element, uint8_t uuid[16]) +int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid) { xmlChar *element_text = NULL; - int scanf_ret; int ret = 0; element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1); - scanf_ret = sscanf(element_text, - FF_IMF_UUID_FORMAT, - &uuid[0], - &uuid[1], - &uuid[2], - &uuid[3], - &uuid[4], - &uuid[5], - &uuid[6], - &uuid[7], - &uuid[8], - &uuid[9], - &uuid[10], - &uuid[11], - &uuid[12], - &uuid[13], - &uuid[14], - &uuid[15]); - if (scanf_ret != 16) { + ret = av_uuid_urn_parse(element_text, uuid); + if (ret) { av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n"); ret = AVERROR_INVALIDDATA; } @@ -370,7 +352,7 @@ static int fill_marker_resource(xmlNodePtr marker_resource_elem, static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl) { int ret = 0; - uint8_t uuid[16]; + AVUUID uuid; xmlNodePtr resource_list_elem = NULL; xmlNodePtr resource_elem = NULL; xmlNodePtr track_id_elem = NULL; @@ -388,8 +370,8 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl) } av_log(NULL, AV_LOG_DEBUG, - "Processing IMF CPL Marker Sequence for Virtual Track " FF_IMF_UUID_FORMAT "\n", - UID_ARG(uuid)); + "Processing IMF CPL Marker Sequence for Virtual Track " AV_PRI_UUID "\n", + AV_UUID_ARG(uuid)); /* create main marker virtual track if it does not exist */ if (!cpl->main_markers_track) { @@ -397,9 +379,9 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl) if (!cpl->main_markers_track) return AVERROR(ENOMEM); imf_marker_virtual_track_init(cpl->main_markers_track); - memcpy(cpl->main_markers_track->base.id_uuid, uuid, sizeof(uuid)); + av_uuid_copy(cpl->main_markers_track->base.id_uuid, uuid); - } else if (memcmp(cpl->main_markers_track->base.id_uuid, uuid, sizeof(uuid)) != 0) { + } else if (!av_uuid_equal(cpl->main_markers_track->base.id_uuid, uuid)) { av_log(NULL, AV_LOG_ERROR, "Multiple marker virtual tracks were found\n"); return AVERROR_INVALIDDATA; } @@ -457,7 +439,7 @@ static int has_stereo_resources(xmlNodePtr element) static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cpl) { int ret = 0; - uint8_t uuid[16]; + AVUUID uuid; xmlNodePtr resource_list_elem = NULL; xmlNodePtr resource_elem = NULL; xmlNodePtr track_id_elem = NULL; @@ -476,12 +458,12 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp } av_log(NULL, AV_LOG_DEBUG, - "Processing IMF CPL Audio Sequence for Virtual Track " FF_IMF_UUID_FORMAT "\n", - UID_ARG(uuid)); + "Processing IMF CPL Audio Sequence for Virtual Track " AV_PRI_UUID "\n", + AV_UUID_ARG(uuid)); /* get the main audio virtual track corresponding to the sequence */ for (uint32_t i = 0; i < cpl->main_audio_track_count; i++) { - if (memcmp(cpl->main_audio_tracks[i].base.id_uuid, uuid, sizeof(uuid)) == 0) { + if (av_uuid_equal(cpl->main_audio_tracks[i].base.id_uuid, uuid)) { vt = &cpl->main_audio_tracks[i]; break; } @@ -501,7 +483,7 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp vt = &cpl->main_audio_tracks[cpl->main_audio_track_count]; imf_trackfile_virtual_track_init(vt); cpl->main_audio_track_count++; - memcpy(vt->base.id_uuid, uuid, sizeof(uuid)); + av_uuid_copy(vt->base.id_uuid, uuid); } /* process resources */ @@ -544,7 +526,7 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL *cpl) { int ret = 0; - uint8_t uuid[16]; + AVUUID uuid; xmlNodePtr resource_list_elem = NULL; xmlNodePtr resource_elem = NULL; xmlNodePtr track_id_elem = NULL; @@ -573,16 +555,16 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL if (!cpl->main_image_2d_track) return AVERROR(ENOMEM); imf_trackfile_virtual_track_init(cpl->main_image_2d_track); - memcpy(cpl->main_image_2d_track->base.id_uuid, uuid, sizeof(uuid)); + av_uuid_copy(cpl->main_image_2d_track->base.id_uuid, uuid); - } else if (memcmp(cpl->main_image_2d_track->base.id_uuid, uuid, sizeof(uuid)) != 0) { + } else if (!av_uuid_equal(cpl->main_image_2d_track->base.id_uuid, uuid)) { av_log(NULL, AV_LOG_ERROR, "Multiple MainImage virtual tracks found\n"); return AVERROR_INVALIDDATA; } av_log(NULL, AV_LOG_DEBUG, - "Processing IMF CPL Main Image Sequence for Virtual Track " FF_IMF_UUID_FORMAT "\n", - UID_ARG(uuid)); + "Processing IMF CPL Main Image Sequence for Virtual Track " AV_PRI_UUID "\n", + AV_UUID_ARG(uuid)); /* process resources */ resource_list_elem = ff_imf_xml_get_child_element_by_name(image_sequence_elem, "ResourceList"); @@ -746,7 +728,7 @@ static void imf_trackfile_virtual_track_free(FFIMFTrackFileVirtualTrack *vt) static void imf_cpl_init(FFIMFCPL *cpl) { - memset(cpl->id_uuid, 0, sizeof(cpl->id_uuid)); + av_uuid_nil(cpl->id_uuid); cpl->content_title_utf8 = NULL; cpl->edit_rate = av_make_q(0, 1); cpl->main_markers_track = NULL; @@ -828,8 +810,8 @@ int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl) (*cpl)->content_title_utf8); av_log(NULL, AV_LOG_INFO, - "IMF CPL Id: " FF_IMF_UUID_FORMAT "\n", - UID_ARG((*cpl)->id_uuid)); + "IMF CPL Id: " AV_PRI_UUID "\n", + AV_UUID_ARG((*cpl)->id_uuid)); } xmlFreeDoc(doc); diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index 4019249f3e..71dfb26958 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -82,7 +82,7 @@ * IMF Asset locator */ typedef struct IMFAssetLocator { - FFIMFUUID uuid; + AVUUID uuid; char *absolute_uri; } IMFAssetLocator; @@ -238,7 +238,7 @@ static int parse_imf_asset_map_from_xml_dom(AVFormatContext *s, return AVERROR_INVALIDDATA; } - av_log(s, AV_LOG_DEBUG, "Found asset id: " FF_IMF_UUID_FORMAT "\n", UID_ARG(asset->uuid)); + av_log(s, AV_LOG_DEBUG, "Found asset id: " AV_PRI_URN_UUID "\n", AV_UUID_ARG(asset->uuid)); if (!(node = ff_imf_xml_get_child_element_by_name(asset_element, "ChunkList"))) { av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing ChunkList node\n"); @@ -343,7 +343,7 @@ clean_up: return ret; } -static IMFAssetLocator *find_asset_map_locator(IMFAssetLocatorMap *asset_map, FFIMFUUID uuid) +static IMFAssetLocator *find_asset_map_locator(IMFAssetLocatorMap *asset_map, AVUUID uuid) { for (uint32_t i = 0; i < asset_map->asset_count; i++) { if (memcmp(asset_map->assets[i].uuid, uuid, 16) == 0) @@ -453,15 +453,15 @@ static int open_track_file_resource(AVFormatContext *s, asset_locator = find_asset_map_locator(&c->asset_locator_map, track_file_resource->track_file_uuid); if (!asset_locator) { - av_log(s, AV_LOG_ERROR, "Could not find asset locator for UUID: " FF_IMF_UUID_FORMAT "\n", - UID_ARG(track_file_resource->track_file_uuid)); + av_log(s, AV_LOG_ERROR, "Could not find asset locator for UUID: " AV_PRI_URN_UUID "\n", + AV_UUID_ARG(track_file_resource->track_file_uuid)); return AVERROR_INVALIDDATA; } av_log(s, AV_LOG_DEBUG, - "Found locator for " FF_IMF_UUID_FORMAT ": %s\n", - UID_ARG(asset_locator->uuid), + "Found locator for " AV_PRI_URN_UUID ": %s\n", + AV_UUID_ARG(asset_locator->uuid), asset_locator->absolute_uri); if (track->resource_count > INT32_MAX - track_file_resource->base.repeat_count @@ -523,14 +523,14 @@ static int open_virtual_track(AVFormatContext *s, for (uint32_t i = 0; i < virtual_track->resource_count; i++) { av_log(s, AV_LOG_DEBUG, - "Open stream from file " FF_IMF_UUID_FORMAT ", stream %d\n", - UID_ARG(virtual_track->resources[i].track_file_uuid), + "Open stream from file " AV_PRI_URN_UUID ", stream %d\n", + AV_UUID_ARG(virtual_track->resources[i].track_file_uuid), i); if ((ret = open_track_file_resource(s, &virtual_track->resources[i], track)) != 0) { av_log(s, AV_LOG_ERROR, - "Could not open image track resource " FF_IMF_UUID_FORMAT "\n", - UID_ARG(virtual_track->resources[i].track_file_uuid)); + "Could not open image track resource " AV_PRI_URN_UUID "\n", + AV_UUID_ARG(virtual_track->resources[i].track_file_uuid)); goto clean_up; } } @@ -604,16 +604,16 @@ static int open_cpl_tracks(AVFormatContext *s) if (c->cpl->main_image_2d_track) { if ((ret = open_virtual_track(s, c->cpl->main_image_2d_track, track_index++)) != 0) { - av_log(s, AV_LOG_ERROR, "Could not open image track " FF_IMF_UUID_FORMAT "\n", - UID_ARG(c->cpl->main_image_2d_track->base.id_uuid)); + av_log(s, AV_LOG_ERROR, "Could not open image track " AV_PRI_URN_UUID "\n", + AV_UUID_ARG(c->cpl->main_image_2d_track->base.id_uuid)); return ret; } } for (uint32_t i = 0; i < c->cpl->main_audio_track_count; i++) { if ((ret = open_virtual_track(s, &c->cpl->main_audio_tracks[i], track_index++)) != 0) { - av_log(s, AV_LOG_ERROR, "Could not open audio track " FF_IMF_UUID_FORMAT "\n", - UID_ARG(c->cpl->main_audio_tracks[i].base.id_uuid)); + av_log(s, AV_LOG_ERROR, "Could not open audio track " AV_PRI_URN_UUID "\n", + AV_UUID_ARG(c->cpl->main_audio_tracks[i].base.id_uuid)); return ret; } } @@ -647,8 +647,8 @@ static int imf_read_header(AVFormatContext *s) av_log(s, AV_LOG_DEBUG, - "parsed IMF CPL: " FF_IMF_UUID_FORMAT "\n", - UID_ARG(c->cpl->id_uuid)); + "parsed IMF CPL: " AV_PRI_URN_UUID "\n", + AV_UUID_ARG(c->cpl->id_uuid)); if (!c->asset_map_paths) { c->asset_map_paths = av_append_path_component(c->base_url, "ASSETMAP.xml"); diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c index 142aa04261..e65629ccbc 100644 --- a/libavformat/tests/imf.c +++ b/libavformat/tests/imf.c @@ -304,7 +304,7 @@ static int test_cpl_parsing(void) } printf("%s\n", cpl->content_title_utf8); - printf(FF_IMF_UUID_FORMAT "\n", UID_ARG(cpl->id_uuid)); + printf(AV_PRI_URN_UUID "\n", AV_UUID_ARG(cpl->id_uuid)); printf("%i %i\n", cpl->edit_rate.num, cpl->edit_rate.den); printf("Marker resource count: %" PRIu32 "\n", cpl->main_markers_track->resource_count); @@ -320,7 +320,7 @@ static int test_cpl_parsing(void) printf("Main image resource count: %" PRIu32 "\n", cpl->main_image_2d_track->resource_count); for (uint32_t i = 0; i < cpl->main_image_2d_track->resource_count; i++) { printf("Track file resource %" PRIu32 "\n", i); - printf(" " FF_IMF_UUID_FORMAT "\n", UID_ARG(cpl->main_image_2d_track->resources[i].track_file_uuid)); + printf(" " AV_PRI_URN_UUID "\n", AV_UUID_ARG(cpl->main_image_2d_track->resources[i].track_file_uuid)); } printf("Main audio track count: %" PRIu32 "\n", cpl->main_audio_track_count); @@ -329,7 +329,7 @@ static int test_cpl_parsing(void) printf(" Main audio resource count: %" PRIu32 "\n", cpl->main_audio_tracks[i].resource_count); for (uint32_t j = 0; j < cpl->main_audio_tracks[i].resource_count; j++) { printf(" Track file resource %" PRIu32 "\n", j); - printf(" " FF_IMF_UUID_FORMAT "\n", UID_ARG(cpl->main_audio_tracks[i].resources[j].track_file_uuid)); + printf(" " AV_PRI_URN_UUID "\n", AV_UUID_ARG(cpl->main_audio_tracks[i].resources[j].track_file_uuid)); } } @@ -363,15 +363,15 @@ static int test_bad_cpl_parsing(void) static int check_asset_locator_attributes(IMFAssetLocator *asset, IMFAssetLocator *expected_asset) { - printf("\tCompare " FF_IMF_UUID_FORMAT " to " FF_IMF_UUID_FORMAT ".\n", - UID_ARG(asset->uuid), - UID_ARG(expected_asset->uuid)); + printf("\tCompare " AV_PRI_URN_UUID " to " AV_PRI_URN_UUID ".\n", + AV_UUID_ARG(asset->uuid), + AV_UUID_ARG(expected_asset->uuid)); for (uint32_t i = 0; i < 16; ++i) { if (asset->uuid[i] != expected_asset->uuid[i]) { - printf("Invalid asset locator UUID: found " FF_IMF_UUID_FORMAT " instead of " FF_IMF_UUID_FORMAT " expected.\n", - UID_ARG(asset->uuid), - UID_ARG(expected_asset->uuid)); + printf("Invalid asset locator UUID: found " AV_PRI_URN_UUID " instead of " AV_PRI_URN_UUID " expected.\n", + AV_UUID_ARG(asset->uuid), + AV_UUID_ARG(expected_asset->uuid)); return 1; } } From patchwork Thu Jun 2 00:30:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 36042 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp3739259pzj; Wed, 1 Jun 2022 17:31:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz151hM9FAik8wYFOM/88Hpec9CwPcXj1NwCdYCI8rmAsxkTtAFH9LC1TSTWbRqN1bBwxPM X-Received: by 2002:a17:907:da3:b0:6fe:f08b:776 with SMTP id go35-20020a1709070da300b006fef08b0776mr1997731ejc.558.1654129907610; Wed, 01 Jun 2022 17:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654129907; cv=none; d=google.com; s=arc-20160816; b=OadDZi0Gxu5DQIhC32ciwz3XJN9qtxL5tIEoeSsuzmHQU3kV3fA3fuIddNMHgyO93f HN6v1ZqBw0cy+5uwZiGhKYsjTNq7ZML7uzoC9t0q++xnWEfmc6FeQLNji74Ngm9OUR2q oyY/33z7K+00CU19RZHXJXB+q3m66aGCNkqYobQASHFdO7rgUhx/pZTLLZZcktCEk/ho KFeGZLVc258rgNQQfft2WnUHVGwgSq1zXyqcglc52wItrU6c5ANujazPf2daR72NOBKN Hw+FX+EpVjzTDvw+VLIM4HenEWBbb0n9Qn6BIv99aHGR69eYCG3icomVAYOo9p3qR4/A Qrjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=XWcceDSo/1xFAx8zLTBiXZcXH51nl0PcWxCzR83IZps=; b=gxC4rqjZb14FP8+UOPtAJPVM+aBzZPWtMeD7/hd5R4+YSTWdMa9pR0jMBgFWKe4ok+ Nod9Y+AhZxqt3vR/bhDhzhowPVZcgM+XsV8ukYypsqfaSGo+ipUonXwNqDu5IalMmH1i nT8Ssub42ubTOc3Zegn6/l8BLofbmg6QCp7BYQCBZGEByF+vy3mUKiqehhHvgU67jwOq my/p/HPYFYZdT3SBdY1Ixxb+tboW0lD7owZDBBRAbyje9iOLt6VDmf6XusQJSHW4zpEg iM2G5eXGaAdsFk3j++7dCQCBqCGy34wP8slvlQeg/OL/WCMi5zQrtpe/+AJHaLPaU23E NXlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ho37-20020a1709070ea500b00702fffc2f45si4269428ejc.705.2022.06.01.17.31.47; Wed, 01 Jun 2022 17:31:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A3A068B7E6; Thu, 2 Jun 2022 03:31:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 390D968B7B9 for ; Thu, 2 Jun 2022 03:30:59 +0300 (EEST) Received: by mail-pl1-f180.google.com with SMTP id s14so3179274plk.8 for ; Wed, 01 Jun 2022 17:30:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=unZSWE+dzJYc0z/tPuP/nXrJrd/oMKbTb0kbc98ykQM=; b=x6KfVYGBDm2sqeXvxle6ibb24IR/0hXv4CFkBGhoeRcGZq65B9HR4NhxXX/k+WQmY7 GVh3c/SupPliMbnrsqDnxBNGp8LhvXOd06fw1e05xBc6sKVWk0m9Rt0bxsLtQEgjgKZs 9m2UftTQRO81aiNRIi2eMLNPjxllnbM6v9qzvQS61oFBSKddFQie7K+X+igezUH+iJwz gmCXEGKKL5inXOJvRfC4WtHhFnxcjwI3PPD2EdDB/aZBzFAi6IN3MIALWidVCQSeDGQA +So+euAgEg078ButI1H0oJ4bap9o+0wujtcukUmsZVDMQmVMunGb8vXd/t9erVjt44/2 IuvA== X-Gm-Message-State: AOAM533G2kmTFGhFoW+mma6h7Hy9wYh0VLzoUMzauivxC4NidqO333hc 1lhQEMQ1koXYrr0iSjnvNkRFkCUp+YQ= X-Received: by 2002:a17:902:7594:b0:15e:bbac:8d49 with SMTP id j20-20020a170902759400b0015ebbac8d49mr2051713pll.124.1654129857094; Wed, 01 Jun 2022 17:30:57 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id p10-20020a170902780a00b0016417aac283sm2165292pll.181.2022.06.01.17.30.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 17:30:56 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Wed, 01 Jun 2022 17:30:51 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Jun 2022 17:30:37 -0700 Message-Id: <20220602003037.24597-6-pal@sandflow.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602003037.24597-1-pal@sandflow.com> References: <20220602003037.24597-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 6/6] avfilter/showinfo: refactor to use avutil/uuid X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Pierre-Anthony Lemieux Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QYOZVPh7gfs9 From: Pierre-Anthony Lemieux --- libavfilter/vf_showinfo.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 12d39310ef..6efcafce28 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -42,6 +42,7 @@ #include "libavutil/mastering_display_metadata.h" #include "libavutil/video_enc_params.h" #include "libavutil/detection_bbox.h" +#include "libavutil/uuid.h" #include "avfilter.h" #include "internal.h" @@ -421,29 +422,20 @@ static void dump_video_enc_params(AVFilterContext *ctx, const AVFrameSideData *s static void dump_sei_unregistered_metadata(AVFilterContext *ctx, const AVFrameSideData *sd) { - const int uuid_size = 16; const uint8_t *user_data = sd->data; - int i; - if (sd->size < uuid_size) { + if (sd->size < AV_UUID_LEN) { av_log(ctx, AV_LOG_ERROR, "invalid data(%"SIZE_SPECIFIER" < " - "UUID(%d-bytes))\n", sd->size, uuid_size); + "UUID(%d-bytes))\n", sd->size, AV_UUID_LEN); return; } av_log(ctx, AV_LOG_INFO, "User Data Unregistered:\n"); - av_log(ctx, AV_LOG_INFO, "UUID="); - for (i = 0; i < uuid_size; i++) { - av_log(ctx, AV_LOG_INFO, "%02x", user_data[i]); - if (i == 3 || i == 5 || i == 7 || i == 9) - av_log(ctx, AV_LOG_INFO, "-"); - } - av_log(ctx, AV_LOG_INFO, "\n"); + av_log(ctx, AV_LOG_INFO, "UUID=" AV_PRI_UUID "\n", AV_UUID_ARG(user_data)); av_log(ctx, AV_LOG_INFO, "User Data="); - for (; i < sd->size; i++) { + for (size_t i = 16; i < sd->size; i++) av_log(ctx, AV_LOG_INFO, "%02x", user_data[i]); - } av_log(ctx, AV_LOG_INFO, "\n"); }