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 <libxml/tree.h>
63 
64 /**
65  * IMF Composition Playlist Base Resource
66  */
67 typedef 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 */
73 
74 /**
75  * IMF Composition Playlist Track File Resource
76  */
77 typedef struct FFIMFTrackFileResource {
79  AVUUID track_file_uuid; /**< TrackFileResourceType/TrackFileId */
81 
82 /**
83  * IMF Marker
84  */
85 typedef 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  */
94 typedef struct FFIMFMarkerResource {
96  uint32_t marker_count; /**< Number of Marker elements */
97  FFIMFMarker *markers; /**< Marker elements */
99 
100 /**
101  * IMF Composition Playlist Virtual Track
102  */
103 typedef struct FFIMFBaseVirtualTrack {
104  AVUUID id_uuid; /**< TrackId associated with the Virtual Track */
106 
107 /**
108  * IMF Composition Playlist Virtual Track that consists of Track File Resources
109  */
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 */
116 
117 /**
118  * IMF Composition Playlist Virtual Track that consists of Marker Resources
119  */
120 typedef struct FFIMFMarkerVirtualTrack {
122  uint32_t resource_count; /**< Number of Resource elements present in the Virtual Track */
123  FFIMFMarkerResource *resources; /**< Resource elements of the Virtual Track */
125 
126 /**
127  * IMF Composition Playlist
128  */
129 typedef 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  */
148 int 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  */
159 int 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  */
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  */
173 void 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  */
179 int 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  */
185 int 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  */
191 int 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  */
197 xmlNodePtr ff_imf_xml_get_child_element_by_name(xmlNodePtr parent, const char *name_utf8);
198 
199 #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:661
FFIMFTrackFileVirtualTrack::resources
FFIMFTrackFileResource * resources
Resource elements of the Virtual Track.
Definition: imf.h:113
FFIMFCPL::id_uuid
AVUUID id_uuid
CompositionPlaylist/Id element.
Definition: imf.h:130
AVUUID
uint8_t AVUUID[AV_UUID_LEN]
Definition: uuid.h:60
FFIMFMarkerVirtualTrack::resources
FFIMFMarkerResource * resources
Resource elements of the Virtual Track.
Definition: imf.h:123
rational.h
FFIMFTrackFileVirtualTrack::resource_count
uint32_t resource_count
Number of Resource elements present in the Virtual Track.
Definition: imf.h:112
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:104
FFIMFMarkerVirtualTrack
IMF Composition Playlist Virtual Track that consists of Marker Resources.
Definition: imf.h:120
FFIMFCPL::content_title_utf8
xmlChar * content_title_utf8
CompositionPlaylist/ContentTitle element.
Definition: imf.h:131
FFIMFCPL::main_audio_tracks
FFIMFTrackFileVirtualTrack * main_audio_tracks
Main Audio Virtual Tracks.
Definition: imf.h:136
FFIMFMarkerResource::base
FFIMFBaseResource base
Definition: imf.h:95
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:751
FFIMFBaseResource::duration
uint32_t duration
BaseResourceType/Duration.
Definition: imf.h:70
FFIMFMarker
IMF Marker.
Definition: imf.h:85
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:133
FFIMFTrackFileVirtualTrack
IMF Composition Playlist Virtual Track that consists of Track File Resources.
Definition: imf.h:110
FFIMFCPL::edit_rate
AVRational edit_rate
CompositionPlaylist/EditRate element.
Definition: imf.h:132
FFIMFTrackFileVirtualTrack::resources_alloc_sz
unsigned int resources_alloc_sz
Size of the resources buffer.
Definition: imf.h:114
FFIMFBaseVirtualTrack
IMF Composition Playlist Virtual Track.
Definition: imf.h:103
FFIMFBaseResource
IMF Composition Playlist Base Resource.
Definition: imf.h:67
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
FFIMFMarkerVirtualTrack::base
FFIMFBaseVirtualTrack base
Definition: imf.h:121
FFIMFTrackFileVirtualTrack::base
FFIMFBaseVirtualTrack base
Definition: imf.h:111
FFIMFBaseResource::edit_rate
AVRational edit_rate
BaseResourceType/EditRate.
Definition: imf.h:68
AVIOContext
Bytestream IO Context.
Definition: avio.h:162
FFIMFTrackFileResource::track_file_uuid
AVUUID track_file_uuid
TrackFileResourceType/TrackFileId.
Definition: imf.h:79
uuid.h
avio.h
FFIMFBaseResource::repeat_count
uint32_t repeat_count
BaseResourceType/RepeatCount.
Definition: imf.h:71
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:777
FFIMFBaseVirtualTrack::id_uuid
AVUUID id_uuid
TrackId associated with the Virtual Track.
Definition: imf.h:104
FFIMFBaseResource::entry_point
uint32_t entry_point
BaseResourceType/EntryPoint.
Definition: imf.h:69
ff_imf_cpl_alloc
FFIMFCPL * ff_imf_cpl_alloc(void)
Allocates and initializes an FFIMFCPL data structure.
Definition: imf_cpl.c:740
FFIMFMarkerResource
IMF Composition Playlist Marker Resource.
Definition: imf.h:94
FFIMFMarkerResource::markers
FFIMFMarker * markers
Marker elements.
Definition: imf.h:97
avformat.h
FFIMFTrackFileResource
IMF Composition Playlist Track File Resource.
Definition: imf.h:77
FFIMFMarker::offset
uint32_t offset
Marker/Offset.
Definition: imf.h:88
FFIMFCPL::main_audio_track_count
uint32_t main_audio_track_count
Number of Main Audio Virtual Tracks.
Definition: imf.h:135
FFIMFMarkerVirtualTrack::resource_count
uint32_t resource_count
Number of Resource elements present in the Virtual Track.
Definition: imf.h:122
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:134
FFIMFMarkerResource::marker_count
uint32_t marker_count
Number of Marker elements.
Definition: imf.h:96
FFIMFCPL
IMF Composition Playlist.
Definition: imf.h:129
FFIMFMarker::label_utf8
xmlChar * label_utf8
Marker/Label.
Definition: imf.h:86
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:89
FFIMFMarker::scope_utf8
xmlChar * scope_utf8
Marker/Label/@scope.
Definition: imf.h:87
FFIMFTrackFileResource::base
FFIMFBaseResource base
Definition: imf.h:78