From patchwork Thu Sep 23 19:29:27 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: 30519 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp778288iob; Thu, 23 Sep 2021 12:29:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzr8W7n8wgYK5h2Qm/85H0h8uCIGwgm7Mw4aD1SRCYh6azJQc1BQHVLhkQ6X0700n9F6zQU X-Received: by 2002:a17:906:3699:: with SMTP id a25mr7046969ejc.452.1632425398018; Thu, 23 Sep 2021 12:29:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632425398; cv=none; d=google.com; s=arc-20160816; b=pUdQZ3Whnr7loOTXkyEy6JSJ08sf2cFxxVgW++lq3irxd8i0D9to81ChnjK94mO2uy KPLUTPGDuDGVUgKOWpvGmjRK4Lu1WkSJ2wqD2K16QrbYUu8ou+D8LuLogNziLZ2G5Ng3 rmFb9PE7YqR7gHwcwqJqtiP7rDHZ62bW9bmiuUKZaSwIaKbhQOHP3rWlI9eIC3W7/fs2 x+lAICyGFsY8FZZE7Aqa0ICrXvEWuVuYCxSClmHZXqR92TL1kq/RMXNSKxxrCeKjthM4 Id4SOnBhSEXMFeJnnq/w33+BI2LQ2I+bPPWBK2samcYVcROLAJTL69B3iTPp9n7PNXxU apmQ== 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=0qs3O0LrEVs/YidTgHkGeAuoF/1ouNJMGzLXeP6qVmw=; b=0nscDg97MyGUU3nPB2rhLyJuCwS4nhfB8cTfVL/BxCUuAQoN5dXAbqgbd0s8sj5mMf dQbVsA3U90iqZQL7oLNt5Ga6lPjKOXSUFsaYn6xDbFiuxN3DpLnkAzSqtB87ogVNuBxA 9plMQXhjP8r8HIVVrfOedShhU1pE49cneyfFCMAYcSoR4wHLmxLByWon2Wl3fX5zWf8h 3ipzmXcfHMXQA/GotrysFaZ4I2GVytyRoY4wp34IeX6hLZ/dTRsH7Z8YXupyJ/GPl5f0 8W5CqLSnZZ99O3Myr/j8UgoHTaEY8glSMJ7apDV5AHd1eZ6aXN94kZSl+9YzDeTN4Zs4 X66A== 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 5si7283271ejq.398.2021.09.23.12.29.57; Thu, 23 Sep 2021 12:29: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 E05D3689D6F; Thu, 23 Sep 2021 22:29:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D5574680AE0 for ; Thu, 23 Sep 2021 22:29:45 +0300 (EEST) Received: by mail-pg1-f173.google.com with SMTP id h3so7360461pgb.7 for ; Thu, 23 Sep 2021 12:29:45 -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=95rdVGbp60129i3yjnupA5SGvWbTWFm/cdJZRxPXw7Q=; b=qaLgnnzasKTvCAA7cHqUGH8gePjjyesMmJZzpIzSym0gyhYWxR5o0W+54K6SgfVCZ6 QIHXiYvwIP5Ym5KEQCGhWqWPl9rVyVdZQgnoqnubzuGlUqOv7/cNX+/j06xHUQVrrk1V 6vtNd5aq3OROXO8j423Q/2Wmcitku0Is+8qEh18+dhQLdCZ4tlZQU1cAQvtHZ/cOshaR GprknxzKCugj4C5cbaEQUeK64D+HaTzsfIgIkzLZzokU07G2mty+8kqy54R4Qs6dYETF Q3Mz3x5UD9DT7ISryNa+820KGS9dYBYhQPA0byXrfZxp1gITYOvRgCzfDNujT+XW2v8u 6gHw== X-Gm-Message-State: AOAM531Q+4FkwwiYMOPsho+zhMVeV6B32qHI7GoLUxRUN7yQblLhsb3K se2HNboAuqyUa8gAZUtxbhFGJqs2JZ8= X-Received: by 2002:a05:6a00:a10:b0:412:448c:89c7 with SMTP id p16-20020a056a000a1000b00412448c89c7mr5857512pfh.83.1632425383589; Thu, 23 Sep 2021 12:29:43 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id i5sm9458508pjk.47.2021.09.23.12.29.41 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 23 Sep 2021 12:29:43 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Thu, 23 Sep 2021 12:29:34 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Sep 2021 12:29:27 -0700 Message-Id: <20210923192931.24829-1-pal@sandflow.com> X-Mailer: git-send-email 2.32.0.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] [IMF demuxer] 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: X00bC81OIVAv From: Pierre-Anthony Lemieux Signed-off-by: Pierre-Anthony Lemieux --- Notes: Public and private header files for the IMF demuxer. The functions and constants defines in the public header file imf.h can be used by other modules. 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. libavformat/imf.h | 156 +++++++++++++++++++++++++++++++++++++ libavformat/imf_internal.h | 100 ++++++++++++++++++++++++ 2 files changed, 256 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..8162cbc031 --- /dev/null +++ b/libavformat/imf.h @@ -0,0 +1,156 @@ +/* + * This file is part of FFmpeg. + * + * 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. + */ + +/** + * 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..a631497920 --- /dev/null +++ b/libavformat/imf_internal.h @@ -0,0 +1,100 @@ +/* + * This file is part of FFmpeg. + * + * 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. + */ + +/** + * 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