Go to the documentation of this file.
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] ==
'\\')
168 const char *base_url)
170 xmlNodePtr asset_map_element =
NULL;
171 xmlNodePtr node =
NULL;
172 xmlNodePtr asset_element =
NULL;
173 unsigned long elem_count;
179 asset_map_element = xmlDocGetRootElement(doc);
181 if (!asset_map_element) {
186 if (asset_map_element->type != XML_ELEMENT_NODE ||
av_strcasecmp(asset_map_element->name,
"AssetMap")) {
189 "Unable to parse asset map XML - wrong root node name[%s] type[%d]\n",
190 asset_map_element->name,
191 (
int)asset_map_element->type);
200 elem_count = xmlChildElementCount(node);
201 if (elem_count > UINT32_MAX
202 || asset_map->
asset_count > UINT32_MAX - elem_count)
213 asset_element = xmlFirstElementChild(node);
214 while (asset_element) {
249 asset_element = xmlNextElementSibling(asset_element);
282 const char *base_url;
283 char *tmp_str =
NULL;
313 doc = xmlReadMemory(buf.str, buf.len, url,
NULL, 0);
319 "Found %d assets from %s\n",
320 c->asset_locator_map.asset_count,
336 if (memcmp(asset_map->
assets[
i].
uuid, uuid, 16) == 0)
337 return &(asset_map->
assets[
i]);
351 if (track_resource->
ctx) {
354 "Input context already opened for %s.\n",
360 if (!track_resource->
ctx)
384 "Could not open %s input context: %s\n",
417 "Seek at resource %s entry point: %" PRIu32
"\n",
424 "Could not seek at %" PRId64
"on %s: %s\n",
451 if (!asset_locator) {
480 vt_ctx.
locator = asset_locator;
481 vt_ctx.
resource = track_file_resource;
538 if (
c->track_count == UINT32_MAX) {
548 c->tracks[
c->track_count++] = track;
563 for (uint32_t
i = 0;
i <
c->track_count;
i++) {
571 first_resource_stream =
c->tracks[
i]->resources[0].ctx->streams[0];
580 asset_stream->
id =
i;
603 if (
c->cpl->main_image_2d_track) {
608 UID_ARG(
c->cpl->main_image_2d_track->base.id_uuid));
613 for (uint32_t
i = 0;
i <
c->cpl->main_audio_track_count;
i++) {
618 UID_ARG(
c->cpl->main_audio_tracks[
i].base.id_uuid));
629 char *asset_map_path;
633 c->interrupt_callback = &
s->interrupt_callback;
655 if (!
c->asset_map_paths) {
657 if (!
c->asset_map_paths) {
666 asset_map_path =
av_strtok(
c->asset_map_paths,
",", &tmp_str);
667 while (asset_map_path !=
NULL) {
692 for (uint32_t
i =
c->track_count;
i > 0;
i--) {
704 if (
av_cmp_q(
c->tracks[
i - 1]->current_timestamp, minimum_timestamp) <= 0) {
705 track =
c->tracks[
i - 1];
712 "Found next track to read: %d (timestamp: %lf / %lf)\n",
715 av_q2d(minimum_timestamp));
730 "Looking for track %d resource for timestamp = %lf / %lf\n",
739 "Found resource %d in track %d to read at timestamp %lf: "
741 ", duration=%" PRIu32
755 "Switch resource on track %d: re-open context\n",
783 if ((
av_reduce(&dst_num, &dst_den,
r.num,
r.den, INT64_MAX) != 1))
816 ", duration=%" PRId64
", stream_index=%d, pos=%" PRId64
881 int64_t skip_samples;
887 if (
ret || skip_samples < 0 || skip_samples > UINT32_MAX) {
894 AV_WL32(side_data + 4, skip_samples);
899 next_timestamp = resource->
end_time;
921 for (uint32_t
i = 0;
i <
c->track_count;
i++) {
933 if (!strstr(p->
buf,
"<CompositionPlaylist"))
939 if (!strstr(p->
buf,
"ContentTitle>"))
948 .help =
"Comma-separated paths to ASSETMAP files."
949 "If not specified, the `ASSETMAP.xml` file in the same "
950 "directory as the CPL is used.",
951 .offset = offsetof(
IMFContext, asset_map_paths),
953 .default_val = {.str =
NULL},
FFIMFTrackFileResource * resources
Resource elements of the Virtual Track.
#define AV_LOG_WARNING
Something somehow does not look correct.
int ffio_copy_url_options(AVIOContext *pb, AVDictionary **avio_opts)
Read url related dictionary options from the AVIOContext and write to the given dictionary.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
enum AVMediaType codec_type
General type of the encoded data.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static int set_context_streams_from_tracks(AVFormatContext *s)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
static int parse_assetmap(AVFormatContext *s, const char *url)
static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *buf, unsigned size)
#define AVERROR_EOF
End of file.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
static int imf_close(AVFormatContext *s)
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
static av_cold void cleanup(FlashSV2Context *s)
AVStream ** streams
A list of all streams in the file.
uint32_t resource_count
Number of Resource elements present in the Virtual Track.
IMFAssetLocatorMap asset_locator_map
static int imf_probe(const AVProbeData *p)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
AVRational av_sub_q(AVRational b, AVRational c)
Subtract one rational from another.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Callback for checking whether to abort blocking functions.
static int imf_uri_is_unix_abs_path(const char *string)
char * av_append_path_component(const char *path, const char *component)
Append path component to the existing path.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
#define AVRATIONAL_ARG(rational)
static int imf_uri_is_dos_abs_path(const char *string)
uint32_t resource_count
Number of resources (<= INT32_MAX)
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
void ff_imf_cpl_free(FFIMFCPL *cpl)
Deletes an FFIMFCPL data structure previously instantiated with ff_imf_cpl_alloc().
static av_cold int read_close(AVFormatContext *ctx)
uint32_t duration
BaseResourceType/Duration.
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 av_opt_set(void *obj, const char *name, const char *val, int search_flags)
int64_t duration
Decoding: duration of the stream, in stream time base.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
const char * av_dirname(char *path)
Thread safe dirname.
static int open_track_file_resource(AVFormatContext *s, FFIMFTrackFileResource *track_file_resource, IMFVirtualTrackPlaybackCtx *track)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
IMF Composition Playlist Virtual Track that consists of Track File Resources.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
AVRational current_timestamp
Current temporal position.
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.
int ff_imf_xml_read_uuid(xmlNodePtr element, uint8_t uuid[16])
Reads a UUID from an XML element.
int avio_read_to_bprint(AVIOContext *h, struct AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
int flags
Flags modifying the (de)muxer behaviour.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
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().
static const AVOption imf_options[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
IMFAssetLocator * locator
static IMFVirtualTrackPlaybackCtx * get_next_track_with_minimum_timestamp(AVFormatContext *s)
FFIMFTrackFileResource * resource
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
static int read_header(FFV1Context *f)
Describe the class of an AVClass context structure.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
static IMFAssetLocator * find_asset_map_locator(IMFAssetLocatorMap *asset_map, FFIMFUUID uuid)
Rational number (pair of numerator and denominator).
const char * av_default_item_name(void *ptr)
Return the context name.
This structure contains the data a format has to probe a file.
static int imf_uri_is_url(const char *string)
AVIOInterruptCB * interrupt_callback
static int get_resource_context_for_timestamp(AVFormatContext *s, IMFVirtualTrackPlaybackCtx *track, IMFVirtualTrackResourcePlaybackCtx **resource)
const AVInputFormat ff_imf_demuxer
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
int sample_rate
Audio only.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
static int imf_read_packet(AVFormatContext *s, AVPacket *pkt)
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
AVRational edit_rate
BaseResourceType/EditRate.
static void imf_asset_locator_map_deinit(IMFAssetLocatorMap *asset_map)
Free a IMFAssetLocatorMap pointer.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static void imf_asset_locator_map_init(IMFAssetLocatorMap *asset_map)
Initializes an IMFAssetLocatorMap structure.
static AVRational av_make_q(int num, int den)
Create an AVRational.
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.
#define AV_NOPTS_VALUE
Undefined timestamp value.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
static int open_cpl_tracks(AVFormatContext *s)
#define AVRATIONAL_FORMAT
uint32_t repeat_count
BaseResourceType/RepeatCount.
int32_t current_resource_index
Index of the current resource in resources, or < 0 if a current resource has yet to be selected.
int ff_imf_parse_cpl(AVIOContext *in, FFIMFCPL **cpl)
Parse an IMF Composition Playlist document into the FFIMFCPL data structure.
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint32_t entry_point
BaseResourceType/EntryPoint.
static int imf_read_header(AVFormatContext *s)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
static void imf_virtual_track_playback_context_deinit(IMFVirtualTrackPlaybackCtx *track)
int32_t index
Track index in playlist.
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.
uint8_t FFIMFUUID[16]
UUID as defined in IETF RFC 422.
static int imf_time_to_ts(int64_t *ts, AVRational t, AVRational time_base)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
int id
Format-specific stream ID.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
FFIMFUUID track_file_uuid
TrackFileResourceType/TrackFileId.
IMF Asset locator map Results from the parsing of one or more ASSETMAP XML files.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int open_track_resource_context(AVFormatContext *s, IMFVirtualTrackResourcePlaybackCtx *track_resource)
AVRational duration
Overall duration.
unsigned int resources_alloc_sz
Size of the buffer holding the resource.
IMF Composition Playlist Track File Resource.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
static int open_virtual_track(AVFormatContext *s, FFIMFTrackFileVirtualTrack *virtual_track, int32_t track_index)
void(* io_close)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static const AVClass imf_class
#define AVIO_FLAG_READ
read-only
char * av_strdup(const char *s)
Duplicate a string.
IMFVirtualTrackPlaybackCtx ** tracks
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
int64_t pos
byte position in stream, -1 if unknown
int(* io_close2)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
IMF Composition Playlist.
Public header file for the processing of Interoperable Master Format (IMF) packages.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
IMFVirtualTrackResourcePlaybackCtx * resources
Buffer holding the resources.
int pts_wrap_bits
Number of bits in timestamps.
#define FF_IMF_UUID_FORMAT
AVRational time_base
Time base of the packet's timestamps.
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.