From patchwork Wed Oct 20 14:53:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 31170 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp1563581ioa; Wed, 20 Oct 2021 07:54:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygGGMAClYbmxVbiynNDIea92HwqqOamzmBwYzSS6c9FktvYKGsScg3mmAf7YzlQ6UwdZvC X-Received: by 2002:a05:6402:5215:: with SMTP id s21mr557369edd.113.1634741677875; Wed, 20 Oct 2021 07:54:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634741677; cv=none; d=google.com; s=arc-20160816; b=cLFEeGg3WlOfso1/XX0+zJDA3x8KfrmTNw+PywbvFe8qsnrgwbcdl4EPUEboynBKJ+ ZtiMHX/mxbqcNUfsLv8vHL9mJICaOimIPodhdQWs0KLnhpcQvlGtnvJppp5Dq+jXEaOL 0uRKRG48AFB50z/C5Z0CsQJXtjTrr9HNLqYzLAY1HQyi6vzErueWRw1GhCd2ZhmVYDin dyMVK6AtqNTYw6Qgn9oyoSgwdC993cNPQq5c+/pjjmwMWUZlbMjjiueFxsj6Zn2nyY82 OBfCBO8/gQn9OrYDIdfs16Hr/EfeRKtXPJsSU4fie2mgFrfywCskOOZqvf0xZ/k3DjTH lXyQ== 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=WQsoi/jnv6Z7jP7KI3IEHCK7PWevruxhjE13JzDBV5k=; b=sKXzMOs56fDTjeWAx5497XrEpJr35pjAhkuM2riALjpj4o2zD9Fkmc+eM68+JNBwvY eU3AFNd9WZwW4t7QRAdngeTAhG4il21BZE+Zk7Aux4pZjgjYOTgo+XOvje2xcSFQPR7c Zt9HlUgQ6ifh1OFcqCiLzpO8pzSfn45A9T0MeLG6orVTgThguvZhvTSkanRBIfJqDG52 qH5BtLI++uvC/8zGytwyAXcmnDYmgGrcTuHSaUQw3RIUqiAAAf2C54C9aRO3RwizybU7 rDUddcpTcCsf0hguElgLVzyrHRPJ41AihnP/vJtVjsO5hqfTXAlhNnvmcz+1MfOeYqlH EDfw== 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 mq22si3010188ejc.734.2021.10.20.07.54.37; Wed, 20 Oct 2021 07:54: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 B1DFC68A7C8; Wed, 20 Oct 2021 17:54:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D5D4468A498 for ; Wed, 20 Oct 2021 17:54:26 +0300 (EEST) Received: by mail-pj1-f41.google.com with SMTP id pi19-20020a17090b1e5300b0019fdd3557d3so2611322pjb.5 for ; Wed, 20 Oct 2021 07:54:26 -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=xeO4qdkLHzjMK8NEG2B3s8845f4t4XoCpJiVq/sCRtQ=; b=qnhqNbIYz8q9FnZmF1IBHc3dSCsVdov6L/w+kgXa3ICUDva2GJusWUW4M1heVoFqiS 90X9EbzJyKcDbJi6ADFHWBqtyD0JSqurkzotUsIQ01p7Fj+DYGChQSuhaJDDgUByt39K MsQHjPXpdIvpj2DAfknB7g+6fT/cci8D+2c4mtcgz0de9JijyRa0fsLPyYtSqDaZ2kKK OY3RQe8KHuFIb0HWbZ/o3X9vkcbmCCQke/OphcvYkAAErr9woEL33WVmqSymcMbp5l7+ 8dGLWM8cdlopwKIhohEzbnP4VdyMh2c45/eo4S3DwwzgKgqAGvqNFMLCsMJLFlJnktEt paXQ== X-Gm-Message-State: AOAM531LtnsoBCWuzln6/AqNXMDqIjWe7fV+30knZ7MfttSRPUrenWrr VVSkoOteXyMuTUtx5d+PawAts7j+6rw= X-Received: by 2002:a17:902:db0e:b0:13e:f4d3:84c with SMTP id m14-20020a170902db0e00b0013ef4d3084cmr39449805plx.2.1634741664445; Wed, 20 Oct 2021 07:54:24 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id mu7sm3127720pjb.12.2021.10.20.07.54.22 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Oct 2021 07:54:23 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Wed, 20 Oct 2021 07:54:14 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 20 Oct 2021 07:53:32 -0700 Message-Id: <20211020145336.19725-1-pal@sandflow.com> X-Mailer: git-send-email 2.33.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avformat/imf: Headers 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: 98tm4kOJz4ol From: Pierre-Anthony Lemieux Signed-off-by: Pierre-Anthony Lemieux --- Notes: The IMF demuxer accepts as input an IMF CPL. The assets referenced by the CPL can be contained in multiple deliveries, each defined by an ASSETMAP file: ffmpeg -assetmaps ,,... -i If -assetmaps is not specified, FFMPEG looks for a file called ASSETMAP.xml in the same directory as the CPL. EXAMPLE: ffmpeg -i http://ffmpeg-imf-samples-public.s3-website-us-west-1.amazonaws.com/countdown/CPL_f5095caa-f204-4e1c-8a84-7af48c7ae16b.xml out.mp4 The Interoperable Master Format (IMF) is a file-based media format for the delivery and storage of professional audio-visual masters. An IMF Composition consists of an XML playlist (the Composition Playlist) and a collection of MXF files (the Track Files). The Composition Playlist (CPL) assembles the Track Files onto a timeline, which consists of multiple tracks. The location of the Track Files referenced by the Composition Playlist is stored in one or more XML documents called Asset Maps. More details at https://www.imfug.com/explainer. The IMF standard was first introduced in 2013 and is managed by the SMPTE. Public and private header files. The functions and constants in imf.h are intended to be useable by other modules. CHANGE NOTES: - fixed patchwork warnings - updated patch notes - added LGPL license libavformat/imf.h | 170 +++++++++++++++++++++++++++++++++++++ libavformat/imf_internal.h | 114 +++++++++++++++++++++++++ 2 files changed, 284 insertions(+) create mode 100644 libavformat/imf.h create mode 100644 libavformat/imf_internal.h diff --git a/libavformat/imf.h b/libavformat/imf.h new file mode 100644 index 0000000000..162662e607 --- /dev/null +++ b/libavformat/imf.h @@ -0,0 +1,170 @@ +/* + * Copyright (c) Sandflow Consulting LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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 ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * 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 + */ + +/** + * Public header file for the processing of Interoperable Master Format (IMF) packages. + * + * @author Pierre-Anthony Lemieux + * @file + * @ingroup lavu_imf + */ + +#ifndef AVFORMAT_IMF_H +#define AVFORMAT_IMF_H + +#include "avformat.h" +#include "libavformat/avio.h" +#include "libavutil/rational.h" +#include + +/** + * UUID as defined in IETF RFC 422 + */ +typedef uint8_t UUID[16]; + +/** + * IMF Composition Playlist Base Resource + */ +typedef struct IMFBaseResource { + AVRational edit_rate; /**< BaseResourceType/EditRate */ + unsigned long entry_point; /**< BaseResourceType/EntryPoint */ + unsigned long duration; /**< BaseResourceType/Duration */ + unsigned long repeat_count; /**< BaseResourceType/RepeatCount */ +} IMFBaseResource; + +/** + * IMF Composition Playlist Track File Resource + */ +typedef struct IMFTrackFileResource { + IMFBaseResource base; + UUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */ +} IMFTrackFileResource; + +/** + * IMF Marker + */ +typedef struct IMFMarker { + xmlChar *label_utf8; /**< Marker/Label */ + xmlChar *scope_utf8; /**< Marker/Label/\@scope */ + unsigned long offset; /**< Marker/Offset */ +} IMFMarker; + +/** + * IMF Composition Playlist Marker Resource + */ +typedef struct IMFMarkerResource { + IMFBaseResource base; + unsigned long marker_count; /**< Number of Marker elements */ + IMFMarker *markers; /**< Marker elements */ +} IMFMarkerResource; + +/** + * IMF Composition Playlist Virtual Track + */ +typedef struct IMFBaseVirtualTrack { + UUID id_uuid; /**< TrackId associated with the Virtual Track */ +} IMFBaseVirtualTrack; + +/** + * IMF Composition Playlist Virtual Track that consists of Track File Resources + */ +typedef struct IMFTrackFileVirtualTrack { + IMFBaseVirtualTrack base; + unsigned long resource_count; /**< Number of Resource elements present in the Virtual Track */ + IMFTrackFileResource *resources; /**< Resource elements of the Virtual Track */ +} IMFTrackFileVirtualTrack; + +/** + * IMF Composition Playlist Virtual Track that consists of Marker Resources + */ +typedef struct IMFMarkerVirtualTrack { + IMFBaseVirtualTrack base; + unsigned long resource_count; /**< Number of Resource elements present in the Virtual Track */ + IMFMarkerResource *resources; /**< Resource elements of the Virtual Track */ +} IMFMarkerVirtualTrack; + +/** + * IMF Composition Playlist + */ +typedef struct IMFCPL { + UUID id_uuid; /**< CompositionPlaylist/Id element */ + xmlChar *content_title_utf8; /**< CompositionPlaylist/ContentTitle element */ + AVRational edit_rate; /**< CompositionPlaylist/EditRate element */ + IMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual Track */ + IMFTrackFileVirtualTrack *main_image_2d_track; /**< Main Image Virtual Track */ + unsigned long main_audio_track_count; /**< Number of Main Audio Virtual Tracks */ + IMFTrackFileVirtualTrack *main_audio_tracks; /**< Main Audio Virtual Tracks */ +} IMFCPL; + +/** + * Parse an IMF CompositionPlaylist element into the IMFCPL data structure. + * @param[in] doc An XML document from which the CPL is read. + * @param[out] cpl Pointer to a memory area (allocated by the client), where the function writes a pointer to the newly constructed + * IMFCPL structure (or NULL if the CPL could not be parsed). The client is responsible for freeing the IMFCPL structure using + * imf_cpl_free(). + * @return A non-zero value in case of an error. + */ +int parse_imf_cpl_from_xml_dom(xmlDocPtr doc, IMFCPL **cpl); + +/** + * Parse an IMF Composition Playlist document into the IMFCPL data structure. + * @param[in] in The context from which the CPL is read. + * @param[out] cpl Pointer to a memory area (allocated by the client), where the function writes a pointer to the newly constructed + * IMFCPL structure (or NULL if the CPL could not be parsed). The client is responsible for freeing the IMFCPL structure using + * imf_cpl_free(). + * @return A non-zero value in case of an error. + */ +int parse_imf_cpl(AVIOContext *in, IMFCPL **cpl); + +/** + * Allocates and initializes an IMFCPL data structure. + * @return A pointer to the newly constructed IMFCPL structure (or NULL if the structure could not be constructed). The client is + * responsible for freeing the IMFCPL structure using imf_cpl_free(). + */ +IMFCPL *imf_cpl_alloc(void); + +/** + * Deletes an IMFCPL data structure previously instantiated with imf_cpl_alloc(). + * @param[in] cpl The IMFCPL structure to delete. + */ +void imf_cpl_free(IMFCPL *cpl); + +#endif diff --git a/libavformat/imf_internal.h b/libavformat/imf_internal.h new file mode 100644 index 0000000000..2a8141153f --- /dev/null +++ b/libavformat/imf_internal.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) Sandflow Consulting LLC + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 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 ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * 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 + */ + +/** + * Private header file for the processing of Interoperable Master Format (IMF) packages. + * + * @author Pierre-Anthony Lemieux + * @author Valentin Noel + * @file + * @ingroup lavu_imf + */ + +#ifndef AVFORMAT_IMF_INTERNAL_H +#define AVFORMAT_IMF_INTERNAL_H + +#include "libavformat/avio.h" +#include "libavutil/rational.h" +#include + +#define UUID_FORMAT "urn:uuid:%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" +#define AVRATIONAL_FORMAT "%d/%d" +#define AVRATIONAL_ARG(rational) rational.num, rational.den + +/** + * IMF Asset locator + */ +typedef struct IMFAssetLocator { + UUID uuid; + const char *absolute_uri; +} IMFAssetLocator; + +/** + * IMF Asset locator map + * Results from the parsing of one or more ASSETMAP XML files + */ +typedef struct IMFAssetLocatorMap { + uint8_t asset_count; + IMFAssetLocator **assets; +} IMFAssetLocatorMap; + +int xml_read_ulong(xmlNodePtr element, unsigned long *number); + +int xml_read_rational(xmlNodePtr element, AVRational *rational); + +int xml_read_UUID(xmlNodePtr element, uint8_t uuid[16]); + +xmlNodePtr xml_get_child_element_by_name(xmlNodePtr parent, const char *name_utf8); + +/** + * Parse a ASSETMAP XML file to extract the UUID-URI mapping of assets. + * @param s the current format context, if any (can be NULL). + * @param doc the XML document to be parsed. + * @param asset_map pointer on the IMFAssetLocatorMap pointer to fill. + * @param base_url the url of the asset map XML file, if any (can be NULL). + * @return a negative value in case of error, 0 otherwise. + */ +int parse_imf_asset_map_from_xml_dom(AVFormatContext *s, xmlDocPtr doc, IMFAssetLocatorMap **asset_map, const char *base_url); + +/** + * Allocate a IMFAssetLocatorMap pointer and return it. + * @return the allocated IMFAssetLocatorMap pointer. + */ +IMFAssetLocatorMap *imf_asset_locator_map_alloc(void); + +/** + * Free a IMFAssetLocatorMap pointer. + */ +void imf_asset_locator_map_free(IMFAssetLocatorMap *asset_map); + +int is_url(const char *string); + +int is_unix_absolute_path(const char *string); + +int is_dos_absolute_path(const char *string); + +#endif