flv.js 426 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["flvjs"] = factory();
  8. else
  9. root["flvjs"] = factory();
  10. })(self, function() {
  11. return /******/ (function() { // webpackBootstrap
  12. /******/ var __webpack_modules__ = ({
  13. /***/ "./node_modules/es6-promise/dist/es6-promise.js":
  14. /*!******************************************************!*\
  15. !*** ./node_modules/es6-promise/dist/es6-promise.js ***!
  16. \******************************************************/
  17. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  18. /*!
  19. * @overview es6-promise - a tiny implementation of Promises/A+.
  20. * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
  21. * @license Licensed under MIT license
  22. * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
  23. * @version v4.2.8+1e68dce6
  24. */
  25. (function (global, factory) {
  26. true ? module.exports = factory() :
  27. 0;
  28. }(this, (function () {
  29. 'use strict';
  30. function objectOrFunction(x) {
  31. var type = typeof x;
  32. return x !== null && (type === 'object' || type === 'function');
  33. }
  34. function isFunction(x) {
  35. return typeof x === 'function';
  36. }
  37. var _isArray = void 0;
  38. if (Array.isArray) {
  39. _isArray = Array.isArray;
  40. }
  41. else {
  42. _isArray = function (x) {
  43. return Object.prototype.toString.call(x) === '[object Array]';
  44. };
  45. }
  46. var isArray = _isArray;
  47. var len = 0;
  48. var vertxNext = void 0;
  49. var customSchedulerFn = void 0;
  50. var asap = function asap(callback, arg) {
  51. queue[len] = callback;
  52. queue[len + 1] = arg;
  53. len += 2;
  54. if (len === 2) {
  55. // If len is 2, that means that we need to schedule an async flush.
  56. // If additional callbacks are queued before the queue is flushed, they
  57. // will be processed by this flush that we are scheduling.
  58. if (customSchedulerFn) {
  59. customSchedulerFn(flush);
  60. }
  61. else {
  62. scheduleFlush();
  63. }
  64. }
  65. };
  66. function setScheduler(scheduleFn) {
  67. customSchedulerFn = scheduleFn;
  68. }
  69. function setAsap(asapFn) {
  70. asap = asapFn;
  71. }
  72. var browserWindow = typeof window !== 'undefined' ? window : undefined;
  73. var browserGlobal = browserWindow || {};
  74. var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
  75. var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
  76. // test for web worker but not in IE10
  77. var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
  78. // node
  79. function useNextTick() {
  80. // node version 0.10.x displays a deprecation warning when nextTick is used recursively
  81. // see https://github.com/cujojs/when/issues/410 for details
  82. return function () {
  83. return process.nextTick(flush);
  84. };
  85. }
  86. // vertx
  87. function useVertxTimer() {
  88. if (typeof vertxNext !== 'undefined') {
  89. return function () {
  90. vertxNext(flush);
  91. };
  92. }
  93. return useSetTimeout();
  94. }
  95. function useMutationObserver() {
  96. var iterations = 0;
  97. var observer = new BrowserMutationObserver(flush);
  98. var node = document.createTextNode('');
  99. observer.observe(node, { characterData: true });
  100. return function () {
  101. node.data = iterations = ++iterations % 2;
  102. };
  103. }
  104. // web worker
  105. function useMessageChannel() {
  106. var channel = new MessageChannel();
  107. channel.port1.onmessage = flush;
  108. return function () {
  109. return channel.port2.postMessage(0);
  110. };
  111. }
  112. function useSetTimeout() {
  113. // Store setTimeout reference so es6-promise will be unaffected by
  114. // other code modifying setTimeout (like sinon.useFakeTimers())
  115. var globalSetTimeout = setTimeout;
  116. return function () {
  117. return globalSetTimeout(flush, 1);
  118. };
  119. }
  120. var queue = new Array(1000);
  121. function flush() {
  122. for (var i = 0; i < len; i += 2) {
  123. var callback = queue[i];
  124. var arg = queue[i + 1];
  125. callback(arg);
  126. queue[i] = undefined;
  127. queue[i + 1] = undefined;
  128. }
  129. len = 0;
  130. }
  131. function attemptVertx() {
  132. try {
  133. var vertx = Function('return this')().require('vertx');
  134. vertxNext = vertx.runOnLoop || vertx.runOnContext;
  135. return useVertxTimer();
  136. }
  137. catch (e) {
  138. return useSetTimeout();
  139. }
  140. }
  141. var scheduleFlush = void 0;
  142. // Decide what async method to use to triggering processing of queued callbacks:
  143. if (isNode) {
  144. scheduleFlush = useNextTick();
  145. }
  146. else if (BrowserMutationObserver) {
  147. scheduleFlush = useMutationObserver();
  148. }
  149. else if (isWorker) {
  150. scheduleFlush = useMessageChannel();
  151. }
  152. else if (browserWindow === undefined && "function" === 'function') {
  153. scheduleFlush = attemptVertx();
  154. }
  155. else {
  156. scheduleFlush = useSetTimeout();
  157. }
  158. function then(onFulfillment, onRejection) {
  159. var parent = this;
  160. var child = new this.constructor(noop);
  161. if (child[PROMISE_ID] === undefined) {
  162. makePromise(child);
  163. }
  164. var _state = parent._state;
  165. if (_state) {
  166. var callback = arguments[_state - 1];
  167. asap(function () {
  168. return invokeCallback(_state, child, callback, parent._result);
  169. });
  170. }
  171. else {
  172. subscribe(parent, child, onFulfillment, onRejection);
  173. }
  174. return child;
  175. }
  176. /**
  177. `Promise.resolve` returns a promise that will become resolved with the
  178. passed `value`. It is shorthand for the following:
  179. ```javascript
  180. let promise = new Promise(function(resolve, reject){
  181. resolve(1);
  182. });
  183. promise.then(function(value){
  184. // value === 1
  185. });
  186. ```
  187. Instead of writing the above, your code now simply becomes the following:
  188. ```javascript
  189. let promise = Promise.resolve(1);
  190. promise.then(function(value){
  191. // value === 1
  192. });
  193. ```
  194. @method resolve
  195. @static
  196. @param {Any} value value that the returned promise will be resolved with
  197. Useful for tooling.
  198. @return {Promise} a promise that will become fulfilled with the given
  199. `value`
  200. */
  201. function resolve$1(object) {
  202. /*jshint validthis:true */
  203. var Constructor = this;
  204. if (object && typeof object === 'object' && object.constructor === Constructor) {
  205. return object;
  206. }
  207. var promise = new Constructor(noop);
  208. resolve(promise, object);
  209. return promise;
  210. }
  211. var PROMISE_ID = Math.random().toString(36).substring(2);
  212. function noop() { }
  213. var PENDING = void 0;
  214. var FULFILLED = 1;
  215. var REJECTED = 2;
  216. function selfFulfillment() {
  217. return new TypeError("You cannot resolve a promise with itself");
  218. }
  219. function cannotReturnOwn() {
  220. return new TypeError('A promises callback cannot return that same promise.');
  221. }
  222. function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {
  223. try {
  224. then$$1.call(value, fulfillmentHandler, rejectionHandler);
  225. }
  226. catch (e) {
  227. return e;
  228. }
  229. }
  230. function handleForeignThenable(promise, thenable, then$$1) {
  231. asap(function (promise) {
  232. var sealed = false;
  233. var error = tryThen(then$$1, thenable, function (value) {
  234. if (sealed) {
  235. return;
  236. }
  237. sealed = true;
  238. if (thenable !== value) {
  239. resolve(promise, value);
  240. }
  241. else {
  242. fulfill(promise, value);
  243. }
  244. }, function (reason) {
  245. if (sealed) {
  246. return;
  247. }
  248. sealed = true;
  249. reject(promise, reason);
  250. }, 'Settle: ' + (promise._label || ' unknown promise'));
  251. if (!sealed && error) {
  252. sealed = true;
  253. reject(promise, error);
  254. }
  255. }, promise);
  256. }
  257. function handleOwnThenable(promise, thenable) {
  258. if (thenable._state === FULFILLED) {
  259. fulfill(promise, thenable._result);
  260. }
  261. else if (thenable._state === REJECTED) {
  262. reject(promise, thenable._result);
  263. }
  264. else {
  265. subscribe(thenable, undefined, function (value) {
  266. return resolve(promise, value);
  267. }, function (reason) {
  268. return reject(promise, reason);
  269. });
  270. }
  271. }
  272. function handleMaybeThenable(promise, maybeThenable, then$$1) {
  273. if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) {
  274. handleOwnThenable(promise, maybeThenable);
  275. }
  276. else {
  277. if (then$$1 === undefined) {
  278. fulfill(promise, maybeThenable);
  279. }
  280. else if (isFunction(then$$1)) {
  281. handleForeignThenable(promise, maybeThenable, then$$1);
  282. }
  283. else {
  284. fulfill(promise, maybeThenable);
  285. }
  286. }
  287. }
  288. function resolve(promise, value) {
  289. if (promise === value) {
  290. reject(promise, selfFulfillment());
  291. }
  292. else if (objectOrFunction(value)) {
  293. var then$$1 = void 0;
  294. try {
  295. then$$1 = value.then;
  296. }
  297. catch (error) {
  298. reject(promise, error);
  299. return;
  300. }
  301. handleMaybeThenable(promise, value, then$$1);
  302. }
  303. else {
  304. fulfill(promise, value);
  305. }
  306. }
  307. function publishRejection(promise) {
  308. if (promise._onerror) {
  309. promise._onerror(promise._result);
  310. }
  311. publish(promise);
  312. }
  313. function fulfill(promise, value) {
  314. if (promise._state !== PENDING) {
  315. return;
  316. }
  317. promise._result = value;
  318. promise._state = FULFILLED;
  319. if (promise._subscribers.length !== 0) {
  320. asap(publish, promise);
  321. }
  322. }
  323. function reject(promise, reason) {
  324. if (promise._state !== PENDING) {
  325. return;
  326. }
  327. promise._state = REJECTED;
  328. promise._result = reason;
  329. asap(publishRejection, promise);
  330. }
  331. function subscribe(parent, child, onFulfillment, onRejection) {
  332. var _subscribers = parent._subscribers;
  333. var length = _subscribers.length;
  334. parent._onerror = null;
  335. _subscribers[length] = child;
  336. _subscribers[length + FULFILLED] = onFulfillment;
  337. _subscribers[length + REJECTED] = onRejection;
  338. if (length === 0 && parent._state) {
  339. asap(publish, parent);
  340. }
  341. }
  342. function publish(promise) {
  343. var subscribers = promise._subscribers;
  344. var settled = promise._state;
  345. if (subscribers.length === 0) {
  346. return;
  347. }
  348. var child = void 0, callback = void 0, detail = promise._result;
  349. for (var i = 0; i < subscribers.length; i += 3) {
  350. child = subscribers[i];
  351. callback = subscribers[i + settled];
  352. if (child) {
  353. invokeCallback(settled, child, callback, detail);
  354. }
  355. else {
  356. callback(detail);
  357. }
  358. }
  359. promise._subscribers.length = 0;
  360. }
  361. function invokeCallback(settled, promise, callback, detail) {
  362. var hasCallback = isFunction(callback), value = void 0, error = void 0, succeeded = true;
  363. if (hasCallback) {
  364. try {
  365. value = callback(detail);
  366. }
  367. catch (e) {
  368. succeeded = false;
  369. error = e;
  370. }
  371. if (promise === value) {
  372. reject(promise, cannotReturnOwn());
  373. return;
  374. }
  375. }
  376. else {
  377. value = detail;
  378. }
  379. if (promise._state !== PENDING) {
  380. // noop
  381. }
  382. else if (hasCallback && succeeded) {
  383. resolve(promise, value);
  384. }
  385. else if (succeeded === false) {
  386. reject(promise, error);
  387. }
  388. else if (settled === FULFILLED) {
  389. fulfill(promise, value);
  390. }
  391. else if (settled === REJECTED) {
  392. reject(promise, value);
  393. }
  394. }
  395. function initializePromise(promise, resolver) {
  396. try {
  397. resolver(function resolvePromise(value) {
  398. resolve(promise, value);
  399. }, function rejectPromise(reason) {
  400. reject(promise, reason);
  401. });
  402. }
  403. catch (e) {
  404. reject(promise, e);
  405. }
  406. }
  407. var id = 0;
  408. function nextId() {
  409. return id++;
  410. }
  411. function makePromise(promise) {
  412. promise[PROMISE_ID] = id++;
  413. promise._state = undefined;
  414. promise._result = undefined;
  415. promise._subscribers = [];
  416. }
  417. function validationError() {
  418. return new Error('Array Methods must be provided an Array');
  419. }
  420. var Enumerator = function () {
  421. function Enumerator(Constructor, input) {
  422. this._instanceConstructor = Constructor;
  423. this.promise = new Constructor(noop);
  424. if (!this.promise[PROMISE_ID]) {
  425. makePromise(this.promise);
  426. }
  427. if (isArray(input)) {
  428. this.length = input.length;
  429. this._remaining = input.length;
  430. this._result = new Array(this.length);
  431. if (this.length === 0) {
  432. fulfill(this.promise, this._result);
  433. }
  434. else {
  435. this.length = this.length || 0;
  436. this._enumerate(input);
  437. if (this._remaining === 0) {
  438. fulfill(this.promise, this._result);
  439. }
  440. }
  441. }
  442. else {
  443. reject(this.promise, validationError());
  444. }
  445. }
  446. Enumerator.prototype._enumerate = function _enumerate(input) {
  447. for (var i = 0; this._state === PENDING && i < input.length; i++) {
  448. this._eachEntry(input[i], i);
  449. }
  450. };
  451. Enumerator.prototype._eachEntry = function _eachEntry(entry, i) {
  452. var c = this._instanceConstructor;
  453. var resolve$$1 = c.resolve;
  454. if (resolve$$1 === resolve$1) {
  455. var _then = void 0;
  456. var error = void 0;
  457. var didError = false;
  458. try {
  459. _then = entry.then;
  460. }
  461. catch (e) {
  462. didError = true;
  463. error = e;
  464. }
  465. if (_then === then && entry._state !== PENDING) {
  466. this._settledAt(entry._state, i, entry._result);
  467. }
  468. else if (typeof _then !== 'function') {
  469. this._remaining--;
  470. this._result[i] = entry;
  471. }
  472. else if (c === Promise$1) {
  473. var promise = new c(noop);
  474. if (didError) {
  475. reject(promise, error);
  476. }
  477. else {
  478. handleMaybeThenable(promise, entry, _then);
  479. }
  480. this._willSettleAt(promise, i);
  481. }
  482. else {
  483. this._willSettleAt(new c(function (resolve$$1) {
  484. return resolve$$1(entry);
  485. }), i);
  486. }
  487. }
  488. else {
  489. this._willSettleAt(resolve$$1(entry), i);
  490. }
  491. };
  492. Enumerator.prototype._settledAt = function _settledAt(state, i, value) {
  493. var promise = this.promise;
  494. if (promise._state === PENDING) {
  495. this._remaining--;
  496. if (state === REJECTED) {
  497. reject(promise, value);
  498. }
  499. else {
  500. this._result[i] = value;
  501. }
  502. }
  503. if (this._remaining === 0) {
  504. fulfill(promise, this._result);
  505. }
  506. };
  507. Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) {
  508. var enumerator = this;
  509. subscribe(promise, undefined, function (value) {
  510. return enumerator._settledAt(FULFILLED, i, value);
  511. }, function (reason) {
  512. return enumerator._settledAt(REJECTED, i, reason);
  513. });
  514. };
  515. return Enumerator;
  516. }();
  517. /**
  518. `Promise.all` accepts an array of promises, and returns a new promise which
  519. is fulfilled with an array of fulfillment values for the passed promises, or
  520. rejected with the reason of the first passed promise to be rejected. It casts all
  521. elements of the passed iterable to promises as it runs this algorithm.
  522. Example:
  523. ```javascript
  524. let promise1 = resolve(1);
  525. let promise2 = resolve(2);
  526. let promise3 = resolve(3);
  527. let promises = [ promise1, promise2, promise3 ];
  528. Promise.all(promises).then(function(array){
  529. // The array here would be [ 1, 2, 3 ];
  530. });
  531. ```
  532. If any of the `promises` given to `all` are rejected, the first promise
  533. that is rejected will be given as an argument to the returned promises's
  534. rejection handler. For example:
  535. Example:
  536. ```javascript
  537. let promise1 = resolve(1);
  538. let promise2 = reject(new Error("2"));
  539. let promise3 = reject(new Error("3"));
  540. let promises = [ promise1, promise2, promise3 ];
  541. Promise.all(promises).then(function(array){
  542. // Code here never runs because there are rejected promises!
  543. }, function(error) {
  544. // error.message === "2"
  545. });
  546. ```
  547. @method all
  548. @static
  549. @param {Array} entries array of promises
  550. @param {String} label optional string for labeling the promise.
  551. Useful for tooling.
  552. @return {Promise} promise that is fulfilled when all `promises` have been
  553. fulfilled, or rejected if any of them become rejected.
  554. @static
  555. */
  556. function all(entries) {
  557. return new Enumerator(this, entries).promise;
  558. }
  559. /**
  560. `Promise.race` returns a new promise which is settled in the same way as the
  561. first passed promise to settle.
  562. Example:
  563. ```javascript
  564. let promise1 = new Promise(function(resolve, reject){
  565. setTimeout(function(){
  566. resolve('promise 1');
  567. }, 200);
  568. });
  569. let promise2 = new Promise(function(resolve, reject){
  570. setTimeout(function(){
  571. resolve('promise 2');
  572. }, 100);
  573. });
  574. Promise.race([promise1, promise2]).then(function(result){
  575. // result === 'promise 2' because it was resolved before promise1
  576. // was resolved.
  577. });
  578. ```
  579. `Promise.race` is deterministic in that only the state of the first
  580. settled promise matters. For example, even if other promises given to the
  581. `promises` array argument are resolved, but the first settled promise has
  582. become rejected before the other promises became fulfilled, the returned
  583. promise will become rejected:
  584. ```javascript
  585. let promise1 = new Promise(function(resolve, reject){
  586. setTimeout(function(){
  587. resolve('promise 1');
  588. }, 200);
  589. });
  590. let promise2 = new Promise(function(resolve, reject){
  591. setTimeout(function(){
  592. reject(new Error('promise 2'));
  593. }, 100);
  594. });
  595. Promise.race([promise1, promise2]).then(function(result){
  596. // Code here never runs
  597. }, function(reason){
  598. // reason.message === 'promise 2' because promise 2 became rejected before
  599. // promise 1 became fulfilled
  600. });
  601. ```
  602. An example real-world use case is implementing timeouts:
  603. ```javascript
  604. Promise.race([ajax('foo.json'), timeout(5000)])
  605. ```
  606. @method race
  607. @static
  608. @param {Array} promises array of promises to observe
  609. Useful for tooling.
  610. @return {Promise} a promise which settles in the same way as the first passed
  611. promise to settle.
  612. */
  613. function race(entries) {
  614. /*jshint validthis:true */
  615. var Constructor = this;
  616. if (!isArray(entries)) {
  617. return new Constructor(function (_, reject) {
  618. return reject(new TypeError('You must pass an array to race.'));
  619. });
  620. }
  621. else {
  622. return new Constructor(function (resolve, reject) {
  623. var length = entries.length;
  624. for (var i = 0; i < length; i++) {
  625. Constructor.resolve(entries[i]).then(resolve, reject);
  626. }
  627. });
  628. }
  629. }
  630. /**
  631. `Promise.reject` returns a promise rejected with the passed `reason`.
  632. It is shorthand for the following:
  633. ```javascript
  634. let promise = new Promise(function(resolve, reject){
  635. reject(new Error('WHOOPS'));
  636. });
  637. promise.then(function(value){
  638. // Code here doesn't run because the promise is rejected!
  639. }, function(reason){
  640. // reason.message === 'WHOOPS'
  641. });
  642. ```
  643. Instead of writing the above, your code now simply becomes the following:
  644. ```javascript
  645. let promise = Promise.reject(new Error('WHOOPS'));
  646. promise.then(function(value){
  647. // Code here doesn't run because the promise is rejected!
  648. }, function(reason){
  649. // reason.message === 'WHOOPS'
  650. });
  651. ```
  652. @method reject
  653. @static
  654. @param {Any} reason value that the returned promise will be rejected with.
  655. Useful for tooling.
  656. @return {Promise} a promise rejected with the given `reason`.
  657. */
  658. function reject$1(reason) {
  659. /*jshint validthis:true */
  660. var Constructor = this;
  661. var promise = new Constructor(noop);
  662. reject(promise, reason);
  663. return promise;
  664. }
  665. function needsResolver() {
  666. throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
  667. }
  668. function needsNew() {
  669. throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
  670. }
  671. /**
  672. Promise objects represent the eventual result of an asynchronous operation. The
  673. primary way of interacting with a promise is through its `then` method, which
  674. registers callbacks to receive either a promise's eventual value or the reason
  675. why the promise cannot be fulfilled.
  676. Terminology
  677. -----------
  678. - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
  679. - `thenable` is an object or function that defines a `then` method.
  680. - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
  681. - `exception` is a value that is thrown using the throw statement.
  682. - `reason` is a value that indicates why a promise was rejected.
  683. - `settled` the final resting state of a promise, fulfilled or rejected.
  684. A promise can be in one of three states: pending, fulfilled, or rejected.
  685. Promises that are fulfilled have a fulfillment value and are in the fulfilled
  686. state. Promises that are rejected have a rejection reason and are in the
  687. rejected state. A fulfillment value is never a thenable.
  688. Promises can also be said to *resolve* a value. If this value is also a
  689. promise, then the original promise's settled state will match the value's
  690. settled state. So a promise that *resolves* a promise that rejects will
  691. itself reject, and a promise that *resolves* a promise that fulfills will
  692. itself fulfill.
  693. Basic Usage:
  694. ------------
  695. ```js
  696. let promise = new Promise(function(resolve, reject) {
  697. // on success
  698. resolve(value);
  699. // on failure
  700. reject(reason);
  701. });
  702. promise.then(function(value) {
  703. // on fulfillment
  704. }, function(reason) {
  705. // on rejection
  706. });
  707. ```
  708. Advanced Usage:
  709. ---------------
  710. Promises shine when abstracting away asynchronous interactions such as
  711. `XMLHttpRequest`s.
  712. ```js
  713. function getJSON(url) {
  714. return new Promise(function(resolve, reject){
  715. let xhr = new XMLHttpRequest();
  716. xhr.open('GET', url);
  717. xhr.onreadystatechange = handler;
  718. xhr.responseType = 'json';
  719. xhr.setRequestHeader('Accept', 'application/json');
  720. xhr.send();
  721. function handler() {
  722. if (this.readyState === this.DONE) {
  723. if (this.status === 200) {
  724. resolve(this.response);
  725. } else {
  726. reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
  727. }
  728. }
  729. };
  730. });
  731. }
  732. getJSON('/posts.json').then(function(json) {
  733. // on fulfillment
  734. }, function(reason) {
  735. // on rejection
  736. });
  737. ```
  738. Unlike callbacks, promises are great composable primitives.
  739. ```js
  740. Promise.all([
  741. getJSON('/posts'),
  742. getJSON('/comments')
  743. ]).then(function(values){
  744. values[0] // => postsJSON
  745. values[1] // => commentsJSON
  746. return values;
  747. });
  748. ```
  749. @class Promise
  750. @param {Function} resolver
  751. Useful for tooling.
  752. @constructor
  753. */
  754. var Promise$1 = function () {
  755. function Promise(resolver) {
  756. this[PROMISE_ID] = nextId();
  757. this._result = this._state = undefined;
  758. this._subscribers = [];
  759. if (noop !== resolver) {
  760. typeof resolver !== 'function' && needsResolver();
  761. this instanceof Promise ? initializePromise(this, resolver) : needsNew();
  762. }
  763. }
  764. /**
  765. The primary way of interacting with a promise is through its `then` method,
  766. which registers callbacks to receive either a promise's eventual value or the
  767. reason why the promise cannot be fulfilled.
  768. ```js
  769. findUser().then(function(user){
  770. // user is available
  771. }, function(reason){
  772. // user is unavailable, and you are given the reason why
  773. });
  774. ```
  775. Chaining
  776. --------
  777. The return value of `then` is itself a promise. This second, 'downstream'
  778. promise is resolved with the return value of the first promise's fulfillment
  779. or rejection handler, or rejected if the handler throws an exception.
  780. ```js
  781. findUser().then(function (user) {
  782. return user.name;
  783. }, function (reason) {
  784. return 'default name';
  785. }).then(function (userName) {
  786. // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
  787. // will be `'default name'`
  788. });
  789. findUser().then(function (user) {
  790. throw new Error('Found user, but still unhappy');
  791. }, function (reason) {
  792. throw new Error('`findUser` rejected and we're unhappy');
  793. }).then(function (value) {
  794. // never reached
  795. }, function (reason) {
  796. // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
  797. // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
  798. });
  799. ```
  800. If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
  801. ```js
  802. findUser().then(function (user) {
  803. throw new PedagogicalException('Upstream error');
  804. }).then(function (value) {
  805. // never reached
  806. }).then(function (value) {
  807. // never reached
  808. }, function (reason) {
  809. // The `PedgagocialException` is propagated all the way down to here
  810. });
  811. ```
  812. Assimilation
  813. ------------
  814. Sometimes the value you want to propagate to a downstream promise can only be
  815. retrieved asynchronously. This can be achieved by returning a promise in the
  816. fulfillment or rejection handler. The downstream promise will then be pending
  817. until the returned promise is settled. This is called *assimilation*.
  818. ```js
  819. findUser().then(function (user) {
  820. return findCommentsByAuthor(user);
  821. }).then(function (comments) {
  822. // The user's comments are now available
  823. });
  824. ```
  825. If the assimliated promise rejects, then the downstream promise will also reject.
  826. ```js
  827. findUser().then(function (user) {
  828. return findCommentsByAuthor(user);
  829. }).then(function (comments) {
  830. // If `findCommentsByAuthor` fulfills, we'll have the value here
  831. }, function (reason) {
  832. // If `findCommentsByAuthor` rejects, we'll have the reason here
  833. });
  834. ```
  835. Simple Example
  836. --------------
  837. Synchronous Example
  838. ```javascript
  839. let result;
  840. try {
  841. result = findResult();
  842. // success
  843. } catch(reason) {
  844. // failure
  845. }
  846. ```
  847. Errback Example
  848. ```js
  849. findResult(function(result, err){
  850. if (err) {
  851. // failure
  852. } else {
  853. // success
  854. }
  855. });
  856. ```
  857. Promise Example;
  858. ```javascript
  859. findResult().then(function(result){
  860. // success
  861. }, function(reason){
  862. // failure
  863. });
  864. ```
  865. Advanced Example
  866. --------------
  867. Synchronous Example
  868. ```javascript
  869. let author, books;
  870. try {
  871. author = findAuthor();
  872. books = findBooksByAuthor(author);
  873. // success
  874. } catch(reason) {
  875. // failure
  876. }
  877. ```
  878. Errback Example
  879. ```js
  880. function foundBooks(books) {
  881. }
  882. function failure(reason) {
  883. }
  884. findAuthor(function(author, err){
  885. if (err) {
  886. failure(err);
  887. // failure
  888. } else {
  889. try {
  890. findBoooksByAuthor(author, function(books, err) {
  891. if (err) {
  892. failure(err);
  893. } else {
  894. try {
  895. foundBooks(books);
  896. } catch(reason) {
  897. failure(reason);
  898. }
  899. }
  900. });
  901. } catch(error) {
  902. failure(err);
  903. }
  904. // success
  905. }
  906. });
  907. ```
  908. Promise Example;
  909. ```javascript
  910. findAuthor().
  911. then(findBooksByAuthor).
  912. then(function(books){
  913. // found books
  914. }).catch(function(reason){
  915. // something went wrong
  916. });
  917. ```
  918. @method then
  919. @param {Function} onFulfilled
  920. @param {Function} onRejected
  921. Useful for tooling.
  922. @return {Promise}
  923. */
  924. /**
  925. `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
  926. as the catch block of a try/catch statement.
  927. ```js
  928. function findAuthor(){
  929. throw new Error('couldn't find that author');
  930. }
  931. // synchronous
  932. try {
  933. findAuthor();
  934. } catch(reason) {
  935. // something went wrong
  936. }
  937. // async with promises
  938. findAuthor().catch(function(reason){
  939. // something went wrong
  940. });
  941. ```
  942. @method catch
  943. @param {Function} onRejection
  944. Useful for tooling.
  945. @return {Promise}
  946. */
  947. Promise.prototype.catch = function _catch(onRejection) {
  948. return this.then(null, onRejection);
  949. };
  950. /**
  951. `finally` will be invoked regardless of the promise's fate just as native
  952. try/catch/finally behaves
  953. Synchronous example:
  954. ```js
  955. findAuthor() {
  956. if (Math.random() > 0.5) {
  957. throw new Error();
  958. }
  959. return new Author();
  960. }
  961. try {
  962. return findAuthor(); // succeed or fail
  963. } catch(error) {
  964. return findOtherAuther();
  965. } finally {
  966. // always runs
  967. // doesn't affect the return value
  968. }
  969. ```
  970. Asynchronous example:
  971. ```js
  972. findAuthor().catch(function(reason){
  973. return findOtherAuther();
  974. }).finally(function(){
  975. // author was either found, or not
  976. });
  977. ```
  978. @method finally
  979. @param {Function} callback
  980. @return {Promise}
  981. */
  982. Promise.prototype.finally = function _finally(callback) {
  983. var promise = this;
  984. var constructor = promise.constructor;
  985. if (isFunction(callback)) {
  986. return promise.then(function (value) {
  987. return constructor.resolve(callback()).then(function () {
  988. return value;
  989. });
  990. }, function (reason) {
  991. return constructor.resolve(callback()).then(function () {
  992. throw reason;
  993. });
  994. });
  995. }
  996. return promise.then(callback, callback);
  997. };
  998. return Promise;
  999. }();
  1000. Promise$1.prototype.then = then;
  1001. Promise$1.all = all;
  1002. Promise$1.race = race;
  1003. Promise$1.resolve = resolve$1;
  1004. Promise$1.reject = reject$1;
  1005. Promise$1._setScheduler = setScheduler;
  1006. Promise$1._setAsap = setAsap;
  1007. Promise$1._asap = asap;
  1008. /*global self*/
  1009. function polyfill() {
  1010. var local = void 0;
  1011. if (typeof __webpack_require__.g !== 'undefined') {
  1012. local = __webpack_require__.g;
  1013. }
  1014. else if (typeof self !== 'undefined') {
  1015. local = self;
  1016. }
  1017. else {
  1018. try {
  1019. local = Function('return this')();
  1020. }
  1021. catch (e) {
  1022. throw new Error('polyfill failed because global object is unavailable in this environment');
  1023. }
  1024. }
  1025. var P = local.Promise;
  1026. if (P) {
  1027. var promiseToString = null;
  1028. try {
  1029. promiseToString = Object.prototype.toString.call(P.resolve());
  1030. }
  1031. catch (e) {
  1032. // silently ignored
  1033. }
  1034. if (promiseToString === '[object Promise]' && !P.cast) {
  1035. return;
  1036. }
  1037. }
  1038. local.Promise = Promise$1;
  1039. }
  1040. // Strange compat..
  1041. Promise$1.polyfill = polyfill;
  1042. Promise$1.Promise = Promise$1;
  1043. return Promise$1;
  1044. })));
  1045. /***/ }),
  1046. /***/ "./node_modules/events/events.js":
  1047. /*!***************************************!*\
  1048. !*** ./node_modules/events/events.js ***!
  1049. \***************************************/
  1050. /***/ (function(module) {
  1051. "use strict";
  1052. // Copyright Joyent, Inc. and other Node contributors.
  1053. //
  1054. // Permission is hereby granted, free of charge, to any person obtaining a
  1055. // copy of this software and associated documentation files (the
  1056. // "Software"), to deal in the Software without restriction, including
  1057. // without limitation the rights to use, copy, modify, merge, publish,
  1058. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1059. // persons to whom the Software is furnished to do so, subject to the
  1060. // following conditions:
  1061. //
  1062. // The above copyright notice and this permission notice shall be included
  1063. // in all copies or substantial portions of the Software.
  1064. //
  1065. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1066. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1067. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1068. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1069. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1070. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1071. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1072. var R = typeof Reflect === 'object' ? Reflect : null;
  1073. var ReflectApply = R && typeof R.apply === 'function'
  1074. ? R.apply
  1075. : function ReflectApply(target, receiver, args) {
  1076. return Function.prototype.apply.call(target, receiver, args);
  1077. };
  1078. var ReflectOwnKeys;
  1079. if (R && typeof R.ownKeys === 'function') {
  1080. ReflectOwnKeys = R.ownKeys;
  1081. }
  1082. else if (Object.getOwnPropertySymbols) {
  1083. ReflectOwnKeys = function ReflectOwnKeys(target) {
  1084. return Object.getOwnPropertyNames(target)
  1085. .concat(Object.getOwnPropertySymbols(target));
  1086. };
  1087. }
  1088. else {
  1089. ReflectOwnKeys = function ReflectOwnKeys(target) {
  1090. return Object.getOwnPropertyNames(target);
  1091. };
  1092. }
  1093. function ProcessEmitWarning(warning) {
  1094. if (console && console.warn)
  1095. console.warn(warning);
  1096. }
  1097. var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
  1098. return value !== value;
  1099. };
  1100. function EventEmitter() {
  1101. EventEmitter.init.call(this);
  1102. }
  1103. module.exports = EventEmitter;
  1104. module.exports.once = once;
  1105. // Backwards-compat with node 0.10.x
  1106. EventEmitter.EventEmitter = EventEmitter;
  1107. EventEmitter.prototype._events = undefined;
  1108. EventEmitter.prototype._eventsCount = 0;
  1109. EventEmitter.prototype._maxListeners = undefined;
  1110. // By default EventEmitters will print a warning if more than 10 listeners are
  1111. // added to it. This is a useful default which helps finding memory leaks.
  1112. var defaultMaxListeners = 10;
  1113. function checkListener(listener) {
  1114. if (typeof listener !== 'function') {
  1115. throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
  1116. }
  1117. }
  1118. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  1119. enumerable: true,
  1120. get: function () {
  1121. return defaultMaxListeners;
  1122. },
  1123. set: function (arg) {
  1124. if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
  1125. throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
  1126. }
  1127. defaultMaxListeners = arg;
  1128. }
  1129. });
  1130. EventEmitter.init = function () {
  1131. if (this._events === undefined ||
  1132. this._events === Object.getPrototypeOf(this)._events) {
  1133. this._events = Object.create(null);
  1134. this._eventsCount = 0;
  1135. }
  1136. this._maxListeners = this._maxListeners || undefined;
  1137. };
  1138. // Obviously not all Emitters should be limited to 10. This function allows
  1139. // that to be increased. Set to zero for unlimited.
  1140. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  1141. if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
  1142. throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
  1143. }
  1144. this._maxListeners = n;
  1145. return this;
  1146. };
  1147. function _getMaxListeners(that) {
  1148. if (that._maxListeners === undefined)
  1149. return EventEmitter.defaultMaxListeners;
  1150. return that._maxListeners;
  1151. }
  1152. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  1153. return _getMaxListeners(this);
  1154. };
  1155. EventEmitter.prototype.emit = function emit(type) {
  1156. var args = [];
  1157. for (var i = 1; i < arguments.length; i++)
  1158. args.push(arguments[i]);
  1159. var doError = (type === 'error');
  1160. var events = this._events;
  1161. if (events !== undefined)
  1162. doError = (doError && events.error === undefined);
  1163. else if (!doError)
  1164. return false;
  1165. // If there is no 'error' event listener then throw.
  1166. if (doError) {
  1167. var er;
  1168. if (args.length > 0)
  1169. er = args[0];
  1170. if (er instanceof Error) {
  1171. // Note: The comments on the `throw` lines are intentional, they show
  1172. // up in Node's output if this results in an unhandled exception.
  1173. throw er; // Unhandled 'error' event
  1174. }
  1175. // At least give some kind of context to the user
  1176. var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
  1177. err.context = er;
  1178. throw err; // Unhandled 'error' event
  1179. }
  1180. var handler = events[type];
  1181. if (handler === undefined)
  1182. return false;
  1183. if (typeof handler === 'function') {
  1184. ReflectApply(handler, this, args);
  1185. }
  1186. else {
  1187. var len = handler.length;
  1188. var listeners = arrayClone(handler, len);
  1189. for (var i = 0; i < len; ++i)
  1190. ReflectApply(listeners[i], this, args);
  1191. }
  1192. return true;
  1193. };
  1194. function _addListener(target, type, listener, prepend) {
  1195. var m;
  1196. var events;
  1197. var existing;
  1198. checkListener(listener);
  1199. events = target._events;
  1200. if (events === undefined) {
  1201. events = target._events = Object.create(null);
  1202. target._eventsCount = 0;
  1203. }
  1204. else {
  1205. // To avoid recursion in the case that type === "newListener"! Before
  1206. // adding it to the listeners, first emit "newListener".
  1207. if (events.newListener !== undefined) {
  1208. target.emit('newListener', type, listener.listener ? listener.listener : listener);
  1209. // Re-assign `events` because a newListener handler could have caused the
  1210. // this._events to be assigned to a new object
  1211. events = target._events;
  1212. }
  1213. existing = events[type];
  1214. }
  1215. if (existing === undefined) {
  1216. // Optimize the case of one listener. Don't need the extra array object.
  1217. existing = events[type] = listener;
  1218. ++target._eventsCount;
  1219. }
  1220. else {
  1221. if (typeof existing === 'function') {
  1222. // Adding the second element, need to change to array.
  1223. existing = events[type] =
  1224. prepend ? [listener, existing] : [existing, listener];
  1225. // If we've already got an array, just append.
  1226. }
  1227. else if (prepend) {
  1228. existing.unshift(listener);
  1229. }
  1230. else {
  1231. existing.push(listener);
  1232. }
  1233. // Check for listener leak
  1234. m = _getMaxListeners(target);
  1235. if (m > 0 && existing.length > m && !existing.warned) {
  1236. existing.warned = true;
  1237. // No error code for this since it is a Warning
  1238. // eslint-disable-next-line no-restricted-syntax
  1239. var w = new Error('Possible EventEmitter memory leak detected. ' +
  1240. existing.length + ' ' + String(type) + ' listeners ' +
  1241. 'added. Use emitter.setMaxListeners() to ' +
  1242. 'increase limit');
  1243. w.name = 'MaxListenersExceededWarning';
  1244. w.emitter = target;
  1245. w.type = type;
  1246. w.count = existing.length;
  1247. ProcessEmitWarning(w);
  1248. }
  1249. }
  1250. return target;
  1251. }
  1252. EventEmitter.prototype.addListener = function addListener(type, listener) {
  1253. return _addListener(this, type, listener, false);
  1254. };
  1255. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  1256. EventEmitter.prototype.prependListener =
  1257. function prependListener(type, listener) {
  1258. return _addListener(this, type, listener, true);
  1259. };
  1260. function onceWrapper() {
  1261. if (!this.fired) {
  1262. this.target.removeListener(this.type, this.wrapFn);
  1263. this.fired = true;
  1264. if (arguments.length === 0)
  1265. return this.listener.call(this.target);
  1266. return this.listener.apply(this.target, arguments);
  1267. }
  1268. }
  1269. function _onceWrap(target, type, listener) {
  1270. var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
  1271. var wrapped = onceWrapper.bind(state);
  1272. wrapped.listener = listener;
  1273. state.wrapFn = wrapped;
  1274. return wrapped;
  1275. }
  1276. EventEmitter.prototype.once = function once(type, listener) {
  1277. checkListener(listener);
  1278. this.on(type, _onceWrap(this, type, listener));
  1279. return this;
  1280. };
  1281. EventEmitter.prototype.prependOnceListener =
  1282. function prependOnceListener(type, listener) {
  1283. checkListener(listener);
  1284. this.prependListener(type, _onceWrap(this, type, listener));
  1285. return this;
  1286. };
  1287. // Emits a 'removeListener' event if and only if the listener was removed.
  1288. EventEmitter.prototype.removeListener =
  1289. function removeListener(type, listener) {
  1290. var list, events, position, i, originalListener;
  1291. checkListener(listener);
  1292. events = this._events;
  1293. if (events === undefined)
  1294. return this;
  1295. list = events[type];
  1296. if (list === undefined)
  1297. return this;
  1298. if (list === listener || list.listener === listener) {
  1299. if (--this._eventsCount === 0)
  1300. this._events = Object.create(null);
  1301. else {
  1302. delete events[type];
  1303. if (events.removeListener)
  1304. this.emit('removeListener', type, list.listener || listener);
  1305. }
  1306. }
  1307. else if (typeof list !== 'function') {
  1308. position = -1;
  1309. for (i = list.length - 1; i >= 0; i--) {
  1310. if (list[i] === listener || list[i].listener === listener) {
  1311. originalListener = list[i].listener;
  1312. position = i;
  1313. break;
  1314. }
  1315. }
  1316. if (position < 0)
  1317. return this;
  1318. if (position === 0)
  1319. list.shift();
  1320. else {
  1321. spliceOne(list, position);
  1322. }
  1323. if (list.length === 1)
  1324. events[type] = list[0];
  1325. if (events.removeListener !== undefined)
  1326. this.emit('removeListener', type, originalListener || listener);
  1327. }
  1328. return this;
  1329. };
  1330. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  1331. EventEmitter.prototype.removeAllListeners =
  1332. function removeAllListeners(type) {
  1333. var listeners, events, i;
  1334. events = this._events;
  1335. if (events === undefined)
  1336. return this;
  1337. // not listening for removeListener, no need to emit
  1338. if (events.removeListener === undefined) {
  1339. if (arguments.length === 0) {
  1340. this._events = Object.create(null);
  1341. this._eventsCount = 0;
  1342. }
  1343. else if (events[type] !== undefined) {
  1344. if (--this._eventsCount === 0)
  1345. this._events = Object.create(null);
  1346. else
  1347. delete events[type];
  1348. }
  1349. return this;
  1350. }
  1351. // emit removeListener for all listeners on all events
  1352. if (arguments.length === 0) {
  1353. var keys = Object.keys(events);
  1354. var key;
  1355. for (i = 0; i < keys.length; ++i) {
  1356. key = keys[i];
  1357. if (key === 'removeListener')
  1358. continue;
  1359. this.removeAllListeners(key);
  1360. }
  1361. this.removeAllListeners('removeListener');
  1362. this._events = Object.create(null);
  1363. this._eventsCount = 0;
  1364. return this;
  1365. }
  1366. listeners = events[type];
  1367. if (typeof listeners === 'function') {
  1368. this.removeListener(type, listeners);
  1369. }
  1370. else if (listeners !== undefined) {
  1371. // LIFO order
  1372. for (i = listeners.length - 1; i >= 0; i--) {
  1373. this.removeListener(type, listeners[i]);
  1374. }
  1375. }
  1376. return this;
  1377. };
  1378. function _listeners(target, type, unwrap) {
  1379. var events = target._events;
  1380. if (events === undefined)
  1381. return [];
  1382. var evlistener = events[type];
  1383. if (evlistener === undefined)
  1384. return [];
  1385. if (typeof evlistener === 'function')
  1386. return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  1387. return unwrap ?
  1388. unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  1389. }
  1390. EventEmitter.prototype.listeners = function listeners(type) {
  1391. return _listeners(this, type, true);
  1392. };
  1393. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  1394. return _listeners(this, type, false);
  1395. };
  1396. EventEmitter.listenerCount = function (emitter, type) {
  1397. if (typeof emitter.listenerCount === 'function') {
  1398. return emitter.listenerCount(type);
  1399. }
  1400. else {
  1401. return listenerCount.call(emitter, type);
  1402. }
  1403. };
  1404. EventEmitter.prototype.listenerCount = listenerCount;
  1405. function listenerCount(type) {
  1406. var events = this._events;
  1407. if (events !== undefined) {
  1408. var evlistener = events[type];
  1409. if (typeof evlistener === 'function') {
  1410. return 1;
  1411. }
  1412. else if (evlistener !== undefined) {
  1413. return evlistener.length;
  1414. }
  1415. }
  1416. return 0;
  1417. }
  1418. EventEmitter.prototype.eventNames = function eventNames() {
  1419. return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
  1420. };
  1421. function arrayClone(arr, n) {
  1422. var copy = new Array(n);
  1423. for (var i = 0; i < n; ++i)
  1424. copy[i] = arr[i];
  1425. return copy;
  1426. }
  1427. function spliceOne(list, index) {
  1428. for (; index + 1 < list.length; index++)
  1429. list[index] = list[index + 1];
  1430. list.pop();
  1431. }
  1432. function unwrapListeners(arr) {
  1433. var ret = new Array(arr.length);
  1434. for (var i = 0; i < ret.length; ++i) {
  1435. ret[i] = arr[i].listener || arr[i];
  1436. }
  1437. return ret;
  1438. }
  1439. function once(emitter, name) {
  1440. return new Promise(function (resolve, reject) {
  1441. function errorListener(err) {
  1442. emitter.removeListener(name, resolver);
  1443. reject(err);
  1444. }
  1445. function resolver() {
  1446. if (typeof emitter.removeListener === 'function') {
  1447. emitter.removeListener('error', errorListener);
  1448. }
  1449. resolve([].slice.call(arguments));
  1450. }
  1451. ;
  1452. eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
  1453. if (name !== 'error') {
  1454. addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
  1455. }
  1456. });
  1457. }
  1458. function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
  1459. if (typeof emitter.on === 'function') {
  1460. eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
  1461. }
  1462. }
  1463. function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
  1464. if (typeof emitter.on === 'function') {
  1465. if (flags.once) {
  1466. emitter.once(name, listener);
  1467. }
  1468. else {
  1469. emitter.on(name, listener);
  1470. }
  1471. }
  1472. else if (typeof emitter.addEventListener === 'function') {
  1473. // EventTarget does not have `error` event semantics like Node
  1474. // EventEmitters, we do not listen for `error` events here.
  1475. emitter.addEventListener(name, function wrapListener(arg) {
  1476. // IE does not have builtin `{ once: true }` support so we
  1477. // have to do it manually.
  1478. if (flags.once) {
  1479. emitter.removeEventListener(name, wrapListener);
  1480. }
  1481. listener(arg);
  1482. });
  1483. }
  1484. else {
  1485. throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
  1486. }
  1487. }
  1488. /***/ }),
  1489. /***/ "./node_modules/webworkify-webpack/index.js":
  1490. /*!**************************************************!*\
  1491. !*** ./node_modules/webworkify-webpack/index.js ***!
  1492. \**************************************************/
  1493. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  1494. function webpackBootstrapFunc(modules) {
  1495. /******/ // The module cache
  1496. /******/ var installedModules = {};
  1497. /******/ // The require function
  1498. /******/ function __nested_webpack_require_164__(moduleId) {
  1499. /******/ // Check if module is in cache
  1500. /******/ if (installedModules[moduleId])
  1501. /******/ return installedModules[moduleId].exports;
  1502. /******/ // Create a new module (and put it into the cache)
  1503. /******/ var module = installedModules[moduleId] = {
  1504. /******/ i: moduleId,
  1505. /******/ l: false,
  1506. /******/ exports: {}
  1507. /******/
  1508. };
  1509. /******/ // Execute the module function
  1510. /******/ modules[moduleId].call(module.exports, module, module.exports, __nested_webpack_require_164__);
  1511. /******/ // Flag the module as loaded
  1512. /******/ module.l = true;
  1513. /******/ // Return the exports of the module
  1514. /******/ return module.exports;
  1515. /******/
  1516. }
  1517. /******/ // expose the modules object (__webpack_modules__)
  1518. /******/ __nested_webpack_require_164__.m = modules;
  1519. /******/ // expose the module cache
  1520. /******/ __nested_webpack_require_164__.c = installedModules;
  1521. /******/ // identity function for calling harmony imports with the correct context
  1522. /******/ __nested_webpack_require_164__.i = function (value) { return value; };
  1523. /******/ // define getter function for harmony exports
  1524. /******/ __nested_webpack_require_164__.d = function (exports, name, getter) {
  1525. /******/ if (!__nested_webpack_require_164__.o(exports, name)) {
  1526. /******/ Object.defineProperty(exports, name, {
  1527. /******/ configurable: false,
  1528. /******/ enumerable: true,
  1529. /******/ get: getter
  1530. /******/
  1531. });
  1532. /******/ }
  1533. /******/
  1534. };
  1535. /******/ // define __esModule on exports
  1536. /******/ __nested_webpack_require_164__.r = function (exports) {
  1537. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  1538. /******/
  1539. };
  1540. /******/ // getDefaultExport function for compatibility with non-harmony modules
  1541. /******/ __nested_webpack_require_164__.n = function (module) {
  1542. /******/ var getter = module && module.__esModule ?
  1543. /******/ function getDefault() { return module['default']; } :
  1544. /******/ function getModuleExports() { return module; };
  1545. /******/ __nested_webpack_require_164__.d(getter, 'a', getter);
  1546. /******/ return getter;
  1547. /******/
  1548. };
  1549. /******/ // Object.prototype.hasOwnProperty.call
  1550. /******/ __nested_webpack_require_164__.o = function (object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  1551. /******/ // __webpack_public_path__
  1552. /******/ __nested_webpack_require_164__.p = "/";
  1553. /******/ // on error function for async loading
  1554. /******/ __nested_webpack_require_164__.oe = function (err) { console.error(err); throw err; };
  1555. var f = __nested_webpack_require_164__(__nested_webpack_require_164__.s = ENTRY_MODULE);
  1556. return f.default || f; // try to call default if defined to also support babel esmodule exports
  1557. }
  1558. var moduleNameReqExp = '[\\.|\\-|\\+|\\w|\/|@]+';
  1559. var dependencyRegExp = '\\(\\s*(\/\\*.*?\\*\/)?\\s*.*?(' + moduleNameReqExp + ').*?\\)'; // additional chars when output.pathinfo is true
  1560. // http://stackoverflow.com/a/2593661/130442
  1561. function quoteRegExp(str) {
  1562. return (str + '').replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&');
  1563. }
  1564. function isNumeric(n) {
  1565. return !isNaN(1 * n); // 1 * n converts integers, integers as string ("123"), 1e3 and "1e3" to integers and strings to NaN
  1566. }
  1567. function getModuleDependencies(sources, module, queueName) {
  1568. var retval = {};
  1569. retval[queueName] = [];
  1570. var fnString = module.toString();
  1571. var wrapperSignature = fnString.match(/^function\s?\w*\(\w+,\s*\w+,\s*(\w+)\)/);
  1572. if (!wrapperSignature)
  1573. return retval;
  1574. var webpackRequireName = wrapperSignature[1];
  1575. // main bundle deps
  1576. var re = new RegExp('(\\\\n|\\W)' + quoteRegExp(webpackRequireName) + dependencyRegExp, 'g');
  1577. var match;
  1578. while ((match = re.exec(fnString))) {
  1579. if (match[3] === 'dll-reference')
  1580. continue;
  1581. retval[queueName].push(match[3]);
  1582. }
  1583. // dll deps
  1584. re = new RegExp('\\(' + quoteRegExp(webpackRequireName) + '\\("(dll-reference\\s(' + moduleNameReqExp + '))"\\)\\)' + dependencyRegExp, 'g');
  1585. while ((match = re.exec(fnString))) {
  1586. if (!sources[match[2]]) {
  1587. retval[queueName].push(match[1]);
  1588. sources[match[2]] = __webpack_require__(match[1]).m;
  1589. }
  1590. retval[match[2]] = retval[match[2]] || [];
  1591. retval[match[2]].push(match[4]);
  1592. }
  1593. // convert 1e3 back to 1000 - this can be important after uglify-js converted 1000 to 1e3
  1594. var keys = Object.keys(retval);
  1595. for (var i = 0; i < keys.length; i++) {
  1596. for (var j = 0; j < retval[keys[i]].length; j++) {
  1597. if (isNumeric(retval[keys[i]][j])) {
  1598. retval[keys[i]][j] = 1 * retval[keys[i]][j];
  1599. }
  1600. }
  1601. }
  1602. return retval;
  1603. }
  1604. function hasValuesInQueues(queues) {
  1605. var keys = Object.keys(queues);
  1606. return keys.reduce(function (hasValues, key) {
  1607. return hasValues || queues[key].length > 0;
  1608. }, false);
  1609. }
  1610. function getRequiredModules(sources, moduleId) {
  1611. var modulesQueue = {
  1612. main: [moduleId]
  1613. };
  1614. var requiredModules = {
  1615. main: []
  1616. };
  1617. var seenModules = {
  1618. main: {}
  1619. };
  1620. while (hasValuesInQueues(modulesQueue)) {
  1621. var queues = Object.keys(modulesQueue);
  1622. for (var i = 0; i < queues.length; i++) {
  1623. var queueName = queues[i];
  1624. var queue = modulesQueue[queueName];
  1625. var moduleToCheck = queue.pop();
  1626. seenModules[queueName] = seenModules[queueName] || {};
  1627. if (seenModules[queueName][moduleToCheck] || !sources[queueName][moduleToCheck])
  1628. continue;
  1629. seenModules[queueName][moduleToCheck] = true;
  1630. requiredModules[queueName] = requiredModules[queueName] || [];
  1631. requiredModules[queueName].push(moduleToCheck);
  1632. var newModules = getModuleDependencies(sources, sources[queueName][moduleToCheck], queueName);
  1633. var newModulesKeys = Object.keys(newModules);
  1634. for (var j = 0; j < newModulesKeys.length; j++) {
  1635. modulesQueue[newModulesKeys[j]] = modulesQueue[newModulesKeys[j]] || [];
  1636. modulesQueue[newModulesKeys[j]] = modulesQueue[newModulesKeys[j]].concat(newModules[newModulesKeys[j]]);
  1637. }
  1638. }
  1639. }
  1640. return requiredModules;
  1641. }
  1642. module.exports = function (moduleId, options) {
  1643. options = options || {};
  1644. var sources = {
  1645. main: __webpack_require__.m
  1646. };
  1647. var requiredModules = options.all ? { main: Object.keys(sources.main) } : getRequiredModules(sources, moduleId);
  1648. var src = '';
  1649. Object.keys(requiredModules).filter(function (m) { return m !== 'main'; }).forEach(function (module) {
  1650. var entryModule = 0;
  1651. while (requiredModules[module][entryModule]) {
  1652. entryModule++;
  1653. }
  1654. requiredModules[module].push(entryModule);
  1655. sources[module][entryModule] = '(function(module, exports, __webpack_require__) { module.exports = __webpack_require__; })';
  1656. src = src + 'var ' + module + ' = (' + webpackBootstrapFunc.toString().replace('ENTRY_MODULE', JSON.stringify(entryModule)) + ')({' + requiredModules[module].map(function (id) { return '' + JSON.stringify(id) + ': ' + sources[module][id].toString(); }).join(',') + '});\n';
  1657. });
  1658. src = src + 'new ((' + webpackBootstrapFunc.toString().replace('ENTRY_MODULE', JSON.stringify(moduleId)) + ')({' + requiredModules.main.map(function (id) { return '' + JSON.stringify(id) + ': ' + sources.main[id].toString(); }).join(',') + '}))(self);';
  1659. var blob = new window.Blob([src], { type: 'text/javascript' });
  1660. if (options.bare) {
  1661. return blob;
  1662. }
  1663. var URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
  1664. var workerUrl = URL.createObjectURL(blob);
  1665. var worker = new window.Worker(workerUrl);
  1666. worker.objectURL = workerUrl;
  1667. return worker;
  1668. };
  1669. /***/ }),
  1670. /***/ "./src/config.js":
  1671. /*!***********************!*\
  1672. !*** ./src/config.js ***!
  1673. \***********************/
  1674. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  1675. "use strict";
  1676. __webpack_require__.r(__webpack_exports__);
  1677. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  1678. /* harmony export */ "defaultConfig": function() { return /* binding */ defaultConfig; },
  1679. /* harmony export */ "createDefaultConfig": function() { return /* binding */ createDefaultConfig; }
  1680. /* harmony export */ });
  1681. /*
  1682. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  1683. *
  1684. * @author zheng qian <xqq@xqq.im>
  1685. *
  1686. * Licensed under the Apache License, Version 2.0 (the "License");
  1687. * you may not use this file except in compliance with the License.
  1688. * You may obtain a copy of the License at
  1689. *
  1690. * http://www.apache.org/licenses/LICENSE-2.0
  1691. *
  1692. * Unless required by applicable law or agreed to in writing, software
  1693. * distributed under the License is distributed on an "AS IS" BASIS,
  1694. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1695. * See the License for the specific language governing permissions and
  1696. * limitations under the License.
  1697. */
  1698. var defaultConfig = {
  1699. enableWorker: false,
  1700. enableStashBuffer: true,
  1701. stashInitialSize: undefined,
  1702. isLive: false,
  1703. lazyLoad: true,
  1704. lazyLoadMaxDuration: 3 * 60,
  1705. lazyLoadRecoverDuration: 30,
  1706. deferLoadAfterSourceOpen: true,
  1707. // autoCleanupSourceBuffer: default as false, leave unspecified
  1708. autoCleanupMaxBackwardDuration: 3 * 60,
  1709. autoCleanupMinBackwardDuration: 2 * 60,
  1710. statisticsInfoReportInterval: 600,
  1711. fixAudioTimestampGap: true,
  1712. accurateSeek: false,
  1713. seekType: 'range',
  1714. seekParamStart: 'bstart',
  1715. seekParamEnd: 'bend',
  1716. rangeLoadZeroStart: false,
  1717. customSeekHandler: undefined,
  1718. reuseRedirectedURL: false,
  1719. // referrerPolicy: leave as unspecified
  1720. headers: undefined,
  1721. customLoader: undefined
  1722. };
  1723. function createDefaultConfig() {
  1724. return Object.assign({}, defaultConfig);
  1725. }
  1726. /***/ }),
  1727. /***/ "./src/core/features.js":
  1728. /*!******************************!*\
  1729. !*** ./src/core/features.js ***!
  1730. \******************************/
  1731. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  1732. "use strict";
  1733. __webpack_require__.r(__webpack_exports__);
  1734. /* harmony import */ var _io_io_controller_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../io/io-controller.js */ "./src/io/io-controller.js");
  1735. /* harmony import */ var _config_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../config.js */ "./src/config.js");
  1736. /*
  1737. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  1738. *
  1739. * @author zheng qian <xqq@xqq.im>
  1740. *
  1741. * Licensed under the Apache License, Version 2.0 (the "License");
  1742. * you may not use this file except in compliance with the License.
  1743. * You may obtain a copy of the License at
  1744. *
  1745. * http://www.apache.org/licenses/LICENSE-2.0
  1746. *
  1747. * Unless required by applicable law or agreed to in writing, software
  1748. * distributed under the License is distributed on an "AS IS" BASIS,
  1749. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1750. * See the License for the specific language governing permissions and
  1751. * limitations under the License.
  1752. */
  1753. var Features = /** @class */ (function () {
  1754. function Features() {
  1755. }
  1756. Features.supportMSEH264Playback = function () {
  1757. return window.MediaSource &&
  1758. window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"');
  1759. };
  1760. Features.supportNetworkStreamIO = function () {
  1761. var ioctl = new _io_io_controller_js__WEBPACK_IMPORTED_MODULE_0__.default({}, (0,_config_js__WEBPACK_IMPORTED_MODULE_1__.createDefaultConfig)());
  1762. var loaderType = ioctl.loaderType;
  1763. ioctl.destroy();
  1764. return loaderType == 'fetch-stream-loader' || loaderType == 'xhr-moz-chunked-loader';
  1765. };
  1766. Features.getNetworkLoaderTypeName = function () {
  1767. var ioctl = new _io_io_controller_js__WEBPACK_IMPORTED_MODULE_0__.default({}, (0,_config_js__WEBPACK_IMPORTED_MODULE_1__.createDefaultConfig)());
  1768. var loaderType = ioctl.loaderType;
  1769. ioctl.destroy();
  1770. return loaderType;
  1771. };
  1772. Features.supportNativeMediaPlayback = function (mimeType) {
  1773. if (Features.videoElement == undefined) {
  1774. Features.videoElement = window.document.createElement('video');
  1775. }
  1776. var canPlay = Features.videoElement.canPlayType(mimeType);
  1777. return canPlay === 'probably' || canPlay == 'maybe';
  1778. };
  1779. Features.getFeatureList = function () {
  1780. var features = {
  1781. mseFlvPlayback: false,
  1782. mseLiveFlvPlayback: false,
  1783. networkStreamIO: false,
  1784. networkLoaderName: '',
  1785. nativeMP4H264Playback: false,
  1786. nativeWebmVP8Playback: false,
  1787. nativeWebmVP9Playback: false
  1788. };
  1789. features.mseFlvPlayback = Features.supportMSEH264Playback();
  1790. features.networkStreamIO = Features.supportNetworkStreamIO();
  1791. features.networkLoaderName = Features.getNetworkLoaderTypeName();
  1792. features.mseLiveFlvPlayback = features.mseFlvPlayback && features.networkStreamIO;
  1793. features.nativeMP4H264Playback = Features.supportNativeMediaPlayback('video/mp4; codecs="avc1.42001E, mp4a.40.2"');
  1794. features.nativeWebmVP8Playback = Features.supportNativeMediaPlayback('video/webm; codecs="vp8.0, vorbis"');
  1795. features.nativeWebmVP9Playback = Features.supportNativeMediaPlayback('video/webm; codecs="vp9"');
  1796. return features;
  1797. };
  1798. return Features;
  1799. }());
  1800. /* harmony default export */ __webpack_exports__["default"] = (Features);
  1801. /***/ }),
  1802. /***/ "./src/core/media-info.js":
  1803. /*!********************************!*\
  1804. !*** ./src/core/media-info.js ***!
  1805. \********************************/
  1806. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  1807. "use strict";
  1808. __webpack_require__.r(__webpack_exports__);
  1809. /*
  1810. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  1811. *
  1812. * @author zheng qian <xqq@xqq.im>
  1813. *
  1814. * Licensed under the Apache License, Version 2.0 (the "License");
  1815. * you may not use this file except in compliance with the License.
  1816. * You may obtain a copy of the License at
  1817. *
  1818. * http://www.apache.org/licenses/LICENSE-2.0
  1819. *
  1820. * Unless required by applicable law or agreed to in writing, software
  1821. * distributed under the License is distributed on an "AS IS" BASIS,
  1822. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1823. * See the License for the specific language governing permissions and
  1824. * limitations under the License.
  1825. */
  1826. var MediaInfo = /** @class */ (function () {
  1827. function MediaInfo() {
  1828. this.mimeType = null;
  1829. this.duration = null;
  1830. this.hasAudio = null;
  1831. this.hasVideo = null;
  1832. this.audioCodec = null;
  1833. this.videoCodec = null;
  1834. this.audioDataRate = null;
  1835. this.videoDataRate = null;
  1836. this.audioSampleRate = null;
  1837. this.audioChannelCount = null;
  1838. this.width = null;
  1839. this.height = null;
  1840. this.fps = null;
  1841. this.profile = null;
  1842. this.level = null;
  1843. this.refFrames = null;
  1844. this.chromaFormat = null;
  1845. this.sarNum = null;
  1846. this.sarDen = null;
  1847. this.metadata = null;
  1848. this.segments = null; // MediaInfo[]
  1849. this.segmentCount = null;
  1850. this.hasKeyframesIndex = null;
  1851. this.keyframesIndex = null;
  1852. }
  1853. MediaInfo.prototype.isComplete = function () {
  1854. var audioInfoComplete = (this.hasAudio === false) ||
  1855. (this.hasAudio === true &&
  1856. this.audioCodec != null &&
  1857. this.audioSampleRate != null &&
  1858. this.audioChannelCount != null);
  1859. var videoInfoComplete = (this.hasVideo === false) ||
  1860. (this.hasVideo === true &&
  1861. this.videoCodec != null &&
  1862. this.width != null &&
  1863. this.height != null &&
  1864. this.fps != null &&
  1865. this.profile != null &&
  1866. this.level != null &&
  1867. this.refFrames != null &&
  1868. this.chromaFormat != null &&
  1869. this.sarNum != null &&
  1870. this.sarDen != null);
  1871. // keyframesIndex may not be present
  1872. return this.mimeType != null &&
  1873. this.duration != null &&
  1874. this.metadata != null &&
  1875. this.hasKeyframesIndex != null &&
  1876. audioInfoComplete &&
  1877. videoInfoComplete;
  1878. };
  1879. MediaInfo.prototype.isSeekable = function () {
  1880. return this.hasKeyframesIndex === true;
  1881. };
  1882. MediaInfo.prototype.getNearestKeyframe = function (milliseconds) {
  1883. if (this.keyframesIndex == null) {
  1884. return null;
  1885. }
  1886. var table = this.keyframesIndex;
  1887. var keyframeIdx = this._search(table.times, milliseconds);
  1888. return {
  1889. index: keyframeIdx,
  1890. milliseconds: table.times[keyframeIdx],
  1891. fileposition: table.filepositions[keyframeIdx]
  1892. };
  1893. };
  1894. MediaInfo.prototype._search = function (list, value) {
  1895. var idx = 0;
  1896. var last = list.length - 1;
  1897. var mid = 0;
  1898. var lbound = 0;
  1899. var ubound = last;
  1900. if (value < list[0]) {
  1901. idx = 0;
  1902. lbound = ubound + 1; // skip search
  1903. }
  1904. while (lbound <= ubound) {
  1905. mid = lbound + Math.floor((ubound - lbound) / 2);
  1906. if (mid === last || (value >= list[mid] && value < list[mid + 1])) {
  1907. idx = mid;
  1908. break;
  1909. }
  1910. else if (list[mid] < value) {
  1911. lbound = mid + 1;
  1912. }
  1913. else {
  1914. ubound = mid - 1;
  1915. }
  1916. }
  1917. return idx;
  1918. };
  1919. return MediaInfo;
  1920. }());
  1921. /* harmony default export */ __webpack_exports__["default"] = (MediaInfo);
  1922. /***/ }),
  1923. /***/ "./src/core/media-segment-info.js":
  1924. /*!****************************************!*\
  1925. !*** ./src/core/media-segment-info.js ***!
  1926. \****************************************/
  1927. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  1928. "use strict";
  1929. __webpack_require__.r(__webpack_exports__);
  1930. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  1931. /* harmony export */ "SampleInfo": function() { return /* binding */ SampleInfo; },
  1932. /* harmony export */ "MediaSegmentInfo": function() { return /* binding */ MediaSegmentInfo; },
  1933. /* harmony export */ "IDRSampleList": function() { return /* binding */ IDRSampleList; },
  1934. /* harmony export */ "MediaSegmentInfoList": function() { return /* binding */ MediaSegmentInfoList; }
  1935. /* harmony export */ });
  1936. /*
  1937. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  1938. *
  1939. * @author zheng qian <xqq@xqq.im>
  1940. *
  1941. * Licensed under the Apache License, Version 2.0 (the "License");
  1942. * you may not use this file except in compliance with the License.
  1943. * You may obtain a copy of the License at
  1944. *
  1945. * http://www.apache.org/licenses/LICENSE-2.0
  1946. *
  1947. * Unless required by applicable law or agreed to in writing, software
  1948. * distributed under the License is distributed on an "AS IS" BASIS,
  1949. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1950. * See the License for the specific language governing permissions and
  1951. * limitations under the License.
  1952. */
  1953. // Represents an media sample (audio / video)
  1954. var SampleInfo = /** @class */ (function () {
  1955. function SampleInfo(dts, pts, duration, originalDts, isSync) {
  1956. this.dts = dts;
  1957. this.pts = pts;
  1958. this.duration = duration;
  1959. this.originalDts = originalDts;
  1960. this.isSyncPoint = isSync;
  1961. this.fileposition = null;
  1962. }
  1963. return SampleInfo;
  1964. }());
  1965. // Media Segment concept is defined in Media Source Extensions spec.
  1966. // Particularly in ISO BMFF format, an Media Segment contains a moof box followed by a mdat box.
  1967. var MediaSegmentInfo = /** @class */ (function () {
  1968. function MediaSegmentInfo() {
  1969. this.beginDts = 0;
  1970. this.endDts = 0;
  1971. this.beginPts = 0;
  1972. this.endPts = 0;
  1973. this.originalBeginDts = 0;
  1974. this.originalEndDts = 0;
  1975. this.syncPoints = []; // SampleInfo[n], for video IDR frames only
  1976. this.firstSample = null; // SampleInfo
  1977. this.lastSample = null; // SampleInfo
  1978. }
  1979. MediaSegmentInfo.prototype.appendSyncPoint = function (sampleInfo) {
  1980. sampleInfo.isSyncPoint = true;
  1981. this.syncPoints.push(sampleInfo);
  1982. };
  1983. return MediaSegmentInfo;
  1984. }());
  1985. // Ordered list for recording video IDR frames, sorted by originalDts
  1986. var IDRSampleList = /** @class */ (function () {
  1987. function IDRSampleList() {
  1988. this._list = [];
  1989. }
  1990. IDRSampleList.prototype.clear = function () {
  1991. this._list = [];
  1992. };
  1993. IDRSampleList.prototype.appendArray = function (syncPoints) {
  1994. var list = this._list;
  1995. if (syncPoints.length === 0) {
  1996. return;
  1997. }
  1998. if (list.length > 0 && syncPoints[0].originalDts < list[list.length - 1].originalDts) {
  1999. this.clear();
  2000. }
  2001. Array.prototype.push.apply(list, syncPoints);
  2002. };
  2003. IDRSampleList.prototype.getLastSyncPointBeforeDts = function (dts) {
  2004. if (this._list.length == 0) {
  2005. return null;
  2006. }
  2007. var list = this._list;
  2008. var idx = 0;
  2009. var last = list.length - 1;
  2010. var mid = 0;
  2011. var lbound = 0;
  2012. var ubound = last;
  2013. if (dts < list[0].dts) {
  2014. idx = 0;
  2015. lbound = ubound + 1;
  2016. }
  2017. while (lbound <= ubound) {
  2018. mid = lbound + Math.floor((ubound - lbound) / 2);
  2019. if (mid === last || (dts >= list[mid].dts && dts < list[mid + 1].dts)) {
  2020. idx = mid;
  2021. break;
  2022. }
  2023. else if (list[mid].dts < dts) {
  2024. lbound = mid + 1;
  2025. }
  2026. else {
  2027. ubound = mid - 1;
  2028. }
  2029. }
  2030. return this._list[idx];
  2031. };
  2032. return IDRSampleList;
  2033. }());
  2034. // Data structure for recording information of media segments in single track.
  2035. var MediaSegmentInfoList = /** @class */ (function () {
  2036. function MediaSegmentInfoList(type) {
  2037. this._type = type;
  2038. this._list = [];
  2039. this._lastAppendLocation = -1; // cached last insert location
  2040. }
  2041. Object.defineProperty(MediaSegmentInfoList.prototype, "type", {
  2042. get: function () {
  2043. return this._type;
  2044. },
  2045. enumerable: false,
  2046. configurable: true
  2047. });
  2048. Object.defineProperty(MediaSegmentInfoList.prototype, "length", {
  2049. get: function () {
  2050. return this._list.length;
  2051. },
  2052. enumerable: false,
  2053. configurable: true
  2054. });
  2055. MediaSegmentInfoList.prototype.isEmpty = function () {
  2056. return this._list.length === 0;
  2057. };
  2058. MediaSegmentInfoList.prototype.clear = function () {
  2059. this._list = [];
  2060. this._lastAppendLocation = -1;
  2061. };
  2062. MediaSegmentInfoList.prototype._searchNearestSegmentBefore = function (originalBeginDts) {
  2063. var list = this._list;
  2064. if (list.length === 0) {
  2065. return -2;
  2066. }
  2067. var last = list.length - 1;
  2068. var mid = 0;
  2069. var lbound = 0;
  2070. var ubound = last;
  2071. var idx = 0;
  2072. if (originalBeginDts < list[0].originalBeginDts) {
  2073. idx = -1;
  2074. return idx;
  2075. }
  2076. while (lbound <= ubound) {
  2077. mid = lbound + Math.floor((ubound - lbound) / 2);
  2078. if (mid === last || (originalBeginDts > list[mid].lastSample.originalDts &&
  2079. (originalBeginDts < list[mid + 1].originalBeginDts))) {
  2080. idx = mid;
  2081. break;
  2082. }
  2083. else if (list[mid].originalBeginDts < originalBeginDts) {
  2084. lbound = mid + 1;
  2085. }
  2086. else {
  2087. ubound = mid - 1;
  2088. }
  2089. }
  2090. return idx;
  2091. };
  2092. MediaSegmentInfoList.prototype._searchNearestSegmentAfter = function (originalBeginDts) {
  2093. return this._searchNearestSegmentBefore(originalBeginDts) + 1;
  2094. };
  2095. MediaSegmentInfoList.prototype.append = function (mediaSegmentInfo) {
  2096. var list = this._list;
  2097. var msi = mediaSegmentInfo;
  2098. var lastAppendIdx = this._lastAppendLocation;
  2099. var insertIdx = 0;
  2100. if (lastAppendIdx !== -1 && lastAppendIdx < list.length &&
  2101. msi.originalBeginDts >= list[lastAppendIdx].lastSample.originalDts &&
  2102. ((lastAppendIdx === list.length - 1) ||
  2103. (lastAppendIdx < list.length - 1 &&
  2104. msi.originalBeginDts < list[lastAppendIdx + 1].originalBeginDts))) {
  2105. insertIdx = lastAppendIdx + 1; // use cached location idx
  2106. }
  2107. else {
  2108. if (list.length > 0) {
  2109. insertIdx = this._searchNearestSegmentBefore(msi.originalBeginDts) + 1;
  2110. }
  2111. }
  2112. this._lastAppendLocation = insertIdx;
  2113. this._list.splice(insertIdx, 0, msi);
  2114. };
  2115. MediaSegmentInfoList.prototype.getLastSegmentBefore = function (originalBeginDts) {
  2116. var idx = this._searchNearestSegmentBefore(originalBeginDts);
  2117. if (idx >= 0) {
  2118. return this._list[idx];
  2119. }
  2120. else { // -1
  2121. return null;
  2122. }
  2123. };
  2124. MediaSegmentInfoList.prototype.getLastSampleBefore = function (originalBeginDts) {
  2125. var segment = this.getLastSegmentBefore(originalBeginDts);
  2126. if (segment != null) {
  2127. return segment.lastSample;
  2128. }
  2129. else {
  2130. return null;
  2131. }
  2132. };
  2133. MediaSegmentInfoList.prototype.getLastSyncPointBefore = function (originalBeginDts) {
  2134. var segmentIdx = this._searchNearestSegmentBefore(originalBeginDts);
  2135. var syncPoints = this._list[segmentIdx].syncPoints;
  2136. while (syncPoints.length === 0 && segmentIdx > 0) {
  2137. segmentIdx--;
  2138. syncPoints = this._list[segmentIdx].syncPoints;
  2139. }
  2140. if (syncPoints.length > 0) {
  2141. return syncPoints[syncPoints.length - 1];
  2142. }
  2143. else {
  2144. return null;
  2145. }
  2146. };
  2147. return MediaSegmentInfoList;
  2148. }());
  2149. /***/ }),
  2150. /***/ "./src/core/mse-controller.js":
  2151. /*!************************************!*\
  2152. !*** ./src/core/mse-controller.js ***!
  2153. \************************************/
  2154. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  2155. "use strict";
  2156. __webpack_require__.r(__webpack_exports__);
  2157. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! events */ "./node_modules/events/events.js");
  2158. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(events__WEBPACK_IMPORTED_MODULE_0__);
  2159. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  2160. /* harmony import */ var _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/browser.js */ "./src/utils/browser.js");
  2161. /* harmony import */ var _mse_events_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./mse-events.js */ "./src/core/mse-events.js");
  2162. /* harmony import */ var _media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./media-segment-info.js */ "./src/core/media-segment-info.js");
  2163. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  2164. /*
  2165. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  2166. *
  2167. * @author zheng qian <xqq@xqq.im>
  2168. *
  2169. * Licensed under the Apache License, Version 2.0 (the "License");
  2170. * you may not use this file except in compliance with the License.
  2171. * You may obtain a copy of the License at
  2172. *
  2173. * http://www.apache.org/licenses/LICENSE-2.0
  2174. *
  2175. * Unless required by applicable law or agreed to in writing, software
  2176. * distributed under the License is distributed on an "AS IS" BASIS,
  2177. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2178. * See the License for the specific language governing permissions and
  2179. * limitations under the License.
  2180. */
  2181. // Media Source Extensions controller
  2182. var MSEController = /** @class */ (function () {
  2183. function MSEController(config) {
  2184. this.TAG = 'MSEController';
  2185. this._config = config;
  2186. this._emitter = new (events__WEBPACK_IMPORTED_MODULE_0___default())();
  2187. if (this._config.isLive && this._config.autoCleanupSourceBuffer == undefined) {
  2188. // For live stream, do auto cleanup by default
  2189. this._config.autoCleanupSourceBuffer = true;
  2190. }
  2191. this.e = {
  2192. onSourceOpen: this._onSourceOpen.bind(this),
  2193. onSourceEnded: this._onSourceEnded.bind(this),
  2194. onSourceClose: this._onSourceClose.bind(this),
  2195. onSourceBufferError: this._onSourceBufferError.bind(this),
  2196. onSourceBufferUpdateEnd: this._onSourceBufferUpdateEnd.bind(this)
  2197. };
  2198. this._mediaSource = null;
  2199. this._mediaSourceObjectURL = null;
  2200. this._mediaElement = null;
  2201. this._isBufferFull = false;
  2202. this._hasPendingEos = false;
  2203. this._requireSetMediaDuration = false;
  2204. this._pendingMediaDuration = 0;
  2205. this._pendingSourceBufferInit = [];
  2206. this._mimeTypes = {
  2207. video: null,
  2208. audio: null
  2209. };
  2210. this._sourceBuffers = {
  2211. video: null,
  2212. audio: null
  2213. };
  2214. this._lastInitSegments = {
  2215. video: null,
  2216. audio: null
  2217. };
  2218. this._pendingSegments = {
  2219. video: [],
  2220. audio: []
  2221. };
  2222. this._pendingRemoveRanges = {
  2223. video: [],
  2224. audio: []
  2225. };
  2226. this._idrList = new _media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.IDRSampleList();
  2227. }
  2228. MSEController.prototype.destroy = function () {
  2229. if (this._mediaElement || this._mediaSource) {
  2230. this.detachMediaElement();
  2231. }
  2232. this.e = null;
  2233. this._emitter.removeAllListeners();
  2234. this._emitter = null;
  2235. };
  2236. MSEController.prototype.on = function (event, listener) {
  2237. this._emitter.addListener(event, listener);
  2238. };
  2239. MSEController.prototype.off = function (event, listener) {
  2240. this._emitter.removeListener(event, listener);
  2241. };
  2242. MSEController.prototype.attachMediaElement = function (mediaElement) {
  2243. if (this._mediaSource) {
  2244. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_5__.IllegalStateException('MediaSource has been attached to an HTMLMediaElement!');
  2245. }
  2246. var ms = this._mediaSource = new window.MediaSource();
  2247. ms.addEventListener('sourceopen', this.e.onSourceOpen);
  2248. ms.addEventListener('sourceended', this.e.onSourceEnded);
  2249. ms.addEventListener('sourceclose', this.e.onSourceClose);
  2250. this._mediaElement = mediaElement;
  2251. this._mediaSourceObjectURL = window.URL.createObjectURL(this._mediaSource);
  2252. mediaElement.src = this._mediaSourceObjectURL;
  2253. };
  2254. MSEController.prototype.detachMediaElement = function () {
  2255. if (this._mediaSource) {
  2256. var ms = this._mediaSource;
  2257. for (var type in this._sourceBuffers) {
  2258. // pending segments should be discard
  2259. var ps = this._pendingSegments[type];
  2260. ps.splice(0, ps.length);
  2261. this._pendingSegments[type] = null;
  2262. this._pendingRemoveRanges[type] = null;
  2263. this._lastInitSegments[type] = null;
  2264. // remove all sourcebuffers
  2265. var sb = this._sourceBuffers[type];
  2266. if (sb) {
  2267. if (ms.readyState !== 'closed') {
  2268. // ms edge can throw an error: Unexpected call to method or property access
  2269. try {
  2270. ms.removeSourceBuffer(sb);
  2271. }
  2272. catch (error) {
  2273. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.e(this.TAG, error.message);
  2274. }
  2275. sb.removeEventListener('error', this.e.onSourceBufferError);
  2276. sb.removeEventListener('updateend', this.e.onSourceBufferUpdateEnd);
  2277. }
  2278. this._mimeTypes[type] = null;
  2279. this._sourceBuffers[type] = null;
  2280. }
  2281. }
  2282. if (ms.readyState === 'open') {
  2283. try {
  2284. ms.endOfStream();
  2285. }
  2286. catch (error) {
  2287. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.e(this.TAG, error.message);
  2288. }
  2289. }
  2290. ms.removeEventListener('sourceopen', this.e.onSourceOpen);
  2291. ms.removeEventListener('sourceended', this.e.onSourceEnded);
  2292. ms.removeEventListener('sourceclose', this.e.onSourceClose);
  2293. this._pendingSourceBufferInit = [];
  2294. this._isBufferFull = false;
  2295. this._idrList.clear();
  2296. this._mediaSource = null;
  2297. }
  2298. if (this._mediaElement) {
  2299. this._mediaElement.src = '';
  2300. this._mediaElement.removeAttribute('src');
  2301. this._mediaElement = null;
  2302. }
  2303. if (this._mediaSourceObjectURL) {
  2304. window.URL.revokeObjectURL(this._mediaSourceObjectURL);
  2305. this._mediaSourceObjectURL = null;
  2306. }
  2307. };
  2308. MSEController.prototype.appendInitSegment = function (initSegment, deferred) {
  2309. if (!this._mediaSource || this._mediaSource.readyState !== 'open') {
  2310. // sourcebuffer creation requires mediaSource.readyState === 'open'
  2311. // so we defer the sourcebuffer creation, until sourceopen event triggered
  2312. this._pendingSourceBufferInit.push(initSegment);
  2313. // make sure that this InitSegment is in the front of pending segments queue
  2314. this._pendingSegments[initSegment.type].push(initSegment);
  2315. return;
  2316. }
  2317. var is = initSegment;
  2318. var mimeType = "" + is.container;
  2319. if (is.codec && is.codec.length > 0) {
  2320. mimeType += ";codecs=" + is.codec;
  2321. }
  2322. var firstInitSegment = false;
  2323. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, 'Received Initialization Segment, mimeType: ' + mimeType);
  2324. this._lastInitSegments[is.type] = is;
  2325. if (mimeType !== this._mimeTypes[is.type]) {
  2326. if (!this._mimeTypes[is.type]) { // empty, first chance create sourcebuffer
  2327. firstInitSegment = true;
  2328. try {
  2329. var sb = this._sourceBuffers[is.type] = this._mediaSource.addSourceBuffer(mimeType);
  2330. sb.addEventListener('error', this.e.onSourceBufferError);
  2331. sb.addEventListener('updateend', this.e.onSourceBufferUpdateEnd);
  2332. }
  2333. catch (error) {
  2334. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.e(this.TAG, error.message);
  2335. this._emitter.emit(_mse_events_js__WEBPACK_IMPORTED_MODULE_3__.default.ERROR, { code: error.code, msg: error.message });
  2336. return;
  2337. }
  2338. }
  2339. else {
  2340. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, "Notice: " + is.type + " mimeType changed, origin: " + this._mimeTypes[is.type] + ", target: " + mimeType);
  2341. }
  2342. this._mimeTypes[is.type] = mimeType;
  2343. }
  2344. if (!deferred) {
  2345. // deferred means this InitSegment has been pushed to pendingSegments queue
  2346. this._pendingSegments[is.type].push(is);
  2347. }
  2348. if (!firstInitSegment) { // append immediately only if init segment in subsequence
  2349. if (this._sourceBuffers[is.type] && !this._sourceBuffers[is.type].updating) {
  2350. this._doAppendSegments();
  2351. }
  2352. }
  2353. if (_utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.safari && is.container === 'audio/mpeg' && is.mediaDuration > 0) {
  2354. // 'audio/mpeg' track under Safari may cause MediaElement's duration to be NaN
  2355. // Manually correct MediaSource.duration to make progress bar seekable, and report right duration
  2356. this._requireSetMediaDuration = true;
  2357. this._pendingMediaDuration = is.mediaDuration / 1000; // in seconds
  2358. this._updateMediaSourceDuration();
  2359. }
  2360. };
  2361. MSEController.prototype.appendMediaSegment = function (mediaSegment) {
  2362. var ms = mediaSegment;
  2363. this._pendingSegments[ms.type].push(ms);
  2364. if (this._config.autoCleanupSourceBuffer && this._needCleanupSourceBuffer()) {
  2365. this._doCleanupSourceBuffer();
  2366. }
  2367. var sb = this._sourceBuffers[ms.type];
  2368. if (sb && !sb.updating && !this._hasPendingRemoveRanges()) {
  2369. this._doAppendSegments();
  2370. }
  2371. };
  2372. MSEController.prototype.seek = function (seconds) {
  2373. // remove all appended buffers
  2374. for (var type in this._sourceBuffers) {
  2375. if (!this._sourceBuffers[type]) {
  2376. continue;
  2377. }
  2378. // abort current buffer append algorithm
  2379. var sb = this._sourceBuffers[type];
  2380. if (this._mediaSource.readyState === 'open') {
  2381. try {
  2382. // If range removal algorithm is running, InvalidStateError will be throwed
  2383. // Ignore it.
  2384. sb.abort();
  2385. }
  2386. catch (error) {
  2387. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.e(this.TAG, error.message);
  2388. }
  2389. }
  2390. // IDRList should be clear
  2391. this._idrList.clear();
  2392. // pending segments should be discard
  2393. var ps = this._pendingSegments[type];
  2394. ps.splice(0, ps.length);
  2395. if (this._mediaSource.readyState === 'closed') {
  2396. // Parent MediaSource object has been detached from HTMLMediaElement
  2397. continue;
  2398. }
  2399. // record ranges to be remove from SourceBuffer
  2400. for (var i = 0; i < sb.buffered.length; i++) {
  2401. var start = sb.buffered.start(i);
  2402. var end = sb.buffered.end(i);
  2403. this._pendingRemoveRanges[type].push({ start: start, end: end });
  2404. }
  2405. // if sb is not updating, let's remove ranges now!
  2406. if (!sb.updating) {
  2407. this._doRemoveRanges();
  2408. }
  2409. // Safari 10 may get InvalidStateError in the later appendBuffer() after SourceBuffer.remove() call
  2410. // Internal parser's state may be invalid at this time. Re-append last InitSegment to workaround.
  2411. // Related issue: https://bugs.webkit.org/show_bug.cgi?id=159230
  2412. if (_utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.safari) {
  2413. var lastInitSegment = this._lastInitSegments[type];
  2414. if (lastInitSegment) {
  2415. this._pendingSegments[type].push(lastInitSegment);
  2416. if (!sb.updating) {
  2417. this._doAppendSegments();
  2418. }
  2419. }
  2420. }
  2421. }
  2422. };
  2423. MSEController.prototype.endOfStream = function () {
  2424. var ms = this._mediaSource;
  2425. var sb = this._sourceBuffers;
  2426. if (!ms || ms.readyState !== 'open') {
  2427. if (ms && ms.readyState === 'closed' && this._hasPendingSegments()) {
  2428. // If MediaSource hasn't turned into open state, and there're pending segments
  2429. // Mark pending endOfStream, defer call until all pending segments appended complete
  2430. this._hasPendingEos = true;
  2431. }
  2432. return;
  2433. }
  2434. if (sb.video && sb.video.updating || sb.audio && sb.audio.updating) {
  2435. // If any sourcebuffer is updating, defer endOfStream operation
  2436. // See _onSourceBufferUpdateEnd()
  2437. this._hasPendingEos = true;
  2438. }
  2439. else {
  2440. this._hasPendingEos = false;
  2441. // Notify media data loading complete
  2442. // This is helpful for correcting total duration to match last media segment
  2443. // Otherwise MediaElement's ended event may not be triggered
  2444. ms.endOfStream();
  2445. }
  2446. };
  2447. MSEController.prototype.getNearestKeyframe = function (dts) {
  2448. return this._idrList.getLastSyncPointBeforeDts(dts);
  2449. };
  2450. MSEController.prototype._needCleanupSourceBuffer = function () {
  2451. if (!this._config.autoCleanupSourceBuffer) {
  2452. return false;
  2453. }
  2454. var currentTime = this._mediaElement.currentTime;
  2455. for (var type in this._sourceBuffers) {
  2456. var sb = this._sourceBuffers[type];
  2457. if (sb) {
  2458. var buffered = sb.buffered;
  2459. if (buffered.length >= 1) {
  2460. if (currentTime - buffered.start(0) >= this._config.autoCleanupMaxBackwardDuration) {
  2461. return true;
  2462. }
  2463. }
  2464. }
  2465. }
  2466. return false;
  2467. };
  2468. MSEController.prototype._doCleanupSourceBuffer = function () {
  2469. var currentTime = this._mediaElement.currentTime;
  2470. for (var type in this._sourceBuffers) {
  2471. var sb = this._sourceBuffers[type];
  2472. if (sb) {
  2473. var buffered = sb.buffered;
  2474. var doRemove = false;
  2475. for (var i = 0; i < buffered.length; i++) {
  2476. var start = buffered.start(i);
  2477. var end = buffered.end(i);
  2478. if (start <= currentTime && currentTime < end + 3) { // padding 3 seconds
  2479. if (currentTime - start >= this._config.autoCleanupMaxBackwardDuration) {
  2480. doRemove = true;
  2481. var removeEnd = currentTime - this._config.autoCleanupMinBackwardDuration;
  2482. this._pendingRemoveRanges[type].push({ start: start, end: removeEnd });
  2483. }
  2484. }
  2485. else if (end < currentTime) {
  2486. doRemove = true;
  2487. this._pendingRemoveRanges[type].push({ start: start, end: end });
  2488. }
  2489. }
  2490. if (doRemove && !sb.updating) {
  2491. this._doRemoveRanges();
  2492. }
  2493. }
  2494. }
  2495. };
  2496. MSEController.prototype._updateMediaSourceDuration = function () {
  2497. var sb = this._sourceBuffers;
  2498. if (this._mediaElement.readyState === 0 || this._mediaSource.readyState !== 'open') {
  2499. return;
  2500. }
  2501. if ((sb.video && sb.video.updating) || (sb.audio && sb.audio.updating)) {
  2502. return;
  2503. }
  2504. var current = this._mediaSource.duration;
  2505. var target = this._pendingMediaDuration;
  2506. if (target > 0 && (isNaN(current) || target > current)) {
  2507. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, "Update MediaSource duration from " + current + " to " + target);
  2508. this._mediaSource.duration = target;
  2509. }
  2510. this._requireSetMediaDuration = false;
  2511. this._pendingMediaDuration = 0;
  2512. };
  2513. MSEController.prototype._doRemoveRanges = function () {
  2514. for (var type in this._pendingRemoveRanges) {
  2515. if (!this._sourceBuffers[type] || this._sourceBuffers[type].updating) {
  2516. continue;
  2517. }
  2518. var sb = this._sourceBuffers[type];
  2519. var ranges = this._pendingRemoveRanges[type];
  2520. while (ranges.length && !sb.updating) {
  2521. var range = ranges.shift();
  2522. sb.remove(range.start, range.end);
  2523. }
  2524. }
  2525. };
  2526. MSEController.prototype._doAppendSegments = function () {
  2527. var pendingSegments = this._pendingSegments;
  2528. for (var type in pendingSegments) {
  2529. if (!this._sourceBuffers[type] || this._sourceBuffers[type].updating) {
  2530. continue;
  2531. }
  2532. if (pendingSegments[type].length > 0) {
  2533. var segment = pendingSegments[type].shift();
  2534. if (segment.timestampOffset) {
  2535. // For MPEG audio stream in MSE, if unbuffered-seeking occurred
  2536. // We need explicitly set timestampOffset to the desired point in timeline for mpeg SourceBuffer.
  2537. var currentOffset = this._sourceBuffers[type].timestampOffset;
  2538. var targetOffset = segment.timestampOffset / 1000; // in seconds
  2539. var delta = Math.abs(currentOffset - targetOffset);
  2540. if (delta > 0.1) { // If time delta > 100ms
  2541. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, "Update MPEG audio timestampOffset from " + currentOffset + " to " + targetOffset);
  2542. this._sourceBuffers[type].timestampOffset = targetOffset;
  2543. }
  2544. delete segment.timestampOffset;
  2545. }
  2546. if (!segment.data || segment.data.byteLength === 0) {
  2547. // Ignore empty buffer
  2548. continue;
  2549. }
  2550. try {
  2551. this._sourceBuffers[type].appendBuffer(segment.data);
  2552. this._isBufferFull = false;
  2553. if (type === 'video' && segment.hasOwnProperty('info')) {
  2554. this._idrList.appendArray(segment.info.syncPoints);
  2555. }
  2556. }
  2557. catch (error) {
  2558. this._pendingSegments[type].unshift(segment);
  2559. if (error.code === 22) { // QuotaExceededError
  2560. /* Notice that FireFox may not throw QuotaExceededError if SourceBuffer is full
  2561. * Currently we can only do lazy-load to avoid SourceBuffer become scattered.
  2562. * SourceBuffer eviction policy may be changed in future version of FireFox.
  2563. *
  2564. * Related issues:
  2565. * https://bugzilla.mozilla.org/show_bug.cgi?id=1279885
  2566. * https://bugzilla.mozilla.org/show_bug.cgi?id=1280023
  2567. */
  2568. // report buffer full, abort network IO
  2569. if (!this._isBufferFull) {
  2570. this._emitter.emit(_mse_events_js__WEBPACK_IMPORTED_MODULE_3__.default.BUFFER_FULL);
  2571. }
  2572. this._isBufferFull = true;
  2573. }
  2574. else {
  2575. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.e(this.TAG, error.message);
  2576. this._emitter.emit(_mse_events_js__WEBPACK_IMPORTED_MODULE_3__.default.ERROR, { code: error.code, msg: error.message });
  2577. }
  2578. }
  2579. }
  2580. }
  2581. };
  2582. MSEController.prototype._onSourceOpen = function () {
  2583. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, 'MediaSource onSourceOpen');
  2584. this._mediaSource.removeEventListener('sourceopen', this.e.onSourceOpen);
  2585. // deferred sourcebuffer creation / initialization
  2586. if (this._pendingSourceBufferInit.length > 0) {
  2587. var pendings = this._pendingSourceBufferInit;
  2588. while (pendings.length) {
  2589. var segment = pendings.shift();
  2590. this.appendInitSegment(segment, true);
  2591. }
  2592. }
  2593. // there may be some pending media segments, append them
  2594. if (this._hasPendingSegments()) {
  2595. this._doAppendSegments();
  2596. }
  2597. this._emitter.emit(_mse_events_js__WEBPACK_IMPORTED_MODULE_3__.default.SOURCE_OPEN);
  2598. };
  2599. MSEController.prototype._onSourceEnded = function () {
  2600. // fired on endOfStream
  2601. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, 'MediaSource onSourceEnded');
  2602. };
  2603. MSEController.prototype._onSourceClose = function () {
  2604. // fired on detaching from media element
  2605. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, 'MediaSource onSourceClose');
  2606. if (this._mediaSource && this.e != null) {
  2607. this._mediaSource.removeEventListener('sourceopen', this.e.onSourceOpen);
  2608. this._mediaSource.removeEventListener('sourceended', this.e.onSourceEnded);
  2609. this._mediaSource.removeEventListener('sourceclose', this.e.onSourceClose);
  2610. }
  2611. };
  2612. MSEController.prototype._hasPendingSegments = function () {
  2613. var ps = this._pendingSegments;
  2614. return ps.video.length > 0 || ps.audio.length > 0;
  2615. };
  2616. MSEController.prototype._hasPendingRemoveRanges = function () {
  2617. var prr = this._pendingRemoveRanges;
  2618. return prr.video.length > 0 || prr.audio.length > 0;
  2619. };
  2620. MSEController.prototype._onSourceBufferUpdateEnd = function () {
  2621. if (this._requireSetMediaDuration) {
  2622. this._updateMediaSourceDuration();
  2623. }
  2624. else if (this._hasPendingRemoveRanges()) {
  2625. this._doRemoveRanges();
  2626. }
  2627. else if (this._hasPendingSegments()) {
  2628. this._doAppendSegments();
  2629. }
  2630. else if (this._hasPendingEos) {
  2631. this.endOfStream();
  2632. }
  2633. this._emitter.emit(_mse_events_js__WEBPACK_IMPORTED_MODULE_3__.default.UPDATE_END);
  2634. };
  2635. MSEController.prototype._onSourceBufferError = function (e) {
  2636. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.e(this.TAG, "SourceBuffer Error: " + e);
  2637. // this error might not always be fatal, just ignore it
  2638. };
  2639. return MSEController;
  2640. }());
  2641. /* harmony default export */ __webpack_exports__["default"] = (MSEController);
  2642. /***/ }),
  2643. /***/ "./src/core/mse-events.js":
  2644. /*!********************************!*\
  2645. !*** ./src/core/mse-events.js ***!
  2646. \********************************/
  2647. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  2648. "use strict";
  2649. __webpack_require__.r(__webpack_exports__);
  2650. /*
  2651. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  2652. *
  2653. * @author zheng qian <xqq@xqq.im>
  2654. *
  2655. * Licensed under the Apache License, Version 2.0 (the "License");
  2656. * you may not use this file except in compliance with the License.
  2657. * You may obtain a copy of the License at
  2658. *
  2659. * http://www.apache.org/licenses/LICENSE-2.0
  2660. *
  2661. * Unless required by applicable law or agreed to in writing, software
  2662. * distributed under the License is distributed on an "AS IS" BASIS,
  2663. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2664. * See the License for the specific language governing permissions and
  2665. * limitations under the License.
  2666. */
  2667. var MSEEvents = {
  2668. ERROR: 'error',
  2669. SOURCE_OPEN: 'source_open',
  2670. UPDATE_END: 'update_end',
  2671. BUFFER_FULL: 'buffer_full'
  2672. };
  2673. /* harmony default export */ __webpack_exports__["default"] = (MSEEvents);
  2674. /***/ }),
  2675. /***/ "./src/core/transmuxer.js":
  2676. /*!********************************!*\
  2677. !*** ./src/core/transmuxer.js ***!
  2678. \********************************/
  2679. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  2680. "use strict";
  2681. __webpack_require__.r(__webpack_exports__);
  2682. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! events */ "./node_modules/events/events.js");
  2683. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(events__WEBPACK_IMPORTED_MODULE_0__);
  2684. /* harmony import */ var webworkify_webpack__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! webworkify-webpack */ "./node_modules/webworkify-webpack/index.js");
  2685. /* harmony import */ var webworkify_webpack__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(webworkify_webpack__WEBPACK_IMPORTED_MODULE_1__);
  2686. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  2687. /* harmony import */ var _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/logging-control.js */ "./src/utils/logging-control.js");
  2688. /* harmony import */ var _transmuxing_controller_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./transmuxing-controller.js */ "./src/core/transmuxing-controller.js");
  2689. /* harmony import */ var _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./transmuxing-events.js */ "./src/core/transmuxing-events.js");
  2690. /* harmony import */ var _media_info_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./media-info.js */ "./src/core/media-info.js");
  2691. /*
  2692. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  2693. *
  2694. * @author zheng qian <xqq@xqq.im>
  2695. *
  2696. * Licensed under the Apache License, Version 2.0 (the "License");
  2697. * you may not use this file except in compliance with the License.
  2698. * You may obtain a copy of the License at
  2699. *
  2700. * http://www.apache.org/licenses/LICENSE-2.0
  2701. *
  2702. * Unless required by applicable law or agreed to in writing, software
  2703. * distributed under the License is distributed on an "AS IS" BASIS,
  2704. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2705. * See the License for the specific language governing permissions and
  2706. * limitations under the License.
  2707. */
  2708. var Transmuxer = /** @class */ (function () {
  2709. function Transmuxer(mediaDataSource, config) {
  2710. this.TAG = 'Transmuxer';
  2711. this._emitter = new (events__WEBPACK_IMPORTED_MODULE_0___default())();
  2712. if (config.enableWorker && typeof (Worker) !== 'undefined') {
  2713. try {
  2714. this._worker = webworkify_webpack__WEBPACK_IMPORTED_MODULE_1___default()(/*require.resolve*/(/*! ./transmuxing-worker */ "./src/core/transmuxing-worker.js"));
  2715. this._workerDestroying = false;
  2716. this._worker.addEventListener('message', this._onWorkerMessage.bind(this));
  2717. this._worker.postMessage({ cmd: 'init', param: [mediaDataSource, config] });
  2718. this.e = {
  2719. onLoggingConfigChanged: this._onLoggingConfigChanged.bind(this)
  2720. };
  2721. _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_3__.default.registerListener(this.e.onLoggingConfigChanged);
  2722. this._worker.postMessage({ cmd: 'logging_config', param: _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_3__.default.getConfig() });
  2723. }
  2724. catch (error) {
  2725. _utils_logger_js__WEBPACK_IMPORTED_MODULE_2__.default.e(this.TAG, 'Error while initialize transmuxing worker, fallback to inline transmuxing');
  2726. this._worker = null;
  2727. this._controller = new _transmuxing_controller_js__WEBPACK_IMPORTED_MODULE_4__.default(mediaDataSource, config);
  2728. }
  2729. }
  2730. else {
  2731. this._controller = new _transmuxing_controller_js__WEBPACK_IMPORTED_MODULE_4__.default(mediaDataSource, config);
  2732. }
  2733. if (this._controller) {
  2734. var ctl = this._controller;
  2735. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.IO_ERROR, this._onIOError.bind(this));
  2736. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.DEMUX_ERROR, this._onDemuxError.bind(this));
  2737. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.INIT_SEGMENT, this._onInitSegment.bind(this));
  2738. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.MEDIA_SEGMENT, this._onMediaSegment.bind(this));
  2739. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.LOADING_COMPLETE, this._onLoadingComplete.bind(this));
  2740. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.RECOVERED_EARLY_EOF, this._onRecoveredEarlyEof.bind(this));
  2741. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.MEDIA_INFO, this._onMediaInfo.bind(this));
  2742. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.METADATA_ARRIVED, this._onMetaDataArrived.bind(this));
  2743. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.SCRIPTDATA_ARRIVED, this._onScriptDataArrived.bind(this));
  2744. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.STATISTICS_INFO, this._onStatisticsInfo.bind(this));
  2745. ctl.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.RECOMMEND_SEEKPOINT, this._onRecommendSeekpoint.bind(this));
  2746. }
  2747. }
  2748. Transmuxer.prototype.destroy = function () {
  2749. if (this._worker) {
  2750. if (!this._workerDestroying) {
  2751. this._workerDestroying = true;
  2752. this._worker.postMessage({ cmd: 'destroy' });
  2753. _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_3__.default.removeListener(this.e.onLoggingConfigChanged);
  2754. this.e = null;
  2755. }
  2756. }
  2757. else {
  2758. this._controller.destroy();
  2759. this._controller = null;
  2760. }
  2761. this._emitter.removeAllListeners();
  2762. this._emitter = null;
  2763. };
  2764. Transmuxer.prototype.on = function (event, listener) {
  2765. this._emitter.addListener(event, listener);
  2766. };
  2767. Transmuxer.prototype.off = function (event, listener) {
  2768. this._emitter.removeListener(event, listener);
  2769. };
  2770. Transmuxer.prototype.hasWorker = function () {
  2771. return this._worker != null;
  2772. };
  2773. Transmuxer.prototype.open = function () {
  2774. if (this._worker) {
  2775. this._worker.postMessage({ cmd: 'start' });
  2776. }
  2777. else {
  2778. this._controller.start();
  2779. }
  2780. };
  2781. Transmuxer.prototype.close = function () {
  2782. if (this._worker) {
  2783. this._worker.postMessage({ cmd: 'stop' });
  2784. }
  2785. else {
  2786. this._controller.stop();
  2787. }
  2788. };
  2789. Transmuxer.prototype.seek = function (milliseconds) {
  2790. if (this._worker) {
  2791. this._worker.postMessage({ cmd: 'seek', param: milliseconds });
  2792. }
  2793. else {
  2794. this._controller.seek(milliseconds);
  2795. }
  2796. };
  2797. Transmuxer.prototype.pause = function () {
  2798. if (this._worker) {
  2799. this._worker.postMessage({ cmd: 'pause' });
  2800. }
  2801. else {
  2802. this._controller.pause();
  2803. }
  2804. };
  2805. Transmuxer.prototype.resume = function () {
  2806. if (this._worker) {
  2807. this._worker.postMessage({ cmd: 'resume' });
  2808. }
  2809. else {
  2810. this._controller.resume();
  2811. }
  2812. };
  2813. Transmuxer.prototype._onInitSegment = function (type, initSegment) {
  2814. var _this = this;
  2815. // do async invoke
  2816. Promise.resolve().then(function () {
  2817. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.INIT_SEGMENT, type, initSegment);
  2818. });
  2819. };
  2820. Transmuxer.prototype._onMediaSegment = function (type, mediaSegment) {
  2821. var _this = this;
  2822. Promise.resolve().then(function () {
  2823. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.MEDIA_SEGMENT, type, mediaSegment);
  2824. });
  2825. };
  2826. Transmuxer.prototype._onLoadingComplete = function () {
  2827. var _this = this;
  2828. Promise.resolve().then(function () {
  2829. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.LOADING_COMPLETE);
  2830. });
  2831. };
  2832. Transmuxer.prototype._onRecoveredEarlyEof = function () {
  2833. var _this = this;
  2834. Promise.resolve().then(function () {
  2835. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.RECOVERED_EARLY_EOF);
  2836. });
  2837. };
  2838. Transmuxer.prototype._onMediaInfo = function (mediaInfo) {
  2839. var _this = this;
  2840. Promise.resolve().then(function () {
  2841. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.MEDIA_INFO, mediaInfo);
  2842. });
  2843. };
  2844. Transmuxer.prototype._onMetaDataArrived = function (metadata) {
  2845. var _this = this;
  2846. Promise.resolve().then(function () {
  2847. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.METADATA_ARRIVED, metadata);
  2848. });
  2849. };
  2850. Transmuxer.prototype._onScriptDataArrived = function (data) {
  2851. var _this = this;
  2852. Promise.resolve().then(function () {
  2853. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.SCRIPTDATA_ARRIVED, data);
  2854. });
  2855. };
  2856. Transmuxer.prototype._onStatisticsInfo = function (statisticsInfo) {
  2857. var _this = this;
  2858. Promise.resolve().then(function () {
  2859. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.STATISTICS_INFO, statisticsInfo);
  2860. });
  2861. };
  2862. Transmuxer.prototype._onIOError = function (type, info) {
  2863. var _this = this;
  2864. Promise.resolve().then(function () {
  2865. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.IO_ERROR, type, info);
  2866. });
  2867. };
  2868. Transmuxer.prototype._onDemuxError = function (type, info) {
  2869. var _this = this;
  2870. Promise.resolve().then(function () {
  2871. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.DEMUX_ERROR, type, info);
  2872. });
  2873. };
  2874. Transmuxer.prototype._onRecommendSeekpoint = function (milliseconds) {
  2875. var _this = this;
  2876. Promise.resolve().then(function () {
  2877. _this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.RECOMMEND_SEEKPOINT, milliseconds);
  2878. });
  2879. };
  2880. Transmuxer.prototype._onLoggingConfigChanged = function (config) {
  2881. if (this._worker) {
  2882. this._worker.postMessage({ cmd: 'logging_config', param: config });
  2883. }
  2884. };
  2885. Transmuxer.prototype._onWorkerMessage = function (e) {
  2886. var message = e.data;
  2887. var data = message.data;
  2888. if (message.msg === 'destroyed' || this._workerDestroying) {
  2889. this._workerDestroying = false;
  2890. this._worker.terminate();
  2891. this._worker = null;
  2892. return;
  2893. }
  2894. switch (message.msg) {
  2895. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.INIT_SEGMENT:
  2896. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.MEDIA_SEGMENT:
  2897. this._emitter.emit(message.msg, data.type, data.data);
  2898. break;
  2899. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.LOADING_COMPLETE:
  2900. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.RECOVERED_EARLY_EOF:
  2901. this._emitter.emit(message.msg);
  2902. break;
  2903. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.MEDIA_INFO:
  2904. Object.setPrototypeOf(data, _media_info_js__WEBPACK_IMPORTED_MODULE_6__.default.prototype);
  2905. this._emitter.emit(message.msg, data);
  2906. break;
  2907. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.METADATA_ARRIVED:
  2908. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.SCRIPTDATA_ARRIVED:
  2909. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.STATISTICS_INFO:
  2910. this._emitter.emit(message.msg, data);
  2911. break;
  2912. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.IO_ERROR:
  2913. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.DEMUX_ERROR:
  2914. this._emitter.emit(message.msg, data.type, data.info);
  2915. break;
  2916. case _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.RECOMMEND_SEEKPOINT:
  2917. this._emitter.emit(message.msg, data);
  2918. break;
  2919. case 'logcat_callback':
  2920. _utils_logger_js__WEBPACK_IMPORTED_MODULE_2__.default.emitter.emit('log', data.type, data.logcat);
  2921. break;
  2922. default:
  2923. break;
  2924. }
  2925. };
  2926. return Transmuxer;
  2927. }());
  2928. /* harmony default export */ __webpack_exports__["default"] = (Transmuxer);
  2929. /***/ }),
  2930. /***/ "./src/core/transmuxing-controller.js":
  2931. /*!********************************************!*\
  2932. !*** ./src/core/transmuxing-controller.js ***!
  2933. \********************************************/
  2934. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  2935. "use strict";
  2936. __webpack_require__.r(__webpack_exports__);
  2937. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! events */ "./node_modules/events/events.js");
  2938. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(events__WEBPACK_IMPORTED_MODULE_0__);
  2939. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  2940. /* harmony import */ var _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/browser.js */ "./src/utils/browser.js");
  2941. /* harmony import */ var _media_info_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./media-info.js */ "./src/core/media-info.js");
  2942. /* harmony import */ var _demux_flv_demuxer_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../demux/flv-demuxer.js */ "./src/demux/flv-demuxer.js");
  2943. /* harmony import */ var _remux_mp4_remuxer_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../remux/mp4-remuxer.js */ "./src/remux/mp4-remuxer.js");
  2944. /* harmony import */ var _demux_demux_errors_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../demux/demux-errors.js */ "./src/demux/demux-errors.js");
  2945. /* harmony import */ var _io_io_controller_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../io/io-controller.js */ "./src/io/io-controller.js");
  2946. /* harmony import */ var _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./transmuxing-events.js */ "./src/core/transmuxing-events.js");
  2947. /*
  2948. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  2949. *
  2950. * @author zheng qian <xqq@xqq.im>
  2951. *
  2952. * Licensed under the Apache License, Version 2.0 (the "License");
  2953. * you may not use this file except in compliance with the License.
  2954. * You may obtain a copy of the License at
  2955. *
  2956. * http://www.apache.org/licenses/LICENSE-2.0
  2957. *
  2958. * Unless required by applicable law or agreed to in writing, software
  2959. * distributed under the License is distributed on an "AS IS" BASIS,
  2960. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2961. * See the License for the specific language governing permissions and
  2962. * limitations under the License.
  2963. */
  2964. // Transmuxing (IO, Demuxing, Remuxing) controller, with multipart support
  2965. var TransmuxingController = /** @class */ (function () {
  2966. function TransmuxingController(mediaDataSource, config) {
  2967. this.TAG = 'TransmuxingController';
  2968. this._emitter = new (events__WEBPACK_IMPORTED_MODULE_0___default())();
  2969. this._config = config;
  2970. // treat single part media as multipart media, which has only one segment
  2971. if (!mediaDataSource.segments) {
  2972. mediaDataSource.segments = [{
  2973. duration: mediaDataSource.duration,
  2974. filesize: mediaDataSource.filesize,
  2975. url: mediaDataSource.url
  2976. }];
  2977. }
  2978. // fill in default IO params if not exists
  2979. if (typeof mediaDataSource.cors !== 'boolean') {
  2980. mediaDataSource.cors = true;
  2981. }
  2982. if (typeof mediaDataSource.withCredentials !== 'boolean') {
  2983. mediaDataSource.withCredentials = false;
  2984. }
  2985. this._mediaDataSource = mediaDataSource;
  2986. this._currentSegmentIndex = 0;
  2987. var totalDuration = 0;
  2988. this._mediaDataSource.segments.forEach(function (segment) {
  2989. // timestampBase for each segment, and calculate total duration
  2990. segment.timestampBase = totalDuration;
  2991. totalDuration += segment.duration;
  2992. // params needed by IOController
  2993. segment.cors = mediaDataSource.cors;
  2994. segment.withCredentials = mediaDataSource.withCredentials;
  2995. // referrer policy control, if exist
  2996. if (config.referrerPolicy) {
  2997. segment.referrerPolicy = config.referrerPolicy;
  2998. }
  2999. });
  3000. if (!isNaN(totalDuration) && this._mediaDataSource.duration !== totalDuration) {
  3001. this._mediaDataSource.duration = totalDuration;
  3002. }
  3003. this._mediaInfo = null;
  3004. this._demuxer = null;
  3005. this._remuxer = null;
  3006. this._ioctl = null;
  3007. this._pendingSeekTime = null;
  3008. this._pendingResolveSeekPoint = null;
  3009. this._statisticsReporter = null;
  3010. }
  3011. TransmuxingController.prototype.destroy = function () {
  3012. this._mediaInfo = null;
  3013. this._mediaDataSource = null;
  3014. if (this._statisticsReporter) {
  3015. this._disableStatisticsReporter();
  3016. }
  3017. if (this._ioctl) {
  3018. this._ioctl.destroy();
  3019. this._ioctl = null;
  3020. }
  3021. if (this._demuxer) {
  3022. this._demuxer.destroy();
  3023. this._demuxer = null;
  3024. }
  3025. if (this._remuxer) {
  3026. this._remuxer.destroy();
  3027. this._remuxer = null;
  3028. }
  3029. this._emitter.removeAllListeners();
  3030. this._emitter = null;
  3031. };
  3032. TransmuxingController.prototype.on = function (event, listener) {
  3033. this._emitter.addListener(event, listener);
  3034. };
  3035. TransmuxingController.prototype.off = function (event, listener) {
  3036. this._emitter.removeListener(event, listener);
  3037. };
  3038. TransmuxingController.prototype.start = function () {
  3039. this._loadSegment(0);
  3040. this._enableStatisticsReporter();
  3041. };
  3042. TransmuxingController.prototype._loadSegment = function (segmentIndex, optionalFrom) {
  3043. this._currentSegmentIndex = segmentIndex;
  3044. var dataSource = this._mediaDataSource.segments[segmentIndex];
  3045. var ioctl = this._ioctl = new _io_io_controller_js__WEBPACK_IMPORTED_MODULE_7__.default(dataSource, this._config, segmentIndex);
  3046. ioctl.onError = this._onIOException.bind(this);
  3047. ioctl.onSeeked = this._onIOSeeked.bind(this);
  3048. ioctl.onComplete = this._onIOComplete.bind(this);
  3049. ioctl.onRedirect = this._onIORedirect.bind(this);
  3050. ioctl.onRecoveredEarlyEof = this._onIORecoveredEarlyEof.bind(this);
  3051. if (optionalFrom) {
  3052. this._demuxer.bindDataSource(this._ioctl);
  3053. }
  3054. else {
  3055. ioctl.onDataArrival = this._onInitChunkArrival.bind(this);
  3056. }
  3057. ioctl.open(optionalFrom);
  3058. };
  3059. TransmuxingController.prototype.stop = function () {
  3060. this._internalAbort();
  3061. this._disableStatisticsReporter();
  3062. };
  3063. TransmuxingController.prototype._internalAbort = function () {
  3064. if (this._ioctl) {
  3065. this._ioctl.destroy();
  3066. this._ioctl = null;
  3067. }
  3068. };
  3069. TransmuxingController.prototype.pause = function () {
  3070. if (this._ioctl && this._ioctl.isWorking()) {
  3071. this._ioctl.pause();
  3072. this._disableStatisticsReporter();
  3073. }
  3074. };
  3075. TransmuxingController.prototype.resume = function () {
  3076. if (this._ioctl && this._ioctl.isPaused()) {
  3077. this._ioctl.resume();
  3078. this._enableStatisticsReporter();
  3079. }
  3080. };
  3081. TransmuxingController.prototype.seek = function (milliseconds) {
  3082. if (this._mediaInfo == null || !this._mediaInfo.isSeekable()) {
  3083. return;
  3084. }
  3085. var targetSegmentIndex = this._searchSegmentIndexContains(milliseconds);
  3086. if (targetSegmentIndex === this._currentSegmentIndex) {
  3087. // intra-segment seeking
  3088. var segmentInfo = this._mediaInfo.segments[targetSegmentIndex];
  3089. if (segmentInfo == undefined) {
  3090. // current segment loading started, but mediainfo hasn't received yet
  3091. // wait for the metadata loaded, then seek to expected position
  3092. this._pendingSeekTime = milliseconds;
  3093. }
  3094. else {
  3095. var keyframe = segmentInfo.getNearestKeyframe(milliseconds);
  3096. this._remuxer.seek(keyframe.milliseconds);
  3097. this._ioctl.seek(keyframe.fileposition);
  3098. // Will be resolved in _onRemuxerMediaSegmentArrival()
  3099. this._pendingResolveSeekPoint = keyframe.milliseconds;
  3100. }
  3101. }
  3102. else {
  3103. // cross-segment seeking
  3104. var targetSegmentInfo = this._mediaInfo.segments[targetSegmentIndex];
  3105. if (targetSegmentInfo == undefined) {
  3106. // target segment hasn't been loaded. We need metadata then seek to expected time
  3107. this._pendingSeekTime = milliseconds;
  3108. this._internalAbort();
  3109. this._remuxer.seek();
  3110. this._remuxer.insertDiscontinuity();
  3111. this._loadSegment(targetSegmentIndex);
  3112. // Here we wait for the metadata loaded, then seek to expected position
  3113. }
  3114. else {
  3115. // We have target segment's metadata, direct seek to target position
  3116. var keyframe = targetSegmentInfo.getNearestKeyframe(milliseconds);
  3117. this._internalAbort();
  3118. this._remuxer.seek(milliseconds);
  3119. this._remuxer.insertDiscontinuity();
  3120. this._demuxer.resetMediaInfo();
  3121. this._demuxer.timestampBase = this._mediaDataSource.segments[targetSegmentIndex].timestampBase;
  3122. this._loadSegment(targetSegmentIndex, keyframe.fileposition);
  3123. this._pendingResolveSeekPoint = keyframe.milliseconds;
  3124. this._reportSegmentMediaInfo(targetSegmentIndex);
  3125. }
  3126. }
  3127. this._enableStatisticsReporter();
  3128. };
  3129. TransmuxingController.prototype._searchSegmentIndexContains = function (milliseconds) {
  3130. var segments = this._mediaDataSource.segments;
  3131. var idx = segments.length - 1;
  3132. for (var i = 0; i < segments.length; i++) {
  3133. if (milliseconds < segments[i].timestampBase) {
  3134. idx = i - 1;
  3135. break;
  3136. }
  3137. }
  3138. return idx;
  3139. };
  3140. TransmuxingController.prototype._onInitChunkArrival = function (data, byteStart) {
  3141. var _this = this;
  3142. var probeData = null;
  3143. var consumed = 0;
  3144. if (byteStart > 0) {
  3145. // IOController seeked immediately after opened, byteStart > 0 callback may received
  3146. this._demuxer.bindDataSource(this._ioctl);
  3147. this._demuxer.timestampBase = this._mediaDataSource.segments[this._currentSegmentIndex].timestampBase;
  3148. consumed = this._demuxer.parseChunks(data, byteStart);
  3149. }
  3150. else if ((probeData = _demux_flv_demuxer_js__WEBPACK_IMPORTED_MODULE_4__.default.probe(data)).match) {
  3151. // Always create new FLVDemuxer
  3152. this._demuxer = new _demux_flv_demuxer_js__WEBPACK_IMPORTED_MODULE_4__.default(probeData, this._config);
  3153. if (!this._remuxer) {
  3154. this._remuxer = new _remux_mp4_remuxer_js__WEBPACK_IMPORTED_MODULE_5__.default(this._config);
  3155. }
  3156. var mds = this._mediaDataSource;
  3157. if (mds.duration != undefined && !isNaN(mds.duration)) {
  3158. this._demuxer.overridedDuration = mds.duration;
  3159. }
  3160. if (typeof mds.hasAudio === 'boolean') {
  3161. this._demuxer.overridedHasAudio = mds.hasAudio;
  3162. }
  3163. if (typeof mds.hasVideo === 'boolean') {
  3164. this._demuxer.overridedHasVideo = mds.hasVideo;
  3165. }
  3166. this._demuxer.timestampBase = mds.segments[this._currentSegmentIndex].timestampBase;
  3167. this._demuxer.onError = this._onDemuxException.bind(this);
  3168. this._demuxer.onMediaInfo = this._onMediaInfo.bind(this);
  3169. this._demuxer.onMetaDataArrived = this._onMetaDataArrived.bind(this);
  3170. this._demuxer.onScriptDataArrived = this._onScriptDataArrived.bind(this);
  3171. this._remuxer.bindDataSource(this._demuxer
  3172. .bindDataSource(this._ioctl));
  3173. this._remuxer.onInitSegment = this._onRemuxerInitSegmentArrival.bind(this);
  3174. this._remuxer.onMediaSegment = this._onRemuxerMediaSegmentArrival.bind(this);
  3175. consumed = this._demuxer.parseChunks(data, byteStart);
  3176. }
  3177. else {
  3178. probeData = null;
  3179. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.e(this.TAG, 'Non-FLV, Unsupported media type!');
  3180. Promise.resolve().then(function () {
  3181. _this._internalAbort();
  3182. });
  3183. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.DEMUX_ERROR, _demux_demux_errors_js__WEBPACK_IMPORTED_MODULE_6__.default.FORMAT_UNSUPPORTED, 'Non-FLV, Unsupported media type');
  3184. consumed = 0;
  3185. }
  3186. return consumed;
  3187. };
  3188. TransmuxingController.prototype._onMediaInfo = function (mediaInfo) {
  3189. var _this = this;
  3190. if (this._mediaInfo == null) {
  3191. // Store first segment's mediainfo as global mediaInfo
  3192. this._mediaInfo = Object.assign({}, mediaInfo);
  3193. this._mediaInfo.keyframesIndex = null;
  3194. this._mediaInfo.segments = [];
  3195. this._mediaInfo.segmentCount = this._mediaDataSource.segments.length;
  3196. Object.setPrototypeOf(this._mediaInfo, _media_info_js__WEBPACK_IMPORTED_MODULE_3__.default.prototype);
  3197. }
  3198. var segmentInfo = Object.assign({}, mediaInfo);
  3199. Object.setPrototypeOf(segmentInfo, _media_info_js__WEBPACK_IMPORTED_MODULE_3__.default.prototype);
  3200. this._mediaInfo.segments[this._currentSegmentIndex] = segmentInfo;
  3201. // notify mediaInfo update
  3202. this._reportSegmentMediaInfo(this._currentSegmentIndex);
  3203. if (this._pendingSeekTime != null) {
  3204. Promise.resolve().then(function () {
  3205. var target = _this._pendingSeekTime;
  3206. _this._pendingSeekTime = null;
  3207. _this.seek(target);
  3208. });
  3209. }
  3210. };
  3211. TransmuxingController.prototype._onMetaDataArrived = function (metadata) {
  3212. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.METADATA_ARRIVED, metadata);
  3213. };
  3214. TransmuxingController.prototype._onScriptDataArrived = function (data) {
  3215. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.SCRIPTDATA_ARRIVED, data);
  3216. };
  3217. TransmuxingController.prototype._onIOSeeked = function () {
  3218. this._remuxer.insertDiscontinuity();
  3219. };
  3220. TransmuxingController.prototype._onIOComplete = function (extraData) {
  3221. var segmentIndex = extraData;
  3222. var nextSegmentIndex = segmentIndex + 1;
  3223. if (nextSegmentIndex < this._mediaDataSource.segments.length) {
  3224. this._internalAbort();
  3225. this._remuxer.flushStashedSamples();
  3226. this._loadSegment(nextSegmentIndex);
  3227. }
  3228. else {
  3229. this._remuxer.flushStashedSamples();
  3230. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.LOADING_COMPLETE);
  3231. this._disableStatisticsReporter();
  3232. }
  3233. };
  3234. TransmuxingController.prototype._onIORedirect = function (redirectedURL) {
  3235. var segmentIndex = this._ioctl.extraData;
  3236. this._mediaDataSource.segments[segmentIndex].redirectedURL = redirectedURL;
  3237. };
  3238. TransmuxingController.prototype._onIORecoveredEarlyEof = function () {
  3239. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.RECOVERED_EARLY_EOF);
  3240. };
  3241. TransmuxingController.prototype._onIOException = function (type, info) {
  3242. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.e(this.TAG, "IOException: type = " + type + ", code = " + info.code + ", msg = " + info.msg);
  3243. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.IO_ERROR, type, info);
  3244. this._disableStatisticsReporter();
  3245. };
  3246. TransmuxingController.prototype._onDemuxException = function (type, info) {
  3247. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.e(this.TAG, "DemuxException: type = " + type + ", info = " + info);
  3248. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.DEMUX_ERROR, type, info);
  3249. };
  3250. TransmuxingController.prototype._onRemuxerInitSegmentArrival = function (type, initSegment) {
  3251. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.INIT_SEGMENT, type, initSegment);
  3252. };
  3253. TransmuxingController.prototype._onRemuxerMediaSegmentArrival = function (type, mediaSegment) {
  3254. if (this._pendingSeekTime != null) {
  3255. // Media segments after new-segment cross-seeking should be dropped.
  3256. return;
  3257. }
  3258. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.MEDIA_SEGMENT, type, mediaSegment);
  3259. // Resolve pending seekPoint
  3260. if (this._pendingResolveSeekPoint != null && type === 'video') {
  3261. var syncPoints = mediaSegment.info.syncPoints;
  3262. var seekpoint = this._pendingResolveSeekPoint;
  3263. this._pendingResolveSeekPoint = null;
  3264. // Safari: Pass PTS for recommend_seekpoint
  3265. if (_utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.safari && syncPoints.length > 0 && syncPoints[0].originalDts === seekpoint) {
  3266. seekpoint = syncPoints[0].pts;
  3267. }
  3268. // else: use original DTS (keyframe.milliseconds)
  3269. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.RECOMMEND_SEEKPOINT, seekpoint);
  3270. }
  3271. };
  3272. TransmuxingController.prototype._enableStatisticsReporter = function () {
  3273. if (this._statisticsReporter == null) {
  3274. this._statisticsReporter = self.setInterval(this._reportStatisticsInfo.bind(this), this._config.statisticsInfoReportInterval);
  3275. }
  3276. };
  3277. TransmuxingController.prototype._disableStatisticsReporter = function () {
  3278. if (this._statisticsReporter) {
  3279. self.clearInterval(this._statisticsReporter);
  3280. this._statisticsReporter = null;
  3281. }
  3282. };
  3283. TransmuxingController.prototype._reportSegmentMediaInfo = function (segmentIndex) {
  3284. var segmentInfo = this._mediaInfo.segments[segmentIndex];
  3285. var exportInfo = Object.assign({}, segmentInfo);
  3286. exportInfo.duration = this._mediaInfo.duration;
  3287. exportInfo.segmentCount = this._mediaInfo.segmentCount;
  3288. delete exportInfo.segments;
  3289. delete exportInfo.keyframesIndex;
  3290. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.MEDIA_INFO, exportInfo);
  3291. };
  3292. TransmuxingController.prototype._reportStatisticsInfo = function () {
  3293. var info = {};
  3294. info.url = this._ioctl.currentURL;
  3295. info.hasRedirect = this._ioctl.hasRedirect;
  3296. if (info.hasRedirect) {
  3297. info.redirectedURL = this._ioctl.currentRedirectedURL;
  3298. }
  3299. info.speed = this._ioctl.currentSpeed;
  3300. info.loaderType = this._ioctl.loaderType;
  3301. info.currentSegmentIndex = this._currentSegmentIndex;
  3302. info.totalSegmentCount = this._mediaDataSource.segments.length;
  3303. this._emitter.emit(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_8__.default.STATISTICS_INFO, info);
  3304. };
  3305. return TransmuxingController;
  3306. }());
  3307. /* harmony default export */ __webpack_exports__["default"] = (TransmuxingController);
  3308. /***/ }),
  3309. /***/ "./src/core/transmuxing-events.js":
  3310. /*!****************************************!*\
  3311. !*** ./src/core/transmuxing-events.js ***!
  3312. \****************************************/
  3313. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  3314. "use strict";
  3315. __webpack_require__.r(__webpack_exports__);
  3316. /*
  3317. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  3318. *
  3319. * @author zheng qian <xqq@xqq.im>
  3320. *
  3321. * Licensed under the Apache License, Version 2.0 (the "License");
  3322. * you may not use this file except in compliance with the License.
  3323. * You may obtain a copy of the License at
  3324. *
  3325. * http://www.apache.org/licenses/LICENSE-2.0
  3326. *
  3327. * Unless required by applicable law or agreed to in writing, software
  3328. * distributed under the License is distributed on an "AS IS" BASIS,
  3329. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3330. * See the License for the specific language governing permissions and
  3331. * limitations under the License.
  3332. */
  3333. var TransmuxingEvents = {
  3334. IO_ERROR: 'io_error',
  3335. DEMUX_ERROR: 'demux_error',
  3336. INIT_SEGMENT: 'init_segment',
  3337. MEDIA_SEGMENT: 'media_segment',
  3338. LOADING_COMPLETE: 'loading_complete',
  3339. RECOVERED_EARLY_EOF: 'recovered_early_eof',
  3340. MEDIA_INFO: 'media_info',
  3341. METADATA_ARRIVED: 'metadata_arrived',
  3342. SCRIPTDATA_ARRIVED: 'scriptdata_arrived',
  3343. STATISTICS_INFO: 'statistics_info',
  3344. RECOMMEND_SEEKPOINT: 'recommend_seekpoint'
  3345. };
  3346. /* harmony default export */ __webpack_exports__["default"] = (TransmuxingEvents);
  3347. /***/ }),
  3348. /***/ "./src/core/transmuxing-worker.js":
  3349. /*!****************************************!*\
  3350. !*** ./src/core/transmuxing-worker.js ***!
  3351. \****************************************/
  3352. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  3353. "use strict";
  3354. __webpack_require__.r(__webpack_exports__);
  3355. /* harmony import */ var _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/logging-control.js */ "./src/utils/logging-control.js");
  3356. /* harmony import */ var _utils_polyfill_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/polyfill.js */ "./src/utils/polyfill.js");
  3357. /* harmony import */ var _transmuxing_controller_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./transmuxing-controller.js */ "./src/core/transmuxing-controller.js");
  3358. /* harmony import */ var _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./transmuxing-events.js */ "./src/core/transmuxing-events.js");
  3359. /*
  3360. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  3361. *
  3362. * @author zheng qian <xqq@xqq.im>
  3363. *
  3364. * Licensed under the Apache License, Version 2.0 (the "License");
  3365. * you may not use this file except in compliance with the License.
  3366. * You may obtain a copy of the License at
  3367. *
  3368. * http://www.apache.org/licenses/LICENSE-2.0
  3369. *
  3370. * Unless required by applicable law or agreed to in writing, software
  3371. * distributed under the License is distributed on an "AS IS" BASIS,
  3372. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3373. * See the License for the specific language governing permissions and
  3374. * limitations under the License.
  3375. */
  3376. /* post message to worker:
  3377. data: {
  3378. cmd: string
  3379. param: any
  3380. }
  3381. receive message from worker:
  3382. data: {
  3383. msg: string,
  3384. data: any
  3385. }
  3386. */
  3387. var TransmuxingWorker = function (self) {
  3388. var TAG = 'TransmuxingWorker';
  3389. var controller = null;
  3390. var logcatListener = onLogcatCallback.bind(this);
  3391. _utils_polyfill_js__WEBPACK_IMPORTED_MODULE_1__.default.install();
  3392. self.addEventListener('message', function (e) {
  3393. switch (e.data.cmd) {
  3394. case 'init':
  3395. controller = new _transmuxing_controller_js__WEBPACK_IMPORTED_MODULE_2__.default(e.data.param[0], e.data.param[1]);
  3396. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.IO_ERROR, onIOError.bind(this));
  3397. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.DEMUX_ERROR, onDemuxError.bind(this));
  3398. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.INIT_SEGMENT, onInitSegment.bind(this));
  3399. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.MEDIA_SEGMENT, onMediaSegment.bind(this));
  3400. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.LOADING_COMPLETE, onLoadingComplete.bind(this));
  3401. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.RECOVERED_EARLY_EOF, onRecoveredEarlyEof.bind(this));
  3402. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.MEDIA_INFO, onMediaInfo.bind(this));
  3403. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.METADATA_ARRIVED, onMetaDataArrived.bind(this));
  3404. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.SCRIPTDATA_ARRIVED, onScriptDataArrived.bind(this));
  3405. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.STATISTICS_INFO, onStatisticsInfo.bind(this));
  3406. controller.on(_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.RECOMMEND_SEEKPOINT, onRecommendSeekpoint.bind(this));
  3407. break;
  3408. case 'destroy':
  3409. if (controller) {
  3410. controller.destroy();
  3411. controller = null;
  3412. }
  3413. self.postMessage({ msg: 'destroyed' });
  3414. break;
  3415. case 'start':
  3416. controller.start();
  3417. break;
  3418. case 'stop':
  3419. controller.stop();
  3420. break;
  3421. case 'seek':
  3422. controller.seek(e.data.param);
  3423. break;
  3424. case 'pause':
  3425. controller.pause();
  3426. break;
  3427. case 'resume':
  3428. controller.resume();
  3429. break;
  3430. case 'logging_config': {
  3431. var config = e.data.param;
  3432. _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_0__.default.applyConfig(config);
  3433. if (config.enableCallback === true) {
  3434. _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_0__.default.addLogListener(logcatListener);
  3435. }
  3436. else {
  3437. _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_0__.default.removeLogListener(logcatListener);
  3438. }
  3439. break;
  3440. }
  3441. }
  3442. });
  3443. function onInitSegment(type, initSegment) {
  3444. var obj = {
  3445. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.INIT_SEGMENT,
  3446. data: {
  3447. type: type,
  3448. data: initSegment
  3449. }
  3450. };
  3451. self.postMessage(obj, [initSegment.data]); // data: ArrayBuffer
  3452. }
  3453. function onMediaSegment(type, mediaSegment) {
  3454. var obj = {
  3455. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.MEDIA_SEGMENT,
  3456. data: {
  3457. type: type,
  3458. data: mediaSegment
  3459. }
  3460. };
  3461. self.postMessage(obj, [mediaSegment.data]); // data: ArrayBuffer
  3462. }
  3463. function onLoadingComplete() {
  3464. var obj = {
  3465. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.LOADING_COMPLETE
  3466. };
  3467. self.postMessage(obj);
  3468. }
  3469. function onRecoveredEarlyEof() {
  3470. var obj = {
  3471. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.RECOVERED_EARLY_EOF
  3472. };
  3473. self.postMessage(obj);
  3474. }
  3475. function onMediaInfo(mediaInfo) {
  3476. var obj = {
  3477. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.MEDIA_INFO,
  3478. data: mediaInfo
  3479. };
  3480. self.postMessage(obj);
  3481. }
  3482. function onMetaDataArrived(metadata) {
  3483. var obj = {
  3484. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.METADATA_ARRIVED,
  3485. data: metadata
  3486. };
  3487. self.postMessage(obj);
  3488. }
  3489. function onScriptDataArrived(data) {
  3490. var obj = {
  3491. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.SCRIPTDATA_ARRIVED,
  3492. data: data
  3493. };
  3494. self.postMessage(obj);
  3495. }
  3496. function onStatisticsInfo(statInfo) {
  3497. var obj = {
  3498. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.STATISTICS_INFO,
  3499. data: statInfo
  3500. };
  3501. self.postMessage(obj);
  3502. }
  3503. function onIOError(type, info) {
  3504. self.postMessage({
  3505. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.IO_ERROR,
  3506. data: {
  3507. type: type,
  3508. info: info
  3509. }
  3510. });
  3511. }
  3512. function onDemuxError(type, info) {
  3513. self.postMessage({
  3514. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.DEMUX_ERROR,
  3515. data: {
  3516. type: type,
  3517. info: info
  3518. }
  3519. });
  3520. }
  3521. function onRecommendSeekpoint(milliseconds) {
  3522. self.postMessage({
  3523. msg: _transmuxing_events_js__WEBPACK_IMPORTED_MODULE_3__.default.RECOMMEND_SEEKPOINT,
  3524. data: milliseconds
  3525. });
  3526. }
  3527. function onLogcatCallback(type, str) {
  3528. self.postMessage({
  3529. msg: 'logcat_callback',
  3530. data: {
  3531. type: type,
  3532. logcat: str
  3533. }
  3534. });
  3535. }
  3536. };
  3537. /* harmony default export */ __webpack_exports__["default"] = (TransmuxingWorker);
  3538. /***/ }),
  3539. /***/ "./src/demux/amf-parser.js":
  3540. /*!*********************************!*\
  3541. !*** ./src/demux/amf-parser.js ***!
  3542. \*********************************/
  3543. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  3544. "use strict";
  3545. __webpack_require__.r(__webpack_exports__);
  3546. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  3547. /* harmony import */ var _utils_utf8_conv_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/utf8-conv.js */ "./src/utils/utf8-conv.js");
  3548. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  3549. /*
  3550. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  3551. *
  3552. * @author zheng qian <xqq@xqq.im>
  3553. *
  3554. * Licensed under the Apache License, Version 2.0 (the "License");
  3555. * you may not use this file except in compliance with the License.
  3556. * You may obtain a copy of the License at
  3557. *
  3558. * http://www.apache.org/licenses/LICENSE-2.0
  3559. *
  3560. * Unless required by applicable law or agreed to in writing, software
  3561. * distributed under the License is distributed on an "AS IS" BASIS,
  3562. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3563. * See the License for the specific language governing permissions and
  3564. * limitations under the License.
  3565. */
  3566. var le = (function () {
  3567. var buf = new ArrayBuffer(2);
  3568. (new DataView(buf)).setInt16(0, 256, true); // little-endian write
  3569. return (new Int16Array(buf))[0] === 256; // platform-spec read, if equal then LE
  3570. })();
  3571. var AMF = /** @class */ (function () {
  3572. function AMF() {
  3573. }
  3574. AMF.parseScriptData = function (arrayBuffer, dataOffset, dataSize) {
  3575. var data = {};
  3576. try {
  3577. var name_1 = AMF.parseValue(arrayBuffer, dataOffset, dataSize);
  3578. var value = AMF.parseValue(arrayBuffer, dataOffset + name_1.size, dataSize - name_1.size);
  3579. data[name_1.data] = value.data;
  3580. }
  3581. catch (e) {
  3582. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.e('AMF', e.toString());
  3583. }
  3584. return data;
  3585. };
  3586. AMF.parseObject = function (arrayBuffer, dataOffset, dataSize) {
  3587. if (dataSize < 3) {
  3588. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.IllegalStateException('Data not enough when parse ScriptDataObject');
  3589. }
  3590. var name = AMF.parseString(arrayBuffer, dataOffset, dataSize);
  3591. var value = AMF.parseValue(arrayBuffer, dataOffset + name.size, dataSize - name.size);
  3592. var isObjectEnd = value.objectEnd;
  3593. return {
  3594. data: {
  3595. name: name.data,
  3596. value: value.data
  3597. },
  3598. size: name.size + value.size,
  3599. objectEnd: isObjectEnd
  3600. };
  3601. };
  3602. AMF.parseVariable = function (arrayBuffer, dataOffset, dataSize) {
  3603. return AMF.parseObject(arrayBuffer, dataOffset, dataSize);
  3604. };
  3605. AMF.parseString = function (arrayBuffer, dataOffset, dataSize) {
  3606. if (dataSize < 2) {
  3607. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.IllegalStateException('Data not enough when parse String');
  3608. }
  3609. var v = new DataView(arrayBuffer, dataOffset, dataSize);
  3610. var length = v.getUint16(0, !le);
  3611. var str;
  3612. if (length > 0) {
  3613. str = (0,_utils_utf8_conv_js__WEBPACK_IMPORTED_MODULE_1__.default)(new Uint8Array(arrayBuffer, dataOffset + 2, length));
  3614. }
  3615. else {
  3616. str = '';
  3617. }
  3618. return {
  3619. data: str,
  3620. size: 2 + length
  3621. };
  3622. };
  3623. AMF.parseLongString = function (arrayBuffer, dataOffset, dataSize) {
  3624. if (dataSize < 4) {
  3625. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.IllegalStateException('Data not enough when parse LongString');
  3626. }
  3627. var v = new DataView(arrayBuffer, dataOffset, dataSize);
  3628. var length = v.getUint32(0, !le);
  3629. var str;
  3630. if (length > 0) {
  3631. str = (0,_utils_utf8_conv_js__WEBPACK_IMPORTED_MODULE_1__.default)(new Uint8Array(arrayBuffer, dataOffset + 4, length));
  3632. }
  3633. else {
  3634. str = '';
  3635. }
  3636. return {
  3637. data: str,
  3638. size: 4 + length
  3639. };
  3640. };
  3641. AMF.parseDate = function (arrayBuffer, dataOffset, dataSize) {
  3642. if (dataSize < 10) {
  3643. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.IllegalStateException('Data size invalid when parse Date');
  3644. }
  3645. var v = new DataView(arrayBuffer, dataOffset, dataSize);
  3646. var timestamp = v.getFloat64(0, !le);
  3647. var localTimeOffset = v.getInt16(8, !le);
  3648. timestamp += localTimeOffset * 60 * 1000; // get UTC time
  3649. return {
  3650. data: new Date(timestamp),
  3651. size: 8 + 2
  3652. };
  3653. };
  3654. AMF.parseValue = function (arrayBuffer, dataOffset, dataSize) {
  3655. if (dataSize < 1) {
  3656. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.IllegalStateException('Data not enough when parse Value');
  3657. }
  3658. var v = new DataView(arrayBuffer, dataOffset, dataSize);
  3659. var offset = 1;
  3660. var type = v.getUint8(0);
  3661. var value;
  3662. var objectEnd = false;
  3663. try {
  3664. switch (type) {
  3665. case 0: // Number(Double) type
  3666. value = v.getFloat64(1, !le);
  3667. offset += 8;
  3668. break;
  3669. case 1: { // Boolean type
  3670. var b = v.getUint8(1);
  3671. value = b ? true : false;
  3672. offset += 1;
  3673. break;
  3674. }
  3675. case 2: { // String type
  3676. var amfstr = AMF.parseString(arrayBuffer, dataOffset + 1, dataSize - 1);
  3677. value = amfstr.data;
  3678. offset += amfstr.size;
  3679. break;
  3680. }
  3681. case 3: { // Object(s) type
  3682. value = {};
  3683. var terminal = 0; // workaround for malformed Objects which has missing ScriptDataObjectEnd
  3684. if ((v.getUint32(dataSize - 4, !le) & 0x00FFFFFF) === 9) {
  3685. terminal = 3;
  3686. }
  3687. while (offset < dataSize - 4) { // 4 === type(UI8) + ScriptDataObjectEnd(UI24)
  3688. var amfobj = AMF.parseObject(arrayBuffer, dataOffset + offset, dataSize - offset - terminal);
  3689. if (amfobj.objectEnd)
  3690. break;
  3691. value[amfobj.data.name] = amfobj.data.value;
  3692. offset += amfobj.size;
  3693. }
  3694. if (offset <= dataSize - 3) {
  3695. var marker = v.getUint32(offset - 1, !le) & 0x00FFFFFF;
  3696. if (marker === 9) {
  3697. offset += 3;
  3698. }
  3699. }
  3700. break;
  3701. }
  3702. case 8: { // ECMA array type (Mixed array)
  3703. value = {};
  3704. offset += 4; // ECMAArrayLength(UI32)
  3705. var terminal = 0; // workaround for malformed MixedArrays which has missing ScriptDataObjectEnd
  3706. if ((v.getUint32(dataSize - 4, !le) & 0x00FFFFFF) === 9) {
  3707. terminal = 3;
  3708. }
  3709. while (offset < dataSize - 8) { // 8 === type(UI8) + ECMAArrayLength(UI32) + ScriptDataVariableEnd(UI24)
  3710. var amfvar = AMF.parseVariable(arrayBuffer, dataOffset + offset, dataSize - offset - terminal);
  3711. if (amfvar.objectEnd)
  3712. break;
  3713. value[amfvar.data.name] = amfvar.data.value;
  3714. offset += amfvar.size;
  3715. }
  3716. if (offset <= dataSize - 3) {
  3717. var marker = v.getUint32(offset - 1, !le) & 0x00FFFFFF;
  3718. if (marker === 9) {
  3719. offset += 3;
  3720. }
  3721. }
  3722. break;
  3723. }
  3724. case 9: // ScriptDataObjectEnd
  3725. value = undefined;
  3726. offset = 1;
  3727. objectEnd = true;
  3728. break;
  3729. case 10: { // Strict array type
  3730. // ScriptDataValue[n]. NOTE: according to video_file_format_spec_v10_1.pdf
  3731. value = [];
  3732. var strictArrayLength = v.getUint32(1, !le);
  3733. offset += 4;
  3734. for (var i = 0; i < strictArrayLength; i++) {
  3735. var val = AMF.parseValue(arrayBuffer, dataOffset + offset, dataSize - offset);
  3736. value.push(val.data);
  3737. offset += val.size;
  3738. }
  3739. break;
  3740. }
  3741. case 11: { // Date type
  3742. var date = AMF.parseDate(arrayBuffer, dataOffset + 1, dataSize - 1);
  3743. value = date.data;
  3744. offset += date.size;
  3745. break;
  3746. }
  3747. case 12: { // Long string type
  3748. var amfLongStr = AMF.parseString(arrayBuffer, dataOffset + 1, dataSize - 1);
  3749. value = amfLongStr.data;
  3750. offset += amfLongStr.size;
  3751. break;
  3752. }
  3753. default:
  3754. // ignore and skip
  3755. offset = dataSize;
  3756. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w('AMF', 'Unsupported AMF value type ' + type);
  3757. }
  3758. }
  3759. catch (e) {
  3760. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.e('AMF', e.toString());
  3761. }
  3762. return {
  3763. data: value,
  3764. size: offset,
  3765. objectEnd: objectEnd
  3766. };
  3767. };
  3768. return AMF;
  3769. }());
  3770. /* harmony default export */ __webpack_exports__["default"] = (AMF);
  3771. /***/ }),
  3772. /***/ "./src/demux/demux-errors.js":
  3773. /*!***********************************!*\
  3774. !*** ./src/demux/demux-errors.js ***!
  3775. \***********************************/
  3776. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  3777. "use strict";
  3778. __webpack_require__.r(__webpack_exports__);
  3779. /*
  3780. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  3781. *
  3782. * @author zheng qian <xqq@xqq.im>
  3783. *
  3784. * Licensed under the Apache License, Version 2.0 (the "License");
  3785. * you may not use this file except in compliance with the License.
  3786. * You may obtain a copy of the License at
  3787. *
  3788. * http://www.apache.org/licenses/LICENSE-2.0
  3789. *
  3790. * Unless required by applicable law or agreed to in writing, software
  3791. * distributed under the License is distributed on an "AS IS" BASIS,
  3792. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3793. * See the License for the specific language governing permissions and
  3794. * limitations under the License.
  3795. */
  3796. var DemuxErrors = {
  3797. OK: 'OK',
  3798. FORMAT_ERROR: 'FormatError',
  3799. FORMAT_UNSUPPORTED: 'FormatUnsupported',
  3800. CODEC_UNSUPPORTED: 'CodecUnsupported'
  3801. };
  3802. /* harmony default export */ __webpack_exports__["default"] = (DemuxErrors);
  3803. /***/ }),
  3804. /***/ "./src/demux/exp-golomb.js":
  3805. /*!*********************************!*\
  3806. !*** ./src/demux/exp-golomb.js ***!
  3807. \*********************************/
  3808. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  3809. "use strict";
  3810. __webpack_require__.r(__webpack_exports__);
  3811. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  3812. /*
  3813. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  3814. *
  3815. * @author zheng qian <xqq@xqq.im>
  3816. *
  3817. * Licensed under the Apache License, Version 2.0 (the "License");
  3818. * you may not use this file except in compliance with the License.
  3819. * You may obtain a copy of the License at
  3820. *
  3821. * http://www.apache.org/licenses/LICENSE-2.0
  3822. *
  3823. * Unless required by applicable law or agreed to in writing, software
  3824. * distributed under the License is distributed on an "AS IS" BASIS,
  3825. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3826. * See the License for the specific language governing permissions and
  3827. * limitations under the License.
  3828. */
  3829. // Exponential-Golomb buffer decoder
  3830. var ExpGolomb = /** @class */ (function () {
  3831. function ExpGolomb(uint8array) {
  3832. this.TAG = 'ExpGolomb';
  3833. this._buffer = uint8array;
  3834. this._buffer_index = 0;
  3835. this._total_bytes = uint8array.byteLength;
  3836. this._total_bits = uint8array.byteLength * 8;
  3837. this._current_word = 0;
  3838. this._current_word_bits_left = 0;
  3839. }
  3840. ExpGolomb.prototype.destroy = function () {
  3841. this._buffer = null;
  3842. };
  3843. ExpGolomb.prototype._fillCurrentWord = function () {
  3844. var buffer_bytes_left = this._total_bytes - this._buffer_index;
  3845. if (buffer_bytes_left <= 0)
  3846. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_0__.IllegalStateException('ExpGolomb: _fillCurrentWord() but no bytes available');
  3847. var bytes_read = Math.min(4, buffer_bytes_left);
  3848. var word = new Uint8Array(4);
  3849. word.set(this._buffer.subarray(this._buffer_index, this._buffer_index + bytes_read));
  3850. this._current_word = new DataView(word.buffer).getUint32(0, false);
  3851. this._buffer_index += bytes_read;
  3852. this._current_word_bits_left = bytes_read * 8;
  3853. };
  3854. ExpGolomb.prototype.readBits = function (bits) {
  3855. if (bits > 32)
  3856. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_0__.InvalidArgumentException('ExpGolomb: readBits() bits exceeded max 32bits!');
  3857. if (bits <= this._current_word_bits_left) {
  3858. var result_1 = this._current_word >>> (32 - bits);
  3859. this._current_word <<= bits;
  3860. this._current_word_bits_left -= bits;
  3861. return result_1;
  3862. }
  3863. var result = this._current_word_bits_left ? this._current_word : 0;
  3864. result = result >>> (32 - this._current_word_bits_left);
  3865. var bits_need_left = bits - this._current_word_bits_left;
  3866. this._fillCurrentWord();
  3867. var bits_read_next = Math.min(bits_need_left, this._current_word_bits_left);
  3868. var result2 = this._current_word >>> (32 - bits_read_next);
  3869. this._current_word <<= bits_read_next;
  3870. this._current_word_bits_left -= bits_read_next;
  3871. result = (result << bits_read_next) | result2;
  3872. return result;
  3873. };
  3874. ExpGolomb.prototype.readBool = function () {
  3875. return this.readBits(1) === 1;
  3876. };
  3877. ExpGolomb.prototype.readByte = function () {
  3878. return this.readBits(8);
  3879. };
  3880. ExpGolomb.prototype._skipLeadingZero = function () {
  3881. var zero_count;
  3882. for (zero_count = 0; zero_count < this._current_word_bits_left; zero_count++) {
  3883. if (0 !== (this._current_word & (0x80000000 >>> zero_count))) {
  3884. this._current_word <<= zero_count;
  3885. this._current_word_bits_left -= zero_count;
  3886. return zero_count;
  3887. }
  3888. }
  3889. this._fillCurrentWord();
  3890. return zero_count + this._skipLeadingZero();
  3891. };
  3892. ExpGolomb.prototype.readUEG = function () {
  3893. var leading_zeros = this._skipLeadingZero();
  3894. return this.readBits(leading_zeros + 1) - 1;
  3895. };
  3896. ExpGolomb.prototype.readSEG = function () {
  3897. var value = this.readUEG();
  3898. if (value & 0x01) {
  3899. return (value + 1) >>> 1;
  3900. }
  3901. else {
  3902. return -1 * (value >>> 1);
  3903. }
  3904. };
  3905. return ExpGolomb;
  3906. }());
  3907. /* harmony default export */ __webpack_exports__["default"] = (ExpGolomb);
  3908. /***/ }),
  3909. /***/ "./src/demux/flv-demuxer.js":
  3910. /*!**********************************!*\
  3911. !*** ./src/demux/flv-demuxer.js ***!
  3912. \**********************************/
  3913. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  3914. "use strict";
  3915. __webpack_require__.r(__webpack_exports__);
  3916. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  3917. /* harmony import */ var _amf_parser_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./amf-parser.js */ "./src/demux/amf-parser.js");
  3918. /* harmony import */ var _sps_parser_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./sps-parser.js */ "./src/demux/sps-parser.js");
  3919. /* harmony import */ var _demux_errors_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./demux-errors.js */ "./src/demux/demux-errors.js");
  3920. /* harmony import */ var _core_media_info_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/media-info.js */ "./src/core/media-info.js");
  3921. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  3922. /*
  3923. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  3924. *
  3925. * @author zheng qian <xqq@xqq.im>
  3926. *
  3927. * Licensed under the Apache License, Version 2.0 (the "License");
  3928. * you may not use this file except in compliance with the License.
  3929. * You may obtain a copy of the License at
  3930. *
  3931. * http://www.apache.org/licenses/LICENSE-2.0
  3932. *
  3933. * Unless required by applicable law or agreed to in writing, software
  3934. * distributed under the License is distributed on an "AS IS" BASIS,
  3935. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3936. * See the License for the specific language governing permissions and
  3937. * limitations under the License.
  3938. */
  3939. function Swap16(src) {
  3940. return (((src >>> 8) & 0xFF) |
  3941. ((src & 0xFF) << 8));
  3942. }
  3943. function Swap32(src) {
  3944. return (((src & 0xFF000000) >>> 24) |
  3945. ((src & 0x00FF0000) >>> 8) |
  3946. ((src & 0x0000FF00) << 8) |
  3947. ((src & 0x000000FF) << 24));
  3948. }
  3949. function ReadBig32(array, index) {
  3950. return ((array[index] << 24) |
  3951. (array[index + 1] << 16) |
  3952. (array[index + 2] << 8) |
  3953. (array[index + 3]));
  3954. }
  3955. var FLVDemuxer = /** @class */ (function () {
  3956. function FLVDemuxer(probeData, config) {
  3957. this.TAG = 'FLVDemuxer';
  3958. this._config = config;
  3959. this._onError = null;
  3960. this._onMediaInfo = null;
  3961. this._onMetaDataArrived = null;
  3962. this._onScriptDataArrived = null;
  3963. this._onTrackMetadata = null;
  3964. this._onDataAvailable = null;
  3965. this._dataOffset = probeData.dataOffset;
  3966. this._firstParse = true;
  3967. this._dispatch = false;
  3968. this._hasAudio = probeData.hasAudioTrack;
  3969. this._hasVideo = probeData.hasVideoTrack;
  3970. this._hasAudioFlagOverrided = false;
  3971. this._hasVideoFlagOverrided = false;
  3972. this._audioInitialMetadataDispatched = false;
  3973. this._videoInitialMetadataDispatched = false;
  3974. this._mediaInfo = new _core_media_info_js__WEBPACK_IMPORTED_MODULE_4__.default();
  3975. this._mediaInfo.hasAudio = this._hasAudio;
  3976. this._mediaInfo.hasVideo = this._hasVideo;
  3977. this._metadata = null;
  3978. this._audioMetadata = null;
  3979. this._videoMetadata = null;
  3980. this._naluLengthSize = 4;
  3981. this._timestampBase = 0; // int32, in milliseconds
  3982. this._timescale = 1000;
  3983. this._duration = 0; // int32, in milliseconds
  3984. this._durationOverrided = false;
  3985. this._referenceFrameRate = {
  3986. fixed: true,
  3987. fps: 23.976,
  3988. fps_num: 23976,
  3989. fps_den: 1000
  3990. };
  3991. this._flvSoundRateTable = [5500, 11025, 22050, 44100, 48000];
  3992. this._mpegSamplingRates = [
  3993. 96000, 88200, 64000, 48000, 44100, 32000,
  3994. 24000, 22050, 16000, 12000, 11025, 8000, 7350
  3995. ];
  3996. this._mpegAudioV10SampleRateTable = [44100, 48000, 32000, 0];
  3997. this._mpegAudioV20SampleRateTable = [22050, 24000, 16000, 0];
  3998. this._mpegAudioV25SampleRateTable = [11025, 12000, 8000, 0];
  3999. this._mpegAudioL1BitRateTable = [0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, -1];
  4000. this._mpegAudioL2BitRateTable = [0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, -1];
  4001. this._mpegAudioL3BitRateTable = [0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1];
  4002. this._videoTrack = { type: 'video', id: 1, sequenceNumber: 0, samples: [], length: 0 };
  4003. this._audioTrack = { type: 'audio', id: 2, sequenceNumber: 0, samples: [], length: 0 };
  4004. this._littleEndian = (function () {
  4005. var buf = new ArrayBuffer(2);
  4006. (new DataView(buf)).setInt16(0, 256, true); // little-endian write
  4007. return (new Int16Array(buf))[0] === 256; // platform-spec read, if equal then LE
  4008. })();
  4009. }
  4010. FLVDemuxer.prototype.destroy = function () {
  4011. this._mediaInfo = null;
  4012. this._metadata = null;
  4013. this._audioMetadata = null;
  4014. this._videoMetadata = null;
  4015. this._videoTrack = null;
  4016. this._audioTrack = null;
  4017. this._onError = null;
  4018. this._onMediaInfo = null;
  4019. this._onMetaDataArrived = null;
  4020. this._onScriptDataArrived = null;
  4021. this._onTrackMetadata = null;
  4022. this._onDataAvailable = null;
  4023. };
  4024. FLVDemuxer.probe = function (buffer) {
  4025. var data = new Uint8Array(buffer);
  4026. var mismatch = { match: false };
  4027. if (data[0] !== 0x46 || data[1] !== 0x4C || data[2] !== 0x56 || data[3] !== 0x01) {
  4028. return mismatch;
  4029. }
  4030. var hasAudio = ((data[4] & 4) >>> 2) !== 0;
  4031. var hasVideo = (data[4] & 1) !== 0;
  4032. var offset = ReadBig32(data, 5);
  4033. if (offset < 9) {
  4034. return mismatch;
  4035. }
  4036. return {
  4037. match: true,
  4038. consumed: offset,
  4039. dataOffset: offset,
  4040. hasAudioTrack: hasAudio,
  4041. hasVideoTrack: hasVideo
  4042. };
  4043. };
  4044. FLVDemuxer.prototype.bindDataSource = function (loader) {
  4045. loader.onDataArrival = this.parseChunks.bind(this);
  4046. return this;
  4047. };
  4048. Object.defineProperty(FLVDemuxer.prototype, "onTrackMetadata", {
  4049. // prototype: function(type: string, metadata: any): void
  4050. get: function () {
  4051. return this._onTrackMetadata;
  4052. },
  4053. set: function (callback) {
  4054. this._onTrackMetadata = callback;
  4055. },
  4056. enumerable: false,
  4057. configurable: true
  4058. });
  4059. Object.defineProperty(FLVDemuxer.prototype, "onMediaInfo", {
  4060. // prototype: function(mediaInfo: MediaInfo): void
  4061. get: function () {
  4062. return this._onMediaInfo;
  4063. },
  4064. set: function (callback) {
  4065. this._onMediaInfo = callback;
  4066. },
  4067. enumerable: false,
  4068. configurable: true
  4069. });
  4070. Object.defineProperty(FLVDemuxer.prototype, "onMetaDataArrived", {
  4071. get: function () {
  4072. return this._onMetaDataArrived;
  4073. },
  4074. set: function (callback) {
  4075. this._onMetaDataArrived = callback;
  4076. },
  4077. enumerable: false,
  4078. configurable: true
  4079. });
  4080. Object.defineProperty(FLVDemuxer.prototype, "onScriptDataArrived", {
  4081. get: function () {
  4082. return this._onScriptDataArrived;
  4083. },
  4084. set: function (callback) {
  4085. this._onScriptDataArrived = callback;
  4086. },
  4087. enumerable: false,
  4088. configurable: true
  4089. });
  4090. Object.defineProperty(FLVDemuxer.prototype, "onError", {
  4091. // prototype: function(type: number, info: string): void
  4092. get: function () {
  4093. return this._onError;
  4094. },
  4095. set: function (callback) {
  4096. this._onError = callback;
  4097. },
  4098. enumerable: false,
  4099. configurable: true
  4100. });
  4101. Object.defineProperty(FLVDemuxer.prototype, "onDataAvailable", {
  4102. // prototype: function(videoTrack: any, audioTrack: any): void
  4103. get: function () {
  4104. return this._onDataAvailable;
  4105. },
  4106. set: function (callback) {
  4107. this._onDataAvailable = callback;
  4108. },
  4109. enumerable: false,
  4110. configurable: true
  4111. });
  4112. Object.defineProperty(FLVDemuxer.prototype, "timestampBase", {
  4113. // timestamp base for output samples, must be in milliseconds
  4114. get: function () {
  4115. return this._timestampBase;
  4116. },
  4117. set: function (base) {
  4118. this._timestampBase = base;
  4119. },
  4120. enumerable: false,
  4121. configurable: true
  4122. });
  4123. Object.defineProperty(FLVDemuxer.prototype, "overridedDuration", {
  4124. get: function () {
  4125. return this._duration;
  4126. },
  4127. // Force-override media duration. Must be in milliseconds, int32
  4128. set: function (duration) {
  4129. this._durationOverrided = true;
  4130. this._duration = duration;
  4131. this._mediaInfo.duration = duration;
  4132. },
  4133. enumerable: false,
  4134. configurable: true
  4135. });
  4136. Object.defineProperty(FLVDemuxer.prototype, "overridedHasAudio", {
  4137. // Force-override audio track present flag, boolean
  4138. set: function (hasAudio) {
  4139. this._hasAudioFlagOverrided = true;
  4140. this._hasAudio = hasAudio;
  4141. this._mediaInfo.hasAudio = hasAudio;
  4142. },
  4143. enumerable: false,
  4144. configurable: true
  4145. });
  4146. Object.defineProperty(FLVDemuxer.prototype, "overridedHasVideo", {
  4147. // Force-override video track present flag, boolean
  4148. set: function (hasVideo) {
  4149. this._hasVideoFlagOverrided = true;
  4150. this._hasVideo = hasVideo;
  4151. this._mediaInfo.hasVideo = hasVideo;
  4152. },
  4153. enumerable: false,
  4154. configurable: true
  4155. });
  4156. FLVDemuxer.prototype.resetMediaInfo = function () {
  4157. this._mediaInfo = new _core_media_info_js__WEBPACK_IMPORTED_MODULE_4__.default();
  4158. };
  4159. FLVDemuxer.prototype._isInitialMetadataDispatched = function () {
  4160. if (this._hasAudio && this._hasVideo) { // both audio & video
  4161. return this._audioInitialMetadataDispatched && this._videoInitialMetadataDispatched;
  4162. }
  4163. if (this._hasAudio && !this._hasVideo) { // audio only
  4164. return this._audioInitialMetadataDispatched;
  4165. }
  4166. if (!this._hasAudio && this._hasVideo) { // video only
  4167. return this._videoInitialMetadataDispatched;
  4168. }
  4169. return false;
  4170. };
  4171. // function parseChunks(chunk: ArrayBuffer, byteStart: number): number;
  4172. FLVDemuxer.prototype.parseChunks = function (chunk, byteStart) {
  4173. if (!this._onError || !this._onMediaInfo || !this._onTrackMetadata || !this._onDataAvailable) {
  4174. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_5__.IllegalStateException('Flv: onError & onMediaInfo & onTrackMetadata & onDataAvailable callback must be specified');
  4175. }
  4176. var offset = 0;
  4177. var le = this._littleEndian;
  4178. if (byteStart === 0) { // buffer with FLV header
  4179. if (chunk.byteLength > 13) {
  4180. var probeData = FLVDemuxer.probe(chunk);
  4181. offset = probeData.dataOffset;
  4182. }
  4183. else {
  4184. return 0;
  4185. }
  4186. }
  4187. if (this._firstParse) { // handle PreviousTagSize0 before Tag1
  4188. this._firstParse = false;
  4189. if (byteStart + offset !== this._dataOffset) {
  4190. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'First time parsing but chunk byteStart invalid!');
  4191. }
  4192. var v = new DataView(chunk, offset);
  4193. var prevTagSize0 = v.getUint32(0, !le);
  4194. if (prevTagSize0 !== 0) {
  4195. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'PrevTagSize0 !== 0 !!!');
  4196. }
  4197. offset += 4;
  4198. }
  4199. while (offset < chunk.byteLength) {
  4200. this._dispatch = true;
  4201. var v = new DataView(chunk, offset);
  4202. if (offset + 11 + 4 > chunk.byteLength) {
  4203. // data not enough for parsing an flv tag
  4204. break;
  4205. }
  4206. var tagType = v.getUint8(0);
  4207. var dataSize = v.getUint32(0, !le) & 0x00FFFFFF;
  4208. if (offset + 11 + dataSize + 4 > chunk.byteLength) {
  4209. // data not enough for parsing actual data body
  4210. break;
  4211. }
  4212. if (tagType !== 8 && tagType !== 9 && tagType !== 18) {
  4213. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, "Unsupported tag type " + tagType + ", skipped");
  4214. // consume the whole tag (skip it)
  4215. offset += 11 + dataSize + 4;
  4216. continue;
  4217. }
  4218. var ts2 = v.getUint8(4);
  4219. var ts1 = v.getUint8(5);
  4220. var ts0 = v.getUint8(6);
  4221. var ts3 = v.getUint8(7);
  4222. var timestamp = ts0 | (ts1 << 8) | (ts2 << 16) | (ts3 << 24);
  4223. var streamId = v.getUint32(7, !le) & 0x00FFFFFF;
  4224. if (streamId !== 0) {
  4225. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Meet tag which has StreamID != 0!');
  4226. }
  4227. var dataOffset = offset + 11;
  4228. switch (tagType) {
  4229. case 8: // Audio
  4230. this._parseAudioData(chunk, dataOffset, dataSize, timestamp);
  4231. break;
  4232. case 9: // Video
  4233. this._parseVideoData(chunk, dataOffset, dataSize, timestamp, byteStart + offset);
  4234. break;
  4235. case 18: // ScriptDataObject
  4236. this._parseScriptData(chunk, dataOffset, dataSize);
  4237. break;
  4238. }
  4239. var prevTagSize = v.getUint32(11 + dataSize, !le);
  4240. if (prevTagSize !== 11 + dataSize) {
  4241. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, "Invalid PrevTagSize " + prevTagSize);
  4242. }
  4243. offset += 11 + dataSize + 4; // tagBody + dataSize + prevTagSize
  4244. }
  4245. // dispatch parsed frames to consumer (typically, the remuxer)
  4246. if (this._isInitialMetadataDispatched()) {
  4247. if (this._dispatch && (this._audioTrack.length || this._videoTrack.length)) {
  4248. this._onDataAvailable(this._audioTrack, this._videoTrack);
  4249. }
  4250. }
  4251. return offset; // consumed bytes, just equals latest offset index
  4252. };
  4253. FLVDemuxer.prototype._parseScriptData = function (arrayBuffer, dataOffset, dataSize) {
  4254. var scriptData = _amf_parser_js__WEBPACK_IMPORTED_MODULE_1__.default.parseScriptData(arrayBuffer, dataOffset, dataSize);
  4255. if (scriptData.hasOwnProperty('onMetaData')) {
  4256. if (scriptData.onMetaData == null || typeof scriptData.onMetaData !== 'object') {
  4257. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Invalid onMetaData structure!');
  4258. return;
  4259. }
  4260. if (this._metadata) {
  4261. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Found another onMetaData tag!');
  4262. }
  4263. this._metadata = scriptData;
  4264. var onMetaData = this._metadata.onMetaData;
  4265. if (this._onMetaDataArrived) {
  4266. this._onMetaDataArrived(Object.assign({}, onMetaData));
  4267. }
  4268. if (typeof onMetaData.hasAudio === 'boolean') { // hasAudio
  4269. if (this._hasAudioFlagOverrided === false) {
  4270. this._hasAudio = onMetaData.hasAudio;
  4271. this._mediaInfo.hasAudio = this._hasAudio;
  4272. }
  4273. }
  4274. if (typeof onMetaData.hasVideo === 'boolean') { // hasVideo
  4275. if (this._hasVideoFlagOverrided === false) {
  4276. this._hasVideo = onMetaData.hasVideo;
  4277. this._mediaInfo.hasVideo = this._hasVideo;
  4278. }
  4279. }
  4280. if (typeof onMetaData.audiodatarate === 'number') { // audiodatarate
  4281. this._mediaInfo.audioDataRate = onMetaData.audiodatarate;
  4282. }
  4283. if (typeof onMetaData.videodatarate === 'number') { // videodatarate
  4284. this._mediaInfo.videoDataRate = onMetaData.videodatarate;
  4285. }
  4286. if (typeof onMetaData.width === 'number') { // width
  4287. this._mediaInfo.width = onMetaData.width;
  4288. }
  4289. if (typeof onMetaData.height === 'number') { // height
  4290. this._mediaInfo.height = onMetaData.height;
  4291. }
  4292. if (typeof onMetaData.duration === 'number') { // duration
  4293. if (!this._durationOverrided) {
  4294. var duration = Math.floor(onMetaData.duration * this._timescale);
  4295. this._duration = duration;
  4296. this._mediaInfo.duration = duration;
  4297. }
  4298. }
  4299. else {
  4300. this._mediaInfo.duration = 0;
  4301. }
  4302. if (typeof onMetaData.framerate === 'number') { // framerate
  4303. var fps_num = Math.floor(onMetaData.framerate * 1000);
  4304. if (fps_num > 0) {
  4305. var fps = fps_num / 1000;
  4306. this._referenceFrameRate.fixed = true;
  4307. this._referenceFrameRate.fps = fps;
  4308. this._referenceFrameRate.fps_num = fps_num;
  4309. this._referenceFrameRate.fps_den = 1000;
  4310. this._mediaInfo.fps = fps;
  4311. }
  4312. }
  4313. if (typeof onMetaData.keyframes === 'object') { // keyframes
  4314. this._mediaInfo.hasKeyframesIndex = true;
  4315. var keyframes = onMetaData.keyframes;
  4316. this._mediaInfo.keyframesIndex = this._parseKeyframesIndex(keyframes);
  4317. onMetaData.keyframes = null; // keyframes has been extracted, remove it
  4318. }
  4319. else {
  4320. this._mediaInfo.hasKeyframesIndex = false;
  4321. }
  4322. this._dispatch = false;
  4323. this._mediaInfo.metadata = onMetaData;
  4324. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.v(this.TAG, 'Parsed onMetaData');
  4325. if (this._mediaInfo.isComplete()) {
  4326. this._onMediaInfo(this._mediaInfo);
  4327. }
  4328. }
  4329. if (Object.keys(scriptData).length > 0) {
  4330. if (this._onScriptDataArrived) {
  4331. this._onScriptDataArrived(Object.assign({}, scriptData));
  4332. }
  4333. }
  4334. };
  4335. FLVDemuxer.prototype._parseKeyframesIndex = function (keyframes) {
  4336. var times = [];
  4337. var filepositions = [];
  4338. // ignore first keyframe which is actually AVC Sequence Header (AVCDecoderConfigurationRecord)
  4339. for (var i = 1; i < keyframes.times.length; i++) {
  4340. var time = this._timestampBase + Math.floor(keyframes.times[i] * 1000);
  4341. times.push(time);
  4342. filepositions.push(keyframes.filepositions[i]);
  4343. }
  4344. return {
  4345. times: times,
  4346. filepositions: filepositions
  4347. };
  4348. };
  4349. FLVDemuxer.prototype._parseAudioData = function (arrayBuffer, dataOffset, dataSize, tagTimestamp) {
  4350. if (dataSize <= 1) {
  4351. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Flv: Invalid audio packet, missing SoundData payload!');
  4352. return;
  4353. }
  4354. if (this._hasAudioFlagOverrided === true && this._hasAudio === false) {
  4355. // If hasAudio: false indicated explicitly in MediaDataSource,
  4356. // Ignore all the audio packets
  4357. return;
  4358. }
  4359. var le = this._littleEndian;
  4360. var v = new DataView(arrayBuffer, dataOffset, dataSize);
  4361. var soundSpec = v.getUint8(0);
  4362. var soundFormat = soundSpec >>> 4;
  4363. if (soundFormat !== 2 && soundFormat !== 10) { // MP3 or AAC
  4364. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.CODEC_UNSUPPORTED, 'Flv: Unsupported audio codec idx: ' + soundFormat);
  4365. return;
  4366. }
  4367. var soundRate = 0;
  4368. var soundRateIndex = (soundSpec & 12) >>> 2;
  4369. if (soundRateIndex >= 0 && soundRateIndex <= 4) {
  4370. soundRate = this._flvSoundRateTable[soundRateIndex];
  4371. }
  4372. else {
  4373. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.FORMAT_ERROR, 'Flv: Invalid audio sample rate idx: ' + soundRateIndex);
  4374. return;
  4375. }
  4376. var soundSize = (soundSpec & 2) >>> 1; // unused
  4377. var soundType = (soundSpec & 1);
  4378. var meta = this._audioMetadata;
  4379. var track = this._audioTrack;
  4380. if (!meta) {
  4381. if (this._hasAudio === false && this._hasAudioFlagOverrided === false) {
  4382. this._hasAudio = true;
  4383. this._mediaInfo.hasAudio = true;
  4384. }
  4385. // initial metadata
  4386. meta = this._audioMetadata = {};
  4387. meta.type = 'audio';
  4388. meta.id = track.id;
  4389. meta.timescale = this._timescale;
  4390. meta.duration = this._duration;
  4391. meta.audioSampleRate = soundRate;
  4392. meta.channelCount = (soundType === 0 ? 1 : 2);
  4393. }
  4394. if (soundFormat === 10) { // AAC
  4395. var aacData = this._parseAACAudioData(arrayBuffer, dataOffset + 1, dataSize - 1);
  4396. if (aacData == undefined) {
  4397. return;
  4398. }
  4399. if (aacData.packetType === 0) { // AAC sequence header (AudioSpecificConfig)
  4400. if (meta.config) {
  4401. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Found another AudioSpecificConfig!');
  4402. }
  4403. var misc = aacData.data;
  4404. meta.audioSampleRate = misc.samplingRate;
  4405. meta.channelCount = misc.channelCount;
  4406. meta.codec = misc.codec;
  4407. meta.originalCodec = misc.originalCodec;
  4408. meta.config = misc.config;
  4409. // The decode result of an aac sample is 1024 PCM samples
  4410. meta.refSampleDuration = 1024 / meta.audioSampleRate * meta.timescale;
  4411. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.v(this.TAG, 'Parsed AudioSpecificConfig');
  4412. if (this._isInitialMetadataDispatched()) {
  4413. // Non-initial metadata, force dispatch (or flush) parsed frames to remuxer
  4414. if (this._dispatch && (this._audioTrack.length || this._videoTrack.length)) {
  4415. this._onDataAvailable(this._audioTrack, this._videoTrack);
  4416. }
  4417. }
  4418. else {
  4419. this._audioInitialMetadataDispatched = true;
  4420. }
  4421. // then notify new metadata
  4422. this._dispatch = false;
  4423. this._onTrackMetadata('audio', meta);
  4424. var mi = this._mediaInfo;
  4425. mi.audioCodec = meta.originalCodec;
  4426. mi.audioSampleRate = meta.audioSampleRate;
  4427. mi.audioChannelCount = meta.channelCount;
  4428. if (mi.hasVideo) {
  4429. if (mi.videoCodec != null) {
  4430. mi.mimeType = 'video/x-flv; codecs="' + mi.videoCodec + ',' + mi.audioCodec + '"';
  4431. }
  4432. }
  4433. else {
  4434. mi.mimeType = 'video/x-flv; codecs="' + mi.audioCodec + '"';
  4435. }
  4436. if (mi.isComplete()) {
  4437. this._onMediaInfo(mi);
  4438. }
  4439. }
  4440. else if (aacData.packetType === 1) { // AAC raw frame data
  4441. var dts = this._timestampBase + tagTimestamp;
  4442. var aacSample = { unit: aacData.data, length: aacData.data.byteLength, dts: dts, pts: dts };
  4443. track.samples.push(aacSample);
  4444. track.length += aacData.data.length;
  4445. }
  4446. else {
  4447. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.e(this.TAG, "Flv: Unsupported AAC data type " + aacData.packetType);
  4448. }
  4449. }
  4450. else if (soundFormat === 2) { // MP3
  4451. if (!meta.codec) {
  4452. // We need metadata for mp3 audio track, extract info from frame header
  4453. var misc = this._parseMP3AudioData(arrayBuffer, dataOffset + 1, dataSize - 1, true);
  4454. if (misc == undefined) {
  4455. return;
  4456. }
  4457. meta.audioSampleRate = misc.samplingRate;
  4458. meta.channelCount = misc.channelCount;
  4459. meta.codec = misc.codec;
  4460. meta.originalCodec = misc.originalCodec;
  4461. // The decode result of an mp3 sample is 1152 PCM samples
  4462. meta.refSampleDuration = 1152 / meta.audioSampleRate * meta.timescale;
  4463. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.v(this.TAG, 'Parsed MPEG Audio Frame Header');
  4464. this._audioInitialMetadataDispatched = true;
  4465. this._onTrackMetadata('audio', meta);
  4466. var mi = this._mediaInfo;
  4467. mi.audioCodec = meta.codec;
  4468. mi.audioSampleRate = meta.audioSampleRate;
  4469. mi.audioChannelCount = meta.channelCount;
  4470. mi.audioDataRate = misc.bitRate;
  4471. if (mi.hasVideo) {
  4472. if (mi.videoCodec != null) {
  4473. mi.mimeType = 'video/x-flv; codecs="' + mi.videoCodec + ',' + mi.audioCodec + '"';
  4474. }
  4475. }
  4476. else {
  4477. mi.mimeType = 'video/x-flv; codecs="' + mi.audioCodec + '"';
  4478. }
  4479. if (mi.isComplete()) {
  4480. this._onMediaInfo(mi);
  4481. }
  4482. }
  4483. // This packet is always a valid audio packet, extract it
  4484. var data = this._parseMP3AudioData(arrayBuffer, dataOffset + 1, dataSize - 1, false);
  4485. if (data == undefined) {
  4486. return;
  4487. }
  4488. var dts = this._timestampBase + tagTimestamp;
  4489. var mp3Sample = { unit: data, length: data.byteLength, dts: dts, pts: dts };
  4490. track.samples.push(mp3Sample);
  4491. track.length += data.length;
  4492. }
  4493. };
  4494. FLVDemuxer.prototype._parseAACAudioData = function (arrayBuffer, dataOffset, dataSize) {
  4495. if (dataSize <= 1) {
  4496. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Flv: Invalid AAC packet, missing AACPacketType or/and Data!');
  4497. return;
  4498. }
  4499. var result = {};
  4500. var array = new Uint8Array(arrayBuffer, dataOffset, dataSize);
  4501. result.packetType = array[0];
  4502. if (array[0] === 0) {
  4503. result.data = this._parseAACAudioSpecificConfig(arrayBuffer, dataOffset + 1, dataSize - 1);
  4504. }
  4505. else {
  4506. result.data = array.subarray(1);
  4507. }
  4508. return result;
  4509. };
  4510. FLVDemuxer.prototype._parseAACAudioSpecificConfig = function (arrayBuffer, dataOffset, dataSize) {
  4511. var array = new Uint8Array(arrayBuffer, dataOffset, dataSize);
  4512. var config = null;
  4513. /* Audio Object Type:
  4514. 0: Null
  4515. 1: AAC Main
  4516. 2: AAC LC
  4517. 3: AAC SSR (Scalable Sample Rate)
  4518. 4: AAC LTP (Long Term Prediction)
  4519. 5: HE-AAC / SBR (Spectral Band Replication)
  4520. 6: AAC Scalable
  4521. */
  4522. var audioObjectType = 0;
  4523. var originalAudioObjectType = 0;
  4524. var audioExtensionObjectType = null;
  4525. var samplingIndex = 0;
  4526. var extensionSamplingIndex = null;
  4527. // 5 bits
  4528. audioObjectType = originalAudioObjectType = array[0] >>> 3;
  4529. // 4 bits
  4530. samplingIndex = ((array[0] & 0x07) << 1) | (array[1] >>> 7);
  4531. if (samplingIndex < 0 || samplingIndex >= this._mpegSamplingRates.length) {
  4532. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.FORMAT_ERROR, 'Flv: AAC invalid sampling frequency index!');
  4533. return;
  4534. }
  4535. var samplingFrequence = this._mpegSamplingRates[samplingIndex];
  4536. // 4 bits
  4537. var channelConfig = (array[1] & 0x78) >>> 3;
  4538. if (channelConfig < 0 || channelConfig >= 8) {
  4539. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.FORMAT_ERROR, 'Flv: AAC invalid channel configuration');
  4540. return;
  4541. }
  4542. if (audioObjectType === 5) { // HE-AAC?
  4543. // 4 bits
  4544. extensionSamplingIndex = ((array[1] & 0x07) << 1) | (array[2] >>> 7);
  4545. // 5 bits
  4546. audioExtensionObjectType = (array[2] & 0x7C) >>> 2;
  4547. }
  4548. // workarounds for various browsers
  4549. var userAgent = self.navigator.userAgent.toLowerCase();
  4550. if (userAgent.indexOf('firefox') !== -1) {
  4551. // firefox: use SBR (HE-AAC) if freq less than 24kHz
  4552. if (samplingIndex >= 6) {
  4553. audioObjectType = 5;
  4554. config = new Array(4);
  4555. extensionSamplingIndex = samplingIndex - 3;
  4556. }
  4557. else { // use LC-AAC
  4558. audioObjectType = 2;
  4559. config = new Array(2);
  4560. extensionSamplingIndex = samplingIndex;
  4561. }
  4562. }
  4563. else if (userAgent.indexOf('android') !== -1) {
  4564. // android: always use LC-AAC
  4565. audioObjectType = 2;
  4566. config = new Array(2);
  4567. extensionSamplingIndex = samplingIndex;
  4568. }
  4569. else {
  4570. // for other browsers, e.g. chrome...
  4571. // Always use HE-AAC to make it easier to switch aac codec profile
  4572. audioObjectType = 5;
  4573. extensionSamplingIndex = samplingIndex;
  4574. config = new Array(4);
  4575. if (samplingIndex >= 6) {
  4576. extensionSamplingIndex = samplingIndex - 3;
  4577. }
  4578. else if (channelConfig === 1) { // Mono channel
  4579. audioObjectType = 2;
  4580. config = new Array(2);
  4581. extensionSamplingIndex = samplingIndex;
  4582. }
  4583. }
  4584. config[0] = audioObjectType << 3;
  4585. config[0] |= (samplingIndex & 0x0F) >>> 1;
  4586. config[1] = (samplingIndex & 0x0F) << 7;
  4587. config[1] |= (channelConfig & 0x0F) << 3;
  4588. if (audioObjectType === 5) {
  4589. config[1] |= ((extensionSamplingIndex & 0x0F) >>> 1);
  4590. config[2] = (extensionSamplingIndex & 0x01) << 7;
  4591. // extended audio object type: force to 2 (LC-AAC)
  4592. config[2] |= (2 << 2);
  4593. config[3] = 0;
  4594. }
  4595. return {
  4596. config: config,
  4597. samplingRate: samplingFrequence,
  4598. channelCount: channelConfig,
  4599. codec: 'mp4a.40.' + audioObjectType,
  4600. originalCodec: 'mp4a.40.' + originalAudioObjectType
  4601. };
  4602. };
  4603. FLVDemuxer.prototype._parseMP3AudioData = function (arrayBuffer, dataOffset, dataSize, requestHeader) {
  4604. if (dataSize < 4) {
  4605. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Flv: Invalid MP3 packet, header missing!');
  4606. return;
  4607. }
  4608. var le = this._littleEndian;
  4609. var array = new Uint8Array(arrayBuffer, dataOffset, dataSize);
  4610. var result = null;
  4611. if (requestHeader) {
  4612. if (array[0] !== 0xFF) {
  4613. return;
  4614. }
  4615. var ver = (array[1] >>> 3) & 0x03;
  4616. var layer = (array[1] & 0x06) >> 1;
  4617. var bitrate_index = (array[2] & 0xF0) >>> 4;
  4618. var sampling_freq_index = (array[2] & 0x0C) >>> 2;
  4619. var channel_mode = (array[3] >>> 6) & 0x03;
  4620. var channel_count = channel_mode !== 3 ? 2 : 1;
  4621. var sample_rate = 0;
  4622. var bit_rate = 0;
  4623. var object_type = 34; // Layer-3, listed in MPEG-4 Audio Object Types
  4624. var codec = 'mp3';
  4625. switch (ver) {
  4626. case 0: // MPEG 2.5
  4627. sample_rate = this._mpegAudioV25SampleRateTable[sampling_freq_index];
  4628. break;
  4629. case 2: // MPEG 2
  4630. sample_rate = this._mpegAudioV20SampleRateTable[sampling_freq_index];
  4631. break;
  4632. case 3: // MPEG 1
  4633. sample_rate = this._mpegAudioV10SampleRateTable[sampling_freq_index];
  4634. break;
  4635. }
  4636. switch (layer) {
  4637. case 1: // Layer 3
  4638. object_type = 34;
  4639. if (bitrate_index < this._mpegAudioL3BitRateTable.length) {
  4640. bit_rate = this._mpegAudioL3BitRateTable[bitrate_index];
  4641. }
  4642. break;
  4643. case 2: // Layer 2
  4644. object_type = 33;
  4645. if (bitrate_index < this._mpegAudioL2BitRateTable.length) {
  4646. bit_rate = this._mpegAudioL2BitRateTable[bitrate_index];
  4647. }
  4648. break;
  4649. case 3: // Layer 1
  4650. object_type = 32;
  4651. if (bitrate_index < this._mpegAudioL1BitRateTable.length) {
  4652. bit_rate = this._mpegAudioL1BitRateTable[bitrate_index];
  4653. }
  4654. break;
  4655. }
  4656. result = {
  4657. bitRate: bit_rate,
  4658. samplingRate: sample_rate,
  4659. channelCount: channel_count,
  4660. codec: codec,
  4661. originalCodec: codec
  4662. };
  4663. }
  4664. else {
  4665. result = array;
  4666. }
  4667. return result;
  4668. };
  4669. FLVDemuxer.prototype._parseVideoData = function (arrayBuffer, dataOffset, dataSize, tagTimestamp, tagPosition) {
  4670. if (dataSize <= 1) {
  4671. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Flv: Invalid video packet, missing VideoData payload!');
  4672. return;
  4673. }
  4674. if (this._hasVideoFlagOverrided === true && this._hasVideo === false) {
  4675. // If hasVideo: false indicated explicitly in MediaDataSource,
  4676. // Ignore all the video packets
  4677. return;
  4678. }
  4679. var spec = (new Uint8Array(arrayBuffer, dataOffset, dataSize))[0];
  4680. var frameType = (spec & 240) >>> 4;
  4681. var codecId = spec & 15;
  4682. if (codecId !== 7) {
  4683. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.CODEC_UNSUPPORTED, "Flv: Unsupported codec in video frame: " + codecId);
  4684. return;
  4685. }
  4686. this._parseAVCVideoPacket(arrayBuffer, dataOffset + 1, dataSize - 1, tagTimestamp, tagPosition, frameType);
  4687. };
  4688. FLVDemuxer.prototype._parseAVCVideoPacket = function (arrayBuffer, dataOffset, dataSize, tagTimestamp, tagPosition, frameType) {
  4689. if (dataSize < 4) {
  4690. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Flv: Invalid AVC packet, missing AVCPacketType or/and CompositionTime');
  4691. return;
  4692. }
  4693. var le = this._littleEndian;
  4694. var v = new DataView(arrayBuffer, dataOffset, dataSize);
  4695. var packetType = v.getUint8(0);
  4696. var cts_unsigned = v.getUint32(0, !le) & 0x00FFFFFF;
  4697. var cts = (cts_unsigned << 8) >> 8; // convert to 24-bit signed int
  4698. if (packetType === 0) { // AVCDecoderConfigurationRecord
  4699. this._parseAVCDecoderConfigurationRecord(arrayBuffer, dataOffset + 4, dataSize - 4);
  4700. }
  4701. else if (packetType === 1) { // One or more Nalus
  4702. this._parseAVCVideoData(arrayBuffer, dataOffset + 4, dataSize - 4, tagTimestamp, tagPosition, frameType, cts);
  4703. }
  4704. else if (packetType === 2) {
  4705. // empty, AVC end of sequence
  4706. }
  4707. else {
  4708. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.FORMAT_ERROR, "Flv: Invalid video packet type " + packetType);
  4709. return;
  4710. }
  4711. };
  4712. FLVDemuxer.prototype._parseAVCDecoderConfigurationRecord = function (arrayBuffer, dataOffset, dataSize) {
  4713. if (dataSize < 7) {
  4714. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Flv: Invalid AVCDecoderConfigurationRecord, lack of data!');
  4715. return;
  4716. }
  4717. var meta = this._videoMetadata;
  4718. var track = this._videoTrack;
  4719. var le = this._littleEndian;
  4720. var v = new DataView(arrayBuffer, dataOffset, dataSize);
  4721. if (!meta) {
  4722. if (this._hasVideo === false && this._hasVideoFlagOverrided === false) {
  4723. this._hasVideo = true;
  4724. this._mediaInfo.hasVideo = true;
  4725. }
  4726. meta = this._videoMetadata = {};
  4727. meta.type = 'video';
  4728. meta.id = track.id;
  4729. meta.timescale = this._timescale;
  4730. meta.duration = this._duration;
  4731. }
  4732. else {
  4733. if (typeof meta.avcc !== 'undefined') {
  4734. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Found another AVCDecoderConfigurationRecord!');
  4735. }
  4736. }
  4737. var version = v.getUint8(0); // configurationVersion
  4738. var avcProfile = v.getUint8(1); // avcProfileIndication
  4739. var profileCompatibility = v.getUint8(2); // profile_compatibility
  4740. var avcLevel = v.getUint8(3); // AVCLevelIndication
  4741. if (version !== 1 || avcProfile === 0) {
  4742. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.FORMAT_ERROR, 'Flv: Invalid AVCDecoderConfigurationRecord');
  4743. return;
  4744. }
  4745. this._naluLengthSize = (v.getUint8(4) & 3) + 1; // lengthSizeMinusOne
  4746. if (this._naluLengthSize !== 3 && this._naluLengthSize !== 4) { // holy shit!!!
  4747. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.FORMAT_ERROR, "Flv: Strange NaluLengthSizeMinusOne: " + (this._naluLengthSize - 1));
  4748. return;
  4749. }
  4750. var spsCount = v.getUint8(5) & 31; // numOfSequenceParameterSets
  4751. if (spsCount === 0) {
  4752. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.FORMAT_ERROR, 'Flv: Invalid AVCDecoderConfigurationRecord: No SPS');
  4753. return;
  4754. }
  4755. else if (spsCount > 1) {
  4756. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, "Flv: Strange AVCDecoderConfigurationRecord: SPS Count = " + spsCount);
  4757. }
  4758. var offset = 6;
  4759. for (var i = 0; i < spsCount; i++) {
  4760. var len = v.getUint16(offset, !le); // sequenceParameterSetLength
  4761. offset += 2;
  4762. if (len === 0) {
  4763. continue;
  4764. }
  4765. // Notice: Nalu without startcode header (00 00 00 01)
  4766. var sps = new Uint8Array(arrayBuffer, dataOffset + offset, len);
  4767. offset += len;
  4768. var config = _sps_parser_js__WEBPACK_IMPORTED_MODULE_2__.default.parseSPS(sps);
  4769. if (i !== 0) {
  4770. // ignore other sps's config
  4771. continue;
  4772. }
  4773. meta.codecWidth = config.codec_size.width;
  4774. meta.codecHeight = config.codec_size.height;
  4775. meta.presentWidth = config.present_size.width;
  4776. meta.presentHeight = config.present_size.height;
  4777. meta.profile = config.profile_string;
  4778. meta.level = config.level_string;
  4779. meta.bitDepth = config.bit_depth;
  4780. meta.chromaFormat = config.chroma_format;
  4781. meta.sarRatio = config.sar_ratio;
  4782. meta.frameRate = config.frame_rate;
  4783. if (config.frame_rate.fixed === false ||
  4784. config.frame_rate.fps_num === 0 ||
  4785. config.frame_rate.fps_den === 0) {
  4786. meta.frameRate = this._referenceFrameRate;
  4787. }
  4788. var fps_den = meta.frameRate.fps_den;
  4789. var fps_num = meta.frameRate.fps_num;
  4790. meta.refSampleDuration = meta.timescale * (fps_den / fps_num);
  4791. var codecArray = sps.subarray(1, 4);
  4792. var codecString = 'avc1.';
  4793. for (var j = 0; j < 3; j++) {
  4794. var h = codecArray[j].toString(16);
  4795. if (h.length < 2) {
  4796. h = '0' + h;
  4797. }
  4798. codecString += h;
  4799. }
  4800. meta.codec = codecString;
  4801. var mi = this._mediaInfo;
  4802. mi.width = meta.codecWidth;
  4803. mi.height = meta.codecHeight;
  4804. mi.fps = meta.frameRate.fps;
  4805. mi.profile = meta.profile;
  4806. mi.level = meta.level;
  4807. mi.refFrames = config.ref_frames;
  4808. mi.chromaFormat = config.chroma_format_string;
  4809. mi.sarNum = meta.sarRatio.width;
  4810. mi.sarDen = meta.sarRatio.height;
  4811. mi.videoCodec = codecString;
  4812. if (mi.hasAudio) {
  4813. if (mi.audioCodec != null) {
  4814. mi.mimeType = 'video/x-flv; codecs="' + mi.videoCodec + ',' + mi.audioCodec + '"';
  4815. }
  4816. }
  4817. else {
  4818. mi.mimeType = 'video/x-flv; codecs="' + mi.videoCodec + '"';
  4819. }
  4820. if (mi.isComplete()) {
  4821. this._onMediaInfo(mi);
  4822. }
  4823. }
  4824. var ppsCount = v.getUint8(offset); // numOfPictureParameterSets
  4825. if (ppsCount === 0) {
  4826. this._onError(_demux_errors_js__WEBPACK_IMPORTED_MODULE_3__.default.FORMAT_ERROR, 'Flv: Invalid AVCDecoderConfigurationRecord: No PPS');
  4827. return;
  4828. }
  4829. else if (ppsCount > 1) {
  4830. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, "Flv: Strange AVCDecoderConfigurationRecord: PPS Count = " + ppsCount);
  4831. }
  4832. offset++;
  4833. for (var i = 0; i < ppsCount; i++) {
  4834. var len = v.getUint16(offset, !le); // pictureParameterSetLength
  4835. offset += 2;
  4836. if (len === 0) {
  4837. continue;
  4838. }
  4839. // pps is useless for extracting video information
  4840. offset += len;
  4841. }
  4842. meta.avcc = new Uint8Array(dataSize);
  4843. meta.avcc.set(new Uint8Array(arrayBuffer, dataOffset, dataSize), 0);
  4844. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.v(this.TAG, 'Parsed AVCDecoderConfigurationRecord');
  4845. if (this._isInitialMetadataDispatched()) {
  4846. // flush parsed frames
  4847. if (this._dispatch && (this._audioTrack.length || this._videoTrack.length)) {
  4848. this._onDataAvailable(this._audioTrack, this._videoTrack);
  4849. }
  4850. }
  4851. else {
  4852. this._videoInitialMetadataDispatched = true;
  4853. }
  4854. // notify new metadata
  4855. this._dispatch = false;
  4856. this._onTrackMetadata('video', meta);
  4857. };
  4858. FLVDemuxer.prototype._parseAVCVideoData = function (arrayBuffer, dataOffset, dataSize, tagTimestamp, tagPosition, frameType, cts) {
  4859. var le = this._littleEndian;
  4860. var v = new DataView(arrayBuffer, dataOffset, dataSize);
  4861. var units = [], length = 0;
  4862. var offset = 0;
  4863. var lengthSize = this._naluLengthSize;
  4864. var dts = this._timestampBase + tagTimestamp;
  4865. var keyframe = (frameType === 1); // from FLV Frame Type constants
  4866. while (offset < dataSize) {
  4867. if (offset + 4 >= dataSize) {
  4868. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, "Malformed Nalu near timestamp " + dts + ", offset = " + offset + ", dataSize = " + dataSize);
  4869. break; // data not enough for next Nalu
  4870. }
  4871. // Nalu with length-header (AVC1)
  4872. var naluSize = v.getUint32(offset, !le); // Big-Endian read
  4873. if (lengthSize === 3) {
  4874. naluSize >>>= 8;
  4875. }
  4876. if (naluSize > dataSize - lengthSize) {
  4877. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, "Malformed Nalus near timestamp " + dts + ", NaluSize > DataSize!");
  4878. return;
  4879. }
  4880. var unitType = v.getUint8(offset + lengthSize) & 0x1F;
  4881. if (unitType === 5) { // IDR
  4882. keyframe = true;
  4883. }
  4884. var data = new Uint8Array(arrayBuffer, dataOffset + offset, lengthSize + naluSize);
  4885. var unit = { type: unitType, data: data };
  4886. units.push(unit);
  4887. length += data.byteLength;
  4888. offset += lengthSize + naluSize;
  4889. }
  4890. if (units.length) {
  4891. var track = this._videoTrack;
  4892. var avcSample = {
  4893. units: units,
  4894. length: length,
  4895. isKeyframe: keyframe,
  4896. dts: dts,
  4897. cts: cts,
  4898. pts: (dts + cts)
  4899. };
  4900. if (keyframe) {
  4901. avcSample.fileposition = tagPosition;
  4902. }
  4903. track.samples.push(avcSample);
  4904. track.length += length;
  4905. }
  4906. };
  4907. return FLVDemuxer;
  4908. }());
  4909. /* harmony default export */ __webpack_exports__["default"] = (FLVDemuxer);
  4910. /***/ }),
  4911. /***/ "./src/demux/sps-parser.js":
  4912. /*!*********************************!*\
  4913. !*** ./src/demux/sps-parser.js ***!
  4914. \*********************************/
  4915. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  4916. "use strict";
  4917. __webpack_require__.r(__webpack_exports__);
  4918. /* harmony import */ var _exp_golomb_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./exp-golomb.js */ "./src/demux/exp-golomb.js");
  4919. /*
  4920. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  4921. *
  4922. * @author zheng qian <xqq@xqq.im>
  4923. *
  4924. * Licensed under the Apache License, Version 2.0 (the "License");
  4925. * you may not use this file except in compliance with the License.
  4926. * You may obtain a copy of the License at
  4927. *
  4928. * http://www.apache.org/licenses/LICENSE-2.0
  4929. *
  4930. * Unless required by applicable law or agreed to in writing, software
  4931. * distributed under the License is distributed on an "AS IS" BASIS,
  4932. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4933. * See the License for the specific language governing permissions and
  4934. * limitations under the License.
  4935. */
  4936. var SPSParser = /** @class */ (function () {
  4937. function SPSParser() {
  4938. }
  4939. SPSParser._ebsp2rbsp = function (uint8array) {
  4940. var src = uint8array;
  4941. var src_length = src.byteLength;
  4942. var dst = new Uint8Array(src_length);
  4943. var dst_idx = 0;
  4944. for (var i = 0; i < src_length; i++) {
  4945. if (i >= 2) {
  4946. // Unescape: Skip 0x03 after 00 00
  4947. if (src[i] === 0x03 && src[i - 1] === 0x00 && src[i - 2] === 0x00) {
  4948. continue;
  4949. }
  4950. }
  4951. dst[dst_idx] = src[i];
  4952. dst_idx++;
  4953. }
  4954. return new Uint8Array(dst.buffer, 0, dst_idx);
  4955. };
  4956. SPSParser.parseSPS = function (uint8array) {
  4957. var rbsp = SPSParser._ebsp2rbsp(uint8array);
  4958. var gb = new _exp_golomb_js__WEBPACK_IMPORTED_MODULE_0__.default(rbsp);
  4959. gb.readByte();
  4960. var profile_idc = gb.readByte(); // profile_idc
  4961. gb.readByte(); // constraint_set_flags[5] + reserved_zero[3]
  4962. var level_idc = gb.readByte(); // level_idc
  4963. gb.readUEG(); // seq_parameter_set_id
  4964. var profile_string = SPSParser.getProfileString(profile_idc);
  4965. var level_string = SPSParser.getLevelString(level_idc);
  4966. var chroma_format_idc = 1;
  4967. var chroma_format = 420;
  4968. var chroma_format_table = [0, 420, 422, 444];
  4969. var bit_depth = 8;
  4970. if (profile_idc === 100 || profile_idc === 110 || profile_idc === 122 ||
  4971. profile_idc === 244 || profile_idc === 44 || profile_idc === 83 ||
  4972. profile_idc === 86 || profile_idc === 118 || profile_idc === 128 ||
  4973. profile_idc === 138 || profile_idc === 144) {
  4974. chroma_format_idc = gb.readUEG();
  4975. if (chroma_format_idc === 3) {
  4976. gb.readBits(1); // separate_colour_plane_flag
  4977. }
  4978. if (chroma_format_idc <= 3) {
  4979. chroma_format = chroma_format_table[chroma_format_idc];
  4980. }
  4981. bit_depth = gb.readUEG() + 8; // bit_depth_luma_minus8
  4982. gb.readUEG(); // bit_depth_chroma_minus8
  4983. gb.readBits(1); // qpprime_y_zero_transform_bypass_flag
  4984. if (gb.readBool()) { // seq_scaling_matrix_present_flag
  4985. var scaling_list_count = (chroma_format_idc !== 3) ? 8 : 12;
  4986. for (var i = 0; i < scaling_list_count; i++) {
  4987. if (gb.readBool()) { // seq_scaling_list_present_flag
  4988. if (i < 6) {
  4989. SPSParser._skipScalingList(gb, 16);
  4990. }
  4991. else {
  4992. SPSParser._skipScalingList(gb, 64);
  4993. }
  4994. }
  4995. }
  4996. }
  4997. }
  4998. gb.readUEG(); // log2_max_frame_num_minus4
  4999. var pic_order_cnt_type = gb.readUEG();
  5000. if (pic_order_cnt_type === 0) {
  5001. gb.readUEG(); // log2_max_pic_order_cnt_lsb_minus_4
  5002. }
  5003. else if (pic_order_cnt_type === 1) {
  5004. gb.readBits(1); // delta_pic_order_always_zero_flag
  5005. gb.readSEG(); // offset_for_non_ref_pic
  5006. gb.readSEG(); // offset_for_top_to_bottom_field
  5007. var num_ref_frames_in_pic_order_cnt_cycle = gb.readUEG();
  5008. for (var i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) {
  5009. gb.readSEG(); // offset_for_ref_frame
  5010. }
  5011. }
  5012. var ref_frames = gb.readUEG(); // max_num_ref_frames
  5013. gb.readBits(1); // gaps_in_frame_num_value_allowed_flag
  5014. var pic_width_in_mbs_minus1 = gb.readUEG();
  5015. var pic_height_in_map_units_minus1 = gb.readUEG();
  5016. var frame_mbs_only_flag = gb.readBits(1);
  5017. if (frame_mbs_only_flag === 0) {
  5018. gb.readBits(1); // mb_adaptive_frame_field_flag
  5019. }
  5020. gb.readBits(1); // direct_8x8_inference_flag
  5021. var frame_crop_left_offset = 0;
  5022. var frame_crop_right_offset = 0;
  5023. var frame_crop_top_offset = 0;
  5024. var frame_crop_bottom_offset = 0;
  5025. var frame_cropping_flag = gb.readBool();
  5026. if (frame_cropping_flag) {
  5027. frame_crop_left_offset = gb.readUEG();
  5028. frame_crop_right_offset = gb.readUEG();
  5029. frame_crop_top_offset = gb.readUEG();
  5030. frame_crop_bottom_offset = gb.readUEG();
  5031. }
  5032. var sar_width = 1, sar_height = 1;
  5033. var fps = 0, fps_fixed = true, fps_num = 0, fps_den = 0;
  5034. var vui_parameters_present_flag = gb.readBool();
  5035. if (vui_parameters_present_flag) {
  5036. if (gb.readBool()) { // aspect_ratio_info_present_flag
  5037. var aspect_ratio_idc = gb.readByte();
  5038. var sar_w_table = [1, 12, 10, 16, 40, 24, 20, 32, 80, 18, 15, 64, 160, 4, 3, 2];
  5039. var sar_h_table = [1, 11, 11, 11, 33, 11, 11, 11, 33, 11, 11, 33, 99, 3, 2, 1];
  5040. if (aspect_ratio_idc > 0 && aspect_ratio_idc < 16) {
  5041. sar_width = sar_w_table[aspect_ratio_idc - 1];
  5042. sar_height = sar_h_table[aspect_ratio_idc - 1];
  5043. }
  5044. else if (aspect_ratio_idc === 255) {
  5045. sar_width = gb.readByte() << 8 | gb.readByte();
  5046. sar_height = gb.readByte() << 8 | gb.readByte();
  5047. }
  5048. }
  5049. if (gb.readBool()) { // overscan_info_present_flag
  5050. gb.readBool(); // overscan_appropriate_flag
  5051. }
  5052. if (gb.readBool()) { // video_signal_type_present_flag
  5053. gb.readBits(4); // video_format & video_full_range_flag
  5054. if (gb.readBool()) { // colour_description_present_flag
  5055. gb.readBits(24); // colour_primaries & transfer_characteristics & matrix_coefficients
  5056. }
  5057. }
  5058. if (gb.readBool()) { // chroma_loc_info_present_flag
  5059. gb.readUEG(); // chroma_sample_loc_type_top_field
  5060. gb.readUEG(); // chroma_sample_loc_type_bottom_field
  5061. }
  5062. if (gb.readBool()) { // timing_info_present_flag
  5063. var num_units_in_tick = gb.readBits(32);
  5064. var time_scale = gb.readBits(32);
  5065. fps_fixed = gb.readBool(); // fixed_frame_rate_flag
  5066. fps_num = time_scale;
  5067. fps_den = num_units_in_tick * 2;
  5068. fps = fps_num / fps_den;
  5069. }
  5070. }
  5071. var sarScale = 1;
  5072. if (sar_width !== 1 || sar_height !== 1) {
  5073. sarScale = sar_width / sar_height;
  5074. }
  5075. var crop_unit_x = 0, crop_unit_y = 0;
  5076. if (chroma_format_idc === 0) {
  5077. crop_unit_x = 1;
  5078. crop_unit_y = 2 - frame_mbs_only_flag;
  5079. }
  5080. else {
  5081. var sub_wc = (chroma_format_idc === 3) ? 1 : 2;
  5082. var sub_hc = (chroma_format_idc === 1) ? 2 : 1;
  5083. crop_unit_x = sub_wc;
  5084. crop_unit_y = sub_hc * (2 - frame_mbs_only_flag);
  5085. }
  5086. var codec_width = (pic_width_in_mbs_minus1 + 1) * 16;
  5087. var codec_height = (2 - frame_mbs_only_flag) * ((pic_height_in_map_units_minus1 + 1) * 16);
  5088. codec_width -= (frame_crop_left_offset + frame_crop_right_offset) * crop_unit_x;
  5089. codec_height -= (frame_crop_top_offset + frame_crop_bottom_offset) * crop_unit_y;
  5090. var present_width = Math.ceil(codec_width * sarScale);
  5091. gb.destroy();
  5092. gb = null;
  5093. return {
  5094. profile_string: profile_string,
  5095. level_string: level_string,
  5096. bit_depth: bit_depth,
  5097. ref_frames: ref_frames,
  5098. chroma_format: chroma_format,
  5099. chroma_format_string: SPSParser.getChromaFormatString(chroma_format),
  5100. frame_rate: {
  5101. fixed: fps_fixed,
  5102. fps: fps,
  5103. fps_den: fps_den,
  5104. fps_num: fps_num
  5105. },
  5106. sar_ratio: {
  5107. width: sar_width,
  5108. height: sar_height
  5109. },
  5110. codec_size: {
  5111. width: codec_width,
  5112. height: codec_height
  5113. },
  5114. present_size: {
  5115. width: present_width,
  5116. height: codec_height
  5117. }
  5118. };
  5119. };
  5120. SPSParser._skipScalingList = function (gb, count) {
  5121. var last_scale = 8, next_scale = 8;
  5122. var delta_scale = 0;
  5123. for (var i = 0; i < count; i++) {
  5124. if (next_scale !== 0) {
  5125. delta_scale = gb.readSEG();
  5126. next_scale = (last_scale + delta_scale + 256) % 256;
  5127. }
  5128. last_scale = (next_scale === 0) ? last_scale : next_scale;
  5129. }
  5130. };
  5131. SPSParser.getProfileString = function (profile_idc) {
  5132. switch (profile_idc) {
  5133. case 66:
  5134. return 'Baseline';
  5135. case 77:
  5136. return 'Main';
  5137. case 88:
  5138. return 'Extended';
  5139. case 100:
  5140. return 'High';
  5141. case 110:
  5142. return 'High10';
  5143. case 122:
  5144. return 'High422';
  5145. case 244:
  5146. return 'High444';
  5147. default:
  5148. return 'Unknown';
  5149. }
  5150. };
  5151. SPSParser.getLevelString = function (level_idc) {
  5152. return (level_idc / 10).toFixed(1);
  5153. };
  5154. SPSParser.getChromaFormatString = function (chroma) {
  5155. switch (chroma) {
  5156. case 420:
  5157. return '4:2:0';
  5158. case 422:
  5159. return '4:2:2';
  5160. case 444:
  5161. return '4:4:4';
  5162. default:
  5163. return 'Unknown';
  5164. }
  5165. };
  5166. return SPSParser;
  5167. }());
  5168. /* harmony default export */ __webpack_exports__["default"] = (SPSParser);
  5169. /***/ }),
  5170. /***/ "./src/flv.js":
  5171. /*!********************!*\
  5172. !*** ./src/flv.js ***!
  5173. \********************/
  5174. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  5175. "use strict";
  5176. __webpack_require__.r(__webpack_exports__);
  5177. /* harmony import */ var _utils_polyfill_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils/polyfill.js */ "./src/utils/polyfill.js");
  5178. /* harmony import */ var _core_features_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./core/features.js */ "./src/core/features.js");
  5179. /* harmony import */ var _io_loader_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./io/loader.js */ "./src/io/loader.js");
  5180. /* harmony import */ var _player_flv_player_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./player/flv-player.js */ "./src/player/flv-player.js");
  5181. /* harmony import */ var _player_native_player_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./player/native-player.js */ "./src/player/native-player.js");
  5182. /* harmony import */ var _player_player_events_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./player/player-events.js */ "./src/player/player-events.js");
  5183. /* harmony import */ var _player_player_errors_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./player/player-errors.js */ "./src/player/player-errors.js");
  5184. /* harmony import */ var _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./utils/logging-control.js */ "./src/utils/logging-control.js");
  5185. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./utils/exception.js */ "./src/utils/exception.js");
  5186. /*
  5187. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  5188. *
  5189. * @author zheng qian <xqq@xqq.im>
  5190. *
  5191. * Licensed under the Apache License, Version 2.0 (the "License");
  5192. * you may not use this file except in compliance with the License.
  5193. * You may obtain a copy of the License at
  5194. *
  5195. * http://www.apache.org/licenses/LICENSE-2.0
  5196. *
  5197. * Unless required by applicable law or agreed to in writing, software
  5198. * distributed under the License is distributed on an "AS IS" BASIS,
  5199. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5200. * See the License for the specific language governing permissions and
  5201. * limitations under the License.
  5202. */
  5203. // here are all the interfaces
  5204. // install polyfills
  5205. _utils_polyfill_js__WEBPACK_IMPORTED_MODULE_0__.default.install();
  5206. // factory method
  5207. function createPlayer(mediaDataSource, optionalConfig) {
  5208. var mds = mediaDataSource;
  5209. if (mds == null || typeof mds !== 'object') {
  5210. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_8__.InvalidArgumentException('MediaDataSource must be an javascript object!');
  5211. }
  5212. if (!mds.hasOwnProperty('type')) {
  5213. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_8__.InvalidArgumentException('MediaDataSource must has type field to indicate video file type!');
  5214. }
  5215. switch (mds.type) {
  5216. case 'flv':
  5217. return new _player_flv_player_js__WEBPACK_IMPORTED_MODULE_3__.default(mds, optionalConfig);
  5218. default:
  5219. return new _player_native_player_js__WEBPACK_IMPORTED_MODULE_4__.default(mds, optionalConfig);
  5220. }
  5221. }
  5222. // feature detection
  5223. function isSupported() {
  5224. return _core_features_js__WEBPACK_IMPORTED_MODULE_1__.default.supportMSEH264Playback();
  5225. }
  5226. function getFeatureList() {
  5227. return _core_features_js__WEBPACK_IMPORTED_MODULE_1__.default.getFeatureList();
  5228. }
  5229. // interfaces
  5230. var flvjs = {};
  5231. flvjs.createPlayer = createPlayer;
  5232. flvjs.isSupported = isSupported;
  5233. flvjs.getFeatureList = getFeatureList;
  5234. flvjs.BaseLoader = _io_loader_js__WEBPACK_IMPORTED_MODULE_2__.BaseLoader;
  5235. flvjs.LoaderStatus = _io_loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderStatus;
  5236. flvjs.LoaderErrors = _io_loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors;
  5237. flvjs.Events = _player_player_events_js__WEBPACK_IMPORTED_MODULE_5__.default;
  5238. flvjs.ErrorTypes = _player_player_errors_js__WEBPACK_IMPORTED_MODULE_6__.ErrorTypes;
  5239. flvjs.ErrorDetails = _player_player_errors_js__WEBPACK_IMPORTED_MODULE_6__.ErrorDetails;
  5240. flvjs.FlvPlayer = _player_flv_player_js__WEBPACK_IMPORTED_MODULE_3__.default;
  5241. flvjs.NativePlayer = _player_native_player_js__WEBPACK_IMPORTED_MODULE_4__.default;
  5242. flvjs.LoggingControl = _utils_logging_control_js__WEBPACK_IMPORTED_MODULE_7__.default;
  5243. Object.defineProperty(flvjs, 'version', {
  5244. enumerable: true,
  5245. get: function () {
  5246. // replace by webpack.DefinePlugin
  5247. return "1.6.2";
  5248. }
  5249. });
  5250. /* harmony default export */ __webpack_exports__["default"] = (flvjs);
  5251. /***/ }),
  5252. /***/ "./src/index.js":
  5253. /*!**********************!*\
  5254. !*** ./src/index.js ***!
  5255. \**********************/
  5256. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  5257. // entry/index file
  5258. // make it compatible with browserify's umd wrapper
  5259. module.exports = __webpack_require__(/*! ./flv.js */ "./src/flv.js").default;
  5260. /***/ }),
  5261. /***/ "./src/io/fetch-stream-loader.js":
  5262. /*!***************************************!*\
  5263. !*** ./src/io/fetch-stream-loader.js ***!
  5264. \***************************************/
  5265. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  5266. "use strict";
  5267. __webpack_require__.r(__webpack_exports__);
  5268. /* harmony import */ var _utils_browser_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/browser.js */ "./src/utils/browser.js");
  5269. /* harmony import */ var _loader_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./loader.js */ "./src/io/loader.js");
  5270. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  5271. /*
  5272. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  5273. *
  5274. * @author zheng qian <xqq@xqq.im>
  5275. *
  5276. * Licensed under the Apache License, Version 2.0 (the "License");
  5277. * you may not use this file except in compliance with the License.
  5278. * You may obtain a copy of the License at
  5279. *
  5280. * http://www.apache.org/licenses/LICENSE-2.0
  5281. *
  5282. * Unless required by applicable law or agreed to in writing, software
  5283. * distributed under the License is distributed on an "AS IS" BASIS,
  5284. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5285. * See the License for the specific language governing permissions and
  5286. * limitations under the License.
  5287. */
  5288. var __extends = (undefined && undefined.__extends) || (function () {
  5289. var extendStatics = function (d, b) {
  5290. extendStatics = Object.setPrototypeOf ||
  5291. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5292. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  5293. return extendStatics(d, b);
  5294. };
  5295. return function (d, b) {
  5296. if (typeof b !== "function" && b !== null)
  5297. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  5298. extendStatics(d, b);
  5299. function __() { this.constructor = d; }
  5300. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5301. };
  5302. })();
  5303. /* fetch + stream IO loader. Currently working on chrome 43+.
  5304. * fetch provides a better alternative http API to XMLHttpRequest
  5305. *
  5306. * fetch spec https://fetch.spec.whatwg.org/
  5307. * stream spec https://streams.spec.whatwg.org/
  5308. */
  5309. var FetchStreamLoader = /** @class */ (function (_super) {
  5310. __extends(FetchStreamLoader, _super);
  5311. function FetchStreamLoader(seekHandler, config) {
  5312. var _this = _super.call(this, 'fetch-stream-loader') || this;
  5313. _this.TAG = 'FetchStreamLoader';
  5314. _this._seekHandler = seekHandler;
  5315. _this._config = config;
  5316. _this._needStash = true;
  5317. _this._requestAbort = false;
  5318. _this._contentLength = null;
  5319. _this._receivedLength = 0;
  5320. return _this;
  5321. }
  5322. FetchStreamLoader.isSupported = function () {
  5323. try {
  5324. // fetch + stream is broken on Microsoft Edge. Disable before build 15048.
  5325. // see https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8196907/
  5326. // Fixed in Jan 10, 2017. Build 15048+ removed from blacklist.
  5327. var isWorkWellEdge = _utils_browser_js__WEBPACK_IMPORTED_MODULE_0__.default.msedge && _utils_browser_js__WEBPACK_IMPORTED_MODULE_0__.default.version.minor >= 15048;
  5328. var browserNotBlacklisted = _utils_browser_js__WEBPACK_IMPORTED_MODULE_0__.default.msedge ? isWorkWellEdge : true;
  5329. return (self.fetch && self.ReadableStream && browserNotBlacklisted);
  5330. }
  5331. catch (e) {
  5332. return false;
  5333. }
  5334. };
  5335. FetchStreamLoader.prototype.destroy = function () {
  5336. if (this.isWorking()) {
  5337. this.abort();
  5338. }
  5339. _super.prototype.destroy.call(this);
  5340. };
  5341. FetchStreamLoader.prototype.open = function (dataSource, range) {
  5342. var _this = this;
  5343. this._dataSource = dataSource;
  5344. this._range = range;
  5345. var sourceURL = dataSource.url;
  5346. if (this._config.reuseRedirectedURL && dataSource.redirectedURL != undefined) {
  5347. sourceURL = dataSource.redirectedURL;
  5348. }
  5349. var seekConfig = this._seekHandler.getConfig(sourceURL, range);
  5350. var headers = new self.Headers();
  5351. if (typeof seekConfig.headers === 'object') {
  5352. var configHeaders = seekConfig.headers;
  5353. for (var key in configHeaders) {
  5354. if (configHeaders.hasOwnProperty(key)) {
  5355. headers.append(key, configHeaders[key]);
  5356. }
  5357. }
  5358. }
  5359. var params = {
  5360. method: 'GET',
  5361. headers: headers,
  5362. mode: 'cors',
  5363. cache: 'default',
  5364. // The default policy of Fetch API in the whatwg standard
  5365. // Safari incorrectly indicates 'no-referrer' as default policy, fuck it
  5366. referrerPolicy: 'no-referrer-when-downgrade'
  5367. };
  5368. // add additional headers
  5369. if (typeof this._config.headers === 'object') {
  5370. for (var key in this._config.headers) {
  5371. headers.append(key, this._config.headers[key]);
  5372. }
  5373. }
  5374. // cors is enabled by default
  5375. if (dataSource.cors === false) {
  5376. // no-cors means 'disregard cors policy', which can only be used in ServiceWorker
  5377. params.mode = 'same-origin';
  5378. }
  5379. // withCredentials is disabled by default
  5380. if (dataSource.withCredentials) {
  5381. params.credentials = 'include';
  5382. }
  5383. // referrerPolicy from config
  5384. if (dataSource.referrerPolicy) {
  5385. params.referrerPolicy = dataSource.referrerPolicy;
  5386. }
  5387. // add abort controller, by wmlgl 2019-5-10 12:21:27
  5388. if (self.AbortController) {
  5389. this._abortController = new self.AbortController();
  5390. params.signal = this._abortController.signal;
  5391. }
  5392. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kConnecting;
  5393. self.fetch(seekConfig.url, params).then(function (res) {
  5394. if (_this._requestAbort) {
  5395. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kIdle;
  5396. res.body.cancel();
  5397. return;
  5398. }
  5399. if (res.ok && (res.status >= 200 && res.status <= 299)) {
  5400. if (res.url !== seekConfig.url) {
  5401. if (_this._onURLRedirect) {
  5402. var redirectedURL = _this._seekHandler.removeURLParameters(res.url);
  5403. _this._onURLRedirect(redirectedURL);
  5404. }
  5405. }
  5406. var lengthHeader = res.headers.get('Content-Length');
  5407. if (lengthHeader != null) {
  5408. _this._contentLength = parseInt(lengthHeader);
  5409. if (_this._contentLength !== 0) {
  5410. if (_this._onContentLengthKnown) {
  5411. _this._onContentLengthKnown(_this._contentLength);
  5412. }
  5413. }
  5414. }
  5415. return _this._pump.call(_this, res.body.getReader());
  5416. }
  5417. else {
  5418. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kError;
  5419. if (_this._onError) {
  5420. _this._onError(_loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderErrors.HTTP_STATUS_CODE_INVALID, { code: res.status, msg: res.statusText });
  5421. }
  5422. else {
  5423. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.RuntimeException('FetchStreamLoader: Http code invalid, ' + res.status + ' ' + res.statusText);
  5424. }
  5425. }
  5426. }).catch(function (e) {
  5427. if (_this._abortController && _this._abortController.signal.aborted) {
  5428. return;
  5429. }
  5430. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kError;
  5431. if (_this._onError) {
  5432. _this._onError(_loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderErrors.EXCEPTION, { code: -1, msg: e.message });
  5433. }
  5434. else {
  5435. throw e;
  5436. }
  5437. });
  5438. };
  5439. FetchStreamLoader.prototype.abort = function () {
  5440. this._requestAbort = true;
  5441. if (this._status !== _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kBuffering || !_utils_browser_js__WEBPACK_IMPORTED_MODULE_0__.default.chrome) {
  5442. // Chrome may throw Exception-like things here, avoid using if is buffering
  5443. if (this._abortController) {
  5444. try {
  5445. this._abortController.abort();
  5446. }
  5447. catch (e) { }
  5448. }
  5449. }
  5450. };
  5451. FetchStreamLoader.prototype._pump = function (reader) {
  5452. var _this = this;
  5453. return reader.read().then(function (result) {
  5454. if (result.done) {
  5455. // First check received length
  5456. if (_this._contentLength !== null && _this._receivedLength < _this._contentLength) {
  5457. // Report Early-EOF
  5458. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kError;
  5459. var type = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderErrors.EARLY_EOF;
  5460. var info = { code: -1, msg: 'Fetch stream meet Early-EOF' };
  5461. if (_this._onError) {
  5462. _this._onError(type, info);
  5463. }
  5464. else {
  5465. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.RuntimeException(info.msg);
  5466. }
  5467. }
  5468. else {
  5469. // OK. Download complete
  5470. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kComplete;
  5471. if (_this._onComplete) {
  5472. _this._onComplete(_this._range.from, _this._range.from + _this._receivedLength - 1);
  5473. }
  5474. }
  5475. }
  5476. else {
  5477. if (_this._abortController && _this._abortController.signal.aborted) {
  5478. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kComplete;
  5479. return;
  5480. }
  5481. else if (_this._requestAbort === true) {
  5482. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kComplete;
  5483. return reader.cancel();
  5484. }
  5485. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kBuffering;
  5486. var chunk = result.value.buffer;
  5487. var byteStart = _this._range.from + _this._receivedLength;
  5488. _this._receivedLength += chunk.byteLength;
  5489. if (_this._onDataArrival) {
  5490. _this._onDataArrival(chunk, byteStart, _this._receivedLength);
  5491. }
  5492. _this._pump(reader);
  5493. }
  5494. }).catch(function (e) {
  5495. if (_this._abortController && _this._abortController.signal.aborted) {
  5496. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kComplete;
  5497. return;
  5498. }
  5499. if (e.code === 11 && _utils_browser_js__WEBPACK_IMPORTED_MODULE_0__.default.msedge) { // InvalidStateError on Microsoft Edge
  5500. // Workaround: Edge may throw InvalidStateError after ReadableStreamReader.cancel() call
  5501. // Ignore the unknown exception.
  5502. // Related issue: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/11265202/
  5503. return;
  5504. }
  5505. _this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kError;
  5506. var type = 0;
  5507. var info = null;
  5508. if ((e.code === 19 || e.message === 'network error') && // NETWORK_ERR
  5509. (_this._contentLength === null ||
  5510. (_this._contentLength !== null && _this._receivedLength < _this._contentLength))) {
  5511. type = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderErrors.EARLY_EOF;
  5512. info = { code: e.code, msg: 'Fetch stream meet Early-EOF' };
  5513. }
  5514. else {
  5515. type = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderErrors.EXCEPTION;
  5516. info = { code: e.code, msg: e.message };
  5517. }
  5518. if (_this._onError) {
  5519. _this._onError(type, info);
  5520. }
  5521. else {
  5522. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.RuntimeException(info.msg);
  5523. }
  5524. });
  5525. };
  5526. return FetchStreamLoader;
  5527. }(_loader_js__WEBPACK_IMPORTED_MODULE_1__.BaseLoader));
  5528. /* harmony default export */ __webpack_exports__["default"] = (FetchStreamLoader);
  5529. /***/ }),
  5530. /***/ "./src/io/io-controller.js":
  5531. /*!*********************************!*\
  5532. !*** ./src/io/io-controller.js ***!
  5533. \*********************************/
  5534. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  5535. "use strict";
  5536. __webpack_require__.r(__webpack_exports__);
  5537. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  5538. /* harmony import */ var _speed_sampler_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./speed-sampler.js */ "./src/io/speed-sampler.js");
  5539. /* harmony import */ var _loader_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./loader.js */ "./src/io/loader.js");
  5540. /* harmony import */ var _fetch_stream_loader_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./fetch-stream-loader.js */ "./src/io/fetch-stream-loader.js");
  5541. /* harmony import */ var _xhr_moz_chunked_loader_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./xhr-moz-chunked-loader.js */ "./src/io/xhr-moz-chunked-loader.js");
  5542. /* harmony import */ var _xhr_range_loader_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./xhr-range-loader.js */ "./src/io/xhr-range-loader.js");
  5543. /* harmony import */ var _websocket_loader_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./websocket-loader.js */ "./src/io/websocket-loader.js");
  5544. /* harmony import */ var _range_seek_handler_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./range-seek-handler.js */ "./src/io/range-seek-handler.js");
  5545. /* harmony import */ var _param_seek_handler_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./param-seek-handler.js */ "./src/io/param-seek-handler.js");
  5546. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  5547. /*
  5548. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  5549. *
  5550. * @author zheng qian <xqq@xqq.im>
  5551. *
  5552. * Licensed under the Apache License, Version 2.0 (the "License");
  5553. * you may not use this file except in compliance with the License.
  5554. * You may obtain a copy of the License at
  5555. *
  5556. * http://www.apache.org/licenses/LICENSE-2.0
  5557. *
  5558. * Unless required by applicable law or agreed to in writing, software
  5559. * distributed under the License is distributed on an "AS IS" BASIS,
  5560. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5561. * See the License for the specific language governing permissions and
  5562. * limitations under the License.
  5563. */
  5564. /**
  5565. * DataSource: {
  5566. * url: string,
  5567. * filesize: number,
  5568. * cors: boolean,
  5569. * withCredentials: boolean
  5570. * }
  5571. *
  5572. */
  5573. // Manage IO Loaders
  5574. var IOController = /** @class */ (function () {
  5575. function IOController(dataSource, config, extraData) {
  5576. this.TAG = 'IOController';
  5577. this._config = config;
  5578. this._extraData = extraData;
  5579. this._stashInitialSize = 1024 * 384; // default initial size: 384KB
  5580. if (config.stashInitialSize != undefined && config.stashInitialSize > 0) {
  5581. // apply from config
  5582. this._stashInitialSize = config.stashInitialSize;
  5583. }
  5584. this._stashUsed = 0;
  5585. this._stashSize = this._stashInitialSize;
  5586. this._bufferSize = 1024 * 1024 * 3; // initial size: 3MB
  5587. this._stashBuffer = new ArrayBuffer(this._bufferSize);
  5588. this._stashByteStart = 0;
  5589. this._enableStash = true;
  5590. if (config.enableStashBuffer === false) {
  5591. this._enableStash = false;
  5592. }
  5593. this._loader = null;
  5594. this._loaderClass = null;
  5595. this._seekHandler = null;
  5596. this._dataSource = dataSource;
  5597. this._isWebSocketURL = /wss?:\/\/(.+?)/.test(dataSource.url);
  5598. this._refTotalLength = dataSource.filesize ? dataSource.filesize : null;
  5599. this._totalLength = this._refTotalLength;
  5600. this._fullRequestFlag = false;
  5601. this._currentRange = null;
  5602. this._redirectedURL = null;
  5603. this._speedNormalized = 0;
  5604. this._speedSampler = new _speed_sampler_js__WEBPACK_IMPORTED_MODULE_1__.default();
  5605. this._speedNormalizeList = [64, 128, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096];
  5606. this._isEarlyEofReconnecting = false;
  5607. this._paused = false;
  5608. this._resumeFrom = 0;
  5609. this._onDataArrival = null;
  5610. this._onSeeked = null;
  5611. this._onError = null;
  5612. this._onComplete = null;
  5613. this._onRedirect = null;
  5614. this._onRecoveredEarlyEof = null;
  5615. this._selectSeekHandler();
  5616. this._selectLoader();
  5617. this._createLoader();
  5618. }
  5619. IOController.prototype.destroy = function () {
  5620. if (this._loader.isWorking()) {
  5621. this._loader.abort();
  5622. }
  5623. this._loader.destroy();
  5624. this._loader = null;
  5625. this._loaderClass = null;
  5626. this._dataSource = null;
  5627. this._stashBuffer = null;
  5628. this._stashUsed = this._stashSize = this._bufferSize = this._stashByteStart = 0;
  5629. this._currentRange = null;
  5630. this._speedSampler = null;
  5631. this._isEarlyEofReconnecting = false;
  5632. this._onDataArrival = null;
  5633. this._onSeeked = null;
  5634. this._onError = null;
  5635. this._onComplete = null;
  5636. this._onRedirect = null;
  5637. this._onRecoveredEarlyEof = null;
  5638. this._extraData = null;
  5639. };
  5640. IOController.prototype.isWorking = function () {
  5641. return this._loader && this._loader.isWorking() && !this._paused;
  5642. };
  5643. IOController.prototype.isPaused = function () {
  5644. return this._paused;
  5645. };
  5646. Object.defineProperty(IOController.prototype, "status", {
  5647. get: function () {
  5648. return this._loader.status;
  5649. },
  5650. enumerable: false,
  5651. configurable: true
  5652. });
  5653. Object.defineProperty(IOController.prototype, "extraData", {
  5654. get: function () {
  5655. return this._extraData;
  5656. },
  5657. set: function (data) {
  5658. this._extraData = data;
  5659. },
  5660. enumerable: false,
  5661. configurable: true
  5662. });
  5663. Object.defineProperty(IOController.prototype, "onDataArrival", {
  5664. // prototype: function onDataArrival(chunks: ArrayBuffer, byteStart: number): number
  5665. get: function () {
  5666. return this._onDataArrival;
  5667. },
  5668. set: function (callback) {
  5669. this._onDataArrival = callback;
  5670. },
  5671. enumerable: false,
  5672. configurable: true
  5673. });
  5674. Object.defineProperty(IOController.prototype, "onSeeked", {
  5675. get: function () {
  5676. return this._onSeeked;
  5677. },
  5678. set: function (callback) {
  5679. this._onSeeked = callback;
  5680. },
  5681. enumerable: false,
  5682. configurable: true
  5683. });
  5684. Object.defineProperty(IOController.prototype, "onError", {
  5685. // prototype: function onError(type: number, info: {code: number, msg: string}): void
  5686. get: function () {
  5687. return this._onError;
  5688. },
  5689. set: function (callback) {
  5690. this._onError = callback;
  5691. },
  5692. enumerable: false,
  5693. configurable: true
  5694. });
  5695. Object.defineProperty(IOController.prototype, "onComplete", {
  5696. get: function () {
  5697. return this._onComplete;
  5698. },
  5699. set: function (callback) {
  5700. this._onComplete = callback;
  5701. },
  5702. enumerable: false,
  5703. configurable: true
  5704. });
  5705. Object.defineProperty(IOController.prototype, "onRedirect", {
  5706. get: function () {
  5707. return this._onRedirect;
  5708. },
  5709. set: function (callback) {
  5710. this._onRedirect = callback;
  5711. },
  5712. enumerable: false,
  5713. configurable: true
  5714. });
  5715. Object.defineProperty(IOController.prototype, "onRecoveredEarlyEof", {
  5716. get: function () {
  5717. return this._onRecoveredEarlyEof;
  5718. },
  5719. set: function (callback) {
  5720. this._onRecoveredEarlyEof = callback;
  5721. },
  5722. enumerable: false,
  5723. configurable: true
  5724. });
  5725. Object.defineProperty(IOController.prototype, "currentURL", {
  5726. get: function () {
  5727. return this._dataSource.url;
  5728. },
  5729. enumerable: false,
  5730. configurable: true
  5731. });
  5732. Object.defineProperty(IOController.prototype, "hasRedirect", {
  5733. get: function () {
  5734. return (this._redirectedURL != null || this._dataSource.redirectedURL != undefined);
  5735. },
  5736. enumerable: false,
  5737. configurable: true
  5738. });
  5739. Object.defineProperty(IOController.prototype, "currentRedirectedURL", {
  5740. get: function () {
  5741. return this._redirectedURL || this._dataSource.redirectedURL;
  5742. },
  5743. enumerable: false,
  5744. configurable: true
  5745. });
  5746. Object.defineProperty(IOController.prototype, "currentSpeed", {
  5747. // in KB/s
  5748. get: function () {
  5749. if (this._loaderClass === _xhr_range_loader_js__WEBPACK_IMPORTED_MODULE_5__.default) {
  5750. // SpeedSampler is inaccuracy if loader is RangeLoader
  5751. return this._loader.currentSpeed;
  5752. }
  5753. return this._speedSampler.lastSecondKBps;
  5754. },
  5755. enumerable: false,
  5756. configurable: true
  5757. });
  5758. Object.defineProperty(IOController.prototype, "loaderType", {
  5759. get: function () {
  5760. return this._loader.type;
  5761. },
  5762. enumerable: false,
  5763. configurable: true
  5764. });
  5765. IOController.prototype._selectSeekHandler = function () {
  5766. var config = this._config;
  5767. if (config.seekType === 'range') {
  5768. this._seekHandler = new _range_seek_handler_js__WEBPACK_IMPORTED_MODULE_7__.default(this._config.rangeLoadZeroStart);
  5769. }
  5770. else if (config.seekType === 'param') {
  5771. var paramStart = config.seekParamStart || 'bstart';
  5772. var paramEnd = config.seekParamEnd || 'bend';
  5773. this._seekHandler = new _param_seek_handler_js__WEBPACK_IMPORTED_MODULE_8__.default(paramStart, paramEnd);
  5774. }
  5775. else if (config.seekType === 'custom') {
  5776. if (typeof config.customSeekHandler !== 'function') {
  5777. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_9__.InvalidArgumentException('Custom seekType specified in config but invalid customSeekHandler!');
  5778. }
  5779. this._seekHandler = new config.customSeekHandler();
  5780. }
  5781. else {
  5782. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_9__.InvalidArgumentException("Invalid seekType in config: " + config.seekType);
  5783. }
  5784. };
  5785. IOController.prototype._selectLoader = function () {
  5786. if (this._config.customLoader != null) {
  5787. this._loaderClass = this._config.customLoader;
  5788. }
  5789. else if (this._isWebSocketURL) {
  5790. this._loaderClass = _websocket_loader_js__WEBPACK_IMPORTED_MODULE_6__.default;
  5791. }
  5792. else if (_fetch_stream_loader_js__WEBPACK_IMPORTED_MODULE_3__.default.isSupported()) {
  5793. this._loaderClass = _fetch_stream_loader_js__WEBPACK_IMPORTED_MODULE_3__.default;
  5794. }
  5795. else if (_xhr_moz_chunked_loader_js__WEBPACK_IMPORTED_MODULE_4__.default.isSupported()) {
  5796. this._loaderClass = _xhr_moz_chunked_loader_js__WEBPACK_IMPORTED_MODULE_4__.default;
  5797. }
  5798. else if (_xhr_range_loader_js__WEBPACK_IMPORTED_MODULE_5__.default.isSupported()) {
  5799. this._loaderClass = _xhr_range_loader_js__WEBPACK_IMPORTED_MODULE_5__.default;
  5800. }
  5801. else {
  5802. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_9__.RuntimeException('Your browser doesn\'t support xhr with arraybuffer responseType!');
  5803. }
  5804. };
  5805. IOController.prototype._createLoader = function () {
  5806. this._loader = new this._loaderClass(this._seekHandler, this._config);
  5807. if (this._loader.needStashBuffer === false) {
  5808. this._enableStash = false;
  5809. }
  5810. this._loader.onContentLengthKnown = this._onContentLengthKnown.bind(this);
  5811. this._loader.onURLRedirect = this._onURLRedirect.bind(this);
  5812. this._loader.onDataArrival = this._onLoaderChunkArrival.bind(this);
  5813. this._loader.onComplete = this._onLoaderComplete.bind(this);
  5814. this._loader.onError = this._onLoaderError.bind(this);
  5815. };
  5816. IOController.prototype.open = function (optionalFrom) {
  5817. this._currentRange = { from: 0, to: -1 };
  5818. if (optionalFrom) {
  5819. this._currentRange.from = optionalFrom;
  5820. }
  5821. this._speedSampler.reset();
  5822. if (!optionalFrom) {
  5823. this._fullRequestFlag = true;
  5824. }
  5825. this._loader.open(this._dataSource, Object.assign({}, this._currentRange));
  5826. };
  5827. IOController.prototype.abort = function () {
  5828. this._loader.abort();
  5829. if (this._paused) {
  5830. this._paused = false;
  5831. this._resumeFrom = 0;
  5832. }
  5833. };
  5834. IOController.prototype.pause = function () {
  5835. if (this.isWorking()) {
  5836. this._loader.abort();
  5837. if (this._stashUsed !== 0) {
  5838. this._resumeFrom = this._stashByteStart;
  5839. this._currentRange.to = this._stashByteStart - 1;
  5840. }
  5841. else {
  5842. this._resumeFrom = this._currentRange.to + 1;
  5843. }
  5844. this._stashUsed = 0;
  5845. this._stashByteStart = 0;
  5846. this._paused = true;
  5847. }
  5848. };
  5849. IOController.prototype.resume = function () {
  5850. if (this._paused) {
  5851. this._paused = false;
  5852. var bytes = this._resumeFrom;
  5853. this._resumeFrom = 0;
  5854. this._internalSeek(bytes, true);
  5855. }
  5856. };
  5857. IOController.prototype.seek = function (bytes) {
  5858. this._paused = false;
  5859. this._stashUsed = 0;
  5860. this._stashByteStart = 0;
  5861. this._internalSeek(bytes, true);
  5862. };
  5863. /**
  5864. * When seeking request is from media seeking, unconsumed stash data should be dropped
  5865. * However, stash data shouldn't be dropped if seeking requested from http reconnection
  5866. *
  5867. * @dropUnconsumed: Ignore and discard all unconsumed data in stash buffer
  5868. */
  5869. IOController.prototype._internalSeek = function (bytes, dropUnconsumed) {
  5870. if (this._loader.isWorking()) {
  5871. this._loader.abort();
  5872. }
  5873. // dispatch & flush stash buffer before seek
  5874. this._flushStashBuffer(dropUnconsumed);
  5875. this._loader.destroy();
  5876. this._loader = null;
  5877. var requestRange = { from: bytes, to: -1 };
  5878. this._currentRange = { from: requestRange.from, to: -1 };
  5879. this._speedSampler.reset();
  5880. this._stashSize = this._stashInitialSize;
  5881. this._createLoader();
  5882. this._loader.open(this._dataSource, requestRange);
  5883. if (this._onSeeked) {
  5884. this._onSeeked();
  5885. }
  5886. };
  5887. IOController.prototype.updateUrl = function (url) {
  5888. if (!url || typeof url !== 'string' || url.length === 0) {
  5889. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_9__.InvalidArgumentException('Url must be a non-empty string!');
  5890. }
  5891. this._dataSource.url = url;
  5892. // TODO: replace with new url
  5893. };
  5894. IOController.prototype._expandBuffer = function (expectedBytes) {
  5895. var bufferNewSize = this._stashSize;
  5896. while (bufferNewSize + 1024 * 1024 * 1 < expectedBytes) {
  5897. bufferNewSize *= 2;
  5898. }
  5899. bufferNewSize += 1024 * 1024 * 1; // bufferSize = stashSize + 1MB
  5900. if (bufferNewSize === this._bufferSize) {
  5901. return;
  5902. }
  5903. var newBuffer = new ArrayBuffer(bufferNewSize);
  5904. if (this._stashUsed > 0) { // copy existing data into new buffer
  5905. var stashOldArray = new Uint8Array(this._stashBuffer, 0, this._stashUsed);
  5906. var stashNewArray = new Uint8Array(newBuffer, 0, bufferNewSize);
  5907. stashNewArray.set(stashOldArray, 0);
  5908. }
  5909. this._stashBuffer = newBuffer;
  5910. this._bufferSize = bufferNewSize;
  5911. };
  5912. IOController.prototype._normalizeSpeed = function (input) {
  5913. var list = this._speedNormalizeList;
  5914. var last = list.length - 1;
  5915. var mid = 0;
  5916. var lbound = 0;
  5917. var ubound = last;
  5918. if (input < list[0]) {
  5919. return list[0];
  5920. }
  5921. // binary search
  5922. while (lbound <= ubound) {
  5923. mid = lbound + Math.floor((ubound - lbound) / 2);
  5924. if (mid === last || (input >= list[mid] && input < list[mid + 1])) {
  5925. return list[mid];
  5926. }
  5927. else if (list[mid] < input) {
  5928. lbound = mid + 1;
  5929. }
  5930. else {
  5931. ubound = mid - 1;
  5932. }
  5933. }
  5934. };
  5935. IOController.prototype._adjustStashSize = function (normalized) {
  5936. var stashSizeKB = 0;
  5937. if (this._config.isLive) {
  5938. // live stream: always use single normalized speed for size of stashSizeKB
  5939. stashSizeKB = normalized;
  5940. }
  5941. else {
  5942. if (normalized < 512) {
  5943. stashSizeKB = normalized;
  5944. }
  5945. else if (normalized >= 512 && normalized <= 1024) {
  5946. stashSizeKB = Math.floor(normalized * 1.5);
  5947. }
  5948. else {
  5949. stashSizeKB = normalized * 2;
  5950. }
  5951. }
  5952. if (stashSizeKB > 8192) {
  5953. stashSizeKB = 8192;
  5954. }
  5955. var bufferSize = stashSizeKB * 1024 + 1024 * 1024 * 1; // stashSize + 1MB
  5956. if (this._bufferSize < bufferSize) {
  5957. this._expandBuffer(bufferSize);
  5958. }
  5959. this._stashSize = stashSizeKB * 1024;
  5960. };
  5961. IOController.prototype._dispatchChunks = function (chunks, byteStart) {
  5962. this._currentRange.to = byteStart + chunks.byteLength - 1;
  5963. return this._onDataArrival(chunks, byteStart);
  5964. };
  5965. IOController.prototype._onURLRedirect = function (redirectedURL) {
  5966. this._redirectedURL = redirectedURL;
  5967. if (this._onRedirect) {
  5968. this._onRedirect(redirectedURL);
  5969. }
  5970. };
  5971. IOController.prototype._onContentLengthKnown = function (contentLength) {
  5972. if (contentLength && this._fullRequestFlag) {
  5973. this._totalLength = contentLength;
  5974. this._fullRequestFlag = false;
  5975. }
  5976. };
  5977. IOController.prototype._onLoaderChunkArrival = function (chunk, byteStart, receivedLength) {
  5978. if (!this._onDataArrival) {
  5979. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_9__.IllegalStateException('IOController: No existing consumer (onDataArrival) callback!');
  5980. }
  5981. if (this._paused) {
  5982. return;
  5983. }
  5984. if (this._isEarlyEofReconnecting) {
  5985. // Auto-reconnect for EarlyEof succeed, notify to upper-layer by callback
  5986. this._isEarlyEofReconnecting = false;
  5987. if (this._onRecoveredEarlyEof) {
  5988. this._onRecoveredEarlyEof();
  5989. }
  5990. }
  5991. this._speedSampler.addBytes(chunk.byteLength);
  5992. // adjust stash buffer size according to network speed dynamically
  5993. var KBps = this._speedSampler.lastSecondKBps;
  5994. if (KBps !== 0) {
  5995. var normalized = this._normalizeSpeed(KBps);
  5996. if (this._speedNormalized !== normalized) {
  5997. this._speedNormalized = normalized;
  5998. this._adjustStashSize(normalized);
  5999. }
  6000. }
  6001. if (!this._enableStash) { // disable stash
  6002. if (this._stashUsed === 0) {
  6003. // dispatch chunk directly to consumer;
  6004. // check ret value (consumed bytes) and stash unconsumed to stashBuffer
  6005. var consumed = this._dispatchChunks(chunk, byteStart);
  6006. if (consumed < chunk.byteLength) { // unconsumed data remain.
  6007. var remain = chunk.byteLength - consumed;
  6008. if (remain > this._bufferSize) {
  6009. this._expandBuffer(remain);
  6010. }
  6011. var stashArray = new Uint8Array(this._stashBuffer, 0, this._bufferSize);
  6012. stashArray.set(new Uint8Array(chunk, consumed), 0);
  6013. this._stashUsed += remain;
  6014. this._stashByteStart = byteStart + consumed;
  6015. }
  6016. }
  6017. else {
  6018. // else: Merge chunk into stashBuffer, and dispatch stashBuffer to consumer.
  6019. if (this._stashUsed + chunk.byteLength > this._bufferSize) {
  6020. this._expandBuffer(this._stashUsed + chunk.byteLength);
  6021. }
  6022. var stashArray = new Uint8Array(this._stashBuffer, 0, this._bufferSize);
  6023. stashArray.set(new Uint8Array(chunk), this._stashUsed);
  6024. this._stashUsed += chunk.byteLength;
  6025. var consumed = this._dispatchChunks(this._stashBuffer.slice(0, this._stashUsed), this._stashByteStart);
  6026. if (consumed < this._stashUsed && consumed > 0) { // unconsumed data remain
  6027. var remainArray = new Uint8Array(this._stashBuffer, consumed);
  6028. stashArray.set(remainArray, 0);
  6029. }
  6030. this._stashUsed -= consumed;
  6031. this._stashByteStart += consumed;
  6032. }
  6033. }
  6034. else { // enable stash
  6035. if (this._stashUsed === 0 && this._stashByteStart === 0) { // seeked? or init chunk?
  6036. // This is the first chunk after seek action
  6037. this._stashByteStart = byteStart;
  6038. }
  6039. if (this._stashUsed + chunk.byteLength <= this._stashSize) {
  6040. // just stash
  6041. var stashArray = new Uint8Array(this._stashBuffer, 0, this._stashSize);
  6042. stashArray.set(new Uint8Array(chunk), this._stashUsed);
  6043. this._stashUsed += chunk.byteLength;
  6044. }
  6045. else { // stashUsed + chunkSize > stashSize, size limit exceeded
  6046. var stashArray = new Uint8Array(this._stashBuffer, 0, this._bufferSize);
  6047. if (this._stashUsed > 0) { // There're stash datas in buffer
  6048. // dispatch the whole stashBuffer, and stash remain data
  6049. // then append chunk to stashBuffer (stash)
  6050. var buffer = this._stashBuffer.slice(0, this._stashUsed);
  6051. var consumed = this._dispatchChunks(buffer, this._stashByteStart);
  6052. if (consumed < buffer.byteLength) {
  6053. if (consumed > 0) {
  6054. var remainArray = new Uint8Array(buffer, consumed);
  6055. stashArray.set(remainArray, 0);
  6056. this._stashUsed = remainArray.byteLength;
  6057. this._stashByteStart += consumed;
  6058. }
  6059. }
  6060. else {
  6061. this._stashUsed = 0;
  6062. this._stashByteStart += consumed;
  6063. }
  6064. if (this._stashUsed + chunk.byteLength > this._bufferSize) {
  6065. this._expandBuffer(this._stashUsed + chunk.byteLength);
  6066. stashArray = new Uint8Array(this._stashBuffer, 0, this._bufferSize);
  6067. }
  6068. stashArray.set(new Uint8Array(chunk), this._stashUsed);
  6069. this._stashUsed += chunk.byteLength;
  6070. }
  6071. else { // stash buffer empty, but chunkSize > stashSize (oh, holy shit)
  6072. // dispatch chunk directly and stash remain data
  6073. var consumed = this._dispatchChunks(chunk, byteStart);
  6074. if (consumed < chunk.byteLength) {
  6075. var remain = chunk.byteLength - consumed;
  6076. if (remain > this._bufferSize) {
  6077. this._expandBuffer(remain);
  6078. stashArray = new Uint8Array(this._stashBuffer, 0, this._bufferSize);
  6079. }
  6080. stashArray.set(new Uint8Array(chunk, consumed), 0);
  6081. this._stashUsed += remain;
  6082. this._stashByteStart = byteStart + consumed;
  6083. }
  6084. }
  6085. }
  6086. }
  6087. };
  6088. IOController.prototype._flushStashBuffer = function (dropUnconsumed) {
  6089. if (this._stashUsed > 0) {
  6090. var buffer = this._stashBuffer.slice(0, this._stashUsed);
  6091. var consumed = this._dispatchChunks(buffer, this._stashByteStart);
  6092. var remain = buffer.byteLength - consumed;
  6093. if (consumed < buffer.byteLength) {
  6094. if (dropUnconsumed) {
  6095. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, remain + " bytes unconsumed data remain when flush buffer, dropped");
  6096. }
  6097. else {
  6098. if (consumed > 0) {
  6099. var stashArray = new Uint8Array(this._stashBuffer, 0, this._bufferSize);
  6100. var remainArray = new Uint8Array(buffer, consumed);
  6101. stashArray.set(remainArray, 0);
  6102. this._stashUsed = remainArray.byteLength;
  6103. this._stashByteStart += consumed;
  6104. }
  6105. return 0;
  6106. }
  6107. }
  6108. this._stashUsed = 0;
  6109. this._stashByteStart = 0;
  6110. return remain;
  6111. }
  6112. return 0;
  6113. };
  6114. IOController.prototype._onLoaderComplete = function (from, to) {
  6115. // Force-flush stash buffer, and drop unconsumed data
  6116. this._flushStashBuffer(true);
  6117. if (this._onComplete) {
  6118. this._onComplete(this._extraData);
  6119. }
  6120. };
  6121. IOController.prototype._onLoaderError = function (type, data) {
  6122. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.e(this.TAG, "Loader error, code = " + data.code + ", msg = " + data.msg);
  6123. this._flushStashBuffer(false);
  6124. if (this._isEarlyEofReconnecting) {
  6125. // Auto-reconnect for EarlyEof failed, throw UnrecoverableEarlyEof error to upper-layer
  6126. this._isEarlyEofReconnecting = false;
  6127. type = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.UNRECOVERABLE_EARLY_EOF;
  6128. }
  6129. switch (type) {
  6130. case _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.EARLY_EOF: {
  6131. if (!this._config.isLive) {
  6132. // Do internal http reconnect if not live stream
  6133. if (this._totalLength) {
  6134. var nextFrom = this._currentRange.to + 1;
  6135. if (nextFrom < this._totalLength) {
  6136. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Connection lost, trying reconnect...');
  6137. this._isEarlyEofReconnecting = true;
  6138. this._internalSeek(nextFrom, false);
  6139. }
  6140. return;
  6141. }
  6142. // else: We don't know totalLength, throw UnrecoverableEarlyEof
  6143. }
  6144. // live stream: throw UnrecoverableEarlyEof error to upper-layer
  6145. type = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.UNRECOVERABLE_EARLY_EOF;
  6146. break;
  6147. }
  6148. case _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.UNRECOVERABLE_EARLY_EOF:
  6149. case _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.CONNECTING_TIMEOUT:
  6150. case _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.HTTP_STATUS_CODE_INVALID:
  6151. case _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.EXCEPTION:
  6152. break;
  6153. }
  6154. if (this._onError) {
  6155. this._onError(type, data);
  6156. }
  6157. else {
  6158. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_9__.RuntimeException('IOException: ' + data.msg);
  6159. }
  6160. };
  6161. return IOController;
  6162. }());
  6163. /* harmony default export */ __webpack_exports__["default"] = (IOController);
  6164. /***/ }),
  6165. /***/ "./src/io/loader.js":
  6166. /*!**************************!*\
  6167. !*** ./src/io/loader.js ***!
  6168. \**************************/
  6169. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  6170. "use strict";
  6171. __webpack_require__.r(__webpack_exports__);
  6172. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  6173. /* harmony export */ "LoaderStatus": function() { return /* binding */ LoaderStatus; },
  6174. /* harmony export */ "LoaderErrors": function() { return /* binding */ LoaderErrors; },
  6175. /* harmony export */ "BaseLoader": function() { return /* binding */ BaseLoader; }
  6176. /* harmony export */ });
  6177. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  6178. /*
  6179. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  6180. *
  6181. * @author zheng qian <xqq@xqq.im>
  6182. *
  6183. * Licensed under the Apache License, Version 2.0 (the "License");
  6184. * you may not use this file except in compliance with the License.
  6185. * You may obtain a copy of the License at
  6186. *
  6187. * http://www.apache.org/licenses/LICENSE-2.0
  6188. *
  6189. * Unless required by applicable law or agreed to in writing, software
  6190. * distributed under the License is distributed on an "AS IS" BASIS,
  6191. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6192. * See the License for the specific language governing permissions and
  6193. * limitations under the License.
  6194. */
  6195. var LoaderStatus = {
  6196. kIdle: 0,
  6197. kConnecting: 1,
  6198. kBuffering: 2,
  6199. kError: 3,
  6200. kComplete: 4
  6201. };
  6202. var LoaderErrors = {
  6203. OK: 'OK',
  6204. EXCEPTION: 'Exception',
  6205. HTTP_STATUS_CODE_INVALID: 'HttpStatusCodeInvalid',
  6206. CONNECTING_TIMEOUT: 'ConnectingTimeout',
  6207. EARLY_EOF: 'EarlyEof',
  6208. UNRECOVERABLE_EARLY_EOF: 'UnrecoverableEarlyEof'
  6209. };
  6210. /* Loader has callbacks which have following prototypes:
  6211. * function onContentLengthKnown(contentLength: number): void
  6212. * function onURLRedirect(url: string): void
  6213. * function onDataArrival(chunk: ArrayBuffer, byteStart: number, receivedLength: number): void
  6214. * function onError(errorType: number, errorInfo: {code: number, msg: string}): void
  6215. * function onComplete(rangeFrom: number, rangeTo: number): void
  6216. */
  6217. var BaseLoader = /** @class */ (function () {
  6218. function BaseLoader(typeName) {
  6219. this._type = typeName || 'undefined';
  6220. this._status = LoaderStatus.kIdle;
  6221. this._needStash = false;
  6222. // callbacks
  6223. this._onContentLengthKnown = null;
  6224. this._onURLRedirect = null;
  6225. this._onDataArrival = null;
  6226. this._onError = null;
  6227. this._onComplete = null;
  6228. }
  6229. BaseLoader.prototype.destroy = function () {
  6230. this._status = LoaderStatus.kIdle;
  6231. this._onContentLengthKnown = null;
  6232. this._onURLRedirect = null;
  6233. this._onDataArrival = null;
  6234. this._onError = null;
  6235. this._onComplete = null;
  6236. };
  6237. BaseLoader.prototype.isWorking = function () {
  6238. return this._status === LoaderStatus.kConnecting || this._status === LoaderStatus.kBuffering;
  6239. };
  6240. Object.defineProperty(BaseLoader.prototype, "type", {
  6241. get: function () {
  6242. return this._type;
  6243. },
  6244. enumerable: false,
  6245. configurable: true
  6246. });
  6247. Object.defineProperty(BaseLoader.prototype, "status", {
  6248. get: function () {
  6249. return this._status;
  6250. },
  6251. enumerable: false,
  6252. configurable: true
  6253. });
  6254. Object.defineProperty(BaseLoader.prototype, "needStashBuffer", {
  6255. get: function () {
  6256. return this._needStash;
  6257. },
  6258. enumerable: false,
  6259. configurable: true
  6260. });
  6261. Object.defineProperty(BaseLoader.prototype, "onContentLengthKnown", {
  6262. get: function () {
  6263. return this._onContentLengthKnown;
  6264. },
  6265. set: function (callback) {
  6266. this._onContentLengthKnown = callback;
  6267. },
  6268. enumerable: false,
  6269. configurable: true
  6270. });
  6271. Object.defineProperty(BaseLoader.prototype, "onURLRedirect", {
  6272. get: function () {
  6273. return this._onURLRedirect;
  6274. },
  6275. set: function (callback) {
  6276. this._onURLRedirect = callback;
  6277. },
  6278. enumerable: false,
  6279. configurable: true
  6280. });
  6281. Object.defineProperty(BaseLoader.prototype, "onDataArrival", {
  6282. get: function () {
  6283. return this._onDataArrival;
  6284. },
  6285. set: function (callback) {
  6286. this._onDataArrival = callback;
  6287. },
  6288. enumerable: false,
  6289. configurable: true
  6290. });
  6291. Object.defineProperty(BaseLoader.prototype, "onError", {
  6292. get: function () {
  6293. return this._onError;
  6294. },
  6295. set: function (callback) {
  6296. this._onError = callback;
  6297. },
  6298. enumerable: false,
  6299. configurable: true
  6300. });
  6301. Object.defineProperty(BaseLoader.prototype, "onComplete", {
  6302. get: function () {
  6303. return this._onComplete;
  6304. },
  6305. set: function (callback) {
  6306. this._onComplete = callback;
  6307. },
  6308. enumerable: false,
  6309. configurable: true
  6310. });
  6311. // pure virtual
  6312. BaseLoader.prototype.open = function (dataSource, range) {
  6313. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_0__.NotImplementedException('Unimplemented abstract function!');
  6314. };
  6315. BaseLoader.prototype.abort = function () {
  6316. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_0__.NotImplementedException('Unimplemented abstract function!');
  6317. };
  6318. return BaseLoader;
  6319. }());
  6320. /***/ }),
  6321. /***/ "./src/io/param-seek-handler.js":
  6322. /*!**************************************!*\
  6323. !*** ./src/io/param-seek-handler.js ***!
  6324. \**************************************/
  6325. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  6326. "use strict";
  6327. __webpack_require__.r(__webpack_exports__);
  6328. /*
  6329. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  6330. *
  6331. * @author zheng qian <xqq@xqq.im>
  6332. *
  6333. * Licensed under the Apache License, Version 2.0 (the "License");
  6334. * you may not use this file except in compliance with the License.
  6335. * You may obtain a copy of the License at
  6336. *
  6337. * http://www.apache.org/licenses/LICENSE-2.0
  6338. *
  6339. * Unless required by applicable law or agreed to in writing, software
  6340. * distributed under the License is distributed on an "AS IS" BASIS,
  6341. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6342. * See the License for the specific language governing permissions and
  6343. * limitations under the License.
  6344. */
  6345. var ParamSeekHandler = /** @class */ (function () {
  6346. function ParamSeekHandler(paramStart, paramEnd) {
  6347. this._startName = paramStart;
  6348. this._endName = paramEnd;
  6349. }
  6350. ParamSeekHandler.prototype.getConfig = function (baseUrl, range) {
  6351. var url = baseUrl;
  6352. if (range.from !== 0 || range.to !== -1) {
  6353. var needAnd = true;
  6354. if (url.indexOf('?') === -1) {
  6355. url += '?';
  6356. needAnd = false;
  6357. }
  6358. if (needAnd) {
  6359. url += '&';
  6360. }
  6361. url += this._startName + "=" + range.from.toString();
  6362. if (range.to !== -1) {
  6363. url += "&" + this._endName + "=" + range.to.toString();
  6364. }
  6365. }
  6366. return {
  6367. url: url,
  6368. headers: {}
  6369. };
  6370. };
  6371. ParamSeekHandler.prototype.removeURLParameters = function (seekedURL) {
  6372. var baseURL = seekedURL.split('?')[0];
  6373. var params = undefined;
  6374. var queryIndex = seekedURL.indexOf('?');
  6375. if (queryIndex !== -1) {
  6376. params = seekedURL.substring(queryIndex + 1);
  6377. }
  6378. var resultParams = '';
  6379. if (params != undefined && params.length > 0) {
  6380. var pairs = params.split('&');
  6381. for (var i = 0; i < pairs.length; i++) {
  6382. var pair = pairs[i].split('=');
  6383. var requireAnd = (i > 0);
  6384. if (pair[0] !== this._startName && pair[0] !== this._endName) {
  6385. if (requireAnd) {
  6386. resultParams += '&';
  6387. }
  6388. resultParams += pairs[i];
  6389. }
  6390. }
  6391. }
  6392. return (resultParams.length === 0) ? baseURL : baseURL + '?' + resultParams;
  6393. };
  6394. return ParamSeekHandler;
  6395. }());
  6396. /* harmony default export */ __webpack_exports__["default"] = (ParamSeekHandler);
  6397. /***/ }),
  6398. /***/ "./src/io/range-seek-handler.js":
  6399. /*!**************************************!*\
  6400. !*** ./src/io/range-seek-handler.js ***!
  6401. \**************************************/
  6402. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  6403. "use strict";
  6404. __webpack_require__.r(__webpack_exports__);
  6405. /*
  6406. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  6407. *
  6408. * @author zheng qian <xqq@xqq.im>
  6409. *
  6410. * Licensed under the Apache License, Version 2.0 (the "License");
  6411. * you may not use this file except in compliance with the License.
  6412. * You may obtain a copy of the License at
  6413. *
  6414. * http://www.apache.org/licenses/LICENSE-2.0
  6415. *
  6416. * Unless required by applicable law or agreed to in writing, software
  6417. * distributed under the License is distributed on an "AS IS" BASIS,
  6418. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6419. * See the License for the specific language governing permissions and
  6420. * limitations under the License.
  6421. */
  6422. var RangeSeekHandler = /** @class */ (function () {
  6423. function RangeSeekHandler(zeroStart) {
  6424. this._zeroStart = zeroStart || false;
  6425. }
  6426. RangeSeekHandler.prototype.getConfig = function (url, range) {
  6427. var headers = {};
  6428. if (range.from !== 0 || range.to !== -1) {
  6429. var param = void 0;
  6430. if (range.to !== -1) {
  6431. param = "bytes=" + range.from.toString() + "-" + range.to.toString();
  6432. }
  6433. else {
  6434. param = "bytes=" + range.from.toString() + "-";
  6435. }
  6436. headers['Range'] = param;
  6437. }
  6438. else if (this._zeroStart) {
  6439. headers['Range'] = 'bytes=0-';
  6440. }
  6441. return {
  6442. url: url,
  6443. headers: headers
  6444. };
  6445. };
  6446. RangeSeekHandler.prototype.removeURLParameters = function (seekedURL) {
  6447. return seekedURL;
  6448. };
  6449. return RangeSeekHandler;
  6450. }());
  6451. /* harmony default export */ __webpack_exports__["default"] = (RangeSeekHandler);
  6452. /***/ }),
  6453. /***/ "./src/io/speed-sampler.js":
  6454. /*!*********************************!*\
  6455. !*** ./src/io/speed-sampler.js ***!
  6456. \*********************************/
  6457. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  6458. "use strict";
  6459. __webpack_require__.r(__webpack_exports__);
  6460. /*
  6461. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  6462. *
  6463. * @author zheng qian <xqq@xqq.im>
  6464. *
  6465. * Licensed under the Apache License, Version 2.0 (the "License");
  6466. * you may not use this file except in compliance with the License.
  6467. * You may obtain a copy of the License at
  6468. *
  6469. * http://www.apache.org/licenses/LICENSE-2.0
  6470. *
  6471. * Unless required by applicable law or agreed to in writing, software
  6472. * distributed under the License is distributed on an "AS IS" BASIS,
  6473. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6474. * See the License for the specific language governing permissions and
  6475. * limitations under the License.
  6476. */
  6477. // Utility class to calculate realtime network I/O speed
  6478. var SpeedSampler = /** @class */ (function () {
  6479. function SpeedSampler() {
  6480. // milliseconds
  6481. this._firstCheckpoint = 0;
  6482. this._lastCheckpoint = 0;
  6483. this._intervalBytes = 0;
  6484. this._totalBytes = 0;
  6485. this._lastSecondBytes = 0;
  6486. // compatibility detection
  6487. if (self.performance && self.performance.now) {
  6488. this._now = self.performance.now.bind(self.performance);
  6489. }
  6490. else {
  6491. this._now = Date.now;
  6492. }
  6493. }
  6494. SpeedSampler.prototype.reset = function () {
  6495. this._firstCheckpoint = this._lastCheckpoint = 0;
  6496. this._totalBytes = this._intervalBytes = 0;
  6497. this._lastSecondBytes = 0;
  6498. };
  6499. SpeedSampler.prototype.addBytes = function (bytes) {
  6500. if (this._firstCheckpoint === 0) {
  6501. this._firstCheckpoint = this._now();
  6502. this._lastCheckpoint = this._firstCheckpoint;
  6503. this._intervalBytes += bytes;
  6504. this._totalBytes += bytes;
  6505. }
  6506. else if (this._now() - this._lastCheckpoint < 1000) {
  6507. this._intervalBytes += bytes;
  6508. this._totalBytes += bytes;
  6509. }
  6510. else { // duration >= 1000
  6511. this._lastSecondBytes = this._intervalBytes;
  6512. this._intervalBytes = bytes;
  6513. this._totalBytes += bytes;
  6514. this._lastCheckpoint = this._now();
  6515. }
  6516. };
  6517. Object.defineProperty(SpeedSampler.prototype, "currentKBps", {
  6518. get: function () {
  6519. this.addBytes(0);
  6520. var durationSeconds = (this._now() - this._lastCheckpoint) / 1000;
  6521. if (durationSeconds == 0)
  6522. durationSeconds = 1;
  6523. return (this._intervalBytes / durationSeconds) / 1024;
  6524. },
  6525. enumerable: false,
  6526. configurable: true
  6527. });
  6528. Object.defineProperty(SpeedSampler.prototype, "lastSecondKBps", {
  6529. get: function () {
  6530. this.addBytes(0);
  6531. if (this._lastSecondBytes !== 0) {
  6532. return this._lastSecondBytes / 1024;
  6533. }
  6534. else { // lastSecondBytes === 0
  6535. if (this._now() - this._lastCheckpoint >= 500) {
  6536. // if time interval since last checkpoint has exceeded 500ms
  6537. // the speed is nearly accurate
  6538. return this.currentKBps;
  6539. }
  6540. else {
  6541. // We don't know
  6542. return 0;
  6543. }
  6544. }
  6545. },
  6546. enumerable: false,
  6547. configurable: true
  6548. });
  6549. Object.defineProperty(SpeedSampler.prototype, "averageKBps", {
  6550. get: function () {
  6551. var durationSeconds = (this._now() - this._firstCheckpoint) / 1000;
  6552. return (this._totalBytes / durationSeconds) / 1024;
  6553. },
  6554. enumerable: false,
  6555. configurable: true
  6556. });
  6557. return SpeedSampler;
  6558. }());
  6559. /* harmony default export */ __webpack_exports__["default"] = (SpeedSampler);
  6560. /***/ }),
  6561. /***/ "./src/io/websocket-loader.js":
  6562. /*!************************************!*\
  6563. !*** ./src/io/websocket-loader.js ***!
  6564. \************************************/
  6565. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  6566. "use strict";
  6567. __webpack_require__.r(__webpack_exports__);
  6568. /* harmony import */ var _loader_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./loader.js */ "./src/io/loader.js");
  6569. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  6570. /*
  6571. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  6572. *
  6573. * @author zheng qian <xqq@xqq.im>
  6574. *
  6575. * Licensed under the Apache License, Version 2.0 (the "License");
  6576. * you may not use this file except in compliance with the License.
  6577. * You may obtain a copy of the License at
  6578. *
  6579. * http://www.apache.org/licenses/LICENSE-2.0
  6580. *
  6581. * Unless required by applicable law or agreed to in writing, software
  6582. * distributed under the License is distributed on an "AS IS" BASIS,
  6583. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6584. * See the License for the specific language governing permissions and
  6585. * limitations under the License.
  6586. */
  6587. var __extends = (undefined && undefined.__extends) || (function () {
  6588. var extendStatics = function (d, b) {
  6589. extendStatics = Object.setPrototypeOf ||
  6590. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6591. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  6592. return extendStatics(d, b);
  6593. };
  6594. return function (d, b) {
  6595. if (typeof b !== "function" && b !== null)
  6596. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  6597. extendStatics(d, b);
  6598. function __() { this.constructor = d; }
  6599. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6600. };
  6601. })();
  6602. // For FLV over WebSocket live stream
  6603. var WebSocketLoader = /** @class */ (function (_super) {
  6604. __extends(WebSocketLoader, _super);
  6605. function WebSocketLoader() {
  6606. var _this = _super.call(this, 'websocket-loader') || this;
  6607. _this.TAG = 'WebSocketLoader';
  6608. _this._needStash = true;
  6609. _this._ws = null;
  6610. _this._requestAbort = false;
  6611. _this._receivedLength = 0;
  6612. return _this;
  6613. }
  6614. WebSocketLoader.isSupported = function () {
  6615. try {
  6616. return (typeof self.WebSocket !== 'undefined');
  6617. }
  6618. catch (e) {
  6619. return false;
  6620. }
  6621. };
  6622. WebSocketLoader.prototype.destroy = function () {
  6623. if (this._ws) {
  6624. this.abort();
  6625. }
  6626. _super.prototype.destroy.call(this);
  6627. };
  6628. WebSocketLoader.prototype.open = function (dataSource) {
  6629. try {
  6630. var ws = this._ws = new self.WebSocket(dataSource.url);
  6631. ws.binaryType = 'arraybuffer';
  6632. ws.onopen = this._onWebSocketOpen.bind(this);
  6633. ws.onclose = this._onWebSocketClose.bind(this);
  6634. ws.onmessage = this._onWebSocketMessage.bind(this);
  6635. ws.onerror = this._onWebSocketError.bind(this);
  6636. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderStatus.kConnecting;
  6637. }
  6638. catch (e) {
  6639. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderStatus.kError;
  6640. var info = { code: e.code, msg: e.message };
  6641. if (this._onError) {
  6642. this._onError(_loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderErrors.EXCEPTION, info);
  6643. }
  6644. else {
  6645. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_1__.RuntimeException(info.msg);
  6646. }
  6647. }
  6648. };
  6649. WebSocketLoader.prototype.abort = function () {
  6650. var ws = this._ws;
  6651. if (ws && (ws.readyState === 0 || ws.readyState === 1)) { // CONNECTING || OPEN
  6652. this._requestAbort = true;
  6653. ws.close();
  6654. }
  6655. this._ws = null;
  6656. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderStatus.kComplete;
  6657. };
  6658. WebSocketLoader.prototype._onWebSocketOpen = function (e) {
  6659. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderStatus.kBuffering;
  6660. };
  6661. WebSocketLoader.prototype._onWebSocketClose = function (e) {
  6662. if (this._requestAbort === true) {
  6663. this._requestAbort = false;
  6664. return;
  6665. }
  6666. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderStatus.kComplete;
  6667. if (this._onComplete) {
  6668. this._onComplete(0, this._receivedLength - 1);
  6669. }
  6670. };
  6671. WebSocketLoader.prototype._onWebSocketMessage = function (e) {
  6672. var _this = this;
  6673. if (e.data instanceof ArrayBuffer) {
  6674. this._dispatchArrayBuffer(e.data);
  6675. }
  6676. else if (e.data instanceof Blob) {
  6677. var reader_1 = new FileReader();
  6678. reader_1.onload = function () {
  6679. _this._dispatchArrayBuffer(reader_1.result);
  6680. };
  6681. reader_1.readAsArrayBuffer(e.data);
  6682. }
  6683. else {
  6684. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderStatus.kError;
  6685. var info = { code: -1, msg: 'Unsupported WebSocket message type: ' + e.data.constructor.name };
  6686. if (this._onError) {
  6687. this._onError(_loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderErrors.EXCEPTION, info);
  6688. }
  6689. else {
  6690. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_1__.RuntimeException(info.msg);
  6691. }
  6692. }
  6693. };
  6694. WebSocketLoader.prototype._dispatchArrayBuffer = function (arraybuffer) {
  6695. var chunk = arraybuffer;
  6696. var byteStart = this._receivedLength;
  6697. this._receivedLength += chunk.byteLength;
  6698. if (this._onDataArrival) {
  6699. this._onDataArrival(chunk, byteStart, this._receivedLength);
  6700. }
  6701. };
  6702. WebSocketLoader.prototype._onWebSocketError = function (e) {
  6703. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderStatus.kError;
  6704. var info = {
  6705. code: e.code,
  6706. msg: e.message
  6707. };
  6708. if (this._onError) {
  6709. this._onError(_loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderErrors.EXCEPTION, info);
  6710. }
  6711. else {
  6712. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_1__.RuntimeException(info.msg);
  6713. }
  6714. };
  6715. return WebSocketLoader;
  6716. }(_loader_js__WEBPACK_IMPORTED_MODULE_0__.BaseLoader));
  6717. /* harmony default export */ __webpack_exports__["default"] = (WebSocketLoader);
  6718. /***/ }),
  6719. /***/ "./src/io/xhr-moz-chunked-loader.js":
  6720. /*!******************************************!*\
  6721. !*** ./src/io/xhr-moz-chunked-loader.js ***!
  6722. \******************************************/
  6723. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  6724. "use strict";
  6725. __webpack_require__.r(__webpack_exports__);
  6726. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  6727. /* harmony import */ var _loader_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./loader.js */ "./src/io/loader.js");
  6728. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  6729. /*
  6730. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  6731. *
  6732. * @author zheng qian <xqq@xqq.im>
  6733. *
  6734. * Licensed under the Apache License, Version 2.0 (the "License");
  6735. * you may not use this file except in compliance with the License.
  6736. * You may obtain a copy of the License at
  6737. *
  6738. * http://www.apache.org/licenses/LICENSE-2.0
  6739. *
  6740. * Unless required by applicable law or agreed to in writing, software
  6741. * distributed under the License is distributed on an "AS IS" BASIS,
  6742. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6743. * See the License for the specific language governing permissions and
  6744. * limitations under the License.
  6745. */
  6746. var __extends = (undefined && undefined.__extends) || (function () {
  6747. var extendStatics = function (d, b) {
  6748. extendStatics = Object.setPrototypeOf ||
  6749. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6750. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  6751. return extendStatics(d, b);
  6752. };
  6753. return function (d, b) {
  6754. if (typeof b !== "function" && b !== null)
  6755. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  6756. extendStatics(d, b);
  6757. function __() { this.constructor = d; }
  6758. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6759. };
  6760. })();
  6761. // For FireFox browser which supports `xhr.responseType = 'moz-chunked-arraybuffer'`
  6762. var MozChunkedLoader = /** @class */ (function (_super) {
  6763. __extends(MozChunkedLoader, _super);
  6764. function MozChunkedLoader(seekHandler, config) {
  6765. var _this = _super.call(this, 'xhr-moz-chunked-loader') || this;
  6766. _this.TAG = 'MozChunkedLoader';
  6767. _this._seekHandler = seekHandler;
  6768. _this._config = config;
  6769. _this._needStash = true;
  6770. _this._xhr = null;
  6771. _this._requestAbort = false;
  6772. _this._contentLength = null;
  6773. _this._receivedLength = 0;
  6774. return _this;
  6775. }
  6776. MozChunkedLoader.isSupported = function () {
  6777. try {
  6778. var xhr = new XMLHttpRequest();
  6779. // Firefox 37- requires .open() to be called before setting responseType
  6780. xhr.open('GET', 'https://example.com', true);
  6781. xhr.responseType = 'moz-chunked-arraybuffer';
  6782. return (xhr.responseType === 'moz-chunked-arraybuffer');
  6783. }
  6784. catch (e) {
  6785. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w('MozChunkedLoader', e.message);
  6786. return false;
  6787. }
  6788. };
  6789. MozChunkedLoader.prototype.destroy = function () {
  6790. if (this.isWorking()) {
  6791. this.abort();
  6792. }
  6793. if (this._xhr) {
  6794. this._xhr.onreadystatechange = null;
  6795. this._xhr.onprogress = null;
  6796. this._xhr.onloadend = null;
  6797. this._xhr.onerror = null;
  6798. this._xhr = null;
  6799. }
  6800. _super.prototype.destroy.call(this);
  6801. };
  6802. MozChunkedLoader.prototype.open = function (dataSource, range) {
  6803. this._dataSource = dataSource;
  6804. this._range = range;
  6805. var sourceURL = dataSource.url;
  6806. if (this._config.reuseRedirectedURL && dataSource.redirectedURL != undefined) {
  6807. sourceURL = dataSource.redirectedURL;
  6808. }
  6809. var seekConfig = this._seekHandler.getConfig(sourceURL, range);
  6810. this._requestURL = seekConfig.url;
  6811. var xhr = this._xhr = new XMLHttpRequest();
  6812. xhr.open('GET', seekConfig.url, true);
  6813. xhr.responseType = 'moz-chunked-arraybuffer';
  6814. xhr.onreadystatechange = this._onReadyStateChange.bind(this);
  6815. xhr.onprogress = this._onProgress.bind(this);
  6816. xhr.onloadend = this._onLoadEnd.bind(this);
  6817. xhr.onerror = this._onXhrError.bind(this);
  6818. // cors is auto detected and enabled by xhr
  6819. // withCredentials is disabled by default
  6820. if (dataSource.withCredentials) {
  6821. xhr.withCredentials = true;
  6822. }
  6823. if (typeof seekConfig.headers === 'object') {
  6824. var headers = seekConfig.headers;
  6825. for (var key in headers) {
  6826. if (headers.hasOwnProperty(key)) {
  6827. xhr.setRequestHeader(key, headers[key]);
  6828. }
  6829. }
  6830. }
  6831. // add additional headers
  6832. if (typeof this._config.headers === 'object') {
  6833. var headers = this._config.headers;
  6834. for (var key in headers) {
  6835. if (headers.hasOwnProperty(key)) {
  6836. xhr.setRequestHeader(key, headers[key]);
  6837. }
  6838. }
  6839. }
  6840. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kConnecting;
  6841. xhr.send();
  6842. };
  6843. MozChunkedLoader.prototype.abort = function () {
  6844. this._requestAbort = true;
  6845. if (this._xhr) {
  6846. this._xhr.abort();
  6847. }
  6848. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kComplete;
  6849. };
  6850. MozChunkedLoader.prototype._onReadyStateChange = function (e) {
  6851. var xhr = e.target;
  6852. if (xhr.readyState === 2) { // HEADERS_RECEIVED
  6853. if (xhr.responseURL != undefined && xhr.responseURL !== this._requestURL) {
  6854. if (this._onURLRedirect) {
  6855. var redirectedURL = this._seekHandler.removeURLParameters(xhr.responseURL);
  6856. this._onURLRedirect(redirectedURL);
  6857. }
  6858. }
  6859. if (xhr.status !== 0 && (xhr.status < 200 || xhr.status > 299)) {
  6860. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kError;
  6861. if (this._onError) {
  6862. this._onError(_loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderErrors.HTTP_STATUS_CODE_INVALID, { code: xhr.status, msg: xhr.statusText });
  6863. }
  6864. else {
  6865. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.RuntimeException('MozChunkedLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText);
  6866. }
  6867. }
  6868. else {
  6869. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kBuffering;
  6870. }
  6871. }
  6872. };
  6873. MozChunkedLoader.prototype._onProgress = function (e) {
  6874. if (this._status === _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kError) {
  6875. // Ignore error response
  6876. return;
  6877. }
  6878. if (this._contentLength === null) {
  6879. if (e.total !== null && e.total !== 0) {
  6880. this._contentLength = e.total;
  6881. if (this._onContentLengthKnown) {
  6882. this._onContentLengthKnown(this._contentLength);
  6883. }
  6884. }
  6885. }
  6886. var chunk = e.target.response;
  6887. var byteStart = this._range.from + this._receivedLength;
  6888. this._receivedLength += chunk.byteLength;
  6889. if (this._onDataArrival) {
  6890. this._onDataArrival(chunk, byteStart, this._receivedLength);
  6891. }
  6892. };
  6893. MozChunkedLoader.prototype._onLoadEnd = function (e) {
  6894. if (this._requestAbort === true) {
  6895. this._requestAbort = false;
  6896. return;
  6897. }
  6898. else if (this._status === _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kError) {
  6899. return;
  6900. }
  6901. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kComplete;
  6902. if (this._onComplete) {
  6903. this._onComplete(this._range.from, this._range.from + this._receivedLength - 1);
  6904. }
  6905. };
  6906. MozChunkedLoader.prototype._onXhrError = function (e) {
  6907. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderStatus.kError;
  6908. var type = 0;
  6909. var info = null;
  6910. if (this._contentLength && e.loaded < this._contentLength) {
  6911. type = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderErrors.EARLY_EOF;
  6912. info = { code: -1, msg: 'Moz-Chunked stream meet Early-Eof' };
  6913. }
  6914. else {
  6915. type = _loader_js__WEBPACK_IMPORTED_MODULE_1__.LoaderErrors.EXCEPTION;
  6916. info = { code: -1, msg: e.constructor.name + ' ' + e.type };
  6917. }
  6918. if (this._onError) {
  6919. this._onError(type, info);
  6920. }
  6921. else {
  6922. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_2__.RuntimeException(info.msg);
  6923. }
  6924. };
  6925. return MozChunkedLoader;
  6926. }(_loader_js__WEBPACK_IMPORTED_MODULE_1__.BaseLoader));
  6927. /* harmony default export */ __webpack_exports__["default"] = (MozChunkedLoader);
  6928. /***/ }),
  6929. /***/ "./src/io/xhr-range-loader.js":
  6930. /*!************************************!*\
  6931. !*** ./src/io/xhr-range-loader.js ***!
  6932. \************************************/
  6933. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  6934. "use strict";
  6935. __webpack_require__.r(__webpack_exports__);
  6936. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  6937. /* harmony import */ var _speed_sampler_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./speed-sampler.js */ "./src/io/speed-sampler.js");
  6938. /* harmony import */ var _loader_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./loader.js */ "./src/io/loader.js");
  6939. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  6940. /*
  6941. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  6942. *
  6943. * @author zheng qian <xqq@xqq.im>
  6944. *
  6945. * Licensed under the Apache License, Version 2.0 (the "License");
  6946. * you may not use this file except in compliance with the License.
  6947. * You may obtain a copy of the License at
  6948. *
  6949. * http://www.apache.org/licenses/LICENSE-2.0
  6950. *
  6951. * Unless required by applicable law or agreed to in writing, software
  6952. * distributed under the License is distributed on an "AS IS" BASIS,
  6953. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6954. * See the License for the specific language governing permissions and
  6955. * limitations under the License.
  6956. */
  6957. var __extends = (undefined && undefined.__extends) || (function () {
  6958. var extendStatics = function (d, b) {
  6959. extendStatics = Object.setPrototypeOf ||
  6960. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6961. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  6962. return extendStatics(d, b);
  6963. };
  6964. return function (d, b) {
  6965. if (typeof b !== "function" && b !== null)
  6966. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  6967. extendStatics(d, b);
  6968. function __() { this.constructor = d; }
  6969. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6970. };
  6971. })();
  6972. // Universal IO Loader, implemented by adding Range header in xhr's request header
  6973. var RangeLoader = /** @class */ (function (_super) {
  6974. __extends(RangeLoader, _super);
  6975. function RangeLoader(seekHandler, config) {
  6976. var _this = _super.call(this, 'xhr-range-loader') || this;
  6977. _this.TAG = 'RangeLoader';
  6978. _this._seekHandler = seekHandler;
  6979. _this._config = config;
  6980. _this._needStash = false;
  6981. _this._chunkSizeKBList = [
  6982. 128, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 5120, 6144, 7168, 8192
  6983. ];
  6984. _this._currentChunkSizeKB = 384;
  6985. _this._currentSpeedNormalized = 0;
  6986. _this._zeroSpeedChunkCount = 0;
  6987. _this._xhr = null;
  6988. _this._speedSampler = new _speed_sampler_js__WEBPACK_IMPORTED_MODULE_1__.default();
  6989. _this._requestAbort = false;
  6990. _this._waitForTotalLength = false;
  6991. _this._totalLengthReceived = false;
  6992. _this._currentRequestURL = null;
  6993. _this._currentRedirectedURL = null;
  6994. _this._currentRequestRange = null;
  6995. _this._totalLength = null; // size of the entire file
  6996. _this._contentLength = null; // Content-Length of entire request range
  6997. _this._receivedLength = 0; // total received bytes
  6998. _this._lastTimeLoaded = 0; // received bytes of current request sub-range
  6999. return _this;
  7000. }
  7001. RangeLoader.isSupported = function () {
  7002. try {
  7003. var xhr = new XMLHttpRequest();
  7004. xhr.open('GET', 'https://example.com', true);
  7005. xhr.responseType = 'arraybuffer';
  7006. return (xhr.responseType === 'arraybuffer');
  7007. }
  7008. catch (e) {
  7009. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w('RangeLoader', e.message);
  7010. return false;
  7011. }
  7012. };
  7013. RangeLoader.prototype.destroy = function () {
  7014. if (this.isWorking()) {
  7015. this.abort();
  7016. }
  7017. if (this._xhr) {
  7018. this._xhr.onreadystatechange = null;
  7019. this._xhr.onprogress = null;
  7020. this._xhr.onload = null;
  7021. this._xhr.onerror = null;
  7022. this._xhr = null;
  7023. }
  7024. _super.prototype.destroy.call(this);
  7025. };
  7026. Object.defineProperty(RangeLoader.prototype, "currentSpeed", {
  7027. get: function () {
  7028. return this._speedSampler.lastSecondKBps;
  7029. },
  7030. enumerable: false,
  7031. configurable: true
  7032. });
  7033. RangeLoader.prototype.open = function (dataSource, range) {
  7034. this._dataSource = dataSource;
  7035. this._range = range;
  7036. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderStatus.kConnecting;
  7037. var useRefTotalLength = false;
  7038. if (this._dataSource.filesize != undefined && this._dataSource.filesize !== 0) {
  7039. useRefTotalLength = true;
  7040. this._totalLength = this._dataSource.filesize;
  7041. }
  7042. if (!this._totalLengthReceived && !useRefTotalLength) {
  7043. // We need total filesize
  7044. this._waitForTotalLength = true;
  7045. this._internalOpen(this._dataSource, { from: 0, to: -1 });
  7046. }
  7047. else {
  7048. // We have filesize, start loading
  7049. this._openSubRange();
  7050. }
  7051. };
  7052. RangeLoader.prototype._openSubRange = function () {
  7053. var chunkSize = this._currentChunkSizeKB * 1024;
  7054. var from = this._range.from + this._receivedLength;
  7055. var to = from + chunkSize;
  7056. if (this._contentLength != null) {
  7057. if (to - this._range.from >= this._contentLength) {
  7058. to = this._range.from + this._contentLength - 1;
  7059. }
  7060. }
  7061. this._currentRequestRange = { from: from, to: to };
  7062. this._internalOpen(this._dataSource, this._currentRequestRange);
  7063. };
  7064. RangeLoader.prototype._internalOpen = function (dataSource, range) {
  7065. this._lastTimeLoaded = 0;
  7066. var sourceURL = dataSource.url;
  7067. if (this._config.reuseRedirectedURL) {
  7068. if (this._currentRedirectedURL != undefined) {
  7069. sourceURL = this._currentRedirectedURL;
  7070. }
  7071. else if (dataSource.redirectedURL != undefined) {
  7072. sourceURL = dataSource.redirectedURL;
  7073. }
  7074. }
  7075. var seekConfig = this._seekHandler.getConfig(sourceURL, range);
  7076. this._currentRequestURL = seekConfig.url;
  7077. var xhr = this._xhr = new XMLHttpRequest();
  7078. xhr.open('GET', seekConfig.url, true);
  7079. xhr.responseType = 'arraybuffer';
  7080. xhr.onreadystatechange = this._onReadyStateChange.bind(this);
  7081. xhr.onprogress = this._onProgress.bind(this);
  7082. xhr.onload = this._onLoad.bind(this);
  7083. xhr.onerror = this._onXhrError.bind(this);
  7084. if (dataSource.withCredentials) {
  7085. xhr.withCredentials = true;
  7086. }
  7087. if (typeof seekConfig.headers === 'object') {
  7088. var headers = seekConfig.headers;
  7089. for (var key in headers) {
  7090. if (headers.hasOwnProperty(key)) {
  7091. xhr.setRequestHeader(key, headers[key]);
  7092. }
  7093. }
  7094. }
  7095. // add additional headers
  7096. if (typeof this._config.headers === 'object') {
  7097. var headers = this._config.headers;
  7098. for (var key in headers) {
  7099. if (headers.hasOwnProperty(key)) {
  7100. xhr.setRequestHeader(key, headers[key]);
  7101. }
  7102. }
  7103. }
  7104. xhr.send();
  7105. };
  7106. RangeLoader.prototype.abort = function () {
  7107. this._requestAbort = true;
  7108. this._internalAbort();
  7109. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderStatus.kComplete;
  7110. };
  7111. RangeLoader.prototype._internalAbort = function () {
  7112. if (this._xhr) {
  7113. this._xhr.onreadystatechange = null;
  7114. this._xhr.onprogress = null;
  7115. this._xhr.onload = null;
  7116. this._xhr.onerror = null;
  7117. this._xhr.abort();
  7118. this._xhr = null;
  7119. }
  7120. };
  7121. RangeLoader.prototype._onReadyStateChange = function (e) {
  7122. var xhr = e.target;
  7123. if (xhr.readyState === 2) { // HEADERS_RECEIVED
  7124. if (xhr.responseURL != undefined) { // if the browser support this property
  7125. var redirectedURL = this._seekHandler.removeURLParameters(xhr.responseURL);
  7126. if (xhr.responseURL !== this._currentRequestURL && redirectedURL !== this._currentRedirectedURL) {
  7127. this._currentRedirectedURL = redirectedURL;
  7128. if (this._onURLRedirect) {
  7129. this._onURLRedirect(redirectedURL);
  7130. }
  7131. }
  7132. }
  7133. if ((xhr.status >= 200 && xhr.status <= 299)) {
  7134. if (this._waitForTotalLength) {
  7135. return;
  7136. }
  7137. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderStatus.kBuffering;
  7138. }
  7139. else {
  7140. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderStatus.kError;
  7141. if (this._onError) {
  7142. this._onError(_loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.HTTP_STATUS_CODE_INVALID, { code: xhr.status, msg: xhr.statusText });
  7143. }
  7144. else {
  7145. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_3__.RuntimeException('RangeLoader: Http code invalid, ' + xhr.status + ' ' + xhr.statusText);
  7146. }
  7147. }
  7148. }
  7149. };
  7150. RangeLoader.prototype._onProgress = function (e) {
  7151. if (this._status === _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderStatus.kError) {
  7152. // Ignore error response
  7153. return;
  7154. }
  7155. if (this._contentLength === null) {
  7156. var openNextRange = false;
  7157. if (this._waitForTotalLength) {
  7158. this._waitForTotalLength = false;
  7159. this._totalLengthReceived = true;
  7160. openNextRange = true;
  7161. var total = e.total;
  7162. this._internalAbort();
  7163. if (total != null & total !== 0) {
  7164. this._totalLength = total;
  7165. }
  7166. }
  7167. // calculate currrent request range's contentLength
  7168. if (this._range.to === -1) {
  7169. this._contentLength = this._totalLength - this._range.from;
  7170. }
  7171. else { // to !== -1
  7172. this._contentLength = this._range.to - this._range.from + 1;
  7173. }
  7174. if (openNextRange) {
  7175. this._openSubRange();
  7176. return;
  7177. }
  7178. if (this._onContentLengthKnown) {
  7179. this._onContentLengthKnown(this._contentLength);
  7180. }
  7181. }
  7182. var delta = e.loaded - this._lastTimeLoaded;
  7183. this._lastTimeLoaded = e.loaded;
  7184. this._speedSampler.addBytes(delta);
  7185. };
  7186. RangeLoader.prototype._normalizeSpeed = function (input) {
  7187. var list = this._chunkSizeKBList;
  7188. var last = list.length - 1;
  7189. var mid = 0;
  7190. var lbound = 0;
  7191. var ubound = last;
  7192. if (input < list[0]) {
  7193. return list[0];
  7194. }
  7195. while (lbound <= ubound) {
  7196. mid = lbound + Math.floor((ubound - lbound) / 2);
  7197. if (mid === last || (input >= list[mid] && input < list[mid + 1])) {
  7198. return list[mid];
  7199. }
  7200. else if (list[mid] < input) {
  7201. lbound = mid + 1;
  7202. }
  7203. else {
  7204. ubound = mid - 1;
  7205. }
  7206. }
  7207. };
  7208. RangeLoader.prototype._onLoad = function (e) {
  7209. if (this._status === _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderStatus.kError) {
  7210. // Ignore error response
  7211. return;
  7212. }
  7213. if (this._waitForTotalLength) {
  7214. this._waitForTotalLength = false;
  7215. return;
  7216. }
  7217. this._lastTimeLoaded = 0;
  7218. var KBps = this._speedSampler.lastSecondKBps;
  7219. if (KBps === 0) {
  7220. this._zeroSpeedChunkCount++;
  7221. if (this._zeroSpeedChunkCount >= 3) {
  7222. // Try get currentKBps after 3 chunks
  7223. KBps = this._speedSampler.currentKBps;
  7224. }
  7225. }
  7226. if (KBps !== 0) {
  7227. var normalized = this._normalizeSpeed(KBps);
  7228. if (this._currentSpeedNormalized !== normalized) {
  7229. this._currentSpeedNormalized = normalized;
  7230. this._currentChunkSizeKB = normalized;
  7231. }
  7232. }
  7233. var chunk = e.target.response;
  7234. var byteStart = this._range.from + this._receivedLength;
  7235. this._receivedLength += chunk.byteLength;
  7236. var reportComplete = false;
  7237. if (this._contentLength != null && this._receivedLength < this._contentLength) {
  7238. // continue load next chunk
  7239. this._openSubRange();
  7240. }
  7241. else {
  7242. reportComplete = true;
  7243. }
  7244. // dispatch received chunk
  7245. if (this._onDataArrival) {
  7246. this._onDataArrival(chunk, byteStart, this._receivedLength);
  7247. }
  7248. if (reportComplete) {
  7249. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderStatus.kComplete;
  7250. if (this._onComplete) {
  7251. this._onComplete(this._range.from, this._range.from + this._receivedLength - 1);
  7252. }
  7253. }
  7254. };
  7255. RangeLoader.prototype._onXhrError = function (e) {
  7256. this._status = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderStatus.kError;
  7257. var type = 0;
  7258. var info = null;
  7259. if (this._contentLength && this._receivedLength > 0
  7260. && this._receivedLength < this._contentLength) {
  7261. type = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.EARLY_EOF;
  7262. info = { code: -1, msg: 'RangeLoader meet Early-Eof' };
  7263. }
  7264. else {
  7265. type = _loader_js__WEBPACK_IMPORTED_MODULE_2__.LoaderErrors.EXCEPTION;
  7266. info = { code: -1, msg: e.constructor.name + ' ' + e.type };
  7267. }
  7268. if (this._onError) {
  7269. this._onError(type, info);
  7270. }
  7271. else {
  7272. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_3__.RuntimeException(info.msg);
  7273. }
  7274. };
  7275. return RangeLoader;
  7276. }(_loader_js__WEBPACK_IMPORTED_MODULE_2__.BaseLoader));
  7277. /* harmony default export */ __webpack_exports__["default"] = (RangeLoader);
  7278. /***/ }),
  7279. /***/ "./src/player/flv-player.js":
  7280. /*!**********************************!*\
  7281. !*** ./src/player/flv-player.js ***!
  7282. \**********************************/
  7283. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  7284. "use strict";
  7285. __webpack_require__.r(__webpack_exports__);
  7286. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! events */ "./node_modules/events/events.js");
  7287. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(events__WEBPACK_IMPORTED_MODULE_0__);
  7288. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  7289. /* harmony import */ var _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils/browser.js */ "./src/utils/browser.js");
  7290. /* harmony import */ var _player_events_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./player-events.js */ "./src/player/player-events.js");
  7291. /* harmony import */ var _core_transmuxer_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/transmuxer.js */ "./src/core/transmuxer.js");
  7292. /* harmony import */ var _core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../core/transmuxing-events.js */ "./src/core/transmuxing-events.js");
  7293. /* harmony import */ var _core_mse_controller_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../core/mse-controller.js */ "./src/core/mse-controller.js");
  7294. /* harmony import */ var _core_mse_events_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../core/mse-events.js */ "./src/core/mse-events.js");
  7295. /* harmony import */ var _player_errors_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./player-errors.js */ "./src/player/player-errors.js");
  7296. /* harmony import */ var _config_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../config.js */ "./src/config.js");
  7297. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  7298. /*
  7299. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  7300. *
  7301. * @author zheng qian <xqq@xqq.im>
  7302. *
  7303. * Licensed under the Apache License, Version 2.0 (the "License");
  7304. * you may not use this file except in compliance with the License.
  7305. * You may obtain a copy of the License at
  7306. *
  7307. * http://www.apache.org/licenses/LICENSE-2.0
  7308. *
  7309. * Unless required by applicable law or agreed to in writing, software
  7310. * distributed under the License is distributed on an "AS IS" BASIS,
  7311. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7312. * See the License for the specific language governing permissions and
  7313. * limitations under the License.
  7314. */
  7315. var FlvPlayer = /** @class */ (function () {
  7316. function FlvPlayer(mediaDataSource, config) {
  7317. this.TAG = 'FlvPlayer';
  7318. this._type = 'FlvPlayer';
  7319. this._emitter = new (events__WEBPACK_IMPORTED_MODULE_0___default())();
  7320. this._config = (0,_config_js__WEBPACK_IMPORTED_MODULE_9__.createDefaultConfig)();
  7321. if (typeof config === 'object') {
  7322. Object.assign(this._config, config);
  7323. }
  7324. if (mediaDataSource.type.toLowerCase() !== 'flv') {
  7325. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_10__.InvalidArgumentException('FlvPlayer requires an flv MediaDataSource input!');
  7326. }
  7327. if (mediaDataSource.isLive === true) {
  7328. this._config.isLive = true;
  7329. }
  7330. this.e = {
  7331. onvLoadedMetadata: this._onvLoadedMetadata.bind(this),
  7332. onvSeeking: this._onvSeeking.bind(this),
  7333. onvCanPlay: this._onvCanPlay.bind(this),
  7334. onvStalled: this._onvStalled.bind(this),
  7335. onvProgress: this._onvProgress.bind(this)
  7336. };
  7337. if (self.performance && self.performance.now) {
  7338. this._now = self.performance.now.bind(self.performance);
  7339. }
  7340. else {
  7341. this._now = Date.now;
  7342. }
  7343. this._pendingSeekTime = null; // in seconds
  7344. this._requestSetTime = false;
  7345. this._seekpointRecord = null;
  7346. this._progressChecker = null;
  7347. this._mediaDataSource = mediaDataSource;
  7348. this._mediaElement = null;
  7349. this._msectl = null;
  7350. this._transmuxer = null;
  7351. this._mseSourceOpened = false;
  7352. this._hasPendingLoad = false;
  7353. this._receivedCanPlay = false;
  7354. this._mediaInfo = null;
  7355. this._statisticsInfo = null;
  7356. var chromeNeedIDRFix = (_utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.chrome &&
  7357. (_utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.version.major < 50 ||
  7358. (_utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.version.major === 50 && _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.version.build < 2661)));
  7359. this._alwaysSeekKeyframe = (chromeNeedIDRFix || _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.msedge || _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.msie) ? true : false;
  7360. if (this._alwaysSeekKeyframe) {
  7361. this._config.accurateSeek = false;
  7362. }
  7363. }
  7364. FlvPlayer.prototype.destroy = function () {
  7365. if (this._progressChecker != null) {
  7366. window.clearInterval(this._progressChecker);
  7367. this._progressChecker = null;
  7368. }
  7369. if (this._transmuxer) {
  7370. this.unload();
  7371. }
  7372. if (this._mediaElement) {
  7373. this.detachMediaElement();
  7374. }
  7375. this.e = null;
  7376. this._mediaDataSource = null;
  7377. this._emitter.removeAllListeners();
  7378. this._emitter = null;
  7379. };
  7380. FlvPlayer.prototype.on = function (event, listener) {
  7381. var _this = this;
  7382. if (event === _player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.MEDIA_INFO) {
  7383. if (this._mediaInfo != null) {
  7384. Promise.resolve().then(function () {
  7385. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.MEDIA_INFO, _this.mediaInfo);
  7386. });
  7387. }
  7388. }
  7389. else if (event === _player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.STATISTICS_INFO) {
  7390. if (this._statisticsInfo != null) {
  7391. Promise.resolve().then(function () {
  7392. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.STATISTICS_INFO, _this.statisticsInfo);
  7393. });
  7394. }
  7395. }
  7396. this._emitter.addListener(event, listener);
  7397. };
  7398. FlvPlayer.prototype.off = function (event, listener) {
  7399. this._emitter.removeListener(event, listener);
  7400. };
  7401. FlvPlayer.prototype.attachMediaElement = function (mediaElement) {
  7402. var _this = this;
  7403. this._mediaElement = mediaElement;
  7404. mediaElement.addEventListener('loadedmetadata', this.e.onvLoadedMetadata);
  7405. mediaElement.addEventListener('seeking', this.e.onvSeeking);
  7406. mediaElement.addEventListener('canplay', this.e.onvCanPlay);
  7407. mediaElement.addEventListener('stalled', this.e.onvStalled);
  7408. mediaElement.addEventListener('progress', this.e.onvProgress);
  7409. this._msectl = new _core_mse_controller_js__WEBPACK_IMPORTED_MODULE_6__.default(this._config);
  7410. this._msectl.on(_core_mse_events_js__WEBPACK_IMPORTED_MODULE_7__.default.UPDATE_END, this._onmseUpdateEnd.bind(this));
  7411. this._msectl.on(_core_mse_events_js__WEBPACK_IMPORTED_MODULE_7__.default.BUFFER_FULL, this._onmseBufferFull.bind(this));
  7412. this._msectl.on(_core_mse_events_js__WEBPACK_IMPORTED_MODULE_7__.default.SOURCE_OPEN, function () {
  7413. _this._mseSourceOpened = true;
  7414. if (_this._hasPendingLoad) {
  7415. _this._hasPendingLoad = false;
  7416. _this.load();
  7417. }
  7418. });
  7419. this._msectl.on(_core_mse_events_js__WEBPACK_IMPORTED_MODULE_7__.default.ERROR, function (info) {
  7420. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.ERROR, _player_errors_js__WEBPACK_IMPORTED_MODULE_8__.ErrorTypes.MEDIA_ERROR, _player_errors_js__WEBPACK_IMPORTED_MODULE_8__.ErrorDetails.MEDIA_MSE_ERROR, info);
  7421. });
  7422. this._msectl.attachMediaElement(mediaElement);
  7423. if (this._pendingSeekTime != null) {
  7424. try {
  7425. mediaElement.currentTime = this._pendingSeekTime;
  7426. this._pendingSeekTime = null;
  7427. }
  7428. catch (e) {
  7429. // IE11 may throw InvalidStateError if readyState === 0
  7430. // We can defer set currentTime operation after loadedmetadata
  7431. }
  7432. }
  7433. };
  7434. FlvPlayer.prototype.detachMediaElement = function () {
  7435. if (this._mediaElement) {
  7436. this._msectl.detachMediaElement();
  7437. this._mediaElement.removeEventListener('loadedmetadata', this.e.onvLoadedMetadata);
  7438. this._mediaElement.removeEventListener('seeking', this.e.onvSeeking);
  7439. this._mediaElement.removeEventListener('canplay', this.e.onvCanPlay);
  7440. this._mediaElement.removeEventListener('stalled', this.e.onvStalled);
  7441. this._mediaElement.removeEventListener('progress', this.e.onvProgress);
  7442. this._mediaElement = null;
  7443. }
  7444. if (this._msectl) {
  7445. this._msectl.destroy();
  7446. this._msectl = null;
  7447. }
  7448. };
  7449. FlvPlayer.prototype.load = function () {
  7450. var _this = this;
  7451. if (!this._mediaElement) {
  7452. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_10__.IllegalStateException('HTMLMediaElement must be attached before load()!');
  7453. }
  7454. if (this._transmuxer) {
  7455. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_10__.IllegalStateException('FlvPlayer.load() has been called, please call unload() first!');
  7456. }
  7457. if (this._hasPendingLoad) {
  7458. return;
  7459. }
  7460. if (this._config.deferLoadAfterSourceOpen && this._mseSourceOpened === false) {
  7461. this._hasPendingLoad = true;
  7462. return;
  7463. }
  7464. if (this._mediaElement.readyState > 0) {
  7465. this._requestSetTime = true;
  7466. // IE11 may throw InvalidStateError if readyState === 0
  7467. this._mediaElement.currentTime = 0;
  7468. }
  7469. this._transmuxer = new _core_transmuxer_js__WEBPACK_IMPORTED_MODULE_4__.default(this._mediaDataSource, this._config);
  7470. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.INIT_SEGMENT, function (type, is) {
  7471. _this._msectl.appendInitSegment(is);
  7472. });
  7473. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.MEDIA_SEGMENT, function (type, ms) {
  7474. _this._msectl.appendMediaSegment(ms);
  7475. // lazyLoad check
  7476. if (_this._config.lazyLoad && !_this._config.isLive) {
  7477. var currentTime = _this._mediaElement.currentTime;
  7478. if (ms.info.endDts >= (currentTime + _this._config.lazyLoadMaxDuration) * 1000) {
  7479. if (_this._progressChecker == null) {
  7480. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(_this.TAG, 'Maximum buffering duration exceeded, suspend transmuxing task');
  7481. _this._suspendTransmuxer();
  7482. }
  7483. }
  7484. }
  7485. });
  7486. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.LOADING_COMPLETE, function () {
  7487. _this._msectl.endOfStream();
  7488. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.LOADING_COMPLETE);
  7489. });
  7490. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.RECOVERED_EARLY_EOF, function () {
  7491. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.RECOVERED_EARLY_EOF);
  7492. });
  7493. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.IO_ERROR, function (detail, info) {
  7494. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.ERROR, _player_errors_js__WEBPACK_IMPORTED_MODULE_8__.ErrorTypes.NETWORK_ERROR, detail, info);
  7495. });
  7496. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.DEMUX_ERROR, function (detail, info) {
  7497. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.ERROR, _player_errors_js__WEBPACK_IMPORTED_MODULE_8__.ErrorTypes.MEDIA_ERROR, detail, { code: -1, msg: info });
  7498. });
  7499. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.MEDIA_INFO, function (mediaInfo) {
  7500. _this._mediaInfo = mediaInfo;
  7501. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.MEDIA_INFO, Object.assign({}, mediaInfo));
  7502. });
  7503. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.METADATA_ARRIVED, function (metadata) {
  7504. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.METADATA_ARRIVED, metadata);
  7505. });
  7506. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.SCRIPTDATA_ARRIVED, function (data) {
  7507. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.SCRIPTDATA_ARRIVED, data);
  7508. });
  7509. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.STATISTICS_INFO, function (statInfo) {
  7510. _this._statisticsInfo = _this._fillStatisticsInfo(statInfo);
  7511. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_3__.default.STATISTICS_INFO, Object.assign({}, _this._statisticsInfo));
  7512. });
  7513. this._transmuxer.on(_core_transmuxing_events_js__WEBPACK_IMPORTED_MODULE_5__.default.RECOMMEND_SEEKPOINT, function (milliseconds) {
  7514. if (_this._mediaElement && !_this._config.accurateSeek) {
  7515. _this._requestSetTime = true;
  7516. _this._mediaElement.currentTime = milliseconds / 1000;
  7517. }
  7518. });
  7519. this._transmuxer.open();
  7520. };
  7521. FlvPlayer.prototype.unload = function () {
  7522. if (this._mediaElement) {
  7523. this._mediaElement.pause();
  7524. }
  7525. if (this._msectl) {
  7526. this._msectl.seek(0);
  7527. }
  7528. if (this._transmuxer) {
  7529. this._transmuxer.close();
  7530. this._transmuxer.destroy();
  7531. this._transmuxer = null;
  7532. }
  7533. };
  7534. FlvPlayer.prototype.play = function () {
  7535. return this._mediaElement.play();
  7536. };
  7537. FlvPlayer.prototype.pause = function () {
  7538. this._mediaElement.pause();
  7539. };
  7540. Object.defineProperty(FlvPlayer.prototype, "type", {
  7541. get: function () {
  7542. return this._type;
  7543. },
  7544. enumerable: false,
  7545. configurable: true
  7546. });
  7547. Object.defineProperty(FlvPlayer.prototype, "buffered", {
  7548. get: function () {
  7549. return this._mediaElement.buffered;
  7550. },
  7551. enumerable: false,
  7552. configurable: true
  7553. });
  7554. Object.defineProperty(FlvPlayer.prototype, "duration", {
  7555. get: function () {
  7556. return this._mediaElement.duration;
  7557. },
  7558. enumerable: false,
  7559. configurable: true
  7560. });
  7561. Object.defineProperty(FlvPlayer.prototype, "volume", {
  7562. get: function () {
  7563. return this._mediaElement.volume;
  7564. },
  7565. set: function (value) {
  7566. this._mediaElement.volume = value;
  7567. },
  7568. enumerable: false,
  7569. configurable: true
  7570. });
  7571. Object.defineProperty(FlvPlayer.prototype, "muted", {
  7572. get: function () {
  7573. return this._mediaElement.muted;
  7574. },
  7575. set: function (muted) {
  7576. this._mediaElement.muted = muted;
  7577. },
  7578. enumerable: false,
  7579. configurable: true
  7580. });
  7581. Object.defineProperty(FlvPlayer.prototype, "currentTime", {
  7582. get: function () {
  7583. if (this._mediaElement) {
  7584. return this._mediaElement.currentTime;
  7585. }
  7586. return 0;
  7587. },
  7588. set: function (seconds) {
  7589. if (this._mediaElement) {
  7590. this._internalSeek(seconds);
  7591. }
  7592. else {
  7593. this._pendingSeekTime = seconds;
  7594. }
  7595. },
  7596. enumerable: false,
  7597. configurable: true
  7598. });
  7599. Object.defineProperty(FlvPlayer.prototype, "mediaInfo", {
  7600. get: function () {
  7601. return Object.assign({}, this._mediaInfo);
  7602. },
  7603. enumerable: false,
  7604. configurable: true
  7605. });
  7606. Object.defineProperty(FlvPlayer.prototype, "statisticsInfo", {
  7607. get: function () {
  7608. if (this._statisticsInfo == null) {
  7609. this._statisticsInfo = {};
  7610. }
  7611. this._statisticsInfo = this._fillStatisticsInfo(this._statisticsInfo);
  7612. return Object.assign({}, this._statisticsInfo);
  7613. },
  7614. enumerable: false,
  7615. configurable: true
  7616. });
  7617. FlvPlayer.prototype._fillStatisticsInfo = function (statInfo) {
  7618. statInfo.playerType = this._type;
  7619. if (!(this._mediaElement instanceof HTMLVideoElement)) {
  7620. return statInfo;
  7621. }
  7622. var hasQualityInfo = true;
  7623. var decoded = 0;
  7624. var dropped = 0;
  7625. if (this._mediaElement.getVideoPlaybackQuality) {
  7626. var quality = this._mediaElement.getVideoPlaybackQuality();
  7627. decoded = quality.totalVideoFrames;
  7628. dropped = quality.droppedVideoFrames;
  7629. }
  7630. else if (this._mediaElement.webkitDecodedFrameCount != undefined) {
  7631. decoded = this._mediaElement.webkitDecodedFrameCount;
  7632. dropped = this._mediaElement.webkitDroppedFrameCount;
  7633. }
  7634. else {
  7635. hasQualityInfo = false;
  7636. }
  7637. if (hasQualityInfo) {
  7638. statInfo.decodedFrames = decoded;
  7639. statInfo.droppedFrames = dropped;
  7640. }
  7641. return statInfo;
  7642. };
  7643. FlvPlayer.prototype._onmseUpdateEnd = function () {
  7644. if (!this._config.lazyLoad || this._config.isLive) {
  7645. return;
  7646. }
  7647. var buffered = this._mediaElement.buffered;
  7648. var currentTime = this._mediaElement.currentTime;
  7649. var currentRangeStart = 0;
  7650. var currentRangeEnd = 0;
  7651. for (var i = 0; i < buffered.length; i++) {
  7652. var start = buffered.start(i);
  7653. var end = buffered.end(i);
  7654. if (start <= currentTime && currentTime < end) {
  7655. currentRangeStart = start;
  7656. currentRangeEnd = end;
  7657. break;
  7658. }
  7659. }
  7660. if (currentRangeEnd >= currentTime + this._config.lazyLoadMaxDuration && this._progressChecker == null) {
  7661. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, 'Maximum buffering duration exceeded, suspend transmuxing task');
  7662. this._suspendTransmuxer();
  7663. }
  7664. };
  7665. FlvPlayer.prototype._onmseBufferFull = function () {
  7666. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, 'MSE SourceBuffer is full, suspend transmuxing task');
  7667. if (this._progressChecker == null) {
  7668. this._suspendTransmuxer();
  7669. }
  7670. };
  7671. FlvPlayer.prototype._suspendTransmuxer = function () {
  7672. if (this._transmuxer) {
  7673. this._transmuxer.pause();
  7674. if (this._progressChecker == null) {
  7675. this._progressChecker = window.setInterval(this._checkProgressAndResume.bind(this), 1000);
  7676. }
  7677. }
  7678. };
  7679. FlvPlayer.prototype._checkProgressAndResume = function () {
  7680. var currentTime = this._mediaElement.currentTime;
  7681. var buffered = this._mediaElement.buffered;
  7682. var needResume = false;
  7683. for (var i = 0; i < buffered.length; i++) {
  7684. var from = buffered.start(i);
  7685. var to = buffered.end(i);
  7686. if (currentTime >= from && currentTime < to) {
  7687. if (currentTime >= to - this._config.lazyLoadRecoverDuration) {
  7688. needResume = true;
  7689. }
  7690. break;
  7691. }
  7692. }
  7693. if (needResume) {
  7694. window.clearInterval(this._progressChecker);
  7695. this._progressChecker = null;
  7696. if (needResume) {
  7697. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.v(this.TAG, 'Continue loading from paused position');
  7698. this._transmuxer.resume();
  7699. }
  7700. }
  7701. };
  7702. FlvPlayer.prototype._isTimepointBuffered = function (seconds) {
  7703. var buffered = this._mediaElement.buffered;
  7704. for (var i = 0; i < buffered.length; i++) {
  7705. var from = buffered.start(i);
  7706. var to = buffered.end(i);
  7707. if (seconds >= from && seconds < to) {
  7708. return true;
  7709. }
  7710. }
  7711. return false;
  7712. };
  7713. FlvPlayer.prototype._internalSeek = function (seconds) {
  7714. var directSeek = this._isTimepointBuffered(seconds);
  7715. var directSeekBegin = false;
  7716. var directSeekBeginTime = 0;
  7717. if (seconds < 1.0 && this._mediaElement.buffered.length > 0) {
  7718. var videoBeginTime = this._mediaElement.buffered.start(0);
  7719. if ((videoBeginTime < 1.0 && seconds < videoBeginTime) || _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.safari) {
  7720. directSeekBegin = true;
  7721. // also workaround for Safari: Seek to 0 may cause video stuck, use 0.1 to avoid
  7722. directSeekBeginTime = _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.safari ? 0.1 : videoBeginTime;
  7723. }
  7724. }
  7725. if (directSeekBegin) { // seek to video begin, set currentTime directly if beginPTS buffered
  7726. this._requestSetTime = true;
  7727. this._mediaElement.currentTime = directSeekBeginTime;
  7728. }
  7729. else if (directSeek) { // buffered position
  7730. if (!this._alwaysSeekKeyframe) {
  7731. this._requestSetTime = true;
  7732. this._mediaElement.currentTime = seconds;
  7733. }
  7734. else {
  7735. var idr = this._msectl.getNearestKeyframe(Math.floor(seconds * 1000));
  7736. this._requestSetTime = true;
  7737. if (idr != null) {
  7738. this._mediaElement.currentTime = idr.dts / 1000;
  7739. }
  7740. else {
  7741. this._mediaElement.currentTime = seconds;
  7742. }
  7743. }
  7744. if (this._progressChecker != null) {
  7745. this._checkProgressAndResume();
  7746. }
  7747. }
  7748. else {
  7749. if (this._progressChecker != null) {
  7750. window.clearInterval(this._progressChecker);
  7751. this._progressChecker = null;
  7752. }
  7753. this._msectl.seek(seconds);
  7754. this._transmuxer.seek(Math.floor(seconds * 1000)); // in milliseconds
  7755. // no need to set mediaElement.currentTime if non-accurateSeek,
  7756. // just wait for the recommend_seekpoint callback
  7757. if (this._config.accurateSeek) {
  7758. this._requestSetTime = true;
  7759. this._mediaElement.currentTime = seconds;
  7760. }
  7761. }
  7762. };
  7763. FlvPlayer.prototype._checkAndApplyUnbufferedSeekpoint = function () {
  7764. if (this._seekpointRecord) {
  7765. if (this._seekpointRecord.recordTime <= this._now() - 100) {
  7766. var target = this._mediaElement.currentTime;
  7767. this._seekpointRecord = null;
  7768. if (!this._isTimepointBuffered(target)) {
  7769. if (this._progressChecker != null) {
  7770. window.clearTimeout(this._progressChecker);
  7771. this._progressChecker = null;
  7772. }
  7773. // .currentTime is consists with .buffered timestamp
  7774. // Chrome/Edge use DTS, while FireFox/Safari use PTS
  7775. this._msectl.seek(target);
  7776. this._transmuxer.seek(Math.floor(target * 1000));
  7777. // set currentTime if accurateSeek, or wait for recommend_seekpoint callback
  7778. if (this._config.accurateSeek) {
  7779. this._requestSetTime = true;
  7780. this._mediaElement.currentTime = target;
  7781. }
  7782. }
  7783. }
  7784. else {
  7785. window.setTimeout(this._checkAndApplyUnbufferedSeekpoint.bind(this), 50);
  7786. }
  7787. }
  7788. };
  7789. FlvPlayer.prototype._checkAndResumeStuckPlayback = function (stalled) {
  7790. var media = this._mediaElement;
  7791. if (stalled || !this._receivedCanPlay || media.readyState < 2) { // HAVE_CURRENT_DATA
  7792. var buffered = media.buffered;
  7793. if (buffered.length > 0 && media.currentTime < buffered.start(0)) {
  7794. _utils_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.w(this.TAG, "Playback seems stuck at " + media.currentTime + ", seek to " + buffered.start(0));
  7795. this._requestSetTime = true;
  7796. this._mediaElement.currentTime = buffered.start(0);
  7797. this._mediaElement.removeEventListener('progress', this.e.onvProgress);
  7798. }
  7799. }
  7800. else {
  7801. // Playback didn't stuck, remove progress event listener
  7802. this._mediaElement.removeEventListener('progress', this.e.onvProgress);
  7803. }
  7804. };
  7805. FlvPlayer.prototype._onvLoadedMetadata = function (e) {
  7806. if (this._pendingSeekTime != null) {
  7807. this._mediaElement.currentTime = this._pendingSeekTime;
  7808. this._pendingSeekTime = null;
  7809. }
  7810. };
  7811. FlvPlayer.prototype._onvSeeking = function (e) {
  7812. var target = this._mediaElement.currentTime;
  7813. var buffered = this._mediaElement.buffered;
  7814. if (this._requestSetTime) {
  7815. this._requestSetTime = false;
  7816. return;
  7817. }
  7818. if (target < 1.0 && buffered.length > 0) {
  7819. // seek to video begin, set currentTime directly if beginPTS buffered
  7820. var videoBeginTime = buffered.start(0);
  7821. if ((videoBeginTime < 1.0 && target < videoBeginTime) || _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.safari) {
  7822. this._requestSetTime = true;
  7823. // also workaround for Safari: Seek to 0 may cause video stuck, use 0.1 to avoid
  7824. this._mediaElement.currentTime = _utils_browser_js__WEBPACK_IMPORTED_MODULE_2__.default.safari ? 0.1 : videoBeginTime;
  7825. return;
  7826. }
  7827. }
  7828. if (this._isTimepointBuffered(target)) {
  7829. if (this._alwaysSeekKeyframe) {
  7830. var idr = this._msectl.getNearestKeyframe(Math.floor(target * 1000));
  7831. if (idr != null) {
  7832. this._requestSetTime = true;
  7833. this._mediaElement.currentTime = idr.dts / 1000;
  7834. }
  7835. }
  7836. if (this._progressChecker != null) {
  7837. this._checkProgressAndResume();
  7838. }
  7839. return;
  7840. }
  7841. this._seekpointRecord = {
  7842. seekPoint: target,
  7843. recordTime: this._now()
  7844. };
  7845. window.setTimeout(this._checkAndApplyUnbufferedSeekpoint.bind(this), 50);
  7846. };
  7847. FlvPlayer.prototype._onvCanPlay = function (e) {
  7848. this._receivedCanPlay = true;
  7849. this._mediaElement.removeEventListener('canplay', this.e.onvCanPlay);
  7850. };
  7851. FlvPlayer.prototype._onvStalled = function (e) {
  7852. this._checkAndResumeStuckPlayback(true);
  7853. };
  7854. FlvPlayer.prototype._onvProgress = function (e) {
  7855. this._checkAndResumeStuckPlayback();
  7856. };
  7857. return FlvPlayer;
  7858. }());
  7859. /* harmony default export */ __webpack_exports__["default"] = (FlvPlayer);
  7860. /***/ }),
  7861. /***/ "./src/player/native-player.js":
  7862. /*!*************************************!*\
  7863. !*** ./src/player/native-player.js ***!
  7864. \*************************************/
  7865. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  7866. "use strict";
  7867. __webpack_require__.r(__webpack_exports__);
  7868. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! events */ "./node_modules/events/events.js");
  7869. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(events__WEBPACK_IMPORTED_MODULE_0__);
  7870. /* harmony import */ var _player_events_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./player-events.js */ "./src/player/player-events.js");
  7871. /* harmony import */ var _config_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../config.js */ "./src/config.js");
  7872. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  7873. /*
  7874. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  7875. *
  7876. * @author zheng qian <xqq@xqq.im>
  7877. *
  7878. * Licensed under the Apache License, Version 2.0 (the "License");
  7879. * you may not use this file except in compliance with the License.
  7880. * You may obtain a copy of the License at
  7881. *
  7882. * http://www.apache.org/licenses/LICENSE-2.0
  7883. *
  7884. * Unless required by applicable law or agreed to in writing, software
  7885. * distributed under the License is distributed on an "AS IS" BASIS,
  7886. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7887. * See the License for the specific language governing permissions and
  7888. * limitations under the License.
  7889. */
  7890. // Player wrapper for browser's native player (HTMLVideoElement) without MediaSource src.
  7891. var NativePlayer = /** @class */ (function () {
  7892. function NativePlayer(mediaDataSource, config) {
  7893. this.TAG = 'NativePlayer';
  7894. this._type = 'NativePlayer';
  7895. this._emitter = new (events__WEBPACK_IMPORTED_MODULE_0___default())();
  7896. this._config = (0,_config_js__WEBPACK_IMPORTED_MODULE_2__.createDefaultConfig)();
  7897. if (typeof config === 'object') {
  7898. Object.assign(this._config, config);
  7899. }
  7900. if (mediaDataSource.type.toLowerCase() === 'flv') {
  7901. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_3__.InvalidArgumentException('NativePlayer does\'t support flv MediaDataSource input!');
  7902. }
  7903. if (mediaDataSource.hasOwnProperty('segments')) {
  7904. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_3__.InvalidArgumentException("NativePlayer(" + mediaDataSource.type + ") doesn't support multipart playback!");
  7905. }
  7906. this.e = {
  7907. onvLoadedMetadata: this._onvLoadedMetadata.bind(this)
  7908. };
  7909. this._pendingSeekTime = null;
  7910. this._statisticsReporter = null;
  7911. this._mediaDataSource = mediaDataSource;
  7912. this._mediaElement = null;
  7913. }
  7914. NativePlayer.prototype.destroy = function () {
  7915. if (this._mediaElement) {
  7916. this.unload();
  7917. this.detachMediaElement();
  7918. }
  7919. this.e = null;
  7920. this._mediaDataSource = null;
  7921. this._emitter.removeAllListeners();
  7922. this._emitter = null;
  7923. };
  7924. NativePlayer.prototype.on = function (event, listener) {
  7925. var _this = this;
  7926. if (event === _player_events_js__WEBPACK_IMPORTED_MODULE_1__.default.MEDIA_INFO) {
  7927. if (this._mediaElement != null && this._mediaElement.readyState !== 0) { // HAVE_NOTHING
  7928. Promise.resolve().then(function () {
  7929. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_1__.default.MEDIA_INFO, _this.mediaInfo);
  7930. });
  7931. }
  7932. }
  7933. else if (event === _player_events_js__WEBPACK_IMPORTED_MODULE_1__.default.STATISTICS_INFO) {
  7934. if (this._mediaElement != null && this._mediaElement.readyState !== 0) {
  7935. Promise.resolve().then(function () {
  7936. _this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_1__.default.STATISTICS_INFO, _this.statisticsInfo);
  7937. });
  7938. }
  7939. }
  7940. this._emitter.addListener(event, listener);
  7941. };
  7942. NativePlayer.prototype.off = function (event, listener) {
  7943. this._emitter.removeListener(event, listener);
  7944. };
  7945. NativePlayer.prototype.attachMediaElement = function (mediaElement) {
  7946. this._mediaElement = mediaElement;
  7947. mediaElement.addEventListener('loadedmetadata', this.e.onvLoadedMetadata);
  7948. if (this._pendingSeekTime != null) {
  7949. try {
  7950. mediaElement.currentTime = this._pendingSeekTime;
  7951. this._pendingSeekTime = null;
  7952. }
  7953. catch (e) {
  7954. // IE11 may throw InvalidStateError if readyState === 0
  7955. // Defer set currentTime operation after loadedmetadata
  7956. }
  7957. }
  7958. };
  7959. NativePlayer.prototype.detachMediaElement = function () {
  7960. if (this._mediaElement) {
  7961. this._mediaElement.src = '';
  7962. this._mediaElement.removeAttribute('src');
  7963. this._mediaElement.removeEventListener('loadedmetadata', this.e.onvLoadedMetadata);
  7964. this._mediaElement = null;
  7965. }
  7966. if (this._statisticsReporter != null) {
  7967. window.clearInterval(this._statisticsReporter);
  7968. this._statisticsReporter = null;
  7969. }
  7970. };
  7971. NativePlayer.prototype.load = function () {
  7972. if (!this._mediaElement) {
  7973. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_3__.IllegalStateException('HTMLMediaElement must be attached before load()!');
  7974. }
  7975. this._mediaElement.src = this._mediaDataSource.url;
  7976. if (this._mediaElement.readyState > 0) {
  7977. this._mediaElement.currentTime = 0;
  7978. }
  7979. this._mediaElement.preload = 'auto';
  7980. this._mediaElement.load();
  7981. this._statisticsReporter = window.setInterval(this._reportStatisticsInfo.bind(this), this._config.statisticsInfoReportInterval);
  7982. };
  7983. NativePlayer.prototype.unload = function () {
  7984. if (this._mediaElement) {
  7985. this._mediaElement.src = '';
  7986. this._mediaElement.removeAttribute('src');
  7987. }
  7988. if (this._statisticsReporter != null) {
  7989. window.clearInterval(this._statisticsReporter);
  7990. this._statisticsReporter = null;
  7991. }
  7992. };
  7993. NativePlayer.prototype.play = function () {
  7994. return this._mediaElement.play();
  7995. };
  7996. NativePlayer.prototype.pause = function () {
  7997. this._mediaElement.pause();
  7998. };
  7999. Object.defineProperty(NativePlayer.prototype, "type", {
  8000. get: function () {
  8001. return this._type;
  8002. },
  8003. enumerable: false,
  8004. configurable: true
  8005. });
  8006. Object.defineProperty(NativePlayer.prototype, "buffered", {
  8007. get: function () {
  8008. return this._mediaElement.buffered;
  8009. },
  8010. enumerable: false,
  8011. configurable: true
  8012. });
  8013. Object.defineProperty(NativePlayer.prototype, "duration", {
  8014. get: function () {
  8015. return this._mediaElement.duration;
  8016. },
  8017. enumerable: false,
  8018. configurable: true
  8019. });
  8020. Object.defineProperty(NativePlayer.prototype, "volume", {
  8021. get: function () {
  8022. return this._mediaElement.volume;
  8023. },
  8024. set: function (value) {
  8025. this._mediaElement.volume = value;
  8026. },
  8027. enumerable: false,
  8028. configurable: true
  8029. });
  8030. Object.defineProperty(NativePlayer.prototype, "muted", {
  8031. get: function () {
  8032. return this._mediaElement.muted;
  8033. },
  8034. set: function (muted) {
  8035. this._mediaElement.muted = muted;
  8036. },
  8037. enumerable: false,
  8038. configurable: true
  8039. });
  8040. Object.defineProperty(NativePlayer.prototype, "currentTime", {
  8041. get: function () {
  8042. if (this._mediaElement) {
  8043. return this._mediaElement.currentTime;
  8044. }
  8045. return 0;
  8046. },
  8047. set: function (seconds) {
  8048. if (this._mediaElement) {
  8049. this._mediaElement.currentTime = seconds;
  8050. }
  8051. else {
  8052. this._pendingSeekTime = seconds;
  8053. }
  8054. },
  8055. enumerable: false,
  8056. configurable: true
  8057. });
  8058. Object.defineProperty(NativePlayer.prototype, "mediaInfo", {
  8059. get: function () {
  8060. var mediaPrefix = (this._mediaElement instanceof HTMLAudioElement) ? 'audio/' : 'video/';
  8061. var info = {
  8062. mimeType: mediaPrefix + this._mediaDataSource.type
  8063. };
  8064. if (this._mediaElement) {
  8065. info.duration = Math.floor(this._mediaElement.duration * 1000);
  8066. if (this._mediaElement instanceof HTMLVideoElement) {
  8067. info.width = this._mediaElement.videoWidth;
  8068. info.height = this._mediaElement.videoHeight;
  8069. }
  8070. }
  8071. return info;
  8072. },
  8073. enumerable: false,
  8074. configurable: true
  8075. });
  8076. Object.defineProperty(NativePlayer.prototype, "statisticsInfo", {
  8077. get: function () {
  8078. var info = {
  8079. playerType: this._type,
  8080. url: this._mediaDataSource.url
  8081. };
  8082. if (!(this._mediaElement instanceof HTMLVideoElement)) {
  8083. return info;
  8084. }
  8085. var hasQualityInfo = true;
  8086. var decoded = 0;
  8087. var dropped = 0;
  8088. if (this._mediaElement.getVideoPlaybackQuality) {
  8089. var quality = this._mediaElement.getVideoPlaybackQuality();
  8090. decoded = quality.totalVideoFrames;
  8091. dropped = quality.droppedVideoFrames;
  8092. }
  8093. else if (this._mediaElement.webkitDecodedFrameCount != undefined) {
  8094. decoded = this._mediaElement.webkitDecodedFrameCount;
  8095. dropped = this._mediaElement.webkitDroppedFrameCount;
  8096. }
  8097. else {
  8098. hasQualityInfo = false;
  8099. }
  8100. if (hasQualityInfo) {
  8101. info.decodedFrames = decoded;
  8102. info.droppedFrames = dropped;
  8103. }
  8104. return info;
  8105. },
  8106. enumerable: false,
  8107. configurable: true
  8108. });
  8109. NativePlayer.prototype._onvLoadedMetadata = function (e) {
  8110. if (this._pendingSeekTime != null) {
  8111. this._mediaElement.currentTime = this._pendingSeekTime;
  8112. this._pendingSeekTime = null;
  8113. }
  8114. this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_1__.default.MEDIA_INFO, this.mediaInfo);
  8115. };
  8116. NativePlayer.prototype._reportStatisticsInfo = function () {
  8117. this._emitter.emit(_player_events_js__WEBPACK_IMPORTED_MODULE_1__.default.STATISTICS_INFO, this.statisticsInfo);
  8118. };
  8119. return NativePlayer;
  8120. }());
  8121. /* harmony default export */ __webpack_exports__["default"] = (NativePlayer);
  8122. /***/ }),
  8123. /***/ "./src/player/player-errors.js":
  8124. /*!*************************************!*\
  8125. !*** ./src/player/player-errors.js ***!
  8126. \*************************************/
  8127. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  8128. "use strict";
  8129. __webpack_require__.r(__webpack_exports__);
  8130. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  8131. /* harmony export */ "ErrorTypes": function() { return /* binding */ ErrorTypes; },
  8132. /* harmony export */ "ErrorDetails": function() { return /* binding */ ErrorDetails; }
  8133. /* harmony export */ });
  8134. /* harmony import */ var _io_loader_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../io/loader.js */ "./src/io/loader.js");
  8135. /* harmony import */ var _demux_demux_errors_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../demux/demux-errors.js */ "./src/demux/demux-errors.js");
  8136. /*
  8137. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  8138. *
  8139. * @author zheng qian <xqq@xqq.im>
  8140. *
  8141. * Licensed under the Apache License, Version 2.0 (the "License");
  8142. * you may not use this file except in compliance with the License.
  8143. * You may obtain a copy of the License at
  8144. *
  8145. * http://www.apache.org/licenses/LICENSE-2.0
  8146. *
  8147. * Unless required by applicable law or agreed to in writing, software
  8148. * distributed under the License is distributed on an "AS IS" BASIS,
  8149. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8150. * See the License for the specific language governing permissions and
  8151. * limitations under the License.
  8152. */
  8153. var ErrorTypes = {
  8154. NETWORK_ERROR: 'NetworkError',
  8155. MEDIA_ERROR: 'MediaError',
  8156. OTHER_ERROR: 'OtherError'
  8157. };
  8158. var ErrorDetails = {
  8159. NETWORK_EXCEPTION: _io_loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderErrors.EXCEPTION,
  8160. NETWORK_STATUS_CODE_INVALID: _io_loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderErrors.HTTP_STATUS_CODE_INVALID,
  8161. NETWORK_TIMEOUT: _io_loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderErrors.CONNECTING_TIMEOUT,
  8162. NETWORK_UNRECOVERABLE_EARLY_EOF: _io_loader_js__WEBPACK_IMPORTED_MODULE_0__.LoaderErrors.UNRECOVERABLE_EARLY_EOF,
  8163. MEDIA_MSE_ERROR: 'MediaMSEError',
  8164. MEDIA_FORMAT_ERROR: _demux_demux_errors_js__WEBPACK_IMPORTED_MODULE_1__.default.FORMAT_ERROR,
  8165. MEDIA_FORMAT_UNSUPPORTED: _demux_demux_errors_js__WEBPACK_IMPORTED_MODULE_1__.default.FORMAT_UNSUPPORTED,
  8166. MEDIA_CODEC_UNSUPPORTED: _demux_demux_errors_js__WEBPACK_IMPORTED_MODULE_1__.default.CODEC_UNSUPPORTED
  8167. };
  8168. /***/ }),
  8169. /***/ "./src/player/player-events.js":
  8170. /*!*************************************!*\
  8171. !*** ./src/player/player-events.js ***!
  8172. \*************************************/
  8173. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  8174. "use strict";
  8175. __webpack_require__.r(__webpack_exports__);
  8176. /*
  8177. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  8178. *
  8179. * @author zheng qian <xqq@xqq.im>
  8180. *
  8181. * Licensed under the Apache License, Version 2.0 (the "License");
  8182. * you may not use this file except in compliance with the License.
  8183. * You may obtain a copy of the License at
  8184. *
  8185. * http://www.apache.org/licenses/LICENSE-2.0
  8186. *
  8187. * Unless required by applicable law or agreed to in writing, software
  8188. * distributed under the License is distributed on an "AS IS" BASIS,
  8189. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8190. * See the License for the specific language governing permissions and
  8191. * limitations under the License.
  8192. */
  8193. var PlayerEvents = {
  8194. ERROR: 'error',
  8195. LOADING_COMPLETE: 'loading_complete',
  8196. RECOVERED_EARLY_EOF: 'recovered_early_eof',
  8197. MEDIA_INFO: 'media_info',
  8198. METADATA_ARRIVED: 'metadata_arrived',
  8199. SCRIPTDATA_ARRIVED: 'scriptdata_arrived',
  8200. STATISTICS_INFO: 'statistics_info'
  8201. };
  8202. /* harmony default export */ __webpack_exports__["default"] = (PlayerEvents);
  8203. /***/ }),
  8204. /***/ "./src/remux/aac-silent.js":
  8205. /*!*********************************!*\
  8206. !*** ./src/remux/aac-silent.js ***!
  8207. \*********************************/
  8208. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  8209. "use strict";
  8210. __webpack_require__.r(__webpack_exports__);
  8211. /*
  8212. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  8213. *
  8214. * This file is modified from dailymotion's hls.js library (hls.js/src/helper/aac.js)
  8215. * @author zheng qian <xqq@xqq.im>
  8216. *
  8217. * Licensed under the Apache License, Version 2.0 (the "License");
  8218. * you may not use this file except in compliance with the License.
  8219. * You may obtain a copy of the License at
  8220. *
  8221. * http://www.apache.org/licenses/LICENSE-2.0
  8222. *
  8223. * Unless required by applicable law or agreed to in writing, software
  8224. * distributed under the License is distributed on an "AS IS" BASIS,
  8225. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8226. * See the License for the specific language governing permissions and
  8227. * limitations under the License.
  8228. */
  8229. var AAC = /** @class */ (function () {
  8230. function AAC() {
  8231. }
  8232. AAC.getSilentFrame = function (codec, channelCount) {
  8233. if (codec === 'mp4a.40.2') {
  8234. // handle LC-AAC
  8235. if (channelCount === 1) {
  8236. return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x23, 0x80]);
  8237. }
  8238. else if (channelCount === 2) {
  8239. return new Uint8Array([0x21, 0x00, 0x49, 0x90, 0x02, 0x19, 0x00, 0x23, 0x80]);
  8240. }
  8241. else if (channelCount === 3) {
  8242. return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x20, 0x84, 0x01, 0x26, 0x40, 0x08, 0x64, 0x00, 0x8e]);
  8243. }
  8244. else if (channelCount === 4) {
  8245. return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x20, 0x84, 0x01, 0x26, 0x40, 0x08, 0x64, 0x00, 0x80, 0x2c, 0x80, 0x08, 0x02, 0x38]);
  8246. }
  8247. else if (channelCount === 5) {
  8248. return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x20, 0x84, 0x01, 0x26, 0x40, 0x08, 0x64, 0x00, 0x82, 0x30, 0x04, 0x99, 0x00, 0x21, 0x90, 0x02, 0x38]);
  8249. }
  8250. else if (channelCount === 6) {
  8251. return new Uint8Array([0x00, 0xc8, 0x00, 0x80, 0x20, 0x84, 0x01, 0x26, 0x40, 0x08, 0x64, 0x00, 0x82, 0x30, 0x04, 0x99, 0x00, 0x21, 0x90, 0x02, 0x00, 0xb2, 0x00, 0x20, 0x08, 0xe0]);
  8252. }
  8253. }
  8254. else {
  8255. // handle HE-AAC (mp4a.40.5 / mp4a.40.29)
  8256. if (channelCount === 1) {
  8257. // ffmpeg -y -f lavfi -i "aevalsrc=0:d=0.05" -c:a libfdk_aac -profile:a aac_he -b:a 4k output.aac && hexdump -v -e '16/1 "0x%x," "\n"' -v output.aac
  8258. return new Uint8Array([0x1, 0x40, 0x22, 0x80, 0xa3, 0x4e, 0xe6, 0x80, 0xba, 0x8, 0x0, 0x0, 0x0, 0x1c, 0x6, 0xf1, 0xc1, 0xa, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e]);
  8259. }
  8260. else if (channelCount === 2) {
  8261. // ffmpeg -y -f lavfi -i "aevalsrc=0|0:d=0.05" -c:a libfdk_aac -profile:a aac_he_v2 -b:a 4k output.aac && hexdump -v -e '16/1 "0x%x," "\n"' -v output.aac
  8262. return new Uint8Array([0x1, 0x40, 0x22, 0x80, 0xa3, 0x5e, 0xe6, 0x80, 0xba, 0x8, 0x0, 0x0, 0x0, 0x0, 0x95, 0x0, 0x6, 0xf1, 0xa1, 0xa, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e]);
  8263. }
  8264. else if (channelCount === 3) {
  8265. // ffmpeg -y -f lavfi -i "aevalsrc=0|0|0:d=0.05" -c:a libfdk_aac -profile:a aac_he_v2 -b:a 4k output.aac && hexdump -v -e '16/1 "0x%x," "\n"' -v output.aac
  8266. return new Uint8Array([0x1, 0x40, 0x22, 0x80, 0xa3, 0x5e, 0xe6, 0x80, 0xba, 0x8, 0x0, 0x0, 0x0, 0x0, 0x95, 0x0, 0x6, 0xf1, 0xa1, 0xa, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e]);
  8267. }
  8268. }
  8269. return null;
  8270. };
  8271. return AAC;
  8272. }());
  8273. /* harmony default export */ __webpack_exports__["default"] = (AAC);
  8274. /***/ }),
  8275. /***/ "./src/remux/mp4-generator.js":
  8276. /*!************************************!*\
  8277. !*** ./src/remux/mp4-generator.js ***!
  8278. \************************************/
  8279. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  8280. "use strict";
  8281. __webpack_require__.r(__webpack_exports__);
  8282. /*
  8283. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  8284. *
  8285. * This file is derived from dailymotion's hls.js library (hls.js/src/remux/mp4-generator.js)
  8286. * @author zheng qian <xqq@xqq.im>
  8287. *
  8288. * Licensed under the Apache License, Version 2.0 (the "License");
  8289. * you may not use this file except in compliance with the License.
  8290. * You may obtain a copy of the License at
  8291. *
  8292. * http://www.apache.org/licenses/LICENSE-2.0
  8293. *
  8294. * Unless required by applicable law or agreed to in writing, software
  8295. * distributed under the License is distributed on an "AS IS" BASIS,
  8296. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8297. * See the License for the specific language governing permissions and
  8298. * limitations under the License.
  8299. */
  8300. // MP4 boxes generator for ISO BMFF (ISO Base Media File Format, defined in ISO/IEC 14496-12)
  8301. var MP4 = /** @class */ (function () {
  8302. function MP4() {
  8303. }
  8304. MP4.init = function () {
  8305. MP4.types = {
  8306. avc1: [], avcC: [], btrt: [], dinf: [],
  8307. dref: [], esds: [], ftyp: [], hdlr: [],
  8308. mdat: [], mdhd: [], mdia: [], mfhd: [],
  8309. minf: [], moof: [], moov: [], mp4a: [],
  8310. mvex: [], mvhd: [], sdtp: [], stbl: [],
  8311. stco: [], stsc: [], stsd: [], stsz: [],
  8312. stts: [], tfdt: [], tfhd: [], traf: [],
  8313. trak: [], trun: [], trex: [], tkhd: [],
  8314. vmhd: [], smhd: [], '.mp3': []
  8315. };
  8316. for (var name_1 in MP4.types) {
  8317. if (MP4.types.hasOwnProperty(name_1)) {
  8318. MP4.types[name_1] = [
  8319. name_1.charCodeAt(0),
  8320. name_1.charCodeAt(1),
  8321. name_1.charCodeAt(2),
  8322. name_1.charCodeAt(3)
  8323. ];
  8324. }
  8325. }
  8326. var constants = MP4.constants = {};
  8327. constants.FTYP = new Uint8Array([
  8328. 0x69, 0x73, 0x6F, 0x6D,
  8329. 0x0, 0x0, 0x0, 0x1,
  8330. 0x69, 0x73, 0x6F, 0x6D,
  8331. 0x61, 0x76, 0x63, 0x31 // avc1
  8332. ]);
  8333. constants.STSD_PREFIX = new Uint8Array([
  8334. 0x00, 0x00, 0x00, 0x00,
  8335. 0x00, 0x00, 0x00, 0x01 // entry_count
  8336. ]);
  8337. constants.STTS = new Uint8Array([
  8338. 0x00, 0x00, 0x00, 0x00,
  8339. 0x00, 0x00, 0x00, 0x00 // entry_count
  8340. ]);
  8341. constants.STSC = constants.STCO = constants.STTS;
  8342. constants.STSZ = new Uint8Array([
  8343. 0x00, 0x00, 0x00, 0x00,
  8344. 0x00, 0x00, 0x00, 0x00,
  8345. 0x00, 0x00, 0x00, 0x00 // sample_count
  8346. ]);
  8347. constants.HDLR_VIDEO = new Uint8Array([
  8348. 0x00, 0x00, 0x00, 0x00,
  8349. 0x00, 0x00, 0x00, 0x00,
  8350. 0x76, 0x69, 0x64, 0x65,
  8351. 0x00, 0x00, 0x00, 0x00,
  8352. 0x00, 0x00, 0x00, 0x00,
  8353. 0x00, 0x00, 0x00, 0x00,
  8354. 0x56, 0x69, 0x64, 0x65,
  8355. 0x6F, 0x48, 0x61, 0x6E,
  8356. 0x64, 0x6C, 0x65, 0x72, 0x00 // name: VideoHandler
  8357. ]);
  8358. constants.HDLR_AUDIO = new Uint8Array([
  8359. 0x00, 0x00, 0x00, 0x00,
  8360. 0x00, 0x00, 0x00, 0x00,
  8361. 0x73, 0x6F, 0x75, 0x6E,
  8362. 0x00, 0x00, 0x00, 0x00,
  8363. 0x00, 0x00, 0x00, 0x00,
  8364. 0x00, 0x00, 0x00, 0x00,
  8365. 0x53, 0x6F, 0x75, 0x6E,
  8366. 0x64, 0x48, 0x61, 0x6E,
  8367. 0x64, 0x6C, 0x65, 0x72, 0x00 // name: SoundHandler
  8368. ]);
  8369. constants.DREF = new Uint8Array([
  8370. 0x00, 0x00, 0x00, 0x00,
  8371. 0x00, 0x00, 0x00, 0x01,
  8372. 0x00, 0x00, 0x00, 0x0C,
  8373. 0x75, 0x72, 0x6C, 0x20,
  8374. 0x00, 0x00, 0x00, 0x01 // version(0) + flags
  8375. ]);
  8376. // Sound media header
  8377. constants.SMHD = new Uint8Array([
  8378. 0x00, 0x00, 0x00, 0x00,
  8379. 0x00, 0x00, 0x00, 0x00 // balance(2) + reserved(2)
  8380. ]);
  8381. // video media header
  8382. constants.VMHD = new Uint8Array([
  8383. 0x00, 0x00, 0x00, 0x01,
  8384. 0x00, 0x00,
  8385. 0x00, 0x00, 0x00, 0x00,
  8386. 0x00, 0x00
  8387. ]);
  8388. };
  8389. // Generate a box
  8390. MP4.box = function (type) {
  8391. var size = 8;
  8392. var result = null;
  8393. var datas = Array.prototype.slice.call(arguments, 1);
  8394. var arrayCount = datas.length;
  8395. for (var i = 0; i < arrayCount; i++) {
  8396. size += datas[i].byteLength;
  8397. }
  8398. result = new Uint8Array(size);
  8399. result[0] = (size >>> 24) & 0xFF; // size
  8400. result[1] = (size >>> 16) & 0xFF;
  8401. result[2] = (size >>> 8) & 0xFF;
  8402. result[3] = (size) & 0xFF;
  8403. result.set(type, 4); // type
  8404. var offset = 8;
  8405. for (var i = 0; i < arrayCount; i++) { // data body
  8406. result.set(datas[i], offset);
  8407. offset += datas[i].byteLength;
  8408. }
  8409. return result;
  8410. };
  8411. // emit ftyp & moov
  8412. MP4.generateInitSegment = function (meta) {
  8413. var ftyp = MP4.box(MP4.types.ftyp, MP4.constants.FTYP);
  8414. var moov = MP4.moov(meta);
  8415. var result = new Uint8Array(ftyp.byteLength + moov.byteLength);
  8416. result.set(ftyp, 0);
  8417. result.set(moov, ftyp.byteLength);
  8418. return result;
  8419. };
  8420. // Movie metadata box
  8421. MP4.moov = function (meta) {
  8422. var mvhd = MP4.mvhd(meta.timescale, meta.duration);
  8423. var trak = MP4.trak(meta);
  8424. var mvex = MP4.mvex(meta);
  8425. return MP4.box(MP4.types.moov, mvhd, trak, mvex);
  8426. };
  8427. // Movie header box
  8428. MP4.mvhd = function (timescale, duration) {
  8429. return MP4.box(MP4.types.mvhd, new Uint8Array([
  8430. 0x00, 0x00, 0x00, 0x00,
  8431. 0x00, 0x00, 0x00, 0x00,
  8432. 0x00, 0x00, 0x00, 0x00,
  8433. (timescale >>> 24) & 0xFF,
  8434. (timescale >>> 16) & 0xFF,
  8435. (timescale >>> 8) & 0xFF,
  8436. (timescale) & 0xFF,
  8437. (duration >>> 24) & 0xFF,
  8438. (duration >>> 16) & 0xFF,
  8439. (duration >>> 8) & 0xFF,
  8440. (duration) & 0xFF,
  8441. 0x00, 0x01, 0x00, 0x00,
  8442. 0x01, 0x00, 0x00, 0x00,
  8443. 0x00, 0x00, 0x00, 0x00,
  8444. 0x00, 0x00, 0x00, 0x00,
  8445. 0x00, 0x01, 0x00, 0x00,
  8446. 0x00, 0x00, 0x00, 0x00,
  8447. 0x00, 0x00, 0x00, 0x00,
  8448. 0x00, 0x00, 0x00, 0x00,
  8449. 0x00, 0x01, 0x00, 0x00,
  8450. 0x00, 0x00, 0x00, 0x00,
  8451. 0x00, 0x00, 0x00, 0x00,
  8452. 0x00, 0x00, 0x00, 0x00,
  8453. 0x40, 0x00, 0x00, 0x00,
  8454. 0x00, 0x00, 0x00, 0x00,
  8455. 0x00, 0x00, 0x00, 0x00,
  8456. 0x00, 0x00, 0x00, 0x00,
  8457. 0x00, 0x00, 0x00, 0x00,
  8458. 0x00, 0x00, 0x00, 0x00,
  8459. 0x00, 0x00, 0x00, 0x00,
  8460. 0xFF, 0xFF, 0xFF, 0xFF // next_track_ID
  8461. ]));
  8462. };
  8463. // Track box
  8464. MP4.trak = function (meta) {
  8465. return MP4.box(MP4.types.trak, MP4.tkhd(meta), MP4.mdia(meta));
  8466. };
  8467. // Track header box
  8468. MP4.tkhd = function (meta) {
  8469. var trackId = meta.id, duration = meta.duration;
  8470. var width = meta.presentWidth, height = meta.presentHeight;
  8471. return MP4.box(MP4.types.tkhd, new Uint8Array([
  8472. 0x00, 0x00, 0x00, 0x07,
  8473. 0x00, 0x00, 0x00, 0x00,
  8474. 0x00, 0x00, 0x00, 0x00,
  8475. (trackId >>> 24) & 0xFF,
  8476. (trackId >>> 16) & 0xFF,
  8477. (trackId >>> 8) & 0xFF,
  8478. (trackId) & 0xFF,
  8479. 0x00, 0x00, 0x00, 0x00,
  8480. (duration >>> 24) & 0xFF,
  8481. (duration >>> 16) & 0xFF,
  8482. (duration >>> 8) & 0xFF,
  8483. (duration) & 0xFF,
  8484. 0x00, 0x00, 0x00, 0x00,
  8485. 0x00, 0x00, 0x00, 0x00,
  8486. 0x00, 0x00, 0x00, 0x00,
  8487. 0x00, 0x00, 0x00, 0x00,
  8488. 0x00, 0x01, 0x00, 0x00,
  8489. 0x00, 0x00, 0x00, 0x00,
  8490. 0x00, 0x00, 0x00, 0x00,
  8491. 0x00, 0x00, 0x00, 0x00,
  8492. 0x00, 0x01, 0x00, 0x00,
  8493. 0x00, 0x00, 0x00, 0x00,
  8494. 0x00, 0x00, 0x00, 0x00,
  8495. 0x00, 0x00, 0x00, 0x00,
  8496. 0x40, 0x00, 0x00, 0x00,
  8497. (width >>> 8) & 0xFF,
  8498. (width) & 0xFF,
  8499. 0x00, 0x00,
  8500. (height >>> 8) & 0xFF,
  8501. (height) & 0xFF,
  8502. 0x00, 0x00
  8503. ]));
  8504. };
  8505. // Media Box
  8506. MP4.mdia = function (meta) {
  8507. return MP4.box(MP4.types.mdia, MP4.mdhd(meta), MP4.hdlr(meta), MP4.minf(meta));
  8508. };
  8509. // Media header box
  8510. MP4.mdhd = function (meta) {
  8511. var timescale = meta.timescale;
  8512. var duration = meta.duration;
  8513. return MP4.box(MP4.types.mdhd, new Uint8Array([
  8514. 0x00, 0x00, 0x00, 0x00,
  8515. 0x00, 0x00, 0x00, 0x00,
  8516. 0x00, 0x00, 0x00, 0x00,
  8517. (timescale >>> 24) & 0xFF,
  8518. (timescale >>> 16) & 0xFF,
  8519. (timescale >>> 8) & 0xFF,
  8520. (timescale) & 0xFF,
  8521. (duration >>> 24) & 0xFF,
  8522. (duration >>> 16) & 0xFF,
  8523. (duration >>> 8) & 0xFF,
  8524. (duration) & 0xFF,
  8525. 0x55, 0xC4,
  8526. 0x00, 0x00 // pre_defined = 0
  8527. ]));
  8528. };
  8529. // Media handler reference box
  8530. MP4.hdlr = function (meta) {
  8531. var data = null;
  8532. if (meta.type === 'audio') {
  8533. data = MP4.constants.HDLR_AUDIO;
  8534. }
  8535. else {
  8536. data = MP4.constants.HDLR_VIDEO;
  8537. }
  8538. return MP4.box(MP4.types.hdlr, data);
  8539. };
  8540. // Media infomation box
  8541. MP4.minf = function (meta) {
  8542. var xmhd = null;
  8543. if (meta.type === 'audio') {
  8544. xmhd = MP4.box(MP4.types.smhd, MP4.constants.SMHD);
  8545. }
  8546. else {
  8547. xmhd = MP4.box(MP4.types.vmhd, MP4.constants.VMHD);
  8548. }
  8549. return MP4.box(MP4.types.minf, xmhd, MP4.dinf(), MP4.stbl(meta));
  8550. };
  8551. // Data infomation box
  8552. MP4.dinf = function () {
  8553. var result = MP4.box(MP4.types.dinf, MP4.box(MP4.types.dref, MP4.constants.DREF));
  8554. return result;
  8555. };
  8556. // Sample table box
  8557. MP4.stbl = function (meta) {
  8558. var result = MP4.box(MP4.types.stbl, // type: stbl
  8559. MP4.stsd(meta), // Sample Description Table
  8560. MP4.box(MP4.types.stts, MP4.constants.STTS), // Time-To-Sample
  8561. MP4.box(MP4.types.stsc, MP4.constants.STSC), // Sample-To-Chunk
  8562. MP4.box(MP4.types.stsz, MP4.constants.STSZ), // Sample size
  8563. MP4.box(MP4.types.stco, MP4.constants.STCO) // Chunk offset
  8564. );
  8565. return result;
  8566. };
  8567. // Sample description box
  8568. MP4.stsd = function (meta) {
  8569. if (meta.type === 'audio') {
  8570. if (meta.codec === 'mp3') {
  8571. return MP4.box(MP4.types.stsd, MP4.constants.STSD_PREFIX, MP4.mp3(meta));
  8572. }
  8573. // else: aac -> mp4a
  8574. return MP4.box(MP4.types.stsd, MP4.constants.STSD_PREFIX, MP4.mp4a(meta));
  8575. }
  8576. else {
  8577. return MP4.box(MP4.types.stsd, MP4.constants.STSD_PREFIX, MP4.avc1(meta));
  8578. }
  8579. };
  8580. MP4.mp3 = function (meta) {
  8581. var channelCount = meta.channelCount;
  8582. var sampleRate = meta.audioSampleRate;
  8583. var data = new Uint8Array([
  8584. 0x00, 0x00, 0x00, 0x00,
  8585. 0x00, 0x00, 0x00, 0x01,
  8586. 0x00, 0x00, 0x00, 0x00,
  8587. 0x00, 0x00, 0x00, 0x00,
  8588. 0x00, channelCount,
  8589. 0x00, 0x10,
  8590. 0x00, 0x00, 0x00, 0x00,
  8591. (sampleRate >>> 8) & 0xFF,
  8592. (sampleRate) & 0xFF,
  8593. 0x00, 0x00
  8594. ]);
  8595. return MP4.box(MP4.types['.mp3'], data);
  8596. };
  8597. MP4.mp4a = function (meta) {
  8598. var channelCount = meta.channelCount;
  8599. var sampleRate = meta.audioSampleRate;
  8600. var data = new Uint8Array([
  8601. 0x00, 0x00, 0x00, 0x00,
  8602. 0x00, 0x00, 0x00, 0x01,
  8603. 0x00, 0x00, 0x00, 0x00,
  8604. 0x00, 0x00, 0x00, 0x00,
  8605. 0x00, channelCount,
  8606. 0x00, 0x10,
  8607. 0x00, 0x00, 0x00, 0x00,
  8608. (sampleRate >>> 8) & 0xFF,
  8609. (sampleRate) & 0xFF,
  8610. 0x00, 0x00
  8611. ]);
  8612. return MP4.box(MP4.types.mp4a, data, MP4.esds(meta));
  8613. };
  8614. MP4.esds = function (meta) {
  8615. var config = meta.config || [];
  8616. var configSize = config.length;
  8617. var data = new Uint8Array([
  8618. 0x00, 0x00, 0x00, 0x00,
  8619. 0x03,
  8620. 0x17 + configSize,
  8621. 0x00, 0x01,
  8622. 0x00,
  8623. 0x04,
  8624. 0x0F + configSize,
  8625. 0x40,
  8626. 0x15,
  8627. 0x00, 0x00, 0x00,
  8628. 0x00, 0x00, 0x00, 0x00,
  8629. 0x00, 0x00, 0x00, 0x00,
  8630. 0x05 // descriptor_type
  8631. ].concat([
  8632. configSize
  8633. ]).concat(config).concat([
  8634. 0x06, 0x01, 0x02 // GASpecificConfig
  8635. ]));
  8636. return MP4.box(MP4.types.esds, data);
  8637. };
  8638. MP4.avc1 = function (meta) {
  8639. var avcc = meta.avcc;
  8640. var width = meta.codecWidth, height = meta.codecHeight;
  8641. var data = new Uint8Array([
  8642. 0x00, 0x00, 0x00, 0x00,
  8643. 0x00, 0x00, 0x00, 0x01,
  8644. 0x00, 0x00, 0x00, 0x00,
  8645. 0x00, 0x00, 0x00, 0x00,
  8646. 0x00, 0x00, 0x00, 0x00,
  8647. 0x00, 0x00, 0x00, 0x00,
  8648. (width >>> 8) & 0xFF,
  8649. (width) & 0xFF,
  8650. (height >>> 8) & 0xFF,
  8651. (height) & 0xFF,
  8652. 0x00, 0x48, 0x00, 0x00,
  8653. 0x00, 0x48, 0x00, 0x00,
  8654. 0x00, 0x00, 0x00, 0x00,
  8655. 0x00, 0x01,
  8656. 0x0A,
  8657. 0x78, 0x71, 0x71, 0x2F,
  8658. 0x66, 0x6C, 0x76, 0x2E,
  8659. 0x6A, 0x73, 0x00, 0x00,
  8660. 0x00, 0x00, 0x00, 0x00,
  8661. 0x00, 0x00, 0x00, 0x00,
  8662. 0x00, 0x00, 0x00, 0x00,
  8663. 0x00, 0x00, 0x00, 0x00,
  8664. 0x00, 0x00, 0x00,
  8665. 0x00, 0x18,
  8666. 0xFF, 0xFF // pre_defined = -1
  8667. ]);
  8668. return MP4.box(MP4.types.avc1, data, MP4.box(MP4.types.avcC, avcc));
  8669. };
  8670. // Movie Extends box
  8671. MP4.mvex = function (meta) {
  8672. return MP4.box(MP4.types.mvex, MP4.trex(meta));
  8673. };
  8674. // Track Extends box
  8675. MP4.trex = function (meta) {
  8676. var trackId = meta.id;
  8677. var data = new Uint8Array([
  8678. 0x00, 0x00, 0x00, 0x00,
  8679. (trackId >>> 24) & 0xFF,
  8680. (trackId >>> 16) & 0xFF,
  8681. (trackId >>> 8) & 0xFF,
  8682. (trackId) & 0xFF,
  8683. 0x00, 0x00, 0x00, 0x01,
  8684. 0x00, 0x00, 0x00, 0x00,
  8685. 0x00, 0x00, 0x00, 0x00,
  8686. 0x00, 0x01, 0x00, 0x01 // default_sample_flags
  8687. ]);
  8688. return MP4.box(MP4.types.trex, data);
  8689. };
  8690. // Movie fragment box
  8691. MP4.moof = function (track, baseMediaDecodeTime) {
  8692. return MP4.box(MP4.types.moof, MP4.mfhd(track.sequenceNumber), MP4.traf(track, baseMediaDecodeTime));
  8693. };
  8694. MP4.mfhd = function (sequenceNumber) {
  8695. var data = new Uint8Array([
  8696. 0x00, 0x00, 0x00, 0x00,
  8697. (sequenceNumber >>> 24) & 0xFF,
  8698. (sequenceNumber >>> 16) & 0xFF,
  8699. (sequenceNumber >>> 8) & 0xFF,
  8700. (sequenceNumber) & 0xFF
  8701. ]);
  8702. return MP4.box(MP4.types.mfhd, data);
  8703. };
  8704. // Track fragment box
  8705. MP4.traf = function (track, baseMediaDecodeTime) {
  8706. var trackId = track.id;
  8707. // Track fragment header box
  8708. var tfhd = MP4.box(MP4.types.tfhd, new Uint8Array([
  8709. 0x00, 0x00, 0x00, 0x00,
  8710. (trackId >>> 24) & 0xFF,
  8711. (trackId >>> 16) & 0xFF,
  8712. (trackId >>> 8) & 0xFF,
  8713. (trackId) & 0xFF
  8714. ]));
  8715. // Track Fragment Decode Time
  8716. var tfdt = MP4.box(MP4.types.tfdt, new Uint8Array([
  8717. 0x00, 0x00, 0x00, 0x00,
  8718. (baseMediaDecodeTime >>> 24) & 0xFF,
  8719. (baseMediaDecodeTime >>> 16) & 0xFF,
  8720. (baseMediaDecodeTime >>> 8) & 0xFF,
  8721. (baseMediaDecodeTime) & 0xFF
  8722. ]));
  8723. var sdtp = MP4.sdtp(track);
  8724. var trun = MP4.trun(track, sdtp.byteLength + 16 + 16 + 8 + 16 + 8 + 8);
  8725. return MP4.box(MP4.types.traf, tfhd, tfdt, trun, sdtp);
  8726. };
  8727. // Sample Dependency Type box
  8728. MP4.sdtp = function (track) {
  8729. var samples = track.samples || [];
  8730. var sampleCount = samples.length;
  8731. var data = new Uint8Array(4 + sampleCount);
  8732. // 0~4 bytes: version(0) & flags
  8733. for (var i = 0; i < sampleCount; i++) {
  8734. var flags = samples[i].flags;
  8735. data[i + 4] = (flags.isLeading << 6) // is_leading: 2 (bit)
  8736. | (flags.dependsOn << 4) // sample_depends_on
  8737. | (flags.isDependedOn << 2) // sample_is_depended_on
  8738. | (flags.hasRedundancy); // sample_has_redundancy
  8739. }
  8740. return MP4.box(MP4.types.sdtp, data);
  8741. };
  8742. // Track fragment run box
  8743. MP4.trun = function (track, offset) {
  8744. var samples = track.samples || [];
  8745. var sampleCount = samples.length;
  8746. var dataSize = 12 + 16 * sampleCount;
  8747. var data = new Uint8Array(dataSize);
  8748. offset += 8 + dataSize;
  8749. data.set([
  8750. 0x00, 0x00, 0x0F, 0x01,
  8751. (sampleCount >>> 24) & 0xFF,
  8752. (sampleCount >>> 16) & 0xFF,
  8753. (sampleCount >>> 8) & 0xFF,
  8754. (sampleCount) & 0xFF,
  8755. (offset >>> 24) & 0xFF,
  8756. (offset >>> 16) & 0xFF,
  8757. (offset >>> 8) & 0xFF,
  8758. (offset) & 0xFF
  8759. ], 0);
  8760. for (var i = 0; i < sampleCount; i++) {
  8761. var duration = samples[i].duration;
  8762. var size = samples[i].size;
  8763. var flags = samples[i].flags;
  8764. var cts = samples[i].cts;
  8765. data.set([
  8766. (duration >>> 24) & 0xFF,
  8767. (duration >>> 16) & 0xFF,
  8768. (duration >>> 8) & 0xFF,
  8769. (duration) & 0xFF,
  8770. (size >>> 24) & 0xFF,
  8771. (size >>> 16) & 0xFF,
  8772. (size >>> 8) & 0xFF,
  8773. (size) & 0xFF,
  8774. (flags.isLeading << 2) | flags.dependsOn,
  8775. (flags.isDependedOn << 6) | (flags.hasRedundancy << 4) | flags.isNonSync,
  8776. 0x00, 0x00,
  8777. (cts >>> 24) & 0xFF,
  8778. (cts >>> 16) & 0xFF,
  8779. (cts >>> 8) & 0xFF,
  8780. (cts) & 0xFF
  8781. ], 12 + 16 * i);
  8782. }
  8783. return MP4.box(MP4.types.trun, data);
  8784. };
  8785. MP4.mdat = function (data) {
  8786. return MP4.box(MP4.types.mdat, data);
  8787. };
  8788. return MP4;
  8789. }());
  8790. MP4.init();
  8791. /* harmony default export */ __webpack_exports__["default"] = (MP4);
  8792. /***/ }),
  8793. /***/ "./src/remux/mp4-remuxer.js":
  8794. /*!**********************************!*\
  8795. !*** ./src/remux/mp4-remuxer.js ***!
  8796. \**********************************/
  8797. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  8798. "use strict";
  8799. __webpack_require__.r(__webpack_exports__);
  8800. /* harmony import */ var _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/logger.js */ "./src/utils/logger.js");
  8801. /* harmony import */ var _mp4_generator_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./mp4-generator.js */ "./src/remux/mp4-generator.js");
  8802. /* harmony import */ var _aac_silent_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./aac-silent.js */ "./src/remux/aac-silent.js");
  8803. /* harmony import */ var _utils_browser_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../utils/browser.js */ "./src/utils/browser.js");
  8804. /* harmony import */ var _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../core/media-segment-info.js */ "./src/core/media-segment-info.js");
  8805. /* harmony import */ var _utils_exception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../utils/exception.js */ "./src/utils/exception.js");
  8806. /*
  8807. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  8808. *
  8809. * @author zheng qian <xqq@xqq.im>
  8810. *
  8811. * Licensed under the Apache License, Version 2.0 (the "License");
  8812. * you may not use this file except in compliance with the License.
  8813. * You may obtain a copy of the License at
  8814. *
  8815. * http://www.apache.org/licenses/LICENSE-2.0
  8816. *
  8817. * Unless required by applicable law or agreed to in writing, software
  8818. * distributed under the License is distributed on an "AS IS" BASIS,
  8819. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8820. * See the License for the specific language governing permissions and
  8821. * limitations under the License.
  8822. */
  8823. // Fragmented mp4 remuxer
  8824. var MP4Remuxer = /** @class */ (function () {
  8825. function MP4Remuxer(config) {
  8826. this.TAG = 'MP4Remuxer';
  8827. this._config = config;
  8828. this._isLive = (config.isLive === true) ? true : false;
  8829. this._dtsBase = -1;
  8830. this._dtsBaseInited = false;
  8831. this._audioDtsBase = Infinity;
  8832. this._videoDtsBase = Infinity;
  8833. this._audioNextDts = undefined;
  8834. this._videoNextDts = undefined;
  8835. this._audioStashedLastSample = null;
  8836. this._videoStashedLastSample = null;
  8837. this._audioMeta = null;
  8838. this._videoMeta = null;
  8839. this._audioSegmentInfoList = new _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.MediaSegmentInfoList('audio');
  8840. this._videoSegmentInfoList = new _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.MediaSegmentInfoList('video');
  8841. this._onInitSegment = null;
  8842. this._onMediaSegment = null;
  8843. // Workaround for chrome < 50: Always force first sample as a Random Access Point in media segment
  8844. // see https://bugs.chromium.org/p/chromium/issues/detail?id=229412
  8845. this._forceFirstIDR = (_utils_browser_js__WEBPACK_IMPORTED_MODULE_3__.default.chrome &&
  8846. (_utils_browser_js__WEBPACK_IMPORTED_MODULE_3__.default.version.major < 50 ||
  8847. (_utils_browser_js__WEBPACK_IMPORTED_MODULE_3__.default.version.major === 50 && _utils_browser_js__WEBPACK_IMPORTED_MODULE_3__.default.version.build < 2661))) ? true : false;
  8848. // Workaround for IE11/Edge: Fill silent aac frame after keyframe-seeking
  8849. // Make audio beginDts equals with video beginDts, in order to fix seek freeze
  8850. this._fillSilentAfterSeek = (_utils_browser_js__WEBPACK_IMPORTED_MODULE_3__.default.msedge || _utils_browser_js__WEBPACK_IMPORTED_MODULE_3__.default.msie);
  8851. // While only FireFox supports 'audio/mp4, codecs="mp3"', use 'audio/mpeg' for chrome, safari, ...
  8852. this._mp3UseMpegAudio = !_utils_browser_js__WEBPACK_IMPORTED_MODULE_3__.default.firefox;
  8853. this._fillAudioTimestampGap = this._config.fixAudioTimestampGap;
  8854. }
  8855. MP4Remuxer.prototype.destroy = function () {
  8856. this._dtsBase = -1;
  8857. this._dtsBaseInited = false;
  8858. this._audioMeta = null;
  8859. this._videoMeta = null;
  8860. this._audioSegmentInfoList.clear();
  8861. this._audioSegmentInfoList = null;
  8862. this._videoSegmentInfoList.clear();
  8863. this._videoSegmentInfoList = null;
  8864. this._onInitSegment = null;
  8865. this._onMediaSegment = null;
  8866. };
  8867. MP4Remuxer.prototype.bindDataSource = function (producer) {
  8868. producer.onDataAvailable = this.remux.bind(this);
  8869. producer.onTrackMetadata = this._onTrackMetadataReceived.bind(this);
  8870. return this;
  8871. };
  8872. Object.defineProperty(MP4Remuxer.prototype, "onInitSegment", {
  8873. /* prototype: function onInitSegment(type: string, initSegment: ArrayBuffer): void
  8874. InitSegment: {
  8875. type: string,
  8876. data: ArrayBuffer,
  8877. codec: string,
  8878. container: string
  8879. }
  8880. */
  8881. get: function () {
  8882. return this._onInitSegment;
  8883. },
  8884. set: function (callback) {
  8885. this._onInitSegment = callback;
  8886. },
  8887. enumerable: false,
  8888. configurable: true
  8889. });
  8890. Object.defineProperty(MP4Remuxer.prototype, "onMediaSegment", {
  8891. /* prototype: function onMediaSegment(type: string, mediaSegment: MediaSegment): void
  8892. MediaSegment: {
  8893. type: string,
  8894. data: ArrayBuffer,
  8895. sampleCount: int32
  8896. info: MediaSegmentInfo
  8897. }
  8898. */
  8899. get: function () {
  8900. return this._onMediaSegment;
  8901. },
  8902. set: function (callback) {
  8903. this._onMediaSegment = callback;
  8904. },
  8905. enumerable: false,
  8906. configurable: true
  8907. });
  8908. MP4Remuxer.prototype.insertDiscontinuity = function () {
  8909. this._audioNextDts = this._videoNextDts = undefined;
  8910. };
  8911. MP4Remuxer.prototype.seek = function (originalDts) {
  8912. this._audioStashedLastSample = null;
  8913. this._videoStashedLastSample = null;
  8914. this._videoSegmentInfoList.clear();
  8915. this._audioSegmentInfoList.clear();
  8916. };
  8917. MP4Remuxer.prototype.remux = function (audioTrack, videoTrack) {
  8918. if (!this._onMediaSegment) {
  8919. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_5__.IllegalStateException('MP4Remuxer: onMediaSegment callback must be specificed!');
  8920. }
  8921. if (!this._dtsBaseInited) {
  8922. this._calculateDtsBase(audioTrack, videoTrack);
  8923. }
  8924. this._remuxVideo(videoTrack);
  8925. this._remuxAudio(audioTrack);
  8926. };
  8927. MP4Remuxer.prototype._onTrackMetadataReceived = function (type, metadata) {
  8928. var metabox = null;
  8929. var container = 'mp4';
  8930. var codec = metadata.codec;
  8931. if (type === 'audio') {
  8932. this._audioMeta = metadata;
  8933. if (metadata.codec === 'mp3' && this._mp3UseMpegAudio) {
  8934. // 'audio/mpeg' for MP3 audio track
  8935. container = 'mpeg';
  8936. codec = '';
  8937. metabox = new Uint8Array();
  8938. }
  8939. else {
  8940. // 'audio/mp4, codecs="codec"'
  8941. metabox = _mp4_generator_js__WEBPACK_IMPORTED_MODULE_1__.default.generateInitSegment(metadata);
  8942. }
  8943. }
  8944. else if (type === 'video') {
  8945. this._videoMeta = metadata;
  8946. metabox = _mp4_generator_js__WEBPACK_IMPORTED_MODULE_1__.default.generateInitSegment(metadata);
  8947. }
  8948. else {
  8949. return;
  8950. }
  8951. // dispatch metabox (Initialization Segment)
  8952. if (!this._onInitSegment) {
  8953. throw new _utils_exception_js__WEBPACK_IMPORTED_MODULE_5__.IllegalStateException('MP4Remuxer: onInitSegment callback must be specified!');
  8954. }
  8955. this._onInitSegment(type, {
  8956. type: type,
  8957. data: metabox.buffer,
  8958. codec: codec,
  8959. container: type + "/" + container,
  8960. mediaDuration: metadata.duration // in timescale 1000 (milliseconds)
  8961. });
  8962. };
  8963. MP4Remuxer.prototype._calculateDtsBase = function (audioTrack, videoTrack) {
  8964. if (this._dtsBaseInited) {
  8965. return;
  8966. }
  8967. if (audioTrack.samples && audioTrack.samples.length) {
  8968. this._audioDtsBase = audioTrack.samples[0].dts;
  8969. }
  8970. if (videoTrack.samples && videoTrack.samples.length) {
  8971. this._videoDtsBase = videoTrack.samples[0].dts;
  8972. }
  8973. this._dtsBase = Math.min(this._audioDtsBase, this._videoDtsBase);
  8974. this._dtsBaseInited = true;
  8975. };
  8976. MP4Remuxer.prototype.flushStashedSamples = function () {
  8977. var videoSample = this._videoStashedLastSample;
  8978. var audioSample = this._audioStashedLastSample;
  8979. var videoTrack = {
  8980. type: 'video',
  8981. id: 1,
  8982. sequenceNumber: 0,
  8983. samples: [],
  8984. length: 0
  8985. };
  8986. if (videoSample != null) {
  8987. videoTrack.samples.push(videoSample);
  8988. videoTrack.length = videoSample.length;
  8989. }
  8990. var audioTrack = {
  8991. type: 'audio',
  8992. id: 2,
  8993. sequenceNumber: 0,
  8994. samples: [],
  8995. length: 0
  8996. };
  8997. if (audioSample != null) {
  8998. audioTrack.samples.push(audioSample);
  8999. audioTrack.length = audioSample.length;
  9000. }
  9001. this._videoStashedLastSample = null;
  9002. this._audioStashedLastSample = null;
  9003. this._remuxVideo(videoTrack, true);
  9004. this._remuxAudio(audioTrack, true);
  9005. };
  9006. MP4Remuxer.prototype._remuxAudio = function (audioTrack, force) {
  9007. if (this._audioMeta == null) {
  9008. return;
  9009. }
  9010. var track = audioTrack;
  9011. var samples = track.samples;
  9012. var dtsCorrection = undefined;
  9013. var firstDts = -1, lastDts = -1, lastPts = -1;
  9014. var refSampleDuration = this._audioMeta.refSampleDuration;
  9015. var mpegRawTrack = this._audioMeta.codec === 'mp3' && this._mp3UseMpegAudio;
  9016. var firstSegmentAfterSeek = this._dtsBaseInited && this._audioNextDts === undefined;
  9017. var insertPrefixSilentFrame = false;
  9018. if (!samples || samples.length === 0) {
  9019. return;
  9020. }
  9021. if (samples.length === 1 && !force) {
  9022. // If [sample count in current batch] === 1 && (force != true)
  9023. // Ignore and keep in demuxer's queue
  9024. return;
  9025. } // else if (force === true) do remux
  9026. var offset = 0;
  9027. var mdatbox = null;
  9028. var mdatBytes = 0;
  9029. // calculate initial mdat size
  9030. if (mpegRawTrack) {
  9031. // for raw mpeg buffer
  9032. offset = 0;
  9033. mdatBytes = track.length;
  9034. }
  9035. else {
  9036. // for fmp4 mdat box
  9037. offset = 8; // size + type
  9038. mdatBytes = 8 + track.length;
  9039. }
  9040. var lastSample = null;
  9041. // Pop the lastSample and waiting for stash
  9042. if (samples.length > 1) {
  9043. lastSample = samples.pop();
  9044. mdatBytes -= lastSample.length;
  9045. }
  9046. // Insert [stashed lastSample in the previous batch] to the front
  9047. if (this._audioStashedLastSample != null) {
  9048. var sample = this._audioStashedLastSample;
  9049. this._audioStashedLastSample = null;
  9050. samples.unshift(sample);
  9051. mdatBytes += sample.length;
  9052. }
  9053. // Stash the lastSample of current batch, waiting for next batch
  9054. if (lastSample != null) {
  9055. this._audioStashedLastSample = lastSample;
  9056. }
  9057. var firstSampleOriginalDts = samples[0].dts - this._dtsBase;
  9058. // calculate dtsCorrection
  9059. if (this._audioNextDts) {
  9060. dtsCorrection = firstSampleOriginalDts - this._audioNextDts;
  9061. }
  9062. else { // this._audioNextDts == undefined
  9063. if (this._audioSegmentInfoList.isEmpty()) {
  9064. dtsCorrection = 0;
  9065. if (this._fillSilentAfterSeek && !this._videoSegmentInfoList.isEmpty()) {
  9066. if (this._audioMeta.originalCodec !== 'mp3') {
  9067. insertPrefixSilentFrame = true;
  9068. }
  9069. }
  9070. }
  9071. else {
  9072. var lastSample_1 = this._audioSegmentInfoList.getLastSampleBefore(firstSampleOriginalDts);
  9073. if (lastSample_1 != null) {
  9074. var distance = (firstSampleOriginalDts - (lastSample_1.originalDts + lastSample_1.duration));
  9075. if (distance <= 3) {
  9076. distance = 0;
  9077. }
  9078. var expectedDts = lastSample_1.dts + lastSample_1.duration + distance;
  9079. dtsCorrection = firstSampleOriginalDts - expectedDts;
  9080. }
  9081. else { // lastSample == null, cannot found
  9082. dtsCorrection = 0;
  9083. }
  9084. }
  9085. }
  9086. if (insertPrefixSilentFrame) {
  9087. // align audio segment beginDts to match with current video segment's beginDts
  9088. var firstSampleDts = firstSampleOriginalDts - dtsCorrection;
  9089. var videoSegment = this._videoSegmentInfoList.getLastSegmentBefore(firstSampleOriginalDts);
  9090. if (videoSegment != null && videoSegment.beginDts < firstSampleDts) {
  9091. var silentUnit = _aac_silent_js__WEBPACK_IMPORTED_MODULE_2__.default.getSilentFrame(this._audioMeta.originalCodec, this._audioMeta.channelCount);
  9092. if (silentUnit) {
  9093. var dts = videoSegment.beginDts;
  9094. var silentFrameDuration = firstSampleDts - videoSegment.beginDts;
  9095. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.v(this.TAG, "InsertPrefixSilentAudio: dts: " + dts + ", duration: " + silentFrameDuration);
  9096. samples.unshift({ unit: silentUnit, dts: dts, pts: dts });
  9097. mdatBytes += silentUnit.byteLength;
  9098. } // silentUnit == null: Cannot generate, skip
  9099. }
  9100. else {
  9101. insertPrefixSilentFrame = false;
  9102. }
  9103. }
  9104. var mp4Samples = [];
  9105. // Correct dts for each sample, and calculate sample duration. Then output to mp4Samples
  9106. for (var i = 0; i < samples.length; i++) {
  9107. var sample = samples[i];
  9108. var unit = sample.unit;
  9109. var originalDts = sample.dts - this._dtsBase;
  9110. var dts = originalDts;
  9111. var needFillSilentFrames = false;
  9112. var silentFrames = null;
  9113. var sampleDuration = 0;
  9114. if (originalDts < -0.001) {
  9115. continue; //pass the first sample with the invalid dts
  9116. }
  9117. if (this._audioMeta.codec !== 'mp3') {
  9118. // for AAC codec, we need to keep dts increase based on refSampleDuration
  9119. var curRefDts = originalDts;
  9120. var maxAudioFramesDrift = 3;
  9121. if (this._audioNextDts) {
  9122. curRefDts = this._audioNextDts;
  9123. }
  9124. dtsCorrection = originalDts - curRefDts;
  9125. if (dtsCorrection <= -maxAudioFramesDrift * refSampleDuration) {
  9126. // If we're overlapping by more than maxAudioFramesDrift number of frame, drop this sample
  9127. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, "Dropping 1 audio frame (originalDts: " + originalDts + " ms ,curRefDts: " + curRefDts + " ms) due to dtsCorrection: " + dtsCorrection + " ms overlap.");
  9128. continue;
  9129. }
  9130. else if (dtsCorrection >= maxAudioFramesDrift * refSampleDuration && this._fillAudioTimestampGap && !_utils_browser_js__WEBPACK_IMPORTED_MODULE_3__.default.safari) {
  9131. // Silent frame generation, if large timestamp gap detected && config.fixAudioTimestampGap
  9132. needFillSilentFrames = true;
  9133. // We need to insert silent frames to fill timestamp gap
  9134. var frameCount = Math.floor(dtsCorrection / refSampleDuration);
  9135. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Large audio timestamp gap detected, may cause AV sync to drift. ' +
  9136. 'Silent frames will be generated to avoid unsync.\n' +
  9137. ("originalDts: " + originalDts + " ms, curRefDts: " + curRefDts + " ms, ") +
  9138. ("dtsCorrection: " + Math.round(dtsCorrection) + " ms, generate: " + frameCount + " frames"));
  9139. dts = Math.floor(curRefDts);
  9140. sampleDuration = Math.floor(curRefDts + refSampleDuration) - dts;
  9141. var silentUnit = _aac_silent_js__WEBPACK_IMPORTED_MODULE_2__.default.getSilentFrame(this._audioMeta.originalCodec, this._audioMeta.channelCount);
  9142. if (silentUnit == null) {
  9143. _utils_logger_js__WEBPACK_IMPORTED_MODULE_0__.default.w(this.TAG, 'Unable to generate silent frame for ' +
  9144. (this._audioMeta.originalCodec + " with " + this._audioMeta.channelCount + " channels, repeat last frame"));
  9145. // Repeat last frame
  9146. silentUnit = unit;
  9147. }
  9148. silentFrames = [];
  9149. for (var j = 0; j < frameCount; j++) {
  9150. curRefDts = curRefDts + refSampleDuration;
  9151. var intDts = Math.floor(curRefDts); // change to integer
  9152. var intDuration = Math.floor(curRefDts + refSampleDuration) - intDts;
  9153. var frame = {
  9154. dts: intDts,
  9155. pts: intDts,
  9156. cts: 0,
  9157. unit: silentUnit,
  9158. size: silentUnit.byteLength,
  9159. duration: intDuration,
  9160. originalDts: originalDts,
  9161. flags: {
  9162. isLeading: 0,
  9163. dependsOn: 1,
  9164. isDependedOn: 0,
  9165. hasRedundancy: 0
  9166. }
  9167. };
  9168. silentFrames.push(frame);
  9169. mdatBytes += frame.size;
  9170. ;
  9171. }
  9172. this._audioNextDts = curRefDts + refSampleDuration;
  9173. }
  9174. else {
  9175. dts = Math.floor(curRefDts);
  9176. sampleDuration = Math.floor(curRefDts + refSampleDuration) - dts;
  9177. this._audioNextDts = curRefDts + refSampleDuration;
  9178. }
  9179. }
  9180. else {
  9181. // keep the original dts calculate algorithm for mp3
  9182. dts = originalDts - dtsCorrection;
  9183. if (i !== samples.length - 1) {
  9184. var nextDts = samples[i + 1].dts - this._dtsBase - dtsCorrection;
  9185. sampleDuration = nextDts - dts;
  9186. }
  9187. else { // the last sample
  9188. if (lastSample != null) { // use stashed sample's dts to calculate sample duration
  9189. var nextDts = lastSample.dts - this._dtsBase - dtsCorrection;
  9190. sampleDuration = nextDts - dts;
  9191. }
  9192. else if (mp4Samples.length >= 1) { // use second last sample duration
  9193. sampleDuration = mp4Samples[mp4Samples.length - 1].duration;
  9194. }
  9195. else { // the only one sample, use reference sample duration
  9196. sampleDuration = Math.floor(refSampleDuration);
  9197. }
  9198. }
  9199. this._audioNextDts = dts + sampleDuration;
  9200. }
  9201. if (firstDts === -1) {
  9202. firstDts = dts;
  9203. }
  9204. mp4Samples.push({
  9205. dts: dts,
  9206. pts: dts,
  9207. cts: 0,
  9208. unit: sample.unit,
  9209. size: sample.unit.byteLength,
  9210. duration: sampleDuration,
  9211. originalDts: originalDts,
  9212. flags: {
  9213. isLeading: 0,
  9214. dependsOn: 1,
  9215. isDependedOn: 0,
  9216. hasRedundancy: 0
  9217. }
  9218. });
  9219. if (needFillSilentFrames) {
  9220. // Silent frames should be inserted after wrong-duration frame
  9221. mp4Samples.push.apply(mp4Samples, silentFrames);
  9222. }
  9223. }
  9224. if (mp4Samples.length === 0) {
  9225. //no samples need to remux
  9226. track.samples = [];
  9227. track.length = 0;
  9228. return;
  9229. }
  9230. // allocate mdatbox
  9231. if (mpegRawTrack) {
  9232. // allocate for raw mpeg buffer
  9233. mdatbox = new Uint8Array(mdatBytes);
  9234. }
  9235. else {
  9236. // allocate for fmp4 mdat box
  9237. mdatbox = new Uint8Array(mdatBytes);
  9238. // size field
  9239. mdatbox[0] = (mdatBytes >>> 24) & 0xFF;
  9240. mdatbox[1] = (mdatBytes >>> 16) & 0xFF;
  9241. mdatbox[2] = (mdatBytes >>> 8) & 0xFF;
  9242. mdatbox[3] = (mdatBytes) & 0xFF;
  9243. // type field (fourCC)
  9244. mdatbox.set(_mp4_generator_js__WEBPACK_IMPORTED_MODULE_1__.default.types.mdat, 4);
  9245. }
  9246. // Write samples into mdatbox
  9247. for (var i = 0; i < mp4Samples.length; i++) {
  9248. var unit = mp4Samples[i].unit;
  9249. mdatbox.set(unit, offset);
  9250. offset += unit.byteLength;
  9251. }
  9252. var latest = mp4Samples[mp4Samples.length - 1];
  9253. lastDts = latest.dts + latest.duration;
  9254. //this._audioNextDts = lastDts;
  9255. // fill media segment info & add to info list
  9256. var info = new _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.MediaSegmentInfo();
  9257. info.beginDts = firstDts;
  9258. info.endDts = lastDts;
  9259. info.beginPts = firstDts;
  9260. info.endPts = lastDts;
  9261. info.originalBeginDts = mp4Samples[0].originalDts;
  9262. info.originalEndDts = latest.originalDts + latest.duration;
  9263. info.firstSample = new _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.SampleInfo(mp4Samples[0].dts, mp4Samples[0].pts, mp4Samples[0].duration, mp4Samples[0].originalDts, false);
  9264. info.lastSample = new _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.SampleInfo(latest.dts, latest.pts, latest.duration, latest.originalDts, false);
  9265. if (!this._isLive) {
  9266. this._audioSegmentInfoList.append(info);
  9267. }
  9268. track.samples = mp4Samples;
  9269. track.sequenceNumber++;
  9270. var moofbox = null;
  9271. if (mpegRawTrack) {
  9272. // Generate empty buffer, because useless for raw mpeg
  9273. moofbox = new Uint8Array();
  9274. }
  9275. else {
  9276. // Generate moof for fmp4 segment
  9277. moofbox = _mp4_generator_js__WEBPACK_IMPORTED_MODULE_1__.default.moof(track, firstDts);
  9278. }
  9279. track.samples = [];
  9280. track.length = 0;
  9281. var segment = {
  9282. type: 'audio',
  9283. data: this._mergeBoxes(moofbox, mdatbox).buffer,
  9284. sampleCount: mp4Samples.length,
  9285. info: info
  9286. };
  9287. if (mpegRawTrack && firstSegmentAfterSeek) {
  9288. // For MPEG audio stream in MSE, if seeking occurred, before appending new buffer
  9289. // We need explicitly set timestampOffset to the desired point in timeline for mpeg SourceBuffer.
  9290. segment.timestampOffset = firstDts;
  9291. }
  9292. this._onMediaSegment('audio', segment);
  9293. };
  9294. MP4Remuxer.prototype._remuxVideo = function (videoTrack, force) {
  9295. if (this._videoMeta == null) {
  9296. return;
  9297. }
  9298. var track = videoTrack;
  9299. var samples = track.samples;
  9300. var dtsCorrection = undefined;
  9301. var firstDts = -1, lastDts = -1;
  9302. var firstPts = -1, lastPts = -1;
  9303. if (!samples || samples.length === 0) {
  9304. return;
  9305. }
  9306. if (samples.length === 1 && !force) {
  9307. // If [sample count in current batch] === 1 && (force != true)
  9308. // Ignore and keep in demuxer's queue
  9309. return;
  9310. } // else if (force === true) do remux
  9311. var offset = 8;
  9312. var mdatbox = null;
  9313. var mdatBytes = 8 + videoTrack.length;
  9314. var lastSample = null;
  9315. // Pop the lastSample and waiting for stash
  9316. if (samples.length > 1) {
  9317. lastSample = samples.pop();
  9318. mdatBytes -= lastSample.length;
  9319. }
  9320. // Insert [stashed lastSample in the previous batch] to the front
  9321. if (this._videoStashedLastSample != null) {
  9322. var sample = this._videoStashedLastSample;
  9323. this._videoStashedLastSample = null;
  9324. samples.unshift(sample);
  9325. mdatBytes += sample.length;
  9326. }
  9327. // Stash the lastSample of current batch, waiting for next batch
  9328. if (lastSample != null) {
  9329. this._videoStashedLastSample = lastSample;
  9330. }
  9331. var firstSampleOriginalDts = samples[0].dts - this._dtsBase;
  9332. // calculate dtsCorrection
  9333. if (this._videoNextDts) {
  9334. dtsCorrection = firstSampleOriginalDts - this._videoNextDts;
  9335. }
  9336. else { // this._videoNextDts == undefined
  9337. if (this._videoSegmentInfoList.isEmpty()) {
  9338. dtsCorrection = 0;
  9339. }
  9340. else {
  9341. var lastSample_2 = this._videoSegmentInfoList.getLastSampleBefore(firstSampleOriginalDts);
  9342. if (lastSample_2 != null) {
  9343. var distance = (firstSampleOriginalDts - (lastSample_2.originalDts + lastSample_2.duration));
  9344. if (distance <= 3) {
  9345. distance = 0;
  9346. }
  9347. var expectedDts = lastSample_2.dts + lastSample_2.duration + distance;
  9348. dtsCorrection = firstSampleOriginalDts - expectedDts;
  9349. }
  9350. else { // lastSample == null, cannot found
  9351. dtsCorrection = 0;
  9352. }
  9353. }
  9354. }
  9355. var info = new _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.MediaSegmentInfo();
  9356. var mp4Samples = [];
  9357. // Correct dts for each sample, and calculate sample duration. Then output to mp4Samples
  9358. for (var i = 0; i < samples.length; i++) {
  9359. var sample = samples[i];
  9360. var originalDts = sample.dts - this._dtsBase;
  9361. var isKeyframe = sample.isKeyframe;
  9362. var dts = originalDts - dtsCorrection;
  9363. var cts = sample.cts;
  9364. var pts = dts + cts;
  9365. if (firstDts === -1) {
  9366. firstDts = dts;
  9367. firstPts = pts;
  9368. }
  9369. var sampleDuration = 0;
  9370. if (i !== samples.length - 1) {
  9371. var nextDts = samples[i + 1].dts - this._dtsBase - dtsCorrection;
  9372. sampleDuration = nextDts - dts;
  9373. }
  9374. else { // the last sample
  9375. if (lastSample != null) { // use stashed sample's dts to calculate sample duration
  9376. var nextDts = lastSample.dts - this._dtsBase - dtsCorrection;
  9377. sampleDuration = nextDts - dts;
  9378. }
  9379. else if (mp4Samples.length >= 1) { // use second last sample duration
  9380. sampleDuration = mp4Samples[mp4Samples.length - 1].duration;
  9381. }
  9382. else { // the only one sample, use reference sample duration
  9383. sampleDuration = Math.floor(this._videoMeta.refSampleDuration);
  9384. }
  9385. }
  9386. if (isKeyframe) {
  9387. var syncPoint = new _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.SampleInfo(dts, pts, sampleDuration, sample.dts, true);
  9388. syncPoint.fileposition = sample.fileposition;
  9389. info.appendSyncPoint(syncPoint);
  9390. }
  9391. mp4Samples.push({
  9392. dts: dts,
  9393. pts: pts,
  9394. cts: cts,
  9395. units: sample.units,
  9396. size: sample.length,
  9397. isKeyframe: isKeyframe,
  9398. duration: sampleDuration,
  9399. originalDts: originalDts,
  9400. flags: {
  9401. isLeading: 0,
  9402. dependsOn: isKeyframe ? 2 : 1,
  9403. isDependedOn: isKeyframe ? 1 : 0,
  9404. hasRedundancy: 0,
  9405. isNonSync: isKeyframe ? 0 : 1
  9406. }
  9407. });
  9408. }
  9409. // allocate mdatbox
  9410. mdatbox = new Uint8Array(mdatBytes);
  9411. mdatbox[0] = (mdatBytes >>> 24) & 0xFF;
  9412. mdatbox[1] = (mdatBytes >>> 16) & 0xFF;
  9413. mdatbox[2] = (mdatBytes >>> 8) & 0xFF;
  9414. mdatbox[3] = (mdatBytes) & 0xFF;
  9415. mdatbox.set(_mp4_generator_js__WEBPACK_IMPORTED_MODULE_1__.default.types.mdat, 4);
  9416. // Write samples into mdatbox
  9417. for (var i = 0; i < mp4Samples.length; i++) {
  9418. var units = mp4Samples[i].units;
  9419. while (units.length) {
  9420. var unit = units.shift();
  9421. var data = unit.data;
  9422. mdatbox.set(data, offset);
  9423. offset += data.byteLength;
  9424. }
  9425. }
  9426. var latest = mp4Samples[mp4Samples.length - 1];
  9427. lastDts = latest.dts + latest.duration;
  9428. lastPts = latest.pts + latest.duration;
  9429. this._videoNextDts = lastDts;
  9430. // fill media segment info & add to info list
  9431. info.beginDts = firstDts;
  9432. info.endDts = lastDts;
  9433. info.beginPts = firstPts;
  9434. info.endPts = lastPts;
  9435. info.originalBeginDts = mp4Samples[0].originalDts;
  9436. info.originalEndDts = latest.originalDts + latest.duration;
  9437. info.firstSample = new _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.SampleInfo(mp4Samples[0].dts, mp4Samples[0].pts, mp4Samples[0].duration, mp4Samples[0].originalDts, mp4Samples[0].isKeyframe);
  9438. info.lastSample = new _core_media_segment_info_js__WEBPACK_IMPORTED_MODULE_4__.SampleInfo(latest.dts, latest.pts, latest.duration, latest.originalDts, latest.isKeyframe);
  9439. if (!this._isLive) {
  9440. this._videoSegmentInfoList.append(info);
  9441. }
  9442. track.samples = mp4Samples;
  9443. track.sequenceNumber++;
  9444. // workaround for chrome < 50: force first sample as a random access point
  9445. // see https://bugs.chromium.org/p/chromium/issues/detail?id=229412
  9446. if (this._forceFirstIDR) {
  9447. var flags = mp4Samples[0].flags;
  9448. flags.dependsOn = 2;
  9449. flags.isNonSync = 0;
  9450. }
  9451. var moofbox = _mp4_generator_js__WEBPACK_IMPORTED_MODULE_1__.default.moof(track, firstDts);
  9452. track.samples = [];
  9453. track.length = 0;
  9454. this._onMediaSegment('video', {
  9455. type: 'video',
  9456. data: this._mergeBoxes(moofbox, mdatbox).buffer,
  9457. sampleCount: mp4Samples.length,
  9458. info: info
  9459. });
  9460. };
  9461. MP4Remuxer.prototype._mergeBoxes = function (moof, mdat) {
  9462. var result = new Uint8Array(moof.byteLength + mdat.byteLength);
  9463. result.set(moof, 0);
  9464. result.set(mdat, moof.byteLength);
  9465. return result;
  9466. };
  9467. return MP4Remuxer;
  9468. }());
  9469. /* harmony default export */ __webpack_exports__["default"] = (MP4Remuxer);
  9470. /***/ }),
  9471. /***/ "./src/utils/browser.js":
  9472. /*!******************************!*\
  9473. !*** ./src/utils/browser.js ***!
  9474. \******************************/
  9475. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  9476. "use strict";
  9477. __webpack_require__.r(__webpack_exports__);
  9478. /*
  9479. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  9480. *
  9481. * @author zheng qian <xqq@xqq.im>
  9482. *
  9483. * Licensed under the Apache License, Version 2.0 (the "License");
  9484. * you may not use this file except in compliance with the License.
  9485. * You may obtain a copy of the License at
  9486. *
  9487. * http://www.apache.org/licenses/LICENSE-2.0
  9488. *
  9489. * Unless required by applicable law or agreed to in writing, software
  9490. * distributed under the License is distributed on an "AS IS" BASIS,
  9491. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9492. * See the License for the specific language governing permissions and
  9493. * limitations under the License.
  9494. */
  9495. var Browser = {};
  9496. function detect() {
  9497. // modified from jquery-browser-plugin
  9498. var ua = self.navigator.userAgent.toLowerCase();
  9499. var match = /(edge)\/([\w.]+)/.exec(ua) ||
  9500. /(opr)[\/]([\w.]+)/.exec(ua) ||
  9501. /(chrome)[ \/]([\w.]+)/.exec(ua) ||
  9502. /(iemobile)[\/]([\w.]+)/.exec(ua) ||
  9503. /(version)(applewebkit)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(ua) ||
  9504. /(webkit)[ \/]([\w.]+).*(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec(ua) ||
  9505. /(webkit)[ \/]([\w.]+)/.exec(ua) ||
  9506. /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
  9507. /(msie) ([\w.]+)/.exec(ua) ||
  9508. ua.indexOf('trident') >= 0 && /(rv)(?::| )([\w.]+)/.exec(ua) ||
  9509. ua.indexOf('compatible') < 0 && /(firefox)[ \/]([\w.]+)/.exec(ua) ||
  9510. [];
  9511. var platform_match = /(ipad)/.exec(ua) ||
  9512. /(ipod)/.exec(ua) ||
  9513. /(windows phone)/.exec(ua) ||
  9514. /(iphone)/.exec(ua) ||
  9515. /(kindle)/.exec(ua) ||
  9516. /(android)/.exec(ua) ||
  9517. /(windows)/.exec(ua) ||
  9518. /(mac)/.exec(ua) ||
  9519. /(linux)/.exec(ua) ||
  9520. /(cros)/.exec(ua) ||
  9521. [];
  9522. var matched = {
  9523. browser: match[5] || match[3] || match[1] || '',
  9524. version: match[2] || match[4] || '0',
  9525. majorVersion: match[4] || match[2] || '0',
  9526. platform: platform_match[0] || ''
  9527. };
  9528. var browser = {};
  9529. if (matched.browser) {
  9530. browser[matched.browser] = true;
  9531. var versionArray = matched.majorVersion.split('.');
  9532. browser.version = {
  9533. major: parseInt(matched.majorVersion, 10),
  9534. string: matched.version
  9535. };
  9536. if (versionArray.length > 1) {
  9537. browser.version.minor = parseInt(versionArray[1], 10);
  9538. }
  9539. if (versionArray.length > 2) {
  9540. browser.version.build = parseInt(versionArray[2], 10);
  9541. }
  9542. }
  9543. if (matched.platform) {
  9544. browser[matched.platform] = true;
  9545. }
  9546. if (browser.chrome || browser.opr || browser.safari) {
  9547. browser.webkit = true;
  9548. }
  9549. // MSIE. IE11 has 'rv' identifer
  9550. if (browser.rv || browser.iemobile) {
  9551. if (browser.rv) {
  9552. delete browser.rv;
  9553. }
  9554. var msie = 'msie';
  9555. matched.browser = msie;
  9556. browser[msie] = true;
  9557. }
  9558. // Microsoft Edge
  9559. if (browser.edge) {
  9560. delete browser.edge;
  9561. var msedge = 'msedge';
  9562. matched.browser = msedge;
  9563. browser[msedge] = true;
  9564. }
  9565. // Opera 15+
  9566. if (browser.opr) {
  9567. var opera = 'opera';
  9568. matched.browser = opera;
  9569. browser[opera] = true;
  9570. }
  9571. // Stock android browsers are marked as Safari
  9572. if (browser.safari && browser.android) {
  9573. var android = 'android';
  9574. matched.browser = android;
  9575. browser[android] = true;
  9576. }
  9577. browser.name = matched.browser;
  9578. browser.platform = matched.platform;
  9579. for (var key in Browser) {
  9580. if (Browser.hasOwnProperty(key)) {
  9581. delete Browser[key];
  9582. }
  9583. }
  9584. Object.assign(Browser, browser);
  9585. }
  9586. detect();
  9587. /* harmony default export */ __webpack_exports__["default"] = (Browser);
  9588. /***/ }),
  9589. /***/ "./src/utils/exception.js":
  9590. /*!********************************!*\
  9591. !*** ./src/utils/exception.js ***!
  9592. \********************************/
  9593. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  9594. "use strict";
  9595. __webpack_require__.r(__webpack_exports__);
  9596. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  9597. /* harmony export */ "RuntimeException": function() { return /* binding */ RuntimeException; },
  9598. /* harmony export */ "IllegalStateException": function() { return /* binding */ IllegalStateException; },
  9599. /* harmony export */ "InvalidArgumentException": function() { return /* binding */ InvalidArgumentException; },
  9600. /* harmony export */ "NotImplementedException": function() { return /* binding */ NotImplementedException; }
  9601. /* harmony export */ });
  9602. /*
  9603. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  9604. *
  9605. * @author zheng qian <xqq@xqq.im>
  9606. *
  9607. * Licensed under the Apache License, Version 2.0 (the "License");
  9608. * you may not use this file except in compliance with the License.
  9609. * You may obtain a copy of the License at
  9610. *
  9611. * http://www.apache.org/licenses/LICENSE-2.0
  9612. *
  9613. * Unless required by applicable law or agreed to in writing, software
  9614. * distributed under the License is distributed on an "AS IS" BASIS,
  9615. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9616. * See the License for the specific language governing permissions and
  9617. * limitations under the License.
  9618. */
  9619. var __extends = (undefined && undefined.__extends) || (function () {
  9620. var extendStatics = function (d, b) {
  9621. extendStatics = Object.setPrototypeOf ||
  9622. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9623. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  9624. return extendStatics(d, b);
  9625. };
  9626. return function (d, b) {
  9627. if (typeof b !== "function" && b !== null)
  9628. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  9629. extendStatics(d, b);
  9630. function __() { this.constructor = d; }
  9631. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9632. };
  9633. })();
  9634. var RuntimeException = /** @class */ (function () {
  9635. function RuntimeException(message) {
  9636. this._message = message;
  9637. }
  9638. Object.defineProperty(RuntimeException.prototype, "name", {
  9639. get: function () {
  9640. return 'RuntimeException';
  9641. },
  9642. enumerable: false,
  9643. configurable: true
  9644. });
  9645. Object.defineProperty(RuntimeException.prototype, "message", {
  9646. get: function () {
  9647. return this._message;
  9648. },
  9649. enumerable: false,
  9650. configurable: true
  9651. });
  9652. RuntimeException.prototype.toString = function () {
  9653. return this.name + ': ' + this.message;
  9654. };
  9655. return RuntimeException;
  9656. }());
  9657. var IllegalStateException = /** @class */ (function (_super) {
  9658. __extends(IllegalStateException, _super);
  9659. function IllegalStateException(message) {
  9660. return _super.call(this, message) || this;
  9661. }
  9662. Object.defineProperty(IllegalStateException.prototype, "name", {
  9663. get: function () {
  9664. return 'IllegalStateException';
  9665. },
  9666. enumerable: false,
  9667. configurable: true
  9668. });
  9669. return IllegalStateException;
  9670. }(RuntimeException));
  9671. var InvalidArgumentException = /** @class */ (function (_super) {
  9672. __extends(InvalidArgumentException, _super);
  9673. function InvalidArgumentException(message) {
  9674. return _super.call(this, message) || this;
  9675. }
  9676. Object.defineProperty(InvalidArgumentException.prototype, "name", {
  9677. get: function () {
  9678. return 'InvalidArgumentException';
  9679. },
  9680. enumerable: false,
  9681. configurable: true
  9682. });
  9683. return InvalidArgumentException;
  9684. }(RuntimeException));
  9685. var NotImplementedException = /** @class */ (function (_super) {
  9686. __extends(NotImplementedException, _super);
  9687. function NotImplementedException(message) {
  9688. return _super.call(this, message) || this;
  9689. }
  9690. Object.defineProperty(NotImplementedException.prototype, "name", {
  9691. get: function () {
  9692. return 'NotImplementedException';
  9693. },
  9694. enumerable: false,
  9695. configurable: true
  9696. });
  9697. return NotImplementedException;
  9698. }(RuntimeException));
  9699. /***/ }),
  9700. /***/ "./src/utils/logger.js":
  9701. /*!*****************************!*\
  9702. !*** ./src/utils/logger.js ***!
  9703. \*****************************/
  9704. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  9705. "use strict";
  9706. __webpack_require__.r(__webpack_exports__);
  9707. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! events */ "./node_modules/events/events.js");
  9708. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(events__WEBPACK_IMPORTED_MODULE_0__);
  9709. /*
  9710. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  9711. *
  9712. * @author zheng qian <xqq@xqq.im>
  9713. *
  9714. * Licensed under the Apache License, Version 2.0 (the "License");
  9715. * you may not use this file except in compliance with the License.
  9716. * You may obtain a copy of the License at
  9717. *
  9718. * http://www.apache.org/licenses/LICENSE-2.0
  9719. *
  9720. * Unless required by applicable law or agreed to in writing, software
  9721. * distributed under the License is distributed on an "AS IS" BASIS,
  9722. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9723. * See the License for the specific language governing permissions and
  9724. * limitations under the License.
  9725. */
  9726. var Log = /** @class */ (function () {
  9727. function Log() {
  9728. }
  9729. Log.e = function (tag, msg) {
  9730. if (!tag || Log.FORCE_GLOBAL_TAG)
  9731. tag = Log.GLOBAL_TAG;
  9732. var str = "[" + tag + "] > " + msg;
  9733. if (Log.ENABLE_CALLBACK) {
  9734. Log.emitter.emit('log', 'error', str);
  9735. }
  9736. if (!Log.ENABLE_ERROR) {
  9737. return;
  9738. }
  9739. if (console.error) {
  9740. console.error(str);
  9741. }
  9742. else if (console.warn) {
  9743. console.warn(str);
  9744. }
  9745. else {
  9746. console.log(str);
  9747. }
  9748. };
  9749. Log.i = function (tag, msg) {
  9750. if (!tag || Log.FORCE_GLOBAL_TAG)
  9751. tag = Log.GLOBAL_TAG;
  9752. var str = "[" + tag + "] > " + msg;
  9753. if (Log.ENABLE_CALLBACK) {
  9754. Log.emitter.emit('log', 'info', str);
  9755. }
  9756. if (!Log.ENABLE_INFO) {
  9757. return;
  9758. }
  9759. if (console.info) {
  9760. console.info(str);
  9761. }
  9762. else {
  9763. console.log(str);
  9764. }
  9765. };
  9766. Log.w = function (tag, msg) {
  9767. if (!tag || Log.FORCE_GLOBAL_TAG)
  9768. tag = Log.GLOBAL_TAG;
  9769. var str = "[" + tag + "] > " + msg;
  9770. if (Log.ENABLE_CALLBACK) {
  9771. Log.emitter.emit('log', 'warn', str);
  9772. }
  9773. if (!Log.ENABLE_WARN) {
  9774. return;
  9775. }
  9776. if (console.warn) {
  9777. console.warn(str);
  9778. }
  9779. else {
  9780. console.log(str);
  9781. }
  9782. };
  9783. Log.d = function (tag, msg) {
  9784. if (!tag || Log.FORCE_GLOBAL_TAG)
  9785. tag = Log.GLOBAL_TAG;
  9786. var str = "[" + tag + "] > " + msg;
  9787. if (Log.ENABLE_CALLBACK) {
  9788. Log.emitter.emit('log', 'debug', str);
  9789. }
  9790. if (!Log.ENABLE_DEBUG) {
  9791. return;
  9792. }
  9793. if (console.debug) {
  9794. console.debug(str);
  9795. }
  9796. else {
  9797. console.log(str);
  9798. }
  9799. };
  9800. Log.v = function (tag, msg) {
  9801. if (!tag || Log.FORCE_GLOBAL_TAG)
  9802. tag = Log.GLOBAL_TAG;
  9803. var str = "[" + tag + "] > " + msg;
  9804. if (Log.ENABLE_CALLBACK) {
  9805. Log.emitter.emit('log', 'verbose', str);
  9806. }
  9807. if (!Log.ENABLE_VERBOSE) {
  9808. return;
  9809. }
  9810. console.log(str);
  9811. };
  9812. return Log;
  9813. }());
  9814. Log.GLOBAL_TAG = 'flv.js';
  9815. Log.FORCE_GLOBAL_TAG = false;
  9816. Log.ENABLE_ERROR = true;
  9817. Log.ENABLE_INFO = true;
  9818. Log.ENABLE_WARN = true;
  9819. Log.ENABLE_DEBUG = true;
  9820. Log.ENABLE_VERBOSE = true;
  9821. Log.ENABLE_CALLBACK = false;
  9822. Log.emitter = new (events__WEBPACK_IMPORTED_MODULE_0___default())();
  9823. /* harmony default export */ __webpack_exports__["default"] = (Log);
  9824. /***/ }),
  9825. /***/ "./src/utils/logging-control.js":
  9826. /*!**************************************!*\
  9827. !*** ./src/utils/logging-control.js ***!
  9828. \**************************************/
  9829. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  9830. "use strict";
  9831. __webpack_require__.r(__webpack_exports__);
  9832. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! events */ "./node_modules/events/events.js");
  9833. /* harmony import */ var events__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(events__WEBPACK_IMPORTED_MODULE_0__);
  9834. /* harmony import */ var _logger_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./logger.js */ "./src/utils/logger.js");
  9835. /*
  9836. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  9837. *
  9838. * @author zheng qian <xqq@xqq.im>
  9839. *
  9840. * Licensed under the Apache License, Version 2.0 (the "License");
  9841. * you may not use this file except in compliance with the License.
  9842. * You may obtain a copy of the License at
  9843. *
  9844. * http://www.apache.org/licenses/LICENSE-2.0
  9845. *
  9846. * Unless required by applicable law or agreed to in writing, software
  9847. * distributed under the License is distributed on an "AS IS" BASIS,
  9848. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9849. * See the License for the specific language governing permissions and
  9850. * limitations under the License.
  9851. */
  9852. var LoggingControl = /** @class */ (function () {
  9853. function LoggingControl() {
  9854. }
  9855. Object.defineProperty(LoggingControl, "forceGlobalTag", {
  9856. get: function () {
  9857. return _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.FORCE_GLOBAL_TAG;
  9858. },
  9859. set: function (enable) {
  9860. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.FORCE_GLOBAL_TAG = enable;
  9861. LoggingControl._notifyChange();
  9862. },
  9863. enumerable: false,
  9864. configurable: true
  9865. });
  9866. Object.defineProperty(LoggingControl, "globalTag", {
  9867. get: function () {
  9868. return _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.GLOBAL_TAG;
  9869. },
  9870. set: function (tag) {
  9871. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.GLOBAL_TAG = tag;
  9872. LoggingControl._notifyChange();
  9873. },
  9874. enumerable: false,
  9875. configurable: true
  9876. });
  9877. Object.defineProperty(LoggingControl, "enableAll", {
  9878. get: function () {
  9879. return _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_VERBOSE
  9880. && _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_DEBUG
  9881. && _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_INFO
  9882. && _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_WARN
  9883. && _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_ERROR;
  9884. },
  9885. set: function (enable) {
  9886. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_VERBOSE = enable;
  9887. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_DEBUG = enable;
  9888. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_INFO = enable;
  9889. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_WARN = enable;
  9890. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_ERROR = enable;
  9891. LoggingControl._notifyChange();
  9892. },
  9893. enumerable: false,
  9894. configurable: true
  9895. });
  9896. Object.defineProperty(LoggingControl, "enableDebug", {
  9897. get: function () {
  9898. return _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_DEBUG;
  9899. },
  9900. set: function (enable) {
  9901. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_DEBUG = enable;
  9902. LoggingControl._notifyChange();
  9903. },
  9904. enumerable: false,
  9905. configurable: true
  9906. });
  9907. Object.defineProperty(LoggingControl, "enableVerbose", {
  9908. get: function () {
  9909. return _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_VERBOSE;
  9910. },
  9911. set: function (enable) {
  9912. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_VERBOSE = enable;
  9913. LoggingControl._notifyChange();
  9914. },
  9915. enumerable: false,
  9916. configurable: true
  9917. });
  9918. Object.defineProperty(LoggingControl, "enableInfo", {
  9919. get: function () {
  9920. return _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_INFO;
  9921. },
  9922. set: function (enable) {
  9923. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_INFO = enable;
  9924. LoggingControl._notifyChange();
  9925. },
  9926. enumerable: false,
  9927. configurable: true
  9928. });
  9929. Object.defineProperty(LoggingControl, "enableWarn", {
  9930. get: function () {
  9931. return _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_WARN;
  9932. },
  9933. set: function (enable) {
  9934. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_WARN = enable;
  9935. LoggingControl._notifyChange();
  9936. },
  9937. enumerable: false,
  9938. configurable: true
  9939. });
  9940. Object.defineProperty(LoggingControl, "enableError", {
  9941. get: function () {
  9942. return _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_ERROR;
  9943. },
  9944. set: function (enable) {
  9945. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_ERROR = enable;
  9946. LoggingControl._notifyChange();
  9947. },
  9948. enumerable: false,
  9949. configurable: true
  9950. });
  9951. LoggingControl.getConfig = function () {
  9952. return {
  9953. globalTag: _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.GLOBAL_TAG,
  9954. forceGlobalTag: _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.FORCE_GLOBAL_TAG,
  9955. enableVerbose: _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_VERBOSE,
  9956. enableDebug: _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_DEBUG,
  9957. enableInfo: _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_INFO,
  9958. enableWarn: _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_WARN,
  9959. enableError: _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_ERROR,
  9960. enableCallback: _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_CALLBACK
  9961. };
  9962. };
  9963. LoggingControl.applyConfig = function (config) {
  9964. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.GLOBAL_TAG = config.globalTag;
  9965. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.FORCE_GLOBAL_TAG = config.forceGlobalTag;
  9966. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_VERBOSE = config.enableVerbose;
  9967. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_DEBUG = config.enableDebug;
  9968. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_INFO = config.enableInfo;
  9969. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_WARN = config.enableWarn;
  9970. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_ERROR = config.enableError;
  9971. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_CALLBACK = config.enableCallback;
  9972. };
  9973. LoggingControl._notifyChange = function () {
  9974. var emitter = LoggingControl.emitter;
  9975. if (emitter.listenerCount('change') > 0) {
  9976. var config = LoggingControl.getConfig();
  9977. emitter.emit('change', config);
  9978. }
  9979. };
  9980. LoggingControl.registerListener = function (listener) {
  9981. LoggingControl.emitter.addListener('change', listener);
  9982. };
  9983. LoggingControl.removeListener = function (listener) {
  9984. LoggingControl.emitter.removeListener('change', listener);
  9985. };
  9986. LoggingControl.addLogListener = function (listener) {
  9987. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.emitter.addListener('log', listener);
  9988. if (_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.emitter.listenerCount('log') > 0) {
  9989. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_CALLBACK = true;
  9990. LoggingControl._notifyChange();
  9991. }
  9992. };
  9993. LoggingControl.removeLogListener = function (listener) {
  9994. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.emitter.removeListener('log', listener);
  9995. if (_logger_js__WEBPACK_IMPORTED_MODULE_1__.default.emitter.listenerCount('log') === 0) {
  9996. _logger_js__WEBPACK_IMPORTED_MODULE_1__.default.ENABLE_CALLBACK = false;
  9997. LoggingControl._notifyChange();
  9998. }
  9999. };
  10000. return LoggingControl;
  10001. }());
  10002. LoggingControl.emitter = new (events__WEBPACK_IMPORTED_MODULE_0___default())();
  10003. /* harmony default export */ __webpack_exports__["default"] = (LoggingControl);
  10004. /***/ }),
  10005. /***/ "./src/utils/polyfill.js":
  10006. /*!*******************************!*\
  10007. !*** ./src/utils/polyfill.js ***!
  10008. \*******************************/
  10009. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  10010. "use strict";
  10011. __webpack_require__.r(__webpack_exports__);
  10012. /*
  10013. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  10014. *
  10015. * @author zheng qian <xqq@xqq.im>
  10016. *
  10017. * Licensed under the Apache License, Version 2.0 (the "License");
  10018. * you may not use this file except in compliance with the License.
  10019. * You may obtain a copy of the License at
  10020. *
  10021. * http://www.apache.org/licenses/LICENSE-2.0
  10022. *
  10023. * Unless required by applicable law or agreed to in writing, software
  10024. * distributed under the License is distributed on an "AS IS" BASIS,
  10025. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10026. * See the License for the specific language governing permissions and
  10027. * limitations under the License.
  10028. */
  10029. var Polyfill = /** @class */ (function () {
  10030. function Polyfill() {
  10031. }
  10032. Polyfill.install = function () {
  10033. // ES6 Object.setPrototypeOf
  10034. Object.setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
  10035. obj.__proto__ = proto;
  10036. return obj;
  10037. };
  10038. // ES6 Object.assign
  10039. Object.assign = Object.assign || function (target) {
  10040. if (target === undefined || target === null) {
  10041. throw new TypeError('Cannot convert undefined or null to object');
  10042. }
  10043. var output = Object(target);
  10044. for (var i = 1; i < arguments.length; i++) {
  10045. var source = arguments[i];
  10046. if (source !== undefined && source !== null) {
  10047. for (var key in source) {
  10048. if (source.hasOwnProperty(key)) {
  10049. output[key] = source[key];
  10050. }
  10051. }
  10052. }
  10053. }
  10054. return output;
  10055. };
  10056. // ES6 Promise (missing support in IE11)
  10057. if (typeof self.Promise !== 'function') {
  10058. __webpack_require__(/*! es6-promise */ "./node_modules/es6-promise/dist/es6-promise.js").polyfill();
  10059. }
  10060. };
  10061. return Polyfill;
  10062. }());
  10063. Polyfill.install();
  10064. /* harmony default export */ __webpack_exports__["default"] = (Polyfill);
  10065. /***/ }),
  10066. /***/ "./src/utils/utf8-conv.js":
  10067. /*!********************************!*\
  10068. !*** ./src/utils/utf8-conv.js ***!
  10069. \********************************/
  10070. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  10071. "use strict";
  10072. __webpack_require__.r(__webpack_exports__);
  10073. /*
  10074. * Copyright (C) 2016 Bilibili. All Rights Reserved.
  10075. *
  10076. * This file is derived from C++ project libWinTF8 (https://github.com/m13253/libWinTF8)
  10077. * @author zheng qian <xqq@xqq.im>
  10078. *
  10079. * Licensed under the Apache License, Version 2.0 (the "License");
  10080. * you may not use this file except in compliance with the License.
  10081. * You may obtain a copy of the License at
  10082. *
  10083. * http://www.apache.org/licenses/LICENSE-2.0
  10084. *
  10085. * Unless required by applicable law or agreed to in writing, software
  10086. * distributed under the License is distributed on an "AS IS" BASIS,
  10087. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10088. * See the License for the specific language governing permissions and
  10089. * limitations under the License.
  10090. */
  10091. function checkContinuation(uint8array, start, checkLength) {
  10092. var array = uint8array;
  10093. if (start + checkLength < array.length) {
  10094. while (checkLength--) {
  10095. if ((array[++start] & 0xC0) !== 0x80)
  10096. return false;
  10097. }
  10098. return true;
  10099. }
  10100. else {
  10101. return false;
  10102. }
  10103. }
  10104. function decodeUTF8(uint8array) {
  10105. var out = [];
  10106. var input = uint8array;
  10107. var i = 0;
  10108. var length = uint8array.length;
  10109. while (i < length) {
  10110. if (input[i] < 0x80) {
  10111. out.push(String.fromCharCode(input[i]));
  10112. ++i;
  10113. continue;
  10114. }
  10115. else if (input[i] < 0xC0) {
  10116. // fallthrough
  10117. }
  10118. else if (input[i] < 0xE0) {
  10119. if (checkContinuation(input, i, 1)) {
  10120. var ucs4 = (input[i] & 0x1F) << 6 | (input[i + 1] & 0x3F);
  10121. if (ucs4 >= 0x80) {
  10122. out.push(String.fromCharCode(ucs4 & 0xFFFF));
  10123. i += 2;
  10124. continue;
  10125. }
  10126. }
  10127. }
  10128. else if (input[i] < 0xF0) {
  10129. if (checkContinuation(input, i, 2)) {
  10130. var ucs4 = (input[i] & 0xF) << 12 | (input[i + 1] & 0x3F) << 6 | input[i + 2] & 0x3F;
  10131. if (ucs4 >= 0x800 && (ucs4 & 0xF800) !== 0xD800) {
  10132. out.push(String.fromCharCode(ucs4 & 0xFFFF));
  10133. i += 3;
  10134. continue;
  10135. }
  10136. }
  10137. }
  10138. else if (input[i] < 0xF8) {
  10139. if (checkContinuation(input, i, 3)) {
  10140. var ucs4 = (input[i] & 0x7) << 18 | (input[i + 1] & 0x3F) << 12
  10141. | (input[i + 2] & 0x3F) << 6 | (input[i + 3] & 0x3F);
  10142. if (ucs4 > 0x10000 && ucs4 < 0x110000) {
  10143. ucs4 -= 0x10000;
  10144. out.push(String.fromCharCode((ucs4 >>> 10) | 0xD800));
  10145. out.push(String.fromCharCode((ucs4 & 0x3FF) | 0xDC00));
  10146. i += 4;
  10147. continue;
  10148. }
  10149. }
  10150. }
  10151. out.push(String.fromCharCode(0xFFFD));
  10152. ++i;
  10153. }
  10154. return out.join('');
  10155. }
  10156. /* harmony default export */ __webpack_exports__["default"] = (decodeUTF8);
  10157. /***/ })
  10158. /******/ });
  10159. /************************************************************************/
  10160. /******/ // The module cache
  10161. /******/ var __webpack_module_cache__ = {};
  10162. /******/
  10163. /******/ // The require function
  10164. /******/ function __webpack_require__(moduleId) {
  10165. /******/ // Check if module is in cache
  10166. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  10167. /******/ if (cachedModule !== undefined) {
  10168. /******/ return cachedModule.exports;
  10169. /******/ }
  10170. /******/ // Create a new module (and put it into the cache)
  10171. /******/ var module = __webpack_module_cache__[moduleId] = {
  10172. /******/ // no module.id needed
  10173. /******/ // no module.loaded needed
  10174. /******/ exports: {}
  10175. /******/ };
  10176. /******/
  10177. /******/ // Execute the module function
  10178. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  10179. /******/
  10180. /******/ // Return the exports of the module
  10181. /******/ return module.exports;
  10182. /******/ }
  10183. /******/
  10184. /******/ // expose the modules object (__webpack_modules__)
  10185. /******/ __webpack_require__.m = __webpack_modules__;
  10186. /******/
  10187. /************************************************************************/
  10188. /******/ /* webpack/runtime/compat get default export */
  10189. /******/ !function() {
  10190. /******/ // getDefaultExport function for compatibility with non-harmony modules
  10191. /******/ __webpack_require__.n = function(module) {
  10192. /******/ var getter = module && module.__esModule ?
  10193. /******/ function() { return module['default']; } :
  10194. /******/ function() { return module; };
  10195. /******/ __webpack_require__.d(getter, { a: getter });
  10196. /******/ return getter;
  10197. /******/ };
  10198. /******/ }();
  10199. /******/
  10200. /******/ /* webpack/runtime/define property getters */
  10201. /******/ !function() {
  10202. /******/ // define getter functions for harmony exports
  10203. /******/ __webpack_require__.d = function(exports, definition) {
  10204. /******/ for(var key in definition) {
  10205. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  10206. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  10207. /******/ }
  10208. /******/ }
  10209. /******/ };
  10210. /******/ }();
  10211. /******/
  10212. /******/ /* webpack/runtime/global */
  10213. /******/ !function() {
  10214. /******/ __webpack_require__.g = (function() {
  10215. /******/ if (typeof globalThis === 'object') return globalThis;
  10216. /******/ try {
  10217. /******/ return this || new Function('return this')();
  10218. /******/ } catch (e) {
  10219. /******/ if (typeof window === 'object') return window;
  10220. /******/ }
  10221. /******/ })();
  10222. /******/ }();
  10223. /******/
  10224. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  10225. /******/ !function() {
  10226. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  10227. /******/ }();
  10228. /******/
  10229. /******/ /* webpack/runtime/make namespace object */
  10230. /******/ !function() {
  10231. /******/ // define __esModule on exports
  10232. /******/ __webpack_require__.r = function(exports) {
  10233. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  10234. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  10235. /******/ }
  10236. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  10237. /******/ };
  10238. /******/ }();
  10239. /******/
  10240. /************************************************************************/
  10241. /******/
  10242. /******/ // module factories are used so entry inlining is disabled
  10243. /******/ // startup
  10244. /******/ // Load entry module and return exports
  10245. /******/ var __webpack_exports__ = __webpack_require__("./src/index.js");
  10246. /******/
  10247. /******/ return __webpack_exports__;
  10248. /******/ })()
  10249. ;
  10250. });
  10251. //# sourceMappingURL=flv.js.map