From patchwork Thu Oct 7 23:41:22 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: 30979 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp304134ioa; Thu, 7 Oct 2021 16:41:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYOcveAMgYKUHikgOurHU1bVBMsXmxPzx/rLmqxdpCgw+oE7wJsE2DH99eds/Uyj3iZaZi X-Received: by 2002:a17:906:6844:: with SMTP id a4mr9177852ejs.65.1633650113856; Thu, 07 Oct 2021 16:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633650113; cv=none; d=google.com; s=arc-20160816; b=mg3geOzNQ/EcrrRdgQ2+M8QKdAIPuJt2mOAnHaD//rpjuPMG98VEC6w7AO0VVw5zYN mkyHWEJM2mk8TxTKF30ReOeV4rqvhao9S3t3+OIdm5e5ZReAYApq70so4fbACeq8xxVR HbH14cT1+G2ue7D/q+x/FpD+0xNhRY1b6fWqZotqQj0AoIy4d0Kdi+rOqC2yv2CBMhrs rOblXtXhE3nRdd1mlzDD59QMxN9RqhCYjAD1Zl56s0ghSqz0XbPup7T+4zHnvzAsY8R4 C+mEkWnlgfJO5b02mRUorAHzDXb2/n/Ax7HhHjbynm7u6ygagLE6knqKD9FMqKvgk7Qx dDZg== 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=cdgybodbNjP1xNDQq1oqvjlEFAi1Cnw5vUoH3o4l9lX5U+XWu2JMx1MzH2PxH3xqC3 qORzNzmSjuH8z8OAXQ3NsvnmzuUKW3X9g03fcaIegV2Kgio1gVoZUz6QdMV+a+sKXMWn eclvTu3KtKxINjinHm1OnDm7QtbVehbUFTr5dEe9576yC6K/imo114W00FKGRDOkPnWe FiSH+7UeGepLnp+DxKxB7Y4/qwuVItgOwUOvJBAHZ6VgmH6teZPYkzMwo2hyNS1CssAz inpwX8UnCxk2vfHXBLh64n4+ljYr61Cg3d8eQ1HMh8SbjTvYTwQY0SkhnjadRyZNRZlY SbnA== 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 gk1si1418191ejc.31.2021.10.07.16.41.53; Thu, 07 Oct 2021 16:41:53 -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 71F31680923; Fri, 8 Oct 2021 02:41:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BDB7F680226 for ; Fri, 8 Oct 2021 02:41:42 +0300 (EEST) Received: by mail-pl1-f174.google.com with SMTP id j15so4985183plh.7 for ; Thu, 07 Oct 2021 16:41:42 -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=MQtB+BmWobLPxCH9qw1po3MaSIt/4CU391/LDIur3aH2tSV3itKRkjvBnWoRxww6Q1 zlyIvhCl/OrAKIcJ+j98V//UVmM1gLA6I8Dx4L2CcqhW954rbF6KQF+CXx0av70rOAt9 hWzafa5+kZ8Y2O69c+o/GoUgF6q39UfvoFT+pWqAPVJOVwCVKxaj9raQ0shAsqV5kUDP yT33ImoXQSsQpNEgeUpnRu38mL8Mw20OyQq/2JglBWt5HZZ0Qwbwuz/UZavDF4oRRyKY tzk2aGtGzeVUssd6lUk8gmCn7XwjhX5/EDIroytKcR4hqNePD7LKIeEU/BTlpYzuMLpw QSUg== X-Gm-Message-State: AOAM5320Ok+IDBKTGhTsYZLgEwiYeq3lwgqI0Fwf/aFqkQr/KDI0MRYl QHF2/egfI5oyDk3/w+j3zWPUqHAAiss= X-Received: by 2002:a17:902:a381:b0:13d:f97d:74d0 with SMTP id x1-20020a170902a38100b0013df97d74d0mr6495796pla.61.1633650100546; Thu, 07 Oct 2021 16:41:40 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id o11sm7756060pjp.0.2021.10.07.16.41.38 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 16:41:40 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Thu, 07 Oct 2021 16:41:33 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Oct 2021 16:41:22 -0700 Message-Id: <20211007234126.5353-1-pal@sandflow.com> X-Mailer: git-send-email 2.32.0.windows.2 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: DI73oV3rpvNN 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 From patchwork Thu Oct 7 23:41:23 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: 30977 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp304279ioa; Thu, 7 Oct 2021 16:42:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqyy2riTNBQuKnXubfzF1TMXtrLxkKQualsrVEPSTICuLVf9Tq9DfJS43XcfwOunjtil3b X-Received: by 2002:a17:906:1c14:: with SMTP id k20mr8986576ejg.22.1633650125394; Thu, 07 Oct 2021 16:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633650125; cv=none; d=google.com; s=arc-20160816; b=ewI/3JzDsteV5fuZcMlML1TxFeReiHSb42rhBtMD9NrbTsBrn5hTSovPV+MewURvEt E/SpN2pQQzBJTcxIchOx65Dej7OCY25KWzHr3SoNhk+SPsIfLnMueNM+46xtfWZrA7EB 5e7GI1Z8vyz6qDBHLdO7iBuRMqkazeX23Z1l42RnOCDCT3vSaX0cBnuNNrB7CkNcjgG8 Lo97/VceBplBAbNj7JmuuvBL1J6YkQ2l+QsQ7uPytQ/mVNAoFlUf5LnQKhd1feNIkbKM qiPstntyBl0SavbfKko2MHQaGzdSBV2x5JsbjiOZQbpCc3REgnoiSMtU8wLqLNDS0V6q zwKg== 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=UC2Nb/SbFpPbrSymZVRBBQnSniXPAk8ekAdknnQc6VI=; b=BtgiJQmXYoofy++9k2yUb+Jk7abYH73YDJKkg0Qh3RDns7tr07ZDnz+QqLNQt2aQSc VW9ykf6FhnaVfySsQhQnUTxXWe7Xg21GCSDcdtgaXy1Jmg+TDK7OePqascvJz/JXG/Pj J5QOcL9TBZ6t4Xbc0AKh4qLBn2DMQ4bYRq8X+HW2+chCazSsEM1ngeAi6UnbQP5PdY/+ Y6lsWFEuPeGQSgWKwCc5XWR7fk93y+qQo2F/28AY/wAn0Un/F/fFvjBIGFjbzvR0TAck wABNMHuQT3KmL/H80EOz8xFh25SLvJXMK6U0xhWuZVqI2j/Ut2gV/yPvHGfC9+FCyY6Z /Vww== 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 29si995887eje.659.2021.10.07.16.42.04; Thu, 07 Oct 2021 16:42:05 -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 88743688178; Fri, 8 Oct 2021 02:41:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E19EB68988E for ; Fri, 8 Oct 2021 02:41:46 +0300 (EEST) Received: by mail-pj1-f54.google.com with SMTP id q7-20020a17090a2e0700b001a01027dd88so4817115pjd.1 for ; Thu, 07 Oct 2021 16:41:46 -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=VDl7jgecMkL4E2oWn9f7OjVd6F/wW3bh4D1l5yXwAG0=; b=YJQufi/OyRlkg15K2P18AmCcwijJ49KS5iMyNgZkHwe5Qvw5pAcv/iJBq+FC+c4Ktw xFjAjeSNaq8WOlNQct+pW7lRridUR1APS66mhYzXIUY0th3Qg+jvpUdnDPyRV+VvY8+8 FLYXGDhnQQ6r488EDZCILo2Jr38+6lDCUJHfIUY5/f05MzxMsgI7O75b6a3OkFA1lmNe KGwfBW4HXnmomdfz3jgj/yR5buWJfV9sXrpvJskzGEfKMzrtHSrnWcm48gpQ2Zr0doVs 9DowlUObzRgoGkEMd7kmT5PX9ZhOefbhb65IGbbz7CFvqLUMOiGR0a12z6vW7pKXh9Sa ALtQ== X-Gm-Message-State: AOAM5309TWmwYfgvhYsSSSW4OUXJPPs41jSxkLaDLEorc0iYOFxO3ncm p/AzdbfJRsj8/ho4tpi8PxBWldq0o2M= X-Received: by 2002:a17:902:e801:b0:13f:255:9db5 with SMTP id u1-20020a170902e80100b0013f02559db5mr6399199plg.23.1633650104878; Thu, 07 Oct 2021 16:41:44 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id l185sm495560pfd.29.2021.10.07.16.41.43 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 16:41:44 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Thu, 07 Oct 2021 16:41:38 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Oct 2021 16:41:23 -0700 Message-Id: <20211007234126.5353-2-pal@sandflow.com> X-Mailer: git-send-email 2.32.0.windows.2 In-Reply-To: <20211007234126.5353-1-pal@sandflow.com> References: <20211007234126.5353-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] avformat/imf: CPL processor 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: jU5WtsP5jy5G From: Pierre-Anthony Lemieux Signed-off-by: Pierre-Anthony Lemieux --- Notes: Implements IMF Composition Playlist (CPL) parsing. libavformat/imf_cpl.c | 666 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 666 insertions(+) create mode 100644 libavformat/imf_cpl.c diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c new file mode 100644 index 0000000000..8ef574ad78 --- /dev/null +++ b/libavformat/imf_cpl.c @@ -0,0 +1,666 @@ +/* + * 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 + */ + +/** + * Implements IMP CPL processing + * + * @author Pierre-Anthony Lemieux + * @file + * @ingroup lavu_imf + */ + +#include "imf.h" +#include "imf_internal.h" +#include "libavformat/mxf.h" +#include "libavutil/bprint.h" +#include "libavutil/error.h" +#include + +xmlNodePtr xml_get_child_element_by_name(xmlNodePtr parent, const char *name_utf8) { + xmlNodePtr cur_element; + + cur_element = xmlFirstElementChild(parent); + while (cur_element) { + if (xmlStrcmp(cur_element->name, name_utf8) == 0) + return cur_element; + cur_element = xmlNextElementSibling(cur_element); + } + return NULL; +} + +int xml_read_UUID(xmlNodePtr element, uint8_t uuid[16]) { + xmlChar *element_text = NULL; + int scanf_ret; + int ret = 0; + + element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1); + scanf_ret = sscanf(element_text, + 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) { + av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n"); + ret = AVERROR_INVALIDDATA; + } + xmlFree(element_text); + + return ret; +} + +int xml_read_rational(xmlNodePtr element, AVRational *rational) { + xmlChar *element_text = NULL; + int ret = 0; + + element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1); + if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2) { + av_log(NULL, AV_LOG_ERROR, "Invalid rational number\n"); + ret = AVERROR_INVALIDDATA; + } + xmlFree(element_text); + + return ret; +} + +int xml_read_ulong(xmlNodePtr element, unsigned long *number) { + xmlChar *element_text = NULL; + int ret = 0; + + element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1); + if (sscanf(element_text, "%lu", number) != 1) { + av_log(NULL, AV_LOG_ERROR, "Invalid unsigned long"); + ret = AVERROR_INVALIDDATA; + } + xmlFree(element_text); + + return ret; +} + +static void imf_base_virtual_track_init(IMFBaseVirtualTrack *track) { + memset(track->id_uuid, 0, sizeof(track->id_uuid)); +} + +static void imf_marker_virtual_track_init(IMFMarkerVirtualTrack *track) { + imf_base_virtual_track_init((IMFBaseVirtualTrack *)track); + track->resource_count = 0; + track->resources = NULL; +} + +static void imf_trackfile_virtual_track_init(IMFTrackFileVirtualTrack *track) { + imf_base_virtual_track_init((IMFBaseVirtualTrack *)track); + track->resource_count = 0; + track->resources = NULL; +} + +static void imf_base_resource_init(IMFBaseResource *rsrc) { + rsrc->duration = 0; + rsrc->edit_rate = av_make_q(0, 0); + rsrc->entry_point = 0; + rsrc->repeat_count = 1; +} + +static void imf_marker_resource_init(IMFMarkerResource *rsrc) { + imf_base_resource_init((IMFBaseResource *)rsrc); + rsrc->marker_count = 0; + rsrc->markers = NULL; +} + +static void imf_marker_init(IMFMarker *marker) { + marker->label_utf8 = NULL; + marker->offset = 0; + marker->scope_utf8 = NULL; +} + +static void imf_trackfile_resource_init(IMFTrackFileResource *rsrc) { + imf_base_resource_init((IMFBaseResource *)rsrc); + memset(rsrc->track_file_uuid, 0, sizeof(rsrc->track_file_uuid)); +} + +static int fill_content_title(xmlNodePtr cpl_element, IMFCPL *cpl) { + xmlNodePtr element = NULL; + + if (!(element = xml_get_child_element_by_name(cpl_element, "ContentTitle"))) { + av_log(NULL, AV_LOG_ERROR, "ContentTitle element not found in the IMF CPL\n"); + return AVERROR_INVALIDDATA; + } + cpl->content_title_utf8 = xmlNodeListGetString(cpl_element->doc, element->xmlChildrenNode, 1); + + return 0; +} + +static int fill_edit_rate(xmlNodePtr cpl_element, IMFCPL *cpl) { + xmlNodePtr element = NULL; + + if (!(element = xml_get_child_element_by_name(cpl_element, "EditRate"))) { + av_log(NULL, AV_LOG_ERROR, "EditRate element not found in the IMF CPL\n"); + return AVERROR_INVALIDDATA; + } + + return xml_read_rational(element, &cpl->edit_rate); +} + +static int fill_id(xmlNodePtr cpl_element, IMFCPL *cpl) { + xmlNodePtr element = NULL; + + if (!(element = xml_get_child_element_by_name(cpl_element, "Id"))) { + av_log(NULL, AV_LOG_ERROR, "Id element not found in the IMF CPL\n"); + return AVERROR_INVALIDDATA; + } + + return xml_read_UUID(element, cpl->id_uuid); +} + +static int fill_marker(xmlNodePtr marker_elem, IMFMarker *marker) { + xmlNodePtr element = NULL; + int ret = 0; + + /* read Offset */ + if (!(element = xml_get_child_element_by_name(marker_elem, "Offset"))) { + av_log(NULL, AV_LOG_ERROR, "Offset element not found in a Marker\n"); + return AVERROR_INVALIDDATA; + } + if ((ret = xml_read_ulong(element, &marker->offset))) + return ret; + + /* read Label and Scope */ + if (!(element = xml_get_child_element_by_name(marker_elem, "Label"))) { + av_log(NULL, AV_LOG_ERROR, "Label element not found in a Marker\n"); + return AVERROR_INVALIDDATA; + } + if (!(marker->label_utf8 = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1))) { + av_log(NULL, AV_LOG_ERROR, "Empty Label element found in a Marker\n"); + return AVERROR_INVALIDDATA; + } + if (!(marker->scope_utf8 = xmlGetNoNsProp(element, "scope"))) { + marker->scope_utf8 = xmlCharStrdup("http://www.smpte-ra.org/schemas/2067-3/2013#standard-markers"); + } + + return ret; +} + +static int fill_base_resource(xmlNodePtr resource_elem, IMFBaseResource *resource, IMFCPL *cpl) { + xmlNodePtr element = NULL; + int ret = 0; + + /* read EditRate */ + if (!(element = xml_get_child_element_by_name(resource_elem, "EditRate"))) { + resource->edit_rate = cpl->edit_rate; + } else if (ret = xml_read_rational(element, &resource->edit_rate)) { + av_log(NULL, AV_LOG_ERROR, "Invalid EditRate element found in a Resource\n"); + return ret; + } + + /* read EntryPoint */ + if (element = xml_get_child_element_by_name(resource_elem, "EntryPoint")) { + if (ret = xml_read_ulong(element, &resource->entry_point)) { + av_log(NULL, AV_LOG_ERROR, "Invalid EntryPoint element found in a Resource\n"); + return ret; + } + } else + resource->entry_point = 0; + + /* read IntrinsicDuration */ + if (!(element = xml_get_child_element_by_name(resource_elem, "IntrinsicDuration"))) { + av_log(NULL, AV_LOG_ERROR, "IntrinsicDuration element missing from Resource\n"); + return AVERROR_INVALIDDATA; + } + if (ret = xml_read_ulong(element, &resource->duration)) { + av_log(NULL, AV_LOG_ERROR, "Invalid IntrinsicDuration element found in a Resource\n"); + return ret; + } + resource->duration -= resource->entry_point; + + /* read SourceDuration */ + if (element = xml_get_child_element_by_name(resource_elem, "SourceDuration")) { + if (ret = xml_read_ulong(element, &resource->duration)) { + av_log(NULL, AV_LOG_ERROR, "SourceDuration element missing from Resource\n"); + return ret; + } + } + + /* read RepeatCount */ + if (element = xml_get_child_element_by_name(resource_elem, "RepeatCount")) { + ret = xml_read_ulong(element, &resource->repeat_count); + } + + return ret; +} + +static int fill_trackfile_resource(xmlNodePtr tf_resource_elem, IMFTrackFileResource *tf_resource, IMFCPL *cpl) { + xmlNodePtr element = NULL; + int ret = 0; + + if (ret = fill_base_resource(tf_resource_elem, (IMFBaseResource *)tf_resource, cpl)) + return ret; + + /* read TrackFileId */ + if (element = xml_get_child_element_by_name(tf_resource_elem, "TrackFileId")) { + if (ret = xml_read_UUID(element, tf_resource->track_file_uuid)) { + av_log(NULL, AV_LOG_ERROR, "Invalid TrackFileId element found in Resource\n"); + return ret; + } + } else { + av_log(NULL, AV_LOG_ERROR, "TrackFileId element missing from Resource\n"); + return AVERROR_INVALIDDATA; + } + + return ret; +} + +static int fill_marker_resource(xmlNodePtr marker_resource_elem, IMFMarkerResource *marker_resource, IMFCPL *cpl) { + xmlNodePtr element = NULL; + int ret = 0; + + if (ret = fill_base_resource(marker_resource_elem, (IMFBaseResource *)marker_resource, cpl)) + return ret; + + /* read markers */ + element = xmlFirstElementChild(marker_resource_elem); + while (element) { + if (xmlStrcmp(element->name, "Marker") == 0) { + marker_resource->markers = av_realloc(marker_resource->markers, (++marker_resource->marker_count) * sizeof(IMFMarker)); + if (!marker_resource->markers) { + av_log(NULL, AV_LOG_PANIC, "Cannot allocate Marker\n"); + exit(1); + } + imf_marker_init(&marker_resource->markers[marker_resource->marker_count - 1]); + fill_marker(element, &marker_resource->markers[marker_resource->marker_count - 1]); + } + element = xmlNextElementSibling(element); + } + + return ret; +} + +static int push_marker_sequence(xmlNodePtr marker_sequence_elem, IMFCPL *cpl) { + int ret = 0; + uint8_t uuid[16]; + xmlNodePtr resource_list_elem = NULL; + xmlNodePtr resource_elem = NULL; + xmlNodePtr track_id_elem = NULL; + + /* read TrackID element */ + if (!(track_id_elem = xml_get_child_element_by_name(marker_sequence_elem, "TrackId"))) { + av_log(NULL, AV_LOG_ERROR, "TrackId element missing from Sequence\n"); + return AVERROR_INVALIDDATA; + } + if (ret = xml_read_UUID(track_id_elem, uuid)) { + av_log(NULL, AV_LOG_ERROR, "Invalid TrackId element found in Sequence\n"); + return AVERROR_INVALIDDATA; + } + av_log(NULL, AV_LOG_DEBUG, "Processing IMF CPL Marker Sequence for Virtual Track " UUID_FORMAT "\n", UID_ARG(uuid)); + + /* create main marker virtual track if it does not exist */ + if (!cpl->main_markers_track) { + cpl->main_markers_track = av_malloc(sizeof(IMFMarkerVirtualTrack)); + if (!cpl->main_markers_track) { + av_log(NULL, AV_LOG_PANIC, "Cannot allocate Marker Virtual Track\n"); + exit(1); + } + imf_marker_virtual_track_init(cpl->main_markers_track); + memcpy(cpl->main_markers_track->base.id_uuid, uuid, sizeof(uuid)); + } else if (memcmp(cpl->main_markers_track->base.id_uuid, uuid, sizeof(uuid)) != 0) { + av_log(NULL, AV_LOG_ERROR, "Multiple marker virtual tracks were found\n"); + return AVERROR_INVALIDDATA; + } + + /* process resources */ + resource_list_elem = xml_get_child_element_by_name(marker_sequence_elem, "ResourceList"); + if (!resource_list_elem) + return 0; + resource_elem = xmlFirstElementChild(resource_list_elem); + while (resource_elem) { + cpl->main_markers_track->resources = av_realloc(cpl->main_markers_track->resources, (++cpl->main_markers_track->resource_count) * sizeof(IMFMarkerResource)); + if (!cpl->main_markers_track->resources) { + av_log(NULL, AV_LOG_PANIC, "Cannot allocate Resource\n"); + exit(1); + } + imf_marker_resource_init(&cpl->main_markers_track->resources[cpl->main_markers_track->resource_count - 1]); + fill_marker_resource(resource_elem, &cpl->main_markers_track->resources[cpl->main_markers_track->resource_count - 1], cpl); + resource_elem = xmlNextElementSibling(resource_elem); + } + + return ret; +} + +static int has_stereo_resources(xmlNodePtr element) { + if (xmlStrcmp(element->name, "Left") == 0 || xmlStrcmp(element->name, "Right") == 0) + return 1; + element = xmlFirstElementChild(element); + while (element) { + if (has_stereo_resources(element)) + return 1; + element = xmlNextElementSibling(element); + } + return 0; +} + +static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, IMFCPL *cpl) { + int ret = 0; + uint8_t uuid[16]; + xmlNodePtr resource_list_elem = NULL; + xmlNodePtr resource_elem = NULL; + xmlNodePtr track_id_elem = NULL; + IMFTrackFileVirtualTrack *vt = NULL; + + /* read TrackID element */ + if (!(track_id_elem = xml_get_child_element_by_name(audio_sequence_elem, "TrackId"))) { + av_log(NULL, AV_LOG_ERROR, "TrackId element missing from audio sequence\n"); + return AVERROR_INVALIDDATA; + } + if (ret = xml_read_UUID(track_id_elem, uuid)) { + av_log(NULL, AV_LOG_ERROR, "Invalid TrackId element found in audio sequence\n"); + return ret; + } + av_log(NULL, AV_LOG_DEBUG, "Processing IMF CPL Audio Sequence for Virtual Track " UUID_FORMAT "\n", UID_ARG(uuid)); + + /* get the main audio virtual track corresponding to the sequence */ + for (int i = 0; i < cpl->main_audio_track_count; i++) + if (memcmp(cpl->main_audio_tracks[i].base.id_uuid, uuid, sizeof(uuid)) == 0) { + vt = &cpl->main_audio_tracks[i]; + break; + } + + /* create a main audio virtual track if none exists for the sequence */ + if (!vt) { + cpl->main_audio_tracks = av_realloc(cpl->main_audio_tracks, sizeof(IMFTrackFileVirtualTrack) * (++cpl->main_audio_track_count)); + if (!cpl->main_audio_tracks) { + av_log(NULL, AV_LOG_PANIC, "Cannot allocate MainAudio virtual track\n"); + exit(1); + } + vt = &cpl->main_audio_tracks[cpl->main_audio_track_count - 1]; + imf_trackfile_virtual_track_init(vt); + memcpy(vt->base.id_uuid, uuid, sizeof(uuid)); + } + + /* process resources */ + resource_list_elem = xml_get_child_element_by_name(audio_sequence_elem, "ResourceList"); + if (!resource_list_elem) + return 0; + resource_elem = xmlFirstElementChild(resource_list_elem); + while (resource_elem) { + vt->resources = av_realloc(vt->resources, (++vt->resource_count) * sizeof(IMFTrackFileResource)); + if (!vt->resources) { + av_log(NULL, AV_LOG_PANIC, "Cannot allocate Resource\n"); + exit(1); + } + imf_trackfile_resource_init(&vt->resources[vt->resource_count - 1]); + fill_trackfile_resource(resource_elem, &vt->resources[vt->resource_count - 1], cpl); + resource_elem = xmlNextElementSibling(resource_elem); + } + + return ret; +} + +static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, IMFCPL *cpl) { + int ret = 0; + uint8_t uuid[16]; + xmlNodePtr resource_list_elem = NULL; + xmlNodePtr resource_elem = NULL; + xmlNodePtr track_id_elem = NULL; + + /* skip stereoscopic resources */ + if (has_stereo_resources(image_sequence_elem)) { + av_log(NULL, AV_LOG_ERROR, "Stereoscopic 3D image virtual tracks not supported\n"); + return AVERROR_PATCHWELCOME; + } + + /* read TrackId element*/ + if (!(track_id_elem = xml_get_child_element_by_name(image_sequence_elem, "TrackId"))) { + av_log(NULL, AV_LOG_ERROR, "TrackId element missing from audio sequence\n"); + return AVERROR_INVALIDDATA; + } + if (ret = xml_read_UUID(track_id_elem, uuid)) { + av_log(NULL, AV_LOG_ERROR, "Invalid TrackId element found in audio sequence\n"); + return ret; + } + + /* create main image virtual track if one does not exist */ + if (!cpl->main_image_2d_track) { + cpl->main_image_2d_track = av_malloc(sizeof(IMFTrackFileVirtualTrack)); + if (!cpl->main_image_2d_track) { + av_log(NULL, AV_LOG_PANIC, "Cannot allocate MainImage virtual track\n"); + exit(1); + } + imf_trackfile_virtual_track_init(cpl->main_image_2d_track); + memcpy(cpl->main_image_2d_track->base.id_uuid, uuid, sizeof(uuid)); + } else if (memcmp(cpl->main_image_2d_track->base.id_uuid, uuid, sizeof(uuid)) != 0) { + 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 " UUID_FORMAT "\n", UID_ARG(uuid)); + + /* process resources */ + if (!(resource_list_elem = xml_get_child_element_by_name(image_sequence_elem, "ResourceList"))) + return 0; + resource_elem = xmlFirstElementChild(resource_list_elem); + while (resource_elem) { + cpl->main_image_2d_track->resources = av_realloc(cpl->main_image_2d_track->resources, (++cpl->main_image_2d_track->resource_count) * sizeof(IMFTrackFileResource)); + if (!cpl->main_image_2d_track->resources) { + av_log(NULL, AV_LOG_PANIC, "Cannot allocate Resource\n"); + exit(1); + } + imf_trackfile_resource_init(&cpl->main_image_2d_track->resources[cpl->main_image_2d_track->resource_count - 1]); + fill_trackfile_resource(resource_elem, &cpl->main_image_2d_track->resources[cpl->main_image_2d_track->resource_count - 1], cpl); + resource_elem = xmlNextElementSibling(resource_elem); + } + + return 0; +} + +static int fill_virtual_tracks(xmlNodePtr cpl_element, IMFCPL *cpl) { + int ret = 0; + xmlNodePtr segment_list_elem = NULL; + xmlNodePtr segment_elem = NULL; + xmlNodePtr sequence_list_elem = NULL; + xmlNodePtr sequence_elem = NULL; + + if (!(segment_list_elem = xml_get_child_element_by_name(cpl_element, "SegmentList"))) { + av_log(NULL, AV_LOG_ERROR, "SegmentList element missing\n"); + return AVERROR_INVALIDDATA; + } + + /* process sequences */ + segment_elem = xmlFirstElementChild(segment_list_elem); + while (segment_elem) { + av_log(NULL, AV_LOG_DEBUG, "Processing IMF CPL Segment\n"); + sequence_list_elem = xml_get_child_element_by_name(segment_elem, "SequenceList"); + if (!segment_list_elem) + continue; + sequence_elem = xmlFirstElementChild(sequence_list_elem); + while (sequence_elem) { + if (xmlStrcmp(sequence_elem->name, "MarkerSequence") == 0) + push_marker_sequence(sequence_elem, cpl); + else if (xmlStrcmp(sequence_elem->name, "MainImageSequence") == 0) + push_main_image_2d_sequence(sequence_elem, cpl); + else if (xmlStrcmp(sequence_elem->name, "MainAudioSequence") == 0) + push_main_audio_sequence(sequence_elem, cpl); + else { + av_log(NULL, AV_LOG_INFO, "The following Sequence is not supported and is ignored: %s\n", sequence_elem->name); + } + sequence_elem = xmlNextElementSibling(sequence_elem); + } + segment_elem = xmlNextElementSibling(segment_elem); + } + + return ret; +} + +int parse_imf_cpl_from_xml_dom(xmlDocPtr doc, IMFCPL **cpl) { + int ret = 0; + xmlNodePtr cpl_element = NULL; + + *cpl = imf_cpl_alloc(); + if (!*cpl) { + av_log(NULL, AV_LOG_FATAL, "Cannot allocate CPL\n"); + ret = AVERROR_BUG; + goto cleanup; + } + cpl_element = xmlDocGetRootElement(doc); + if (xmlStrcmp(cpl_element->name, "CompositionPlaylist")) { + av_log(NULL, AV_LOG_ERROR, "The root element of the CPL is not CompositionPlaylist\n"); + ret = AVERROR_INVALIDDATA; + goto cleanup; + } + if (ret = fill_content_title(cpl_element, *cpl)) + goto cleanup; + if (ret = fill_id(cpl_element, *cpl)) + goto cleanup; + if (ret = fill_edit_rate(cpl_element, *cpl)) + goto cleanup; + if (ret = fill_virtual_tracks(cpl_element, *cpl)) + goto cleanup; + +cleanup: + if (*cpl && ret) { + imf_cpl_free(*cpl); + *cpl = NULL; + } + return ret; +} + +static void imf_marker_free(IMFMarker *marker) { + if (!marker) + return; + xmlFree(marker->label_utf8); + xmlFree(marker->scope_utf8); +} + +static void imf_marker_resource_free(IMFMarkerResource *rsrc) { + if (!rsrc) + return; + for (unsigned long i = 0; i < rsrc->marker_count; i++) + imf_marker_free(&rsrc->markers[i]); + av_free(rsrc->markers); +} + +static void imf_marker_virtual_track_free(IMFMarkerVirtualTrack *vt) { + if (!vt) + return; + for (unsigned long i = 0; i < vt->resource_count; i++) + imf_marker_resource_free(&vt->resources[i]); + av_free(vt->resources); +} + +static void imf_trackfile_virtual_track_free(IMFTrackFileVirtualTrack *vt) { + if (!vt) + return; + av_free(vt->resources); +} + +static void imf_cpl_init(IMFCPL *cpl) { + memset(cpl->id_uuid, 0, sizeof(cpl->id_uuid)); + cpl->content_title_utf8 = NULL; + cpl->edit_rate = av_make_q(0, 0); + cpl->main_markers_track = NULL; + cpl->main_image_2d_track = NULL; + cpl->main_audio_track_count = 0; + cpl->main_audio_tracks = NULL; +} + +IMFCPL *imf_cpl_alloc(void) { + IMFCPL *cpl; + + cpl = av_malloc(sizeof(IMFCPL)); + if (!cpl) + return NULL; + imf_cpl_init(cpl); + return cpl; +} + +void imf_cpl_free(IMFCPL *cpl) { + if (cpl) { + xmlFree(cpl->content_title_utf8); + imf_marker_virtual_track_free(cpl->main_markers_track); + imf_trackfile_virtual_track_free(cpl->main_image_2d_track); + for (unsigned long i = 0; i < cpl->main_audio_track_count; i++) + imf_trackfile_virtual_track_free(&cpl->main_audio_tracks[i]); + } + av_free(cpl); + cpl = NULL; +} + +int parse_imf_cpl(AVIOContext *in, IMFCPL **cpl) { + AVBPrint buf; + xmlDoc *doc = NULL; + int ret = 0; + int64_t filesize = 0; + + filesize = avio_size(in); + filesize = filesize > 0 ? filesize : 8192; + av_bprint_init(&buf, filesize + 1, AV_BPRINT_SIZE_UNLIMITED); + if ((ret = avio_read_to_bprint(in, &buf, UINT_MAX - 1)) < 0 || !avio_feof(in) || (filesize = buf.len) == 0) { + if (ret == 0) { + av_log(NULL, AV_LOG_ERROR, "Cannot read IMF CPL\n"); + return AVERROR_INVALIDDATA; + } + } else { + LIBXML_TEST_VERSION + doc = xmlReadMemory(buf.str, filesize, NULL, NULL, 0); + if (!doc) { + av_log(NULL, AV_LOG_ERROR, "XML parsing failed when reading the IMF CPL\n"); + ret = AVERROR_INVALIDDATA; + } + if (ret = parse_imf_cpl_from_xml_dom(doc, cpl)) { + av_log(NULL, AV_LOG_ERROR, "Cannot parse IMF CPL\n"); + } else { + av_log(NULL, AV_LOG_INFO, "IMF CPL ContentTitle: %s\n", (*cpl)->content_title_utf8); + av_log(NULL, AV_LOG_INFO, "IMF CPL Id: " UUID_FORMAT "\n", UID_ARG((*cpl)->id_uuid)); + } + xmlFreeDoc(doc); + xmlCleanupParser(); + } + + return ret; +} From patchwork Thu Oct 7 23:41:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 30976 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp304405ioa; Thu, 7 Oct 2021 16:42:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbVq2sDfG9CoHF860yR32EXly/8abQ/AJMGsbccD6PD4DBj+RWYKFiQS9SO/uZwvFbQUsI X-Received: by 2002:a17:906:180a:: with SMTP id v10mr9322969eje.112.1633650136530; Thu, 07 Oct 2021 16:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633650136; cv=none; d=google.com; s=arc-20160816; b=gUTTafQ71VJZLhfvYG6nogP4Bw4Hz48jBkhYT7FNaD5kZSeuX7BLto4gLi0GjmdI/g /2d1ox3sUWx3/AXWnhP5WFXrj9OMmdF+SBqv7TgYEwWyhoqdGtB3HbaEpmHcgxC4WQqv CqbpqiQbU821LLR42zhoFBjHP/VyaMpMarvY5UeKb9JeifWTm4MfCKwlZ01fjQGFC9gG /BIP1FduG5yrX3vT/twJpLFAeFoepbmQ7xL4X1ULuacbVP6xEVjpmySUJ7a0tRJt/aTe qaMBgsOHK2EdiFTiJlzZ0a3LNNVmJLysudzcUxSw454rBB4vOqcKozJYkHga/BLEvyUb Ddlg== 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=zdF/AGLuybWPKJDF9qaw/DurJbk04RQ0F0hHMAndSIU=; b=RlgLBQkQA8H5pqV1V9Udj7RDg02oXK+i5+S28nfHKMpJu+EC/M/8j5JiaQWyCDwVfR NerRjz1QJ67m633k24TYbQYrpLFUmJTzQ/93iBYo9brDgzCC0IPUpqwiKRiB7sb6Ej/b Ebv8iSV9SZY+Yu1CaiNcbfxIQ9zzLvAiD6fDCeBL+/P/zBY3ltU0Dfhq3gF5Ey3v+CaS zSTigEpjswYUXK8Hn9VkqldNGX+KwzQMWj2+Sq3IDiYFqEB6tUStVo1ojOd6uURNvSXO iUE0SosSWBH0pMUwdfgRirvSH+c4LiZVoND0ICcA8Ss9L4piq0m9pp88McufIOjMAuGt COJw== 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 p23si1186770edw.186.2021.10.07.16.42.16; Thu, 07 Oct 2021 16:42:16 -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 AA91868A3E8; Fri, 8 Oct 2021 02:41:56 +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 83F6C6898E7 for ; Fri, 8 Oct 2021 02:41:50 +0300 (EEST) Received: by mail-pl1-f180.google.com with SMTP id w14so5007816pll.2 for ; Thu, 07 Oct 2021 16:41: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=oNDW1DmiEY210XCDMnK6L2RN56+Aag2FEKzxJrKco+0=; b=BnxUsT5oU3oez5dp5jIS4xfjamb4lnoRnOBFTRLDnqZrQYL6gzKpctmBr1Ypsi9GG/ RAhQdppTHJqtllnVFXhckPV3ir+AvZp1EKPwNfkFrJ26LDDibo/2ljj3UnlO2UznLFxx GdPHRPqH7kC/600ttASUZzYwpEerBk8R+1hV1vsiFFDzebWQqy8klReC8kRRX3tcBZvv soC8ynT9sUMTtrQZE14PsLPqSYocW3DfH8cM9e3Rb+YMRsU+uN8S9Ppssgj63MdEcLyv CYGMYB7r/a3qQuxMW4sfKxHoodlNLYItyrPRu3lj92gKsnoN0yUcaGvsLaVK3vLtMKxo bu9A== X-Gm-Message-State: AOAM5331EXaCZVlHR2Sh7F2WPlxpZpk7ZiMXzapzLDiROzZq0fCU1X5o 6tCFErgVGSMvNxtUiA0oQLMhlT77ldo= X-Received: by 2002:a17:90b:4a92:: with SMTP id lp18mr8076189pjb.47.1633650108294; Thu, 07 Oct 2021 16:41: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 u1sm306482pje.47.2021.10.07.16.41.46 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 16:41:47 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Thu, 07 Oct 2021 16:41:41 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Oct 2021 16:41:24 -0700 Message-Id: <20211007234126.5353-3-pal@sandflow.com> X-Mailer: git-send-email 2.32.0.windows.2 In-Reply-To: <20211007234126.5353-1-pal@sandflow.com> References: <20211007234126.5353-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avformat/imf: Demuxer implementation 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: HZF7XmdHOZfo From: Pierre-Anthony Lemieux Signed-off-by: Pierre-Anthony Lemieux --- Notes: Implements the IMF demuxer. libavformat/imfdec.c | 660 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 660 insertions(+) create mode 100644 libavformat/imfdec.c diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c new file mode 100644 index 0000000000..0c64fe0c03 --- /dev/null +++ b/libavformat/imfdec.c @@ -0,0 +1,660 @@ +/* + * 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 + */ + +/** + * Demuxes an IMF Composition + * + * References + * OV 2067-0:2018 - SMPTE Overview Document - Interoperable Master Format + * ST 2067-2:2020 - SMPTE Standard - Interoperable Master Format — Core Constraints + * ST 2067-3:2020 - SMPTE Standard - Interoperable Master Format — Composition Playlist + * ST 2067-5:2020 - SMPTE Standard - Interoperable Master Format — Essence Component + * ST 2067-20:2016 - SMPTE Standard - Interoperable Master Format — Application #2 + * ST 2067-21:2020 - SMPTE Standard - Interoperable Master Format — Application #2 Extended + * ST 2067-102:2017 - SMPTE Standard - Interoperable Master Format — Common Image Pixel Color Schemes + * ST 429-9:2007 - SMPTE Standard - D-Cinema Packaging — Asset Mapping and File Segmentation + * + * @author Marc-Antoine Arnaud + * @author Valentin Noel + * @file + * @ingroup lavu_imf + */ + +#include "imf.h" +#include "imf_internal.h" +#include "internal.h" +#include "libavutil/opt.h" +#include "libavutil/bprint.h" +#include "libavutil/avstring.h" +#include "mxf.h" +#include "url.h" +#include +#include + +#define MAX_BPRINT_READ_SIZE (UINT_MAX - 1) +#define DEFAULT_ASSETMAP_SIZE 8 * 1024 + +typedef struct IMFVirtualTrackResourcePlaybackCtx { + IMFAssetLocator *locator; + IMFTrackFileResource *resource; + AVFormatContext *ctx; +} IMFVirtualTrackResourcePlaybackCtx; + +typedef struct IMFVirtualTrackPlaybackCtx { + // Track index in playlist + int32_t index; + // Time counters + AVRational current_timestamp; + AVRational duration; + // Resources + unsigned int resource_count; + IMFVirtualTrackResourcePlaybackCtx **resources; + // Decoding cursors + uint32_t current_resource_index; + int64_t last_pts; +} IMFVirtualTrackPlaybackCtx; + +typedef struct IMFContext { + const AVClass *class; + const char *base_url; + char *asset_map_paths; + AVIOInterruptCB *interrupt_callback; + AVDictionary *avio_opts; + IMFCPL *cpl; + IMFAssetLocatorMap *asset_locator_map; + unsigned int track_count; + IMFVirtualTrackPlaybackCtx **tracks; +} IMFContext; + +int is_url(const char *string) { + char *substr = strstr(string, "://"); + return substr != NULL; +} + +int is_unix_absolute_path(const char *string) { + char *substr = strstr(string, "/"); + int index = (int)(substr - string); + return index == 0; +} + +int is_dos_absolute_path(const char *string) { + // Absolute path case: `C:\path\to\somwhere` + char *substr = strstr(string, ":\\"); + int index = (int)(substr - string); + if (index == 1) { + return 1; + } + + // Absolute path case: `C:/path/to/somwhere` + substr = strstr(string, ":/"); + index = (int)(substr - string); + if (index == 1) { + return 1; + } + + // Network path case: `\\path\to\somwhere` + substr = strstr(string, "\\\\"); + index = (int)(substr - string); + return index == 0; +} + +int parse_imf_asset_map_from_xml_dom(AVFormatContext *s, xmlDocPtr doc, IMFAssetLocatorMap **asset_map, const char *base_url) { + xmlNodePtr asset_map_element = NULL; + xmlNodePtr node = NULL; + char *uri; + int ret = 0; + + IMFAssetLocator *asset = NULL; + + asset_map_element = xmlDocGetRootElement(doc); + + if (!asset_map_element) { + av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing root node\n"); + return AVERROR_INVALIDDATA; + } + + if (asset_map_element->type != XML_ELEMENT_NODE || av_strcasecmp(asset_map_element->name, "AssetMap")) { + av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - wrong root node name[%s] type[%d]\n", asset_map_element->name, (int)asset_map_element->type); + return AVERROR_INVALIDDATA; + } + + // parse asset locators + + if (!(node = xml_get_child_element_by_name(asset_map_element, "AssetList"))) { + av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing AssetList node\n"); + return AVERROR_INVALIDDATA; + } + + node = xmlFirstElementChild(node); + while (node) { + if (av_strcasecmp(node->name, "Asset") != 0) { + continue; + } + + asset = av_malloc(sizeof(IMFAssetLocator)); + + if (xml_read_UUID(xml_get_child_element_by_name(node, "Id"), asset->uuid)) { + av_log(s, AV_LOG_ERROR, "Could not parse UUID from asset in asset map.\n"); + av_freep(&asset); + return 1; + } + + av_log(s, AV_LOG_DEBUG, "Found asset id: " UUID_FORMAT "\n", UID_ARG(asset->uuid)); + + if (!(node = xml_get_child_element_by_name(node, "ChunkList"))) { + av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing ChunkList node\n"); + return AVERROR_INVALIDDATA; + } + + if (!(node = xml_get_child_element_by_name(node, "Chunk"))) { + av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing Chunk node\n"); + return AVERROR_INVALIDDATA; + } + + uri = xmlNodeGetContent(xml_get_child_element_by_name(node, "Path")); + + if (!is_url(uri) && !is_unix_absolute_path(uri) && !is_dos_absolute_path(uri)) { + uri = av_append_path_component(base_url, uri); + } + + asset->absolute_uri = strdup(uri); + av_free(uri); + + av_log(s, AV_LOG_DEBUG, "Found asset absolute URI: %s\n", asset->absolute_uri); + + node = xmlNextElementSibling(node->parent->parent); + + (*asset_map)->assets = av_realloc((*asset_map)->assets, ((*asset_map)->asset_count + 1) * sizeof(IMFAssetLocator)); + (*asset_map)->assets[(*asset_map)->asset_count++] = asset; + } + + return ret; +} + +IMFAssetLocatorMap *imf_asset_locator_map_alloc(void) { + IMFAssetLocatorMap *asset_map; + + asset_map = av_malloc(sizeof(IMFAssetLocatorMap)); + if (!asset_map) + return NULL; + + asset_map->assets = NULL; + asset_map->asset_count = 0; + return asset_map; +} + +void imf_asset_locator_map_free(IMFAssetLocatorMap *asset_map) { + if (asset_map == NULL) { + return; + } + + for (int i = 0; i < asset_map->asset_count; ++i) { + av_free(asset_map->assets[i]); + } + + av_freep(&asset_map->assets); + av_freep(&asset_map); +} + +static int parse_assetmap(AVFormatContext *s, const char *url, AVIOContext *in) { + IMFContext *c = s->priv_data; + struct AVBPrint buf; + AVDictionary *opts = NULL; + xmlDoc *doc = NULL; + const char *base_url; + + int close_in = 0; + int ret; + int64_t filesize; + + base_url = av_dirname(strdup(url)); + if (c->asset_locator_map == NULL) { + c->asset_locator_map = imf_asset_locator_map_alloc(); + if (!c->asset_locator_map) { + av_log(s, AV_LOG_ERROR, "Unable to allocate asset map locator\n"); + return AVERROR_BUG; + } + } + + av_log(s, AV_LOG_DEBUG, "Asset Map URL: %s\n", url); + + if (!in) { + close_in = 1; + + av_dict_copy(&opts, c->avio_opts, 0); + ret = avio_open2(&in, url, AVIO_FLAG_READ, c->interrupt_callback, &opts); + av_dict_free(&opts); + if (ret < 0) + return ret; + } + + filesize = avio_size(in); + filesize = filesize > 0 ? filesize : DEFAULT_ASSETMAP_SIZE; + + av_bprint_init(&buf, filesize + 1, AV_BPRINT_SIZE_UNLIMITED); + + if ((ret = avio_read_to_bprint(in, &buf, MAX_BPRINT_READ_SIZE)) < 0 || !avio_feof(in) || (filesize = buf.len) == 0) { + av_log(s, AV_LOG_ERROR, "Unable to read to asset map '%s'\n", url); + if (ret == 0) + ret = AVERROR_INVALIDDATA; + } else { + LIBXML_TEST_VERSION + + doc = xmlReadMemory(buf.str, filesize, url, NULL, 0); + + ret = parse_imf_asset_map_from_xml_dom(s, doc, &c->asset_locator_map, base_url); + if (ret != 0) { + goto cleanup; + } + + av_log(s, AV_LOG_DEBUG, "Found %d assets from %s\n", c->asset_locator_map->asset_count, url); + + cleanup: + xmlFreeDoc(doc); + } + if (close_in) { + avio_close(in); + } + return ret; +} + +static IMFAssetLocator *find_asset_map_locator(IMFAssetLocatorMap *asset_map, UUID uuid) { + IMFAssetLocator *asset_locator; + for (int i = 0; i < asset_map->asset_count; ++i) { + asset_locator = asset_map->assets[i]; + if (memcmp(asset_map->assets[i]->uuid, uuid, 16) == 0) { + return asset_locator; + } + } + return NULL; +} + +static int open_track_resource_context(AVFormatContext *s, IMFVirtualTrackResourcePlaybackCtx *track_resource) { + int ret = 0; + int64_t entry_point; + + if (!track_resource->ctx) { + track_resource->ctx = avformat_alloc_context(); + } + + if (track_resource->ctx->iformat) { + av_log(s, AV_LOG_DEBUG, "Input context already opened for %s.\n", track_resource->locator->absolute_uri); + return ret; + } + + ret = avformat_open_input(&track_resource->ctx, track_resource->locator->absolute_uri, NULL, NULL); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Could not open %s input context: %s\n", track_resource->locator->absolute_uri, av_err2str(ret)); + goto cleanup; + } + + ret = avformat_find_stream_info(track_resource->ctx, NULL); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Could not find %s stream information: %s\n", track_resource->locator->absolute_uri, av_err2str(ret)); + goto cleanup; + } + + // Compare the source timebase to the resource edit rate, considering the first stream of the source file + if (av_cmp_q(track_resource->ctx->streams[0]->time_base, av_inv_q(track_resource->resource->base.edit_rate))) { + av_log(s, AV_LOG_WARNING, "Incoherent source stream timebase %d/%d regarding resource edit rate: %d/%d", track_resource->ctx->streams[0]->time_base.num, track_resource->ctx->streams[0]->time_base.den, track_resource->resource->base.edit_rate.den, track_resource->resource->base.edit_rate.num); + } + + entry_point = (int64_t)track_resource->resource->base.entry_point * track_resource->resource->base.edit_rate.den * AV_TIME_BASE / track_resource->resource->base.edit_rate.num; + + if (entry_point) { + av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %ld\n", track_resource->locator->absolute_uri, track_resource->resource->base.entry_point); + ret = avformat_seek_file(track_resource->ctx, -1, entry_point, entry_point, entry_point, 0); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Could not seek at %" PRId64 "on %s: %s\n", entry_point, track_resource->locator->absolute_uri, av_err2str(ret)); + goto cleanup; + } + } + + return ret; +cleanup: + avformat_free_context(track_resource->ctx); + return ret; +} + +static int open_track_file_resource(AVFormatContext *s, IMFTrackFileResource *track_file_resource, IMFVirtualTrackPlaybackCtx *track) { + IMFContext *c = s->priv_data; + IMFVirtualTrackResourcePlaybackCtx *track_resource; + IMFAssetLocator *asset_locator; + + int ret; + + if (!(asset_locator = find_asset_map_locator(c->asset_locator_map, track_file_resource->track_file_uuid))) { + av_log(s, AV_LOG_ERROR, "Could not find asset locator for UUID: " UUID_FORMAT "\n", UID_ARG(track_file_resource->track_file_uuid)); + return AVERROR_INVALIDDATA; + } + + av_log(s, AV_LOG_DEBUG, "Found locator for " UUID_FORMAT ": %s\n", UID_ARG(asset_locator->uuid), asset_locator->absolute_uri); + + track_resource = av_mallocz(sizeof(IMFVirtualTrackResourcePlaybackCtx)); + track_resource->locator = asset_locator; + track_resource->resource = track_file_resource; + + if ((ret = open_track_resource_context(s, track_resource)) != 0) { + return ret; + } + + for (int repetition = 0; repetition < track_file_resource->base.repeat_count; ++repetition) { + track->resources = av_realloc(track->resources, (track->resource_count + 1) * sizeof(IMFVirtualTrackResourcePlaybackCtx)); + track->resources[track->resource_count++] = track_resource; + track->duration = av_add_q(track->duration, av_make_q((int)track_resource->resource->base.duration * track_resource->resource->base.edit_rate.den, track_resource->resource->base.edit_rate.num)); + } + + return ret; +} + +static int open_virtual_track(AVFormatContext *s, IMFTrackFileVirtualTrack *virtual_track, int32_t track_index) { + IMFContext *c = s->priv_data; + IMFVirtualTrackPlaybackCtx *track; + int ret = 0; + + track = av_mallocz(sizeof(IMFVirtualTrackPlaybackCtx)); + track->index = track_index; + track->duration = av_make_q(0, INT32_MAX); + + for (int i = 0; i < virtual_track->resource_count; i++) { + av_log(s, AV_LOG_DEBUG, "Open stream from file " UUID_FORMAT ", stream %d\n", UID_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 " UUID_FORMAT "\n", UID_ARG(virtual_track->resources[i].track_file_uuid)); + return ret; + } + } + + track->current_timestamp = av_make_q(0, track->duration.den); + + c->tracks = av_realloc(c->tracks, (c->track_count + 1) * sizeof(IMFVirtualTrackPlaybackCtx)); + c->tracks[c->track_count++] = track; + + return ret; +} + +static void imf_virtual_track_playback_context_free(IMFVirtualTrackPlaybackCtx *track) { + if (!track) { + return; + } + + for (int i = 0; i < track->resource_count; ++i) { + if (!track->resources[i]) { + continue; + } + + if (track->resources[i]->ctx && track->resources[i]->ctx->iformat) { + avformat_free_context(track->resources[i]->ctx); + track->resources[i]->ctx = NULL; + } + } +} + +static int set_context_streams_from_tracks(AVFormatContext *s) { + IMFContext *c = s->priv_data; + + AVStream *asset_stream; + AVStream *first_resource_stream; + + int ret = 0; + + for (int i = 0; i < c->track_count; ++i) { + // Open the first resource of the track to get stream information + first_resource_stream = c->tracks[i]->resources[0]->ctx->streams[0]; + + av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", c->tracks[i]->index); + + // Copy stream information + asset_stream = avformat_new_stream(s, NULL); + asset_stream->id = i; + if ((ret = avcodec_parameters_copy(asset_stream->codecpar, first_resource_stream->codecpar)) < 0) { + av_log(s, AV_LOG_ERROR, "Could not copy stream parameters\n"); + break; + } + avpriv_set_pts_info(asset_stream, first_resource_stream->pts_wrap_bits, first_resource_stream->time_base.num, first_resource_stream->time_base.den); + asset_stream->duration = (int64_t)av_q2d(av_mul_q(c->tracks[i]->duration, av_inv_q(asset_stream->time_base))); + } + + return ret; +} + +static int open_cpl_tracks(AVFormatContext *s) { + IMFContext *c = s->priv_data; + int32_t track_index = 0; + int ret; + + 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 " UUID_FORMAT "\n", UID_ARG(c->cpl->main_image_2d_track->base.id_uuid)); + return ret; + } + } + + for (int audio_track_index = 0; audio_track_index < c->cpl->main_audio_track_count; ++audio_track_index) { + if ((ret = open_virtual_track(s, &c->cpl->main_audio_tracks[audio_track_index], track_index++)) != 0) { + av_log(s, AV_LOG_ERROR, "Could not open audio track " UUID_FORMAT "\n", UID_ARG(c->cpl->main_audio_tracks[audio_track_index].base.id_uuid)); + return ret; + } + } + + return set_context_streams_from_tracks(s); +} + +static int imf_close(AVFormatContext *s); + +static int imf_read_header(AVFormatContext *s) { + IMFContext *c = s->priv_data; + char *asset_map_path; + int ret; + + c->base_url = av_dirname(av_strdup(s->url)); + + av_log(s, AV_LOG_DEBUG, "start parsing IMF CPL: %s\n", s->url); + + if ((ret = parse_imf_cpl(s->pb, &c->cpl)) < 0) + goto fail; + + av_log(s, AV_LOG_DEBUG, "parsed IMF CPL: " UUID_FORMAT "\n", UID_ARG(c->cpl->id_uuid)); + + if (!c->asset_map_paths) { + c->asset_map_paths = av_append_path_component(c->base_url, "ASSETMAP.xml"); + } + + // Parse each asset map XML file + asset_map_path = strtok(c->asset_map_paths, ","); + while (asset_map_path != NULL) { + av_log(s, AV_LOG_DEBUG, "start parsing IMF Asset Map: %s\n", asset_map_path); + + if ((ret = parse_assetmap(s, asset_map_path, NULL)) < 0) + goto fail; + + asset_map_path = strtok(NULL, ","); + } + + av_log(s, AV_LOG_DEBUG, "parsed IMF Asset Maps\n"); + + if ((ret = open_cpl_tracks(s)) != 0) { + goto fail; + } + + av_log(s, AV_LOG_DEBUG, "parsed IMF package\n"); + return ret; + +fail: + imf_close(s); + return ret; +} + +static IMFVirtualTrackPlaybackCtx *get_next_track_with_minimum_timestamp(AVFormatContext *s) { + IMFContext *c = s->priv_data; + IMFVirtualTrackPlaybackCtx *track; + + AVRational minimum_timestamp = av_make_q(INT32_MAX, 1); + for (int i = 0; i < c->track_count; ++i) { + av_log(s, AV_LOG_DEBUG, "Compare track %d timestamp " AVRATIONAL_FORMAT " to minimum " AVRATIONAL_FORMAT " (over duration: " AVRATIONAL_FORMAT ")\n", i, AVRATIONAL_ARG(c->tracks[i]->current_timestamp), AVRATIONAL_ARG(minimum_timestamp), AVRATIONAL_ARG(c->tracks[i]->duration)); + if (av_cmp_q(c->tracks[i]->current_timestamp, minimum_timestamp) < 0) { + track = c->tracks[i]; + minimum_timestamp = track->current_timestamp; + } + } + + av_log(s, AV_LOG_DEBUG, "Found next track to read: %d (timestamp: %lf / %lf)\n", track->index, av_q2d(track->current_timestamp), av_q2d(minimum_timestamp)); + return track; +} + +static IMFVirtualTrackResourcePlaybackCtx *get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrackPlaybackCtx *track) { + AVRational edit_unit_duration = av_inv_q(track->resources[0]->resource->base.edit_rate); + AVRational cumulated_duration = av_make_q(0, edit_unit_duration.den); + + av_log(s, AV_LOG_DEBUG, "Looking for track %d resource for timestamp = %lf / %lf\n", track->index, av_q2d(track->current_timestamp), av_q2d(track->duration)); + for (int i = 0; i < track->resource_count; ++i) { + cumulated_duration = av_add_q(cumulated_duration, av_make_q((int)track->resources[i]->resource->base.duration * edit_unit_duration.num, edit_unit_duration.den)); + + if (av_cmp_q(av_add_q(track->current_timestamp, edit_unit_duration), cumulated_duration) <= 0) { + av_log(s, AV_LOG_DEBUG, "Found resource %d in track %d to read for timestamp %lf (on cumulated=%lf): entry=%ld, duration=%lu, editrate=" AVRATIONAL_FORMAT " | edit_unit_duration=%lf\n", i, track->index, av_q2d(track->current_timestamp), av_q2d(cumulated_duration), track->resources[i]->resource->base.entry_point, track->resources[i]->resource->base.duration, AVRATIONAL_ARG(track->resources[i]->resource->base.edit_rate), av_q2d(edit_unit_duration)); + + if (track->current_resource_index != i) { + av_log(s, AV_LOG_DEBUG, "Switch resource on track %d: re-open context\n", track->index); + if (track->resources[track->current_resource_index] != NULL) { + avformat_close_input(&track->resources[track->current_resource_index]->ctx); + } + if (open_track_resource_context(s, track->resources[i]) != 0) { + return NULL; + } + track->current_resource_index = i; + } + return track->resources[track->current_resource_index]; + } + } + return NULL; +} + +static int ff_imf_read_packet(AVFormatContext *s, AVPacket *pkt) { + IMFContext *c = s->priv_data; + + IMFVirtualTrackResourcePlaybackCtx *resource_to_read = NULL; + AVRational edit_unit_duration; + int ret = 0; + + IMFVirtualTrackPlaybackCtx *track_to_read = get_next_track_with_minimum_timestamp(s); + FFStream* track_to_read_stream_internal; + + if (av_cmp_q(track_to_read->current_timestamp, track_to_read->duration) == 0) { + return AVERROR_EOF; + } + + resource_to_read = get_resource_context_for_timestamp(s, track_to_read); + + if (!resource_to_read) { + edit_unit_duration = av_inv_q(track_to_read->resources[track_to_read->current_resource_index]->resource->base.edit_rate); + if (av_cmp_q(av_add_q(track_to_read->current_timestamp, edit_unit_duration), track_to_read->duration) > 0) { + return AVERROR_EOF; + } + + av_log(s, AV_LOG_ERROR, "Could not find IMF track resource to read\n"); + return AVERROR_STREAM_NOT_FOUND; + } + + while (!ff_check_interrupt(c->interrupt_callback) && !ret) { + ret = av_read_frame(resource_to_read->ctx, pkt); + av_log(s, AV_LOG_DEBUG, "Got packet: pts=%" PRId64 ", dts=%" PRId64 ", duration=%" PRId64 ", stream_index=%d, pos=%" PRId64 "\n", pkt->pts, pkt->dts, pkt->duration, pkt->stream_index, pkt->pos); + track_to_read_stream_internal = ffstream(s->streams[track_to_read->index]); + if (ret >= 0) { + // Update packet info from track + if (pkt->dts < track_to_read_stream_internal->cur_dts && track_to_read->last_pts > 0) { + pkt->dts = track_to_read_stream_internal->cur_dts; + } + + pkt->pts = track_to_read->last_pts; + pkt->dts = pkt->dts - (int64_t)track_to_read->resources[track_to_read->current_resource_index]->resource->base.entry_point; + pkt->stream_index = track_to_read->index; + + // Update track cursors + track_to_read->current_timestamp = av_add_q(track_to_read->current_timestamp, av_make_q((int)pkt->duration * resource_to_read->ctx->streams[0]->time_base.num, resource_to_read->ctx->streams[0]->time_base.den)); + track_to_read->last_pts += pkt->duration; + + return 0; + } else if (ret != AVERROR_EOF) { + av_log(s, AV_LOG_ERROR, "Could not get packet from track %d: %s\n", track_to_read->index, av_err2str(ret)); + return ret; + } + } + + return AVERROR_EOF; +} + +static int imf_close(AVFormatContext *s) { + IMFContext *c = s->priv_data; + + av_log(s, AV_LOG_DEBUG, "Close IMF package\n"); + av_dict_free(&c->avio_opts); + av_freep(&c->base_url); + imf_asset_locator_map_free(c->asset_locator_map); + imf_cpl_free(c->cpl); + + for (int i = 0; i < c->track_count; ++i) { + imf_virtual_track_playback_context_free(c->tracks[i]); + } + + return 0; +} + +static const AVOption imf_options[] = { + {"assetmaps", "IMF CPL-related asset map comma-separated absolute paths. If not specified, the CPL sibling `ASSETMAP.xml` file is used.", offsetof(IMFContext, asset_map_paths), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM}, + {NULL}}; + +static const AVClass imf_class = { + .class_name = "imf", + .item_name = av_default_item_name, + .option = imf_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +const AVInputFormat ff_imf_demuxer = { + .name = "imf", + .long_name = NULL_IF_CONFIG_SMALL("IMF (Interoperable Master Format)"), + .priv_class = &imf_class, + .priv_data_size = sizeof(IMFContext), + .read_header = imf_read_header, + .read_packet = ff_imf_read_packet, + .read_close = imf_close, + .extensions = "xml", + .mime_type = "application/xml,text/xml", +}; From patchwork Thu Oct 7 23:41:25 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: 30978 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp304501ioa; Thu, 7 Oct 2021 16:42:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+BgCJW9JWPwiviMMLg5jrDPussLSTBQQs4IzL+mtJ7eKCuFHhML5t+BjCzu3Rwvpw/sLg X-Received: by 2002:a17:906:60c7:: with SMTP id f7mr9248595ejk.57.1633650148525; Thu, 07 Oct 2021 16:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633650148; cv=none; d=google.com; s=arc-20160816; b=lojJPpQ9bKbX6tkTad9bl0ZLLQ6Sui6iZRcxEyy+230qGfQA19lZE2tQ7oGGGhtpCF IoTxIE6BuXj6mxa/eKQU8f8lRAWDLrmkTpaIFxPv+iM8FWTsVYD8oXPB46NnNIZHRERL N/wevl2xEuz8s+9/GpAbGnj71P3CtFbhG/c+0lg/2x8WFptmLnyDbdksu6e5EjNbHT8n 7Bn0ubENJPKRoLhY3q044/fMkkCNjK5I77Z99s0TqyfY4Sz7/kK9C7INJ0G+zIdihzBq K4oHv5IfN2LVlsdp57l9UMcBBO8KArSbvFf1ULTzLvZQHvrVld3t4xHAppZ+CnYVfBXW nSNw== 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=fFX9Yh4PKyy+lGzOQg101tH4Zomafj/DWB6AwQC8CIY=; b=FbK1YzYBSbK/ZeDpumkk962HYXsHh6SMl8c5wGnbK1ZuA0P/ti8yJhXWqFEKQgANjD k9XpbEOcdOwBMJ0BGD5f0xak0nVxeXSu1K2sX65TQ5jngPPjr59x7O5o3iXSiwK/MLQf bkaULAJGLEzOGB+zwvrGYaKE5L7p4hAZajQeyTcMUJX+BQoMA/0g/3M/0ZzlTvVkzI/R H+S9HYtOOPrLuGtZql0TRi1ZVlW1zH/OgBcCtcw6MILxHmNWUXLvpnDr5RzuZ4PGPvjB vyJ6VriE1GTfGT1+Avi+fv5PSP+k62wIEyKfi7sW6jgkS0R079qcjnqn8FIqzofCvtKU 90dQ== 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 w6si1096149ejn.107.2021.10.07.16.42.28; Thu, 07 Oct 2021 16:42:28 -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 B2CEE68A4CA; Fri, 8 Oct 2021 02:42:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 97C0D68A0AE for ; Fri, 8 Oct 2021 02:41:53 +0300 (EEST) Received: by mail-pg1-f170.google.com with SMTP id e7so1365690pgk.2 for ; Thu, 07 Oct 2021 16:41:53 -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=4KlS8xU3cVznssuqPWrnsADMmk508HcTszL5Skvt2N4=; b=TN4hB16PFjg41yvsOmJGmO82fGoC/mp4vApHSItBIrqhXe1WjilMsXZPUllNatKr7L YFM2FYQ29t2rnZoQuhVbrkerw8Pr+blCEnAIHcEnznlKjrDCtF1sDdN8VFT2MFGlQn9a C0KiyEcdgfniLfVANCxTGKp6ta9Lv+n/zpLbI2J0hWkQsmJr+N6uPHK+t35ZGDhMM6ry qqfz0hd3l753gfxtP4CUWhkATK3RODlrSEGIQnq2ai6HpFZVi8154jI6/+rwDstFCKH4 kE6u/ckd25d93SQFBk/qpr2oVqEQknmB909oTyjHxxV/EgByL5n79TC2CLbK+PAqRx32 XNNA== X-Gm-Message-State: AOAM530IQ3IjpwCkJK7OVLuUiyXp3IvlpuniluN7WppLAdt16y/uHA4U Oryo9qD2xyladh+GXBdMvVseC4mIANU= X-Received: by 2002:a62:cd0f:0:b0:447:b8fe:d6c2 with SMTP id o15-20020a62cd0f000000b00447b8fed6c2mr6816657pfg.70.1633650111406; Thu, 07 Oct 2021 16:41:51 -0700 (PDT) Received: from localhost (76-14-89-2.sf-cable.astound.net. [76.14.89.2]) by smtp.gmail.com with ESMTPSA id q73sm480241pfc.179.2021.10.07.16.41.49 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 16:41:51 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Thu, 07 Oct 2021 16:41:44 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Oct 2021 16:41:25 -0700 Message-Id: <20211007234126.5353-4-pal@sandflow.com> X-Mailer: git-send-email 2.32.0.windows.2 In-Reply-To: <20211007234126.5353-1-pal@sandflow.com> References: <20211007234126.5353-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] avformat/imf: 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: PgVtV5gz0tXy From: Pierre-Anthony Lemieux Signed-off-by: Pierre-Anthony Lemieux --- Notes: Tests for the public API of the IMF demuxer. libavformat/tests/imf.c | 490 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 490 insertions(+) create mode 100644 libavformat/tests/imf.c diff --git a/libavformat/tests/imf.c b/libavformat/tests/imf.c new file mode 100644 index 0000000000..548b848f0f --- /dev/null +++ b/libavformat/tests/imf.c @@ -0,0 +1,490 @@ +/* + * 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 + */ + +/** + * Tests for IMF CPL and ASSETMAP processing + * + * @author Valentin Noel + * @author Pierre-Anthony Lemieux + * @file + * @ingroup lavu_imf + */ + +#include "libavformat/imf.h" +#include "libavformat/imf_internal.h" +#include "libavformat/mxf.h" + +#include + +const char *cpl_doc = + "" + "urn:uuid:8713c020-2489-45f5-a9f7-87be539e20b5" + "2021-07-13T17:06:22Z" + "FFMPEG" + "FFMPEG sample content" + "" + " " + " urn:uuid:8e097bb0-cff7-4969-a692-bad47bfb528f" + " " + "" + "24000 1001" + "" + "" + "urn:uuid:81fed4e5-9722-400a-b9d1-7f2bd21df4b6" + "" + "" + "urn:uuid:16327185-9205-47ef-a17b-ee28df251db7" + "urn:uuid:461f5424-8f6e-48a9-a385-5eda46fda381" + "" + "" + "urn:uuid:ea3d0f23-55d6-4e03-86ec-cfe0666f0e6a" + "24" + "" + "" + "5" + "" + "" + "" + "" + "" + "urn:uuid:6ae100b0-92d1-41be-9321-85e0933dfc42" + "urn:uuid:e8ef9653-565c-479c-8039-82d4547973c5" + "" + "" + "urn:uuid:7d418acb-07a3-4e57-984c-b8ea2f7de4ec" + "24" + "urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751" + "urn:uuid:6f768ca4-c89e-4dac-9056-a29425d40ba1" + "" + "" + "" + "" + "urn:uuid:754dae53-c25f-4f3c-97e4-2bfe5463f83b" + "urn:uuid:68e3fae5-d94b-44d2-92a6-b94877fbcdb5" + "" + "" + "urn:uuid:61ce2a70-10a2-4521-850b-4218755ff3c9" + "24" + "urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751" + "urn:uuid:381dadd2-061e-46cc-a63a-e3d58ce7f488" + "" + "" + "" + "" + "urn:uuid:d29b3884-6633-4dad-9c67-7154af342bc6" + "urn:uuid:6978c106-95bc-424b-a17c-628206a5892d" + "" + "" + "urn:uuid:001ea472-f5da-436c-86de-acaa68c1a7e4" + "24" + "urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751" + "urn:uuid:381dadd2-061e-46cc-a63a-e3d58ce7f488" + "" + "" + "" + "" + "urn:uuid:02af22bf-f776-488a-b001-eb6e16953119" + "urn:uuid:19ff6da1-be79-4235-8d04-42201ad06e65" + "" + "" + "urn:uuid:dfa84292-0609-4097-824c-8e2e15e2ce4d" + "24" + "urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751" + "urn:uuid:bd6272b6-511e-47c1-93bc-d56ebd314a70" + "" + "" + "" + "" + "" + "" + "urn:uuid:a94be493-cd55-4bf7-b496-ea87bfe38632" + "" + "" + "urn:uuid:20c6020b-1fc0-4080-bcf7-89f09f95bea8" + "urn:uuid:461f5424-8f6e-48a9-a385-5eda46fda381" + "" + "" + "urn:uuid:d1f93845-d3e5-4c3b-aa67-8d96c45cfe9c" + "36" + "" + "" + "20" + "" + "" + "" + "24" + "" + "" + "" + "" + "" + "urn:uuid:9b509f42-e4e8-4f78-8c2a-12ddd79ef3c5" + "urn:uuid:e8ef9653-565c-479c-8039-82d4547973c5" + "" + "" + "urn:uuid:a733d812-a3d7-45e9-ba50-13b856d5d35a" + "36" + "urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751" + "urn:uuid:f3b263b3-096b-4360-a952-b1a9623cd0ca" + "" + "" + "" + "" + "urn:uuid:19a282e6-beac-4d99-a008-afa61378eb6c" + "urn:uuid:68e3fae5-d94b-44d2-92a6-b94877fbcdb5" + "" + "" + "urn:uuid:53de5ff9-f5f7-47c5-a2d8-117c36cce517" + "36" + "urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751" + "urn:uuid:2484d613-bb7d-4bcc-8b0f-2e65938f0535" + "" + "" + "" + "" + "urn:uuid:94b0ef77-0621-4086-95a2-85432fa97d40" + "urn:uuid:6978c106-95bc-424b-a17c-628206a5892d" + "" + "" + "urn:uuid:2ce499f2-59bc-4053-87bc-80f4b7e7b73e" + "36" + "urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751" + "urn:uuid:2484d613-bb7d-4bcc-8b0f-2e65938f0535" + "" + "" + "" + "" + "urn:uuid:9ac3b905-c599-4da8-8f0f-fc07e619899d" + "urn:uuid:19ff6da1-be79-4235-8d04-42201ad06e65" + "" + "" + "urn:uuid:0239017b-2ad9-4235-b46d-c4c1126e29fc" + "36" + "urn:uuid:f00e49a8-0dec-4e6c-95e7-078df988b751" + "urn:uuid:bd6272b6-511e-47c1-93bc-d56ebd314a70" + "" + "" + "" + "" + "" + "" + ""; + +const char *cpl_bad_doc = ""; + +const char *asset_map_doc = + "" + "" + "urn:uuid:68d9f591-8191-46b5-38b4-affb87a14132" + "IMF_TEST_ASSET_MAP" + "Some tool" + "1" + "2021-06-07T12:00:00+00:00" + "FFmpeg" + "" + "" + "urn:uuid:b5d674b8-c6ce-4bce-3bdf-be045dfdb2d0" + "" + "" + "IMF_TEST_ASSET_MAP_video.mxf" + "1" + "0" + "1234567" + "" + "" + "" + "" + "urn:uuid:ec3467ec-ab2a-4f49-c8cb-89caa3761f4a" + "" + "" + "IMF_TEST_ASSET_MAP_video_1.mxf" + "1" + "0" + "234567" + "" + "" + "" + "" + "urn:uuid:5cf5b5a7-8bb3-4f08-eaa6-3533d4b77fa6" + "" + "" + "IMF_TEST_ASSET_MAP_audio.mxf" + "1" + "0" + "34567" + "" + "" + "" + "" + "urn:uuid:559777d6-ec29-4375-f90d-300b0bf73686" + "" + "" + "CPL_IMF_TEST_ASSET_MAP.xml" + "1" + "0" + "12345" + "" + "" + "" + "" + "urn:uuid:dd04528d-9b80-452a-7a13-805b08278b3d" + "true" + "" + "" + "PKL_IMF_TEST_ASSET_MAP.xml" + "1" + "0" + "2345" + "" + "" + "" + "" + ""; + +static int test_cpl_parsing(void) { + xmlDocPtr doc; + IMFCPL *cpl; + int ret; + + doc = xmlReadMemory(cpl_doc, strlen(cpl_doc), NULL, NULL, 0); + if (doc == NULL) { + printf("XML parsing failed.\n"); + return 1; + } + + ret = parse_imf_cpl_from_xml_dom(doc, &cpl); + if (ret) { + printf("CPL parsing failed.\n"); + return 1; + } + + printf("%s\n", cpl->content_title_utf8); + printf(UUID_FORMAT "\n", UID_ARG(cpl->id_uuid)); + printf("%i %i\n", cpl->edit_rate.num, cpl->edit_rate.den); + + printf("Marker resource count: %lu\n", cpl->main_markers_track->resource_count); + for (unsigned long i = 0; i < cpl->main_markers_track->resource_count; i++) { + printf("Marker resource %lu\n", i); + for (unsigned long j = 0; j < cpl->main_markers_track->resources[i].marker_count; j++) { + printf(" Marker %lu\n", j); + printf(" Label %s\n", cpl->main_markers_track->resources[i].markers[j].label_utf8); + printf(" Offset %lu\n", cpl->main_markers_track->resources[i].markers[j].offset); + } + } + + printf("Main image resource count: %lu\n", cpl->main_image_2d_track->resource_count); + for (unsigned long i = 0; i < cpl->main_image_2d_track->resource_count; i++) { + printf("Track file resource %lu\n", i); + printf(" " UUID_FORMAT "\n", UID_ARG(cpl->main_image_2d_track->resources[i].track_file_uuid)); + } + + printf("Main audio track count: %lu\n", cpl->main_audio_track_count); + for (unsigned long i = 0; i < cpl->main_audio_track_count; i++) { + printf(" Main audio virtual track %lu\n", i); + printf(" Main audio resource count: %lu\n", cpl->main_audio_tracks[i].resource_count); + for (unsigned long j = 0; j < cpl->main_audio_tracks[i].resource_count; j++) { + printf(" Track file resource %lu\n", j); + printf(" " UUID_FORMAT "\n", UID_ARG(cpl->main_audio_tracks[i].resources[j].track_file_uuid)); + } + } + + imf_cpl_free(cpl); + + return 0; +} + +static int test_bad_cpl_parsing(void) { + xmlDocPtr doc; + IMFCPL *cpl; + int ret; + + doc = xmlReadMemory(cpl_bad_doc, strlen(cpl_bad_doc), NULL, NULL, 0); + if (doc == NULL) { + printf("XML parsing failed.\n"); + return ret; + } + + ret = parse_imf_cpl_from_xml_dom(doc, &cpl); + if (ret) { + printf("CPL parsing failed.\n"); + return ret; + } + + return 0; +} + +static int check_asset_locator_attributes(IMFAssetLocator *asset, IMFAssetLocator expected_asset) { + + printf("\tCompare " UUID_FORMAT " to " UUID_FORMAT ".\n", UID_ARG(asset->uuid), UID_ARG(expected_asset.uuid)); + for (int i = 0; i < 16; ++i) { + if (asset->uuid[i] != expected_asset.uuid[i]) { + printf("Invalid asset locator UUID: found " UUID_FORMAT " instead of " UUID_FORMAT " expected.\n", UID_ARG(asset->uuid), UID_ARG(expected_asset.uuid)); + return 1; + } + } + + printf("\tCompare %s to %s.\n", asset->absolute_uri, expected_asset.absolute_uri); + if (strcmp(asset->absolute_uri, expected_asset.absolute_uri) != 0) { + printf("Invalid asset locator URI: found %s instead of %s expected.\n", asset->absolute_uri, expected_asset.absolute_uri); + return 1; + } + + return 0; +} + +static const IMFAssetLocator ASSET_MAP_EXPECTED_LOCATORS[5] = { + [0] = {.uuid = {0xb5, 0xd6, 0x74, 0xb8, 0xc6, 0xce, 0x4b, 0xce, 0x3b, 0xdf, 0xbe, 0x04, 0x5d, 0xfd, 0xb2, 0xd0}, .absolute_uri = "IMF_TEST_ASSET_MAP_video.mxf"}, + [1] = {.uuid = {0xec, 0x34, 0x67, 0xec, 0xab, 0x2a, 0x4f, 0x49, 0xc8, 0xcb, 0x89, 0xca, 0xa3, 0x76, 0x1f, 0x4a}, .absolute_uri = "IMF_TEST_ASSET_MAP_video_1.mxf"}, + [2] = {.uuid = {0x5c, 0xf5, 0xb5, 0xa7, 0x8b, 0xb3, 0x4f, 0x08, 0xea, 0xa6, 0x35, 0x33, 0xd4, 0xb7, 0x7f, 0xa6}, .absolute_uri = "IMF_TEST_ASSET_MAP_audio.mxf"}, + [3] = {.uuid = {0x55, 0x97, 0x77, 0xd6, 0xec, 0x29, 0x43, 0x75, 0xf9, 0x0d, 0x30, 0x0b, 0x0b, 0xf7, 0x36, 0x86}, .absolute_uri = "CPL_IMF_TEST_ASSET_MAP.xml"}, + [4] = {.uuid = {0xdd, 0x04, 0x52, 0x8d, 0x9b, 0x80, 0x45, 0x2a, 0x7a, 0x13, 0x80, 0x5b, 0x08, 0x27, 0x8b, 0x3d}, .absolute_uri = "PKL_IMF_TEST_ASSET_MAP.xml"}, +}; + +static int test_asset_map_parsing(void) { + IMFAssetLocatorMap *asset_locator_map; + xmlDoc *doc; + int ret; + + doc = xmlReadMemory(asset_map_doc, strlen(asset_map_doc), NULL, NULL, 0); + if (doc == NULL) { + printf("Asset map XML parsing failed.\n"); + return 1; + } + + printf("Allocate asset map\n"); + asset_locator_map = imf_asset_locator_map_alloc(); + + printf("Parse asset map XML document\n"); + ret = parse_imf_asset_map_from_xml_dom(NULL, doc, &asset_locator_map, doc->name); + if (ret) { + printf("Asset map parsing failed.\n"); + goto cleanup; + } + + printf("Compare assets count: %d to 5\n", asset_locator_map->asset_count); + if (asset_locator_map->asset_count != 5) { + printf("Asset map parsing failed: found %d assets instead of 5 expected.\n", asset_locator_map->asset_count); + ret = 1; + goto cleanup; + } + + for (int i = 0; i < asset_locator_map->asset_count; ++i) { + printf("For asset: %d:\n", i); + ret = check_asset_locator_attributes(asset_locator_map->assets[i], ASSET_MAP_EXPECTED_LOCATORS[i]); + if (ret > 0) { + goto cleanup; + } + } + +cleanup: + imf_asset_locator_map_free(asset_locator_map); + xmlFreeDoc(doc); + return ret; +} + +typedef struct PathTypeTestStruct { + const char *path; + int is_url; + int is_unix_absolute_path; + int is_dos_absolute_path; +} PathTypeTestStruct; + +static const PathTypeTestStruct PATH_TYPE_TEST_STRUCTS[11] = { + [0] = {.path = "file://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0}, + [1] = {.path = "http://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0}, + [2] = {.path = "https://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0}, + [3] = {.path = "s3://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0}, + [4] = {.path = "ftp://path/to/somewhere", .is_url = 1, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0}, + [5] = {.path = "/path/to/somewhere", .is_url = 0, .is_unix_absolute_path = 1, .is_dos_absolute_path = 0}, + [6] = {.path = "path/to/somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0}, + [7] = {.path = "C:\\path\\to\\somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 1}, + [8] = {.path = "C:/path/to/somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 1}, + [9] = {.path = "\\\\path\\to\\somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 1}, + [10] = {.path = "path\\to\\somewhere", .is_url = 0, .is_unix_absolute_path = 0, .is_dos_absolute_path = 0}, +}; + +static int test_path_type_functions(void) { + PathTypeTestStruct path_type; + for (int i = 0; i < 11; ++i) { + path_type = PATH_TYPE_TEST_STRUCTS[i]; + if (is_url(path_type.path) != path_type.is_url) { + fprintf(stderr, "URL comparison test failed for '%s', got %d instead of expected %d\n", path_type.path, path_type.is_url, !path_type.is_url); + goto fail; + } + + if (is_unix_absolute_path(path_type.path) != path_type.is_unix_absolute_path) { + fprintf(stderr, "Unix absolute path comparison test failed for '%s', got %d instead of expected %d\n", path_type.path, path_type.is_unix_absolute_path, !path_type.is_unix_absolute_path); + goto fail; + } + + if (is_dos_absolute_path(path_type.path) != path_type.is_dos_absolute_path) { + fprintf(stderr, "DOS absolute path comparison test failed for '%s', got %d instead of expected %d\n", path_type.path, path_type.is_dos_absolute_path, !path_type.is_dos_absolute_path); + goto fail; + } + } + + return 0; + +fail: + return 1; +} + +int main(int argc, char *argv[]) { + int ret = 0; + + if (test_cpl_parsing() != 0) + ret = 1; + + if (test_asset_map_parsing() != 0) + ret = 1; + + if (test_path_type_functions() != 0) + ret = 1; + + printf("#### The following should fail ####\n"); + if (test_bad_cpl_parsing() == 0) + ret = 1; + printf("#### End failing test ####\n"); + + return ret; +} From patchwork Thu Oct 7 23:41:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierre-Anthony Lemieux X-Patchwork-Id: 30975 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp304618ioa; Thu, 7 Oct 2021 16:42:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXBarEZcEl0XSse9hiyv9dRL8Qpzj/O1hTA+V8Q1DkySpZnuP4R3aK21tuNDDHc35bejYX X-Received: by 2002:a17:906:6448:: with SMTP id l8mr9475408ejn.301.1633650159112; Thu, 07 Oct 2021 16:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633650159; cv=none; d=google.com; s=arc-20160816; b=d0tqEJNscU8JvKb/NZoXLvqlHHwBbya0RT/0waLyFTajG/UdrvOdt4f5PPx/GwCxaU BAAmMQ29V/prIv/rP2wylmhTD7V46+IqR4wTCYrR5syX6kG5cbk+6bXYqmbOtNqS2BdH 0mfrXybblkqxuifvAozizqdLLbnqC4tmfEGHcbkcrVbn3wFVAWUk175rD78tLdA1HFoc LycpzAVxxITI2J1AkmvB5fZNz107t/11a2FGPTn0FS/l9lXrR9Nyr5OHW8A/RLdSh3kz t8iEthJpCzVi4hWr+0erp+VcKx1OSdy0CVzCGZyspFKS/EFI+2Da1iF2cU73fjLKafyc Bmtw== 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=R5zBaPQZ01rtZ5NiEUj+hzxeBY3L1A9RnPoI9fJWrI4=; b=o8ibwKEoF+qHxfE/oaSW4zRIYx445IeGll+x54MfK38Sfxwo8Lo/sEOtbMpeGptJ9B OpFvzilnv3ZmXdjXjKGSQWS5KXm8Jsa932AyHR+gJqiwxpHntlF4I0iS8ijkcq8eitqS Kw1XQQVv9ufEzunJjlZ3qKU0AQil3wA5aRiRQMel9DDaBpcy2/a2N02M7f8zom2U2yQP //C1rm/5Lc0m1SPIIljWJ7EqvWR7er1BtnXSYZ924xewzQ+88UY86BADxprhk+KNOR4T SuL4AGTFmmFMoINShpqs9r+yvNaJevic0jyquWsH6z1bUyPeTdmJqWPLvg+QkIL6/AZs XdLw== 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 b11si1079104edm.525.2021.10.07.16.42.38; Thu, 07 Oct 2021 16:42:39 -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 BECAF68A57B; Fri, 8 Oct 2021 02:42:02 +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 9FBA268A447 for ; Fri, 8 Oct 2021 02:41:56 +0300 (EEST) Received: by mail-pj1-f41.google.com with SMTP id pf6-20020a17090b1d8600b0019fa884ab85so8127696pjb.5 for ; Thu, 07 Oct 2021 16:41: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=SiZ9IcY6j8NP6rj7BDHkJmXzvpKTFCoWDAQ5OzZYv4g=; b=dreqT2/nKA13oxqdc9/sIxbzoxiC8dWGVSan8BgQUrepCstzPgRiwSgSi4qkfkiXJ4 lK5HNfUortBchyCsT9G22H6EE4P1Jqi8/2D7mH/rsELXAmy8HCxoL9fgSMuAN3YOyOex yD7TsbCwTdFF6BQbH13JMiSwnKB5T0HTIUsTQV/7Eg4xDOpAJpUS/f5oouG9br7aLye3 luMCTzQ80Y6ZEq8Jj/zOMivmu9lXegHay0i5oun/3J7rhI2FIlpIF2eHBV2po9qTPAfI HjfUT/Eb4mQGxKNHIYpfMPnvdB3NcRKm5BVFEpy/Am8rYl51fnmQosR18TqSnFm35H0S vhDg== X-Gm-Message-State: AOAM5302VloIPosu8wCizfXDokEBaRbQRinl1U8fE/ESDs0CLuTxjea5 tlMJipidjMDJoU0bhN5K4Nb+Ng5ihVE= X-Received: by 2002:a17:903:1208:b0:13a:8c8:8a33 with SMTP id l8-20020a170903120800b0013a08c88a33mr6699161plh.89.1633650114669; Thu, 07 Oct 2021 16:41: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 c24sm422182pgj.63.2021.10.07.16.41.52 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Oct 2021 16:41:54 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Thu, 07 Oct 2021 16:41:47 -0700 From: pal@sandflow.com To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Oct 2021 16:41:26 -0700 Message-Id: <20211007234126.5353-5-pal@sandflow.com> X-Mailer: git-send-email 2.32.0.windows.2 In-Reply-To: <20211007234126.5353-1-pal@sandflow.com> References: <20211007234126.5353-1-pal@sandflow.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avformat/imf: Build system 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: Wo3qJdyrlN4D From: Pierre-Anthony Lemieux Signed-off-by: Pierre-Anthony Lemieux --- Notes: Modify the FFMPEG build system to add support for an IMF demuxer. MAINTAINERS | 1 + configure | 3 ++- doc/demuxers.texi | 6 ++++++ libavformat/Makefile | 2 ++ libavformat/allformats.c | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index dcac46003e..7a6972fe1a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -433,6 +433,7 @@ Muxers/Demuxers: idroqdec.c Mike Melanson iff.c Jaikrishnan Menon img2*.c Michael Niedermayer + imf*.c Marc-Antoine Arnaud, Pierre-Anthony Lemieux, Valentin Noël ipmovie.c Mike Melanson ircam* Paul B Mahol iss.c Stefan Gehrer diff --git a/configure b/configure index 5e630e6e5d..9fbffff217 100755 --- a/configure +++ b/configure @@ -297,7 +297,7 @@ External library support: --enable-libxvid enable Xvid encoding via xvidcore, native MPEG-4/Xvid encoder exists [no] --enable-libxml2 enable XML parsing using the C library libxml2, needed - for dash demuxing support [no] + for dash and imf demuxing support [no] --enable-libzimg enable z.lib, needed for zscale filter [no] --enable-libzmq enable message passing via libzmq [no] --enable-libzvbi enable teletext support via libzvbi [no] @@ -3364,6 +3364,7 @@ hls_muxer_select="mpegts_muxer" hls_muxer_suggest="gcrypt openssl" image2_alias_pix_demuxer_select="image2_demuxer" image2_brender_pix_demuxer_select="image2_demuxer" +imf_demuxer_deps="libxml2" ipod_muxer_select="mov_muxer" ismv_muxer_select="mov_muxer" ivf_muxer_select="av1_metadata_bsf vp9_superframe_bsf" diff --git a/doc/demuxers.texi b/doc/demuxers.texi index 1c9575b2e8..37efe6ce1a 100644 --- a/doc/demuxers.texi +++ b/doc/demuxers.texi @@ -267,6 +267,12 @@ which streams to actually receive. Each stream mirrors the @code{id} and @code{bandwidth} properties from the @code{} as metadata keys named "id" and "variant_bitrate" respectively. +@section imf + +Interoperable Master Format demuxer. + +This demuxer presents audio and video streams found in an IMF Composition. + @section flv, live_flv, kux Adobe Flash Video Format demuxer. diff --git a/libavformat/Makefile b/libavformat/Makefile index c45caa3eed..42ced953f6 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -284,6 +284,7 @@ OBJS-$(CONFIG_IMAGE_WEBP_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_IMAGE_XBM_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_IMAGE_XPM_PIPE_DEMUXER) += img2dec.o img2.o OBJS-$(CONFIG_IMAGE_XWD_PIPE_DEMUXER) += img2dec.o img2.o +OBJS-$(CONFIG_IMF_DEMUXER) += imfdec.o imf_cpl.o OBJS-$(CONFIG_INGENIENT_DEMUXER) += ingenientdec.o rawdec.o OBJS-$(CONFIG_IPMOVIE_DEMUXER) += ipmovie.o OBJS-$(CONFIG_IPU_DEMUXER) += ipudec.o rawdec.o @@ -693,6 +694,7 @@ TESTPROGS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpdh TESTPROGS-$(CONFIG_MOV_MUXER) += movenc TESTPROGS-$(CONFIG_NETWORK) += noproxy TESTPROGS-$(CONFIG_SRTP) += srtp +TESTPROGS-$(CONFIG_IMF_DEMUXER) += imf TOOLS = aviocat \ ismindex \ diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 5471f7c16f..bad4494981 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -211,6 +211,7 @@ extern const AVInputFormat ff_image2pipe_demuxer; extern const AVOutputFormat ff_image2pipe_muxer; extern const AVInputFormat ff_image2_alias_pix_demuxer; extern const AVInputFormat ff_image2_brender_pix_demuxer; +extern const AVInputFormat ff_imf_demuxer; extern const AVInputFormat ff_ingenient_demuxer; extern const AVInputFormat ff_ipmovie_demuxer; extern const AVOutputFormat ff_ipod_muxer;