76#include <libxml/parser.h>
78#define AVRATIONAL_FORMAT "%d/%d"
79#define AVRATIONAL_ARG(rational) rational.num, rational.den
132 return strstr(
string,
"://") !=
NULL;
137 return string[0] ==
'/';
143 if (
string[1] ==
':' &&
string[2] ==
'\\')
147 if (
string[1] ==
':' &&
string[2] ==
'/')
151 if (
string[0] ==
'\\' &&
string[1] ==
'\\')
165 if ((
av_reduce(&dst_num, &dst_den,
r.num,
r.den, INT64_MAX) != 1))
187 const char *base_url)
189 xmlNodePtr asset_map_element =
NULL;
190 xmlNodePtr node =
NULL;
191 xmlNodePtr asset_element =
NULL;
192 unsigned long elem_count;
198 asset_map_element = xmlDocGetRootElement(doc);
200 if (!asset_map_element) {
205 if (asset_map_element->type != XML_ELEMENT_NODE ||
av_strcasecmp(asset_map_element->name,
"AssetMap")) {
206 av_log(
s,
AV_LOG_ERROR,
"Unable to parse asset map XML - wrong root node name[%s] type[%d]\n",
207 asset_map_element->name, (
int)asset_map_element->type);
216 elem_count = xmlChildElementCount(node);
217 if (elem_count > UINT32_MAX
218 || asset_map->
asset_count > UINT32_MAX - elem_count)
229 asset_element = xmlFirstElementChild(node);
230 while (asset_element) {
260 av_log(
s,
AV_LOG_ERROR,
"Unable to parse asset map XML - missing Path element in Chunk\n");
264 uri = xmlNodeGetContent(path_node);
265 if (!uri || !uri[0]) {
283 asset_element = xmlNextElementSibling(asset_element);
316 const char *base_url;
317 char *tmp_str =
NULL;
347 doc = xmlReadMemory(buf.str, buf.len, url,
NULL, 0);
352 c->asset_locator_map.asset_count, url);
367 if (memcmp(asset_map->
assets[
i].
uuid, uuid, 16) == 0)
368 return &(asset_map->
assets[
i]);
384 if (track_resource->
ctx) {
391 if (!track_resource->
ctx)
402 if ((ret =
av_opt_set(track_resource->
ctx,
"format_whitelist",
"mxf", 0)))
446 "Could not seek at %" PRId64
"on %s: %s\n",
473 if (!asset_locator) {
500 vt_ctx.
locator = asset_locator;
501 vt_ctx.
resource = track_file_resource;
564 if (
c->track_count == UINT32_MAX) {
574 c->tracks[
c->track_count++] = track;
589 for (uint32_t
i = 0;
i <
c->track_count;
i++) {
597 first_resource_stream =
c->tracks[
i]->resources[0].ctx->streams[0];
606 asset_stream->
id =
i;
625 if (
c->cpl->main_image_2d_track) {
628 AV_UUID_ARG(
c->cpl->main_image_2d_track->base.id_uuid));
633 for (uint32_t
i = 0;
i <
c->cpl->main_audio_track_count;
i++) {
647 char *asset_map_path;
653 c->interrupt_callback = &
s->interrupt_callback;
671 if (!tcr &&
c->cpl->tc) {
684 if (!
c->asset_map_paths) {
686 if (!
c->asset_map_paths) {
695 asset_map_path =
av_strtok(
c->asset_map_paths,
",", &tmp_str);
696 while (asset_map_path !=
NULL) {
721 for (uint32_t
i =
c->track_count;
i > 0;
i--) {
729 if (
av_cmp_q(
c->tracks[
i - 1]->current_timestamp, minimum_timestamp) <= 0) {
730 track =
c->tracks[
i - 1];
749 "Looking for track %d resource for timestamp = %lf / %lf\n",
814 ", duration=%" PRId64
", stream_index=%d, pos=%" PRId64
820 if (
pkt->stream_index != 0)
832 pkt->pts += delta_ts;
834 pkt->dts += delta_ts;
860 pkt->duration = new_pkt_dur;
886 if (ret || skip_samples < 0 || skip_samples > UINT32_MAX) {
893 AV_WL32(side_data + 4, skip_samples);
898 next_timestamp = resource->
end_time;
920 for (uint32_t
i = 0;
i <
c->track_count;
i++) {
932 if (!strstr(p->buf,
"<CompositionPlaylist"))
938 if (!strstr(p->buf,
"ContentTitle>"))
951 in_tb.
den * out_tb.
num, INT64_MAX);
952 if (!ret || dst_den != 1)
968 if (stream_index < 0)
970 av_make_q(
c->cpl->edit_rate.den,
c->cpl->edit_rate.num),
971 &min_ts, &ts, &max_ts);
974 av_make_q(
c->cpl->edit_rate.den,
c->cpl->edit_rate.num),
975 &min_ts, &ts, &max_ts);
987 for (
i = 0;
i <
c->track_count;
i++) {
1015 .name =
"assetmaps",
1016 .help =
"Comma-separated paths to ASSETMAP files."
1017 "If not specified, the `ASSETMAP.xml` file in the same "
1018 "directory as the CPL is used.",
1019 .offset = offsetof(
IMFContext, asset_map_paths),
1021 .default_val = {.str =
NULL},
1028 .class_name =
"imf",
static AVDictionary * opts
#define AVIO_FLAG_READ
read-only
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.
int ffio_copy_url_options(AVIOContext *pb, AVDictionary **avio_opts)
Read url related dictionary options from the AVIOContext and write to the given dictionary.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
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,...
#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...
static int read_header(FFV1Context *f, RangeCoder *c)
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.
@ 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...
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
@ AV_PKT_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
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.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static AVRational av_make_q(int num, int den)
Create an AVRational.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
AVRational av_sub_q(AVRational b, AVRational c)
Subtract one rational from another.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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)
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().
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
const char * av_dirname(char *path)
Thread safe dirname.
char * av_append_path_component(const char *path, const char *component)
Append path component to the existing path.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
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.
int ff_imf_parse_cpl(void *log_ctx, AVIOContext *in, FFIMFCPL **cpl)
Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
void ff_imf_cpl_free(FFIMFCPL *cpl)
Deletes an FFIMFCPL data structure previously instantiated with ff_imf_cpl_alloc().
int ff_imf_xml_read_uuid(xmlNodePtr element, AVUUID uuid)
Reads a UUID from an XML element.
static void imf_asset_locator_map_init(IMFAssetLocatorMap *asset_map)
Initializes an IMFAssetLocatorMap structure.
static int imf_uri_is_url(const char *string)
static int set_context_streams_from_tracks(AVFormatContext *s)
static int imf_uri_is_unix_abs_path(const char *string)
static const AVClass imf_class
#define AVRATIONAL_FORMAT
static int imf_uri_is_dos_abs_path(const char *string)
static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb)
static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
#define AVRATIONAL_ARG(rational)
static const AVOption imf_options[]
static int imf_read_header(AVFormatContext *s)
static IMFAssetLocator * find_asset_map_locator(IMFAssetLocatorMap *asset_map, AVUUID uuid)
static int imf_read_packet(AVFormatContext *s, AVPacket *pkt)
static int open_track_file_resource(AVFormatContext *s, FFIMFTrackFileResource *track_file_resource, IMFVirtualTrackPlaybackCtx *track)
static int open_cpl_tracks(AVFormatContext *s)
static void imf_asset_locator_map_deinit(IMFAssetLocatorMap *asset_map)
Free a IMFAssetLocatorMap pointer.
static int open_virtual_track(AVFormatContext *s, FFIMFTrackFileVirtualTrack *virtual_track, int32_t track_index)
static int imf_close(AVFormatContext *s)
static int parse_assetmap(AVFormatContext *s, const char *url)
static IMFVirtualTrackPlaybackCtx * get_next_track_with_minimum_timestamp(AVFormatContext *s)
static int imf_probe(const AVProbeData *p)
static int get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrackPlaybackCtx *track, IMFVirtualTrackResourcePlaybackCtx **resource)
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.
static void imf_virtual_track_playback_context_deinit(IMFVirtualTrackPlaybackCtx *track)
static int imf_seek(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
static int open_track_resource_context(AVFormatContext *s, IMFVirtualTrackPlaybackCtx *track, int32_t resource_index)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
Memory handling functions.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
AVChannelLayout ch_layout
The channel layout and number of channels.
enum AVMediaType codec_type
General type of the encoded data.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int(* io_close2)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
int flags
Flags modifying the (de)muxer behaviour.
AVStream ** streams
A list of all streams in the file.
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
Callback for checking whether to abort blocking functions.
This structure stores compressed data.
This structure contains the data a format has to probe a file.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int64_t nb_frames
number of frames in this stream if known or 0
int64_t duration
Decoding: duration of the stream, in stream time base.
int id
Format-specific stream ID.
int pts_wrap_bits
Number of bits in timestamps.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
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.
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.
IMF Asset locator map Results from the parsing of one or more ASSETMAP XML files.
IMFAssetLocatorMap asset_locator_map
AVIOInterruptCB * interrupt_callback
IMFVirtualTrackPlaybackCtx ** tracks
AVRational duration
Overall duration.
AVRational current_timestamp
Current temporal position.
uint32_t resource_count
Number of resources (<= INT32_MAX)
int32_t current_resource_index
Index of the current resource in resources, or < 0 if a current resource has yet to be selected.
int32_t index
Track index in playlist.
IMFVirtualTrackResourcePlaybackCtx * resources
Buffer holding the resources.
unsigned int resources_alloc_sz
Size of the buffer holding the resource.
AVRational end_time
exclusive end time of the resource on the CPL timeline (s)
AVFormatContext * ctx
Context associated with the resource.
IMFAssetLocator * locator
Location of the resource.
FFIMFTrackFileResource * resource
Underlying IMF CPL resource.
AVRational ts_offset
start_time minus the entry point into the resource (s)
AVRational start_time
inclusive start time of the resource on the CPL timeline (s)
char * av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum_arg)
Load timecode string in buf.
#define AV_TIMECODE_STR_SIZE
uint8_t AVUUID[AV_UUID_LEN]
static int track_index(VividasDemuxContext *viv, AVFormatContext *s, const uint8_t *buf, unsigned size)