History

avformat/imf: clean-up logging * remove logging to NULL * remove extraneous logging

Pierre-Anthony Lemieux committed 3 years ago

Commit 0f2f0dd1 parent ba2c7914 files · +91 −100Browse files

Unified · Split

4 files
  1. libavformat/imf.h +4 −2
  2. libavformat/imf_cpl.c +84 −95
  3. libavformat/imfdec.c +1 −1
  4. libavformat/tests/imf.c +2 −2
libavformat/imf.h+4−2
@@ -140,6 +140,7 @@ typedef struct FFIMFCPL { · 139 unmodified lines
140 140
141/**141/**
142 * Parse an IMF CompositionPlaylist element into the FFIMFCPL data structure.142 * Parse an IMF CompositionPlaylist element into the FFIMFCPL data structure.
143 * @param[in] log_ctx Logging context (points to an instance of AVClass). May be NULL.
143 * @param[in] doc An XML document from which the CPL is read.144 * @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 the145 * @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 (or146 * function writes a pointer to the newly constructed FFIMFCPL structure (or
@@ -147,10 +148,11 @@ typedef struct FFIMFCPL { · 1 unmodified line
147 * the FFIMFCPL structure using ff_imf_cpl_free().148 * the FFIMFCPL structure using ff_imf_cpl_free().
148 * @return A non-zero value in case of an error.149 * @return A non-zero value in case of an error.
149 */150 */
150int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl);151int ff_imf_parse_cpl_from_xml_dom(void *log_ctx, xmlDocPtr doc, FFIMFCPL **cpl);
151 152
152/**153/**
153 * Parse an IMF Composition Playlist document into the FFIMFCPL data structure.154 * Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
155 * @param[in] log_ctx Logging context (points to an instance of AVClass). May be NULL.
154 * @param[in] in The context from which the CPL is read.156 * @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 the157 * @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 (or158 * function writes a pointer to the newly constructed FFIMFCPL structure (or
@@ -158,7 +160,7 @@ int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl); · 1 unmodified line
158 * the FFIMFCPL structure using ff_imf_cpl_free().160 * the FFIMFCPL structure using ff_imf_cpl_free().
159 * @return A non-zero value in case of an error.161 * @return A non-zero value in case of an error.
160 */162 */
161int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl);163int ff_imf_parse_cpl(void *log_ctx, AVIOContext *in, FFIMFCPL **cpl);
162 164
163/**165/**
164 * Allocates and initializes an FFIMFCPL data structure.166 * Allocates and initializes an FFIMFCPL data structure.
libavformat/imf_cpl.c+84−95
@@ -76,10 +76,8 @@ int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid) · 75 unmodified lines
76 76
77 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);77 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
78 ret = av_uuid_urn_parse(element_text, uuid);78 ret = av_uuid_urn_parse(element_text, uuid);
79 if (ret) {79 if (ret)
80 av_log(NULL, AV_LOG_ERROR, "Invalid UUID\n");
81 ret = AVERROR_INVALIDDATA;80 ret = AVERROR_INVALIDDATA;
82 }
83 xmlFree(element_text);81 xmlFree(element_text);
84 82
85 return ret;83 return ret;
@@ -90,10 +88,8 @@ int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational) · 4 unmodified lines
90 int ret = 0;88 int ret = 0;
91 89
92 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);90 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
93 if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2) {91 if (sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2)
94 av_log(NULL, AV_LOG_ERROR, "Invalid rational number\n");
95 ret = AVERROR_INVALIDDATA;92 ret = AVERROR_INVALIDDATA;
96 }
97 xmlFree(element_text);93 xmlFree(element_text);
98 94
99 return ret;95 return ret;
@@ -104,10 +100,8 @@ int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t *number) · 4 unmodified lines
104 int ret = 0;100 int ret = 0;
105 101
106 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);102 xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
107 if (sscanf(element_text, "%" PRIu32, number) != 1) {103 if (sscanf(element_text, "%" PRIu32, number) != 1)
108 av_log(NULL, AV_LOG_ERROR, "Invalid unsigned 32-bit integer");
109 ret = AVERROR_INVALIDDATA;104 ret = AVERROR_INVALIDDATA;
110 }
111 xmlFree(element_text);105 xmlFree(element_text);
112 106
113 return ret;107 return ret;
@@ -181,10 +175,8 @@ static int fill_content_title(xmlNodePtr cpl_element, FFIMFCPL *cpl) · 67 unmodified lines
181{175{
182 xmlNodePtr element = NULL;176 xmlNodePtr element = NULL;
183 177
184 if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, "ContentTitle"))) {178 if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, "ContentTitle")))
185 av_log(NULL, AV_LOG_ERROR, "ContentTitle element not found in the IMF CPL\n");
186 return AVERROR_INVALIDDATA;179 return AVERROR_INVALIDDATA;
187 }
188 cpl->content_title_utf8 = xmlNodeListGetString(cpl_element->doc,180 cpl->content_title_utf8 = xmlNodeListGetString(cpl_element->doc,
189 element->xmlChildrenNode,181 element->xmlChildrenNode,
190 1);182 1);
@@ -242,22 +234,15 @@ static int fill_timecode(xmlNodePtr cpl_element, FFIMFCPL *cpl) · 51 unmodified lines
242 return 0;234 return 0;
243 235
244 element = ff_imf_xml_get_child_element_by_name(tc_element, "TimecodeDropFrame");236 element = ff_imf_xml_get_child_element_by_name(tc_element, "TimecodeDropFrame");
245 if (!element) {237 if (!element)
246 av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
247 a TimecodeDropFrame child element\n");
248 return AVERROR_INVALIDDATA;238 return AVERROR_INVALIDDATA;
249 }
250 239
251 if (ff_imf_xml_read_boolean(element, &df)) {240 if (ff_imf_xml_read_boolean(element, &df))
252 av_log(NULL, AV_LOG_ERROR, "TimecodeDropFrame element is invalid\n");
253 return AVERROR_INVALIDDATA;241 return AVERROR_INVALIDDATA;
254 }242
255 element = ff_imf_xml_get_child_element_by_name(tc_element, "TimecodeStartAddress");243 element = ff_imf_xml_get_child_element_by_name(tc_element, "TimecodeStartAddress");
256 if (!element) {244 if (!element)
257 av_log(NULL, AV_LOG_ERROR, "CompositionTimecode element is missing\
258 a TimecodeStartAddress child element\n");
259 return AVERROR_INVALIDDATA;245 return AVERROR_INVALIDDATA;
260 }
261 246
262 tc_str = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);247 tc_str = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1);
263 ret = parse_cpl_tc_type(tc_str, comps);248 ret = parse_cpl_tc_type(tc_str, comps);
@@ -280,10 +265,8 @@ static int fill_edit_rate(xmlNodePtr cpl_element, FFIMFCPL *cpl) · 16 unmodified lines
280{265{
281 xmlNodePtr element = NULL;266 xmlNodePtr element = NULL;
282 267
283 if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, "EditRate"))) {268 if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, "EditRate")))
284 av_log(NULL, AV_LOG_ERROR, "EditRate element not found in the IMF CPL\n");
285 return AVERROR_INVALIDDATA;269 return AVERROR_INVALIDDATA;
286 }
287 270
288 return ff_imf_xml_read_rational(element, &cpl->edit_rate);271 return ff_imf_xml_read_rational(element, &cpl->edit_rate);
289}272}
@@ -292,10 +275,8 @@ static int fill_id(xmlNodePtr cpl_element, FFIMFCPL *cpl) · 2 unmodified lines
292{275{
293 xmlNodePtr element = NULL;276 xmlNodePtr element = NULL;
294 277
295 if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, "Id"))) {278 if (!(element = ff_imf_xml_get_child_element_by_name(cpl_element, "Id")))
296 av_log(NULL, AV_LOG_ERROR, "Id element not found in the IMF CPL\n");
297 return AVERROR_INVALIDDATA;279 return AVERROR_INVALIDDATA;
298 }
299 280
300 return ff_imf_xml_read_uuid(element, cpl->id_uuid);281 return ff_imf_xml_read_uuid(element, cpl->id_uuid);
301}282}
@@ -306,22 +287,19 @@ static int fill_marker(xmlNodePtr marker_elem, FFIMFMarker *marker) · 4 unmodified lines
306 int ret = 0;287 int ret = 0;
307 288
308 /* read Offset */289 /* read Offset */
309 if (!(element = ff_imf_xml_get_child_element_by_name(marker_elem, "Offset"))) {290 if (!(element = ff_imf_xml_get_child_element_by_name(marker_elem, "Offset")))
310 av_log(NULL, AV_LOG_ERROR, "Offset element not found in a Marker\n");
311 return AVERROR_INVALIDDATA;291 return AVERROR_INVALIDDATA;
312 }292
313 if ((ret = ff_imf_xml_read_uint32(element, &marker->offset)))293 if ((ret = ff_imf_xml_read_uint32(element, &marker->offset)))
314 return ret;294 return ret;
315 295
316 /* read Label and Scope */296 /* read Label and Scope */
317 if (!(element = ff_imf_xml_get_child_element_by_name(marker_elem, "Label"))) {297 if (!(element = ff_imf_xml_get_child_element_by_name(marker_elem, "Label")))
318 av_log(NULL, AV_LOG_ERROR, "Label element not found in a Marker\n");
319 return AVERROR_INVALIDDATA;298 return AVERROR_INVALIDDATA;
320 }299
321 if (!(marker->label_utf8 = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1))) {300 if (!(marker->label_utf8 = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1)))
322 av_log(NULL, AV_LOG_ERROR, "Empty Label element found in a Marker\n");
323 return AVERROR_INVALIDDATA;301 return AVERROR_INVALIDDATA;
324 }302
325 if (!(marker->scope_utf8 = xmlGetNoNsProp(element, "scope"))) {303 if (!(marker->scope_utf8 = xmlGetNoNsProp(element, "scope"))) {
326 marker->scope_utf8304 marker->scope_utf8
327 = xmlCharStrdup("http://www.smpte-ra.org/schemas/2067-3/2013#standard-markers");305 = xmlCharStrdup("http://www.smpte-ra.org/schemas/2067-3/2013#standard-markers");
@@ -334,7 +312,8 @@ static int fill_marker(xmlNodePtr marker_elem, FFIMFMarker *marker) · 6 unmodified lines
334 return ret;312 return ret;
335}313}
336 314
337static int fill_base_resource(xmlNodePtr resource_elem, FFIMFBaseResource *resource, FFIMFCPL *cpl)315static int fill_base_resource(void *log_ctx, xmlNodePtr resource_elem,
316 FFIMFBaseResource *resource, FFIMFCPL *cpl)
338{317{
339 xmlNodePtr element = NULL;318 xmlNodePtr element = NULL;
340 int ret = 0;319 int ret = 0;
@@ -343,14 +322,14 @@ static int fill_base_resource(xmlNodePtr resource_elem, FFIMFBaseResource *resou · 2 unmodified lines
343 if (!(element = ff_imf_xml_get_child_element_by_name(resource_elem, "EditRate"))) {322 if (!(element = ff_imf_xml_get_child_element_by_name(resource_elem, "EditRate"))) {
344 resource->edit_rate = cpl->edit_rate;323 resource->edit_rate = cpl->edit_rate;
345 } else if ((ret = ff_imf_xml_read_rational(element, &resource->edit_rate))) {324 } else if ((ret = ff_imf_xml_read_rational(element, &resource->edit_rate))) {
346 av_log(NULL, AV_LOG_ERROR, "Invalid EditRate element found in a Resource\n");325 av_log(log_ctx, AV_LOG_ERROR, "Invalid EditRate element found in a Resource\n");
347 return ret;326 return ret;
348 }327 }
349 328
350 /* read EntryPoint */329 /* read EntryPoint */
351 if ((element = ff_imf_xml_get_child_element_by_name(resource_elem, "EntryPoint"))) {330 if ((element = ff_imf_xml_get_child_element_by_name(resource_elem, "EntryPoint"))) {
352 if ((ret = ff_imf_xml_read_uint32(element, &resource->entry_point))) {331 if ((ret = ff_imf_xml_read_uint32(element, &resource->entry_point))) {
353 av_log(NULL, AV_LOG_ERROR, "Invalid EntryPoint element found in a Resource\n");332 av_log(log_ctx, AV_LOG_ERROR, "Invalid EntryPoint element found in a Resource\n");
354 return ret;333 return ret;
355 }334 }
356 } else {335 } else {
@@ -359,11 +338,11 @@ static int fill_base_resource(xmlNodePtr resource_elem, FFIMFBaseResource *resou · 2 unmodified lines
359 338
360 /* read IntrinsicDuration */339 /* read IntrinsicDuration */
361 if (!(element = ff_imf_xml_get_child_element_by_name(resource_elem, "IntrinsicDuration"))) {340 if (!(element = ff_imf_xml_get_child_element_by_name(resource_elem, "IntrinsicDuration"))) {
362 av_log(NULL, AV_LOG_ERROR, "IntrinsicDuration element missing from Resource\n");341 av_log(log_ctx, AV_LOG_ERROR, "IntrinsicDuration element missing from Resource\n");
363 return AVERROR_INVALIDDATA;342 return AVERROR_INVALIDDATA;
364 }343 }
365 if ((ret = ff_imf_xml_read_uint32(element, &resource->duration))) {344 if ((ret = ff_imf_xml_read_uint32(element, &resource->duration))) {
366 av_log(NULL, AV_LOG_ERROR, "Invalid IntrinsicDuration element found in a Resource\n");345 av_log(log_ctx, AV_LOG_ERROR, "Invalid IntrinsicDuration element found in a Resource\n");
367 return ret;346 return ret;
368 }347 }
369 resource->duration -= resource->entry_point;348 resource->duration -= resource->entry_point;
@@ -371,7 +350,7 @@ static int fill_base_resource(xmlNodePtr resource_elem, FFIMFBaseResource *resou · 1 unmodified line
371 /* read SourceDuration */350 /* read SourceDuration */
372 if ((element = ff_imf_xml_get_child_element_by_name(resource_elem, "SourceDuration"))) {351 if ((element = ff_imf_xml_get_child_element_by_name(resource_elem, "SourceDuration"))) {
373 if ((ret = ff_imf_xml_read_uint32(element, &resource->duration))) {352 if ((ret = ff_imf_xml_read_uint32(element, &resource->duration))) {
374 av_log(NULL, AV_LOG_ERROR, "SourceDuration element missing from Resource\n");353 av_log(log_ctx, AV_LOG_ERROR, "SourceDuration element missing from Resource\n");
375 return ret;354 return ret;
376 }355 }
377 }356 }
@@ -383,38 +362,38 @@ static int fill_base_resource(xmlNodePtr resource_elem, FFIMFBaseResource *resou · 5 unmodified lines
383 return ret;362 return ret;
384}363}
385 364
386static int fill_trackfile_resource(xmlNodePtr tf_resource_elem,365static int fill_trackfile_resource(void *log_ctx, xmlNodePtr tf_resource_elem,
387 FFIMFTrackFileResource *tf_resource,366 FFIMFTrackFileResource *tf_resource,
388 FFIMFCPL *cpl)367 FFIMFCPL *cpl)
389{368{
390 xmlNodePtr element = NULL;369 xmlNodePtr element = NULL;
391 int ret = 0;370 int ret = 0;
392 371
393 if ((ret = fill_base_resource(tf_resource_elem, (FFIMFBaseResource *)tf_resource, cpl)))372 if ((ret = fill_base_resource(log_ctx, tf_resource_elem, (FFIMFBaseResource *)tf_resource, cpl)))
394 return ret;373 return ret;
395 374
396 /* read TrackFileId */375 /* read TrackFileId */
397 if ((element = ff_imf_xml_get_child_element_by_name(tf_resource_elem, "TrackFileId"))) {376 if ((element = ff_imf_xml_get_child_element_by_name(tf_resource_elem, "TrackFileId"))) {
398 if ((ret = ff_imf_xml_read_uuid(element, tf_resource->track_file_uuid))) {377 if ((ret = ff_imf_xml_read_uuid(element, tf_resource->track_file_uuid))) {
399 av_log(NULL, AV_LOG_ERROR, "Invalid TrackFileId element found in Resource\n");378 av_log(log_ctx, AV_LOG_ERROR, "Invalid TrackFileId element found in Resource\n");
400 return ret;379 return ret;
401 }380 }
402 } else {381 } else {
403 av_log(NULL, AV_LOG_ERROR, "TrackFileId element missing from Resource\n");382 av_log(log_ctx, AV_LOG_ERROR, "TrackFileId element missing from Resource\n");
404 return AVERROR_INVALIDDATA;383 return AVERROR_INVALIDDATA;
405 }384 }
406 385
407 return ret;386 return ret;
408}387}
409 388
410static int fill_marker_resource(xmlNodePtr marker_resource_elem,389static int fill_marker_resource(void *log_ctx, xmlNodePtr marker_resource_elem,
411 FFIMFMarkerResource *marker_resource,390 FFIMFMarkerResource *marker_resource,
412 FFIMFCPL *cpl)391 FFIMFCPL *cpl)
413{392{
414 xmlNodePtr element = NULL;393 xmlNodePtr element = NULL;
415 int ret = 0;394 int ret = 0;
416 395
417 if ((ret = fill_base_resource(marker_resource_elem, (FFIMFBaseResource *)marker_resource, cpl)))396 if ((ret = fill_base_resource(log_ctx, marker_resource_elem, (FFIMFBaseResource *)marker_resource, cpl)))
418 return ret;397 return ret;
419 398
420 /* read markers */399 /* read markers */
@@ -436,8 +415,10 @@ static int fill_marker_resource(xmlNodePtr marker_resource_elem, · 15 unmodified lines
436 ret = fill_marker(element,415 ret = fill_marker(element,
437 &marker_resource->markers[marker_resource->marker_count]);416 &marker_resource->markers[marker_resource->marker_count]);
438 marker_resource->marker_count++;417 marker_resource->marker_count++;
439 if (ret)418 if (ret) {
419 av_log(log_ctx, AV_LOG_ERROR, "Invalid Marker element\n");
440 return ret;420 return ret;
421 }
441 }422 }
442 423
443 element = xmlNextElementSibling(element);424 element = xmlNextElementSibling(element);
@@ -446,7 +427,7 @@ static int fill_marker_resource(xmlNodePtr marker_resource_elem, · 2 unmodified lines
446 return ret;427 return ret;
447}428}
448 429
449static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl)430static int push_marker_sequence(void *log_ctx, xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl)
450{431{
451 int ret = 0;432 int ret = 0;
452 AVUUID uuid;433 AVUUID uuid;
@@ -458,14 +439,14 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl) · 5 unmodified lines
458 439
459 /* read TrackID element */440 /* read TrackID element */
460 if (!(track_id_elem = ff_imf_xml_get_child_element_by_name(marker_sequence_elem, "TrackId"))) {441 if (!(track_id_elem = ff_imf_xml_get_child_element_by_name(marker_sequence_elem, "TrackId"))) {
461 av_log(NULL, AV_LOG_ERROR, "TrackId element missing from Sequence\n");442 av_log(log_ctx, AV_LOG_ERROR, "TrackId element missing from Sequence\n");
462 return AVERROR_INVALIDDATA;443 return AVERROR_INVALIDDATA;
463 }444 }
464 if (ff_imf_xml_read_uuid(track_id_elem, uuid)) {445 if (ff_imf_xml_read_uuid(track_id_elem, uuid)) {
465 av_log(NULL, AV_LOG_ERROR, "Invalid TrackId element found in Sequence\n");446 av_log(log_ctx, AV_LOG_ERROR, "Invalid TrackId element found in Sequence\n");
466 return AVERROR_INVALIDDATA;447 return AVERROR_INVALIDDATA;
467 }448 }
468 av_log(NULL,449 av_log(log_ctx,
469 AV_LOG_DEBUG,450 AV_LOG_DEBUG,
470 "Processing IMF CPL Marker Sequence for Virtual Track " AV_PRI_UUID "\n",451 "Processing IMF CPL Marker Sequence for Virtual Track " AV_PRI_UUID "\n",
471 AV_UUID_ARG(uuid));452 AV_UUID_ARG(uuid));
@@ -479,7 +460,7 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl) · 7 unmodified lines
479 av_uuid_copy(cpl->main_markers_track->base.id_uuid, uuid);460 av_uuid_copy(cpl->main_markers_track->base.id_uuid, uuid);
480 461
481 } else if (!av_uuid_equal(cpl->main_markers_track->base.id_uuid, uuid)) {462 } else if (!av_uuid_equal(cpl->main_markers_track->base.id_uuid, uuid)) {
482 av_log(NULL, AV_LOG_ERROR, "Multiple marker virtual tracks were found\n");463 av_log(log_ctx, AV_LOG_ERROR, "Multiple marker virtual tracks were found\n");
483 return AVERROR_INVALIDDATA;464 return AVERROR_INVALIDDATA;
484 }465 }
485 466
@@ -496,7 +477,7 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl) · 10 unmodified lines
496 cpl->main_markers_track->resource_count + resource_elem_count,477 cpl->main_markers_track->resource_count + resource_elem_count,
497 sizeof(FFIMFMarkerResource));478 sizeof(FFIMFMarkerResource));
498 if (!tmp) {479 if (!tmp) {
499 av_log(NULL, AV_LOG_ERROR, "Cannot allocate Marker Resources\n");480 av_log(log_ctx, AV_LOG_ERROR, "Cannot allocate Marker Resources\n");
500 return AVERROR(ENOMEM);481 return AVERROR(ENOMEM);
501 }482 }
502 cpl->main_markers_track->resources = tmp;483 cpl->main_markers_track->resources = tmp;
@@ -504,7 +485,7 @@ static int push_marker_sequence(xmlNodePtr marker_sequence_elem, FFIMFCPL *cpl) · 1 unmodified line
504 resource_elem = xmlFirstElementChild(resource_list_elem);485 resource_elem = xmlFirstElementChild(resource_list_elem);
505 while (resource_elem) {486 while (resource_elem) {
506 imf_marker_resource_init(&cpl->main_markers_track->resources[cpl->main_markers_track->resource_count]);487 imf_marker_resource_init(&cpl->main_markers_track->resources[cpl->main_markers_track->resource_count]);
507 ret = fill_marker_resource(resource_elem,488 ret = fill_marker_resource(log_ctx, resource_elem,
508 &cpl->main_markers_track->resources[cpl->main_markers_track->resource_count],489 &cpl->main_markers_track->resources[cpl->main_markers_track->resource_count],
509 cpl);490 cpl);
510 cpl->main_markers_track->resource_count++;491 cpl->main_markers_track->resource_count++;
@@ -533,7 +514,7 @@ static int has_stereo_resources(xmlNodePtr element) · 22 unmodified lines
533 return 0;514 return 0;
534}515}
535 516
536static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cpl)517static int push_main_audio_sequence(void *log_ctx, xmlNodePtr audio_sequence_elem, FFIMFCPL *cpl)
537{518{
538 int ret = 0;519 int ret = 0;
539 AVUUID uuid;520 AVUUID uuid;
@@ -546,14 +527,14 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp · 6 unmodified lines
546 527
547 /* read TrackID element */528 /* read TrackID element */
548 if (!(track_id_elem = ff_imf_xml_get_child_element_by_name(audio_sequence_elem, "TrackId"))) {529 if (!(track_id_elem = ff_imf_xml_get_child_element_by_name(audio_sequence_elem, "TrackId"))) {
549 av_log(NULL, AV_LOG_ERROR, "TrackId element missing from audio sequence\n");530 av_log(log_ctx, AV_LOG_ERROR, "TrackId element missing from audio sequence\n");
550 return AVERROR_INVALIDDATA;531 return AVERROR_INVALIDDATA;
551 }532 }
552 if ((ret = ff_imf_xml_read_uuid(track_id_elem, uuid))) {533 if ((ret = ff_imf_xml_read_uuid(track_id_elem, uuid))) {
553 av_log(NULL, AV_LOG_ERROR, "Invalid TrackId element found in audio sequence\n");534 av_log(log_ctx, AV_LOG_ERROR, "Invalid TrackId element found in audio sequence\n");
554 return ret;535 return ret;
555 }536 }
556 av_log(NULL,537 av_log(log_ctx,
557 AV_LOG_DEBUG,538 AV_LOG_DEBUG,
558 "Processing IMF CPL Audio Sequence for Virtual Track " AV_PRI_UUID "\n",539 "Processing IMF CPL Audio Sequence for Virtual Track " AV_PRI_UUID "\n",
559 AV_UUID_ARG(uuid));540 AV_UUID_ARG(uuid));
@@ -597,7 +578,7 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp · 37 unmodified lines
597 (vt->resource_count + resource_elem_count)578 (vt->resource_count + resource_elem_count)
598 * sizeof(FFIMFTrackFileResource));579 * sizeof(FFIMFTrackFileResource));
599 if (!tmp) {580 if (!tmp) {
600 av_log(NULL, AV_LOG_ERROR, "Cannot allocate Main Audio Resources\n");581 av_log(log_ctx, AV_LOG_ERROR, "Cannot allocate Main Audio Resources\n");
601 return AVERROR(ENOMEM);582 return AVERROR(ENOMEM);
602 }583 }
603 vt->resources = tmp;584 vt->resources = tmp;
@@ -605,11 +586,11 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp · 1 unmodified line
605 resource_elem = xmlFirstElementChild(resource_list_elem);586 resource_elem = xmlFirstElementChild(resource_list_elem);
606 while (resource_elem) {587 while (resource_elem) {
607 imf_trackfile_resource_init(&vt->resources[vt->resource_count]);588 imf_trackfile_resource_init(&vt->resources[vt->resource_count]);
608 ret = fill_trackfile_resource(resource_elem,589 ret = fill_trackfile_resource(log_ctx, resource_elem,
609 &vt->resources[vt->resource_count],590 &vt->resources[vt->resource_count],
610 cpl);591 cpl);
611 if (ret)592 if (ret)
612 av_log(NULL, AV_LOG_ERROR, "Invalid Resource\n");593 av_log(log_ctx, AV_LOG_ERROR, "Invalid Resource\n");
613 else594 else
614 vt->resource_count++;595 vt->resource_count++;
615 596
@@ -619,7 +600,7 @@ static int push_main_audio_sequence(xmlNodePtr audio_sequence_elem, FFIMFCPL *cp · 3 unmodified lines
619 return ret;600 return ret;
620}601}
621 602
622static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL *cpl)603static int push_main_image_2d_sequence(void *log_ctx, xmlNodePtr image_sequence_elem, FFIMFCPL *cpl)
623{604{
624 int ret = 0;605 int ret = 0;
625 AVUUID uuid;606 AVUUID uuid;
@@ -631,17 +612,17 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL · 5 unmodified lines
631 612
632 /* skip stereoscopic resources */613 /* skip stereoscopic resources */
633 if (has_stereo_resources(image_sequence_elem)) {614 if (has_stereo_resources(image_sequence_elem)) {
634 av_log(NULL, AV_LOG_ERROR, "Stereoscopic 3D image virtual tracks not supported\n");615 av_log(log_ctx, AV_LOG_ERROR, "Stereoscopic 3D image virtual tracks not supported\n");
635 return AVERROR_PATCHWELCOME;616 return AVERROR_PATCHWELCOME;
636 }617 }
637 618
638 /* read TrackId element*/619 /* read TrackId element*/
639 if (!(track_id_elem = ff_imf_xml_get_child_element_by_name(image_sequence_elem, "TrackId"))) {620 if (!(track_id_elem = ff_imf_xml_get_child_element_by_name(image_sequence_elem, "TrackId"))) {
640 av_log(NULL, AV_LOG_ERROR, "TrackId element missing from audio sequence\n");621 av_log(log_ctx, AV_LOG_ERROR, "TrackId element missing from audio sequence\n");
641 return AVERROR_INVALIDDATA;622 return AVERROR_INVALIDDATA;
642 }623 }
643 if ((ret = ff_imf_xml_read_uuid(track_id_elem, uuid))) {624 if ((ret = ff_imf_xml_read_uuid(track_id_elem, uuid))) {
644 av_log(NULL, AV_LOG_ERROR, "Invalid TrackId element found in audio sequence\n");625 av_log(log_ctx, AV_LOG_ERROR, "Invalid TrackId element found in audio sequence\n");
645 return ret;626 return ret;
646 }627 }
647 628
@@ -654,10 +635,10 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL · 6 unmodified lines
654 av_uuid_copy(cpl->main_image_2d_track->base.id_uuid, uuid);635 av_uuid_copy(cpl->main_image_2d_track->base.id_uuid, uuid);
655 636
656 } else if (!av_uuid_equal(cpl->main_image_2d_track->base.id_uuid, uuid)) {637 } else if (!av_uuid_equal(cpl->main_image_2d_track->base.id_uuid, uuid)) {
657 av_log(NULL, AV_LOG_ERROR, "Multiple MainImage virtual tracks found\n");638 av_log(log_ctx, AV_LOG_ERROR, "Multiple MainImage virtual tracks found\n");
658 return AVERROR_INVALIDDATA;639 return AVERROR_INVALIDDATA;
659 }640 }
660 av_log(NULL,641 av_log(log_ctx,
661 AV_LOG_DEBUG,642 AV_LOG_DEBUG,
662 "Processing IMF CPL Main Image Sequence for Virtual Track " AV_PRI_UUID "\n",643 "Processing IMF CPL Main Image Sequence for Virtual Track " AV_PRI_UUID "\n",
663 AV_UUID_ARG(uuid));644 AV_UUID_ARG(uuid));
@@ -678,7 +659,7 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL · 14 unmodified lines
678 (cpl->main_image_2d_track->resource_count + resource_elem_count)659 (cpl->main_image_2d_track->resource_count + resource_elem_count)
679 * sizeof(FFIMFTrackFileResource));660 * sizeof(FFIMFTrackFileResource));
680 if (!tmp) {661 if (!tmp) {
681 av_log(NULL, AV_LOG_ERROR, "Cannot allocate Main Image Resources\n");662 av_log(log_ctx, AV_LOG_ERROR, "Cannot allocate Main Image Resources\n");
682 return AVERROR(ENOMEM);663 return AVERROR(ENOMEM);
683 }664 }
684 cpl->main_image_2d_track->resources = tmp;665 cpl->main_image_2d_track->resources = tmp;
@@ -687,11 +668,11 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL · 2 unmodified lines
687 while (resource_elem) {668 while (resource_elem) {
688 imf_trackfile_resource_init(669 imf_trackfile_resource_init(
689 &cpl->main_image_2d_track->resources[cpl->main_image_2d_track->resource_count]);670 &cpl->main_image_2d_track->resources[cpl->main_image_2d_track->resource_count]);
690 ret = fill_trackfile_resource(resource_elem,671 ret = fill_trackfile_resource(log_ctx, resource_elem,
691 &cpl->main_image_2d_track->resources[cpl->main_image_2d_track->resource_count],672 &cpl->main_image_2d_track->resources[cpl->main_image_2d_track->resource_count],
692 cpl);673 cpl);
693 if (ret)674 if (ret)
694 av_log(NULL, AV_LOG_ERROR, "Invalid Resource\n");675 av_log(log_ctx, AV_LOG_ERROR, "Invalid Resource\n");
695 else676 else
696 cpl->main_image_2d_track->resource_count++;677 cpl->main_image_2d_track->resource_count++;
697 678
@@ -701,7 +682,7 @@ static int push_main_image_2d_sequence(xmlNodePtr image_sequence_elem, FFIMFCPL · 3 unmodified lines
701 return 0;682 return 0;
702}683}
703 684
704static int fill_virtual_tracks(xmlNodePtr cpl_element, FFIMFCPL *cpl)685static int fill_virtual_tracks(void *log_ctx, xmlNodePtr cpl_element, FFIMFCPL *cpl)
705{686{
706 int ret = 0;687 int ret = 0;
707 xmlNodePtr segment_list_elem = NULL;688 xmlNodePtr segment_list_elem = NULL;
@@ -710,14 +691,14 @@ static int fill_virtual_tracks(xmlNodePtr cpl_element, FFIMFCPL *cpl) · 2 unmodified lines
710 xmlNodePtr sequence_elem = NULL;691 xmlNodePtr sequence_elem = NULL;
711 692
712 if (!(segment_list_elem = ff_imf_xml_get_child_element_by_name(cpl_element, "SegmentList"))) {693 if (!(segment_list_elem = ff_imf_xml_get_child_element_by_name(cpl_element, "SegmentList"))) {
713 av_log(NULL, AV_LOG_ERROR, "SegmentList element missing\n");694 av_log(log_ctx, AV_LOG_ERROR, "SegmentList element missing\n");
714 return AVERROR_INVALIDDATA;695 return AVERROR_INVALIDDATA;
715 }696 }
716 697
717 /* process sequences */698 /* process sequences */
718 segment_elem = xmlFirstElementChild(segment_list_elem);699 segment_elem = xmlFirstElementChild(segment_list_elem);
719 while (segment_elem) {700 while (segment_elem) {
720 av_log(NULL, AV_LOG_DEBUG, "Processing IMF CPL Segment\n");701 av_log(log_ctx, AV_LOG_DEBUG, "Processing IMF CPL Segment\n");
721 702
722 sequence_list_elem = ff_imf_xml_get_child_element_by_name(segment_elem, "SequenceList");703 sequence_list_elem = ff_imf_xml_get_child_element_by_name(segment_elem, "SequenceList");
723 if (!sequence_list_elem)704 if (!sequence_list_elem)
@@ -726,16 +707,16 @@ static int fill_virtual_tracks(xmlNodePtr cpl_element, FFIMFCPL *cpl) · 2 unmodified lines
726 sequence_elem = xmlFirstElementChild(sequence_list_elem);707 sequence_elem = xmlFirstElementChild(sequence_list_elem);
727 while (sequence_elem) {708 while (sequence_elem) {
728 if (xmlStrcmp(sequence_elem->name, "MarkerSequence") == 0)709 if (xmlStrcmp(sequence_elem->name, "MarkerSequence") == 0)
729 ret = push_marker_sequence(sequence_elem, cpl);710 ret = push_marker_sequence(log_ctx, sequence_elem, cpl);
730 711
731 else if (xmlStrcmp(sequence_elem->name, "MainImageSequence") == 0)712 else if (xmlStrcmp(sequence_elem->name, "MainImageSequence") == 0)
732 ret = push_main_image_2d_sequence(sequence_elem, cpl);713 ret = push_main_image_2d_sequence(log_ctx, sequence_elem, cpl);
733 714
734 else if (xmlStrcmp(sequence_elem->name, "MainAudioSequence") == 0)715 else if (xmlStrcmp(sequence_elem->name, "MainAudioSequence") == 0)
735 ret = push_main_audio_sequence(sequence_elem, cpl);716 ret = push_main_audio_sequence(log_ctx, sequence_elem, cpl);
736 717
737 else718 else
738 av_log(NULL,719 av_log(log_ctx,
739 AV_LOG_INFO,720 AV_LOG_INFO,
740 "The following Sequence is not supported and is ignored: %s\n",721 "The following Sequence is not supported and is ignored: %s\n",
741 sequence_elem->name);722 sequence_elem->name);
@@ -753,7 +734,7 @@ static int fill_virtual_tracks(xmlNodePtr cpl_element, FFIMFCPL *cpl) · 11 unmodified lines
753 return ret;734 return ret;
754}735}
755 736
756int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl)737int ff_imf_parse_cpl_from_xml_dom(void *log_ctx, xmlDocPtr doc, FFIMFCPL **cpl)
757{738{
758 int ret = 0;739 int ret = 0;
759 xmlNodePtr cpl_element = NULL;740 xmlNodePtr cpl_element = NULL;
@@ -766,20 +747,28 @@ int ff_imf_parse_cpl_from_xml_dom(xmlDocPtr doc, FFIMFCPL **cpl) · 6 unmodified lines
766 747
767 cpl_element = xmlDocGetRootElement(doc);748 cpl_element = xmlDocGetRootElement(doc);
768 if (!cpl_element || xmlStrcmp(cpl_element->name, "CompositionPlaylist")) {749 if (!cpl_element || xmlStrcmp(cpl_element->name, "CompositionPlaylist")) {
769 av_log(NULL, AV_LOG_ERROR, "The root element of the CPL is not CompositionPlaylist\n");750 av_log(log_ctx, AV_LOG_ERROR, "The root element of the CPL is not CompositionPlaylist\n");
770 ret = AVERROR_INVALIDDATA;751 ret = AVERROR_INVALIDDATA;
771 goto cleanup;752 goto cleanup;
772 }753 }
773 754
774 if ((ret = fill_content_title(cpl_element, *cpl)))755 if ((ret = fill_content_title(cpl_element, *cpl))) {
756 av_log(log_ctx, AV_LOG_ERROR, "Cannot read the ContentTitle element from the IMF CPL\n");
775 goto cleanup;757 goto cleanup;
776 if ((ret = fill_id(cpl_element, *cpl)))758 }
759 if ((ret = fill_id(cpl_element, *cpl))) {
760 av_log(log_ctx, AV_LOG_ERROR, "Id element not found in the IMF CPL\n");
777 goto cleanup;761 goto cleanup;
778 if ((ret = fill_edit_rate(cpl_element, *cpl)))762 }
763 if ((ret = fill_edit_rate(cpl_element, *cpl))) {
764 av_log(log_ctx, AV_LOG_ERROR, "EditRate element not found in the IMF CPL\n");
779 goto cleanup;765 goto cleanup;
780 if ((ret = fill_timecode(cpl_element, *cpl)))766 }
767 if ((ret = fill_timecode(cpl_element, *cpl))) {
768 av_log(log_ctx, AV_LOG_ERROR, "Invalid CompositionTimecode element found in the IMF CPL\n");
781 goto cleanup;769 goto cleanup;
782 if ((ret = fill_virtual_tracks(cpl_element, *cpl)))770 }
771 if ((ret = fill_virtual_tracks(log_ctx, cpl_element, *cpl)))
783 goto cleanup;772 goto cleanup;
784 773
785cleanup:774cleanup:
@@ -875,7 +864,7 @@ void ff_imf_cpl_free(FFIMFCPL *cpl) · 89 unmodified lines
875 av_freep(&cpl);864 av_freep(&cpl);
876}865}
877 866
878int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl)867int ff_imf_parse_cpl(void *log_ctx, AVIOContext *in, FFIMFCPL **cpl)
879{868{
880 AVBPrint buf;869 AVBPrint buf;
881 xmlDoc *doc = NULL;870 xmlDoc *doc = NULL;
@@ -885,7 +874,7 @@ int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl) · 3 unmodified lines
885 874
886 ret = avio_read_to_bprint(in, &buf, SIZE_MAX);875 ret = avio_read_to_bprint(in, &buf, SIZE_MAX);
887 if (ret < 0 || !avio_feof(in)) {876 if (ret < 0 || !avio_feof(in)) {
888 av_log(NULL, AV_LOG_ERROR, "Cannot read IMF CPL\n");877 av_log(log_ctx, AV_LOG_ERROR, "Cannot read IMF CPL\n");
889 if (ret == 0)878 if (ret == 0)
890 ret = AVERROR_INVALIDDATA;879 ret = AVERROR_INVALIDDATA;
891 goto clean_up;880 goto clean_up;
@@ -895,21 +884,21 @@ int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl) · 3 unmodified lines
895 884
896 doc = xmlReadMemory(buf.str, buf.len, NULL, NULL, 0);885 doc = xmlReadMemory(buf.str, buf.len, NULL, NULL, 0);
897 if (!doc) {886 if (!doc) {
898 av_log(NULL,887 av_log(log_ctx,
899 AV_LOG_ERROR,888 AV_LOG_ERROR,
900 "XML parsing failed when reading the IMF CPL\n");889 "XML parsing failed when reading the IMF CPL\n");
901 ret = AVERROR_INVALIDDATA;890 ret = AVERROR_INVALIDDATA;
902 goto clean_up;891 goto clean_up;
903 }892 }
904 893
905 if ((ret = ff_imf_parse_cpl_from_xml_dom(doc, cpl))) {894 if ((ret = ff_imf_parse_cpl_from_xml_dom(log_ctx, doc, cpl))) {
906 av_log(NULL, AV_LOG_ERROR, "Cannot parse IMF CPL\n");895 av_log(log_ctx, AV_LOG_ERROR, "Cannot parse IMF CPL\n");
907 } else {896 } else {
908 av_log(NULL,897 av_log(log_ctx,
909 AV_LOG_INFO,898 AV_LOG_INFO,
910 "IMF CPL ContentTitle: %s\n",899 "IMF CPL ContentTitle: %s\n",
911 (*cpl)->content_title_utf8);900 (*cpl)->content_title_utf8);
912 av_log(NULL,901 av_log(log_ctx,
913 AV_LOG_INFO,902 AV_LOG_INFO,
914 "IMF CPL Id: " AV_PRI_UUID "\n",903 "IMF CPL Id: " AV_PRI_UUID "\n",
915 AV_UUID_ARG((*cpl)->id_uuid));904 AV_UUID_ARG((*cpl)->id_uuid));
libavformat/imfdec.c+1−1
@@ -649,7 +649,7 @@ static int imf_read_header(AVFormatContext *s) · 648 unmodified lines
649 649
650 av_log(s, AV_LOG_DEBUG, "start parsing IMF CPL: %s\n", s->url);650 av_log(s, AV_LOG_DEBUG, "start parsing IMF CPL: %s\n", s->url);
651 651
652 if ((ret = ff_imf_parse_cpl(s->pb, &c->cpl)) < 0)652 if ((ret = ff_imf_parse_cpl(s, s->pb, &c->cpl)) < 0)
653 return ret;653 return ret;
654 654
655 tcr = av_dict_get(s->metadata, "timecode", NULL, 0);655 tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
libavformat/tests/imf.c+2−2
@@ -341,7 +341,7 @@ static int test_cpl_parsing(void) · 340 unmodified lines
341 return 1;341 return 1;
342 }342 }
343 343
344 ret = ff_imf_parse_cpl_from_xml_dom(doc, &cpl);344 ret = ff_imf_parse_cpl_from_xml_dom(NULL, doc, &cpl);
345 xmlFreeDoc(doc);345 xmlFreeDoc(doc);
346 if (ret) {346 if (ret) {
347 printf("CPL parsing failed.\n");347 printf("CPL parsing failed.\n");
@@ -394,7 +394,7 @@ static int test_cpl_from_doc(FFIMFCPL **cpl, const char* cpl_doc, int should_pas · 46 unmodified lines
394 return should_pass;394 return should_pass;
395 }395 }
396 396
397 ret = ff_imf_parse_cpl_from_xml_dom(doc, cpl);397 ret = ff_imf_parse_cpl_from_xml_dom(NULL, doc, cpl);
398 xmlFreeDoc(doc);398 xmlFreeDoc(doc);
399 if (ret) {399 if (ret) {
400 printf("CPL parsing failed.\n");400 printf("CPL parsing failed.\n");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t