aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/imf.h
blob: 62c4468ce9fc3dd4e1bd3ebbda852a5ccc313391 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/*
 *
 * Copyright (c) Sandflow Consulting LLC
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * Public header file for the processing of Interoperable Master Format (IMF)
 * packages.
 *
 * @author Pierre-Anthony Lemieux
 * @author Valentin Noel
 * @file
 * @ingroup lavu_imf
 */

#ifndef AVFORMAT_IMF_H
#define AVFORMAT_IMF_H

#include "avformat.h"
#include "libavformat/avio.h"
#include "libavutil/rational.h"
#include <libxml/tree.h>

#define FF_IMF_UUID_FORMAT                            \
    "urn:uuid:%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-" \
    "%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"

/**
 * UUID as defined in IETF RFC 422
 */
typedef uint8_t FFIMFUUID[16];

/**
 * IMF Composition Playlist Base Resource
 */
typedef struct FFIMFBaseResource {
    AVRational edit_rate;  /**< BaseResourceType/EditRate */
    uint32_t entry_point;  /**< BaseResourceType/EntryPoint */
    uint32_t duration;     /**< BaseResourceType/Duration */
    uint32_t repeat_count; /**< BaseResourceType/RepeatCount */
} FFIMFBaseResource;

/**
 * IMF Composition Playlist Track File Resource
 */
typedef struct FFIMFTrackFileResource {
    FFIMFBaseResource base;
    FFIMFUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
} FFIMFTrackFileResource;

/**
 * IMF Marker
 */
typedef struct FFIMFMarker {
    xmlChar *label_utf8; /**< Marker/Label */
    xmlChar *scope_utf8; /**< Marker/Label/\@scope */
    uint32_t offset;     /**< Marker/Offset */
} FFIMFMarker;

/**
 * IMF Composition Playlist Marker Resource
 */
typedef struct FFIMFMarkerResource {
    FFIMFBaseResource base;
    uint32_t marker_count; /**< Number of Marker elements */
    FFIMFMarker *markers;  /**< Marker elements */
} FFIMFMarkerResource;

/**
 * IMF Composition Playlist Virtual Track
 */
typedef struct FFIMFBaseVirtualTrack {
    FFIMFUUID id_uuid; /**< TrackId associated with the Virtual Track */
} FFIMFBaseVirtualTrack;

/**
 * IMF Composition Playlist Virtual Track that consists of Track File Resources
 */
typedef struct FFIMFTrackFileVirtualTrack {
    FFIMFBaseVirtualTrack base;
    uint32_t resource_count;           /**< Number of Resource elements present in the Virtual Track */
    FFIMFTrackFileResource *resources; /**< Resource elements of the Virtual Track */
    unsigned int resources_alloc_sz;   /**< Size of the resources buffer */
} FFIMFTrackFileVirtualTrack;

/**
 * IMF Composition Playlist Virtual Track that consists of Marker Resources
 */
typedef struct FFIMFMarkerVirtualTrack {
    FFIMFBaseVirtualTrack base;
    uint32_t resource_count;        /**< Number of Resource elements present in the Virtual Track */
    FFIMFMarkerResource *resources; /**< Resource elements of the Virtual Track */
} FFIMFMarkerVirtualTrack;

/**
 * IMF Composition Playlist
 */
typedef struct FFIMFCPL {
    FFIMFUUID id_uuid;                               /**< CompositionPlaylist/Id element */
    xmlChar *content_title_utf8;                     /**< CompositionPlaylist/ContentTitle element */
    AVRational edit_rate;                            /**< CompositionPlaylist/EditRate element */
    FFIMFMarkerVirtualTrack *main_markers_track;     /**< Main Marker Virtual Track */
    FFIMFTrackFileVirtualTrack *main_image_2d_track; /**< Main Image Virtual Track */
    uint32_t main_audio_track_count;                 /**< Number of Main Audio Virtual Tracks */
    FFIMFTrackFileVirtualTrack *main_audio_tracks;   /**< Main Audio Virtual Tracks */
} FFIMFCPL;

/**
 * Parse an IMF CompositionPlaylist element into the FFIMFCPL 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 FFIMFCPL structure (or
 *  NULL if the CPL could not be parsed). The client is responsible for freeing
 *  the FFIMFCPL structure using ff_imf_cpl_free().
 * @return A non-zero value in case of an error.
 */
int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl);

/**
 * Parse an IMF Composition Playlist document into the FFIMFCPL 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 FFIMFCPL structure (or
 * NULL if the CPL could not be parsed). The client is responsible for freeing
 * the FFIMFCPL structure using ff_imf_cpl_free().
 * @return A non-zero value in case of an error.
 */
int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl);

/**
 * Allocates and initializes an FFIMFCPL data structure.
 * @return A pointer to the newly constructed FFIMFCPL structure (or NULL if the
 * structure could not be constructed). The client is responsible for freeing
 * the FFIMFCPL structure using ff_imf_cpl_free().
 */
FFIMFCPL *ff_imf_cpl_alloc(void);

/**
 * Deletes an FFIMFCPL data structure previously instantiated with ff_imf_cpl_alloc().
 * @param[in] cpl The FFIMFCPL structure to delete.
 */
void ff_imf_cpl_free(FFIMFCPL *cpl);

/**
 * Reads an unsigned 32-bit integer from an XML element
 * @return 0 on success, < 0 AVERROR code on error.
 */
int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t *number);

/**
 * Reads an AVRational from an XML element
 * @return 0 on success, < 0 AVERROR code on error.
 */
int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational);

/**
 * Reads a UUID from an XML element
 * @return 0 on success, < 0 AVERROR code on error.
 */
int ff_imf_xml_read_uuid(xmlNodePtr element, uint8_t uuid[16]);

/**
 * Returns the first child element with the specified local name
 * @return A pointer to the child element, or NULL if no such child element exists.
 */
xmlNodePtr ff_imf_xml_get_child_element_by_name(xmlNodePtr parent, const char *name_utf8);

#endif