74 #define EBML_UNKNOWN_LENGTH UINT64_MAX
75 #define NEEDS_CHECKING 2
79 #define SKIP_THRESHOLD 1024 * 1024
82 #define UNKNOWN_EQUIV 50 * 1024
138 typedef struct Ebml {
423 #define CHILD_OF(parent) { .def = { .n = parent } }
821 uint32_t
id, int64_t position)
850 "Seek to desired resync point failed. Seeking to "
851 "earliest point available instead.\n");
853 last_pos + 1), SEEK_SET);
889 int max_size, uint64_t *number,
int eof_forbidden)
903 if (!total || read > max_size) {
907 "0x00 at pos %"PRId64
" (0x%"PRIx64
") invalid as first byte "
908 "of an EBML number\n",
pos,
pos);
911 "Length %d indicated by an EBML number's first byte 0x%02x "
912 "at pos %"PRId64
" (0x%"PRIx64
") exceeds max length %d.\n",
913 read, (uint8_t) total,
pos,
pos, max_size);
921 total = (total << 8) |
avio_r8(pb);
936 "Read error at pos. %"PRIu64
" (0x%"PRIx64
")\n",
942 "at pos. %"PRIu64
" (0x%"PRIx64
")\n",
pos,
pos);
957 if (res > 0 && *number + 1 == 1ULL << (7 * res))
967 uint64_t default_value, uint64_t *num)
972 *num = default_value;
978 *num = (*num << 8) |
avio_r8(pb);
988 int64_t default_value, int64_t *num)
993 *num = default_value;
1000 *num = ((uint64_t)*num << 8) |
avio_r8(pb);
1011 double default_value,
double *num)
1014 *num = default_value;
1016 }
else if (
size == 4) {
1018 }
else if (
size == 8) {
1031 const char *default_value,
char **
str)
1036 if (
size == 0 && default_value) {
1090 uint64_t length, int64_t
pos)
1102 level->length = length;
1122 *num = unum - ((1LL << (7 * res - 1)) - 1);
1153 *(uint64_t *)dst =
syntax[
i].def.u;
1156 *(int64_t *) dst =
syntax[
i].def.i;
1159 *(
double *) dst =
syntax[
i].def.f;
1192 return id && (
bits + 7) / 8 == (8 -
bits % 8);
1200 uint32_t
id, int64_t
pos)
1272 "at pos. %"PRIu64
" (0x%"PRIx64
")\n",
pos,
pos);
1279 pos_alt =
pos + res;
1302 "%"PRId64
"\n",
id,
pos);
1312 if ((
unsigned)
list->nb_elem + 1 >= UINT_MAX /
syntax->list_elem_size)
1315 &
list->alloc_elem_size,
1316 (
list->nb_elem + 1) *
syntax->list_elem_size);
1319 list->elem = newelem;
1336 uint64_t elem_end = pos_alt + length,
1339 if (elem_end < level_end) {
1341 }
else if (elem_end == level_end) {
1345 "Element at 0x%"PRIx64
" ending at 0x%"PRIx64
" exceeds "
1346 "containing master element ending at 0x%"PRIx64
"\n",
1347 pos, elem_end, level_end);
1354 "at 0x%"PRIx64
" inside parent with finite size\n",
pos);
1364 "Found unknown-length element 0x%"PRIX32
" other than "
1365 "a cluster at 0x%"PRIx64
". Spec-incompliant, but "
1366 "parsing will nevertheless be attempted.\n",
id,
pos);
1373 if (max_lengths[
syntax->type] && length > max_lengths[
syntax->type]) {
1376 "Invalid length 0x%"PRIx64
" > 0x%"PRIx64
" for element "
1377 "with ID 0x%"PRIX32
" at 0x%"PRIx64
"\n",
1378 length, max_lengths[
syntax->type],
id,
pos);
1381 "Element with ID 0x%"PRIX32
" at pos. 0x%"PRIx64
" has "
1382 "unknown length, yet the length of an element of its "
1383 "type must be known.\n",
id,
pos);
1386 "Found unknown-length element with ID 0x%"PRIX32
" at "
1387 "pos. 0x%"PRIx64
" for which no syntax for parsing is "
1388 "available.\n",
id,
pos);
1425 "Unknown element %"PRIX32
" at pos. 0x%"PRIx64
" with "
1426 "length 0x%"PRIx64
" considered as invalid data. Last "
1427 "known good position 0x%"PRIx64
", %d unknown elements"
1473 if (!level1_elem->
pos) {
1476 }
else if (level1_elem->
pos !=
pos)
1494 if ((res2 =
avio_skip(pb, length - 1)) >= 0) {
1533 if (elem->
count != UINT_MAX)
1556 void *data_off = (
char *)
data +
syntax[
i].data_offset;
1567 if (
syntax[
i].list_elem_size) {
1569 char *ptr =
list->elem;
1570 for (j = 0; j <
list->nb_elem;
1571 j++, ptr +=
syntax[
i].list_elem_size)
1575 list->alloc_elem_size = 0;
1590 int len_mask = 0x80,
size = 1, n = 1,
i;
1598 while (
size <= 8 && !(total & len_mask)) {
1604 total &= (len_mask - 1);
1606 total = (total << 8) | p->
buf[4 + n++];
1608 if (total + 1 == 1ULL << (7 *
size)){
1623 if (total < probelen)
1625 for (n = 4 +
size; n <= 4 +
size + total - probelen; n++)
1641 if (tracks[
i].num == num)
1652 uint8_t *
data = *buf;
1653 int isize = *buf_size;
1654 uint8_t *pkt_data =
NULL;
1656 int pkt_size = isize;
1660 if (pkt_size >= 10000000
U)
1663 switch (encodings[0].compression.algo) {
1669 if (header_size && !
header) {
1677 pkt_size = isize + header_size;
1682 memcpy(pkt_data,
header, header_size);
1683 memcpy(pkt_data + header_size,
data, isize);
1690 olen = pkt_size *= 3;
1697 pkt_data = newpktdata;
1710 z_stream zstream = { 0 };
1711 if (!pkt_size || inflateInit(&zstream) != Z_OK)
1713 zstream.next_in =
data;
1714 zstream.avail_in = isize;
1719 inflateEnd(&zstream);
1723 pkt_data = newpktdata;
1724 zstream.avail_out = pkt_size - zstream.total_out;
1725 zstream.next_out = pkt_data + zstream.total_out;
1727 }
while (
result == Z_OK && pkt_size < 10000000);
1728 pkt_size = zstream.total_out;
1729 inflateEnd(&zstream);
1730 if (
result != Z_STREAM_END) {
1731 if (
result == Z_MEM_ERROR)
1743 bz_stream bzstream = { 0 };
1744 if (!pkt_size || BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
1746 bzstream.next_in =
data;
1747 bzstream.avail_in = isize;
1752 BZ2_bzDecompressEnd(&bzstream);
1756 pkt_data = newpktdata;
1757 bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
1758 bzstream.next_out = pkt_data + bzstream.total_out_lo32;
1759 result = BZ2_bzDecompress(&bzstream);
1760 }
while (
result == BZ_OK && pkt_size < 10000000);
1761 pkt_size = bzstream.total_out_lo32;
1762 BZ2_bzDecompressEnd(&bzstream);
1763 if (
result != BZ_STREAM_END) {
1764 if (
result == BZ_MEM_ERROR)
1780 *buf_size = pkt_size;
1795 for (
i = 0;
i <
list->nb_elem;
i++) {
1796 const char *lang = tags[
i].
lang &&
1797 strcmp(tags[
i].lang,
"und") ? tags[
i].
lang :
NULL;
1799 if (!tags[
i].
name) {
1807 if (tags[
i].def || !lang) {
1809 if (tags[
i].
sub.nb_elem)
1816 if (tags[
i].
sub.nb_elem)
1830 if (tags[
i].target.attachuid) {
1834 if (attachment[j].
uid == tags[
i].target.attachuid &&
1835 attachment[j].stream) {
1837 &attachment[j].stream->metadata,
NULL);
1843 "The tags at index %d refer to a "
1844 "non-existent attachment %"PRId64
".\n",
1845 i, tags[
i].target.attachuid);
1847 }
else if (tags[
i].target.chapteruid) {
1851 if (chapter[j].
uid == tags[
i].target.chapteruid &&
1852 chapter[j].chapter) {
1854 &chapter[j].chapter->metadata,
NULL);
1860 "The tags at index %d refer to a non-existent chapter "
1862 i, tags[
i].target.chapteruid);
1864 }
else if (tags[
i].target.trackuid) {
1868 if (track[j].
uid == tags[
i].target.trackuid &&
1871 &track[j].stream->metadata,
NULL);
1877 "The tags at index %d refer to a non-existent track "
1879 i, tags[
i].target.trackuid);
1883 tags[
i].target.type);
1902 "Max EBML element depth (%d) reached, "
1935 for (
i = 0;
i < seekhead_list->
nb_elem;
i++) {
1937 uint32_t
id = seekheads[
i].
id;
1945 if (!elem || elem->
parsed)
1968 uint64_t index_scale = 1;
1974 index_list = &matroska->
index;
1985 for (j = 0; j < pos_list->
nb_elem; j++) {
1988 if (track && track->
stream)
2018 static const char *
const aac_profiles[] = {
"MAIN",
"LC",
"SSR" };
2064 int block_last, block_type, block_size;
2070 if (block_size >
size)
2079 chmask =
av_dict_get(dict,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK",
NULL, 0);
2084 "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
2100 int minor, micro, bttb = 0;
2105 bttb = (
minor >= 36 && minor <= 51 && micro >= 100);
2107 switch (field_order) {
2126 int *h_width,
int *h_height)
2128 switch (stereo_mode) {
2153 int has_mastering_primaries, has_mastering_luminance;
2158 mastering_meta = &
color->mastering_meta;
2160 has_mastering_primaries =
2161 mastering_meta->
r_x > 0 && mastering_meta->
r_y > 0 &&
2162 mastering_meta->
g_x > 0 && mastering_meta->
g_y > 0 &&
2163 mastering_meta->
b_x > 0 && mastering_meta->
b_y > 0 &&
2187 (
color->chroma_siting_vert - 1) << 7);
2196 (uint8_t *)metadata,
size);
2205 if (has_mastering_primaries || has_mastering_luminance) {
2214 if (has_mastering_primaries) {
2225 if (has_mastering_luminance) {
2239 const uint8_t *priv_data = mkv_projection->
private.
data;
2241 size_t spherical_size;
2242 uint32_t l = 0, t = 0,
r = 0,
b = 0;
2243 uint32_t padding = 0;
2246 if (mkv_projection->
private.
size && priv_data[0] != 0) {
2259 if (
b >= UINT_MAX - t ||
r >= UINT_MAX - l) {
2261 "Invalid bounding rectangle coordinates "
2262 "%"PRIu32
",%"PRIu32
",%"PRIu32
",%"PRIu32
"\n",
2271 if (l || t ||
r ||
b)
2284 "Unknown spherical cubemap layout %"PRIu32
"\n",
layout);
2288 padding =
AV_RB32(priv_data + 8);
2299 "Unknown spherical metadata type %"PRIu64
"\n",
2343 for (
int i = 0;
i < mappings_list->
nb_elem;
i++) {
2346 switch (mapping->
type) {
2347 case MKBETAG(
'd',
'v',
'c',
'C'):
2348 case
MKBETAG(
'd',
'v',
'v',
'C'):
2355 "Unknown block additional mapping type 0x%"PRIx64
", value %"PRIu64
", name \"%s\"\n",
2403 uint8_t *extradata =
NULL;
2404 int extradata_size = 0;
2405 int extradata_offset = 0;
2410 char* key_id_base64 =
NULL;
2419 "Unknown or unsupported track type %"PRIu64
"\n",
2438 "Invalid sample rate %f, defaulting to 8000 instead.\n",
2446 if (default_duration > UINT64_MAX || default_duration < 0) {
2448 "Invalid frame rate %e. Cannot calculate default duration.\n",
2464 if (encodings_list->
nb_elem > 1) {
2466 "Multiple combined encodings not supported");
2467 }
else if (encodings_list->
nb_elem == 1) {
2468 if (encodings[0].
type) {
2469 if (encodings[0].encryption.key_id.size > 0) {
2472 const int b64_size =
AV_BASE64_SIZE(encodings[0].encryption.key_id.size);
2474 if (key_id_base64 ==
NULL)
2478 encodings[0].encryption.key_id.data,
2479 encodings[0].encryption.key_id.size);
2481 encodings[0].
scope = 0;
2483 "Unsupported encoding type");
2496 encodings[0].
scope = 0;
2498 "Unsupported encoding type");
2508 "Failed to decode codec private data\n");
2527 encodings[0].
scope & 1 &&
2546 if (key_id_base64) {
2552 if (!strcmp(track->
codec_id,
"V_MS/VFW/FOURCC") &&
2563 extradata_offset = 40;
2564 }
else if (!strcmp(track->
codec_id,
"A_MS/ACM") &&
2578 }
else if (!strcmp(track->
codec_id,
"A_QUICKTIME")
2582 uint16_t sample_size;
2588 if (sample_size == 8) {
2591 }
else if (sample_size == 16) {
2600 }
else if (!strcmp(track->
codec_id,
"V_QUICKTIME") &&
2656 extradata[0] = (
profile << 3) | ((sri & 0x0E) >> 1);
2657 extradata[1] = ((sri & 0x01) << 7) | (track->
audio.
channels << 3);
2658 if (strstr(track->
codec_id,
"SBR")) {
2660 extradata[2] = 0x56;
2661 extradata[3] = 0xE5;
2662 extradata[4] = 0x80 | (sri << 3);
2675 AV_WB32(extradata, extradata_size);
2676 memcpy(&extradata[4],
"alac", 4);
2685 "Too large audio channel number %"PRIu64
2686 " or bitdepth %"PRIu64
". Skipping track.\n",
2695 extradata_size = 22;
2700 bytestream_put_be32(&ptr,
AV_RB32(
"TTA1"));
2701 bytestream_put_le16(&ptr, 1);
2712 extradata_offset = 26;
2727 flavor = bytestream_get_be16(&ptr);
2746 static const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 };
2755 extradata_offset = 78;
2767 "in absence of valid CodecPrivate.\n");
2784 "Unknown/unsupported AVCodecID %s.\n", track->
codec_id);
2788 "Track TimestampScale too small %f, assuming 1.0.\n",
2793 1000 * 1000 * 1000);
2802 if (strcmp(track->
language,
"und"))
2835 int display_width_mul = 1;
2836 int display_height_mul = 1;
2867 #if FF_API_R_FRAME_RATE
2887 snprintf(buf,
sizeof(buf),
"%s_%d",
2890 if (
planes[j].
uid == tracks[k].
uid && tracks[k].stream) {
2892 "stereo_mode", buf, 0);
2926 (
AVRational){1, st->codecpar->codec_id == AV_CODEC_ID_OPUS ?
2927 48000 : st->codecpar->sample_rate});
2937 if (!strcmp(track->
codec_id,
"D_WEBVTT/CAPTIONS")) {
2939 }
else if (!strcmp(track->
codec_id,
"D_WEBVTT/DESCRIPTIONS")) {
2941 }
else if (!strcmp(track->
codec_id,
"D_WEBVTT/METADATA")) {
2967 uint64_t max_start = 0;
2982 ebml.
max_size >
sizeof(uint64_t) ||
2986 "EBML version %"PRIu64
", doctype %s, doc version %"PRIu64,
2992 "EBML header using unsupported features\n"
2993 "(EBML version %"PRIu64
", doctype %s, doc version %"PRIu64
")\n",
3045 attachments = attachments_list->
elem;
3046 for (j = 0; j < attachments_list->
nb_elem; j++) {
3047 if (!(attachments[j].filename && attachments[j].mime &&
3048 attachments[j].bin.data && attachments[j].bin.size > 0)) {
3067 attachments[j].
stream = st;
3078 attachments[j].bin.size);
3090 chapters = chapters_list->
elem;
3093 (max_start == 0 || chapters[
i].start > max_start)) {
3099 max_start = chapters[
i].
start;
3147 uint32_t lace_size[256],
int *laces)
3150 uint8_t *
data = *buf;
3154 lace_size[0] =
size;
3170 for (n = 0; n < *laces - 1; n++) {
3178 lace_size[n] +=
temp;
3181 }
while (
temp == 0xff);
3186 lace_size[n] =
size - total;
3191 if (
size % (*laces))
3193 for (n = 0; n < *laces; n++)
3194 lace_size[n] =
size / *laces;
3211 total = lace_size[0] = num;
3213 for (n = 1; n < *laces - 1; n++) {
3219 if (lace_size[n - 1] + snum > (uint64_t)INT_MAX)
3222 lace_size[n] = lace_size[n - 1] + snum;
3223 total += lace_size[n];
3231 lace_size[*laces - 1] =
size - total;
3243 uint8_t *
data,
int size, uint64_t timecode,
3258 if (
size < cfs *
h / 2) {
3260 "Corrupt int4 RM-style audio packet size\n");
3263 for (x = 0; x <
h / 2; x++)
3264 memcpy(track->
audio.
buf + x * 2 *
w + y * cfs,
3265 data + x * cfs, cfs);
3269 "Corrupt sipr RM-style audio packet size\n");
3276 "Corrupt generic RM-style audio packet size\n");
3279 for (x = 0; x <
w /
sps; x++)
3281 sps * (
h * x + ((
h + 1) / 2) * (y & 1) + (y >> 1)),
3322 uint8_t *dst =
NULL;
3340 while (srclen >= 8) {
3350 multiblock = (
flags & 0x1800) != 0x1800;
3362 if (blocksize > srclen) {
3373 dstlen += blocksize + 32;
3384 memcpy(dst +
offset + 32,
src, blocksize);
3387 srclen -= blocksize;
3388 offset += blocksize + 32;
3407 int dstlen = *
size + 8;
3415 memcpy(dst + 8, *
data, dstlen - 8);
3427 uint8_t *
data,
int data_len,
3433 uint8_t *
id, *settings, *text, *buf;
3434 int id_len, settings_len, text_len;
3442 q =
data + data_len;
3447 if (*p ==
'\r' || *p ==
'\n') {
3456 if (p >= q || *p !=
'\n')
3463 if (*p ==
'\r' || *p ==
'\n') {
3464 settings_len = p - settings;
3472 if (p >= q || *p !=
'\n')
3478 while (text_len > 0) {
3479 const int len = text_len - 1;
3480 const uint8_t
c = p[
len];
3481 if (
c !=
'\r' &&
c !=
'\n')
3494 memcpy(
pkt->
data, text, text_len);
3504 memcpy(buf,
id, id_len);
3507 if (settings_len > 0) {
3515 memcpy(buf, settings, settings_len);
3542 uint64_t timecode, uint64_t lace_duration,
3544 uint8_t *additional, uint64_t additional_id,
int additional_size,
3545 int64_t discard_padding)
3547 uint8_t *pkt_data =
data;
3555 "Error parsing a wavpack block.\n");
3568 "Error parsing a prores block.\n");
3576 if (!pkt_size && !additional_size)
3595 if (additional_size > 0) {
3598 additional_size + 8);
3603 AV_WB64(side_data, additional_id);
3604 memcpy(side_data + 8, additional, additional_size);
3607 if (discard_padding) {
3618 if (discard_padding > 0) {
3619 AV_WL32(side_data + 4, discard_padding);
3621 AV_WL32(side_data, -discard_padding);
3648 int size, int64_t
pos, uint64_t cluster_time,
3650 uint8_t *additional, uint64_t additional_id,
int additional_size,
3651 int64_t cluster_pos, int64_t discard_padding)
3659 uint32_t lace_size[256];
3660 int n,
flags, laces = 0;
3662 int trust_default_duration;
3672 if (!track ||
size < 3)
3675 if (!(st = track->
stream)) {
3677 "No stream associated to TrackNumber %"PRIu64
". "
3678 "Ignoring Block with this TrackNumber.\n", num);
3684 if (block_duration > INT64_MAX)
3685 block_duration = INT64_MAX;
3694 if (cluster_time != (uint64_t) -1 &&
3695 (block_time >= 0 || cluster_time >= -block_time)) {
3696 uint64_t timecode_cluster_in_track_tb = (double) cluster_time / track->
time_scale;
3699 timecode < track->end_timecode)
3717 else if (!
ffstream(st)->skip_to_keyframe) {
3724 &pb.
pub, lace_size, &laces);
3735 trust_default_duration = 0;
3739 if (!block_duration && trust_default_duration)
3742 if (cluster_time != (uint64_t)-1 && (block_time >= 0 || cluster_time >= -block_time))
3746 for (n = 0; n < laces; n++) {
3747 int64_t lace_duration = block_duration*(n+1) / laces - block_duration*n / laces;
3748 uint8_t *out_data =
data;
3773 timecode, lace_duration,
3783 additional, additional_id, additional_size,
3790 timecode = lace_duration ? timecode + lace_duration :
AV_NOPTS_VALUE;
3822 if (res >= 0 &&
block->bin.size > 0) {
3824 uint8_t* additional =
block->additional.size > 0 ?
3831 block->additional.size, cluster->
pos,
3832 block->discard_padding);
3842 "end of segment.\n");
3874 int64_t timestamp,
int flags)
3878 AVStream *st =
s->streams[stream_index];
3957 #if CONFIG_WEBM_DASH_MANIFEST_DEMUXER
3959 int64_t start_time_ns;
3960 int64_t end_time_ns;
3961 int64_t start_offset;
3969 static CueDesc get_cue_desc(
AVFormatContext *
s, int64_t ts, int64_t cues_start) {
3978 return (CueDesc) {-1, -1, -1, -1};
3979 for (
i = 1;
i < nb_index_entries;
i++) {
3980 if (index_entries[
i - 1].timestamp * matroska->
time_scale <= ts &&
3981 index_entries[
i].timestamp * matroska->
time_scale > ts) {
3988 if (
i != nb_index_entries - 1) {
4007 int64_t cluster_pos, before_pos;
4020 uint64_t cluster_id, cluster_length;
4026 if (read < 0 || cluster_id != 0xF43B675)
4040 cluster_pos += 4 + read + cluster_length;
4053 static int buffer_size_after_time_downloaded(int64_t time_ns,
double search_sec, int64_t
bps,
4054 double min_buffer,
double*
buffer,
4058 double nano_seconds_per_second = 1000000000.0;
4059 double time_sec = time_ns / nano_seconds_per_second;
4061 int64_t time_to_search_ns = (int64_t)(search_sec * nano_seconds_per_second);
4062 int64_t end_time_ns = time_ns + time_to_search_ns;
4063 double sec_downloaded = 0.0;
4064 CueDesc desc_curr = get_cue_desc(
s, time_ns, cues_start);
4065 if (desc_curr.start_time_ns == -1)
4067 *sec_to_download = 0.0;
4070 if (time_ns > desc_curr.start_time_ns) {
4071 int64_t cue_nano = desc_curr.end_time_ns - time_ns;
4072 double percent = (double)(cue_nano) / (desc_curr.end_time_ns - desc_curr.start_time_ns);
4073 double cueBytes = (desc_curr.end_offset - desc_curr.start_offset) * percent;
4074 double timeToDownload = (cueBytes * 8.0) /
bps;
4076 sec_downloaded += (cue_nano / nano_seconds_per_second) - timeToDownload;
4077 *sec_to_download += timeToDownload;
4080 if (desc_curr.end_time_ns >= end_time_ns) {
4081 double desc_end_time_sec = desc_curr.end_time_ns / nano_seconds_per_second;
4082 double percent_to_sub = search_sec / (desc_end_time_sec - time_sec);
4083 sec_downloaded = percent_to_sub * sec_downloaded;
4084 *sec_to_download = percent_to_sub * *sec_to_download;
4087 if ((sec_downloaded + *
buffer) <= min_buffer) {
4092 desc_curr = get_cue_desc(
s, desc_curr.end_time_ns, cues_start);
4095 while (desc_curr.start_time_ns != -1) {
4096 int64_t desc_bytes = desc_curr.end_offset - desc_curr.start_offset;
4097 int64_t desc_ns = desc_curr.end_time_ns - desc_curr.start_time_ns;
4098 double desc_sec = desc_ns / nano_seconds_per_second;
4099 double bits = (desc_bytes * 8.0);
4100 double time_to_download =
bits /
bps;
4102 sec_downloaded += desc_sec - time_to_download;
4103 *sec_to_download += time_to_download;
4105 if (desc_curr.end_time_ns >= end_time_ns) {
4106 double desc_end_time_sec = desc_curr.end_time_ns / nano_seconds_per_second;
4107 double percent_to_sub = search_sec / (desc_end_time_sec - time_sec);
4108 sec_downloaded = percent_to_sub * sec_downloaded;
4109 *sec_to_download = percent_to_sub * *sec_to_download;
4111 if ((sec_downloaded + *
buffer) <= min_buffer)
4116 if ((sec_downloaded + *
buffer) <= min_buffer) {
4121 desc_curr = get_cue_desc(
s, desc_curr.end_time_ns, cues_start);
4134 static int64_t webm_dash_manifest_compute_bandwidth(
AVFormatContext *
s, int64_t cues_start)
4139 double bandwidth = 0.0;
4142 int64_t prebuffer_ns = 1000000000;
4144 double nano_seconds_per_second = 1000000000.0;
4145 int64_t prebuffered_ns = time_ns + prebuffer_ns;
4146 double prebuffer_bytes = 0.0;
4147 int64_t temp_prebuffer_ns = prebuffer_ns;
4148 int64_t pre_bytes, pre_ns;
4149 double pre_sec, prebuffer, bits_per_second;
4150 CueDesc desc_beg = get_cue_desc(
s, time_ns, cues_start);
4153 CueDesc desc_end = desc_beg;
4157 while (desc_end.start_time_ns != -1 && desc_end.end_time_ns < prebuffered_ns) {
4159 prebuffer_bytes += desc_end.end_offset - desc_end.start_offset;
4160 temp_prebuffer_ns -= desc_end.end_time_ns - desc_end.start_time_ns;
4161 desc_end = get_cue_desc(
s, desc_end.end_time_ns, cues_start);
4163 if (desc_end.start_time_ns == -1) {
4167 bits_per_second = 0.0;
4171 pre_bytes = desc_end.end_offset - desc_end.start_offset;
4172 pre_ns = desc_end.end_time_ns - desc_end.start_time_ns;
4175 pre_sec = pre_ns / nano_seconds_per_second;
4177 pre_bytes * ((temp_prebuffer_ns / nano_seconds_per_second) / pre_sec);
4179 prebuffer = prebuffer_ns / nano_seconds_per_second;
4182 bits_per_second = 0.0;
4184 int64_t desc_bytes = desc_end.end_offset - desc_beg.start_offset;
4185 int64_t desc_ns = desc_end.end_time_ns - desc_beg.start_time_ns;
4186 double desc_sec, calc_bits_per_second, percent, mod_bits_per_second;
4187 if (desc_bytes <= 0)
4190 desc_sec = desc_ns / nano_seconds_per_second;
4191 calc_bits_per_second = (desc_bytes * 8) / desc_sec;
4194 percent = (desc_bytes - prebuffer_bytes) / desc_bytes;
4195 mod_bits_per_second = calc_bits_per_second * percent;
4197 if (prebuffer < desc_sec) {
4203 int64_t
bps = (int64_t)(mod_bits_per_second) + 1;
4204 const double min_buffer = 0.0;
4205 double buffer = prebuffer;
4206 double sec_to_download = 0.0;
4208 int rv = buffer_size_after_time_downloaded(prebuffered_ns, search_sec,
bps,
4209 min_buffer, &
buffer, &sec_to_download,
4213 }
else if (rv == 0) {
4214 bits_per_second = (double)(
bps);
4219 desc_end = get_cue_desc(
s, desc_end.end_time_ns, cues_start);
4220 }
while (desc_end.start_time_ns != -1);
4222 if (bandwidth < bits_per_second) bandwidth = bits_per_second;
4224 return (int64_t)bandwidth;
4236 int64_t cues_start = -1, cues_end = -1, before_pos, bandwidth;
4245 if (
i >= seekhead_list->
nb_elem)
return -1;
4249 if (
avio_seek(matroska->
ctx->
pb, cues_start, SEEK_SET) == cues_start) {
4253 uint64_t cues_length, cues_id;
4261 cues_end = cues_start + 4 + bytes_read + cues_length - 1;
4264 if (cues_start == -1 || cues_end == -1)
return -1;
4280 if (cues_start <= init_range)
4284 bandwidth = webm_dash_manifest_compute_bandwidth(
s, cues_start);
4285 if (bandwidth < 0)
return -1;
4301 bprint.str[--bprint.len] =
'\0';
4340 buf = strrchr(
s->url,
'/');
4349 ret = webm_dash_manifest_cues(
s, init_range);
4369 #define OFFSET(x) offsetof(MatroskaDemuxContext, x)
4384 .
name =
"webm_dash_manifest",
4396 .
name =
"matroska,webm",
4398 .extensions =
"mkv,mk3d,mka,mks,webm",