580 if (
avio_seek(pb, last_pos + 1, SEEK_SET) < 0)
629 int max_size, uint64_t *number)
642 "Read error at pos. %"PRIu64
" (0x%"PRIx64
")\n",
651 if (read > max_size) {
654 "Invalid EBML number size tag 0x%02x at pos %"PRIu64
" (0x%"PRIx64
")\n",
662 total = (total << 8) |
avio_r8(pb);
678 if (res > 0 && *number + 1 == 1ULL << (7 * res))
679 *number = 0xffffffffffffffULL;
697 *num = (*num << 8) |
avio_r8(pb);
812 *num = unum - ((1LL << (7 * res - 1)) - 1);
821 uint32_t
id,
void *
data)
824 for (i = 0; syntax[i].
id; i++)
825 if (
id == syntax[i].
id)
857 for (i = 0; syntax[i].
id; i++)
858 switch (syntax[i].type) {
860 *(uint64_t *) ((
char *) data + syntax[i].
data_offset) = syntax[i].def.
u;
863 *(
double *) ((
char *) data + syntax[i].data_offset) = syntax[i].
def.
f;
868 if (syntax[i].def.
s) {
897 uint32_t
id = syntax->
id;
919 if (max_lengths[syntax->
type] && length > max_lengths[syntax->
type]) {
921 "Invalid length 0x%"PRIx64
" > 0x%"PRIx64
" for syntax element %i\n",
922 length, max_lengths[syntax->
type], syntax->
type);
927 switch (syntax->
type) {
964 for (i = 0; syntax[i].
id; i++) {
965 void *data_off = (
char *) data + syntax[i].data_offset;
966 switch (syntax[i].type) {
975 if (syntax[i].list_elem_size) {
977 char *ptr = list->
elem;
996 int len_mask = 0x80,
size = 1, n = 1, i;
1004 while (
size <= 8 && !(total & len_mask)) {
1010 total &= (len_mask - 1);
1012 total = (total << 8) | p->
buf[4 + n++];
1024 if (total < probelen)
1026 for (n = 4 +
size; n <= 4 +
size + total - probelen; n++)
1042 if (tracks[i].num == num)
1054 int isize = *buf_size;
1057 int pkt_size = isize;
1061 if (pkt_size >= 10000000)
1064 switch (encodings[0].compression.algo) {
1073 pkt_size = isize + header_size;
1078 memcpy(pkt_data, header, header_size);
1079 memcpy(pkt_data + header_size, data, isize);
1085 olen = pkt_size *= 3;
1091 pkt_data = newpktdata;
1104 z_stream zstream = { 0 };
1105 if (inflateInit(&zstream) != Z_OK)
1107 zstream.next_in =
data;
1108 zstream.avail_in = isize;
1113 inflateEnd(&zstream);
1116 pkt_data = newpktdata;
1117 zstream.avail_out = pkt_size - zstream.total_out;
1118 zstream.next_out = pkt_data + zstream.total_out;
1119 result = inflate(&zstream, Z_NO_FLUSH);
1120 }
while (result == Z_OK && pkt_size < 10000000);
1121 pkt_size = zstream.total_out;
1122 inflateEnd(&zstream);
1123 if (result != Z_STREAM_END) {
1124 if (result == Z_MEM_ERROR)
1136 bz_stream bzstream = { 0 };
1137 if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
1139 bzstream.next_in =
data;
1140 bzstream.avail_in = isize;
1145 BZ2_bzDecompressEnd(&bzstream);
1148 pkt_data = newpktdata;
1149 bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
1150 bzstream.next_out = pkt_data + bzstream.total_out_lo32;
1151 result = BZ2_bzDecompress(&bzstream);
1152 }
while (result == BZ_OK && pkt_size < 10000000);
1153 pkt_size = bzstream.total_out_lo32;
1154 BZ2_bzDecompressEnd(&bzstream);
1155 if (result != BZ_STREAM_END) {
1156 if (result == BZ_MEM_ERROR)
1170 *buf_size = pkt_size;
1179 AVPacket *pkt, uint64_t display_duration)
1182 char *layer, *ptr = pkt->
data, *end = ptr + pkt->
size;
1184 for (; *ptr !=
',' && ptr < end - 1; ptr++)
1188 for (; *ptr !=
',' && ptr < end - 1; ptr++)
1191 int64_t end_pts = pkt->
pts + display_duration;
1193 int ec = matroska->
time_scale * end_pts / 10000000;
1194 int sh, sm, ss, eh, em, es,
len;
1211 snprintf(line->
data, len,
1212 "Dialogue: %s,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,%s\r\n",
1213 layer, sh, sm, ss, sc, eh, em, es, ec, ptr);
1223 int old_size = out->
size;
1242 for (i = 0; i < list->
nb_elem; i++) {
1243 const char *lang = tags[i].
lang &&
1244 strcmp(tags[i].lang,
"und") ? tags[i].
lang :
NULL;
1246 if (!tags[i].
name) {
1251 snprintf(key,
sizeof(key),
"%s/%s", prefix, tags[i].name);
1254 if (tags[i].def || !lang) {
1256 if (tags[i].sub.nb_elem)
1263 if (tags[i].sub.nb_elem)
1277 if (tags[i].target.attachuid) {
1280 if (attachment[j].uid == tags[i].target.attachuid &&
1283 &attachment[j].stream->metadata,
NULL);
1284 }
else if (tags[i].target.chapteruid) {
1287 if (chapter[j].uid == tags[i].target.chapteruid &&
1290 &chapter[j].chapter->metadata,
NULL);
1291 }
else if (tags[i].target.trackuid) {
1294 if (track[j].uid == tags[i].target.trackuid && track[j].
stream)
1296 &track[j].stream->metadata,
NULL);
1308 uint32_t level_up = matroska->
level_up;
1316 if (idx >= seekhead_list->
nb_elem ||
1328 "Max EBML element depth (%d) reached, "
1333 level.
length = (uint64_t) -1;
1338 ret =
ebml_parse(matroska, matroska_segment, matroska);
1343 if (length == (uint64_t) -1)
1367 for (i = 0; i < seekhead_list->
nb_elem; i++) {
1369 if (seekhead[i].pos <= before_pos)
1389 int index_scale = 1;
1392 for (i = 0; i < seekhead_list->
nb_elem; i++)
1395 assert(i <= seekhead_list->nb_elem);
1399 index_list = &matroska->
index;
1400 index = index_list->
elem;
1406 for (i = 0; i < index_list->
nb_elem; i++) {
1409 for (j = 0; j < pos_list->
nb_elem; j++) {
1412 if (track && track->stream)
1415 index[i].
time / index_scale, 0, 0,
1423 static const char *
const aac_profiles[] = {
"MAIN",
"LC",
"SSR" };
1426 for (profile = 0; profile <
FF_ARRAY_ELEMS(aac_profiles); profile++)
1427 if (strstr(codec_id, aac_profiles[profile]))
1463 int block_last, block_type, block_size;
1469 if (block_size > size)
1478 chmask =
av_dict_get(dict,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK",
NULL, 0);
1481 if (!mask || mask & ~0x3ffffULL) {
1483 "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
1510 int extradata_size = 0;
1511 int extradata_offset = 0;
1519 "Unknown or unsupported track type %"PRIu64
"\n",
1537 if (encodings_list->
nb_elem > 1) {
1539 "Multiple combined encodings not supported");
1540 }
else if (encodings_list->
nb_elem == 1) {
1541 if (encodings[0].type ||
1553 encodings[0].
scope = 0;
1555 "Unsupported encoding type");
1565 "Failed to decode codec private data\n");
1585 if (!strcmp(track->
codec_id,
"V_MS/VFW/FOURCC") &&
1592 extradata_offset = 40;
1593 }
else if (!strcmp(track->
codec_id,
"A_MS/ACM") &&
1605 }
else if (!strcmp(track->
codec_id,
"V_QUICKTIME") &&
1644 extradata[0] = (profile << 3) | ((sri & 0x0E) >> 1);
1645 extradata[1] = ((sri & 0x01) << 7) | (track->
audio.
channels << 3);
1646 if (strstr(track->
codec_id,
"SBR")) {
1648 extradata[2] = 0x56;
1649 extradata[3] = 0xE5;
1650 extradata[4] = 0x80 | (sri << 3);
1663 AV_WB32(extradata, extradata_size);
1664 memcpy(&extradata[4],
"alac", 4);
1669 extradata_size = 30;
1686 extradata_offset = 26;
1718 const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 };
1723 extradata_offset = 78;
1734 "Unknown/unsupported AVCodecID %s.\n", track->
codec_id);
1739 1000 * 1000 * 1000);
1748 if (strcmp(track->
language,
"und"))
1822 uint64_t max_start = 0;
1836 ebml.
max_size >
sizeof(uint64_t) ||
1840 "EBML header using unsupported features\n"
1841 "(EBML version %"PRIu64
", doctype %s, doc version %"PRIu64
")\n",
1860 res =
ebml_parse(matroska, matroska_segments, matroska);
1867 res =
ebml_parse(matroska, matroska_segment, matroska);
1882 attachments = attachments_list->
elem;
1883 for (j = 0; j < attachments_list->
nb_elem; j++) {
1884 if (!(attachments[j].filename && attachments[j].mime &&
1885 attachments[j].bin.data && attachments[j].
bin.
size > 0)) {
1909 attachments[j].
stream = st;
1913 chapters = chapters_list->
elem;
1914 for (i = 0; i < chapters_list->
nb_elem; i++)
1916 (max_start == 0 || chapters[i].start > max_start)) {
1920 chapters[i].
start, chapters[i].
end,
1923 "title", chapters[i].
title, 0);
1924 max_start = chapters[i].
start;
1950 matroska->
packets = newpackets;
1980 int *buf_size,
int type,
1981 uint32_t **lace_buf,
int *laces)
1983 int res = 0, n,
size = *buf_size;
1985 uint32_t *lace_size;
1993 *lace_buf[0] =
size;
2001 lace_size =
av_mallocz(*laces *
sizeof(
int));
2010 for (n = 0; res == 0 && n < *laces - 1; n++) {
2017 lace_size[n] += temp;
2023 total += lace_size[n];
2025 if (size <= total) {
2030 lace_size[n] = size - total;
2035 if (size % (*laces)) {
2039 for (n = 0; n < *laces; n++)
2040 lace_size[n] = size / *laces;
2050 "EBML block data error\n");
2056 total = lace_size[0] = num;
2057 for (n = 1; res == 0 && n < *laces - 1; n++) {
2063 "EBML block data error\n");
2069 lace_size[n] = lace_size[n - 1] + snum;
2070 total += lace_size[n];
2072 if (size <= total) {
2076 lace_size[*laces - 1] = size - total;
2082 *lace_buf = lace_size;
2105 if (size < cfs * h / 2) {
2107 "Corrupt int4 RM-style audio packet size\n");
2110 for (x = 0; x < h / 2; x++)
2111 memcpy(track->
audio.
buf + x * 2 * w + y * cfs,
2112 data + x * cfs, cfs);
2116 "Corrupt sipr RM-style audio packet size\n");
2119 memcpy(track->
audio.
buf + y * w, data, w);
2121 if (size < sps * w / sps) {
2123 "Corrupt generic RM-style audio packet size\n");
2126 for (x = 0; x < w / sps; x++)
2128 sps * (h * x + ((h + 1) / 2) * (y & 1) + (y >> 1)),
2129 data + x * sps, sps);
2165 int ret, offset = 0;
2167 if (srclen < 12 || track->stream->codec->extradata_size < 2)
2176 while (srclen >= 8) {
2182 uint32_t crc =
AV_RL32(src + 4);
2186 multiblock = (flags & 0x1800) != 0x1800;
2198 if (blocksize > srclen) {
2203 tmp =
av_realloc(dst, dstlen + blocksize + 32);
2209 dstlen += blocksize + 32;
2212 AV_WL32(dst + offset + 4, blocksize + 24);
2213 AV_WL16(dst + offset + 8, ver);
2214 AV_WL16(dst + offset + 10, 0);
2215 AV_WL32(dst + offset + 12, 0);
2216 AV_WL32(dst + offset + 16, 0);
2217 AV_WL32(dst + offset + 20, samples);
2218 AV_WL32(dst + offset + 24, flags);
2219 AV_WL32(dst + offset + 28, crc);
2220 memcpy(dst + offset + 32, src, blocksize);
2223 srclen -= blocksize;
2224 offset += blocksize + 32;
2240 uint64_t timecode, uint64_t
duration,
2245 int offset = 0, res;
2248 if (encodings && encodings->
scope & 1) {
2259 "Error parsing a wavpack block.\n");
2262 if (pkt_data != data)
2279 bytestream_put_be32(&buf, pkt_size);
2280 bytestream_put_be32(&buf,
MKBETAG(
'i',
'c',
'p',
'f'));
2283 memcpy(pkt->
data + offset, pkt_data, pkt_size);
2285 if (pkt_data != data)
2292 pkt->
dts = timecode;
2294 pkt->
pts = timecode;
2318 if (pkt_data != data)
2324 int size, int64_t pos, uint64_t cluster_time,
2326 int64_t cluster_pos)
2333 uint32_t *lace_size =
NULL;
2334 int n,
flags, laces = 0;
2345 if (!track || !track->
stream) {
2347 "Invalid stream %"PRIu64
" or size %u\n", num, size);
2349 }
else if (size <= 3)
2359 if (is_keyframe == -1)
2362 if (cluster_time != (uint64_t) -1 &&
2363 (block_time >= 0 || cluster_time >= -block_time)) {
2364 timecode = cluster_time + block_time - track->
codec_delay;
2366 timecode < track->end_timecode)
2375 if (!is_keyframe || timecode < matroska->skip_to_timecode)
2381 &lace_size, &laces);
2387 duration = block_duration / laces;
2388 if (block_duration != duration * laces) {
2390 "Incorrect block_duration, possibly corrupted container");
2394 block_duration = duration * laces;
2401 for (n = 0; n < laces; n++) {
2409 timecode, duration, pos);
2414 timecode, duration, pos,
2415 !n ? is_keyframe : 0);
2422 data += lace_size[n];
2436 matroska_cluster_incremental_parsing,
2451 matroska_clusters_incremental,
2456 matroska_cluster_incremental_parsing,
2464 blocks = blocks_list->
elem;
2468 if (blocks[i].bin.size > 0 && blocks[i].
bin.
data) {
2470 if (!blocks[i].non_simple)
2499 res =
ebml_parse(matroska, matroska_clusters, &cluster);
2500 blocks_list = &cluster.
blocks;
2501 blocks = blocks_list->
elem;
2502 for (i = 0; i < blocks_list->
nb_elem && !res; i++)
2503 if (blocks[i].bin.size > 0 && blocks[i].
bin.
data) {
2505 if (!blocks[i].non_simple)
2538 int64_t timestamp,
int flags)
2543 int i,
index, index_sub, index_min;
2582 if (index_sub >= 0 &&
2586 index_min = index_sub;
2617 .
name =
"matroska,webm",
2619 .extensions =
"mkv,mk3d,mka,mks",
2626 .mime_type =
"audio/webm,audio/x-matroska,video/webm,video/x-matroska"
static EbmlSyntax matroska_simpletag[]
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define MATROSKA_ID_TRACKDEFAULTDURATION
void avio_wl16(AVIOContext *s, unsigned int val)
static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, int idx)
#define MATROSKA_ID_VIDEOFLAGINTERLACED
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void matroska_convert_tags(AVFormatContext *s)
#define MATROSKA_ID_DATEUTC
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.
#define MATROSKA_ID_TRACKFLAGLACING
#define MATROSKA_ID_TRACKENTRY
static int matroska_deliver_packet(MatroskaDemuxContext *matroska, AVPacket *pkt)
#define MATROSKA_ID_VIDEODISPLAYHEIGHT
AVInputFormat ff_matroska_demuxer
static int is_keyframe(NalUnitType naltype)
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.
#define MATROSKA_ID_CUETRACKPOSITION
#define MATROSKA_ID_CODECPRIVATE
const unsigned char ff_sipr_subpk_size[4]
#define MATROSKA_ID_TAGTARGETS_TYPE
#define AV_LOG_WARNING
Something somehow does not look correct.
static int ebml_level_end(MatroskaDemuxContext *matroska)
int64_t pos
byte position in stream, -1 if unknown
static int matroska_ebmlnum_sint(MatroskaDemuxContext *matroska, uint8_t *data, uint32_t size, int64_t *num)
#define MATROSKA_ID_ENCODINGTYPE
#define MATROSKA_ID_AUDIOBITDEPTH
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
#define MATROSKA_ID_TRACKFLAGDEFAULT
static EbmlSyntax matroska_segments[]
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
MatroskaCluster current_cluster
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
#define MATROSKA_ID_TAGTARGETS_ATTACHUID
int index
stream index in AVFormatContext
#define MATROSKA_ID_CLUSTERPOSITION
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define MATROSKA_ID_FILEDATA
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
#define EBML_ID_DOCTYPEREADVERSION
#define MATROSKA_ID_BLOCKREFERENCE
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define MATROSKA_ID_TRACKTYPE
int current_cluster_num_blocks
#define MATROSKA_ID_TAGTARGETS_CHAPTERUID
#define MATROSKA_ID_VIDEOASPECTRATIO
#define MATROSKA_ID_MUXINGAPP
#define MATROSKA_ID_AUDIOCHANNELS
#define FF_ARRAY_ELEMS(a)
MatroskaLevel levels[EBML_MAX_DEPTH]
static EbmlSyntax matroska_track_audio[]
#define MATROSKA_ID_CUECLUSTERPOSITION
unsigned int avio_rb16(AVIOContext *s)
const struct EbmlSyntax * n
#define MATROSKA_ID_EDITIONFLAGDEFAULT
#define MATROSKA_ID_CLUSTERTIMECODE
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static EbmlSyntax matroska_tag[]
static EbmlSyntax matroska_attachment[]
#define MATROSKA_ID_CHAPTERTIMEEND
static EbmlSyntax matroska_track[]
#define MATROSKA_ID_TRACKCONTENTENCODINGS
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define AV_LZO_OUTPUT_FULL
decoded data did not fit into output buffer
#define MATROSKA_ID_FILEDESC
#define MATROSKA_ID_TRACKCONTENTENCODING
#define MATROSKA_ID_CODECDOWNLOADURL
void avio_wl32(AVIOContext *s, unsigned int val)
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
#define MATROSKA_ID_CHAPLANG
#define MATROSKA_ID_EDITIONFLAGORDERED
#define MATROSKA_ID_TRACKLANGUAGE
MatroskaTrackCompression compression
const AVCodecTag ff_codec_movvideo_tags[]
unsigned int avio_rb32(AVIOContext *s)
int ff_mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mode)
#define MATROSKA_ID_VIDEOPIXELCROPT
#define MATROSKA_ID_TIMECODESCALE
static int matroska_aac_sri(int samplerate)
enum AVStreamParseType need_parsing
#define MATROSKA_ID_SIMPLEBLOCK
#define MATROSKA_ID_TAGTARGETS_TYPEVALUE
#define MATROSKA_ID_EDITIONFLAGHIDDEN
#define AV_LZO_OUTPUT_PADDING
static EbmlSyntax matroska_cluster[]
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.
#define MATROSKA_ID_CODECNAME
AVStream ** streams
A list of all streams in the file.
static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, int64_t pos, uint64_t cluster_time, uint64_t block_duration, int is_keyframe, int64_t cluster_pos)
#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int flags
Flags modifying the (de)muxer behaviour.
static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska)
#define MATROSKA_ID_VIDEODISPLAYWIDTH
#define MATROSKA_ID_EDITIONUID
int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, const uint8_t *buf, int size, int parse_picture)
static EbmlSyntax ebml_header[]
#define AVERROR_EOF
End of file.
#define MATROSKA_ID_CODECDECODEALL
static av_cold int read_close(AVFormatContext *ctx)
const uint8_t ff_log2_tab[256]
static void matroska_fix_ass_packet(MatroskaDemuxContext *matroska, AVPacket *pkt, uint64_t display_duration)
uint64_t avio_rb64(AVIOContext *s)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
#define MATROSKA_ID_TRACKNUMBER
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define MATROSKA_ID_SEGMENTUID
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static EbmlSyntax matroska_tracks[]
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int matroska_parse_cluster(MatroskaDemuxContext *matroska)
static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, void *data)
#define MATROSKA_ID_CUEBLOCKNUMBER
#define MATROSKA_ID_TRACKUID
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static EbmlSyntax matroska_info[]
#define MATROSKA_ID_ENCODINGORDER
#define MATROSKA_ID_VIDEOSTEREOMODE
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
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.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
#define MATROSKA_ID_BLOCKDURATION
#define EBML_ID_EBMLREADVERSION
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
static const uint16_t mask[17]
FLAC (Free Lossless Audio Codec) decoder/demuxer common functions.
static int ebml_read_length(MatroskaDemuxContext *matroska, AVIOContext *pb, uint64_t *number)
Read a EBML length value.
static EbmlSyntax matroska_index[]
int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
#define MATROSKA_ID_CLUSTER
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define MATROSKA_ID_FILEMIMETYPE
static int matroska_ebmlnum_uint(MatroskaDemuxContext *matroska, uint8_t *data, uint32_t size, uint64_t *num)
int64_t convergence_duration
Time difference in AVStream->time_base units from the pts of this packet to the point at which the ou...
#define MATROSKA_ID_WRITINGAPP
static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, MatroskaTrack *track, AVStream *st, uint8_t *data, int size, uint64_t timecode, uint64_t duration, int64_t pos)
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
preferred ID for decoding MPEG audio layer 1, 2 or 3
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
#define MATROSKA_ID_TAGDEFAULT_BUG
int cues_parsing_deferred
static EbmlSyntax matroska_clusters[]
static EbmlSyntax matroska_chapter[]
#define MATROSKA_ID_VIDEOPIXELCROPR
void av_log(void *avcl, int level, const char *fmt,...)
#define MATROSKA_ID_ENCODINGCOMPSETTINGS
#define EBML_ID_EBMLMAXIDLENGTH
#define MATROSKA_ID_CHAPTERFLAGHIDDEN
AVRational avg_frame_rate
Average framerate.
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.
static EbmlSyntax matroska_attachments[]
int flags
A combination of AV_PKT_FLAG values.
static EbmlSyntax matroska_cluster_incremental_parsing[]
uint64_t channel_layout
Audio channel layout.
int avio_r8(AVIOContext *s)
AVCodecContext * codec
Codec context associated with this stream.
static void ebml_free(EbmlSyntax *syntax, void *data)
const CodecMime ff_mkv_mime_tags[]
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static EbmlSyntax matroska_chapters[]
uint64_t skip_to_timecode
static int matroska_read_header(AVFormatContext *s)
static void matroska_parse_cues(MatroskaDemuxContext *matroska)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
int bit_rate
the average bitrate
static void matroska_execute_seekhead(MatroskaDemuxContext *matroska)
#define EBML_ID_EBMLVERSION
#define AV_TIME_BASE
Internal time base represented as integer.
#define MATROSKA_ID_TAGTARGETS
const AVCodecTag ff_codec_bmp_tags[]
#define MATROSKA_ID_TAGNAME
union EbmlSyntax::@108 def
#define MATROSKA_ID_TRACKTIMECODESCALE
static int ebml_parse_elem(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, void *data)
static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb, int max_size, uint64_t *number)
int width
picture width / height.
#define MATROSKA_ID_CHAPTERFLAGENABLED
static EbmlSyntax matroska_track_encodings[]
static MatroskaTrack * matroska_find_track_by_num(MatroskaDemuxContext *matroska, int num)
static av_always_inline int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
#define MATROSKA_ID_SIMPLETAG
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
static EbmlSyntax matroska_track_encoding[]
#define MATROSKA_ID_TRACKMAXCACHE
#define MATROSKA_ID_CHAPTERPHYSEQUIV
static int matroska_read_close(AVFormatContext *s)
#define FLAC_STREAMINFO_SIZE
static int ebml_read_ascii(AVIOContext *pb, int size, char **str)
static int matroska_decode_buffer(uint8_t **buf, int *buf_size, MatroskaTrack *track)
#define MATROSKA_ID_CHAPTERATOM
int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen)
Decodes LZO 1x compressed data.
Opaque data information usually sparse.
#define MATROSKA_ID_VIDEOCOLORSPACE
static EbmlSyntax matroska_segment[]
#define MATROSKA_ID_CHAPTERS
static int matroska_probe(AVProbeData *p)
static void matroska_convert_tag(AVFormatContext *s, EbmlList *list, AVDictionary **metadata, char *prefix)
#define MATROSKA_ID_AUDIOSAMPLINGFREQ
#define MATROSKA_ID_TRACKMINCACHE
static int matroska_parse_flac(AVFormatContext *s, MatroskaTrack *track, int *offset)
static int read_header(FFV1Context *f)
if(ac->has_optimized_func)
static int matroska_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
static EbmlSyntax matroska_seekhead[]
static int matroska_parse_wavpack(MatroskaTrack *track, uint8_t *src, uint8_t **pdst, int *size)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
int64_t current_cluster_pos
#define MATROSKA_ID_VIDEOPIXELCROPB
#define AV_LOG_INFO
Standard information.
static int matroska_parse_tracks(AVFormatContext *s)
#define MATROSKA_ID_TRACKFLAGFORCED
enum AVMediaType codec_type
static int ebml_read_master(MatroskaDemuxContext *matroska, uint64_t length)
#define MATROSKA_ID_TAGDEFAULT
#define MATROSKA_ID_SEEKID
char * av_strdup(const char *s)
Duplicate the string s.
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
int sample_rate
samples per second
AVIOContext * pb
I/O context.
#define MATROSKA_ID_ENCODINGCOMPALGO
#define MATROSKA_ID_BLOCK
#define MATROSKA_ID_TAGTARGETS_TRACKUID
uint8_t * data
The data buffer.
#define MATROSKA_ID_TAGLANG
static EbmlSyntax matroska_tags[]
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
#define MATROSKA_ID_TRACKFLAGENABLED
#define MATROSKA_ID_TRACKS
#define MATROSKA_ID_TRACKNAME
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static EbmlSyntax matroska_cluster_incremental[]
#define MATROSKA_ID_SEEKENTRY
#define MATROSKA_ID_EDITIONENTRY
#define MATROSKA_ID_BLOCKGROUP
#define MATROSKA_ID_VIDEOPIXELHEIGHT
rational number numerator/denominator
static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, int *buf_size, int type, uint32_t **lace_buf, int *laces)
#define MATROSKA_ID_CUETIME
static int matroska_read_packet(AVFormatContext *s, AVPacket *pkt)
static EbmlSyntax matroska_blockgroup[]
static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, void *data)
static av_always_inline void flac_parse_block_header(const uint8_t *block_header, int *last, int *type, int *size)
Parse the metadata block parameters from the header.
#define MATROSKA_ID_TITLE
#define MATROSKA_ID_TRACKVIDEO
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 ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, uint32_t id, void *data)
static EbmlSyntax ebml_syntax[]
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
#define MATROSKA_ID_VIDEOFRAMERATE
#define MATROSKA_ID_ATTACHMENTS
#define MATROSKA_ID_CHAPTERDISPLAY
#define MATROSKA_ID_FILENAME
const int avpriv_mpeg4audio_sample_rates[16]
const AVMetadataConv ff_mkv_metadata_conv[]
#define MATROSKA_ID_CODECID
static EbmlSyntax matroska_clusters_incremental[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
A reference to a data buffer.
void ff_rm_reorder_sipr_data(uint8_t *buf, int sub_packet_h, int framesize)
Perform 4-bit block reordering for SIPR data.
#define MATROSKA_ID_CUETRACK
static EbmlSyntax matroska_track_encoding_compression[]
#define MATROSKA_ID_SEEKPOSITION
static int matroska_resync(MatroskaDemuxContext *matroska, int64_t last_pos)
#define MATROSKA_ID_CODECDELAY
#define MATROSKA_ID_CHAPTERTIMESTART
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
int64_t start_time
Decoding: pts of the first frame of the stream, in stream time base.
int error_recognition
Error recognition; higher values will detect more errors but may misdetect some more or less valid pa...
int disposition
AV_DISPOSITION_* bit field.
static EbmlSyntax matroska_seekhead_entry[]
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
#define MATROSKA_ID_SEGMENT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
static EbmlSyntax matroska_tagtargets[]
#define MKBETAG(a, b, c, d)
#define MATROSKA_ID_SEEKHEAD
#define MATROSKA_ID_ENCODINGCOMPRESSION
#define MATROSKA_ID_CLUSTERPREVSIZE
int eof_reached
true if eof reached
#define MATROSKA_ID_POINTENTRY
int channels
number of audio channels
#define MATROSKA_ID_FILEUID
#define MATROSKA_ID_VIDEOPIXELCROPL
void * priv_data
Format private data.
#define MATROSKA_ID_CHAPTERUID
static EbmlSyntax matroska_index_entry[]
static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin)
#define MATROSKA_ID_VIDEODISPLAYUNIT
static int ebml_read_uint(AVIOContext *pb, int size, uint64_t *num)
#define MATROSKA_ID_TRACKMAXBLKADDID
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define EBML_ID_EBMLMAXSIZELENGTH
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
#define MATROSKA_ID_CHAPSTRING
static int matroska_merge_packets(AVPacket *out, AVPacket *in)
#define MATROSKA_ID_TAGSTRING
static EbmlSyntax matroska_index_pos[]
static int ebml_read_float(AVIOContext *pb, int size, double *num)
#define MATROSKA_ID_DURATION
static int matroska_aac_profile(char *codec_id)
#define EBML_ID_DOCTYPEVERSION
static void matroska_clear_queue(MatroskaDemuxContext *matroska)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
static EbmlSyntax matroska_chapter_entry[]
#define MKTAG(a, b, c, d)
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
#define MATROSKA_ID_ATTACHEDFILE
This structure stores compressed data.
static EbmlSyntax matroska_chapter_display[]
#define MATROSKA_ID_CODECSTATE
uint64_t default_duration
static int matroska_parse_frame(MatroskaDemuxContext *matroska, MatroskaTrack *track, AVStream *st, uint8_t *data, int pkt_size, uint64_t timecode, uint64_t duration, int64_t pos, int is_keyframe)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define MATROSKA_ID_CODECINFOURL
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define MATROSKA_ID_VIDEOPIXELWIDTH
#define MATROSKA_ID_TRACKAUDIO
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define MATROSKA_ID_ENCODINGSCOPE
const CodecTags ff_mkv_codec_tags[]
static const char *const matroska_doctypes[]
static EbmlSyntax matroska_track_video[]