72 #define EBML_UNKNOWN_LENGTH UINT64_MAX 73 #define NEEDS_CHECKING 2 77 #define SKIP_THRESHOLD 1024 * 1024 80 #define UNKNOWN_EQUIV 50 * 1024 410 #define CHILD_OF(parent) { .def = { .n = parent } } 462 CHILD_OF(matroska_track_video_color)
465 static EbmlSyntax matroska_track_video_color[] = {
538 static EbmlSyntax matroska_track_encoding[] = {
547 static EbmlSyntax matroska_track_encodings[] = {
555 CHILD_OF(matroska_track_combine_planes)
558 static EbmlSyntax matroska_track_combine_planes[] = {
563 static EbmlSyntax matroska_track_operation[] = {
629 static EbmlSyntax matroska_chapter_entry[] = {
739 static EbmlSyntax matroska_blockadditions[] = {
757 static EbmlSyntax matroska_cluster_parsing[] = {
801 uint32_t
id, int64_t position)
828 "Seek to desired resync point failed. Seeking to " 829 "earliest point available instead.\n");
831 last_pos + 1), SEEK_SET);
867 int max_size, uint64_t *number,
int eof_forbidden)
881 if (!total || read > max_size) {
885 "0x00 at pos %"PRId64
" (0x%"PRIx64
") invalid as first byte " 886 "of an EBML number\n", pos, pos);
889 "Length %d indicated by an EBML number's first byte 0x%02x " 890 "at pos %"PRId64
" (0x%"PRIx64
") exceeds max length %d.\n",
891 read, (
uint8_t) total, pos, pos, max_size);
899 total = (total << 8) |
avio_r8(pb);
914 "Read error at pos. %"PRIu64
" (0x%"PRIx64
")\n",
920 "at pos. %"PRIu64
" (0x%"PRIx64
")\n", pos, pos);
935 if (res > 0 && *number + 1 == 1ULL << (7 * res))
945 uint64_t default_value, uint64_t *num)
950 *num = default_value;
956 *num = (*num << 8) |
avio_r8(pb);
966 int64_t default_value, int64_t *num)
971 *num = default_value;
978 *num = ((uint64_t)*num << 8) |
avio_r8(pb);
989 double default_value,
double *num)
992 *num = default_value;
994 }
else if (size == 4) {
996 }
else if (size == 8) {
1009 const char *default_value,
char **
str)
1014 if (size == 0 && default_value) {
1100 *num = unum - ((1LL << (7 * res - 1)) - 1);
1114 for (i = 0; syntax[
i].
id; i++)
1115 if (
id == syntax[i].
id)
1127 for (
int i = 0; syntax[
i].
id;
i++) {
1128 void *dst = (
char *)data + syntax[
i].data_offset;
1129 switch (syntax[
i].
type) {
1131 *(uint64_t *)dst = syntax[
i].def.
u;
1134 *(int64_t *) dst = syntax[
i].
def.
i;
1137 *(
double *) dst = syntax[
i].def.
f;
1142 if (syntax[
i].def.
s) {
1170 return id && (bits + 7) / 8 == (8 - bits % 8);
1178 uint32_t
id, int64_t
pos)
1250 "at pos. %"PRIu64
" (0x%"PRIx64
")\n", pos, pos);
1257 pos_alt = pos + res;
1270 while (syntax->
def.
n) {
1280 "%"PRId64
"\n",
id, pos);
1297 list->
elem = newelem;
1314 uint64_t elem_end = pos_alt +
length,
1317 if (elem_end < level_end) {
1319 }
else if (elem_end == level_end) {
1323 "Element at 0x%"PRIx64
" ending at 0x%"PRIx64
" exceeds " 1324 "containing master element ending at 0x%"PRIx64
"\n",
1325 pos, elem_end, level_end);
1332 "at 0x%"PRIx64
" inside parent with finite size\n", pos);
1342 "Found unknown-length element 0x%"PRIX32
" other than " 1343 "a cluster at 0x%"PRIx64
". Spec-incompliant, but " 1344 "parsing will nevertheless be attempted.\n",
id, pos);
1351 if (max_lengths[syntax->
type] && length > max_lengths[syntax->
type]) {
1354 "Invalid length 0x%"PRIx64
" > 0x%"PRIx64
" for element " 1355 "with ID 0x%"PRIX32
" at 0x%"PRIx64
"\n",
1356 length, max_lengths[syntax->
type],
id, pos);
1359 "Element with ID 0x%"PRIX32
" at pos. 0x%"PRIx64
" has " 1360 "unknown length, yet the length of an element of its " 1361 "type must be known.\n",
id, pos);
1364 "Found unknown-length element with ID 0x%"PRIX32
" at " 1365 "pos. 0x%"PRIx64
" for which no syntax for parsing is " 1366 "available.\n",
id, pos);
1403 "Unknown element %"PRIX32
" at pos. 0x%"PRIx64
" with " 1404 "length 0x%"PRIx64
" considered as invalid data. Last " 1405 "known good position 0x%"PRIx64
", %d unknown elements" 1406 " in a row\n",
id, pos, length, matroska->
resync_pos,
1413 if (update_pos > 0) {
1424 switch (syntax->
type) {
1451 if (!level1_elem->
pos) {
1454 }
else if (level1_elem->
pos != pos)
1472 if ((res2 =
avio_skip(pb, length - 1)) >= 0) {
1511 if (elem->
count != UINT_MAX)
1533 for (i = 0; syntax[
i].
id; i++) {
1534 void *data_off = (
char *) data + syntax[i].data_offset;
1535 switch (syntax[i].
type) {
1545 if (syntax[i].list_elem_size) {
1547 char *ptr = list->
elem;
1548 for (j = 0; j < list->
nb_elem;
1568 int len_mask = 0x80,
size = 1, n = 1,
i;
1576 while (
size <= 8 && !(total & len_mask)) {
1582 total &= (len_mask - 1);
1584 total = (total << 8) | p->
buf[4 + n++];
1586 if (total + 1 == 1ULL << (7 *
size)){
1601 if (total < probelen)
1603 for (n = 4 +
size; n <= 4 +
size + total - probelen; n++)
1619 if (tracks[i].num == num)
1631 int isize = *buf_size;
1634 int pkt_size = isize;
1638 if (pkt_size >= 10000000
U)
1641 switch (encodings[0].compression.algo) {
1647 if (header_size && !header) {
1655 pkt_size = isize + header_size;
1660 memcpy(pkt_data, header, header_size);
1661 memcpy(pkt_data + header_size, data, isize);
1668 olen = pkt_size *= 3;
1675 pkt_data = newpktdata;
1688 z_stream zstream = { 0 };
1689 if (inflateInit(&zstream) != Z_OK)
1691 zstream.next_in =
data;
1692 zstream.avail_in = isize;
1697 inflateEnd(&zstream);
1701 pkt_data = newpktdata;
1702 zstream.avail_out = pkt_size - zstream.total_out;
1703 zstream.next_out = pkt_data + zstream.total_out;
1704 result =
inflate(&zstream, Z_NO_FLUSH);
1705 }
while (result == Z_OK && pkt_size < 10000000);
1706 pkt_size = zstream.total_out;
1707 inflateEnd(&zstream);
1708 if (result != Z_STREAM_END) {
1709 if (result == Z_MEM_ERROR)
1721 bz_stream bzstream = { 0 };
1722 if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
1724 bzstream.next_in =
data;
1725 bzstream.avail_in = isize;
1730 BZ2_bzDecompressEnd(&bzstream);
1734 pkt_data = newpktdata;
1735 bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
1736 bzstream.next_out = pkt_data + bzstream.total_out_lo32;
1737 result = BZ2_bzDecompress(&bzstream);
1738 }
while (result == BZ_OK && pkt_size < 10000000);
1739 pkt_size = bzstream.total_out_lo32;
1740 BZ2_bzDecompressEnd(&bzstream);
1741 if (result != BZ_STREAM_END) {
1742 if (result == BZ_MEM_ERROR)
1758 *buf_size = pkt_size;
1773 for (i = 0; i < list->
nb_elem; i++) {
1774 const char *lang = tags[
i].
lang &&
1775 strcmp(tags[i].lang,
"und") ? tags[
i].
lang :
NULL;
1777 if (!tags[i].
name) {
1782 snprintf(key,
sizeof(key),
"%s/%s", prefix, tags[i].name);
1785 if (tags[i].def || !lang) {
1787 if (tags[i].
sub.nb_elem)
1794 if (tags[i].
sub.nb_elem)
1808 if (tags[i].target.attachuid) {
1812 if (attachment[j].
uid == tags[i].target.attachuid &&
1815 &attachment[j].stream->metadata,
NULL);
1821 "The tags at index %d refer to a " 1822 "non-existent attachment %"PRId64
".\n",
1823 i, tags[i].target.attachuid);
1825 }
else if (tags[i].target.chapteruid) {
1829 if (chapter[j].
uid == tags[i].target.chapteruid &&
1832 &chapter[j].chapter->metadata,
NULL);
1838 "The tags at index %d refer to a non-existent chapter " 1840 i, tags[i].target.chapteruid);
1842 }
else if (tags[i].target.trackuid) {
1846 if (track[j].
uid == tags[i].target.trackuid &&
1849 &track[j].stream->metadata,
NULL);
1855 "The tags at index %d refer to a non-existent track " 1857 i, tags[i].target.trackuid);
1879 "Max EBML element depth (%d) reached, " 1887 ret =
ebml_parse(matroska, matroska_segment, matroska);
1910 for (i = 0; i < seekhead_list->
nb_elem; i++) {
1912 uint32_t
id = seekheads[
i].
id;
1920 if (!elem || elem->
parsed)
1943 uint64_t index_scale = 1;
1949 index_list = &matroska->
index;
1950 index = index_list->
elem;
1953 if (index[1].time > 1E14 / matroska->
time_scale) {
1957 for (i = 0; i < index_list->
nb_elem; i++) {
1960 for (j = 0; j < pos_list->
nb_elem; j++) {
1963 if (track && track->stream)
1966 index[i].
time / index_scale, 0, 0,
1993 static const char *
const aac_profiles[] = {
"MAIN",
"LC",
"SSR" };
1996 for (profile = 0; profile <
FF_ARRAY_ELEMS(aac_profiles); profile++)
1997 if (strstr(codec_id, aac_profiles[profile]))
2039 int block_last, block_type, block_size;
2045 if (block_size > size)
2054 chmask =
av_dict_get(dict,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK",
NULL, 0);
2057 if (!mask || mask & ~0x3ffffULL) {
2059 "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
2075 int minor, micro, bttb = 0;
2079 if (matroska->
muxingapp && sscanf(matroska->
muxingapp,
"Lavf57.%d.%d", &minor, µ) == 2)
2080 bttb = (minor >= 36 && minor <= 51 && micro >= 100);
2082 switch (field_order) {
2101 int *h_width,
int *h_height)
2103 switch (stereo_mode) {
2128 int has_mastering_primaries, has_mastering_luminance;
2135 has_mastering_primaries =
2136 mastering_meta->
r_x > 0 && mastering_meta->
r_y > 0 &&
2137 mastering_meta->
g_x > 0 && mastering_meta->
g_y > 0 &&
2138 mastering_meta->
b_x > 0 && mastering_meta->
b_y > 0 &&
2180 if (has_mastering_primaries || has_mastering_luminance) {
2189 if (has_mastering_primaries) {
2200 if (has_mastering_luminance) {
2216 size_t spherical_size;
2217 uint32_t l = 0, t = 0,
r = 0,
b = 0;
2218 uint32_t padding = 0;
2221 if (mkv_projection->
private.
size && priv_data[0] != 0) {
2234 if (
b >= UINT_MAX - t ||
r >= UINT_MAX - l) {
2236 "Invalid bounding rectangle coordinates " 2237 "%"PRIu32
",%"PRIu32
",%"PRIu32
",%"PRIu32
"\n",
2246 if (l || t ||
r ||
b)
2259 "Unknown spherical cubemap layout %"PRIu32
"\n", layout);
2263 padding =
AV_RB32(priv_data + 8);
2274 "Unknown spherical metadata type %"PRIu64
"\n",
2348 int extradata_size = 0;
2349 int extradata_offset = 0;
2352 char* key_id_base64 =
NULL;
2361 "Unknown or unsupported track type %"PRIu64
"\n",
2380 "Invalid sample rate %f, defaulting to 8000 instead.\n",
2388 if (default_duration > UINT64_MAX || default_duration < 0) {
2390 "Invalid frame rate %e. Cannot calculate default duration.\n",
2406 if (encodings_list->
nb_elem > 1) {
2408 "Multiple combined encodings not supported");
2409 }
else if (encodings_list->
nb_elem == 1) {
2410 if (encodings[0].
type) {
2411 if (encodings[0].encryption.key_id.size > 0) {
2414 const int b64_size =
AV_BASE64_SIZE(encodings[0].encryption.key_id.size);
2416 if (key_id_base64 ==
NULL)
2420 encodings[0].encryption.key_id.data,
2423 encodings[0].
scope = 0;
2425 "Unsupported encoding type");
2438 encodings[0].
scope = 0;
2440 "Unsupported encoding type");
2450 "Failed to decode codec private data\n");
2469 encodings[0].
scope & 1 &&
2487 if (key_id_base64) {
2493 if (!strcmp(track->
codec_id,
"V_MS/VFW/FOURCC") &&
2504 extradata_offset = 40;
2505 }
else if (!strcmp(track->
codec_id,
"A_MS/ACM") &&
2518 }
else if (!strcmp(track->
codec_id,
"A_QUICKTIME")
2522 uint16_t sample_size;
2528 if (sample_size == 8) {
2529 fourcc =
MKTAG(
'r',
'a',
'w',
' ');
2531 }
else if (sample_size == 16) {
2532 fourcc =
MKTAG(
't',
'w',
'o',
's');
2536 if ((fourcc ==
MKTAG(
't',
'w',
'o',
's') ||
2537 fourcc ==
MKTAG(
's',
'o',
'w',
't')) &&
2540 }
else if (!strcmp(track->
codec_id,
"V_QUICKTIME") &&
2547 fourcc =
MKTAG(
'S',
'V',
'Q',
'3');
2596 extradata[0] = (profile << 3) | ((sri & 0x0E) >> 1);
2597 extradata[1] = ((sri & 0x01) << 7) | (track->
audio.
channels << 3);
2598 if (strstr(track->
codec_id,
"SBR")) {
2600 extradata[2] = 0x56;
2601 extradata[3] = 0xE5;
2602 extradata[4] = 0x80 | (sri << 3);
2615 AV_WB32(extradata, extradata_size);
2616 memcpy(&extradata[4],
"alac", 4);
2625 "Too large audio channel number %"PRIu64
2626 " or bitdepth %"PRIu64
". Skipping track.\n",
2635 extradata_size = 22;
2640 bytestream_put_be32(&ptr,
AV_RB32(
"TTA1"));
2641 bytestream_put_le16(&ptr, 1);
2652 extradata_offset = 26;
2686 static const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 };
2695 extradata_offset = 78;
2707 "in absence of valid CodecPrivate.\n");
2722 extradata_offset = 4;
2728 "Unknown/unsupported AVCodecID %s.\n", track->
codec_id);
2732 "Track TimestampScale too small %f, assuming 1.0.\n",
2737 1000 * 1000 * 1000);
2746 if (strcmp(track->
language,
"und"))
2779 int display_width_mul = 1;
2780 int display_height_mul = 1;
2810 #if FF_API_R_FRAME_RATE 2830 snprintf(buf,
sizeof(buf),
"%s_%d",
2833 if (planes[j].
uid == tracks[k].
uid && tracks[k].stream) {
2835 "stereo_mode", buf, 0);
2869 (
AVRational){1, st->codecpar->codec_id == AV_CODEC_ID_OPUS ?
2870 48000 : st->codecpar->sample_rate});
2880 if (!strcmp(track->
codec_id,
"D_WEBVTT/CAPTIONS")) {
2882 }
else if (!strcmp(track->
codec_id,
"D_WEBVTT/DESCRIPTIONS")) {
2884 }
else if (!strcmp(track->
codec_id,
"D_WEBVTT/METADATA")) {
2905 uint64_t max_start = 0;
2920 ebml.
max_size >
sizeof(uint64_t) ||
2924 "EBML version %"PRIu64
", doctype %s, doc version %"PRIu64,
2930 "EBML header using unsupported features\n" 2931 "(EBML version %"PRIu64
", doctype %s, doc version %"PRIu64
")\n",
2948 res =
ebml_parse(matroska, matroska_segments, matroska);
2955 res =
ebml_parse(matroska, matroska_segment, matroska);
2977 attachments = attachments_list->
elem;
2978 for (j = 0; j < attachments_list->
nb_elem; j++) {
2979 if (!(attachments[j].filename && attachments[j].mime &&
2980 attachments[j].bin.data && attachments[j].
bin.
size > 0)) {
2999 attachments[j].
stream = st;
3031 chapters = chapters_list->
elem;
3032 for (i = 0; i < chapters_list->
nb_elem; i++)
3034 (max_start == 0 || chapters[i].start > max_start)) {
3040 max_start = chapters[
i].
start;
3060 if (matroska->
queue) {
3091 uint32_t lace_size[256],
int *laces)
3098 lace_size[0] =
size;
3114 for (n = 0; n < *laces - 1; n++) {
3122 lace_size[n] +=
temp;
3125 }
while (temp == 0xff);
3130 lace_size[n] = size - total;
3135 if (size % (*laces))
3137 for (n = 0; n < *laces; n++)
3138 lace_size[n] = size / *laces;
3155 total = lace_size[0] = num;
3157 for (n = 1; n < *laces - 1; n++) {
3163 if (lace_size[n - 1] + snum > (uint64_t)INT_MAX)
3166 lace_size[n] = lace_size[n - 1] + snum;
3167 total += lace_size[n];
3175 lace_size[*laces - 1] = size - total;
3202 if (size < cfs * h / 2) {
3204 "Corrupt int4 RM-style audio packet size\n");
3207 for (x = 0; x < h / 2; x++)
3208 memcpy(track->
audio.
buf + x * 2 * w + y * cfs,
3209 data + x * cfs, cfs);
3213 "Corrupt sipr RM-style audio packet size\n");
3216 memcpy(track->
audio.
buf + y * w, data, w);
3220 "Corrupt generic RM-style audio packet size\n");
3223 for (x = 0; x < w /
sps; x++)
3225 sps * (h * x + ((h + 1) / 2) * (y & 1) + (y >> 1)),
3226 data + x * sps, sps);
3284 while (srclen >= 8) {
3290 uint32_t crc =
AV_RL32(src + 4);
3294 multiblock = (flags & 0x1800) != 0x1800;
3306 if (blocksize > srclen) {
3317 dstlen += blocksize + 32;
3320 AV_WL32(dst + offset + 4, blocksize + 24);
3321 AV_WL16(dst + offset + 8, ver);
3322 AV_WL16(dst + offset + 10, 0);
3323 AV_WL32(dst + offset + 12, 0);
3324 AV_WL32(dst + offset + 16, 0);
3325 AV_WL32(dst + offset + 20, samples);
3326 AV_WL32(dst + offset + 24, flags);
3327 AV_WL32(dst + offset + 28, crc);
3328 memcpy(dst + offset + 32, src, blocksize);
3331 srclen -= blocksize;
3332 offset += blocksize + 32;
3351 int dstlen = *size + 8;
3359 memcpy(dst + 8, *data, dstlen - 8);
3378 int id_len, settings_len, text_len;
3386 q = data + data_len;
3391 if (*p ==
'\r' || *p ==
'\n') {
3400 if (p >= q || *p !=
'\n')
3407 if (*p ==
'\r' || *p ==
'\n') {
3408 settings_len = p - settings;
3416 if (p >= q || *p !=
'\n')
3422 while (text_len > 0) {
3423 const int len = text_len - 1;
3425 if (c !=
'\r' && c !=
'\n')
3438 memcpy(pkt->
data, text, text_len);
3448 memcpy(buf,
id, id_len);
3451 if (settings_len > 0) {
3459 memcpy(buf, settings, settings_len);
3466 pkt->
pts = timecode;
3486 uint64_t timecode, uint64_t lace_duration,
3488 uint8_t *additional, uint64_t additional_id,
int additional_size,
3489 int64_t discard_padding)
3499 "Error parsing a wavpack block.\n");
3512 "Error parsing a prores block.\n");
3520 if (!pkt_size && !additional_size)
3535 pkt->
data = pkt_data;
3536 pkt->
size = pkt_size;
3540 if (additional_size > 0) {
3543 additional_size + 8);
3548 AV_WB64(side_data, additional_id);
3549 memcpy(side_data + 8, additional, additional_size);
3552 if (discard_padding) {
3563 if (discard_padding > 0) {
3564 AV_WL32(side_data + 4, discard_padding);
3566 AV_WL32(side_data, -discard_padding);
3571 pkt->
dts = timecode;
3573 pkt->
pts = timecode;
3577 #if FF_API_CONVERGENCE_DURATION 3580 pkt->convergence_duration = lace_duration;
3601 int size, int64_t
pos, uint64_t cluster_time,
3603 uint8_t *additional, uint64_t additional_id,
int additional_size,
3604 int64_t cluster_pos, int64_t discard_padding)
3612 uint32_t lace_size[256];
3613 int n,
flags, laces = 0;
3615 int trust_default_duration;
3625 if (!track || size < 3)
3628 if (!(st = track->
stream)) {
3630 "No stream associated to TrackNumber %"PRIu64
". " 3631 "Ignoring Block with this TrackNumber.\n", num);
3637 if (block_duration > INT64_MAX)
3638 block_duration = INT64_MAX;
3644 if (is_keyframe == -1)
3647 if (cluster_time != (uint64_t) -1 &&
3648 (block_time >= 0 || cluster_time >= -block_time)) {
3649 uint64_t timecode_cluster_in_track_tb = (double) cluster_time / track->
time_scale;
3652 timecode < track->end_timecode)
3677 &pb, lace_size, &laces);
3688 trust_default_duration = 0;
3692 if (!block_duration && trust_default_duration)
3695 if (cluster_time != (uint64_t)-1 && (block_time >= 0 || cluster_time >= -block_time))
3699 for (n = 0; n < laces; n++) {
3700 int64_t lace_duration = block_duration*(n+1) / laces - block_duration*n / laces;
3726 timecode, lace_duration,
3734 out_size, timecode, lace_duration,
3735 pos, !n ? is_keyframe : 0,
3736 additional, additional_id, additional_size,
3743 timecode = lace_duration ? timecode + lace_duration :
AV_NOPTS_VALUE;
3744 data += lace_size[n];
3765 res =
ebml_parse(matroska, matroska_cluster_enter, cluster);
3773 res =
ebml_parse(matroska, matroska_cluster_parsing, cluster);
3775 if (res >= 0 && block->
bin.
size > 0) {
3789 memset(block, 0,
sizeof(*block));
3795 "end of segment.\n");
3827 int64_t timestamp,
int flags)
3924 for (i = 1; i < nb_index_entries; i++) {
3925 if (index_entries[i - 1].timestamp * matroska->
time_scale <= ts &&
3933 if (i != nb_index_entries - 1) {
3950 int64_t cluster_pos, before_pos;
3955 if (index < 0)
return 0;
3959 uint64_t cluster_id, cluster_length;
3965 if (read < 0 || cluster_id != 0xF43B675)
3979 cluster_pos += 4 + read + cluster_length;
3993 double min_buffer,
double*
buffer,
3997 double nano_seconds_per_second = 1000000000.0;
3998 double time_sec = time_ns / nano_seconds_per_second;
4000 int64_t time_to_search_ns = (int64_t)(search_sec * nano_seconds_per_second);
4001 int64_t end_time_ns = time_ns + time_to_search_ns;
4002 double sec_downloaded = 0.0;
4006 *sec_to_download = 0.0;
4010 int64_t cue_nano = desc_curr.
end_time_ns - time_ns;
4013 double timeToDownload = (cueBytes * 8.0) /
bps;
4015 sec_downloaded += (cue_nano / nano_seconds_per_second) - timeToDownload;
4016 *sec_to_download += timeToDownload;
4020 double desc_end_time_sec = desc_curr.
end_time_ns / nano_seconds_per_second;
4021 double percent_to_sub = search_sec / (desc_end_time_sec - time_sec);
4022 sec_downloaded = percent_to_sub * sec_downloaded;
4023 *sec_to_download = percent_to_sub * *sec_to_download;
4026 if ((sec_downloaded + *buffer) <= min_buffer) {
4037 double desc_sec = desc_ns / nano_seconds_per_second;
4038 double bits = (desc_bytes * 8.0);
4039 double time_to_download = bits /
bps;
4041 sec_downloaded += desc_sec - time_to_download;
4042 *sec_to_download += time_to_download;
4045 double desc_end_time_sec = desc_curr.
end_time_ns / nano_seconds_per_second;
4046 double percent_to_sub = search_sec / (desc_end_time_sec - time_sec);
4047 sec_downloaded = percent_to_sub * sec_downloaded;
4048 *sec_to_download = percent_to_sub * *sec_to_download;
4050 if ((sec_downloaded + *buffer) <= min_buffer)
4055 if ((sec_downloaded + *buffer) <= min_buffer) {
4062 *buffer = *buffer + sec_downloaded;
4077 double bandwidth = 0.0;
4081 int64_t prebuffer_ns = 1000000000;
4083 double nano_seconds_per_second = 1000000000.0;
4084 int64_t prebuffered_ns = time_ns + prebuffer_ns;
4085 double prebuffer_bytes = 0.0;
4086 int64_t temp_prebuffer_ns = prebuffer_ns;
4087 int64_t pre_bytes, pre_ns;
4088 double pre_sec, prebuffer, bits_per_second;
4106 bits_per_second = 0.0;
4112 pre_sec = pre_ns / nano_seconds_per_second;
4114 pre_bytes * ((temp_prebuffer_ns / nano_seconds_per_second) / pre_sec);
4116 prebuffer = prebuffer_ns / nano_seconds_per_second;
4119 bits_per_second = 0.0;
4123 double desc_sec = desc_ns / nano_seconds_per_second;
4124 double calc_bits_per_second = (desc_bytes * 8) / desc_sec;
4127 double percent = (desc_bytes - prebuffer_bytes) / desc_bytes;
4128 double mod_bits_per_second = calc_bits_per_second * percent;
4130 if (prebuffer < desc_sec) {
4136 int64_t
bps = (int64_t)(mod_bits_per_second) + 1;
4137 const double min_buffer = 0.0;
4138 double buffer = prebuffer;
4139 double sec_to_download = 0.0;
4142 min_buffer, &buffer, &sec_to_download,
4146 }
else if (rv == 0) {
4147 bits_per_second = (double)(bps);
4155 if (bandwidth < bits_per_second) bandwidth = bits_per_second;
4157 return (int64_t)bandwidth;
4166 int64_t cues_start = -1, cues_end = -1, before_pos, bandwidth;
4171 for (i = 0; i < seekhead_list->
nb_elem; i++)
4175 if (i >= seekhead_list->
nb_elem)
return -1;
4179 if (
avio_seek(matroska->
ctx->
pb, cues_start, SEEK_SET) == cues_start) {
4183 uint64_t cues_length, cues_id;
4191 cues_end = cues_start + 4 + bytes_read + cues_length - 1;
4194 if (cues_start == -1 || cues_end == -1)
return -1;
4207 if (cues_start <= init_range)
4212 if (bandwidth < 0)
return -1;
4221 if (!buf)
return -1;
4273 buf = strrchr(s->
url,
'/');
4305 #define OFFSET(x) offsetof(MatroskaDemuxContext, x) 4320 .
name =
"matroska,webm",
4322 .extensions =
"mkv,mk3d,mka,mks,webm",
4329 .mime_type =
"audio/webm,audio/x-matroska,video/webm,video/x-matroska" 4333 .
name =
"webm_dash_manifest",
4339 .priv_class = &webm_dash_class,
int32_t pitch
Rotation around the right vector [-90, 90].
#define MATROSKA_ID_SEEKPREROLL
#define MATROSKA_ID_VIDEOPROJECTIONPOSEYAW
AVSphericalMapping * av_spherical_alloc(size_t *size)
Allocate a AVSphericalVideo structure and initialize its fields to default values.
uint64_t codec_delay_in_track_tb
enum AVChromaLocation chroma_location
static EbmlSyntax matroska_simpletag[]
#define MATROSKA_ID_BLOCKADDID
#define MATROSKA_ID_TRACKDEFAULTDURATION
enum AVFieldOrder field_order
Video only.
static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, MatroskaTrack *track, AVStream *st, uint8_t *data, int size, uint64_t timecode, int64_t pos)
enum AVColorTransferCharacteristic color_trc
#define MATROSKA_ID_VIDEOFLAGINTERLACED
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MATROSKA_ID_VIDEOCOLOR_GX
const char *const ff_matroska_video_stereo_plane[MATROSKA_VIDEO_STEREO_PLANE_COUNT]
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...
The optional first identifier line of a WebVTT cue.
unsigned MaxCLL
Max content light level (cd/m^2).
#define MATROSKA_ID_TRACKFLAGLACING
static int webm_dash_manifest_read_packet(AVFormatContext *s, AVPacket *pkt)
#define MATROSKA_ID_TRACKENTRY
static int matroska_deliver_packet(MatroskaDemuxContext *matroska, AVPacket *pkt)
static const CodecMime mkv_image_mime_tags[]
#define MATROSKA_ID_VIDEODISPLAYHEIGHT
static EbmlSyntax matroska_blockmore[]
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
AVInputFormat ff_matroska_demuxer
ptrdiff_t const GLvoid * data
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_VIDEOPROJECTIONPOSEROLL
#define MATROSKA_ID_CUETRACKPOSITION
#define MATROSKA_ID_CODECPRIVATE
#define MATROSKA_ID_TRACKFLAGVISUALIMPAIRED
const unsigned char ff_sipr_subpk_size[4]
#define MATROSKA_ID_TAGTARGETS_TYPE
#define AV_LOG_WARNING
Something somehow does not look correct.
static EbmlSyntax matroska_track_video[19]
#define LIBAVUTIL_VERSION_INT
#define INITIALIZATION_RANGE
unsigned char * buf_ptr
Current position in the buffer.
int64_t pos
byte position in stream, -1 if unknown
static int webm_clusters_start_with_keyframe(AVFormatContext *s)
#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 int segment_start(AVFormatContext *s, int write_header)
static EbmlSyntax matroska_segments[]
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
MatroskaCluster current_cluster
Video represents a portion of a sphere mapped on a flat surface using equirectangular projection...
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
#define MATROSKA_ID_TAGTARGETS_ATTACHUID
int index
stream index in AVFormatContext
static EbmlSyntax matroska_track_video_projection[]
#define MATROSKA_ID_CLUSTERPOSITION
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define MATROSKA_ID_FILEDATA
const char * av_default_item_name(void *ptr)
Return the context name.
MatroskaTrackVideoProjection projection
AVFormatInternal * internal
An opaque field for libavformat internal usage.
#define EBML_ID_DOCTYPEREADVERSION
#define MATROSKA_ID_BLOCKREFERENCE
#define MATROSKA_ID_TRACKTYPE
unsigned char * buffer
Start of the buffer.
#define MATROSKA_ID_TAGTARGETS_CHAPTERUID
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#define MATROSKA_ID_VIDEOCOLOR_RX
Video represents a sphere mapped on a flat surface using equirectangular projection.
#define MATROSKA_ID_VIDEOASPECTRATIO
uint64_t chroma_siting_vert
#define MATROSKA_ID_MUXINGAPP
#define MATROSKA_ID_AUDIOCHANNELS
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
#define FF_ARRAY_ELEMS(a)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...