134 #define ASF_MAX_STREAMS 127
135 #define FRAME_HEADER_SIZE 6
141 0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2
144 #define PRINT_IF_GUID(g, cmp) \
145 if (!ff_guidcmp(g, &cmp)) \
146 av_log(NULL, AV_LOG_TRACE, "(GUID: %s) ", # cmp)
174 else PRINT_IF_GUID(g, stream_bitrate_guid);
178 for (i = 0; i < 16; i++)
184 #define print_guid(g) while(0)
224 int ret,
type, picsize, desc_len;
227 if (len < 1 + 4 + 2 + 2) {
247 if (!strncmp(mime->
str, mimetype,
sizeof(mimetype))) {
259 if (picsize >= len) {
266 desc_len = (len - picsize) * 2 + 1;
308 if (id3v2_extra_meta)
320 if ((
unsigned)len >= (UINT_MAX -
LEN) / 2)
323 if (!asf->
export_xmp && !strncmp(key,
"xmp", 3))
332 }
else if (type == -1) {
335 }
else if (type == 1) {
336 if (!strcmp(key,
"WM/Picture")) {
338 }
else if (!strcmp(key,
"ID3")) {
344 }
else if (type > 1 && type <= 5) {
347 }
else if (type == 6) {
352 "Unsupported value type %d in tag %s.\n", type, key);
395 int type_specific_size, sizeX;
398 int test_for_ext_stream_audio, is_dvr_ms_audio = 0;
418 (10000000 / 1000) - start_time;
422 test_for_ext_stream_audio = 0;
433 test_for_ext_stream_audio = 1;
449 if (test_for_ext_stream_audio) {
468 if (is_dvr_ms_audio) {
480 if (size >= (pos2 + 8 - pos1 + 24)) {
494 size - (
avio_tell(pb) - pos1 + 24) >= 51) {
533 if (tag1 ==
MKTAG(
'D',
'V',
'R',
' ')) {
549 avio_skip(pb, size - (pos2 - pos1 + 24));
559 int ext_len, payload_ext_ct, stream_ct, i;
560 uint32_t leak_rate, stream_num;
561 unsigned int stream_languageid_index;
576 if (stream_num < 128)
583 if (stream_num < 128) {
588 for (i = 0; i < stream_ct; i++) {
594 for (i = 0; i < payload_ext_ct; i++) {
615 int len1, len2, len3, len4, len5;
622 get_tag(s,
"title", 0, len1, 32);
623 get_tag(s,
"author", 0, len2, 32);
624 get_tag(s,
"copyright", 0, len3, 32);
625 get_tag(s,
"comment", 0, len4, 32);
635 int desc_count, i,
ret;
638 for (i = 0; i < desc_count; i++) {
639 int name_len, value_type, value_len;
649 if (!value_type && value_len % 2)
654 if (!strcmp(name,
"AspectRatioX"))
656 else if (!strcmp(name,
"AspectRatioY"))
659 get_tag(s, name, value_type, value_len, 32);
671 for (j = 0; j < stream_count; j++) {
673 unsigned int lang_len =
avio_r8(pb);
675 sizeof(lang))) < lang_len)
689 int n, stream_num, name_len, value_len;
693 for (i = 0; i <
n; i++) {
706 i, stream_num, name_len, value_type, value_len, name);
708 if (!strcmp(name,
"AspectRatioX")){
711 asf->
dar[stream_num].
num = aspect_x;
712 }
else if(!strcmp(name,
"AspectRatioY")){
715 asf->
dar[stream_num].
den = aspect_y;
717 get_tag(s, name, value_type, value_len, 16);
736 for (i = 0; i < name_len; i++)
739 for (i = 0; i <
count; i++) {
751 sizeof(name))) < name_len)
777 for (i = 0; i<128; i++)
789 if (!(asf->
hdr.
flags & 0x01) && gsize >= 100)
836 "DRM protected stream detected, decoding will likely fail!\n");
845 get_tag(s,
"ASF_Protection_Type", -1, len, 32);
847 get_tag(s,
"ASF_Key_ID", -1, len, 32);
849 get_tag(s,
"ASF_License_URL", -1, len, 32);
852 "Ext DRM protected stream detected, decoding will likely fail!\n");
861 "gpos mismatch our pos=%"PRIu64
", end=%"PRId64
"\n",
874 for (i = 0; i < 128; i++) {
876 if (stream_num >= 0) {
884 }
else if ((asf->
dar[0].
num > 0) && (asf->
dar[0].
den > 0) &&
898 if (rfc1766 && strlen(rfc1766) > 1) {
899 const char primary_tag[3] = { rfc1766[0], rfc1766[1],
'\0' };
914 #define DO_2BITS(bits, var, defval) \
915 switch (bits & 3) { \
917 var = avio_rl32(pb); \
921 var = avio_rl16(pb); \
942 uint32_t packet_length, padsize;
958 if (c == 0x82 && !d && !e)
971 "ff asf bad header %x at:%"PRId64
"\n", c,
avio_tell(pb));
973 if ((c & 0x8f) == 0x82) {
994 if (!packet_length || packet_length >= (1
U << 29)) {
996 "invalid packet_length %"PRIu32
" at:%"PRId64
"\n",
1000 if (padsize >= packet_length) {
1002 "invalid padsize %"PRIu32
" at:%"PRId64
"\n", padsize,
avio_tell(pb));
1018 if (rsize > packet_length - padsize) {
1021 "invalid packet header length %d for pktlen %"PRIu32
"-%"PRIu32
" at %"PRId64
"\n",
1022 rsize, packet_length, padsize,
avio_tell(pb));
1026 if (packet_length < asf->hdr.min_pktsize)
1050 asfst = &asf->
streams[num & 0x7f];
1218 "stream:%d, expected:%d but got %d from pkt)\n",
1247 if (asf_st->
pkt.data) {
1249 "freeing incomplete packet size %d, new %d\n",
1277 av_log(asf,
AV_LOG_TRACE,
"new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n",
1299 "packet fragment position invalid %u,%u not in %u\n",
1313 if (ret < 0 || asf->packet_frag_offset + ret == 0)
1336 asf_st->
pkt.size > 100) {
1338 for (i = 0; i < asf_st->
pkt.size && !asf_st->
pkt.data[i]; i++)
1340 if (i == asf_st->
pkt.size) {
1352 "pkt.size != ds_packet_size * ds_span (%d %d %d)\n",
1362 memset(newdata + asf_st->
pkt.size, 0,
1364 while (offset < asf_st->pkt.
size) {
1366 int row = off / asf_st->
ds_span;
1367 int col = off % asf_st->
ds_span;
1371 memcpy(newdata + offset,
1384 #if FF_API_DESTRUCT_PACKET
1389 asf_st->
pkt.buf = 0;
1390 asf_st->
pkt.size = 0;
1391 asf_st->
pkt.data = 0;
1392 asf_st->
pkt.side_data_elems = 0;
1443 for (i = 0; i < 128; i++) {
1458 for (i = 0; i < 128; i++) {
1476 int64_t *ppos, int64_t pos_limit)
1482 int64_t pos = *ppos;
1556 int64_t itime, last_pos = -1;
1566 "itime:0x%"PRIx64
", pct:%d, ict:%d\n", itime, pct, ict);
1568 for (i = 0; i < ict; i++) {
1574 if (pos != last_pos) {
1576 pktnum, pktct, index_pts);
1658 .priv_class = &asf_class,
#define FRAME_HEADER_SIZE
const ff_asf_guid ff_asf_header
discard all frames except keyframes
static int asf_read_marker(AVFormatContext *s, int64_t size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t avio_size(AVIOContext *s)
Get the filesize.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
void av_free_packet(AVPacket *pkt)
Free a packet.
const ff_asf_guid ff_asf_ext_stream_audio_stream
const ff_asf_guid ff_asf_ext_content_encryption
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
const ff_asf_guid ff_asf_codec_comment_header
const ff_asf_guid ff_asf_metadata_header
static void get_id3_tag(AVFormatContext *s, int len)
#define AV_LOG_WARNING
Something somehow does not look correct.
AVInputFormat ff_asf_demuxer
#define LIBAVUTIL_VERSION_INT
static int asf_read_ext_stream_properties(AVFormatContext *s, int64_t size)
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
static const AVClass asf_class
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
uint64_t data_offset
beginning of the first data packet
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
static const AVOption options[]
static int asf_read_metadata(AVFormatContext *s, int64_t size)
int index
stream index in AVFormatContext
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
int64_t packet_frag_timestamp
const ff_asf_guid ff_asf_command_stream
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
#define FF_ARRAY_ELEMS(a)
const ff_asf_guid ff_asf_ext_stream_header
int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size, int big_endian)
uint32_t min_pktsize
size of a data packet invalid if broadcasting
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header. ...
int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a UTF-16 string from pb and convert it to UTF-8.
static int asf_read_file_properties(AVFormatContext *s, int64_t size)
Macro definitions for various function/variable attributes.
const ff_asf_guid ff_asf_data_header
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ffio_limit(AVIOContext *s, int size)
static int64_t start_time
uint32_t flags
0x01 - broadcast 0x02 - seekable rest is reserved should be 0
Opaque data information usually continuous.
const ff_asf_guid ff_asf_audio_stream
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
static av_cold int end(AVCodecContext *avctx)
enum AVStreamParseType need_parsing
int id
Format-specific stream ID.
ASFStream streams[128]
it's max number and it's not that big
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
#define DO_2BITS(bits, var, defval)
uint64_t send_time
time to send file, in 100-nanosecond units invalid if broadcasting (could be ignored) ...
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int asfid2avid[128]
conversion table from asf ID 2 AVStream ID
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
uint64_t file_size
in bytes invalid if broadcasting
ff_asf_guid guid
generated by client computer
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
const ff_asf_guid ff_asf_audio_conceal_none
static int asf_read_picture(AVFormatContext *s, int len)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
const ff_asf_guid ff_asf_head1_guid
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
const ff_asf_guid ff_asf_simple_index_header
const ff_asf_guid ff_asf_head2_guid
unsigned int avio_rl32(AVIOContext *s)
const char * av_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
const ff_asf_guid ff_asf_video_conceal_none
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_get_guid(AVIOContext *s, ff_asf_guid *g)
ASFStream * asf_st[ASF_MAX_STREAMS]
currently decoded stream
static const uint8_t offset[127][2]
uint64_t data_object_size
size of the data object
static int asf_build_simple_index(AVFormatContext *s, int stream_index)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
const char * ff_id3v2_picture_types[21]
int flags
A combination of AV_PKT_FLAG values.
static int asf_get_packet(AVFormatContext *s, AVIOContext *pb)
Load a single ASF packet into the demuxer.
static int asf_read_header(AVFormatContext *s)
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
uint32_t max_pktsize
shall be the same as for min_pktsize invalid if broadcasting
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
const CodecMime ff_id3v2_mime_tags[]
common internal API header
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int bit_rate
the average bitrate
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
const ff_asf_guid ff_asf_digital_signature
const AVCodecTag ff_codec_bmp_tags[]
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
char stream_languages[128][6]
max number of streams, language for each (RFC1766, e.g. en-US)
int width
picture width / height.
GLsizei GLboolean const GLfloat * value
const ff_asf_guid ff_asf_extended_content_header
unsigned int packet_frag_size
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
const ff_asf_guid ff_asf_ext_stream_embed_stream_header
const ff_asf_guid ff_asf_my_guid
Usually treated as AVMEDIA_TYPE_DATA.
static int asf_probe(AVProbeData *pd)
preferred ID for MPEG-1/2 video decoding
static int read_header(FFV1Context *f)
static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
uint32_t ignore
preroll is 64bit - but let's just ignore it
#define AV_LOG_INFO
Standard information.
uint32_t stream_bitrates[128]
max number of streams, bitrate for each (for streaming)
uint64_t create_time
time of creation, in 100-nanosecond units since 1.1.1601 invalid if broadcasting
enum AVMediaType codec_type
const ff_asf_guid ff_asf_file_header
uint64_t play_time
play time, in 100-nanosecond units invalid if broadcasting
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
AVIOContext * pb
I/O context.
static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
const ff_asf_guid ff_asf_video_stream
uint8_t * data
The data buffer.
static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
uint16_t stream_language_index
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
rational number numerator/denominator
const ff_asf_guid ff_asf_stream_header
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
unsigned int packet_frag_offset
static int asf_read_close(AVFormatContext *s)
const AVMetadataConv ff_asf_metadata_conv[]
static void skip_to_key(AVFormatContext *s)
uint64_t data_object_offset
data object offset (excl. GUID & size)
int error
contains the error code or 0 if no error happened
This structure contains the data a format has to probe a file.
static int asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb)
static int asf_read_content_desc(AVFormatContext *s, int64_t size)
const ff_asf_guid ff_asf_comment_header
static int64_t pts
Global timestamp for the audio frames.
int64_t duration
Decoding: duration of the stream, in stream time base.
uint32_t preroll
timestamp of the first packet, in milliseconds if nonzero - subtract from time
A reference to a data buffer.
const ff_asf_guid ff_asf_language_guid
unsigned int avio_rl16(AVIOContext *s)
const ff_asf_guid ff_asf_jfif_media
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal and external API header
int disposition
AV_DISPOSITION_* bit field.
const ff_asf_guid ff_asf_codec_comment1_header
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta, unsigned int max_search_size)
Read an ID3v2 tag, including supported extra metadata and chapters.
int64_t avio_seek_time(AVIOContext *h, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
const ff_asf_guid ff_asf_content_encryption
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define FF_ENABLE_DEPRECATION_WARNINGS
void * priv_data
Format private data.
static int asf_read_language_list(AVFormatContext *s, int64_t size)
static int get_value(AVIOContext *pb, int type, int type2_size)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
Parse data from individual ASF packets (which were previously loaded with asf_get_packet()).
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
const ff_asf_guid ff_asf_marker_header
void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size)
Send a nice hexadecimal dump of a buffer to the log.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
static void get_tag(AVFormatContext *s, const char *key, int type, int len, int type2_size)
#define MKTAG(a, b, c, d)
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
static av_always_inline int ff_guidcmp(const void *g1, const void *g2)
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
static void asf_reset_header(AVFormatContext *s)
This structure stores compressed data.
uint64_t avio_rl64(AVIOContext *s)
uint32_t max_bitrate
bandwidth of stream in bps should be the sum of bitrates of the individual media streams ...
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
const ff_asf_guid ff_asf_metadata_library_header
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
#define AV_NOPTS_VALUE
Undefined timestamp value.