xref: /third_party/ffmpeg/libavformat/imf.h (revision cabdff1a)
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/*
20 *
21 * Copyright (c) Sandflow Consulting LLC
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions are met:
25 *
26 * * Redistributions of source code must retain the above copyright notice, this
27 *   list of conditions and the following disclaimer.
28 * * Redistributions in binary form must reproduce the above copyright notice,
29 *   this list of conditions and the following disclaimer in the documentation
30 *   and/or other materials provided with the distribution.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
36 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGE.
43 */
44
45/**
46 * Public header file for the processing of Interoperable Master Format (IMF)
47 * packages.
48 *
49 * @author Pierre-Anthony Lemieux
50 * @author Valentin Noel
51 * @file
52 * @ingroup lavu_imf
53 */
54
55#ifndef AVFORMAT_IMF_H
56#define AVFORMAT_IMF_H
57
58#include "avformat.h"
59#include "libavformat/avio.h"
60#include "libavutil/rational.h"
61#include "libavutil/uuid.h"
62#include <libxml/tree.h>
63
64/**
65 * IMF Composition Playlist Base Resource
66 */
67typedef struct FFIMFBaseResource {
68    AVRational edit_rate;  /**< BaseResourceType/EditRate */
69    uint32_t entry_point;  /**< BaseResourceType/EntryPoint */
70    uint32_t duration;     /**< BaseResourceType/Duration */
71    uint32_t repeat_count; /**< BaseResourceType/RepeatCount */
72} FFIMFBaseResource;
73
74/**
75 * IMF Composition Playlist Track File Resource
76 */
77typedef struct FFIMFTrackFileResource {
78    FFIMFBaseResource base;
79    AVUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
80} FFIMFTrackFileResource;
81
82/**
83 * IMF Marker
84 */
85typedef struct FFIMFMarker {
86    xmlChar *label_utf8; /**< Marker/Label */
87    xmlChar *scope_utf8; /**< Marker/Label/\@scope */
88    uint32_t offset;     /**< Marker/Offset */
89} FFIMFMarker;
90
91/**
92 * IMF Composition Playlist Marker Resource
93 */
94typedef struct FFIMFMarkerResource {
95    FFIMFBaseResource base;
96    uint32_t marker_count; /**< Number of Marker elements */
97    FFIMFMarker *markers;  /**< Marker elements */
98} FFIMFMarkerResource;
99
100/**
101 * IMF Composition Playlist Virtual Track
102 */
103typedef struct FFIMFBaseVirtualTrack {
104    AVUUID id_uuid; /**< TrackId associated with the Virtual Track */
105} FFIMFBaseVirtualTrack;
106
107/**
108 * IMF Composition Playlist Virtual Track that consists of Track File Resources
109 */
110typedef struct FFIMFTrackFileVirtualTrack {
111    FFIMFBaseVirtualTrack base;
112    uint32_t resource_count;           /**< Number of Resource elements present in the Virtual Track */
113    FFIMFTrackFileResource *resources; /**< Resource elements of the Virtual Track */
114    unsigned int resources_alloc_sz;   /**< Size of the resources buffer */
115} FFIMFTrackFileVirtualTrack;
116
117/**
118 * IMF Composition Playlist Virtual Track that consists of Marker Resources
119 */
120typedef struct FFIMFMarkerVirtualTrack {
121    FFIMFBaseVirtualTrack base;
122    uint32_t resource_count;        /**< Number of Resource elements present in the Virtual Track */
123    FFIMFMarkerResource *resources; /**< Resource elements of the Virtual Track */
124} FFIMFMarkerVirtualTrack;
125
126/**
127 * IMF Composition Playlist
128 */
129typedef struct FFIMFCPL {
130    AVUUID id_uuid;                               /**< CompositionPlaylist/Id element */
131    xmlChar *content_title_utf8;                     /**< CompositionPlaylist/ContentTitle element */
132    AVRational edit_rate;                            /**< CompositionPlaylist/EditRate element */
133    FFIMFMarkerVirtualTrack *main_markers_track;     /**< Main Marker Virtual Track */
134    FFIMFTrackFileVirtualTrack *main_image_2d_track; /**< Main Image Virtual Track */
135    uint32_t main_audio_track_count;                 /**< Number of Main Audio Virtual Tracks */
136    FFIMFTrackFileVirtualTrack *main_audio_tracks;   /**< Main Audio Virtual Tracks */
137} FFIMFCPL;
138
139/**
140 * Parse an IMF CompositionPlaylist element into the FFIMFCPL data structure.
141 * @param[in] doc An XML document from which the CPL is read.
142 * @param[out] cpl Pointer to a memory area (allocated by the client), where the
143 *  function writes a pointer to the newly constructed FFIMFCPL structure (or
144 *  NULL if the CPL could not be parsed). The client is responsible for freeing
145 *  the FFIMFCPL structure using ff_imf_cpl_free().
146 * @return A non-zero value in case of an error.
147 */
148int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl);
149
150/**
151 * Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
152 * @param[in] in The context from which the CPL is read.
153 * @param[out] cpl Pointer to a memory area (allocated by the client), where the
154 * function writes a pointer to the newly constructed FFIMFCPL structure (or
155 * NULL if the CPL could not be parsed). The client is responsible for freeing
156 * the FFIMFCPL structure using ff_imf_cpl_free().
157 * @return A non-zero value in case of an error.
158 */
159int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl);
160
161/**
162 * Allocates and initializes an FFIMFCPL data structure.
163 * @return A pointer to the newly constructed FFIMFCPL structure (or NULL if the
164 * structure could not be constructed). The client is responsible for freeing
165 * the FFIMFCPL structure using ff_imf_cpl_free().
166 */
167FFIMFCPL *ff_imf_cpl_alloc(void);
168
169/**
170 * Deletes an FFIMFCPL data structure previously instantiated with ff_imf_cpl_alloc().
171 * @param[in] cpl The FFIMFCPL structure to delete.
172 */
173void ff_imf_cpl_free(FFIMFCPL *cpl);
174
175/**
176 * Reads an unsigned 32-bit integer from an XML element
177 * @return 0 on success, < 0 AVERROR code on error.
178 */
179int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t *number);
180
181/**
182 * Reads an AVRational from an XML element
183 * @return 0 on success, < 0 AVERROR code on error.
184 */
185int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational);
186
187/**
188 * Reads a UUID from an XML element
189 * @return 0 on success, < 0 AVERROR code on error.
190 */
191int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid);
192
193/**
194 * Returns the first child element with the specified local name
195 * @return A pointer to the child element, or NULL if no such child element exists.
196 */
197xmlNodePtr ff_imf_xml_get_child_element_by_name(xmlNodePtr parent, const char *name_utf8);
198
199#endif
200