72 #define EBML_UNKNOWN_LENGTH UINT64_MAX 73 #define NEEDS_CHECKING 2 77 #define SKIP_THRESHOLD 1024 * 1024 80 #define UNKNOWN_EQUIV 50 * 1024 409 #define CHILD_OF(parent) { .def = { .n = parent } } 461 CHILD_OF(matroska_track_video_color)
464 static EbmlSyntax matroska_track_video_color[] = {
537 static EbmlSyntax matroska_track_encoding[] = {
546 static EbmlSyntax matroska_track_encodings[] = {
554 CHILD_OF(matroska_track_combine_planes)
557 static EbmlSyntax matroska_track_combine_planes[] = {
562 static EbmlSyntax matroska_track_operation[] = {
627 static EbmlSyntax matroska_chapter_entry[] = {
737 static EbmlSyntax matroska_blockadditions[] = {
755 static EbmlSyntax matroska_cluster_parsing[] = {
799 uint32_t
id, int64_t position)
826 "Seek to desired resync point failed. Seeking to " 827 "earliest point available instead.\n");
829 last_pos + 1), SEEK_SET);
865 int max_size, uint64_t *number,
int eof_forbidden)
879 if (!total || read > max_size) {
883 "0x00 at pos %"PRId64
" (0x%"PRIx64
") invalid as first byte " 884 "of an EBML number\n", pos, pos);
887 "Length %d indicated by an EBML number's first byte 0x%02x " 888 "at pos %"PRId64
" (0x%"PRIx64
") exceeds max length %d.\n",
889 read, (
uint8_t) total, pos, pos, max_size);
897 total = (total << 8) |
avio_r8(pb);
912 "Read error at pos. %"PRIu64
" (0x%"PRIx64
")\n",
918 "at pos. %"PRIu64
" (0x%"PRIx64
")\n", pos, pos);
933 if (res > 0 && *number + 1 == 1ULL << (7 * res))
943 uint64_t default_value, uint64_t *num)
948 *num = default_value;
954 *num = (*num << 8) |
avio_r8(pb);
964 int64_t default_value, int64_t *num)
969 *num = default_value;
976 *num = ((uint64_t)*num << 8) |
avio_r8(pb);
987 double default_value,
double *num)
990 *num = default_value;
992 }
else if (size == 4) {
994 }
else if (size == 8) {
1007 const char *default_value,
char **
str)
1012 if (size == 0 && default_value) {
1098 *num = unum - ((1LL << (7 * res - 1)) - 1);
1112 for (i = 0; syntax[
i].
id; i++)
1113 if (
id == syntax[i].
id)
1125 for (
int i = 0; syntax[
i].
id;
i++) {
1126 void *dst = (
char *)data + syntax[
i].data_offset;
1127 switch (syntax[
i].
type) {
1129 *(uint64_t *)dst = syntax[
i].def.
u;
1132 *(int64_t *) dst = syntax[
i].
def.
i;
1135 *(
double *) dst = syntax[
i].def.
f;
1140 if (syntax[
i].def.
s) {
1168 return id && (bits + 7) / 8 == (8 - bits % 8);
1176 uint32_t
id, int64_t
pos)
1248 "at pos. %"PRIu64
" (0x%"PRIx64
")\n", pos, pos);
1255 pos_alt = pos + res;
1268 while (syntax->
def.
n) {
1278 "%"PRId64
"\n",
id, pos);
1295 list->
elem = newelem;
1312 uint64_t elem_end = pos_alt +
length,
1315 if (elem_end < level_end) {
1317 }
else if (elem_end == level_end) {
1321 "Element at 0x%"PRIx64
" ending at 0x%"PRIx64
" exceeds " 1322 "containing master element ending at 0x%"PRIx64
"\n",
1323 pos, elem_end, level_end);
1330 "at 0x%"PRIx64
" inside parent with finite size\n", pos);
1340 "Found unknown-length element 0x%"PRIX32
" other than " 1341 "a cluster at 0x%"PRIx64
". Spec-incompliant, but " 1342 "parsing will nevertheless be attempted.\n",
id, pos);
1349 if (max_lengths[syntax->
type] && length > max_lengths[syntax->
type]) {
1352 "Invalid length 0x%"PRIx64
" > 0x%"PRIx64
" for element " 1353 "with ID 0x%"PRIX32
" at 0x%"PRIx64
"\n",
1354 length, max_lengths[syntax->
type],
id, pos);
1357 "Element with ID 0x%"PRIX32
" at pos. 0x%"PRIx64
" has " 1358 "unknown length, yet the length of an element of its " 1359 "type must be known.\n",
id, pos);
1362 "Found unknown-length element with ID 0x%"PRIX32
" at " 1363 "pos. 0x%"PRIx64
" for which no syntax for parsing is " 1364 "available.\n",
id, pos);
1401 "Unknown element %"PRIX32
" at pos. 0x%"PRIx64
" with " 1402 "length 0x%"PRIx64
" considered as invalid data. Last " 1403 "known good position 0x%"PRIx64
", %d unknown elements" 1404 " in a row\n",
id, pos, length, matroska->
resync_pos,
1411 if (update_pos > 0) {
1422 switch (syntax->
type) {
1449 if (!level1_elem->
pos) {
1452 }
else if (level1_elem->
pos != pos)
1470 if ((res2 =
avio_skip(pb, length - 1)) >= 0) {
1509 if (elem->
count != UINT_MAX)
1531 for (i = 0; syntax[
i].
id; i++) {
1532 void *data_off = (
char *) data + syntax[i].data_offset;
1533 switch (syntax[i].
type) {
1543 if (syntax[i].list_elem_size) {
1545 char *ptr = list->
elem;
1546 for (j = 0; j < list->
nb_elem;
1566 int len_mask = 0x80,
size = 1, n = 1,
i;
1574 while (
size <= 8 && !(total & len_mask)) {
1580 total &= (len_mask - 1);
1582 total = (total << 8) | p->
buf[4 + n++];
1584 if (total + 1 == 1ULL << (7 *
size)){
1599 if (total < probelen)
1601 for (n = 4 +
size; n <= 4 +
size + total - probelen; n++)
1617 if (tracks[i].num == num)
1629 int isize = *buf_size;
1632 int pkt_size = isize;
1636 if (pkt_size >= 10000000
U)
1639 switch (encodings[0].compression.algo) {
1645 if (header_size && !header) {
1653 pkt_size = isize + header_size;
1658 memcpy(pkt_data, header, header_size);
1659 memcpy(pkt_data + header_size, data, isize);
1666 olen = pkt_size *= 3;
1673 pkt_data = newpktdata;
1686 z_stream zstream = { 0 };
1687 if (inflateInit(&zstream) != Z_OK)
1689 zstream.next_in =
data;
1690 zstream.avail_in = isize;
1695 inflateEnd(&zstream);
1699 pkt_data = newpktdata;
1700 zstream.avail_out = pkt_size - zstream.total_out;
1701 zstream.next_out = pkt_data + zstream.total_out;
1702 result =
inflate(&zstream, Z_NO_FLUSH);
1703 }
while (result == Z_OK && pkt_size < 10000000);
1704 pkt_size = zstream.total_out;
1705 inflateEnd(&zstream);
1706 if (result != Z_STREAM_END) {
1707 if (result == Z_MEM_ERROR)
1719 bz_stream bzstream = { 0 };
1720 if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
1722 bzstream.next_in =
data;
1723 bzstream.avail_in = isize;
1728 BZ2_bzDecompressEnd(&bzstream);
1732 pkt_data = newpktdata;
1733 bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
1734 bzstream.next_out = pkt_data + bzstream.total_out_lo32;
1735 result = BZ2_bzDecompress(&bzstream);
1736 }
while (result == BZ_OK && pkt_size < 10000000);
1737 pkt_size = bzstream.total_out_lo32;
1738 BZ2_bzDecompressEnd(&bzstream);
1739 if (result != BZ_STREAM_END) {
1740 if (result == BZ_MEM_ERROR)
1756 *buf_size = pkt_size;
1771 for (i = 0; i < list->
nb_elem; i++) {
1772 const char *lang = tags[
i].
lang &&
1773 strcmp(tags[i].lang,
"und") ? tags[
i].
lang :
NULL;
1775 if (!tags[i].
name) {
1780 snprintf(key,
sizeof(key),
"%s/%s", prefix, tags[i].name);
1783 if (tags[i].def || !lang) {
1785 if (tags[i].
sub.nb_elem)
1792 if (tags[i].
sub.nb_elem)
1806 if (tags[i].target.attachuid) {
1810 if (attachment[j].
uid == tags[i].target.attachuid &&
1813 &attachment[j].stream->metadata,
NULL);
1819 "The tags at index %d refer to a " 1820 "non-existent attachment %"PRId64
".\n",
1821 i, tags[i].target.attachuid);
1823 }
else if (tags[i].target.chapteruid) {
1827 if (chapter[j].
uid == tags[i].target.chapteruid &&
1830 &chapter[j].chapter->metadata,
NULL);
1836 "The tags at index %d refer to a non-existent chapter " 1838 i, tags[i].target.chapteruid);
1840 }
else if (tags[i].target.trackuid) {
1844 if (track[j].
uid == tags[i].target.trackuid &&
1847 &track[j].stream->metadata,
NULL);
1853 "The tags at index %d refer to a non-existent track " 1855 i, tags[i].target.trackuid);
1877 "Max EBML element depth (%d) reached, " 1885 ret =
ebml_parse(matroska, matroska_segment, matroska);
1908 for (i = 0; i < seekhead_list->
nb_elem; i++) {
1910 uint32_t
id = seekheads[
i].
id;
1918 if (!elem || elem->
parsed)
1941 uint64_t index_scale = 1;
1947 index_list = &matroska->
index;
1948 index = index_list->
elem;
1951 if (index[1].time > 1E14 / matroska->
time_scale) {
1955 for (i = 0; i < index_list->
nb_elem; i++) {
1958 for (j = 0; j < pos_list->
nb_elem; j++) {
1961 if (track && track->stream)
1964 index[i].
time / index_scale, 0, 0,
1991 static const char *
const aac_profiles[] = {
"MAIN",
"LC",
"SSR" };
1994 for (profile = 0; profile <
FF_ARRAY_ELEMS(aac_profiles); profile++)
1995 if (strstr(codec_id, aac_profiles[profile]))
2037 int block_last, block_type, block_size;
2043 if (block_size > size)
2052 chmask =
av_dict_get(dict,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK",
NULL, 0);
2055 if (!mask || mask & ~0x3ffffULL) {
2057 "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
2073 int minor, micro, bttb = 0;
2077 if (matroska->
muxingapp && sscanf(matroska->
muxingapp,
"Lavf57.%d.%d", &minor, µ) == 2)
2078 bttb = (minor >= 36 && minor <= 51 && micro >= 100);
2080 switch (field_order) {
2099 int *h_width,
int *h_height)
2101 switch (stereo_mode) {
2126 int has_mastering_primaries, has_mastering_luminance;
2133 has_mastering_primaries =
2134 mastering_meta->
r_x > 0 && mastering_meta->
r_y > 0 &&
2135 mastering_meta->
g_x > 0 && mastering_meta->
g_y > 0 &&
2136 mastering_meta->
b_x > 0 && mastering_meta->
b_y > 0 &&
2178 if (has_mastering_primaries || has_mastering_luminance) {
2187 if (has_mastering_primaries) {
2198 if (has_mastering_luminance) {
2214 size_t spherical_size;
2215 uint32_t l = 0, t = 0,
r = 0,
b = 0;
2216 uint32_t padding = 0;
2219 if (mkv_projection->
private.
size && priv_data[0] != 0) {
2232 if (
b >= UINT_MAX - t ||
r >= UINT_MAX - l) {
2234 "Invalid bounding rectangle coordinates " 2235 "%"PRIu32
",%"PRIu32
",%"PRIu32
",%"PRIu32
"\n",
2244 if (l || t ||
r ||
b)
2257 "Unknown spherical cubemap layout %"PRIu32
"\n", layout);
2261 padding =
AV_RB32(priv_data + 8);
2272 "Unknown spherical metadata type %"PRIu64
"\n",
2346 int extradata_size = 0;
2347 int extradata_offset = 0;
2350 char* key_id_base64 =
NULL;
2359 "Unknown or unsupported track type %"PRIu64
"\n",
2378 "Invalid sample rate %f, defaulting to 8000 instead.\n",
2386 if (default_duration > UINT64_MAX || default_duration < 0) {
2388 "Invalid frame rate %e. Cannot calculate default duration.\n",
2404 if (encodings_list->
nb_elem > 1) {
2406 "Multiple combined encodings not supported");
2407 }
else if (encodings_list->
nb_elem == 1) {
2408 if (encodings[0].
type) {
2409 if (encodings[0].encryption.key_id.size > 0) {
2412 const int b64_size =
AV_BASE64_SIZE(encodings[0].encryption.key_id.size);
2414 if (key_id_base64 ==
NULL)
2418 encodings[0].encryption.key_id.data,
2421 encodings[0].
scope = 0;
2423 "Unsupported encoding type");
2436 encodings[0].
scope = 0;
2438 "Unsupported encoding type");
2448 "Failed to decode codec private data\n");
2467 encodings[0].
scope & 1 &&
2486 if (key_id_base64) {
2492 if (!strcmp(track->
codec_id,
"V_MS/VFW/FOURCC") &&
2503 extradata_offset = 40;
2504 }
else if (!strcmp(track->
codec_id,
"A_MS/ACM") &&
2517 }
else if (!strcmp(track->
codec_id,
"A_QUICKTIME")
2521 uint16_t sample_size;
2527 if (sample_size == 8) {
2528 fourcc =
MKTAG(
'r',
'a',
'w',
' ');
2530 }
else if (sample_size == 16) {
2531 fourcc =
MKTAG(
't',
'w',
'o',
's');
2535 if ((fourcc ==
MKTAG(
't',
'w',
'o',
's') ||
2536 fourcc ==
MKTAG(
's',
'o',
'w',
't')) &&
2539 }
else if (!strcmp(track->
codec_id,
"V_QUICKTIME") &&
2546 fourcc =
MKTAG(
'S',
'V',
'Q',
'3');
2595 extradata[0] = (profile << 3) | ((sri & 0x0E) >> 1);
2596 extradata[1] = ((sri & 0x01) << 7) | (track->
audio.
channels << 3);
2597 if (strstr(track->
codec_id,
"SBR")) {
2599 extradata[2] = 0x56;
2600 extradata[3] = 0xE5;
2601 extradata[4] = 0x80 | (sri << 3);
2614 AV_WB32(extradata, extradata_size);
2615 memcpy(&extradata[4],
"alac", 4);
2624 "Too large audio channel number %"PRIu64
2625 " or bitdepth %"PRIu64
". Skipping track.\n",
2634 extradata_size = 22;
2639 bytestream_put_be32(&ptr,
AV_RB32(
"TTA1"));
2640 bytestream_put_le16(&ptr, 1);
2651 extradata_offset = 26;
2685 static const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 };
2694 extradata_offset = 78;
2706 "in absence of valid CodecPrivate.\n");
2721 extradata_offset = 4;
2727 "Unknown/unsupported AVCodecID %s.\n", track->
codec_id);
2731 "Track TimestampScale too small %f, assuming 1.0.\n",
2736 1000 * 1000 * 1000);
2745 if (strcmp(track->
language,
"und"))
2775 int display_width_mul = 1;
2776 int display_height_mul = 1;
2806 #if FF_API_R_FRAME_RATE 2826 snprintf(buf,
sizeof(buf),
"%s_%d",
2829 if (planes[j].
uid == tracks[k].
uid && tracks[k].stream) {
2831 "stereo_mode", buf, 0);
2865 (
AVRational){1, st->codecpar->codec_id == AV_CODEC_ID_OPUS ?
2866 48000 : st->codecpar->sample_rate});
2876 if (!strcmp(track->
codec_id,
"D_WEBVTT/CAPTIONS")) {
2878 }
else if (!strcmp(track->
codec_id,
"D_WEBVTT/DESCRIPTIONS")) {
2880 }
else if (!strcmp(track->
codec_id,
"D_WEBVTT/METADATA")) {
2901 uint64_t max_start = 0;
2916 ebml.
max_size >
sizeof(uint64_t) ||
2920 "EBML version %"PRIu64
", doctype %s, doc version %"PRIu64,
2926 "EBML header using unsupported features\n" 2927 "(EBML version %"PRIu64
", doctype %s, doc version %"PRIu64
")\n",
2944 res =
ebml_parse(matroska, matroska_segments, matroska);
2951 res =
ebml_parse(matroska, matroska_segment, matroska);
2973 attachments = attachments_list->
elem;
2974 for (j = 0; j < attachments_list->
nb_elem; j++) {
2975 if (!(attachments[j].filename && attachments[j].mime &&
2976 attachments[j].bin.data && attachments[j].
bin.
size > 0)) {
2989 if (!strncmp(mkv_image_mime_tags[i].
str, attachments[j].mime,
2990 strlen(mkv_image_mime_tags[i].str))) {
2996 attachments[j].
stream = st;
3019 if (!strncmp(mkv_mime_tags[i].
str, attachments[j].mime,
3020 strlen(mkv_mime_tags[i].str))) {
3029 chapters = chapters_list->
elem;
3030 for (i = 0; i < chapters_list->
nb_elem; i++)
3032 (max_start == 0 || chapters[i].start > max_start)) {
3038 max_start = chapters[
i].
start;
3058 if (matroska->
queue) {
3089 uint32_t lace_size[256],
int *laces)
3096 lace_size[0] =
size;
3112 for (n = 0; n < *laces - 1; n++) {
3120 lace_size[n] +=
temp;
3123 }
while (temp == 0xff);
3128 lace_size[n] = size - total;
3133 if (size % (*laces))
3135 for (n = 0; n < *laces; n++)
3136 lace_size[n] = size / *laces;
3153 total = lace_size[0] = num;
3155 for (n = 1; n < *laces - 1; n++) {
3161 if (lace_size[n - 1] + snum > (uint64_t)INT_MAX)
3164 lace_size[n] = lace_size[n - 1] + snum;
3165 total += lace_size[n];
3173 lace_size[*laces - 1] = size - total;
3200 if (size < cfs * h / 2) {
3202 "Corrupt int4 RM-style audio packet size\n");
3205 for (x = 0; x < h / 2; x++)
3206 memcpy(track->
audio.
buf + x * 2 * w + y * cfs,
3207 data + x * cfs, cfs);
3211 "Corrupt sipr RM-style audio packet size\n");
3214 memcpy(track->
audio.
buf + y * w, data, w);
3218 "Corrupt generic RM-style audio packet size\n");
3221 for (x = 0; x < w /
sps; x++)
3223 sps * (h * x + ((h + 1) / 2) * (y & 1) + (y >> 1)),
3224 data + x * sps, sps);
3282 while (srclen >= 8) {
3288 uint32_t crc =
AV_RL32(src + 4);
3292 multiblock = (flags & 0x1800) != 0x1800;
3304 if (blocksize > srclen) {
3315 dstlen += blocksize + 32;
3318 AV_WL32(dst + offset + 4, blocksize + 24);
3319 AV_WL16(dst + offset + 8, ver);
3320 AV_WL16(dst + offset + 10, 0);
3321 AV_WL32(dst + offset + 12, 0);
3322 AV_WL32(dst + offset + 16, 0);
3323 AV_WL32(dst + offset + 20, samples);
3324 AV_WL32(dst + offset + 24, flags);
3325 AV_WL32(dst + offset + 28, crc);
3326 memcpy(dst + offset + 32, src, blocksize);
3329 srclen -= blocksize;
3330 offset += blocksize + 32;
3349 int dstlen = *size + 8;
3357 memcpy(dst + 8, *data, dstlen - 8);
3376 int id_len, settings_len, text_len;
3384 q = data + data_len;
3389 if (*p ==
'\r' || *p ==
'\n') {
3398 if (p >= q || *p !=
'\n')
3405 if (*p ==
'\r' || *p ==
'\n') {
3406 settings_len = p - settings;
3414 if (p >= q || *p !=
'\n')
3420 while (text_len > 0) {
3421 const int len = text_len - 1;
3423 if (c !=
'\r' && c !=
'\n')
3436 memcpy(pkt->
data, text, text_len);
3446 memcpy(buf,
id, id_len);
3449 if (settings_len > 0) {
3457 memcpy(buf, settings, settings_len);
3464 pkt->
pts = timecode;
3484 uint64_t timecode, uint64_t lace_duration,
3486 uint8_t *additional, uint64_t additional_id,
int additional_size,
3487 int64_t discard_padding)
3497 "Error parsing a wavpack block.\n");
3510 "Error parsing a prores block.\n");
3518 if (!pkt_size && !additional_size)
3533 pkt->
data = pkt_data;
3534 pkt->
size = pkt_size;
3538 if (additional_size > 0) {
3541 additional_size + 8);
3546 AV_WB64(side_data, additional_id);
3547 memcpy(side_data + 8, additional, additional_size);
3550 if (discard_padding) {
3561 if (discard_padding > 0) {
3562 AV_WL32(side_data + 4, discard_padding);
3564 AV_WL32(side_data, -discard_padding);
3569 pkt->
dts = timecode;
3571 pkt->
pts = timecode;
3575 #if FF_API_CONVERGENCE_DURATION 3578 pkt->convergence_duration = lace_duration;
3599 int size, int64_t
pos, uint64_t cluster_time,
3601 uint8_t *additional, uint64_t additional_id,
int additional_size,
3602 int64_t cluster_pos, int64_t discard_padding)
3610 uint32_t lace_size[256];
3611 int n,
flags, laces = 0;
3613 int trust_default_duration;
3623 if (!track || size < 3)
3626 if (!(st = track->
stream)) {
3628 "No stream associated to TrackNumber %"PRIu64
". " 3629 "Ignoring Block with this TrackNumber.\n", num);
3635 if (block_duration > INT64_MAX)
3636 block_duration = INT64_MAX;
3642 if (is_keyframe == -1)
3645 if (cluster_time != (uint64_t) -1 &&
3646 (block_time >= 0 || cluster_time >= -block_time)) {
3647 uint64_t timecode_cluster_in_track_tb = (double) cluster_time / track->
time_scale;
3650 timecode < track->end_timecode)
3675 &pb, lace_size, &laces);
3686 trust_default_duration = 0;
3690 if (!block_duration && trust_default_duration)
3693 if (cluster_time != (uint64_t)-1 && (block_time >= 0 || cluster_time >= -block_time))
3697 for (n = 0; n < laces; n++) {
3698 int64_t lace_duration = block_duration*(n+1) / laces - block_duration*n / laces;
3724 timecode, lace_duration,
3732 out_size, timecode, lace_duration,
3733 pos, !n ? is_keyframe : 0,
3734 additional, additional_id, additional_size,
3741 timecode = lace_duration ? timecode + lace_duration :
AV_NOPTS_VALUE;
3742 data += lace_size[n];
3763 res =
ebml_parse(matroska, matroska_cluster_enter, cluster);
3771 res =
ebml_parse(matroska, matroska_cluster_parsing, cluster);
3773 if (res >= 0 && block->
bin.
size > 0) {
3787 memset(block, 0,
sizeof(*block));
3793 "end of segment.\n");
3825 int64_t timestamp,
int flags)
3922 for (i = 1; i < nb_index_entries; i++) {
3923 if (index_entries[i - 1].timestamp * matroska->
time_scale <= ts &&
3931 if (i != nb_index_entries - 1) {
3948 int64_t cluster_pos, before_pos;
3953 if (index < 0)
return 0;
3957 uint64_t cluster_id, cluster_length;
3963 if (read < 0 || cluster_id != 0xF43B675)
3977 cluster_pos += 4 + read + cluster_length;
3991 double min_buffer,
double*
buffer,
3995 double nano_seconds_per_second = 1000000000.0;
3996 double time_sec = time_ns / nano_seconds_per_second;
3998 int64_t time_to_search_ns = (int64_t)(search_sec * nano_seconds_per_second);
3999 int64_t end_time_ns = time_ns + time_to_search_ns;
4000 double sec_downloaded = 0.0;
4004 *sec_to_download = 0.0;
4008 int64_t cue_nano = desc_curr.
end_time_ns - time_ns;
4011 double timeToDownload = (cueBytes * 8.0) /
bps;
4013 sec_downloaded += (cue_nano / nano_seconds_per_second) - timeToDownload;
4014 *sec_to_download += timeToDownload;
4018 double desc_end_time_sec = desc_curr.
end_time_ns / nano_seconds_per_second;
4019 double percent_to_sub = search_sec / (desc_end_time_sec - time_sec);
4020 sec_downloaded = percent_to_sub * sec_downloaded;
4021 *sec_to_download = percent_to_sub * *sec_to_download;
4024 if ((sec_downloaded + *buffer) <= min_buffer) {
4035 double desc_sec = desc_ns / nano_seconds_per_second;
4036 double bits = (desc_bytes * 8.0);
4037 double time_to_download = bits /
bps;
4039 sec_downloaded += desc_sec - time_to_download;
4040 *sec_to_download += time_to_download;
4043 double desc_end_time_sec = desc_curr.
end_time_ns / nano_seconds_per_second;
4044 double percent_to_sub = search_sec / (desc_end_time_sec - time_sec);
4045 sec_downloaded = percent_to_sub * sec_downloaded;
4046 *sec_to_download = percent_to_sub * *sec_to_download;
4048 if ((sec_downloaded + *buffer) <= min_buffer)
4053 if ((sec_downloaded + *buffer) <= min_buffer) {
4060 *buffer = *buffer + sec_downloaded;
4075 double bandwidth = 0.0;
4079 int64_t prebuffer_ns = 1000000000;
4081 double nano_seconds_per_second = 1000000000.0;
4082 int64_t prebuffered_ns = time_ns + prebuffer_ns;
4083 double prebuffer_bytes = 0.0;
4084 int64_t temp_prebuffer_ns = prebuffer_ns;
4085 int64_t pre_bytes, pre_ns;
4086 double pre_sec, prebuffer, bits_per_second;
4104 bits_per_second = 0.0;
4110 pre_sec = pre_ns / nano_seconds_per_second;
4112 pre_bytes * ((temp_prebuffer_ns / nano_seconds_per_second) / pre_sec);
4114 prebuffer = prebuffer_ns / nano_seconds_per_second;
4117 bits_per_second = 0.0;
4121 double desc_sec = desc_ns / nano_seconds_per_second;
4122 double calc_bits_per_second = (desc_bytes * 8) / desc_sec;
4125 double percent = (desc_bytes - prebuffer_bytes) / desc_bytes;
4126 double mod_bits_per_second = calc_bits_per_second * percent;
4128 if (prebuffer < desc_sec) {
4134 int64_t
bps = (int64_t)(mod_bits_per_second) + 1;
4135 const double min_buffer = 0.0;
4136 double buffer = prebuffer;
4137 double sec_to_download = 0.0;
4140 min_buffer, &buffer, &sec_to_download,
4144 }
else if (rv == 0) {
4145 bits_per_second = (double)(bps);
4153 if (bandwidth < bits_per_second) bandwidth = bits_per_second;
4155 return (int64_t)bandwidth;
4164 int64_t cues_start = -1, cues_end = -1, before_pos, bandwidth;
4169 for (i = 0; i < seekhead_list->
nb_elem; i++)
4173 if (i >= seekhead_list->
nb_elem)
return -1;
4177 if (
avio_seek(matroska->
ctx->
pb, cues_start, SEEK_SET) == cues_start) {
4181 uint64_t cues_length, cues_id;
4189 cues_end = cues_start + 4 + bytes_read + cues_length - 1;
4192 if (cues_start == -1 || cues_end == -1)
return -1;
4205 if (cues_start <= init_range)
4210 if (bandwidth < 0)
return -1;
4219 if (!buf)
return -1;
4271 buf = strrchr(s->
url,
'/');
4303 #define OFFSET(x) offsetof(MatroskaDemuxContext, x) 4318 .
name =
"matroska,webm",
4320 .extensions =
"mkv,mk3d,mka,mks,webm",
4327 .mime_type =
"audio/webm,audio/x-matroska,video/webm,video/x-matroska" 4331 .
name =
"webm_dash_manifest",
4337 .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...
static EbmlSyntax matroska_index[2]
#define MATROSKA_ID_VIDEOPROJECTIONTYPE