FFmpeg
imf.h
Go to the documentation of this file.
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 "libavutil/timecode.h"
63 #include <libxml/tree.h>
64 
65 /**
66  * IMF Composition Playlist Base Resource
67  */
68 typedef struct FFIMFBaseResource {
69  AVRational edit_rate; /**< BaseResourceType/EditRate */
70  uint32_t entry_point; /**< BaseResourceType/EntryPoint */
71  uint32_t duration; /**< BaseResourceType/Duration */
72  uint32_t repeat_count; /**< BaseResourceType/RepeatCount */
74 
75 /**
76  * IMF Composition Playlist Track File Resource
77  */
78 typedef struct FFIMFTrackFileResource {
80  AVUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
82 
83 /**
84  * IMF Marker
85  */
86 typedef struct FFIMFMarker {
87  xmlChar *label_utf8; /**< Marker/Label */
88  xmlChar *scope_utf8; /**< Marker/Label/\@scope */
89  uint32_t offset; /**< Marker/Offset */
90 } FFIMFMarker;
91 
92 /**
93  * IMF Composition Playlist Marker Resource
94  */
95 typedef struct FFIMFMarkerResource {
97  uint32_t marker_count; /**< Number of Marker elements */
98  FFIMFMarker *markers; /**< Marker elements */
100 
101 /**
102  * IMF Composition Playlist Virtual Track
103  */
104 typedef struct FFIMFBaseVirtualTrack {
105  AVUUID id_uuid; /**< TrackId associated with the Virtual Track */
107 
108 /**
109  * IMF Composition Playlist Virtual Track that consists of Track File Resources
110  */
113  uint32_t resource_count; /**< Number of Resource elements present in the Virtual Track */
114  FFIMFTrackFileResource *resources; /**< Resource elements of the Virtual Track */
115  unsigned int resources_alloc_sz; /**< Size of the resources buffer */
117 
118 /**
119  * IMF Composition Playlist Virtual Track that consists of Marker Resources
120  */
121 typedef struct FFIMFMarkerVirtualTrack {
123  uint32_t resource_count; /**< Number of Resource elements present in the Virtual Track */
124  FFIMFMarkerResource *resources; /**< Resource elements of the Virtual Track */
126 
127 /**
128  * IMF Composition Playlist
129  */
130 typedef struct FFIMFCPL {
131  AVUUID id_uuid; /**< CompositionPlaylist/Id element */
132  xmlChar *content_title_utf8; /**< CompositionPlaylist/ContentTitle element */
133  AVRational edit_rate; /**< CompositionPlaylist/EditRate element */
134  AVTimecode *tc; /**< CompositionPlaylist/CompositionTimecode element */
135  FFIMFMarkerVirtualTrack *main_markers_track; /**< Main Marker Virtual Track */
136  FFIMFTrackFileVirtualTrack *main_image_2d_track; /**< Main Image Virtual Track */
137  uint32_t main_audio_track_count; /**< Number of Main Audio Virtual Tracks */
138  FFIMFTrackFileVirtualTrack *main_audio_tracks; /**< Main Audio Virtual Tracks */
139 } FFIMFCPL;
140 
141 /**
142  * Parse an IMF CompositionPlaylist element into the FFIMFCPL data structure.
143  * @param[in] doc An XML document from which the CPL is read.
144  * @param[out] cpl Pointer to a memory area (allocated by the client), where the
145  * function writes a pointer to the newly constructed FFIMFCPL structure (or
146  * NULL if the CPL could not be parsed). The client is responsible for freeing
147  * the FFIMFCPL structure using ff_imf_cpl_free().
148  * @return A non-zero value in case of an error.
149  */
150 int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl);
151 
152 /**
153  * Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
154  * @param[in] in The context from which the CPL is read.
155  * @param[out] cpl Pointer to a memory area (allocated by the client), where the
156  * function writes a pointer to the newly constructed FFIMFCPL structure (or
157  * NULL if the CPL could not be parsed). The client is responsible for freeing
158  * the FFIMFCPL structure using ff_imf_cpl_free().
159  * @return A non-zero value in case of an error.
160  */
161 int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl);
162 
163 /**
164  * Allocates and initializes an FFIMFCPL data structure.
165  * @return A pointer to the newly constructed FFIMFCPL structure (or NULL if the
166  * structure could not be constructed). The client is responsible for freeing
167  * the FFIMFCPL structure using ff_imf_cpl_free().
168  */
170 
171 /**
172  * Deletes an FFIMFCPL data structure previously instantiated with ff_imf_cpl_alloc().
173  * @param[in] cpl The FFIMFCPL structure to delete.
174  */
175 void ff_imf_cpl_free(FFIMFCPL *cpl);
176 
177 /**
178  * Reads an unsigned 32-bit integer from an XML element
179  * @return 0 on success, < 0 AVERROR code on error.
180  */
181 int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t *number);
182 
183 /**
184  * Reads an AVRational from an XML element
185  * @return 0 on success, < 0 AVERROR code on error.
186  */
187 int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational);
188 
189 /**
190  * Reads a UUID from an XML element
191  * @return 0 on success, < 0 AVERROR code on error.
192  */
193 int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid);
194 
195 /**
196  * Returns the first child element with the specified local name
197  * @return A pointer to the child element, or NULL if no such child element exists.
198  */
199 xmlNodePtr ff_imf_xml_get_child_element_by_name(xmlNodePtr parent, const char *name_utf8);
200 
201 #endif
ff_imf_parse_cpl_from_xml_dom
int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl)
Parse an IMF CompositionPlaylist element into the FFIMFCPL data structure.
Definition: imf_cpl.c:758
FFIMFTrackFileVirtualTrack::resources
FFIMFTrackFileResource * resources
Resource elements of the Virtual Track.
Definition: imf.h:114
FFIMFCPL::id_uuid
AVUUID id_uuid
CompositionPlaylist/Id element.
Definition: imf.h:131
AVUUID
uint8_t AVUUID[AV_UUID_LEN]
Definition: uuid.h:60
FFIMFMarkerVirtualTrack::resources
FFIMFMarkerResource * resources
Resource elements of the Virtual Track.
Definition: imf.h:124
rational.h
FFIMFTrackFileVirtualTrack::resource_count
uint32_t resource_count
Number of Resource elements present in the Virtual Track.
Definition: imf.h:113
ff_imf_xml_read_uint32
int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t *number)
Reads an unsigned 32-bit integer from an XML element.
Definition: imf_cpl.c:102
FFIMFMarkerVirtualTrack
IMF Composition Playlist Virtual Track that consists of Marker Resources.
Definition: imf.h:121
FFIMFCPL::content_title_utf8
xmlChar * content_title_utf8
CompositionPlaylist/ContentTitle element.
Definition: imf.h:132
FFIMFCPL::main_audio_tracks
FFIMFTrackFileVirtualTrack * main_audio_tracks
Main Audio Virtual Tracks.
Definition: imf.h:138
FFIMFMarkerResource::base
FFIMFBaseResource base
Definition: imf.h:96
timecode.h
ff_imf_cpl_free
void ff_imf_cpl_free(FFIMFCPL *cpl)
Deletes an FFIMFCPL data structure previously instantiated with ff_imf_cpl_alloc().
Definition: imf_cpl.c:851
FFIMFBaseResource::duration
uint32_t duration
BaseResourceType/Duration.
Definition: imf.h:71
FFIMFMarker
IMF Marker.
Definition: imf.h:86
ff_imf_xml_get_child_element_by_name
xmlNodePtr ff_imf_xml_get_child_element_by_name(xmlNodePtr parent, const char *name_utf8)
Returns the first child element with the specified local name.
Definition: imf_cpl.c:59
FFIMFCPL::main_markers_track
FFIMFMarkerVirtualTrack * main_markers_track
Main Marker Virtual Track.
Definition: imf.h:135
FFIMFCPL::tc
AVTimecode * tc
CompositionPlaylist/CompositionTimecode element.
Definition: imf.h:134
FFIMFTrackFileVirtualTrack
IMF Composition Playlist Virtual Track that consists of Track File Resources.
Definition: imf.h:111
FFIMFCPL::edit_rate
AVRational edit_rate
CompositionPlaylist/EditRate element.
Definition: imf.h:133
FFIMFTrackFileVirtualTrack::resources_alloc_sz
unsigned int resources_alloc_sz
Size of the resources buffer.
Definition: imf.h:115
FFIMFBaseVirtualTrack
IMF Composition Playlist Virtual Track.
Definition: imf.h:104
FFIMFBaseResource
IMF Composition Playlist Base Resource.
Definition: imf.h:68
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
FFIMFMarkerVirtualTrack::base
FFIMFBaseVirtualTrack base
Definition: imf.h:122
FFIMFTrackFileVirtualTrack::base
FFIMFBaseVirtualTrack base
Definition: imf.h:112
FFIMFBaseResource::edit_rate
AVRational edit_rate
BaseResourceType/EditRate.
Definition: imf.h:69
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
FFIMFTrackFileResource::track_file_uuid
AVUUID track_file_uuid
TrackFileResourceType/TrackFileId.
Definition: imf.h:80
uuid.h
avio.h
FFIMFBaseResource::repeat_count
uint32_t repeat_count
BaseResourceType/RepeatCount.
Definition: imf.h:72
ff_imf_parse_cpl
int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl)
Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
Definition: imf_cpl.c:880
FFIMFBaseVirtualTrack::id_uuid
AVUUID id_uuid
TrackId associated with the Virtual Track.
Definition: imf.h:105
FFIMFBaseResource::entry_point
uint32_t entry_point
BaseResourceType/EntryPoint.
Definition: imf.h:70
ff_imf_cpl_alloc
FFIMFCPL * ff_imf_cpl_alloc(void)
Allocates and initializes an FFIMFCPL data structure.
Definition: imf_cpl.c:840
FFIMFMarkerResource
IMF Composition Playlist Marker Resource.
Definition: imf.h:95
FFIMFMarkerResource::markers
FFIMFMarker * markers
Marker elements.
Definition: imf.h:98
avformat.h
FFIMFTrackFileResource
IMF Composition Playlist Track File Resource.
Definition: imf.h:78
FFIMFMarker::offset
uint32_t offset
Marker/Offset.
Definition: imf.h:89
FFIMFCPL::main_audio_track_count
uint32_t main_audio_track_count
Number of Main Audio Virtual Tracks.
Definition: imf.h:137
FFIMFMarkerVirtualTrack::resource_count
uint32_t resource_count
Number of Resource elements present in the Virtual Track.
Definition: imf.h:123
ff_imf_xml_read_uuid
int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
Reads a UUID from an XML element.
Definition: imf_cpl.c:73
FFIMFCPL::main_image_2d_track
FFIMFTrackFileVirtualTrack * main_image_2d_track
Main Image Virtual Track.
Definition: imf.h:136
FFIMFMarkerResource::marker_count
uint32_t marker_count
Number of Marker elements.
Definition: imf.h:97
FFIMFCPL
IMF Composition Playlist.
Definition: imf.h:130
FFIMFMarker::label_utf8
xmlChar * label_utf8
Marker/Label.
Definition: imf.h:87
AVTimecode
Definition: timecode.h:41
ff_imf_xml_read_rational
int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational)
Reads an AVRational from an XML element.
Definition: imf_cpl.c:88
FFIMFMarker::scope_utf8
xmlChar * scope_utf8
Marker/Label/@scope.
Definition: imf.h:88
FFIMFTrackFileResource::base
FFIMFBaseResource base
Definition: imf.h:79