71 #define EBML_UNKNOWN_LENGTH UINT64_MAX
72 #define NEEDS_CHECKING 2
76 #define SKIP_THRESHOLD 1024 * 1024
79 #define UNKNOWN_EQUIV 50 * 1024
124 typedef struct Ebml {
391 #define CHILD_OF(parent) { .def = { .n = parent } }
758 uint32_t
id, int64_t position)
787 "Seek to desired resync point failed. Seeking to "
788 "earliest point available instead.\n");
790 last_pos + 1), SEEK_SET);
826 int max_size, uint64_t *number,
int eof_forbidden)
840 if (!total || read > max_size) {
844 "0x00 at pos %"PRId64
" (0x%"PRIx64
") invalid as first byte "
845 "of an EBML number\n", pos, pos);
848 "Length %d indicated by an EBML number's first byte 0x%02x "
849 "at pos %"PRId64
" (0x%"PRIx64
") exceeds max length %d.\n",
850 read, (
uint8_t) total, pos, pos, max_size);
858 total = (total << 8) |
avio_r8(pb);
873 "Read error at pos. %"PRIu64
" (0x%"PRIx64
")\n",
879 "at pos. %"PRIu64
" (0x%"PRIx64
")\n", pos, pos);
894 if (res > 0 && *number + 1 == 1ULL << (7 * res))
910 *num = (*num << 8) |
avio_r8(pb);
930 *num = ((uint64_t)*num << 8) |
avio_r8(pb);
1011 uint64_t
length, int64_t pos)
1054 *num = unum - ((1LL << (7 * res - 1)) - 1);
1068 for (
i = 0; syntax[
i].
id;
i++)
1069 if (
id == syntax[
i].
id)
1081 for (
int i = 0; syntax[
i].
id;
i++)
1082 switch (syntax[
i].
type) {
1087 *(int64_t *) ((
char *)
data + syntax[
i].data_offset) = syntax[
i].
def.
i;
1095 if (syntax[
i].def.
s) {
1123 return id && (
bits + 7) / 8 == (8 -
bits % 8);
1204 "at pos. %"PRIu64
" (0x%"PRIx64
")\n", pos, pos);
1211 pos_alt = pos + res;
1224 while (syntax->
def.
n) {
1234 "%"PRId64
"\n",
id, pos);
1247 &
list->alloc_elem_size,
1251 list->elem = newelem;
1268 uint64_t elem_end = pos_alt +
length,
1271 if (elem_end < level_end) {
1273 }
else if (elem_end == level_end) {
1277 "Element at 0x%"PRIx64
" ending at 0x%"PRIx64
" exceeds "
1278 "containing master element ending at 0x%"PRIx64
"\n",
1279 pos, elem_end, level_end);
1286 "at 0x%"PRIx64
" inside parent with finite size\n", pos);
1296 "Found unknown-length element 0x%"PRIX32
" other than "
1297 "a cluster at 0x%"PRIx64
". Spec-incompliant, but "
1298 "parsing will nevertheless be attempted.\n",
id, pos);
1305 if (max_lengths[syntax->
type] &&
length > max_lengths[syntax->
type]) {
1308 "Invalid length 0x%"PRIx64
" > 0x%"PRIx64
" for element "
1309 "with ID 0x%"PRIX32
" at 0x%"PRIx64
"\n",
1313 "Element with ID 0x%"PRIX32
" at pos. 0x%"PRIx64
" has "
1314 "unknown length, yet the length of an element of its "
1315 "type must be known.\n",
id, pos);
1318 "Found unknown-length element with ID 0x%"PRIX32
" at "
1319 "pos. 0x%"PRIx64
" for which no syntax for parsing is "
1320 "available.\n",
id, pos);
1357 "Unknown element %"PRIX32
" at pos. 0x%"PRIx64
" with "
1358 "length 0x%"PRIx64
" considered as invalid data. Last "
1359 "known good position 0x%"PRIx64
", %d unknown elements"
1378 switch (syntax->
type) {
1405 if (!level1_elem->
pos) {
1407 level1_elem->
pos = pos;
1408 }
else if (level1_elem->
pos != pos)
1481 for (
i = 0; syntax[
i].
id;
i++) {
1482 void *data_off = (
char *)
data + syntax[
i].data_offset;
1483 switch (syntax[
i].
type) {
1493 if (syntax[
i].list_elem_size) {
1495 char *ptr =
list->elem;
1496 for (j = 0; j <
list->nb_elem;
1501 list->alloc_elem_size = 0;
1516 int len_mask = 0x80,
size = 1,
n = 1,
i;
1524 while (
size <= 8 && !(total & len_mask)) {
1530 total &= (len_mask - 1);
1532 total = (total << 8) | p->
buf[4 +
n++];
1534 if (total + 1 == 1ULL << (7 *
size)){
1549 if (total < probelen)
1551 for (
n = 4 +
size;
n <= 4 +
size + total - probelen;
n++)
1567 if (tracks[
i].num == num)
1579 int isize = *buf_size;
1582 int pkt_size = isize;
1586 if (pkt_size >= 10000000
U)
1589 switch (encodings[0].compression.algo) {
1595 if (header_size && !
header) {
1603 pkt_size = isize + header_size;
1608 memcpy(pkt_data,
header, header_size);
1609 memcpy(pkt_data + header_size,
data, isize);
1615 olen = pkt_size *= 3;
1622 pkt_data = newpktdata;
1635 z_stream zstream = { 0 };
1636 if (!pkt_size || inflateInit(&zstream) != Z_OK)
1638 zstream.next_in =
data;
1639 zstream.avail_in = isize;
1644 inflateEnd(&zstream);
1648 pkt_data = newpktdata;
1649 zstream.avail_out = pkt_size - zstream.total_out;
1650 zstream.next_out = pkt_data + zstream.total_out;
1652 }
while (
result == Z_OK && pkt_size < 10000000);
1653 pkt_size = zstream.total_out;
1654 inflateEnd(&zstream);
1655 if (
result != Z_STREAM_END) {
1656 if (
result == Z_MEM_ERROR)
1668 bz_stream bzstream = { 0 };
1669 if (!pkt_size || BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
1671 bzstream.next_in =
data;
1672 bzstream.avail_in = isize;
1677 BZ2_bzDecompressEnd(&bzstream);
1681 pkt_data = newpktdata;
1682 bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
1683 bzstream.next_out = pkt_data + bzstream.total_out_lo32;
1684 result = BZ2_bzDecompress(&bzstream);
1685 }
while (
result == BZ_OK && pkt_size < 10000000);
1686 pkt_size = bzstream.total_out_lo32;
1687 BZ2_bzDecompressEnd(&bzstream);
1688 if (
result != BZ_STREAM_END) {
1689 if (
result == BZ_MEM_ERROR)
1705 *buf_size = pkt_size;
1720 for (
i = 0;
i <
list->nb_elem;
i++) {
1721 const char *lang = tags[
i].
lang &&
1722 strcmp(tags[
i].lang,
"und") ? tags[
i].
lang :
NULL;
1724 if (!tags[
i].
name) {
1732 if (tags[
i].def || !lang) {
1734 if (tags[
i].sub.nb_elem)
1741 if (tags[
i].sub.nb_elem)
1755 if (tags[
i].target.attachuid) {
1759 if (attachment[j].
uid == tags[
i].target.attachuid &&
1760 attachment[j].stream) {
1762 &attachment[j].stream->metadata,
NULL);
1768 "The tags at index %d refer to a "
1769 "non-existent attachment %"PRId64
".\n",
1770 i, tags[
i].target.attachuid);
1772 }
else if (tags[
i].target.chapteruid) {
1776 if (chapter[j].
uid == tags[
i].target.chapteruid &&
1777 chapter[j].chapter) {
1779 &chapter[j].chapter->metadata,
NULL);
1785 "The tags at index %d refer to a non-existent chapter "
1787 i, tags[
i].target.chapteruid);
1789 }
else if (tags[
i].target.trackuid) {
1793 if (track[j].
uid == tags[
i].target.trackuid &&
1796 &track[j].stream->metadata,
NULL);
1802 "The tags at index %d refer to a non-existent track "
1804 i, tags[
i].target.trackuid);
1808 tags[
i].target.type);
1827 "Max EBML element depth (%d) reached, "
1860 for (
i = 0;
i < seekhead_list->
nb_elem;
i++) {
1862 uint32_t
id = seekheads[
i].
id;
1870 if (!elem || elem->
parsed)
1893 uint64_t index_scale = 1;
1899 index_list = &matroska->
index;
1910 for (j = 0; j < pos_list->
nb_elem; j++) {
1913 if (track && track->
stream)
1943 static const char *
const aac_profiles[] = {
"MAIN",
"LC",
"SSR" };
1989 int block_last, block_type, block_size;
1995 if (block_size >
size)
2004 chmask =
av_dict_get(dict,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK",
NULL, 0);
2009 "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
2025 int major, minor, micro, bttb = 0;
2029 if (matroska->
muxingapp && sscanf(matroska->
muxingapp,
"Lavf%d.%d.%d", &major, &minor, µ) == 3)
2030 bttb = (major == 57 && minor >= 36 && minor <= 51 && micro >= 100);
2032 switch (field_order) {
2051 int *h_width,
int *h_height)
2053 switch (stereo_mode) {
2078 int has_mastering_primaries, has_mastering_luminance;
2083 mastering_meta = &
color->mastering_meta;
2085 has_mastering_primaries =
2086 mastering_meta->
r_x > 0 && mastering_meta->
r_y > 0 &&
2087 mastering_meta->
g_x > 0 && mastering_meta->
g_y > 0 &&
2088 mastering_meta->
b_x > 0 && mastering_meta->
b_y > 0 &&
2090 has_mastering_luminance = mastering_meta->
max_luminance > 0;
2109 (
color->chroma_siting_vert - 1) << 7);
2127 if (has_mastering_primaries || has_mastering_luminance) {
2129 const int chroma_den = 50000;
2130 const int luma_den = 10000;
2139 if (has_mastering_primaries) {
2141 round(mastering_meta->
r_x * chroma_den), chroma_den);
2143 round(mastering_meta->
r_y * chroma_den), chroma_den);
2145 round(mastering_meta->
g_x * chroma_den), chroma_den);
2147 round(mastering_meta->
g_y * chroma_den), chroma_den);
2149 round(mastering_meta->
b_x * chroma_den), chroma_den);
2151 round(mastering_meta->
b_y * chroma_den), chroma_den);
2153 round(mastering_meta->
white_x * chroma_den), chroma_den);
2155 round(mastering_meta->
white_y * chroma_den), chroma_den);
2158 if (has_mastering_luminance) {
2172 size_t spherical_size;
2173 uint32_t l = 0, t = 0,
r = 0,
b = 0;
2174 uint32_t padding = 0;
2181 if (bytestream2_get_byte(&gb) != 0) {
2191 t = bytestream2_get_be32(&gb);
2192 b = bytestream2_get_be32(&gb);
2193 l = bytestream2_get_be32(&gb);
2194 r = bytestream2_get_be32(&gb);
2196 if (
b >= UINT_MAX - t ||
r >= UINT_MAX - l) {
2198 "Invalid bounding rectangle coordinates "
2199 "%"PRIu32
",%"PRIu32
",%"PRIu32
",%"PRIu32
"\n",
2208 if (l || t ||
r ||
b)
2218 uint32_t
layout = bytestream2_get_be32(&gb);
2221 "Unknown spherical cubemap layout %"PRIu32
"\n",
layout);
2225 padding = bytestream2_get_be32(&gb);
2236 "Unknown spherical metadata type %"PRIu64
"\n",
2310 int extradata_size = 0;
2311 int extradata_offset = 0;
2314 char* key_id_base64 =
NULL;
2323 "Unknown or unsupported track type %"PRIu64
"\n",
2342 "Invalid sample rate %f, defaulting to 8000 instead.\n",
2350 if (default_duration > UINT64_MAX || default_duration < 0) {
2352 "Invalid frame rate %e. Cannot calculate default duration.\n",
2368 if (encodings_list->
nb_elem > 1) {
2370 "Multiple combined encodings not supported");
2371 }
else if (encodings_list->
nb_elem == 1) {
2372 if (encodings[0].
type) {
2373 if (encodings[0].encryption.key_id.size > 0) {
2376 const int b64_size =
AV_BASE64_SIZE(encodings[0].encryption.key_id.size);
2378 if (key_id_base64 ==
NULL)
2382 encodings[0].encryption.key_id.data,
2383 encodings[0].encryption.key_id.size);
2385 encodings[0].
scope = 0;
2387 "Unsupported encoding type");
2400 encodings[0].
scope = 0;
2402 "Unsupported encoding type");
2412 "Failed to decode codec private data\n");
2445 if (key_id_base64) {
2451 if (!strcmp(track->
codec_id,
"V_MS/VFW/FOURCC") &&
2462 extradata_offset = 40;
2463 }
else if (!strcmp(track->
codec_id,
"A_MS/ACM") &&
2476 }
else if (!strcmp(track->
codec_id,
"A_QUICKTIME")
2480 uint16_t sample_size;
2486 if (sample_size == 8) {
2489 }
else if (sample_size == 16) {
2498 }
else if (!strcmp(track->
codec_id,
"V_QUICKTIME") &&
2554 extradata[0] = (
profile << 3) | ((sri & 0x0E) >> 1);
2555 extradata[1] = ((sri & 0x01) << 7) | (track->
audio.
channels << 3);
2556 if (strstr(track->
codec_id,
"SBR")) {
2558 extradata[2] = 0x56;
2559 extradata[3] = 0xE5;
2560 extradata[4] = 0x80 | (sri << 3);
2573 AV_WB32(extradata, extradata_size);
2574 memcpy(&extradata[4],
"alac", 4);
2582 "Too large audio channel number %"PRIu64
2583 " or bitdepth %"PRIu64
". Skipping track.\n",
2592 extradata_size = 30;
2610 extradata_offset = 26;
2646 static const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 };
2651 extradata_offset = 78;
2666 extradata_offset = 4;
2672 "Unknown/unsupported AVCodecID %s.\n", track->
codec_id);
2677 1000 * 1000 * 1000);
2686 if (strcmp(track->
language,
"und"))
2710 int display_width_mul = 1;
2711 int display_height_mul = 1;
2742 #if FF_API_R_FRAME_RATE
2765 if (
planes[j].
uid == tracks[k].
uid && tracks[k].stream) {
2767 "stereo_mode",
buf, 0);
2801 (
AVRational){1, st->codecpar->codec_id == AV_CODEC_ID_OPUS ?
2802 48000 : st->codecpar->sample_rate});
2812 if (!strcmp(track->
codec_id,
"D_WEBVTT/CAPTIONS")) {
2814 }
else if (!strcmp(track->
codec_id,
"D_WEBVTT/DESCRIPTIONS")) {
2816 }
else if (!strcmp(track->
codec_id,
"D_WEBVTT/METADATA")) {
2834 uint64_t max_start = 0;
2849 ebml.
max_size >
sizeof(uint64_t) ||
2853 "EBML version %"PRIu64
", doctype %s, doc version %"PRIu64,
2859 "EBML header using unsupported features\n"
2860 "(EBML version %"PRIu64
", doctype %s, doc version %"PRIu64
")\n",
2910 attachments = attachments_list->
elem;
2911 for (j = 0; j < attachments_list->
nb_elem; j++) {
2912 if (!(attachments[j].filename && attachments[j].mime &&
2913 attachments[j].bin.data && attachments[j].bin.size > 0)) {
2931 attachments[j].
stream = st;
2952 attachments[j].bin.size);
2965 chapters = chapters_list->
elem;
2968 (max_start == 0 || chapters[
i].
start > max_start)) {
2974 if (chapters[
i].chapter) {
2976 "title", chapters[
i].title, 0);
2978 max_start = chapters[
i].
start;
2998 if (matroska->
queue) {
3028 int *buf_size,
int type,
3029 uint32_t **lace_buf,
int *laces)
3031 int res = 0,
n,
size = *buf_size;
3033 uint32_t *lace_size;
3037 *lace_buf =
av_malloc(
sizeof(**lace_buf));
3041 *lace_buf[0] =
size;
3060 for (
n = 0; res == 0 &&
n < *laces - 1;
n++) {
3064 if (
size <= total) {
3070 lace_size[
n] +=
temp;
3082 lace_size[
n] =
size - total;
3087 if (
size % (*laces)) {
3091 for (
n = 0;
n < *laces;
n++)
3092 lace_size[
n] =
size / *laces;
3100 if (n < 0 || num > INT_MAX) {
3102 "EBML block data error\n");
3108 total = lace_size[0] = num;
3109 for (
n = 1; res == 0 &&
n < *laces - 1;
n++) {
3113 if (
r < 0 || lace_size[
n - 1] + snum > (uint64_t)INT_MAX) {
3115 "EBML block data error\n");
3121 lace_size[
n] = lace_size[
n - 1] + snum;
3122 total += lace_size[
n];
3128 lace_size[*laces - 1] =
size - total;
3134 *lace_buf = lace_size;
3157 if (
size < cfs *
h / 2) {
3159 "Corrupt int4 RM-style audio packet size\n");
3162 for (x = 0; x <
h / 2; x++)
3163 memcpy(track->
audio.
buf + x * 2 *
w + y * cfs,
3164 data + x * cfs, cfs);
3168 "Corrupt sipr RM-style audio packet size\n");
3175 "Corrupt generic RM-style audio packet size\n");
3178 for (x = 0; x <
w /
sps; x++)
3180 sps * (
h * x + ((
h + 1) / 2) * (y & 1) + (y >> 1)),
3228 if (srclen < 12 || track->stream->codecpar->extradata_size < 2)
3237 while (srclen >= 8) {
3247 multiblock = (
flags & 0x1800) != 0x1800;
3259 if (blocksize > srclen) {
3270 dstlen += blocksize + 32;
3281 memcpy(dst +
offset + 32,
src, blocksize);
3284 srclen -= blocksize;
3285 offset += blocksize + 32;
3304 int dstlen = *
size + 8;
3312 memcpy(dst + 8,
src, dstlen - 8);
3331 int id_len, settings_len, text_len;
3339 q =
data + data_len;
3344 if (*p ==
'\r' || *p ==
'\n') {
3353 if (p >= q || *p !=
'\n')
3360 if (*p ==
'\r' || *p ==
'\n') {
3361 settings_len = p - settings;
3369 if (p >= q || *p !=
'\n')
3375 while (text_len > 0) {
3376 const int len = text_len - 1;
3378 if (
c !=
'\r' &&
c !=
'\n')
3391 memcpy(
pkt->
data, text, text_len);
3401 memcpy(
buf,
id, id_len);
3404 if (settings_len > 0) {
3412 memcpy(
buf, settings, settings_len);
3439 uint64_t timecode, uint64_t lace_duration,
3441 uint8_t *additional, uint64_t additional_id,
int additional_size,
3442 int64_t discard_padding)
3449 if (encodings && !encodings->
type && encodings->
scope & 1) {
3460 "Error parsing a wavpack block.\n");
3463 if (pkt_data !=
data)
3474 "Error parsing a prores block.\n");
3477 if (pkt_data !=
data)
3482 if (!pkt_size && !additional_size)
3486 if (pkt_data !=
data)
3502 if (additional_size > 0) {
3505 additional_size + 8);
3510 AV_WB64(side_data, additional_id);
3511 memcpy(side_data + 8, additional, additional_size);
3514 if (discard_padding) {
3525 if (discard_padding > 0) {
3526 AV_WL32(side_data + 4, discard_padding);
3528 AV_WL32(side_data, -discard_padding);
3539 #if FF_API_CONVERGENCE_DURATION
3557 if (pkt_data !=
data)
3563 int size, int64_t pos, uint64_t cluster_time,
3565 uint8_t *additional, uint64_t additional_id,
int additional_size,
3566 int64_t cluster_pos, int64_t discard_padding)
3573 uint32_t *lace_size =
NULL;
3576 int trust_default_duration = 1;
3585 if (!track ||
size < 3)
3588 if (!(st = track->
stream)) {
3590 "No stream associated to TrackNumber %"PRIu64
". "
3591 "Ignoring Block with this TrackNumber.\n", num);
3597 if (block_duration > INT64_MAX)
3598 block_duration = INT64_MAX;
3607 if (cluster_time != (uint64_t) -1 &&
3608 (block_time >= 0 || cluster_time >= -block_time)) {
3611 timecode < track->end_timecode)
3636 &lace_size, &laces);
3645 trust_default_duration = 0;
3649 if (!block_duration && trust_default_duration)
3652 if (cluster_time != (uint64_t)-1 && (block_time >= 0 || cluster_time >= -block_time))
3656 for (
n = 0;
n < laces;
n++) {
3657 int64_t lace_duration = block_duration*(
n+1) / laces - block_duration*
n / laces;
3659 if (lace_size[
n] >
size) {
3678 timecode, lace_duration,
3684 timecode, lace_duration, pos,
3686 additional, additional_id, additional_size,
3693 timecode = lace_duration ? timecode + lace_duration :
AV_NOPTS_VALUE;
3694 data += lace_size[
n];
3695 size -= lace_size[
n];
3728 if (res >= 0 &&
block->bin.size > 0) {
3737 block->additional.size, cluster->
pos,
3738 block->discard_padding);
3748 "end of segment.\n");
3780 int64_t timestamp,
int flags)
3784 AVStream *st =
s->streams[stream_index];
3860 int64_t start_time_ns;
3861 int64_t end_time_ns;
3862 int64_t start_offset;
3874 int nb_index_entries =
s->streams[0]->nb_index_entries;
3878 return (
CueDesc) {-1, -1, -1, -1};
3879 for (
i = 1;
i < nb_index_entries;
i++) {
3880 if (index_entries[
i - 1].timestamp * matroska->
time_scale <= ts &&
3881 index_entries[
i].timestamp * matroska->
time_scale > ts) {
3888 if (
i != nb_index_entries - 1) {
3905 int64_t cluster_pos, before_pos;
3907 if (
s->streams[0]->nb_index_entries <= 0)
return 0;
3910 if (
index < 0)
return 0;
3911 cluster_pos =
s->streams[0]->index_entries[
index].pos;
3914 uint64_t cluster_id, cluster_length;
3920 if (read < 0 || cluster_id != 0xF43B675)
3934 cluster_pos += 4 + read + cluster_length;
3948 double min_buffer,
double*
buffer,
3952 double nano_seconds_per_second = 1000000000.0;
3953 double time_sec = time_ns / nano_seconds_per_second;
3955 int64_t time_to_search_ns = (int64_t)(search_sec * nano_seconds_per_second);
3956 int64_t end_time_ns = time_ns + time_to_search_ns;
3957 double sec_downloaded = 0.0;
3961 *sec_to_download = 0.0;
3965 int64_t cue_nano = desc_curr.
end_time_ns - time_ns;
3968 double timeToDownload = (cueBytes * 8.0) /
bps;
3970 sec_downloaded += (cue_nano / nano_seconds_per_second) - timeToDownload;
3971 *sec_to_download += timeToDownload;
3975 double desc_end_time_sec = desc_curr.
end_time_ns / nano_seconds_per_second;
3976 double percent_to_sub = search_sec / (desc_end_time_sec - time_sec);
3977 sec_downloaded = percent_to_sub * sec_downloaded;
3978 *sec_to_download = percent_to_sub * *sec_to_download;
3981 if ((sec_downloaded + *
buffer) <= min_buffer) {
3992 double desc_sec = desc_ns / nano_seconds_per_second;
3993 double bits = (desc_bytes * 8.0);
3994 double time_to_download =
bits /
bps;
3996 sec_downloaded += desc_sec - time_to_download;
3997 *sec_to_download += time_to_download;
4000 double desc_end_time_sec = desc_curr.
end_time_ns / nano_seconds_per_second;
4001 double percent_to_sub = search_sec / (desc_end_time_sec - time_sec);
4002 sec_downloaded = percent_to_sub * sec_downloaded;
4003 *sec_to_download = percent_to_sub * *sec_to_download;
4005 if ((sec_downloaded + *
buffer) <= min_buffer)
4010 if ((sec_downloaded + *
buffer) <= min_buffer) {
4032 double bandwidth = 0.0;
4036 int64_t prebuffer_ns = 1000000000;
4038 double nano_seconds_per_second = 1000000000.0;
4039 int64_t prebuffered_ns = time_ns + prebuffer_ns;
4040 double prebuffer_bytes = 0.0;
4041 int64_t temp_prebuffer_ns = prebuffer_ns;
4042 int64_t pre_bytes, pre_ns;
4043 double pre_sec, prebuffer, bits_per_second;
4061 bits_per_second = 0.0;
4069 pre_sec = pre_ns / nano_seconds_per_second;
4071 pre_bytes * ((temp_prebuffer_ns / nano_seconds_per_second) / pre_sec);
4073 prebuffer = prebuffer_ns / nano_seconds_per_second;
4076 bits_per_second = 0.0;
4080 double desc_sec, calc_bits_per_second, percent, mod_bits_per_second;
4081 if (desc_bytes <= 0)
4084 desc_sec = desc_ns / nano_seconds_per_second;
4085 calc_bits_per_second = (desc_bytes * 8) / desc_sec;
4088 percent = (desc_bytes - prebuffer_bytes) / desc_bytes;
4089 mod_bits_per_second = calc_bits_per_second * percent;
4091 if (prebuffer < desc_sec) {
4097 int64_t
bps = (int64_t)(mod_bits_per_second) + 1;
4098 const double min_buffer = 0.0;
4099 double buffer = prebuffer;
4100 double sec_to_download = 0.0;
4103 min_buffer, &
buffer, &sec_to_download,
4107 }
else if (rv == 0) {
4108 bits_per_second = (double)(
bps);
4116 if (bandwidth < bits_per_second) bandwidth = bits_per_second;
4118 return (int64_t)bandwidth;
4127 int64_t cues_start = -1, cues_end = -1, before_pos, bandwidth;
4136 if (
i >= seekhead_list->
nb_elem)
return -1;
4140 if (
avio_seek(matroska->
ctx->
pb, cues_start, SEEK_SET) == cues_start) {
4144 uint64_t cues_length, cues_id;
4152 cues_end = cues_start + 4 + bytes_read + cues_length - 1;
4155 if (cues_start == -1 || cues_end == -1)
return -1;
4168 if (cues_start <= init_range)
4173 if (bandwidth < 0)
return -1;
4182 if (!
buf)
return -1;
4184 for (
i = 0;
i <
s->streams[0]->nb_index_entries;
i++) {
4186 "%" PRId64
"%s",
s->streams[0]->index_entries[
i].timestamp,
4187 i !=
s->streams[0]->nb_index_entries - 1 ?
"," :
"");
4188 if (
ret <= 0 || (
ret == 20 &&
i ==
s->streams[0]->nb_index_entries - 1)) {
4234 buf = strrchr(
s->url,
'/');
4266 #define OFFSET(x) offsetof(MatroskaDemuxContext, x)
4281 .
name =
"matroska,webm",
4283 .extensions =
"mkv,mk3d,mka,mks",
4290 .mime_type =
"audio/webm,audio/x-matroska,video/webm,video/x-matroska"
4294 .
name =
"webm_dash_manifest",