FFmpeg
Loading...
Searching...
No Matches
imfdec.c
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 * Demuxes an IMF Composition
47 *
48 * References
49 * OV 2067-0:2018 - SMPTE Overview Document - Interoperable Master Format
50 * ST 2067-2:2020 - SMPTE Standard - Interoperable Master Format — Core Constraints
51 * ST 2067-3:2020 - SMPTE Standard - Interoperable Master Format — Composition Playlist
52 * ST 2067-5:2020 - SMPTE Standard - Interoperable Master Format — Essence Component
53 * ST 2067-20:2016 - SMPTE Standard - Interoperable Master Format — Application #2
54 * ST 2067-21:2020 - SMPTE Standard - Interoperable Master Format — Application #2 Extended
55 * ST 2067-102:2017 - SMPTE Standard - Interoperable Master Format — Common Image Pixel Color Schemes
56 * ST 429-9:2007 - SMPTE Standard - D-Cinema Packaging — Asset Mapping and File Segmentation
57 *
58 * @author Marc-Antoine Arnaud
59 * @author Valentin Noel
60 * @author Nicholas Vanderzwet
61 * @file
62 * @ingroup lavu_imf
63 */
64
65#include "avio_internal.h"
66#include "demux.h"
67#include "imf.h"
68#include "internal.h"
69#include "libavcodec/packet.h"
70#include "libavutil/avstring.h"
71#include "libavutil/bprint.h"
73#include "libavutil/mem.h"
74#include "libavutil/opt.h"
75#include <inttypes.h>
76#include <libxml/parser.h>
77
78#define AVRATIONAL_FORMAT "%d/%d"
79#define AVRATIONAL_ARG(rational) rational.num, rational.den
80#define MAX_RESOURCES FFMIN(1 << 20, INT_MAX / (int)sizeof(IMFVirtualTrackResourcePlaybackCtx))
81
82/**
83 * IMF Asset locator
84 */
89
90/**
91 * IMF Asset locator map
92 * Results from the parsing of one or more ASSETMAP XML files
93 */
98
100 IMFAssetLocator *locator; /**< Location of the resource */
101 FFIMFTrackFileResource *resource; /**< Underlying IMF CPL resource */
102 AVFormatContext *ctx; /**< Context associated with the resource */
103 AVRational start_time; /**< inclusive start time of the resource on the CPL timeline (s) */
104 AVRational end_time; /**< exclusive end time of the resource on the CPL timeline (s) */
105 AVRational ts_offset; /**< start_time minus the entry point into the resource (s) */
107
109 int32_t index; /**< Track index in playlist */
110 AVRational current_timestamp; /**< Current temporal position */
111 AVRational duration; /**< Overall duration */
112 uint32_t resource_count; /**< Number of resources (<= INT32_MAX) */
113 unsigned int resources_alloc_sz; /**< Size of the buffer holding the resource */
114 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the resources */
115 int32_t current_resource_index; /**< Index of the current resource in resources,
116 or < 0 if a current resource has yet to be selected */
118
131
132static int imf_uri_is_url(const char *string)
133{
134 return strstr(string, "://") != NULL;
135}
136
137static int imf_uri_is_unix_abs_path(const char *string)
138{
139 return string[0] == '/';
140}
141
142static int imf_uri_is_dos_abs_path(const char *string)
143{
144 /* Absolute path case: `C:\path\to\somewhere` */
145 if (string[1] == ':' && string[2] == '\\')
146 return 1;
147
148 /* Absolute path case: `C:/path/to/somewhere` */
149 if (string[1] == ':' && string[2] == '/')
150 return 1;
151
152 /* Network path case: `\\path\to\somewhere` */
153 if (string[0] == '\\' && string[1] == '\\')
154 return 1;
155
156 return 0;
157}
158
159static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
160{
161 int dst_num;
162 int dst_den;
164
165 r = av_div_q(t, time_base);
166
167 if ((av_reduce(&dst_num, &dst_den, r.num, r.den, INT64_MAX) != 1))
168 return 1;
169
170 if (dst_den != 1)
171 return 1;
172
173 *ts = dst_num;
174
175 return 0;
176}
177
178/**
179 * Parse a ASSETMAP XML file to extract the UUID-URI mapping of assets.
180 * @param s the current format context, if any (can be NULL).
181 * @param doc the XML document to be parsed.
182 * @param asset_map pointer on the IMFAssetLocatorMap to fill.
183 * @param base_url the url of the asset map XML file, if any (can be NULL).
184 * @return a negative value in case of error, 0 otherwise.
185 */
187 xmlDocPtr doc,
188 IMFAssetLocatorMap *asset_map,
189 const char *base_url)
190{
191 xmlNodePtr asset_map_element = NULL;
192 xmlNodePtr node = NULL;
193 xmlNodePtr asset_element = NULL;
194 unsigned long elem_count;
195 char *uri;
196 int ret = 0;
197 IMFAssetLocator *asset = NULL;
198 void *tmp;
199
200 asset_map_element = xmlDocGetRootElement(doc);
201
202 if (!asset_map_element) {
203 av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing root node\n");
204 return AVERROR_INVALIDDATA;
205 }
206
207 if (asset_map_element->type != XML_ELEMENT_NODE || av_strcasecmp(asset_map_element->name, "AssetMap")) {
208 av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - wrong root node name[%s] type[%d]\n",
209 asset_map_element->name, (int)asset_map_element->type);
210 return AVERROR_INVALIDDATA;
211 }
212
213 /* parse asset locators */
214 if (!(node = ff_imf_xml_get_child_element_by_name(asset_map_element, "AssetList"))) {
215 av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing AssetList node\n");
216 return AVERROR_INVALIDDATA;
217 }
218 elem_count = xmlChildElementCount(node);
219 if (elem_count > UINT32_MAX
220 || asset_map->asset_count > UINT32_MAX - elem_count)
221 return AVERROR(ENOMEM);
222 tmp = av_realloc_array(asset_map->assets,
223 elem_count + asset_map->asset_count,
224 sizeof(IMFAssetLocator));
225 if (!tmp) {
226 av_log(s, AV_LOG_ERROR, "Cannot allocate IMF asset locators\n");
227 return AVERROR(ENOMEM);
228 }
229 asset_map->assets = tmp;
230
231 asset_element = xmlFirstElementChild(node);
232 for (; asset_element; asset_element = xmlNextElementSibling(asset_element)) {
233 if (av_strcasecmp(asset_element->name, "Asset") != 0)
234 continue;
235
236 asset = &(asset_map->assets[asset_map->asset_count]);
237
238 if (!(node = ff_imf_xml_get_child_element_by_name(asset_element, "Id"))) {
239 av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing Id node\n");
240 return AVERROR_INVALIDDATA;
241 }
242
243 if (ff_imf_xml_read_uuid(node, asset->uuid)) {
244 av_log(s, AV_LOG_ERROR, "Could not parse UUID from asset in asset map.\n");
245 return AVERROR_INVALIDDATA;
246 }
247
248 av_log(s, AV_LOG_DEBUG, "Found asset id: " AV_PRI_URN_UUID "\n", AV_UUID_ARG(asset->uuid));
249
250 if (!(node = ff_imf_xml_get_child_element_by_name(asset_element, "ChunkList"))) {
251 av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing ChunkList node\n");
252 return AVERROR_INVALIDDATA;
253 }
254
255 if (!(node = ff_imf_xml_get_child_element_by_name(node, "Chunk"))) {
256 av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing Chunk node\n");
257 return AVERROR_INVALIDDATA;
258 }
259
260 xmlNodePtr path_node = ff_imf_xml_get_child_element_by_name(node, "Path");
261 if (!path_node) {
262 av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - missing Path element in Chunk\n");
264 break;
265 }
266 uri = xmlNodeGetContent(path_node);
267 if (!uri || !uri[0]) {
268 av_log(s, AV_LOG_ERROR, "Unable to parse asset map XML - empty Path element in Chunk\n");
269 xmlFree(uri);
271 break;
272 }
273
275 asset->absolute_uri = av_append_path_component(base_url, uri);
276 else
277 asset->absolute_uri = av_strdup(uri);
278 xmlFree(uri);
279 if (!asset->absolute_uri)
280 return AVERROR(ENOMEM);
281
282 av_log(s, AV_LOG_DEBUG, "Found asset absolute URI: %s\n", asset->absolute_uri);
283
284 asset_map->asset_count++;
285 }
286
287 return ret;
288}
289
290/**
291 * Initializes an IMFAssetLocatorMap structure.
292 */
294{
295 asset_map->assets = NULL;
296 asset_map->asset_count = 0;
297}
298
299/**
300 * Free a IMFAssetLocatorMap pointer.
301 */
303{
304 for (uint32_t i = 0; i < asset_map->asset_count; i++)
305 av_freep(&asset_map->assets[i].absolute_uri);
306
307 av_freep(&asset_map->assets);
308}
309
310static int parse_assetmap(AVFormatContext *s, const char *url)
311{
312 IMFContext *c = s->priv_data;
313 AVIOContext *in = NULL;
314 struct AVBPrint buf;
316 xmlDoc *doc = NULL;
317 const char *base_url;
318 char *tmp_str = NULL;
319 int ret;
320
321 av_log(s, AV_LOG_DEBUG, "Asset Map URL: %s\n", url);
322
323 av_dict_copy(&opts, c->avio_opts, 0);
324 ret = s->io_open(s, &in, url, AVIO_FLAG_READ, &opts);
326 if (ret < 0)
327 return ret;
328
329 av_bprint_init(&buf, 0, INT_MAX); // xmlReadMemory uses integer length
330
331 ret = avio_read_to_bprint(in, &buf, SIZE_MAX);
332 if (ret < 0 || !avio_feof(in)) {
333 av_log(s, AV_LOG_ERROR, "Unable to read to asset map '%s'\n", url);
334 if (ret == 0)
336 goto clean_up;
337 }
338
339 LIBXML_TEST_VERSION
340
341 tmp_str = av_strdup(url);
342 if (!tmp_str) {
343 ret = AVERROR(ENOMEM);
344 goto clean_up;
345 }
346 base_url = av_dirname(tmp_str);
347
348 doc = xmlReadMemory(buf.str, buf.len, url, NULL, 0);
349
350 ret = parse_imf_asset_map_from_xml_dom(s, doc, &c->asset_locator_map, base_url);
351 if (!ret)
352 av_log(s, AV_LOG_DEBUG, "Found %d assets from %s\n",
353 c->asset_locator_map.asset_count, url);
354
355 xmlFreeDoc(doc);
356
357clean_up:
358 if (tmp_str)
359 av_freep(&tmp_str);
360 ff_format_io_close(s, &in);
362 return ret;
363}
364
366{
367 for (uint32_t i = 0; i < asset_map->asset_count; i++) {
368 if (memcmp(asset_map->assets[i].uuid, uuid, 16) == 0)
369 return &(asset_map->assets[i]);
370 }
371 return NULL;
372}
373
376 int32_t resource_index)
377{
378 IMFContext *c = s->priv_data;
379 int ret = 0;
380 int64_t seek_offset = 0;
382 AVStream *st;
383 IMFVirtualTrackResourcePlaybackCtx *track_resource = track->resources + resource_index;
384
385 if (track_resource->ctx) {
386 av_log(s, AV_LOG_DEBUG, "Input context already opened for %s.\n",
387 track_resource->locator->absolute_uri);
388 return 0;
389 }
390
391 track_resource->ctx = avformat_alloc_context();
392 if (!track_resource->ctx)
393 return AVERROR(ENOMEM);
394
395 track_resource->ctx->io_open = s->io_open;
396 track_resource->ctx->io_close2 = s->io_close2;
397 track_resource->ctx->opaque = s->opaque;
398 track_resource->ctx->flags |= s->flags & ~AVFMT_FLAG_CUSTOM_IO;
399
400 if ((ret = ff_copy_whiteblacklists(track_resource->ctx, s)) < 0)
401 goto cleanup;
402
403 if ((ret = av_opt_set(track_resource->ctx, "format_whitelist", "mxf", 0)))
404 goto cleanup;
405
406 if ((ret = av_dict_copy(&opts, c->avio_opts, 0)) < 0)
407 goto cleanup;
408
409 ret = avformat_open_input(&track_resource->ctx,
410 track_resource->locator->absolute_uri,
411 NULL,
412 &opts);
413 if (ret < 0) {
414 av_log(s, AV_LOG_ERROR, "Could not open %s input context: %s\n",
415 track_resource->locator->absolute_uri, av_err2str(ret));
416 goto cleanup;
417 }
419
420 /* make sure there is only one stream in the file */
421
422 if (track_resource->ctx->nb_streams != 1) {
424 goto cleanup;
425 }
426
427 st = track_resource->ctx->streams[0];
428
429 /* Determine the seek offset into the Track File, taking into account:
430 * - the current timestamp within the virtual track
431 * - the entry point of the resource
432 */
433 if (imf_time_to_ts(&seek_offset,
434 av_sub_q(track->current_timestamp, track_resource->ts_offset),
435 st->time_base))
436 av_log(s, AV_LOG_WARNING, "Incoherent stream timebase " AVRATIONAL_FORMAT
437 "and composition timeline position: " AVRATIONAL_FORMAT "\n",
439
440 if (seek_offset) {
441 av_log(s, AV_LOG_DEBUG, "Seek at resource %s entry point: %" PRIi64 "\n",
442 track_resource->locator->absolute_uri, seek_offset);
443 ret = avformat_seek_file(track_resource->ctx, 0, seek_offset, seek_offset, seek_offset, 0);
444 if (ret < 0) {
445 av_log(s,
447 "Could not seek at %" PRId64 "on %s: %s\n",
448 seek_offset,
449 track_resource->locator->absolute_uri,
450 av_err2str(ret));
451 avformat_close_input(&track_resource->ctx);
452 return ret;
453 }
454 }
455
456 return 0;
457
458cleanup:
460 avformat_free_context(track_resource->ctx);
461 track_resource->ctx = NULL;
462 return ret;
463}
464
466 FFIMFTrackFileResource *track_file_resource,
468{
469 IMFContext *c = s->priv_data;
470 IMFAssetLocator *asset_locator;
472 void *tmp;
473
474 asset_locator = find_asset_map_locator(&c->asset_locator_map, track_file_resource->track_file_uuid);
475 if (!asset_locator) {
476 av_log(s, AV_LOG_ERROR, "Could not find asset locator for UUID: " AV_PRI_URN_UUID "\n",
477 AV_UUID_ARG(track_file_resource->track_file_uuid));
478 return AVERROR_INVALIDDATA;
479 }
480
481 av_log(s,
483 "Found locator for " AV_PRI_URN_UUID ": %s\n",
484 AV_UUID_ARG(asset_locator->uuid),
485 asset_locator->absolute_uri);
486
487 if (track_file_resource->base.repeat_count
488 > MAX_RESOURCES - c->total_resource_count)
489 return AVERROR(ENOMEM);
490 c->total_resource_count += track_file_resource->base.repeat_count;
492 &track->resources_alloc_sz,
493 (track->resource_count + track_file_resource->base.repeat_count)
495 if (!tmp)
496 return AVERROR(ENOMEM);
497 track->resources = tmp;
498
499 av_reduce(&duration.num, &duration.den,
500 track_file_resource->base.duration * (int64_t)track_file_resource->base.edit_rate.den,
501 track_file_resource->base.edit_rate.num, INT_MAX);
502
503 for (uint32_t i = 0; i < track_file_resource->base.repeat_count; i++) {
505
506 vt_ctx.locator = asset_locator;
507 vt_ctx.resource = track_file_resource;
508 vt_ctx.ctx = NULL;
509 vt_ctx.start_time = track->duration;
510 vt_ctx.ts_offset = av_sub_q(vt_ctx.start_time,
511 av_div_q(av_make_q((int)track_file_resource->base.entry_point, 1),
512 track_file_resource->base.edit_rate));
513 vt_ctx.end_time = av_add_q(track->duration, duration);
514 track->resources[track->resource_count++] = vt_ctx;
515 track->duration = vt_ctx.end_time;
516 }
517
518 return 0;
519}
520
522{
523 for (uint32_t i = 0; i < track->resource_count; i++)
525
526 av_freep(&track->resources);
527}
528
530 FFIMFTrackFileVirtualTrack *virtual_track,
532{
533 IMFContext *c = s->priv_data;
535 void *tmp;
536 int ret = 0;
537
538 if (!(track = av_mallocz(sizeof(IMFVirtualTrackPlaybackCtx))))
539 return AVERROR(ENOMEM);
540 track->current_resource_index = -1;
541 track->index = track_index;
542 track->duration = av_make_q(0, 1);
543
544 if (!virtual_track->resource_count) {
545 av_log(s, AV_LOG_ERROR, "Virtual track has no resources\n");
547 goto clean_up;
548 }
549
550 for (uint32_t i = 0; i < virtual_track->resource_count; i++) {
551 av_log(s,
553 "Open stream from file " AV_PRI_URN_UUID ", stream %d\n",
554 AV_UUID_ARG(virtual_track->resources[i].track_file_uuid),
555 i);
556 if ((ret = open_track_file_resource(s, &virtual_track->resources[i], track)) != 0) {
557 av_log(s,
559 "Could not open image track resource " AV_PRI_URN_UUID "\n",
560 AV_UUID_ARG(virtual_track->resources[i].track_file_uuid));
561 goto clean_up;
562 }
563 }
564
565 track->current_timestamp = av_make_q(0, track->duration.den);
566
567 if (c->track_count == UINT32_MAX) {
568 ret = AVERROR(ENOMEM);
569 goto clean_up;
570 }
571 tmp = av_realloc_array(c->tracks, c->track_count + 1, sizeof(IMFVirtualTrackPlaybackCtx *));
572 if (!tmp) {
573 ret = AVERROR(ENOMEM);
574 goto clean_up;
575 }
576 c->tracks = tmp;
577 c->tracks[c->track_count++] = track;
578
579 return 0;
580
581clean_up:
583 av_free(track);
584 return ret;
585}
586
588{
589 IMFContext *c = s->priv_data;
590 int ret = 0;
591
592 for (uint32_t i = 0; i < c->track_count; i++) {
593 AVStream *asset_stream;
594 AVStream *first_resource_stream;
595
596 /* Open the first resource of the track to get stream information */
597 ret = open_track_resource_context(s, c->tracks[i], 0);
598 if (ret)
599 return ret;
600 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
601 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", c->tracks[i]->index);
602
603 asset_stream = ff_stream_clone(s, first_resource_stream);
604 if (!asset_stream) {
605 av_log(s, AV_LOG_ERROR, "Could not clone stream\n");
606 return AVERROR(ENOMEM);
607 }
608
609 asset_stream->id = i;
610 asset_stream->nb_frames = 0;
611 avpriv_set_pts_info(asset_stream,
612 first_resource_stream->pts_wrap_bits,
613 first_resource_stream->time_base.num,
614 first_resource_stream->time_base.den);
615 asset_stream->duration = (int64_t)av_q2d(av_mul_q(c->tracks[i]->duration,
616 av_inv_q(asset_stream->time_base)));
617 }
618
619 return 0;
620}
621
623{
624 IMFContext *c = s->priv_data;
626 int ret;
627
628 if (c->cpl->main_image_2d_track) {
629 if ((ret = open_virtual_track(s, c->cpl->main_image_2d_track, track_index++)) != 0) {
630 av_log(s, AV_LOG_ERROR, "Could not open image track " AV_PRI_URN_UUID "\n",
631 AV_UUID_ARG(c->cpl->main_image_2d_track->base.id_uuid));
632 return ret;
633 }
634 }
635
636 for (uint32_t i = 0; i < c->cpl->main_audio_track_count; i++) {
637 if ((ret = open_virtual_track(s, &c->cpl->main_audio_tracks[i], track_index++)) != 0) {
638 av_log(s, AV_LOG_ERROR, "Could not open audio track " AV_PRI_URN_UUID "\n",
639 AV_UUID_ARG(c->cpl->main_audio_tracks[i].base.id_uuid));
640 return ret;
641 }
642 }
643
645}
646
648{
649 IMFContext *c = s->priv_data;
650 char *asset_map_path;
651 char *tmp_str;
653 char tc_buf[AV_TIMECODE_STR_SIZE];
654 int ret = 0;
655
656 c->interrupt_callback = &s->interrupt_callback;
657 tmp_str = av_strdup(s->url);
658 if (!tmp_str)
659 return AVERROR(ENOMEM);
660 c->base_url = av_strdup(av_dirname(tmp_str));
661 av_freep(&tmp_str);
662 if (!c->base_url)
663 return AVERROR(ENOMEM);
664
665 if ((ret = ffio_copy_url_options(s->pb, &c->avio_opts)) < 0)
666 return ret;
667
668 av_log(s, AV_LOG_DEBUG, "start parsing IMF CPL: %s\n", s->url);
669
670 if ((ret = ff_imf_parse_cpl(s, s->pb, &c->cpl)) < 0)
671 return ret;
672
673 tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
674 if (!tcr && c->cpl->tc) {
675 ret = av_dict_set(&s->metadata, "timecode",
676 av_timecode_make_string(c->cpl->tc, tc_buf, 0), 0);
677 if (ret)
678 return ret;
679 av_log(s, AV_LOG_INFO, "Setting timecode to IMF CPL timecode %s\n", tc_buf);
680 }
681
682 av_log(s,
684 "parsed IMF CPL: " AV_PRI_URN_UUID "\n",
685 AV_UUID_ARG(c->cpl->id_uuid));
686
687 if (!c->asset_map_paths) {
688 c->asset_map_paths = av_append_path_component(c->base_url, "ASSETMAP.xml");
689 if (!c->asset_map_paths) {
690 ret = AVERROR(ENOMEM);
691 return ret;
692 }
693 av_log(s, AV_LOG_DEBUG, "No asset maps provided, using the default ASSETMAP.xml\n");
694 }
695
696 /* Parse each asset map XML file */
697 imf_asset_locator_map_init(&c->asset_locator_map);
698 asset_map_path = av_strtok(c->asset_map_paths, ",", &tmp_str);
699 while (asset_map_path != NULL) {
700 av_log(s, AV_LOG_DEBUG, "start parsing IMF Asset Map: %s\n", asset_map_path);
701
702 if ((ret = parse_assetmap(s, asset_map_path)))
703 return ret;
704
705 asset_map_path = av_strtok(NULL, ",", &tmp_str);
706 }
707
708 av_log(s, AV_LOG_DEBUG, "parsed IMF Asset Maps\n");
709
710 if ((ret = open_cpl_tracks(s)))
711 return ret;
712
713 av_log(s, AV_LOG_DEBUG, "parsed IMF package\n");
714
715 return 0;
716}
717
719{
720 IMFContext *c = s->priv_data;
722 AVRational minimum_timestamp = av_make_q(INT32_MAX, 1);
723
724 for (uint32_t i = c->track_count; i > 0; i--) {
725 av_log(s, AV_LOG_TRACE, "Compare track %d timestamp " AVRATIONAL_FORMAT
726 " to minimum " AVRATIONAL_FORMAT
727 " (over duration: " AVRATIONAL_FORMAT ")\n", i,
728 AVRATIONAL_ARG(c->tracks[i - 1]->current_timestamp),
729 AVRATIONAL_ARG(minimum_timestamp),
730 AVRATIONAL_ARG(c->tracks[i - 1]->duration));
731
732 if (av_cmp_q(c->tracks[i - 1]->current_timestamp, minimum_timestamp) <= 0) {
733 track = c->tracks[i - 1];
734 minimum_timestamp = track->current_timestamp;
735 }
736 }
737
738 return track;
739}
740
742{
743 *resource = NULL;
744
745 if (av_cmp_q(track->current_timestamp, track->duration) >= 0) {
746 av_log(s, AV_LOG_DEBUG, "Reached the end of the virtual track\n");
747 return AVERROR_EOF;
748 }
749
750 av_log(s,
752 "Looking for track %d resource for timestamp = %lf / %lf\n",
753 track->index,
755 av_q2d(track->duration));
756 for (uint32_t i = 0; i < track->resource_count; i++) {
757
758 if (av_cmp_q(track->resources[i].end_time, track->current_timestamp) > 0) {
759 av_log(s, AV_LOG_DEBUG, "Found resource %d in track %d to read at timestamp %lf: "
760 "entry=%" PRIu32 ", duration=%" PRIu32 ", editrate=" AVRATIONAL_FORMAT "\n",
761 i, track->index, av_q2d(track->current_timestamp),
765
766 if (track->current_resource_index != i) {
767 int ret;
768
769 av_log(s, AV_LOG_TRACE, "Switch resource on track %d: re-open context\n",
770 track->index);
771
773 if (ret != 0)
774 return ret;
775 if (track->current_resource_index > 0)
777 track->current_resource_index = i;
778 }
779
780 *resource = track->resources + track->current_resource_index;
781 return 0;
782 }
783 }
784
785 av_log(s, AV_LOG_ERROR, "Could not find IMF track resource to read\n");
787}
788
790{
792 int ret = 0;
794 int64_t delta_ts;
795 AVStream *st;
796 AVRational next_timestamp;
797
799
800 if (!track) {
801 av_log(s, AV_LOG_ERROR, "No track found for playback\n");
802 return AVERROR_INVALIDDATA;
803 }
804
805 av_log(s, AV_LOG_DEBUG, "Found track %d to read at timestamp %lf\n",
806 track->index, av_q2d(track->current_timestamp));
807
808 ret = get_resource_context_for_timestamp(s, track, &resource);
809 if (ret)
810 return ret;
811
812 ret = av_read_frame(resource->ctx, pkt);
813 if (ret)
814 return ret;
815
816 av_log(s, AV_LOG_DEBUG, "Got packet: pts=%" PRId64 ", dts=%" PRId64
817 ", duration=%" PRId64 ", stream_index=%d, pos=%" PRId64
818 ", time_base=" AVRATIONAL_FORMAT "\n", pkt->pts, pkt->dts, pkt->duration,
819 pkt->stream_index, pkt->pos, AVRATIONAL_ARG(pkt->time_base));
820
821 /* IMF resources contain only one stream */
822
823 if (pkt->stream_index != 0)
824 return AVERROR_INVALIDDATA;
825 st = resource->ctx->streams[0];
826
827 pkt->stream_index = track->index;
828
829 /* adjust the packet PTS and DTS based on the temporal position of the resource within the timeline */
830
831 ret = imf_time_to_ts(&delta_ts, resource->ts_offset, st->time_base);
832
833 if (!ret) {
834 if (pkt->pts != AV_NOPTS_VALUE)
835 pkt->pts += delta_ts;
836 if (pkt->dts != AV_NOPTS_VALUE)
837 pkt->dts += delta_ts;
838 } else {
839 av_log(s, AV_LOG_WARNING, "Incoherent time stamp " AVRATIONAL_FORMAT
840 " for time base " AVRATIONAL_FORMAT,
841 AVRATIONAL_ARG(resource->ts_offset),
842 AVRATIONAL_ARG(pkt->time_base));
843 }
844
845 /* advance the track timestamp by the packet duration */
846
847 next_timestamp = av_add_q(track->current_timestamp,
848 av_mul_q(av_make_q((int)pkt->duration, 1), st->time_base));
849
850 /* if necessary, clamp the next timestamp to the end of the current resource */
851
852 if (av_cmp_q(next_timestamp, resource->end_time) > 0) {
853
854 int64_t new_pkt_dur;
855
856 /* shrink the packet duration */
857
858 ret = imf_time_to_ts(&new_pkt_dur,
859 av_sub_q(resource->end_time, track->current_timestamp),
860 st->time_base);
861
862 if (!ret)
863 pkt->duration = new_pkt_dur;
864 else
865 av_log(s, AV_LOG_WARNING, "Incoherent time base in packet duration calculation\n");
866
867 /* shrink the packet itself for audio essence */
868
870
872 /* AV_CODEC_ID_PCM_S24LE is the only PCM format supported in IMF */
873 /* in this case, explicitly shrink the packet */
874
875 int bytes_per_sample = av_get_exact_bits_per_sample(st->codecpar->codec_id) >> 3;
876 int64_t nbsamples = av_rescale_q(pkt->duration,
877 st->time_base,
879 av_shrink_packet(pkt, nbsamples * st->codecpar->ch_layout.nb_channels * bytes_per_sample);
880
881 } else {
882 /* in all other cases, use side data to skip samples */
883 int64_t skip_samples;
884
885 ret = imf_time_to_ts(&skip_samples,
886 av_sub_q(next_timestamp, resource->end_time),
888
889 if (ret || skip_samples < 0 || skip_samples > UINT32_MAX) {
890 av_log(s, AV_LOG_WARNING, "Cannot skip audio samples\n");
891 } else {
892 uint8_t *side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10);
893 if (!side_data)
894 return AVERROR(ENOMEM);
895
896 AV_WL32(side_data + 4, skip_samples); /* skip from end of this packet */
897 side_data[6] = 1; /* reason for end is convergence */
898 }
899 }
900
901 next_timestamp = resource->end_time;
902
903 } else {
904 av_log(s, AV_LOG_WARNING, "Non-audio packet duration reduced\n");
905 }
906 }
907
908 track->current_timestamp = next_timestamp;
909
910 return 0;
911}
912
914{
915 IMFContext *c = s->priv_data;
916
917 av_log(s, AV_LOG_DEBUG, "Close IMF package\n");
918 av_dict_free(&c->avio_opts);
919 av_freep(&c->base_url);
920 imf_asset_locator_map_deinit(&c->asset_locator_map);
921 ff_imf_cpl_free(c->cpl);
922
923 for (uint32_t i = 0; i < c->track_count; i++) {
925 av_freep(&c->tracks[i]);
926 }
927
928 av_freep(&c->tracks);
929
930 return 0;
931}
932
933static int imf_probe(const AVProbeData *p)
934{
935 if (!strstr(p->buf, "<CompositionPlaylist"))
936 return 0;
937
938 /* check for a ContentTitle element without including ContentTitleText,
939 * which is used by the D-Cinema CPL.
940 */
941 if (!strstr(p->buf, "ContentTitle>"))
942 return 0;
943
944 return AVPROBE_SCORE_MAX;
945}
946
947static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb)
948{
949 return av_rescale_q_rnd(ts, in_tb, out_tb, AV_ROUND_DOWN) ==
950 av_rescale_q_rnd(ts, in_tb, out_tb, AV_ROUND_UP);
951}
952
953static int imf_seek(AVFormatContext *s, int stream_index, int64_t min_ts,
954 int64_t ts, int64_t max_ts, int flags)
955{
956 IMFContext *c = s->priv_data;
957 uint32_t i;
958
960 return AVERROR(ENOSYS);
961
962 /* rescale timestamps to Composition edit units */
963 if (stream_index < 0)
965 av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num),
966 &min_ts, &ts, &max_ts);
967 else
968 ff_rescale_interval(s->streams[stream_index]->time_base,
969 av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num),
970 &min_ts, &ts, &max_ts);
971
972 /* requested timestamp bounds are too close */
973 if (max_ts < min_ts)
974 return -1;
975
976 /* clamp requested timestamp to provided bounds */
977 ts = FFMAX(FFMIN(ts, max_ts), min_ts);
978
979 av_log(s, AV_LOG_DEBUG, "Seeking to Composition Playlist edit unit %" PRIi64 "\n", ts);
980
981 /* set the dts of each stream and temporal offset of each track */
982 for (i = 0; i < c->track_count; i++) {
983 AVStream *st = s->streams[i];
984 IMFVirtualTrackPlaybackCtx *t = c->tracks[i];
985 int64_t dts;
986
987 if (!coherent_ts(ts, av_make_q(c->cpl->edit_rate.den, c->cpl->edit_rate.num),
988 st->time_base))
989 av_log(s, AV_LOG_WARNING, "Seek position is not coherent across tracks\n");
990
991 dts = av_rescale_q(ts, av_inv_q(c->cpl->edit_rate), st->time_base);
992
993 av_log(s, AV_LOG_DEBUG, "Seeking to dts=%" PRId64 " on stream_index=%d\n",
994 dts, i);
995
997 if (t->current_resource_index >= 0) {
1000 }
1001 }
1002
1003 return 0;
1004}
1005
1006static const AVOption imf_options[] = {
1007 {
1008 .name = "assetmaps",
1009 .help = "Comma-separated paths to ASSETMAP files."
1010 "If not specified, the `ASSETMAP.xml` file in the same "
1011 "directory as the CPL is used.",
1012 .offset = offsetof(IMFContext, asset_map_paths),
1013 .type = AV_OPT_TYPE_STRING,
1014 .default_val = {.str = NULL},
1016 },
1017 {NULL},
1018};
1019
1020static const AVClass imf_class = {
1021 .class_name = "imf",
1022 .item_name = av_default_item_name,
1023 .option = imf_options,
1024 .version = LIBAVUTIL_VERSION_INT,
1025};
1026
1028 .p.name = "imf",
1029 .p.long_name = NULL_IF_CONFIG_SMALL("IMF (Interoperable Master Format)"),
1030 .p.flags = AVFMT_NO_BYTE_SEEK,
1031 .p.priv_class = &imf_class,
1032 .flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
1033 .priv_data_size = sizeof(IMFContext),
1038 .read_seek2 = imf_seek,
1039};
const FFInputFormat ff_imf_demuxer
Definition imfdec.c:1027
static AVDictionary * opts
int32_t
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition avformat.c:992
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition avformat.c:910
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:865
AVStream * ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
Create a new stream and copy to it all parameters from a source stream, with the exception of the ind...
Definition avformat.c:266
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:485
#define AVFMT_NO_BYTE_SEEK
Format does not allow seeking by bytes.
Definition avformat.h:508
#define AVSEEK_FLAG_BYTE
seeking based on position in bytes
Definition avformat.h:2748
#define AVSEEK_FLAG_FRAME
seeking based on frame number
Definition avformat.h:2750
#define AVFMT_FLAG_CUSTOM_IO
The caller has supplied a custom AVIOContext, don't avio_close() it.
Definition avformat.h:1561
#define AVIO_FLAG_READ
read-only
Definition avio.h:630
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
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.
Definition aviobuf.c:1222
int ffio_copy_url_options(AVIOContext *pb, AVDictionary **avio_opts)
Read url related dictionary options from the AVIOContext and write to the given dictionary.
Definition aviobuf.c:962
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
AVBPrint public header.
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
void ff_rescale_interval(AVRational tb_in, AVRational tb_out, int64_t *min_ts, int64_t *ts, int64_t *max_ts)
Rescales a timestamp and the endpoints of an interval to which the temstamp belongs,...
Definition seek.c:872
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition demux.h:35
static AVPacket * pkt
static int64_t duration
Definition ffplay.c:359
int ret
Definition ffplay.c:391
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:580
static av_cold void cleanup(FlashSV2Context *s)
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition utils.c:461
@ AV_CODEC_ID_PCM_S24LE
Definition codec_id.h:345
@ AV_PKT_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
Definition packet.h:153
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition packet.c:231
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition packet.c:113
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition options.c:165
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition avformat.c:165
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
Definition seek.c:789
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition demux.c:1646
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition demux.c:231
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition demux.c:400
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:234
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:236
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition dict.c:61
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition dict.c:250
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:87
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
Definition error.h:67
#define AVERROR_EOF
End of file.
Definition error.h:57
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
Definition rational.c:93
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition rational.c:80
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition rational.c:35
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition rational.h:89
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition rational.h:159
AVRational av_sub_q(AVRational b, AVRational c)
Subtract one rational from another.
Definition rational.c:101
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition rational.c:88
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_DOWN
Round toward -infinity.
@ AV_ROUND_UP
Round toward +infinity.
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.
Definition mem.c:601
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition mem.c:318
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition avstring.c:179
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition avstring.c:208
const char * av_dirname(char *path)
Thread safe dirname.
Definition avstring.c:274
char * av_append_path_component(const char *path, const char *component)
Append path component to the existing path.
Definition avstring.c:295
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition opt.c:904
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.
Definition imf_cpl.c:59
int ff_imf_parse_cpl(void *log_ctx, AVIOContext *in, FFIMFCPL **cpl)
Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
Definition imf_cpl.c:878
void ff_imf_cpl_free(FFIMFCPL *cpl)
Deletes an FFIMFCPL data structure previously instantiated with ff_imf_cpl_alloc().
Definition imf_cpl.c:849
int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
Reads a UUID from an XML element.
Definition imf_cpl.c:73
#define MAX_RESOURCES
Definition imfdec.c:80
static void imf_asset_locator_map_init(IMFAssetLocatorMap *asset_map)
Initializes an IMFAssetLocatorMap structure.
Definition imfdec.c:293
static int imf_uri_is_url(const char *string)
Definition imfdec.c:132
static int set_context_streams_from_tracks(AVFormatContext *s)
Definition imfdec.c:587
static int imf_uri_is_unix_abs_path(const char *string)
Definition imfdec.c:137
static const AVClass imf_class
Definition imfdec.c:1020
#define AVRATIONAL_FORMAT
Definition imfdec.c:78
static int imf_uri_is_dos_abs_path(const char *string)
Definition imfdec.c:142
static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb)
Definition imfdec.c:947
static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
Definition imfdec.c:159
#define AVRATIONAL_ARG(rational)
Definition imfdec.c:79
static const AVOption imf_options[]
Definition imfdec.c:1006
static int imf_read_header(AVFormatContext *s)
Definition imfdec.c:647
static IMFAssetLocator * find_asset_map_locator(IMFAssetLocatorMap *asset_map, AVUUID uuid)
Definition imfdec.c:365
static int imf_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition imfdec.c:789
static int open_track_file_resource(AVFormatContext *s, FFIMFTrackFileResource *track_file_resource, IMFVirtualTrackPlaybackCtx *track)
Definition imfdec.c:465
static int open_cpl_tracks(AVFormatContext *s)
Definition imfdec.c:622
static void imf_asset_locator_map_deinit(IMFAssetLocatorMap *asset_map)
Free a IMFAssetLocatorMap pointer.
Definition imfdec.c:302
static int open_virtual_track(AVFormatContext *s, FFIMFTrackFileVirtualTrack *virtual_track, int32_t track_index)
Definition imfdec.c:529
static int imf_close(AVFormatContext *s)
Definition imfdec.c:913
static int parse_assetmap(AVFormatContext *s, const char *url)
Definition imfdec.c:310
static IMFVirtualTrackPlaybackCtx * get_next_track_with_minimum_timestamp(AVFormatContext *s)
Definition imfdec.c:718
static int imf_probe(const AVProbeData *p)
Definition imfdec.c:933
static int get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrackPlaybackCtx *track, IMFVirtualTrackResourcePlaybackCtx **resource)
Definition imfdec.c:741
static int parse_imf_asset_map_from_xml_dom(AVFormatContext *s, xmlDocPtr doc, IMFAssetLocatorMap *asset_map, const char *base_url)
Parse a ASSETMAP XML file to extract the UUID-URI mapping of assets.
Definition imfdec.c:186
static void imf_virtual_track_playback_context_deinit(IMFVirtualTrackPlaybackCtx *track)
Definition imfdec.c:521
static int imf_seek(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Definition imfdec.c:953
static int open_track_resource_context(AVFormatContext *s, IMFVirtualTrackPlaybackCtx *track, int32_t resource_index)
Definition imfdec.c:374
#define r
Definition input.c:42
#define AV_WL32(p, v)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
static av_cold int read_close(AVFormatContext *ctx)
Definition libcdio.c:143
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
Memory handling functions.
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1401
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition avformat.h:1457
int(* io_close2)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
Definition avformat.h:2037
int flags
Flags modifying the (de)muxer behaviour.
Definition avformat.h:1553
void * opaque
User data.
Definition avformat.h:1986
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1469
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
Definition avformat.h:2027
Bytestream IO Context.
Definition avio.h:160
Callback for checking whether to abort blocking functions.
Definition avio.h:59
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
This structure contains the data a format has to probe a file.
Definition avformat.h:473
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
int64_t nb_frames
number of frames in this stream if known or 0
Definition avformat.h:829
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition avformat.h:827
int id
Format-specific stream ID.
Definition avformat.h:780
int pts_wrap_bits
Number of bits in timestamps.
Definition avformat.h:911
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:807
AVRational edit_rate
BaseResourceType/EditRate.
Definition imf.h:69
uint32_t duration
BaseResourceType/Duration.
Definition imf.h:71
uint32_t repeat_count
BaseResourceType/RepeatCount.
Definition imf.h:72
uint32_t entry_point
BaseResourceType/EntryPoint.
Definition imf.h:70
IMF Composition Playlist.
Definition imf.h:130
IMF Composition Playlist Track File Resource.
Definition imf.h:78
FFIMFBaseResource base
Definition imf.h:79
AVUUID track_file_uuid
TrackFileResourceType/TrackFileId.
Definition imf.h:80
IMF Composition Playlist Virtual Track that consists of Track File Resources.
Definition imf.h:111
FFIMFTrackFileResource * resources
Resource elements of the Virtual Track.
Definition imf.h:114
uint32_t resource_count
Number of Resource elements present in the Virtual Track.
Definition imf.h:113
IMF Asset locator map Results from the parsing of one or more ASSETMAP XML files.
Definition imfdec.c:94
uint32_t asset_count
Definition imfdec.c:95
IMFAssetLocator * assets
Definition imfdec.c:96
IMF Asset locator.
Definition imfdec.c:85
char * absolute_uri
Definition imfdec.c:87
AVUUID uuid
Definition imfdec.c:86
const char * base_url
Definition imfdec.c:121
IMFAssetLocatorMap asset_locator_map
Definition imfdec.c:126
FFIMFCPL * cpl
Definition imfdec.c:125
uint32_t track_count
Definition imfdec.c:127
AVDictionary * avio_opts
Definition imfdec.c:124
AVIOInterruptCB * interrupt_callback
Definition imfdec.c:123
char * asset_map_paths
Definition imfdec.c:122
uint32_t total_resource_count
Definition imfdec.c:129
IMFVirtualTrackPlaybackCtx ** tracks
Definition imfdec.c:128
AVRational duration
Overall duration.
Definition imfdec.c:111
AVRational current_timestamp
Current temporal position.
Definition imfdec.c:110
uint32_t resource_count
Number of resources (<= INT32_MAX)
Definition imfdec.c:112
int32_t current_resource_index
Index of the current resource in resources, or < 0 if a current resource has yet to be selected.
Definition imfdec.c:115
int32_t index
Track index in playlist.
Definition imfdec.c:109
IMFVirtualTrackResourcePlaybackCtx * resources
Buffer holding the resources.
Definition imfdec.c:114
unsigned int resources_alloc_sz
Size of the buffer holding the resource.
Definition imfdec.c:113
AVRational end_time
exclusive end time of the resource on the CPL timeline (s)
Definition imfdec.c:104
AVFormatContext * ctx
Context associated with the resource.
Definition imfdec.c:102
IMFAssetLocator * locator
Location of the resource.
Definition imfdec.c:100
FFIMFTrackFileResource * resource
Underlying IMF CPL resource.
Definition imfdec.c:101
AVRational ts_offset
start_time minus the entry point into the resource (s)
Definition imfdec.c:105
AVRational start_time
inclusive start time of the resource on the CPL timeline (s)
Definition imfdec.c:103
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
char * av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum_arg)
Load timecode string in buf.
Definition timecode.c:104
#define AV_TIMECODE_STR_SIZE
Definition timecode.h:33
#define AV_PRI_URN_UUID
Definition uuid.h:43
#define AV_UUID_ARG(x)
Definition uuid.h:51
uint8_t AVUUID[AV_UUID_LEN]
Definition uuid.h:60
static int track_index(VividasDemuxContext *viv, AVFormatContext *s, const uint8_t *buf, unsigned size)
Definition vividas.c:438
static double c[64]