57#include <libxml/parser.h>
61 xmlNodePtr cur_element;
63 cur_element = xmlFirstElementChild(parent);
65 if (xmlStrcmp(cur_element->name, name_utf8) == 0)
68 cur_element = xmlNextElementSibling(cur_element);
77 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
83 xmlFree(element_text);
92 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
93 if (element_text ==
NULL || sscanf(element_text,
"%i %i", &rational->
num, &rational->
den) != 2
94 || rational->
num <= 0 || rational->
den <= 0)
96 xmlFree(element_text);
105 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
106 if (element_text ==
NULL || sscanf(element_text,
"%" PRIu32, number) != 1)
108 xmlFree(element_text);
117 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
118 if (xmlStrcmp(element_text,
"true") == 0 || xmlStrcmp(element_text,
"1") == 0)
120 else if (xmlStrcmp(element_text,
"false") == 0 || xmlStrcmp(element_text,
"0") == 0)
124 xmlFree(element_text);
179 xmlNodePtr element =
NULL;
184 element->xmlChildrenNode,
196 if (digit >=
'0' && digit <=
'9')
214 for (
int i = 0;
i < 4;
i++) {
221 if (hi == -1 || lo == -1)
224 tc_comps[
i] = 10 * hi + lo;
232 xmlNodePtr tc_element =
NULL;
233 xmlNodePtr element =
NULL;
234 xmlChar *tc_str =
NULL;
254 tc_str = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
267 comps[0], comps[1], comps[2], comps[3],
275 xmlNodePtr element =
NULL;
285 xmlNodePtr element =
NULL;
295 xmlNodePtr element =
NULL;
309 if (!(marker->
label_utf8 = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1)))
312 if (!(marker->
scope_utf8 = xmlGetNoNsProp(element,
"scope"))) {
314 = xmlCharStrdup(
"http://www.smpte-ra.org/schemas/2067-3/2013#standard-markers");
325 xmlNodePtr element =
NULL;
352 av_log(log_ctx,
AV_LOG_ERROR,
"Invalid IntrinsicDuration element found in a Resource\n");
356 av_log(log_ctx,
AV_LOG_ERROR,
"EntryPoint is beyond the IntrinsicDuration of a Resource\n");
380 xmlNodePtr element =
NULL;
404 xmlNodePtr element =
NULL;
411 element = xmlFirstElementChild(marker_resource_elem);
413 if (xmlStrcmp(element->name,
"Marker") == 0) {
435 element = xmlNextElementSibling(element);
445 xmlNodePtr resource_list_elem =
NULL;
446 xmlNodePtr resource_elem =
NULL;
447 xmlNodePtr track_id_elem =
NULL;
448 unsigned long resource_elem_count;
462 "Processing IMF CPL Marker Sequence for Virtual Track " AV_PRI_UUID "\n",
480 if (!resource_list_elem)
483 resource_elem_count = xmlChildElementCount(resource_list_elem);
484 if (resource_elem_count > UINT32_MAX
496 resource_elem = xmlFirstElementChild(resource_list_elem);
497 while (resource_elem) {
506 resource_elem = xmlNextElementSibling(resource_elem);
514 if (xmlStrcmp(element->name,
"Left") == 0 || xmlStrcmp(element->name,
"Right") == 0)
517 element = xmlFirstElementChild(element);
522 element = xmlNextElementSibling(element);
532 xmlNodePtr resource_list_elem =
NULL;
533 xmlNodePtr resource_elem =
NULL;
534 xmlNodePtr track_id_elem =
NULL;
535 unsigned long resource_elem_count;
550 "Processing IMF CPL Audio Sequence for Virtual Track " AV_PRI_UUID "\n",
580 if (!resource_list_elem)
583 resource_elem_count = xmlChildElementCount(resource_list_elem);
584 if (resource_elem_count > UINT32_MAX
597 resource_elem = xmlFirstElementChild(resource_list_elem);
598 while (resource_elem) {
608 resource_elem = xmlNextElementSibling(resource_elem);
618 xmlNodePtr resource_list_elem =
NULL;
619 xmlNodePtr resource_elem =
NULL;
620 xmlNodePtr track_id_elem =
NULL;
622 unsigned long resource_elem_count;
626 av_log(log_ctx,
AV_LOG_ERROR,
"Stereoscopic 3D image virtual tracks not supported\n");
654 "Processing IMF CPL Main Image Sequence for Virtual Track " AV_PRI_UUID "\n",
659 if (!resource_list_elem)
662 resource_elem_count = xmlChildElementCount(resource_list_elem);
663 if (resource_elem_count > UINT32_MAX
678 resource_elem = xmlFirstElementChild(resource_list_elem);
679 while (resource_elem) {
690 resource_elem = xmlNextElementSibling(resource_elem);
699 xmlNodePtr segment_list_elem =
NULL;
700 xmlNodePtr segment_elem =
NULL;
701 xmlNodePtr sequence_list_elem =
NULL;
702 xmlNodePtr sequence_elem =
NULL;
710 segment_elem = xmlFirstElementChild(segment_list_elem);
711 while (segment_elem) {
715 if (sequence_list_elem) {
717 sequence_elem = xmlFirstElementChild(sequence_list_elem);
718 while (sequence_elem) {
719 if (xmlStrcmp(sequence_elem->name,
"MarkerSequence") == 0)
722 else if (xmlStrcmp(sequence_elem->name,
"MainImageSequence") == 0)
725 else if (xmlStrcmp(sequence_elem->name,
"MainAudioSequence") == 0)
731 "The following Sequence is not supported and is ignored: %s\n",
732 sequence_elem->name);
738 sequence_elem = xmlNextElementSibling(sequence_elem);
742 segment_elem = xmlNextElementSibling(segment_elem);
751 xmlNodePtr cpl_element =
NULL;
759 cpl_element = xmlDocGetRootElement(doc);
760 if (!cpl_element || xmlStrcmp(cpl_element->name,
"CompositionPlaylist")) {
761 av_log(log_ctx,
AV_LOG_ERROR,
"The root element of the CPL is not CompositionPlaylist\n");
767 av_log(log_ctx,
AV_LOG_ERROR,
"Cannot read the ContentTitle element from the IMF CPL\n");
779 av_log(log_ctx,
AV_LOG_ERROR,
"Invalid CompositionTimecode element found in the IMF CPL\n");
896 doc = xmlReadMemory(buf.str, buf.len,
NULL,
NULL, 0);
900 "XML parsing failed when reading the IMF CPL\n");
910 "IMF CPL ContentTitle: %s\n",
911 (*cpl)->content_title_utf8);
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
int avio_read_to_bprint(AVIOContext *h, struct AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define i(width, name, range_min, range_max)
static av_cold void cleanup(FlashSV2Context *s)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
size_t static size_t av_strnlen(const char *s, size_t len)
Get the count of continuous non zero chars starting from the beginning.
Public header file for the processing of Interoperable Master Format (IMF) packages.
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.
static int ff_imf_xml_read_boolean(xmlNodePtr element, int *value)
static void imf_marker_resource_init(FFIMFMarkerResource *rsrc)
static void imf_marker_free(FFIMFMarker *marker)
FFIMFCPL * ff_imf_cpl_alloc(void)
Allocates and initializes an FFIMFCPL data structure.
static void imf_cpl_init(FFIMFCPL *cpl)
static void imf_marker_init(FFIMFMarker *marker)
int ff_imf_parse_cpl(void *log_ctx, AVIOContext *in, FFIMFCPL **cpl)
Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
static int fill_trackfile_resource(void *log_ctx, xmlNodePtr tf_resource_elem, FFIMFTrackFileResource *tf_resource, FFIMFCPL *cpl)
static int fill_marker_resource(void *log_ctx, xmlNodePtr marker_resource_elem, FFIMFMarkerResource *marker_resource, FFIMFCPL *cpl)
static int has_stereo_resources(xmlNodePtr element)
static void imf_trackfile_resource_init(FFIMFTrackFileResource *rsrc)
static void imf_marker_resource_free(FFIMFMarkerResource *rsrc)
static void imf_base_resource_init(FFIMFBaseResource *rsrc)
static int push_main_image_2d_sequence(void *log_ctx, xmlNodePtr image_sequence_elem, FFIMFCPL *cpl)
static int fill_id(xmlNodePtr cpl_element, FFIMFCPL *cpl)
static void imf_marker_virtual_track_init(FFIMFMarkerVirtualTrack *track)
int ff_imf_parse_cpl_from_xml_dom(void *log_ctx, xmlDocPtr doc, FFIMFCPL **cpl)
Parse an IMF CompositionPlaylist element into the FFIMFCPL data structure.
static void imf_trackfile_virtual_track_init(FFIMFTrackFileVirtualTrack *track)
int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational)
Reads a positive AVRational from an XML element.
static int parse_cpl_tc_type(const char *s, int *tc_comps)
Parses a string that conform to the TimecodeType used in IMF CPL and defined in SMPTE ST 2067-3.
static int fill_marker(xmlNodePtr marker_elem, FFIMFMarker *marker)
static int digit_to_int(char digit)
void ff_imf_cpl_free(FFIMFCPL *cpl)
Deletes an FFIMFCPL data structure previously instantiated with ff_imf_cpl_alloc().
static int push_marker_sequence(void *log_ctx, xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl)
static void imf_trackfile_virtual_track_free(FFIMFTrackFileVirtualTrack *vt)
static void imf_marker_virtual_track_free(FFIMFMarkerVirtualTrack *vt)
static int fill_content_title(xmlNodePtr cpl_element, FFIMFCPL *cpl)
static int fill_base_resource(void *log_ctx, xmlNodePtr resource_elem, FFIMFBaseResource *resource, FFIMFCPL *cpl)
static int push_main_audio_sequence(void *log_ctx, xmlNodePtr audio_sequence_elem, FFIMFCPL *cpl)
int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t *number)
Reads an unsigned 32-bit integer from an XML element.
int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
Reads a UUID from an XML element.
static void imf_base_virtual_track_init(FFIMFBaseVirtualTrack *track)
static int fill_timecode(xmlNodePtr cpl_element, FFIMFCPL *cpl)
static int fill_edit_rate(xmlNodePtr cpl_element, FFIMFCPL *cpl)
static int fill_virtual_tracks(void *log_ctx, xmlNodePtr cpl_element, FFIMFCPL *cpl)
Memory handling functions.
Rational number (pair of numerator and denominator).
IMF Composition Playlist Base Resource.
AVRational edit_rate
BaseResourceType/EditRate.
uint32_t duration
BaseResourceType/Duration.
uint32_t repeat_count
BaseResourceType/RepeatCount.
uint32_t entry_point
BaseResourceType/EntryPoint.
IMF Composition Playlist Virtual Track.
AVUUID id_uuid
TrackId associated with the Virtual Track.
IMF Composition Playlist.
FFIMFMarkerVirtualTrack * main_markers_track
Main Marker Virtual Track.
AVRational edit_rate
CompositionPlaylist/EditRate element.
FFIMFTrackFileVirtualTrack * main_audio_tracks
Main Audio Virtual Tracks.
xmlChar * content_title_utf8
CompositionPlaylist/ContentTitle element.
uint32_t main_audio_track_count
Number of Main Audio Virtual Tracks.
FFIMFTrackFileVirtualTrack * main_image_2d_track
Main Image Virtual Track.
AVUUID id_uuid
CompositionPlaylist/Id element.
AVTimecode * tc
CompositionPlaylist/CompositionTimecode element.
IMF Composition Playlist Marker Resource.
uint32_t marker_count
Number of Marker elements.
FFIMFMarker * markers
Marker elements.
IMF Composition Playlist Virtual Track that consists of Marker Resources.
uint32_t resource_count
Number of Resource elements present in the Virtual Track.
FFIMFBaseVirtualTrack base
FFIMFMarkerResource * resources
Resource elements of the Virtual Track.
xmlChar * label_utf8
Marker/Label.
uint32_t offset
Marker/Offset.
xmlChar * scope_utf8
Marker/Label/@scope.
IMF Composition Playlist Track File Resource.
AVUUID track_file_uuid
TrackFileResourceType/TrackFileId.
IMF Composition Playlist Virtual Track that consists of Track File Resources.
FFIMFTrackFileResource * resources
Resource elements of the Virtual Track.
uint32_t resource_count
Number of Resource elements present in the Virtual Track.
unsigned int resources_alloc_sz
Size of the resources buffer.
FFIMFBaseVirtualTrack base
int av_timecode_init_from_components(AVTimecode *tc, AVRational rate, int flags, int hh, int mm, int ss, int ff, void *log_ctx)
Init a timecode struct from the passed timecode components.
@ AV_TIMECODE_FLAG_DROPFRAME
timecode is drop frame
int av_uuid_urn_parse(const char *in, AVUUID uu)
Parses a URN representation of a UUID, as specified at IETF RFC 4122, into an AVUUID.
static void av_uuid_copy(AVUUID dest, const AVUUID src)
Copies the bytes of src into dest.
static int av_uuid_equal(const AVUUID uu1, const AVUUID uu2)
Compares two UUIDs for equality.
static void av_uuid_nil(AVUUID uu)
Sets a UUID to the nil UUID, i.e.
uint8_t AVUUID[AV_UUID_LEN]