Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 | 60x 60x 60x 60x 197x 1x 196x 3x 193x 65x 65x 193x 193x 193x 65x 65x 193x 190x 3x 3x 3x 3x 2x 1x 35x 35x 35x 11x 11x 35x 43x 25x 38x 43x 6x 6x 6x 3x 3x 6x 6x 8x 8x 8x 8x 8x 8x 7x 1x 7x 7x 7x 6x 39x 39x 6x 39x 38x 36x 2x 4x 4x 4x 42x 28x 14x 16x 1x 16x 16x 16x 38x 31x 7x 7x 7x 7x 38x 28x 10x 12x 12x 12x 11x 9x 2x 8x 8x 8x 29x 82x 29x 82x 77x 5x 5x 2x 1x 4x 5x 5x 1x 4x 35x 1x 34x 34x 43x 43x 32x 2x 33x 33x 33x 45x 39x 32x 45x 45x 18x 18x 17x 17x 1x 45x 17x 45x 2x 2x 2x 2x 2x 1x 1x 1x 1x 2x 38x 35x 35x 35x 35x 43x 39x 4x 4x 4x 4x 66x 66x 5x 5x 1x 4x 4x 4x 1x 1x 1x 4x 69x 69x 1x 68x 68x 68x 59x 100x 100x 68x 37x 209x 202x 7x 11x 11x 11x 162x 162x 11x 162x 16x 3x 3x 2x 3x 41x 38x 3x 1x 2x 41x 2x 8x 1x 7x 7x 1x 6x 2x 1x 1x 5x 4x 4x 2x 4x 21x 36x 37x 37x 37x 22x 41x 41x 41x 83x 65x 18x 30x 30x 30x 74x 52x 22x 22x 19x 3x 3x 9x 11x 18x 74x 74x 74x 10x 74x 23x 23x 23x 77x 37x 6x 37x 39x 39x 1x 38x 38x 13x 23x 38x 67x 62x 5x 5x 5x 5x 34x 9x 6x 6x 6x 9x 9x 9x 6x 6x 6x 6x 6x 6x 6x 6x 9x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 5x 6x 4x 4x 6x 6x 4x 6x 4x 6x 5x 5x 6x 4x 6x 4x 6x 4x 6x 4x 6x 4x 6x 4x 6x 6x 6x 6x 6x 1x 1x 5x 1x 1x 1x 4x 3x 3x 1x 2x 1x 6x 6x 1x 5x 2x 5x 2x 2x 2x 2x 3x 5x 3x 5x 3x 2x 1x 5x 2x 5x 2x 5x 2x 5x 2x 5x 2x 3x 2x 5x 2x 3x 2x 5x 2x 5x 6x 4x 4x 4x 1x 1x 1x 1x 5x 5x 5x 43x 43x 18x 25x 25x 27x 27x 27x 26x 41x 41x 41x 40x 41x 41x 41x 41x 27x 3x 3x 10x 4x 4x 10x 22x 22x 22x 1x 3x 3x 3x 4x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 22x 62x 62x 62x 62x 62x 62x 62x 66x 66x 2x 2x 64x 2x 2x 62x 59x 59x 66x 5x 2x 3x 66x 63x 63x 63x 63x 63x 2x 63x 4x 63x 63x 63x 66x 66x 62x 3x 59x 59x 58x 63x 63x 63x 9x 63x 59x 59x 56x 56x 56x 54x 56x 56x 56x 54x 56x 56x 56x 56x 59x 59x 1x 59x 58x 58x 57x 1x 1x 1x 58x 1x 1x 1x 1x 1x 1x 3x 3x 2x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 18x 18x 18x 18x 19x 16x 16x 16x 7x 7x 2x 16x 16x 1x 15x 16x 1x 16x 1x 16x 4x 16x 4x 16x 16x 18x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 5x 5x 3x 3x 5x 5x 5x 5x 5x 5x 5x 3x 1x 1x 1x 1x 2x 8x 5x 5x 5x 5x 5x 3x 4x 4x 42x 42x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 8x 8x 8x 1x 7x 1x 6x 1x 5x 5x 5x 5x 5x 6x 42x 314x 314x 261x 314x 45x 60x 60x 60x 1x | /**
* The copyright in this software is being made available under the BSD License,
* included below. This software may be subject to other third party and contributor
* rights, including patent rights, and no such rights are granted under this license.
*
* Copyright (c) 2013, Dash Industry Forum.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* * Neither the name of Dash Industry Forum nor the names of its
* contributors may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
import AdaptationSet from '../vo/AdaptationSet.js';
import BaseURL from '../vo/BaseURL.js';
import CMCDParameters from '../vo/CMCDParameters.js';
import ClientDataReporting from '../vo/ClientDataReporting.js';
import Constants from '../../streaming/constants/Constants.js';
import ContentProtection from '../vo/ContentProtection.js';
import ContentSteering from '../vo/ContentSteering.js';
import DashConstants from '../constants/DashConstants.js';
import DashJSError from '../../streaming/vo/DashJSError.js';
import Debug from '../../core/Debug.js';
import DescriptorType from '../vo/DescriptorType.js';
import Errors from '../../core/errors/Errors.js';
import Event from '../vo/Event.js';
import EventStream from '../vo/EventStream.js';
import FactoryMaker from '../../core/FactoryMaker.js';
import Mpd from '../vo/Mpd.js';
import MpdLocation from '../vo/MpdLocation.js';
import ObjectUtils from '../../streaming/utils/ObjectUtils.js';
import PatchLocation from '../vo/PatchLocation.js';
import Period from '../vo/Period.js';
import Preselection from '../vo/Preselection.js';
import ProducerReferenceTime from '../vo/ProducerReferenceTime.js';
import Representation from '../vo/Representation.js';
import URLUtils from '../../streaming/utils/URLUtils.js';
import UTCTiming from '../vo/UTCTiming.js';
import Utils from '../../core/Utils.js';
import SegmentSequenceProperties from '../vo/SegmentSequenceProperties.js';
function DashManifestModel() {
let instance,
logger,
errHandler,
BASE64;
const context = this.context;
const urlUtils = URLUtils(context).getInstance();
const isInteger = Number.isInteger || function (value) {
return typeof value === 'number' &&
isFinite(value) &&
Math.floor(value) === value;
};
function setup() {
logger = Debug(context).getInstance().getLogger(instance);
}
function getIsTypeOf(adaptation, type) {
if (!adaptation) {
throw new Error('adaptation is not defined');
}
if (!type) {
throw new Error('type is not defined');
}
// Check for thumbnail images
if (adaptation.Representation && adaptation.Representation.length) {
const essentialProperties = getEssentialProperties(adaptation.Representation[0]);
Iif (essentialProperties && essentialProperties.some(essentialProperty => Constants.THUMBNAILS_SCHEME_ID_URIS.indexOf(essentialProperty.schemeIdUri) >= 0)) {
return (type === Constants.IMAGE);
}
}
// Check ContentComponent.contentType
Iif (adaptation.ContentComponent && adaptation.ContentComponent.length > 0) {
if (adaptation.ContentComponent.length > 1) {
return (type === Constants.MUXED);
} else if (adaptation.ContentComponent[0].contentType === type) {
return true;
}
}
const mimeTypeRegEx = (type === Constants.TEXT) ? new RegExp('(ttml|vtt|wvtt|stpp)') : new RegExp(type);
// Check codecs
if (adaptation.Representation && adaptation.Representation.length) {
const codecs = adaptation.Representation[0].codecs;
Iif (mimeTypeRegEx.test(codecs)) {
return true;
}
}
// Check Adaptation's mimeType
if (adaptation.hasOwnProperty(DashConstants.MIME_TYPE)) {
return mimeTypeRegEx.test(adaptation.mimeType);
}
// Check Representation's mimeType
if (adaptation.Representation) {
let representation;
for (let i = 0; i < adaptation.Representation.length; i++) {
representation = adaptation.Representation[i];
if (representation.hasOwnProperty(DashConstants.MIME_TYPE)) {
return mimeTypeRegEx.test(representation.mimeType);
}
}
}
return false;
}
function getPreselectionIsTypeOf(preselection, adaptations, type) {
if (!preselection) {
throw new Error('preselection is not defined');
}
if (!adaptations) {
throw new Error('adaptations is not defined');
}
if (!type) {
throw new Error('type is not defined');
}
const mainAdaptationSet = getMainAdaptationSetForPreselection(preselection, adaptations);
return mainAdaptationSet ? getIsTypeOf(mainAdaptationSet, type) : false;
}
function getIsFragmented(adaptation) {
Iif (!adaptation) {
throw new Error('adaptation is not defined');
}
Iif (adaptation.hasOwnProperty(DashConstants.SEGMENT_TEMPLATE) ||
adaptation.hasOwnProperty(DashConstants.SEGMENT_TIMELINE) ||
adaptation.hasOwnProperty(DashConstants.SEGMENT_LIST) ||
adaptation.hasOwnProperty(DashConstants.SEGMENT_BASE)) {
return true;
}
if (adaptation.Representation && adaptation.Representation.length > 0) {
const representation = adaptation.Representation[0];
Iif (representation.hasOwnProperty(DashConstants.SEGMENT_TEMPLATE) ||
representation.hasOwnProperty(DashConstants.SEGMENT_TIMELINE) ||
representation.hasOwnProperty(DashConstants.SEGMENT_LIST) ||
representation.hasOwnProperty(DashConstants.SEGMENT_BASE)) {
return true;
}
}
return false;
}
function getIsAudio(adaptation) {
return getIsTypeOf(adaptation, Constants.AUDIO);
}
function getIsVideo(adaptation) {
return getIsTypeOf(adaptation, Constants.VIDEO);
}
function getIsText(adaptation) {
return getIsTypeOf(adaptation, Constants.TEXT);
}
function getIsMuxed(adaptation) {
return getIsTypeOf(adaptation, Constants.MUXED);
}
function getIsImage(adaptation) {
return getIsTypeOf(adaptation, Constants.IMAGE);
}
function getProducerReferenceTimesForAdaptation(adaptation) {
const prtArray = adaptation && adaptation.hasOwnProperty(DashConstants.PRODUCER_REFERENCE_TIME) ? adaptation[DashConstants.PRODUCER_REFERENCE_TIME] : [];
// ProducerReferenceTime elements can also be contained in Representations
const representationsArray = adaptation && adaptation.hasOwnProperty(DashConstants.REPRESENTATION) ? adaptation[DashConstants.REPRESENTATION] : [];
representationsArray.forEach((rep) => {
if (rep.hasOwnProperty(DashConstants.PRODUCER_REFERENCE_TIME)) {
prtArray.push(...rep[DashConstants.PRODUCER_REFERENCE_TIME]);
}
});
const prtsForAdaptation = [];
// Unlikely to have multiple ProducerReferenceTimes.
prtArray.forEach((prt) => {
const entry = new ProducerReferenceTime();
if (prt.hasOwnProperty(DashConstants.ID)) {
entry[DashConstants.ID] = parseInt(prt[DashConstants.ID]);
} else E{
// Ignore. Missing mandatory attribute
return;
}
if (prt.hasOwnProperty(DashConstants.WALL_CLOCK_TIME)) {
entry[DashConstants.WALL_CLOCK_TIME] = prt[DashConstants.WALL_CLOCK_TIME];
} else E{
// Ignore. Missing mandatory attribute
return;
}
if (prt.hasOwnProperty(DashConstants.PRESENTATION_TIME)) {
entry[DashConstants.PRESENTATION_TIME] = prt[DashConstants.PRESENTATION_TIME];
} else {
// Ignore. Missing mandatory attribute
return;
}
Iif (prt.hasOwnProperty(DashConstants.INBAND)) {
entry[DashConstants.INBAND] = prt[DashConstants.INBAND] !== 'false';
}
Iif (prt.hasOwnProperty(DashConstants.TYPE)) {
entry[DashConstants.TYPE] = prt[DashConstants.TYPE];
}
// Not interested in other attributes for now
// UTC element contained must be same as that in the MPD
prtsForAdaptation.push(entry);
})
return prtsForAdaptation;
}
function getLanguageForAdaptation(adaptation) {
let lang = '';
if (adaptation && adaptation.hasOwnProperty(DashConstants.LANG)) {
lang = adaptation.lang;
}
return lang;
}
function getViewpointForAdaptation(adaptation) {
if (!adaptation || !adaptation.hasOwnProperty(DashConstants.VIEWPOINT) || !adaptation[DashConstants.VIEWPOINT].length) {
return [];
}
return adaptation[DashConstants.VIEWPOINT].map(viewpoint => {
const vp = new DescriptorType();
vp.init(viewpoint);
return vp
});
}
function getRolesForAdaptation(adaptation) {
if (!adaptation || !adaptation.hasOwnProperty(DashConstants.ROLE) || !adaptation[DashConstants.ROLE].length) {
return [];
}
return adaptation[DashConstants.ROLE].map(role => {
// conceal misspelled "Main" from earlier MPEG-DASH editions (fixed with 6th edition)
if (role.schemeIdUri === Constants.DASH_ROLE_SCHEME_ID && role.value === 'Main') {
role.value = DashConstants.MAIN;
}
const r = new DescriptorType();
r.init(role);
return r
});
}
function getAccessibilityForAdaptation(adaptation) {
if (!adaptation || !adaptation.hasOwnProperty(DashConstants.ACCESSIBILITY) || !adaptation[DashConstants.ACCESSIBILITY].length) {
return [];
}
return adaptation[DashConstants.ACCESSIBILITY].map(accessibility => {
const a = new DescriptorType();
a.init(accessibility);
return a
});
}
function getAudioChannelConfigurationForAdaptation(adaptation) {
if (!adaptation || !adaptation.hasOwnProperty(DashConstants.AUDIO_CHANNEL_CONFIGURATION) || !adaptation[DashConstants.AUDIO_CHANNEL_CONFIGURATION].length) {
return [];
}
return adaptation[DashConstants.AUDIO_CHANNEL_CONFIGURATION].map(audioChanCfg => {
const acc = new DescriptorType();
acc.init(audioChanCfg);
return acc
});
}
function getAudioChannelConfigurationForRepresentation(representation) {
if (!representation || !representation.hasOwnProperty(DashConstants.AUDIO_CHANNEL_CONFIGURATION) || !representation[DashConstants.AUDIO_CHANNEL_CONFIGURATION].length) {
return [];
}
return representation[DashConstants.AUDIO_CHANNEL_CONFIGURATION].map(audioChanCfg => {
const acc = new DescriptorType();
acc.init(audioChanCfg);
return acc
});
}
function getRepresentationSortFunction() {
return (a, b) => a.bandwidth - b.bandwidth;
}
function processAdaptation(realAdaptation) {
if (realAdaptation && realAdaptation.Representation) {
realAdaptation.Representation.sort(getRepresentationSortFunction());
}
return realAdaptation;
}
function getRealAdaptations(manifest, periodIndex) {
return manifest && manifest.Period && isInteger(periodIndex) ? manifest.Period[periodIndex] ? manifest.Period[periodIndex].AdaptationSet : [] : [];
}
function getRealPeriods(manifest) {
return manifest && manifest.Period ? manifest.Period : [];
}
function getRealPeriodForIndex(index, manifest) {
const realPeriods = getRealPeriods(manifest);
if (realPeriods.length > 0 && isInteger(index)) {
return realPeriods[index];
} else {
return null;
}
}
function getAdaptationForId(id, manifest, periodIndex) {
const realAdaptations = getRealAdaptations(manifest, periodIndex);
let i,
len;
for (i = 0, len = realAdaptations.length; i < len; i++) {
if (realAdaptations[i].hasOwnProperty(DashConstants.ID) && realAdaptations[i].id === id) {
return realAdaptations[i];
}
}
return null;
}
function getAdaptationForIndex(index, manifest, periodIndex) {
const realAdaptations = getRealAdaptations(manifest, periodIndex);
if (realAdaptations.length > 0 && isInteger(index)) {
return realAdaptations[index];
} else {
return null;
}
}
function getIndexForAdaptation(realAdaptation, manifest, periodIndex) {
if (!realAdaptation) {
return -1;
}
const realAdaptations = getRealAdaptations(manifest, periodIndex);
for (let i = 0; i < realAdaptations.length; i++) {
let objectUtils = ObjectUtils(context).getInstance();
if (objectUtils.areEqual(realAdaptations[i], realAdaptation)) {
return i;
}
}
return -1;
}
function getAdaptationsForType(manifest, periodIndex, type) {
const realAdaptations = getRealAdaptations(manifest, periodIndex);
let i,
len;
const adaptations = [];
for (i = 0, len = realAdaptations.length; i < len; i++) {
if (getIsTypeOf(realAdaptations[i], type)) {
adaptations.push(processAdaptation(realAdaptations[i]));
}
}
return adaptations;
}
function getCodec(adaptation, representationIndex, addResolutionInfo) {
let codec = null;
if (adaptation && adaptation.Representation && adaptation.Representation.length > 0) {
const representation = isInteger(representationIndex) && representationIndex >= 0 && representationIndex < adaptation.Representation.length ?
adaptation.Representation[representationIndex] : adaptation.Representation[0];
if (representation) {
codec = representation.mimeType + ';codecs="' + representation.codecs + '"';
if (addResolutionInfo && representation.width !== undefined) {
codec += ';width="' + representation.width + '";height="' + representation.height + '"';
}
}
}
// If the codec contains a profiles parameter we remove it. Otherwise, it will cause problems when checking for codec capabilities of the platform
if (codec) {
codec = codec.replace(/\sprofiles=[^;]*/g, '');
}
return codec;
}
function getCodecForPreselection(preselection, adaptations, addResolutionInfo) {
let codec = null;
if (preselection && adaptations) {
const mainAdaptationSet = getMainAdaptationSetForPreselection(preselection, adaptations);
let mainAsCodec = getCodec(mainAdaptationSet, 0, addResolutionInfo);
// we just take the subparameters from the first Representation of the main AdaptationSet
if (preselection.hasOwnProperty(DashConstants.CODECS)) {
let sCodecs = preselection.codecs;
// Since Preselection elements don't get the @mimeType attribute assigned, this
// copies the media type from the main adaptationSet but takes the codec from
// the preselection.
codec = mainAsCodec.replace(/(codecs=")[^"]*(")/, `$1${sCodecs}$2`);
logger.info('Preselection has own codecs-attribute: replacing in MainAdaptationSet (was: ' + mainAsCodec + '), new Preselection codec is: ' + codec)
} else {
codec = mainAsCodec;
}
}
return codec;
}
function getMimeType(adaptation) {
return adaptation && adaptation.Representation && adaptation.Representation.length > 0 ? adaptation.Representation[0].mimeType : null;
}
function getSegmentAlignment(adaptation) {
Iif (adaptation && adaptation.hasOwnProperty(DashConstants.SEGMENT_ALIGNMENT)) {
return adaptation[DashConstants.SEGMENT_ALIGNMENT] === 'true'
}
return false
}
function getSubSegmentAlignment(adaptation) {
Iif (adaptation && adaptation.hasOwnProperty(DashConstants.SUB_SEGMENT_ALIGNMENT)) {
return adaptation[DashConstants.SUB_SEGMENT_ALIGNMENT] === 'true'
}
return false
}
function getLabelsForAdaptation(adaptation) {
if (!adaptation || !adaptation.Label) {
return [];
}
const labelArray = [];
for (let i = 0; i < adaptation.Label.length; i++) {
labelArray.push({
lang: adaptation.Label[i].lang,
text: adaptation.Label[i].__text || adaptation.Label[i]
});
}
return labelArray;
}
function isPeriodEncrypted(period) {
const contentProtectionElements = getContentProtectionByPeriod(period);
return contentProtectionElements && contentProtectionElements.length > 0;
}
function getContentProtectionByManifest(manifest) {
let protectionElements = [];
if (!manifest) {
return protectionElements
}
const mpdElements = _getContentProtectionFromElement(manifest);
protectionElements = protectionElements.concat(mpdElements);
if (manifest.hasOwnProperty(DashConstants.PERIOD) && manifest[DashConstants.PERIOD].length > 0) {
manifest[DashConstants.PERIOD].forEach((period) => {
const curr = getContentProtectionByPeriod(period)
protectionElements = protectionElements.concat(curr);
})
}
return protectionElements
}
function getContentProtectionByPeriod(period) {
let protectionElements = [];
if (!period) {
return protectionElements
}
const periodProtectionElements = _getContentProtectionFromElement(period);
protectionElements = protectionElements.concat(periodProtectionElements);
if (period.hasOwnProperty(DashConstants.ADAPTATION_SET) && period[DashConstants.ADAPTATION_SET].length > 0) {
period[DashConstants.ADAPTATION_SET].forEach((adaptation) => {
const curr = _getContentProtectionFromElement(adaptation);
protectionElements = protectionElements.concat(curr);
})
}
return protectionElements
}
function getContentProtectionByAdaptation(adaptation) {
return _getContentProtectionFromElement(adaptation);
}
function _getContentProtectionFromElement(element) {
if (!element || !element.hasOwnProperty(DashConstants.CONTENT_PROTECTION) || element.ContentProtection.length === 0) {
return [];
}
return element[DashConstants.CONTENT_PROTECTION].map(contentProtectionData => {
const contentProtection = new ContentProtection();
contentProtection.init(contentProtectionData);
return contentProtection
});
}
function getIsDynamic(manifest) {
let isDynamic = false;
if (manifest && manifest.hasOwnProperty('type')) {
isDynamic = (manifest.type === DashConstants.DYNAMIC);
}
return isDynamic;
}
function getId(manifest) {
return (manifest && manifest[DashConstants.ID]) || null;
}
function hasProfile(manifest, profile) {
let has = false;
if (manifest && manifest.profiles && manifest.profiles.length > 0) {
has = (manifest.profiles.indexOf(profile) !== -1);
}
return has;
}
function getDuration(manifest) {
let mpdDuration;
//@mediaPresentationDuration specifies the duration of the entire Media Presentation.
//If the attribute is not present, the duration of the Media Presentation is unknown.
if (manifest && manifest.hasOwnProperty(DashConstants.MEDIA_PRESENTATION_DURATION)) {
mpdDuration = manifest.mediaPresentationDuration;
} else if (manifest && manifest.type === 'dynamic') {
mpdDuration = Number.POSITIVE_INFINITY;
} else {
mpdDuration = Number.MAX_SAFE_INTEGER || Number.MAX_VALUE;
}
return mpdDuration;
}
function getBandwidth(representation) {
return representation && representation.bandwidth ? representation.bandwidth : NaN;
}
function getFramerate(realRepresentation) {
if (!realRepresentation) {
return null
}
const frameRate = realRepresentation[DashConstants.FRAMERATE];
if (!frameRate) {
return null
}
if (typeof frameRate === 'string' && frameRate.includes('/')) {
const [numerator, denominator] = frameRate.split('/').map(value => parseInt(value, 10));
if (!isNaN(numerator) && !isNaN(denominator) && denominator !== 0) {
return numerator / denominator;
}
}
return parseInt(frameRate);
}
function getManifestUpdatePeriod(manifest, latencyOfLastUpdate = 0) {
let delay = NaN;
if (manifest && manifest.hasOwnProperty(DashConstants.MINIMUM_UPDATE_PERIOD)) {
delay = manifest.minimumUpdatePeriod;
}
return isNaN(delay) ? delay : Math.max(delay - latencyOfLastUpdate, 1);
}
function getPublishTime(manifest) {
return manifest && manifest.hasOwnProperty(DashConstants.PUBLISH_TIME) ? new Date(manifest[DashConstants.PUBLISH_TIME]) : null;
}
function getRepresentationCount(adaptation) {
return adaptation && adaptation.Representation ? adaptation.Representation.length : 0;
}
function getBitrateListForAdaptation(realAdaptation) {
const processedRealAdaptation = processAdaptation(realAdaptation);
const realRepresentations = processedRealAdaptation && processedRealAdaptation.Representation ? processedRealAdaptation.Representation : [];
return realRepresentations.map((realRepresentation) => {
return {
bandwidth: realRepresentation.bandwidth,
width: realRepresentation.width || 0,
height: realRepresentation.height || 0,
scanType: realRepresentation.scanType || null,
id: realRepresentation.id || null
};
});
}
function getSelectionPriority(realAdaption) {
try {
const priority = realAdaption && typeof realAdaption.selectionPriority !== 'undefined' ? parseInt(realAdaption.selectionPriority) : 1;
return isNaN(priority) ? 1 : priority;
} catch (e) {
return 1;
}
}
// propertyType is one of { DashConstants.ESSENTIAL_PROPERTY, DashConstants.SUPPLEMENTAL_PROPERTY }
function _getProperties(propertyType, element) {
if (!element || !element.hasOwnProperty(propertyType) || !element[propertyType].length) {
return [];
}
return element[propertyType].map((property) => {
const s = new DescriptorType();
s.init(property);
return s
});
}
function _getPropertiesCommonToAllRepresentations(propertyType, repr) {
if (!repr || !repr.length) {
return [];
}
let propertiesOfFirstRepresentation = repr[0][propertyType] || [];
if (propertiesOfFirstRepresentation.length === 0) {
return [];
}
Iif (repr.length === 1) {
return propertiesOfFirstRepresentation;
}
// now, only return properties present on all Representations
// repr.legth is always >= 2
return propertiesOfFirstRepresentation.filter(prop => {
return repr.slice(1).every(currRep => {
return currRep.hasOwnProperty(propertyType) && currRep[propertyType].some(e => {
return e.schemeIdUri === prop.schemeIdUri && e.value === prop.value;
});
});
})
}
function _getCombinedPropertiesForAdaptationSet(propertyType, adaptation) {
Iif (!adaptation) {
return [];
}
let allProperties = _getPropertiesCommonToAllRepresentations(propertyType, adaptation[DashConstants.REPRESENTATION]);
if (adaptation.hasOwnProperty(propertyType) && adaptation[propertyType].length) {
allProperties.push(...adaptation[propertyType])
}
// we don't check whether there are duplicates on AdaptationSets and Representations
return allProperties.map(essentialProperty => {
const s = new DescriptorType();
s.init(essentialProperty);
return s
});
}
function getEssentialProperties(element) {
return _getProperties(DashConstants.ESSENTIAL_PROPERTY, element);
}
function getCombinedEssentialPropertiesForAdaptationSet(adaptation) {
return _getCombinedPropertiesForAdaptationSet(DashConstants.ESSENTIAL_PROPERTY, adaptation);
}
function getSupplementalProperties(element) {
return _getProperties(DashConstants.SUPPLEMENTAL_PROPERTY, element);
}
function getCombinedSupplementalPropertiesForAdaptationSet(adaptation) {
return _getCombinedPropertiesForAdaptationSet(DashConstants.SUPPLEMENTAL_PROPERTY, adaptation);
}
function getSegmentSequencePropertiesForAdaptationSet(adaptation) {
const segmentSequenceProperties = [];
if (!adaptation) {
return segmentSequenceProperties;
}
segmentSequenceProperties.push(..._getSegmentSequencePropertiesForElement(adaptation));
if (adaptation.Representation && adaptation.Representation.length) {
adaptation.Representation.forEach((representation) => {
segmentSequenceProperties.push(..._getSegmentSequencePropertiesForElement(representation));
})
}
return segmentSequenceProperties;
}
function _getSegmentSequencePropertiesForElement(element) {
if (!element || !element.hasOwnProperty(DashConstants.SEGMENT_SEQUENCE_PROPERTIES) || !element[DashConstants.SEGMENT_SEQUENCE_PROPERTIES].length) {
return [];
}
return element[DashConstants.SEGMENT_SEQUENCE_PROPERTIES].map((property) => {
const segmentSequenceProperties = new SegmentSequenceProperties(property);
segmentSequenceProperties.init(property);
return segmentSequenceProperties
});
}
function getRepresentationFor(index, adaptation) {
return adaptation && adaptation.Representation && adaptation.Representation.length > 0 &&
isInteger(index) ? adaptation.Representation[index] : null;
}
function getRealAdaptationFor(voAdaptation) {
if (voAdaptation && voAdaptation.period && isInteger(voAdaptation.period.index)) {
const periodArray = voAdaptation.period.mpd.manifest.Period[voAdaptation.period.index];
if (periodArray && periodArray.AdaptationSet && isInteger(voAdaptation.index)) {
return processAdaptation(periodArray.AdaptationSet[voAdaptation.index]);
}
}
}
function getRepresentationsForAdaptation(voAdaptation, mediaInfo) {
const voRepresentations = [];
const processedRealAdaptation = getRealAdaptationFor(voAdaptation);
let baseUrl;
if (processedRealAdaptation && processedRealAdaptation.Representation) {
// TODO: TO BE REMOVED. We should get just the baseUrl elements that affects to the representations
// that we are processing. Making it works properly will require much further changes and given
// parsing base Urls parameters is needed for our ultra low latency examples, we will
// keep this "tricky" code until the real (and good) solution comes
if (voAdaptation && voAdaptation.period && isInteger(voAdaptation.period.index)) {
const baseUrls = getBaseURLsFromElement(voAdaptation.period.mpd.manifest);
if (baseUrls) {
baseUrl = baseUrls[0];
}
}
for (let i = 0, len = processedRealAdaptation.Representation.length; i < len; ++i) {
const realRepresentation = processedRealAdaptation.Representation[i];
const voRepresentation = _createVoRepresentation(mediaInfo, realRepresentation, voAdaptation, processedRealAdaptation, baseUrl, i)
voRepresentations.push(voRepresentation);
}
}
return voRepresentations;
}
function _createVoRepresentation(mediaInfo, realRepresentation, voAdaptation, processedRealAdaptation, baseUrl, index) {
const voRepresentation = new Representation();
_assignDefaultAttributesToVoRepresentation(voRepresentation, realRepresentation, voAdaptation, mediaInfo, index);
const { segmentInfo, segmentInfoType } = _deriveSegmentInfo(realRepresentation);
voRepresentation.segmentInfoType = segmentInfoType
_processSegmentInfo(segmentInfo, segmentInfoType, voRepresentation, processedRealAdaptation, realRepresentation, baseUrl);
_assignPixelValues(voRepresentation)
return voRepresentation
}
function _assignDefaultAttributesToVoRepresentation(voRepresentation, realRepresentation, voAdaptation, mediaInfo, index) {
voRepresentation.index = index;
voRepresentation.adaptation = voAdaptation;
voRepresentation.mediaInfo = mediaInfo;
if (realRepresentation.hasOwnProperty(DashConstants.ID)) {
voRepresentation.id = realRepresentation.id;
}
if (realRepresentation.hasOwnProperty(DashConstants.CODECS)) {
voRepresentation.codecs = realRepresentation.codecs;
voRepresentation.codecFamily = Utils.getCodecFamily(voRepresentation.codecs);
}
Iif (realRepresentation.hasOwnProperty(DashConstants.DEPENDENCY_ID)) {
// According to spec, the DEPENDENCY_ID attribute is a space-separated list of ID values
// Only using the first ID from this list as the handling of multiple IDs is not supported yet
const dependencyIdListString = realRepresentation[DashConstants.DEPENDENCY_ID].toString();
const dependencyIds = dependencyIdListString.split(' ');
const dependencyId = dependencyIds[0];
voRepresentation.dependencyId = dependencyId;
voRepresentation.dependentRepresentation = new Representation();
voRepresentation.dependentRepresentation.id = dependencyId;
}
if (realRepresentation.hasOwnProperty(DashConstants.MIME_TYPE)) {
voRepresentation.mimeType = realRepresentation[DashConstants.MIME_TYPE];
}
if (realRepresentation.hasOwnProperty(DashConstants.CODEC_PRIVATE_DATA)) {
voRepresentation.codecPrivateData = realRepresentation.codecPrivateData;
}
if (realRepresentation.hasOwnProperty(DashConstants.BANDWITH)) {
voRepresentation.bandwidth = realRepresentation.bandwidth;
voRepresentation.bitrateInKbit = realRepresentation.bandwidth / 1000;
}
if (realRepresentation.hasOwnProperty(DashConstants.WIDTH)) {
voRepresentation.width = realRepresentation.width;
}
if (realRepresentation.hasOwnProperty(DashConstants.HEIGHT)) {
voRepresentation.height = realRepresentation.height;
}
if (realRepresentation.hasOwnProperty(DashConstants.SCAN_TYPE)) {
voRepresentation.scanType = realRepresentation.scanType;
}
if (realRepresentation.hasOwnProperty(DashConstants.FRAMERATE)) {
voRepresentation.frameRate = getFramerate(realRepresentation);
}
if (realRepresentation.hasOwnProperty(DashConstants.QUALITY_RANKING)) {
voRepresentation.qualityRanking = realRepresentation[DashConstants.QUALITY_RANKING];
}
if (realRepresentation.hasOwnProperty(DashConstants.MAX_PLAYOUT_RATE)) {
voRepresentation.maxPlayoutRate = realRepresentation.maxPlayoutRate;
}
voRepresentation.essentialProperties = getEssentialProperties(realRepresentation);
voRepresentation.supplementalProperties = getSupplementalProperties(realRepresentation);
voRepresentation.segmentSequenceProperties = _getSegmentSequencePropertiesForElement(realRepresentation);
voRepresentation.path = [voAdaptation.period.index, voAdaptation.index, index];
}
function _deriveSegmentInfo(realRepresentation) {
let segmentInfo;
let segmentInfoType;
if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_BASE)) {
segmentInfo = realRepresentation.SegmentBase;
segmentInfoType = DashConstants.SEGMENT_BASE;
} else if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_LIST)) {
segmentInfo = realRepresentation.SegmentList;
if (segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE)) {
segmentInfoType = DashConstants.SEGMENT_TIMELINE;
} else E{
segmentInfoType = DashConstants.SEGMENT_LIST;
}
} else if (realRepresentation.hasOwnProperty(DashConstants.SEGMENT_TEMPLATE)) {
segmentInfo = realRepresentation.SegmentTemplate;
if (segmentInfo.hasOwnProperty(DashConstants.SEGMENT_TIMELINE)) {
segmentInfoType = DashConstants.SEGMENT_TIMELINE;
} else {
segmentInfoType = DashConstants.SEGMENT_TEMPLATE;
}
} else {
segmentInfoType = DashConstants.BASE_URL;
}
return { segmentInfo, segmentInfoType }
}
function _processSegmentInfo(segmentInfo, segmentInfoType, voRepresentation, processedRealAdaptation, realRepresentation, baseUrl) {
if (!segmentInfo) {
return
}
if (segmentInfo.hasOwnProperty(DashConstants.INITIALIZATION_MINUS)) {
voRepresentation.initialization = segmentInfo.initialization.split('$Bandwidth$')
.join(realRepresentation.bandwidth).split('$RepresentationID$').join(realRepresentation.id);
}
if (segmentInfo.hasOwnProperty(DashConstants.INITIALIZATION)) {
const initialization = segmentInfo.Initialization;
if (initialization.hasOwnProperty(DashConstants.SOURCE_URL)) {
voRepresentation.initialization = initialization.sourceURL;
}
Iif (initialization.hasOwnProperty(DashConstants.RANGE)) {
voRepresentation.range = initialization.range;
// initialization source url will be determined from
// BaseURL when resolved at load time.
}
} else Iif (getIsText(processedRealAdaptation) &&
getIsFragmented(processedRealAdaptation) &&
processedRealAdaptation.mimeType &&
processedRealAdaptation.mimeType.indexOf('application/mp4') === -1) {
voRepresentation.range = 0;
}
if (segmentInfo.hasOwnProperty(DashConstants.TIMESCALE)) {
voRepresentation.timescale = segmentInfo.timescale;
}
if (segmentInfo.hasOwnProperty(DashConstants.DURATION)) {
// TODO according to the spec @maxSegmentDuration specifies the maximum duration of any Segment in any Representation in the Media Presentation
// It is also said that for a SegmentTimeline any @d value shall not exceed the value of MPD@maxSegmentDuration, but nothing is said about
// SegmentTemplate @duration attribute. We need to find out if @maxSegmentDuration should be used instead of calculated duration if the the duration
// exceeds @maxSegmentDuration
voRepresentation.segmentDuration = segmentInfo.duration / voRepresentation.timescale;
} else if (segmentInfoType === DashConstants.SEGMENT_TIMELINE) {
voRepresentation.segmentDuration = calcSegmentDuration(segmentInfo.SegmentTimeline) / voRepresentation.timescale;
}
if (segmentInfo.hasOwnProperty(DashConstants.MEDIA)) {
voRepresentation.media = segmentInfo.media;
}
if (segmentInfo.hasOwnProperty(DashConstants.START_NUMBER)) {
voRepresentation.startNumber = parseInt(segmentInfo.startNumber);
}
if (segmentInfo.hasOwnProperty(DashConstants.INDEX_RANGE)) {
voRepresentation.indexRange = segmentInfo.indexRange;
}
if (segmentInfo.hasOwnProperty(DashConstants.PRESENTATION_TIME_OFFSET)) {
voRepresentation.presentationTimeOffset = segmentInfo.presentationTimeOffset / voRepresentation.timescale;
}
if (segmentInfo.hasOwnProperty(DashConstants.AVAILABILITY_TIME_OFFSET)) {
voRepresentation.availabilityTimeOffset = segmentInfo.availabilityTimeOffset;
} else if (baseUrl && baseUrl.availabilityTimeOffset !== undefined) {
voRepresentation.availabilityTimeOffset = baseUrl.availabilityTimeOffset;
}
if (segmentInfo.hasOwnProperty(DashConstants.AVAILABILITY_TIME_COMPLETE)) {
voRepresentation.availabilityTimeComplete = segmentInfo.availabilityTimeComplete !== 'false';
} else if (baseUrl && baseUrl.availabilityTimeComplete !== undefined) {
voRepresentation.availabilityTimeComplete = baseUrl.availabilityTimeComplete;
}
if (segmentInfo.hasOwnProperty(DashConstants.END_NUMBER)) {
voRepresentation.endNumber = segmentInfo[DashConstants.END_NUMBER];
}
voRepresentation.mseTimeOffset = _calcMseTimeOffset(voRepresentation);
}
function _assignPixelValues(voRepresentation) {
if (!isNaN(voRepresentation.width) && !isNaN(voRepresentation.height) && !isNaN(voRepresentation.frameRate)) {
voRepresentation.pixelsPerSecond = Math.max(1, voRepresentation.width * voRepresentation.height * voRepresentation.frameRate)
if (!isNaN(voRepresentation.bandwidth)) {
voRepresentation.bitsPerPixel = voRepresentation.bandwidth / voRepresentation.pixelsPerSecond
}
}
}
function calcSegmentDuration(segmentTimeline) {
Iif (!segmentTimeline || !segmentTimeline.S) {
return NaN;
}
let s0 = segmentTimeline.S[0];
let s1 = segmentTimeline.S[1];
return s0.hasOwnProperty('d') ? s0.d : (s1.t - s0.t);
}
function _calcMseTimeOffset(representation) {
// The MSEOffset is offset from AST for media. It is Period@start - presentationTimeOffset
const presentationOffset = representation.presentationTimeOffset;
const periodStart = representation.adaptation.period.start;
return (periodStart - presentationOffset);
}
function _convertType(element) {
Iif (getIsMuxed(element)) {
return Constants.MUXED;
} else if (getIsAudio(element)) {
return Constants.AUDIO;
} else if (getIsVideo(element)) {
return Constants.VIDEO;
} else Eif (getIsText(element)) {
return Constants.TEXT;
} else if (getIsImage(element)) {
return Constants.IMAGE;
} else {
logger.warn('Unknown Preselection stream type');
}
return null;
}
function getAdaptationsForPeriod(voPeriod) {
const realPeriod = voPeriod && isInteger(voPeriod.index) ? voPeriod.mpd.manifest.Period[voPeriod.index] : null;
const voAdaptations = [];
let voAdaptationSet,
realAdaptationSet,
i;
if (realPeriod && realPeriod.AdaptationSet) {
for (i = 0; i < realPeriod.AdaptationSet.length; i++) {
realAdaptationSet = realPeriod.AdaptationSet[i];
voAdaptationSet = new AdaptationSet();
if (realAdaptationSet.hasOwnProperty(DashConstants.ID)) {
voAdaptationSet.id = realAdaptationSet.id;
}
voAdaptationSet.index = i;
voAdaptationSet.period = voPeriod;
voAdaptationSet.type = _convertType(realAdaptationSet);
voAdaptations.push(voAdaptationSet);
}
}
return voAdaptations;
}
function _getAllAdaptationSetsForPreselection(preselection, adaptations) {
Iif (!preselection || !preselection.hasOwnProperty(DashConstants.PRESELECTION_COMPONENTS) || !Array.isArray(adaptations)) {
return undefined;
}
const preselectionComponentIds = String(preselection.preselectionComponents).split(' ');
return preselectionComponentIds.map(c => adaptations.find(adaptation => adaptation.id === c));
}
function getMainAdaptationSetForPreselection(preselection, adaptations) {
Iif (!preselection || !preselection.hasOwnProperty(DashConstants.PRESELECTION_COMPONENTS) || !Array.isArray(adaptations)) {
return undefined;
}
const preselectionComponentIds = String(preselection.preselectionComponents).split(' ');
return adaptations.find(adaptation => adaptation.id === preselectionComponentIds[0]);
}
function getCommonRepresentationForPreselection(preselection, adaptations) {
if (!preselection || !Array.isArray(adaptations)) {
return undefined;
}
const mainAS = getMainAdaptationSetForPreselection(preselection, adaptations);
return mainAS.Representation[0];
}
function getPreselectionsForPeriod(voPeriod) {
const realPeriod = voPeriod && isInteger(voPeriod.index) ? voPeriod.mpd.manifest.Period[voPeriod.index] : null;
const voPreselections = [];
let voPreselection,
realPreselection,
i;
if (realPeriod && realPeriod.Preselection) {
for (i = 0; i < realPeriod.Preselection.length; i++) {
realPreselection = realPeriod.Preselection[i];
voPreselection = new Preselection();
const preselectionAdaptationSets = _getAllAdaptationSetsForPreselection(realPreselection, realPeriod.AdaptationSet);
let allComponentsAvailable = preselectionAdaptationSets.every(adaptation => !!adaptation);
// up to now, we only support single-representation preselections, not multi-representation
if (allComponentsAvailable && preselectionAdaptationSets.length === 1) {
if (realPreselection.hasOwnProperty(DashConstants.ID)) {
voPreselection.id = realPreselection.id;
}
voPreselection.index = i;
voPreselection.period = voPeriod;
Iif (realPreselection.hasOwnProperty(DashConstants.TAG)) {
voPreselection.tag = realPreselection.tag;
}
if (realPreselection.hasOwnProperty(DashConstants.PRESELECTION_COMPONENTS)) {
voPreselection.preselectionComponents = preselectionAdaptationSets;
} else E{
logger.warn('Preselection (index: ' + voPreselection.index + ') missing component(s)');
}
Iif (realPreselection.hasOwnProperty(DashConstants.ORDER)) {
voPreselection.order = realPreselection.order;
}
voPreselection.type = _convertType(preselectionAdaptationSets[0]);
voPreselections.push(voPreselection);
} else {
logger.warn('Preselection removed because we don\'t support multi-representation preselections or not all components available.');
}
}
}
return voPreselections;
}
function getRegularPeriods(mpd) {
const isDynamic = mpd ? getIsDynamic(mpd.manifest) : false;
const voPeriods = [];
let realPreviousPeriod = null;
let realPeriod = null;
let voPreviousPeriod = null;
let voPeriod = null;
let len,
i;
for (i = 0, len = mpd && mpd.manifest && mpd.manifest.Period ? mpd.manifest.Period.length : 0; i < len; i++) {
realPeriod = mpd.manifest.Period[i];
// If the attribute @start is present in the Period, then the
// Period is a regular Period and the PeriodStart is equal
// to the value of this attribute.
if (realPeriod.hasOwnProperty(DashConstants.START)) {
voPeriod = new Period();
voPeriod.start = realPeriod.start;
}
// If the @start attribute is absent, but the previous Period element contains a @duration attribute then this new Period is also a regular Period. The start time of the new Period PeriodStart is the sum of the start time of the previous Period PeriodStart and the value of the attribute @duration of the previous Period.
else if (realPreviousPeriod !== null && realPreviousPeriod.hasOwnProperty(DashConstants.DURATION) && voPreviousPeriod !== null) {
voPeriod = new Period();
voPeriod.start = parseFloat((voPreviousPeriod.start + voPreviousPeriod.duration).toFixed(5));
}
// If (i) @start attribute is absent, and (ii) the Period element is the first in the MPD, and (iii) the MPD@type is 'static', then the PeriodStart time shall be set to zero.
else if (i === 0 && !isDynamic) {
voPeriod = new Period();
voPeriod.start = 0;
}
// The Period extends until the PeriodStart of the next Period.
// The difference between the PeriodStart time of a Period and
// the PeriodStart time of the following Period.
if (voPreviousPeriod !== null && isNaN(voPreviousPeriod.duration)) {
if (voPeriod !== null) {
voPreviousPeriod.duration = parseFloat((voPeriod.start - voPreviousPeriod.start).toFixed(5));
} else {
logger.warn('First period duration could not be calculated because lack of start and duration period properties. This will cause timing issues during playback');
}
}
if (voPeriod !== null) {
voPeriod.id = getPeriodId(realPeriod, i);
voPeriod.index = i;
voPeriod.mpd = mpd;
voPeriod.isEncrypted = isPeriodEncrypted(realPeriod);
if (realPeriod.hasOwnProperty(DashConstants.DURATION)) {
voPeriod.duration = realPeriod.duration;
}
if (voPreviousPeriod) {
voPreviousPeriod.nextPeriodId = voPeriod.id;
}
voPeriods.push(voPeriod);
realPreviousPeriod = realPeriod;
voPreviousPeriod = voPeriod;
}
realPeriod = null;
voPeriod = null;
}
if (voPeriods.length === 0) {
return voPeriods;
}
// The last Period extends until the end of the Media Presentation.
// The difference between the PeriodStart time of the last Period
// and the mpd duration
if (voPreviousPeriod !== null && isNaN(voPreviousPeriod.duration)) {
voPreviousPeriod.duration = parseFloat((getEndTimeForLastPeriod(voPreviousPeriod) - voPreviousPeriod.start).toFixed(5));
}
return voPeriods;
}
function getPeriodId(realPeriod, i) {
Iif (!realPeriod) {
throw new Error('Period cannot be null or undefined');
}
let id = Period.DEFAULT_ID + '_' + i;
if (realPeriod.hasOwnProperty(DashConstants.ID) && realPeriod.id.toString().length > 0 && realPeriod.id !== '__proto__') {
id = realPeriod.id.toString();
}
return id;
}
function getMpd(manifest) {
const mpd = new Mpd();
if (manifest) {
mpd.manifest = manifest;
Iif (manifest.hasOwnProperty(DashConstants.AVAILABILITY_START_TIME)) {
mpd.availabilityStartTime = new Date(manifest.availabilityStartTime.getTime());
} else {
if (manifest.loadedTime) {
mpd.availabilityStartTime = new Date(manifest.loadedTime.getTime());
}
}
Iif (manifest.hasOwnProperty(DashConstants.AVAILABILITY_END_TIME)) {
mpd.availabilityEndTime = new Date(manifest.availabilityEndTime.getTime());
}
Iif (manifest.hasOwnProperty(DashConstants.MINIMUM_UPDATE_PERIOD)) {
mpd.minimumUpdatePeriod = manifest.minimumUpdatePeriod;
}
if (manifest.hasOwnProperty(DashConstants.MEDIA_PRESENTATION_DURATION)) {
mpd.mediaPresentationDuration = manifest.mediaPresentationDuration;
}
Iif (manifest.hasOwnProperty(DashConstants.SUGGESTED_PRESENTATION_DELAY)) {
mpd.suggestedPresentationDelay = manifest.suggestedPresentationDelay;
}
Iif (manifest.hasOwnProperty(DashConstants.TIMESHIFT_BUFFER_DEPTH)) {
mpd.timeShiftBufferDepth = manifest.timeShiftBufferDepth;
}
Iif (manifest.hasOwnProperty(DashConstants.MAX_SEGMENT_DURATION)) {
mpd.maxSegmentDuration = manifest.maxSegmentDuration;
}
Iif (manifest.hasOwnProperty(DashConstants.PUBLISH_TIME)) {
mpd.publishTime = new Date(manifest.publishTime);
}
}
return mpd;
}
function checkConfig() {
if (!errHandler || !errHandler.hasOwnProperty('error')) {
throw new Error(Constants.MISSING_CONFIG_ERROR);
}
}
function getEndTimeForLastPeriod(voPeriod) {
checkConfig();
const isDynamic = getIsDynamic(voPeriod.mpd.manifest);
let periodEnd;
if (voPeriod.mpd.manifest.mediaPresentationDuration) {
periodEnd = voPeriod.mpd.manifest.mediaPresentationDuration;
} else Iif (voPeriod.duration) {
periodEnd = voPeriod.duration;
} else Iif (isDynamic) {
periodEnd = Number.POSITIVE_INFINITY;
} else {
errHandler.error(new DashJSError(Errors.MANIFEST_ERROR_ID_PARSE_CODE, 'Must have @mediaPresentationDuration on MPD or an explicit @duration on the last period.', voPeriod));
}
return periodEnd;
}
function getEventsForPeriod(period) {
const manifest = period && period.mpd && period.mpd.manifest ? period.mpd.manifest : null;
const periodArray = manifest ? manifest.Period : null;
const eventStreams = periodArray && period && isInteger(period.index) ? periodArray[period.index].EventStream : null;
const events = [];
let i,
j;
Iif (eventStreams) {
for (i = 0; i < eventStreams.length; i++) {
const eventStream = new EventStream();
eventStream.period = period;
eventStream.timescale = 1;
if (eventStreams[i].hasOwnProperty(Constants.SCHEME_ID_URI)) {
eventStream.schemeIdUri = eventStreams[i][Constants.SCHEME_ID_URI];
} else {
throw new Error('Invalid EventStream. SchemeIdUri has to be set');
}
if (eventStreams[i].hasOwnProperty(DashConstants.TIMESCALE)) {
eventStream.timescale = eventStreams[i][DashConstants.TIMESCALE];
}
if (eventStreams[i].hasOwnProperty(DashConstants.VALUE)) {
eventStream.value = eventStreams[i][DashConstants.VALUE];
}
if (eventStreams[i].hasOwnProperty(DashConstants.PRESENTATION_TIME_OFFSET)) {
eventStream.presentationTimeOffset = eventStreams[i][DashConstants.PRESENTATION_TIME_OFFSET];
}
for (j = 0; eventStreams[i].Event && j < eventStreams[i].Event.length; j++) {
const currentMpdEvent = eventStreams[i].Event[j];
const event = new Event();
event.presentationTime = 0;
event.eventStream = eventStream;
if (currentMpdEvent.hasOwnProperty(DashConstants.PRESENTATION_TIME)) {
event.presentationTime = currentMpdEvent.presentationTime;
}
const presentationTimeOffset = eventStream.presentationTimeOffset ? eventStream.presentationTimeOffset / eventStream.timescale : 0;
event.calculatedPresentationTime = event.presentationTime / eventStream.timescale + period.start - presentationTimeOffset;
if (currentMpdEvent.hasOwnProperty(DashConstants.DURATION)) {
event.duration = currentMpdEvent.duration / eventStream.timescale;
}
if (currentMpdEvent.hasOwnProperty(DashConstants.ID)) {
event.id = parseInt(currentMpdEvent.id);
} else {
event.id = null;
}
if (currentMpdEvent.Signal && currentMpdEvent.Signal.Binary && currentMpdEvent.Signal.Binary.__text) {
// toString is used to manage both regular and namespaced tags
event.messageData = BASE64.decodeArray(currentMpdEvent.Signal.Binary.__text.toString());
} else {
// From Cor.1: 'NOTE: this attribute is an alternative
// to specifying a complete XML element(s) in the Event.
// It is useful when an event leans itself to a compact
// string representation'.
event.messageData =
currentMpdEvent.messageData ||
currentMpdEvent.__cdata ||
currentMpdEvent.__text;
}
events.push(event);
}
}
}
return events;
}
function getEventStreams(inbandStreams, representation, period) {
const eventStreams = [];
let i;
if (!inbandStreams) {
return eventStreams;
}
for (i = 0; i < inbandStreams.length; i++) {
const eventStream = new EventStream();
eventStream.timescale = 1;
eventStream.representation = representation;
if (inbandStreams[i].hasOwnProperty(Constants.SCHEME_ID_URI)) {
eventStream.schemeIdUri = inbandStreams[i].schemeIdUri;
} else {
throw new Error('Invalid EventStream. SchemeIdUri has to be set');
}
if (inbandStreams[i].hasOwnProperty(DashConstants.TIMESCALE)) {
eventStream.timescale = inbandStreams[i].timescale;
}
if (inbandStreams[i].hasOwnProperty(DashConstants.VALUE)) {
eventStream.value = inbandStreams[i].value;
}
eventStreams.push(eventStream);
eventStream.period = period;
}
return eventStreams;
}
function getEventStreamForAdaptationSet(manifest, adaptation, period) {
let inbandStreams,
periodArray,
adaptationArray;
Iif (manifest && manifest.Period && adaptation && adaptation.period && isInteger(adaptation.period.index)) {
periodArray = manifest.Period[adaptation.period.index];
if (periodArray && periodArray.AdaptationSet && isInteger(adaptation.index)) {
adaptationArray = periodArray.AdaptationSet[adaptation.index];
if (adaptationArray) {
inbandStreams = adaptationArray.InbandEventStream;
}
}
}
return getEventStreams(inbandStreams, null, period);
}
function getEventStreamForRepresentation(manifest, representation, period) {
let inbandStreams,
periodArray,
adaptationArray,
representationArray;
if (manifest && manifest.Period && representation && representation.adaptation && representation.adaptation.period && isInteger(representation.adaptation.period.index)) {
periodArray = manifest.Period[representation.adaptation.period.index];
if (periodArray && periodArray.AdaptationSet && isInteger(representation.adaptation.index)) {
adaptationArray = periodArray.AdaptationSet[representation.adaptation.index];
if (adaptationArray && adaptationArray.Representation && isInteger(representation.index)) {
representationArray = adaptationArray.Representation[representation.index];
if (representationArray) {
inbandStreams = representationArray.InbandEventStream;
}
}
}
}
return getEventStreams(inbandStreams, representation, period);
}
function getUTCTimingSources(manifest) {
const isDynamic = getIsDynamic(manifest);
const hasAST = manifest ? manifest.hasOwnProperty(DashConstants.AVAILABILITY_START_TIME) : false;
const utcTimingsArray = manifest ? manifest.UTCTiming : null;
const utcTimingEntries = [];
// do not bother synchronizing the clock unless MPD is live,
// or it is static and has availabilityStartTime attribute
Iif ((isDynamic || hasAST)) {
if (utcTimingsArray) {
// the order is important here - 23009-1 states that the order
// in the manifest "indicates relative preference, first having
// the highest, and the last the lowest priority".
utcTimingsArray.forEach(function (utcTiming) {
const entry = new UTCTiming();
if (utcTiming.hasOwnProperty(Constants.SCHEME_ID_URI)) {
entry.schemeIdUri = utcTiming.schemeIdUri;
} else {
// entries of type DescriptorType with no schemeIdUri
// are meaningless. let's just ignore this entry and
// move on.
return;
}
// this is (incorrectly) interpreted as a number - schema
// defines it as a string
if (utcTiming.hasOwnProperty(DashConstants.VALUE)) {
entry.value = utcTiming.value.toString();
} else {
// without a value, there's not a lot we can do with
// this entry. let's just ignore this one and move on
return;
}
// we're not interested in the optional id or any other
// attributes which might be attached to the entry
utcTimingEntries.push(entry);
});
}
}
return utcTimingEntries;
}
function getBaseURLsFromElement(node) {
const baseUrls = [];
// if node.BaseURL and node.baseUri are undefined entries
// will be [undefined] which entries.some will just skip
const entries = node.BaseURL || [node.baseUri];
let earlyReturn = false;
entries.some(entry => {
if (entry) {
const baseUrl = new BaseURL();
let text = entry.__text || entry;
if (urlUtils.isRelative(text)) {
// it doesn't really make sense to have relative and
// absolute URLs at the same level, or multiple
// relative URLs at the same level, so assume we are
// done from this level of the MPD
earlyReturn = true;
// deal with the specific case where the MPD@BaseURL
// is specified and is relative. when no MPD@BaseURL
// entries exist, that case is handled by the
// [node.baseUri] in the entries definition.
if (node.baseUri) {
text = urlUtils.resolve(text, node.baseUri);
}
}
baseUrl.url = text;
// serviceLocation is optional, but we need it in order
// to blacklist correctly. if it's not available, use
// anything unique since there's no relationship to any
// other BaseURL and, in theory, the url should be
// unique so use this instead.
if (entry.hasOwnProperty(DashConstants.SERVICE_LOCATION) &&
entry.serviceLocation.length) {
baseUrl.serviceLocation = entry.serviceLocation;
} else {
baseUrl.serviceLocation = text;
}
if (entry.hasOwnProperty(DashConstants.DVB_PRIORITY)) {
baseUrl.dvbPriority = entry[DashConstants.DVB_PRIORITY];
}
if (entry.hasOwnProperty(DashConstants.DVB_WEIGHT)) {
baseUrl.dvbWeight = entry[DashConstants.DVB_WEIGHT];
}
if (entry.hasOwnProperty(DashConstants.AVAILABILITY_TIME_OFFSET)) {
baseUrl.availabilityTimeOffset = entry[DashConstants.AVAILABILITY_TIME_OFFSET];
}
if (entry.hasOwnProperty(DashConstants.AVAILABILITY_TIME_COMPLETE)) {
baseUrl.availabilityTimeComplete = entry[DashConstants.AVAILABILITY_TIME_COMPLETE] !== 'false';
}
/* NOTE: byteRange currently unused
*/
baseUrls.push(baseUrl);
return earlyReturn;
}
});
return baseUrls;
}
function getContentSteering(manifest) {
if (manifest && manifest.hasOwnProperty(DashConstants.CONTENT_STEERING)) {
// Only one ContentSteering element is supported on MPD level
const element = manifest[DashConstants.CONTENT_STEERING][0];
return _createContentSteeringInstance(element);
}
return undefined;
}
function _createContentSteeringInstance(element) {
const entry = new ContentSteering();
entry.serverUrl = element.__text;
if (element.hasOwnProperty(DashConstants.DEFAULT_SERVICE_LOCATION)) {
entry.defaultServiceLocation = element[DashConstants.DEFAULT_SERVICE_LOCATION];
entry.defaultServiceLocationArray = entry.defaultServiceLocation.split(' ');
}
if (element.hasOwnProperty(DashConstants.QUERY_BEFORE_START)) {
entry.queryBeforeStart = element[DashConstants.QUERY_BEFORE_START].toLowerCase() === 'true';
}
if (element.hasOwnProperty(DashConstants.CLIENT_REQUIREMENT)) {
entry.clientRequirement = element[DashConstants.CLIENT_REQUIREMENT].toLowerCase() !== 'false';
}
return entry;
}
function _createClientDataReportingInstance(element) {
const entry = new ClientDataReporting();
if (element.hasOwnProperty(DashConstants.CMCD_PARAMETERS) && element[DashConstants.CMCD_PARAMETERS].schemeIdUri === Constants.CTA_5004_2023_SCHEME) {
entry.cmcdParameters = new CMCDParameters();
entry.cmcdParameters.init(element[DashConstants.CMCD_PARAMETERS]);
}
if (element.hasOwnProperty(DashConstants.SERVICE_LOCATIONS) && element[DashConstants.SERVICE_LOCATIONS] !== '') {
entry.serviceLocations = element[DashConstants.SERVICE_LOCATIONS];
entry.serviceLocationsArray = entry.serviceLocations.toString().split(' ');
}
if (element.hasOwnProperty(DashConstants.ADAPTATION_SETS) && element[DashConstants.ADAPTATION_SETS] !== '') {
entry.adaptationSets = element[DashConstants.ADAPTATION_SETS];
entry.adaptationSetsArray = entry.adaptationSets.toString().split(' ');
}
return entry;
}
function getLocation(manifest) {
if (manifest && manifest.hasOwnProperty(DashConstants.LOCATION)) {
return manifest[DashConstants.LOCATION].map((entry) => {
const text = entry.__text || entry;
const serviceLocation = entry.hasOwnProperty(DashConstants.SERVICE_LOCATION) ? entry[DashConstants.SERVICE_LOCATION] : null;
return new MpdLocation(text, serviceLocation)
})
}
return [];
}
function getPatchLocation(manifest) {
if (manifest && manifest.hasOwnProperty(DashConstants.PATCH_LOCATION)) {
return manifest[DashConstants.PATCH_LOCATION].map((entry) => {
const text = entry.__text || entry;
const serviceLocation = entry.hasOwnProperty(DashConstants.SERVICE_LOCATION) ? entry[DashConstants.SERVICE_LOCATION] : null;
let ttl = entry.hasOwnProperty(DashConstants.TTL) ? parseFloat(entry[DashConstants.TTL]) * 1000 : NaN;
return new PatchLocation(text, serviceLocation, ttl)
})
}
return [];
}
function getSuggestedPresentationDelay(mpd) {
return mpd && mpd.hasOwnProperty(DashConstants.SUGGESTED_PRESENTATION_DELAY) ? mpd.suggestedPresentationDelay : null;
}
function getAvailabilityStartTime(mpd) {
return mpd && mpd.hasOwnProperty(DashConstants.AVAILABILITY_START_TIME) && mpd.availabilityStartTime !== null ? mpd.availabilityStartTime.getTime() : null;
}
function getServiceDescriptions(manifest) {
const serviceDescriptions = [];
if (manifest && manifest.hasOwnProperty(DashConstants.SERVICE_DESCRIPTION)) {
for (const sd of manifest.ServiceDescription) {
// Convert each of the properties defined in
let id = null,
schemeIdUri = null,
latency = null,
playbackRate = null,
operatingQuality = null,
operatingBandwidth = null,
contentSteering = null,
clientDataReporting = null;
for (const prop in sd) {
if (sd.hasOwnProperty(prop)) {
Iif (prop === DashConstants.ID) {
id = sd[prop];
} else if (prop === DashConstants.SERVICE_DESCRIPTION_SCOPE) {
schemeIdUri = sd[prop].schemeIdUri;
} else if (prop === DashConstants.SERVICE_DESCRIPTION_LATENCY) {
latency = {
target: parseInt(sd[prop].target),
max: parseInt(sd[prop].max),
min: parseInt(sd[prop].min),
referenceId: parseInt(sd[prop].referenceId)
};
} else if (prop === DashConstants.SERVICE_DESCRIPTION_PLAYBACK_RATE) {
playbackRate = {
max: parseFloat(sd[prop].max),
min: parseFloat(sd[prop].min)
};
} else Iif (prop === DashConstants.SERVICE_DESCRIPTION_OPERATING_QUALITY) {
operatingQuality = {
mediaType: sd[prop].mediaType,
max: parseInt(sd[prop].max),
min: parseInt(sd[prop].min),
target: parseInt(sd[prop].target),
type: sd[prop].type,
maxQualityDifference: parseInt(sd[prop].maxQualityDifference)
}
} else Iif (prop === DashConstants.SERVICE_DESCRIPTION_OPERATING_BANDWIDTH) {
operatingBandwidth = {
mediaType: sd[prop].mediaType,
max: parseInt(sd[prop].max),
min: parseInt(sd[prop].min),
target: parseInt(sd[prop].target)
}
} else Iif (prop === DashConstants.CONTENT_STEERING) {
let element = sd[prop];
element = Array.isArray(element) ? element.at(element.length - 1) : element;
contentSteering = _createContentSteeringInstance(element);
} else if (prop === DashConstants.CLIENT_DATA_REPORTING) {
clientDataReporting = _createClientDataReportingInstance(sd[prop]);
}
}
}
serviceDescriptions.push({
id,
schemeIdUri,
latency,
playbackRate,
operatingQuality,
operatingBandwidth,
contentSteering,
clientDataReporting
});
}
}
return serviceDescriptions;
}
function setConfig(config) {
Iif (!config) {
return;
}
if (config.errHandler) {
errHandler = config.errHandler;
}
if (config.BASE64) {
BASE64 = config.BASE64;
}
}
instance = {
getAccessibilityForAdaptation,
getAdaptationForId,
getAdaptationForIndex,
getAdaptationsForPeriod,
getAdaptationsForType,
getAudioChannelConfigurationForAdaptation,
getAudioChannelConfigurationForRepresentation,
getAvailabilityStartTime,
getBandwidth,
getBaseURLsFromElement,
getBitrateListForAdaptation,
getCodec,
getCodecForPreselection,
getCombinedEssentialPropertiesForAdaptationSet,
getCombinedSupplementalPropertiesForAdaptationSet,
getContentProtectionByAdaptation,
getContentProtectionByManifest,
getContentProtectionByPeriod,
getContentSteering,
getDuration,
getEssentialProperties,
getEventStreamForAdaptationSet,
getEventStreamForRepresentation,
getEventsForPeriod,
getFramerate,
getId,
getIndexForAdaptation,
getIsDynamic,
getIsFragmented,
getIsText,
getIsTypeOf,
getLabelsForAdaptation,
getLanguageForAdaptation,
getLocation,
getMainAdaptationSetForPreselection,
getCommonRepresentationForPreselection,
getManifestUpdatePeriod,
getMimeType,
getMpd,
getPatchLocation,
getPreselectionIsTypeOf,
getPreselectionsForPeriod,
getProducerReferenceTimesForAdaptation,
getPublishTime,
getRealPeriodForIndex,
getRealPeriods,
getRegularPeriods,
getRepresentationCount,
getRepresentationFor,
getRepresentationSortFunction,
getRepresentationsForAdaptation,
getRolesForAdaptation,
getSegmentAlignment,
getSegmentSequencePropertiesForAdaptationSet,
getSelectionPriority,
getServiceDescriptions,
getSubSegmentAlignment,
getSuggestedPresentationDelay,
getSupplementalProperties,
getUTCTimingSources,
getViewpointForAdaptation,
hasProfile,
isPeriodEncrypted,
setConfig
};
setup();
return instance;
}
DashManifestModel.__dashjs_factory_name = 'DashManifestModel';
export default FactoryMaker.getSingletonFactory(DashManifestModel);
|