Something went wrong. Try again.
🎥 Command line media player
Something went wrong. Try again.
C
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270/* * This file is part of mpv. * * mpv is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * mpv is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with mpv. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>#include <inttypes.h>#include <unistd.h>#include <string.h>#include <stdbool.h>#include <assert.h>#include <time.h>#include <math.h>#include <pthread.h>#include <sys/types.h>
#include <libavutil/avstring.h>#include <libavutil/common.h>
#include "config.h"#include "mpv_talloc.h"#include "client.h"#include "common/av_common.h"#include "common/codecs.h"#include "common/msg.h"#include "common/msg_control.h"#include "filters/f_decoder_wrapper.h"#include "command.h"#include "osdep/timer.h"#include "common/common.h"#include "input/input.h"#include "input/keycodes.h"#include "stream/stream.h"#include "demux/demux.h"#include "demux/stheader.h"#include "common/playlist.h"#include "sub/osd.h"#include "sub/dec_sub.h"#include "options/m_option.h"#include "options/m_property.h"#include "options/m_config.h"#include "video/out/vo.h"#include "video/csputils.h"#include "video/hwdec.h"#include "audio/aframe.h"#include "audio/format.h"#include "audio/out/ao.h"#include "video/out/bitmap_packer.h"#include "options/path.h"#include "screenshot.h"#include "misc/dispatch.h"#include "misc/node.h"#include "misc/thread_pool.h"#include "misc/thread_tools.h"
#include "osdep/io.h"#include "osdep/subprocess.h"
#include "core.h"
#ifdef _WIN32#include <windows.h>#endif
struct command_ctx { // All properties, terminated with a {0} item. struct m_property *properties;
bool is_idle;
double last_seek_time; double last_seek_pts; double marked_pts;
char **warned_deprecated; int num_warned_deprecated;
struct overlay *overlays; int num_overlays; // One of these is in use by the OSD; the other one exists so that the // bitmap list can be manipulated without additional synchronization. struct sub_bitmaps overlay_osd[2]; int overlay_osd_current; struct bitmap_packer *overlay_packer;
struct hook_handler **hooks; int num_hooks; int64_t hook_seq; // for hook_handler.seq
struct ao_hotplug *hotplug;
struct mp_cmd_ctx *cache_dump_cmd; // in progress cache dumping
char **script_props;
double cached_window_scale;};
static const struct m_option script_props_type = { .type = &m_option_type_keyvalue_list};
struct overlay { struct mp_image *source; int x, y;};
struct hook_handler { char *client; // client API user name char *type; // kind of hook, e.g. "on_load" uint64_t user_id; // user-chosen ID int priority; // priority for global hook order int64_t seq; // unique ID, != 0, also for fixed order on equal priorities bool legacy; // old cmd based hook API bool active; // hook is currently in progress (only 1 at a time for now)};
// U+279C HEAVY ROUND-TIPPED RIGHTWARDS ARROW// U+00A0 NO-BREAK SPACE#define ARROW_SP "\342\236\234\302\240"
const char list_current[] = OSD_ASS_0 ARROW_SP OSD_ASS_1;const char list_normal[] = OSD_ASS_0 "{\\alpha&HFF}" ARROW_SP "{\\r}" OSD_ASS_1;
static int edit_filters(struct MPContext *mpctx, struct mp_log *log, enum stream_type mediatype, const char *cmd, const char *arg);static int set_filters(struct MPContext *mpctx, enum stream_type mediatype, struct m_obj_settings *new_chain);
static bool is_property_set(int action, void *val);
static void hook_remove(struct MPContext *mpctx, struct hook_handler *h){ struct command_ctx *cmd = mpctx->command_ctx; for (int n = 0; n < cmd->num_hooks; n++) { if (cmd->hooks[n] == h) { talloc_free(cmd->hooks[n]); MP_TARRAY_REMOVE_AT(cmd->hooks, cmd->num_hooks, n); return; } } assert(0);}
bool mp_hook_test_completion(struct MPContext *mpctx, char *type){ struct command_ctx *cmd = mpctx->command_ctx; for (int n = 0; n < cmd->num_hooks; n++) { struct hook_handler *h = cmd->hooks[n]; if (h->active && strcmp(h->type, type) == 0) { if (!mp_client_exists(mpctx, h->client)) { MP_WARN(mpctx, "client removed during hook handling\n"); hook_remove(mpctx, h); break; } return false; } } return true;}
static int invoke_hook_handler(struct MPContext *mpctx, struct hook_handler *h){ MP_VERBOSE(mpctx, "Running hook: %s/%s\n", h->client, h->type); h->active = true;
uint64_t reply_id = 0; void *data; int msg; if (h->legacy) { mpv_event_client_message *m = talloc_ptrtype(NULL, m); *m = (mpv_event_client_message){0}; MP_TARRAY_APPEND(m, m->args, m->num_args, "hook_run"); MP_TARRAY_APPEND(m, m->args, m->num_args, talloc_asprintf(m, "%llu", (long long)h->user_id)); MP_TARRAY_APPEND(m, m->args, m->num_args, talloc_asprintf(m, "%llu", (long long)h->seq)); data = m; msg = MPV_EVENT_CLIENT_MESSAGE; } else { mpv_event_hook *m = talloc_ptrtype(NULL, m); *m = (mpv_event_hook){ .name = talloc_strdup(m, h->type), .id = h->seq, }, reply_id = h->user_id; data = m; msg = MPV_EVENT_HOOK; } int r = mp_client_send_event(mpctx, h->client, reply_id, msg, data); if (r < 0) { MP_WARN(mpctx, "Sending hook command failed. Removing hook.\n"); hook_remove(mpctx, h); mp_wakeup_core(mpctx); // repeat next iteration to finish } return r;}
static int run_next_hook_handler(struct MPContext *mpctx, char *type, int index){ struct command_ctx *cmd = mpctx->command_ctx;
for (int n = index; n < cmd->num_hooks; n++) { struct hook_handler *h = cmd->hooks[n]; if (strcmp(h->type, type) == 0) return invoke_hook_handler(mpctx, h); }
mp_wakeup_core(mpctx); // finished hook return 0;}
// Start processing script/client API hooks. This is asynchronous, and the// caller needs to use mp_hook_test_completion() to check whether they're done.void mp_hook_start(struct MPContext *mpctx, char *type){ while (run_next_hook_handler(mpctx, type, 0) < 0) { // We can repeat this until all broken clients have been removed, and // hook processing is successfully started. }}
int mp_hook_continue(struct MPContext *mpctx, char *client, uint64_t id){ struct command_ctx *cmd = mpctx->command_ctx;
for (int n = 0; n < cmd->num_hooks; n++) { struct hook_handler *h = cmd->hooks[n]; if (strcmp(h->client, client) == 0 && h->seq == id) { if (!h->active) break; h->active = false; return run_next_hook_handler(mpctx, h->type, n + 1); } }
MP_ERR(mpctx, "invalid hook API usage\n"); return MPV_ERROR_INVALID_PARAMETER;}
static int compare_hook(const void *pa, const void *pb){ struct hook_handler **h1 = (void *)pa; struct hook_handler **h2 = (void *)pb; if ((*h1)->priority != (*h2)->priority) return (*h1)->priority - (*h2)->priority; return (*h1)->seq - (*h2)->seq;}
void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name, uint64_t user_id, int pri, bool legacy){ if (legacy) MP_WARN(mpctx, "The old hook API is deprecated! Use the libmpv API.\n");
struct command_ctx *cmd = mpctx->command_ctx; struct hook_handler *h = talloc_ptrtype(cmd, h); int64_t seq = ++cmd->hook_seq; *h = (struct hook_handler){ .client = talloc_strdup(h, client), .type = talloc_strdup(h, name), .user_id = user_id, .priority = pri, .seq = seq, .legacy = legacy, }; MP_TARRAY_APPEND(cmd, cmd->hooks, cmd->num_hooks, h); qsort(cmd->hooks, cmd->num_hooks, sizeof(cmd->hooks[0]), compare_hook);}
// Call before a seek, in order to allow revert-seek to undo the seek.void mark_seek(struct MPContext *mpctx){ struct command_ctx *cmd = mpctx->command_ctx; double now = mp_time_sec(); if (now > cmd->last_seek_time + 2.0 || cmd->last_seek_pts == MP_NOPTS_VALUE) cmd->last_seek_pts = get_current_time(mpctx); cmd->last_seek_time = now;}
static char *skip_n_lines(char *text, int lines){ while (text && lines > 0) { char *next = strchr(text, '\n'); text = next ? next + 1 : NULL; lines--; } return text;}
static int count_lines(char *text){ int count = 0; while (text) { char *next = strchr(text, '\n'); if (!next || (next[0] == '\n' && !next[1])) break; text = next + 1; count++; } return count;}
// Given a huge string separated by new lines, attempts to cut off text above// the current line to keep the line visible, and below to keep rendering// performance up. pos gives the current line (0 for the first line).// "text" might be returned as is, or it can be freed and a new allocation is// returned.// This is only a heuristic - we can't deal with line breaking.static char *cut_osd_list(struct MPContext *mpctx, char *text, int pos){ int screen_h, font_h; osd_get_text_size(mpctx->osd, &screen_h, &font_h); int max_lines = screen_h / MPMAX(font_h, 1) - 1;
if (!text || max_lines < 5) return text;
int count = count_lines(text); if (count <= max_lines) return text;
char *new = talloc_strdup(NULL, "");
int start = MPMAX(pos - max_lines / 2, 0); if (start == 1) start = 0; // avoid weird transition when pad_h becomes visible int pad_h = start > 0;
int space = max_lines - pad_h - 1; int pad_t = count - start > space; if (!pad_t) start = count - space;
if (pad_h) { new = talloc_asprintf_append_buffer(new, "\342\206\221 (%d hidden items)\n", start); }
char *head = skip_n_lines(text, start); if (!head) { talloc_free(new); return text; }
int lines_shown = max_lines - pad_h - pad_t; char *tail = skip_n_lines(head, lines_shown); new = talloc_asprintf_append_buffer(new, "%.*s", (int)(tail ? tail - head : strlen(head)), head); if (pad_t) { new = talloc_asprintf_append_buffer(new, "\342\206\223 (%d hidden items)\n", count - start - lines_shown + 1); }
talloc_free(text); return new;}
static char *format_delay(double time){ return talloc_asprintf(NULL, "%d ms", (int)lrint(time * 1000));}
// Property-option bridge. (Maps the property to the option with the same name.)static int mp_property_generic_option(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct m_config_option *opt = m_config_get_co(mpctx->mconfig, bstr0(prop->name));
if (!opt) return M_PROPERTY_UNKNOWN;
switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = *(opt->opt); return M_PROPERTY_OK; case M_PROPERTY_GET: if (!opt->data) return M_PROPERTY_NOT_IMPLEMENTED; m_option_copy(opt->opt, arg, opt->data); return M_PROPERTY_OK; case M_PROPERTY_SET: if (m_config_set_option_raw(mpctx->mconfig, opt, arg, 0) < 0) return M_PROPERTY_ERROR; return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
/// Playback speed (RW)static int mp_property_playback_speed(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (action == M_PROPERTY_PRINT) { double speed = mpctx->opts->playback_speed; *(char **)arg = talloc_asprintf(NULL, "%.2f", speed); return M_PROPERTY_OK; } return mp_property_generic_option(mpctx, prop, action, arg);}
static int mp_property_av_speed_correction(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; char *type = prop->priv; double val = 0; switch (type[0]) { case 'a': val = mpctx->speed_factor_a; break; case 'v': val = mpctx->speed_factor_v; break; default: abort(); }
if (action == M_PROPERTY_PRINT) { *(char **)arg = talloc_asprintf(NULL, "%+.05f%%", (val - 1) * 100); return M_PROPERTY_OK; }
return m_property_double_ro(action, arg, val);}
static int mp_property_display_sync_active(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; return m_property_flag_ro(action, arg, mpctx->display_sync_active);}
/// filename with path (RO)static int mp_property_path(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->filename) return M_PROPERTY_UNAVAILABLE; return m_property_strdup_ro(action, arg, mpctx->filename);}
static int mp_property_filename(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->filename) return M_PROPERTY_UNAVAILABLE; char *filename = talloc_strdup(NULL, mpctx->filename); if (mp_is_url(bstr0(filename))) mp_url_unescape_inplace(filename); char *f = (char *)mp_basename(filename); if (!f[0]) f = filename; if (action == M_PROPERTY_KEY_ACTION) { struct m_property_action_arg *ka = arg; if (strcmp(ka->key, "no-ext") == 0) { action = ka->action; arg = ka->arg; bstr root; if (mp_splitext(f, &root)) f = bstrto0(filename, root); } } int r = m_property_strdup_ro(action, arg, f); talloc_free(filename); return r;}
static int mp_property_stream_open_filename(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->stream_open_filename || !mpctx->playing) return M_PROPERTY_UNAVAILABLE; switch (action) { case M_PROPERTY_SET: { if (mpctx->demuxer) return M_PROPERTY_ERROR; mpctx->stream_open_filename = talloc_strdup(mpctx->stream_open_filename, *(char **)arg); mp_notify_property(mpctx, prop->name); return M_PROPERTY_OK; } case M_PROPERTY_GET_TYPE: case M_PROPERTY_GET: return m_property_strdup_ro(action, arg, mpctx->stream_open_filename); } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_file_size(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE;
int64_t size = mpctx->demuxer->filesize; if (size < 0) return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_PRINT) { *(char **)arg = format_file_size(size); return M_PROPERTY_OK; } return m_property_int64_ro(action, arg, size);}
static int mp_property_media_title(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; char *name = NULL; if (mpctx->opts->media_title) name = mpctx->opts->media_title; if (name && name[0]) return m_property_strdup_ro(action, arg, name); if (mpctx->demuxer) { name = mp_tags_get_str(mpctx->demuxer->metadata, "service_name"); if (name && name[0]) return m_property_strdup_ro(action, arg, name); name = mp_tags_get_str(mpctx->demuxer->metadata, "title"); if (name && name[0]) return m_property_strdup_ro(action, arg, name); name = mp_tags_get_str(mpctx->demuxer->metadata, "icy-title"); if (name && name[0]) return m_property_strdup_ro(action, arg, name); } if (mpctx->playing && mpctx->playing->title) return m_property_strdup_ro(action, arg, mpctx->playing->title); return mp_property_filename(ctx, prop, action, arg);}
static int mp_property_stream_path(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer || !mpctx->demuxer->filename) return M_PROPERTY_UNAVAILABLE; return m_property_strdup_ro(action, arg, mpctx->demuxer->filename);}
/// Demuxer name (RO)static int mp_property_demuxer(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct demuxer *demuxer = mpctx->demuxer; if (!demuxer) return M_PROPERTY_UNAVAILABLE; return m_property_strdup_ro(action, arg, demuxer->desc->name);}
static int mp_property_file_format(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct demuxer *demuxer = mpctx->demuxer; if (!demuxer) return M_PROPERTY_UNAVAILABLE; const char *name = demuxer->filetype ? demuxer->filetype : demuxer->desc->name; return m_property_strdup_ro(action, arg, name);}
static int mp_property_stream_pos(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct demuxer *demuxer = mpctx->demuxer; if (!demuxer || demuxer->filepos < 0) return M_PROPERTY_UNAVAILABLE; return m_property_int64_ro(action, arg, demuxer->filepos);}
/// Stream end offset (RO)static int mp_property_stream_end(void *ctx, struct m_property *prop, int action, void *arg){ return mp_property_file_size(ctx, prop, action, arg);}
// Does some magic to handle "<name>/full" as time formatted with milliseconds.// Assumes prop is the type of the actual property.static int property_time(int action, void *arg, double time){ if (time == MP_NOPTS_VALUE) return M_PROPERTY_UNAVAILABLE;
const struct m_option time_type = {.type = CONF_TYPE_TIME}; switch (action) { case M_PROPERTY_GET: *(double *)arg = time; return M_PROPERTY_OK; case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = time_type; return M_PROPERTY_OK; case M_PROPERTY_KEY_ACTION: { struct m_property_action_arg *ka = arg;
if (strcmp(ka->key, "full") != 0) return M_PROPERTY_UNKNOWN;
switch (ka->action) { case M_PROPERTY_GET: *(double *)ka->arg = time; return M_PROPERTY_OK; case M_PROPERTY_PRINT: *(char **)ka->arg = mp_format_time(time, true); return M_PROPERTY_OK; case M_PROPERTY_GET_TYPE: *(struct m_option *)ka->arg = time_type; return M_PROPERTY_OK; } } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_duration(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; double len = get_time_length(mpctx);
if (len < 0) return M_PROPERTY_UNAVAILABLE;
return property_time(action, arg, len);}
static int mp_property_avsync(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->ao_chain || !mpctx->vo_chain) return M_PROPERTY_UNAVAILABLE; if (action == M_PROPERTY_PRINT) { *(char **)arg = talloc_asprintf(NULL, "%7.3f", mpctx->last_av_difference); return M_PROPERTY_OK; } return m_property_double_ro(action, arg, mpctx->last_av_difference);}
static int mp_property_total_avsync_change(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->ao_chain || !mpctx->vo_chain) return M_PROPERTY_UNAVAILABLE; if (mpctx->total_avsync_change == MP_NOPTS_VALUE) return M_PROPERTY_UNAVAILABLE; return m_property_double_ro(action, arg, mpctx->total_avsync_change);}
static int mp_property_frame_drop_dec(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct mp_decoder_wrapper *dec = mpctx->vo_chain && mpctx->vo_chain->track ? mpctx->vo_chain->track->dec : NULL; if (!dec) return M_PROPERTY_UNAVAILABLE;
return m_property_int_ro(action, arg, dec->dropped_frames);}
static int mp_property_mistimed_frame_count(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->vo_chain || !mpctx->display_sync_active) return M_PROPERTY_UNAVAILABLE;
return m_property_int_ro(action, arg, mpctx->mistimed_frames_total);}
static int mp_property_vsync_ratio(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->vo_chain || !mpctx->display_sync_active) return M_PROPERTY_UNAVAILABLE;
int vsyncs = 0, frames = 0; for (int n = 0; n < mpctx->num_past_frames; n++) { int vsync = mpctx->past_frames[n].num_vsyncs; if (vsync < 0) break; vsyncs += vsync; frames += 1; }
if (!frames) return M_PROPERTY_UNAVAILABLE;
return m_property_double_ro(action, arg, vsyncs / (double)frames);}
static int mp_property_frame_drop_vo(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->vo_chain) return M_PROPERTY_UNAVAILABLE;
return m_property_int_ro(action, arg, vo_get_drop_count(mpctx->video_out));}
static int mp_property_vo_delayed_frame_count(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->vo_chain) return M_PROPERTY_UNAVAILABLE;
return m_property_int_ro(action, arg, vo_get_delayed_count(mpctx->video_out));}
/// Current position in percent (RW)static int mp_property_percent_pos(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->playback_initialized) return M_PROPERTY_UNAVAILABLE;
switch (action) { case M_PROPERTY_SET: { double pos = *(double *)arg; queue_seek(mpctx, MPSEEK_FACTOR, pos / 100.0, MPSEEK_DEFAULT, 0); return M_PROPERTY_OK; } case M_PROPERTY_GET: { double pos = get_current_pos_ratio(mpctx, false) * 100.0; if (pos < 0) return M_PROPERTY_UNAVAILABLE; *(double *)arg = pos; return M_PROPERTY_OK; } case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){ .type = CONF_TYPE_DOUBLE, .flags = M_OPT_RANGE, .min = 0, .max = 100, }; return M_PROPERTY_OK; case M_PROPERTY_PRINT: { int pos = get_percent_pos(mpctx); if (pos < 0) return M_PROPERTY_UNAVAILABLE; *(char **)arg = talloc_asprintf(NULL, "%d", pos); return M_PROPERTY_OK; } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_time_start(void *ctx, struct m_property *prop, int action, void *arg){ // minor backwards-compat. return property_time(action, arg, 0);}
/// Current position in seconds (RW)static int mp_property_time_pos(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->playback_initialized) return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_SET) { queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, MPSEEK_DEFAULT, 0); return M_PROPERTY_OK; } return property_time(action, arg, get_current_time(mpctx));}
/// Current audio pts in seconds (R)static int mp_property_audio_pts(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->playback_initialized || mpctx->audio_status < STATUS_PLAYING || mpctx->audio_status >= STATUS_EOF) return M_PROPERTY_UNAVAILABLE;
return property_time(action, arg, playing_audio_pts(mpctx));}
static bool time_remaining(MPContext *mpctx, double *remaining){ double len = get_time_length(mpctx); double playback = get_playback_time(mpctx);
if (playback == MP_NOPTS_VALUE || len <= 0) return false;
*remaining = len - playback;
return len >= 0;}
static int mp_property_remaining(void *ctx, struct m_property *prop, int action, void *arg){ double remaining; if (!time_remaining(ctx, &remaining)) return M_PROPERTY_UNAVAILABLE;
return property_time(action, arg, remaining);}
static int mp_property_playtime_remaining(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; double remaining; if (!time_remaining(mpctx, &remaining)) return M_PROPERTY_UNAVAILABLE;
double speed = mpctx->video_speed; return property_time(action, arg, remaining / speed);}
static int mp_property_playback_time(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->playback_initialized) return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_SET) { queue_seek(mpctx, MPSEEK_ABSOLUTE, *(double *)arg, MPSEEK_DEFAULT, 0); return M_PROPERTY_OK; } return property_time(action, arg, get_playback_time(mpctx));}
/// Current chapter (RW)static int mp_property_chapter(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->playback_initialized) return M_PROPERTY_UNAVAILABLE;
int chapter = get_current_chapter(mpctx); int num = get_chapter_count(mpctx); if (chapter < -1) return M_PROPERTY_UNAVAILABLE;
switch (action) { case M_PROPERTY_GET: *(int *) arg = chapter; return M_PROPERTY_OK; case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){ .type = CONF_TYPE_INT, .flags = M_OPT_MIN | M_OPT_MAX, .min = -1, .max = num - 1, }; return M_PROPERTY_OK; case M_PROPERTY_PRINT: { *(char **) arg = chapter_display_name(mpctx, chapter); return M_PROPERTY_OK; } case M_PROPERTY_SWITCH: case M_PROPERTY_SET: ; mark_seek(mpctx); int step_all; if (action == M_PROPERTY_SWITCH) { struct m_property_switch_arg *sarg = arg; step_all = lrint(sarg->inc); // Check threshold for relative backward seeks if (mpctx->opts->chapter_seek_threshold >= 0 && step_all < 0) { double current_chapter_start = chapter_start_time(mpctx, chapter); // If we are far enough into a chapter, seek back to the // beginning of current chapter instead of previous one if (current_chapter_start != MP_NOPTS_VALUE && get_current_time(mpctx) - current_chapter_start > mpctx->opts->chapter_seek_threshold) { step_all++; } } } else // Absolute set step_all = *(int *)arg - chapter; chapter += step_all; if (chapter < -1) chapter = -1; if (chapter >= num && step_all > 0) { if (mpctx->opts->keep_open) { seek_to_last_frame(mpctx); } else { // semi-broken file; ignore for user convenience if (action == M_PROPERTY_SWITCH && num < 2) return M_PROPERTY_UNAVAILABLE; if (!mpctx->stop_play) mpctx->stop_play = PT_NEXT_ENTRY; mp_wakeup_core(mpctx); } } else { double pts = chapter_start_time(mpctx, chapter); if (pts != MP_NOPTS_VALUE) { queue_seek(mpctx, MPSEEK_ABSOLUTE, pts, MPSEEK_DEFAULT, 0); mpctx->last_chapter_seek = chapter; mpctx->last_chapter_pts = pts; } } return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
static int get_chapter_entry(int item, int action, void *arg, void *ctx){ struct MPContext *mpctx = ctx; char *name = chapter_name(mpctx, item); double time = chapter_start_time(mpctx, item); struct m_sub_property props[] = { {"title", SUB_PROP_STR(name)}, {"time", {.type = CONF_TYPE_TIME}, {.time = time}}, {0} };
int r = m_property_read_sub(props, action, arg); return r;}
static int parse_node_chapters(struct MPContext *mpctx, struct mpv_node *given_chapters){ if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE;
if (given_chapters->format != MPV_FORMAT_NODE_ARRAY) return M_PROPERTY_ERROR;
double len = get_time_length(mpctx);
talloc_free(mpctx->chapters); mpctx->num_chapters = 0; mpctx->chapters = talloc_array(NULL, struct demux_chapter, 0);
for (int n = 0; n < given_chapters->u.list->num; n++) { struct mpv_node *chapter_data = &given_chapters->u.list->values[n];
if (chapter_data->format != MPV_FORMAT_NODE_MAP) continue;
mpv_node_list *chapter_data_elements = chapter_data->u.list;
double time = -1; char *title = 0;
for (int e = 0; e < chapter_data_elements->num; e++) { struct mpv_node *chapter_data_element = &chapter_data_elements->values[e]; char *key = chapter_data_elements->keys[e]; switch (chapter_data_element->format) { case MPV_FORMAT_INT64: if (strcmp(key, "time") == 0) time = (double)chapter_data_element->u.int64; break; case MPV_FORMAT_DOUBLE: if (strcmp(key, "time") == 0) time = chapter_data_element->u.double_; break; case MPV_FORMAT_STRING: if (strcmp(key, "title") == 0) title = chapter_data_element->u.string; break; } }
if (time >= 0 && time < len) { struct demux_chapter new = { .pts = time, .metadata = talloc_zero(mpctx->chapters, struct mp_tags), }; if (title) mp_tags_set_str(new.metadata, "title", title); MP_TARRAY_APPEND(NULL, mpctx->chapters, mpctx->num_chapters, new); } }
mp_notify(mpctx, MPV_EVENT_CHAPTER_CHANGE, NULL); mp_notify_property(mpctx, "chapter-list");
return M_PROPERTY_OK;}
static int mp_property_list_chapters(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; int count = get_chapter_count(mpctx); switch (action) { case M_PROPERTY_PRINT: { int cur = mpctx->playback_initialized ? get_current_chapter(mpctx) : -1; char *res = NULL; int n;
if (count < 1) { res = talloc_asprintf_append(res, "No chapters."); }
for (n = 0; n < count; n++) { char *name = chapter_display_name(mpctx, n); double t = chapter_start_time(mpctx, n); char* time = mp_format_time(t, false); res = talloc_asprintf_append(res, "%s", time); talloc_free(time); const char *m = n == cur ? list_current : list_normal; res = talloc_asprintf_append(res, " %s%s\n", m, name); talloc_free(name); }
*(char **)arg = res; return M_PROPERTY_OK; } case M_PROPERTY_SET: { struct mpv_node *given_chapters = arg; return parse_node_chapters(mpctx, given_chapters); } } return m_property_read_list(action, arg, count, get_chapter_entry, mpctx);}
static int mp_property_current_edition(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct demuxer *demuxer = mpctx->demuxer; if (!demuxer || demuxer->num_editions <= 0) return M_PROPERTY_UNAVAILABLE; return m_property_int_ro(action, arg, demuxer->edition);}
static int mp_property_edition(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct demuxer *demuxer = mpctx->demuxer;
if (action == M_PROPERTY_GET_CONSTRICTED_TYPE && demuxer) { *(struct m_option *)arg = (struct m_option){ .type = CONF_TYPE_INT, .flags = M_OPT_RANGE, .min = 0, .max = demuxer->num_editions - 1, }; return M_PROPERTY_OK; }
return mp_property_generic_option(mpctx, prop, action, arg);}
static int get_edition_entry(int item, int action, void *arg, void *ctx){ struct MPContext *mpctx = ctx;
struct demuxer *demuxer = mpctx->demuxer; struct demux_edition *ed = &demuxer->editions[item];
char *title = mp_tags_get_str(ed->metadata, "title");
struct m_sub_property props[] = { {"id", SUB_PROP_INT(item)}, {"title", SUB_PROP_STR(title), .unavailable = !title}, {"default", SUB_PROP_FLAG(ed->default_edition)}, {0} };
return m_property_read_sub(props, action, arg);}
static int property_list_editions(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct demuxer *demuxer = mpctx->demuxer; if (!demuxer) return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_PRINT) { char *res = NULL;
struct demux_edition *editions = demuxer->editions; int num_editions = demuxer->num_editions; int current = demuxer->edition;
if (!num_editions) res = talloc_asprintf_append(res, "No editions.");
for (int n = 0; n < num_editions; n++) { struct demux_edition *ed = &editions[n];
res = talloc_strdup_append(res, n == current ? list_current : list_normal); res = talloc_asprintf_append(res, "%d: ", n); char *title = mp_tags_get_str(ed->metadata, "title"); if (!title) title = "unnamed"; res = talloc_asprintf_append(res, "'%s'\n", title); }
*(char **)arg = res; return M_PROPERTY_OK; } return m_property_read_list(action, arg, demuxer->num_editions, get_edition_entry, mpctx);}
/// Number of chapters in filestatic int mp_property_chapters(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->playback_initialized) return M_PROPERTY_UNAVAILABLE; int count = get_chapter_count(mpctx); return m_property_int_ro(action, arg, count);}
static int mp_property_editions(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct demuxer *demuxer = mpctx->demuxer; if (!demuxer) return M_PROPERTY_UNAVAILABLE; if (demuxer->num_editions <= 0) return M_PROPERTY_UNAVAILABLE; return m_property_int_ro(action, arg, demuxer->num_editions);}
static int get_tag_entry(int item, int action, void *arg, void *ctx){ struct mp_tags *tags = ctx;
struct m_sub_property props[] = { {"key", SUB_PROP_STR(tags->keys[item])}, {"value", SUB_PROP_STR(tags->values[item])}, {0} };
return m_property_read_sub(props, action, arg);}
// tags can be NULL for M_PROPERTY_GET_TYPE. (In all other cases, tags must be// provided, even for M_PROPERTY_KEY_ACTION GET_TYPE sub-actions.)static int tag_property(int action, void *arg, struct mp_tags *tags){ switch (action) { case M_PROPERTY_GET_NODE: // same as GET, because type==mpv_node case M_PROPERTY_GET: { mpv_node_list *list = talloc_zero(NULL, mpv_node_list); mpv_node node = { .format = MPV_FORMAT_NODE_MAP, .u.list = list, }; list->num = tags->num_keys; list->values = talloc_array(list, mpv_node, list->num); list->keys = talloc_array(list, char*, list->num); for (int n = 0; n < tags->num_keys; n++) { list->keys[n] = talloc_strdup(list, tags->keys[n]); list->values[n] = (struct mpv_node){ .format = MPV_FORMAT_STRING, .u.string = talloc_strdup(list, tags->values[n]), }; } *(mpv_node*)arg = node; return M_PROPERTY_OK; } case M_PROPERTY_GET_TYPE: { *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE}; return M_PROPERTY_OK; } case M_PROPERTY_PRINT: { char *res = NULL; for (int n = 0; n < tags->num_keys; n++) { res = talloc_asprintf_append_buffer(res, "%s: %s\n", tags->keys[n], tags->values[n]); } if (!res) res = talloc_strdup(NULL, "(empty)"); *(char **)arg = res; return M_PROPERTY_OK; } case M_PROPERTY_KEY_ACTION: { struct m_property_action_arg *ka = arg; bstr key; char *rem; m_property_split_path(ka->key, &key, &rem); if (bstr_equals0(key, "list")) { struct m_property_action_arg nka = *ka; nka.key = rem; return m_property_read_list(action, &nka, tags->num_keys, get_tag_entry, tags); } // Direct access without this prefix is allowed for compatibility. bstr k = bstr0(ka->key); bstr_eatstart0(&k, "by-key/"); char *meta = mp_tags_get_bstr(tags, k); if (!meta) return M_PROPERTY_UNKNOWN; switch (ka->action) { case M_PROPERTY_GET: *(char **)ka->arg = talloc_strdup(NULL, meta); return M_PROPERTY_OK; case M_PROPERTY_GET_TYPE: *(struct m_option *)ka->arg = (struct m_option){ .type = CONF_TYPE_STRING, }; return M_PROPERTY_OK; } } } return M_PROPERTY_NOT_IMPLEMENTED;}
/// Demuxer meta datastatic int mp_property_metadata(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct demuxer *demuxer = mpctx->demuxer; if (!demuxer) return M_PROPERTY_UNAVAILABLE;
return tag_property(action, arg, demuxer->metadata);}
static int mp_property_filtered_metadata(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->filtered_tags) return M_PROPERTY_UNAVAILABLE;
return tag_property(action, arg, mpctx->filtered_tags);}
static int mp_property_chapter_metadata(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; int chapter = get_current_chapter(mpctx); if (chapter < 0) return M_PROPERTY_UNAVAILABLE; return tag_property(action, arg, mpctx->chapters[chapter].metadata);}
static int mp_property_filter_metadata(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; const char *type = prop->priv;
if (action == M_PROPERTY_KEY_ACTION) { struct m_property_action_arg *ka = arg; bstr key; char *rem; m_property_split_path(ka->key, &key, &rem); struct mp_tags *metadata = NULL; struct mp_output_chain *chain = NULL; if (strcmp(type, "vf") == 0) { chain = mpctx->vo_chain ? mpctx->vo_chain->filter : NULL; } else if (strcmp(type, "af") == 0) { chain = mpctx->ao_chain ? mpctx->ao_chain->filter : NULL; } if (!chain) return M_PROPERTY_UNAVAILABLE;
if (ka->action != M_PROPERTY_GET_TYPE) { struct mp_filter_command cmd = { .type = MP_FILTER_COMMAND_GET_META, .res = &metadata, }; mp_output_chain_command(chain, mp_tprintf(80, "%.*s", BSTR_P(key)), &cmd);
if (!metadata) return M_PROPERTY_ERROR; }
int res; if (strlen(rem)) { struct m_property_action_arg next_ka = *ka; next_ka.key = rem; res = tag_property(M_PROPERTY_KEY_ACTION, &next_ka, metadata); } else { res = tag_property(ka->action, ka->arg, metadata); } talloc_free(metadata); return res; } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_core_idle(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; return m_property_flag_ro(action, arg, !mpctx->playback_active);}
static int mp_property_idle(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx; return m_property_flag_ro(action, arg, cmd->is_idle);}
static int mp_property_eof_reached(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->playback_initialized) return M_PROPERTY_UNAVAILABLE; bool eof = mpctx->video_status == STATUS_EOF && mpctx->audio_status == STATUS_EOF; return m_property_flag_ro(action, arg, eof);}
static int mp_property_seeking(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->playback_initialized) return M_PROPERTY_UNAVAILABLE; return m_property_flag_ro(action, arg, !mpctx->restart_complete);}
static int mp_property_playback_abort(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; return m_property_flag_ro(action, arg, !mpctx->playing || mpctx->stop_play);}
static int mp_property_cache_speed(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE;
struct demux_reader_state s; demux_get_reader_state(mpctx->demuxer, &s);
uint64_t val = s.bytes_per_second;
if (action == M_PROPERTY_PRINT) { *(char **)arg = talloc_strdup_append(format_file_size(val), "/s"); return M_PROPERTY_OK; } return m_property_int64_ro(action, arg, val);}
static int mp_property_demuxer_cache_duration(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE;
struct demux_reader_state s; demux_get_reader_state(mpctx->demuxer, &s);
if (s.ts_duration < 0) return M_PROPERTY_UNAVAILABLE;
return m_property_double_ro(action, arg, s.ts_duration);}
static int mp_property_demuxer_cache_time(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE;
struct demux_reader_state s; demux_get_reader_state(mpctx->demuxer, &s);
if (s.ts_end == MP_NOPTS_VALUE) return M_PROPERTY_UNAVAILABLE;
return m_property_double_ro(action, arg, s.ts_end);}
static int mp_property_demuxer_cache_idle(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE;
struct demux_reader_state s; demux_get_reader_state(mpctx->demuxer, &s);
return m_property_flag_ro(action, arg, s.idle);}
static int mp_property_demuxer_cache_state(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE;
if (action == M_PROPERTY_GET_TYPE) { *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE}; return M_PROPERTY_OK; } if (action != M_PROPERTY_GET) return M_PROPERTY_NOT_IMPLEMENTED;
struct demux_reader_state s; demux_get_reader_state(mpctx->demuxer, &s);
struct mpv_node *r = (struct mpv_node *)arg; node_init(r, MPV_FORMAT_NODE_MAP, NULL);
if (s.ts_end != MP_NOPTS_VALUE) node_map_add_double(r, "cache-end", s.ts_end);
if (s.ts_reader != MP_NOPTS_VALUE) node_map_add_double(r, "reader-pts", s.ts_reader);
if (s.ts_duration >= 0) node_map_add_double(r, "cache-duration", s.ts_duration);
node_map_add_flag(r, "eof", s.eof); node_map_add_flag(r, "underrun", s.underrun); node_map_add_flag(r, "idle", s.idle); node_map_add_int64(r, "total-bytes", s.total_bytes); node_map_add_int64(r, "fw-bytes", s.fw_bytes); if (s.file_cache_bytes >= 0) node_map_add_int64(r, "file-cache-bytes", s.file_cache_bytes); if (s.seeking != MP_NOPTS_VALUE) node_map_add_double(r, "debug-seeking", s.seeking); node_map_add_int64(r, "debug-low-level-seeks", s.low_level_seeks); node_map_add_int64(r, "debug-byte-level-seeks", s.byte_level_seeks); if (s.ts_last != MP_NOPTS_VALUE) node_map_add_double(r, "debug-ts-last", s.ts_last);
node_map_add_flag(r, "bof-cached", s.bof_cached); node_map_add_flag(r, "eof-cached", s.eof_cached);
struct mpv_node *ranges = node_map_add(r, "seekable-ranges", MPV_FORMAT_NODE_ARRAY); for (int n = s.num_seek_ranges - 1; n >= 0; n--) { struct demux_seek_range *range = &s.seek_ranges[n]; struct mpv_node *sub = node_array_add(ranges, MPV_FORMAT_NODE_MAP); node_map_add_double(sub, "start", range->start); node_map_add_double(sub, "end", range->end); }
return M_PROPERTY_OK;}
static int mp_property_demuxer_start_time(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE;
return m_property_double_ro(action, arg, mpctx->demuxer->start_time);}
static int mp_property_paused_for_cache(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->playback_initialized) return M_PROPERTY_UNAVAILABLE; return m_property_flag_ro(action, arg, mpctx->paused_for_cache);}
static int mp_property_cache_buffering(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; int state = get_cache_buffering_percentage(mpctx); if (state < 0) return M_PROPERTY_UNAVAILABLE; return m_property_int_ro(action, arg, state);}
static int mp_property_demuxer_is_network(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE;
return m_property_flag_ro(action, arg, mpctx->demuxer->is_network);}
static int mp_property_clock(void *ctx, struct m_property *prop, int action, void *arg){ char outstr[6]; time_t t = time(NULL); struct tm *tmp = localtime(&t);
if ((tmp != NULL) && (strftime(outstr, sizeof(outstr), "%H:%M", tmp) == 5)) return m_property_strdup_ro(action, arg, outstr); return M_PROPERTY_UNAVAILABLE;}
static int mp_property_seekable(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; return m_property_flag_ro(action, arg, mpctx->demuxer->seekable);}
static int mp_property_partially_seekable(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->demuxer) return M_PROPERTY_UNAVAILABLE; return m_property_flag_ro(action, arg, mpctx->demuxer->partially_seekable);}
static int mp_property_mixer_active(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; return m_property_flag_ro(action, arg, !!mpctx->ao);}
/// Volume (RW)static int mp_property_volume(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct MPOpts *opts = mpctx->opts;
switch (action) { case M_PROPERTY_GET_CONSTRICTED_TYPE: *(struct m_option *)arg = (struct m_option){ .type = CONF_TYPE_FLOAT, .flags = M_OPT_RANGE, .min = 0, .max = opts->softvol_max, }; return M_PROPERTY_OK; case M_PROPERTY_PRINT: *(char **)arg = talloc_asprintf(NULL, "%i", (int)opts->softvol_volume); return M_PROPERTY_OK; }
return mp_property_generic_option(mpctx, prop, action, arg);}
static int mp_property_ao_volume(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct ao *ao = mpctx->ao; if (!ao) return M_PROPERTY_NOT_IMPLEMENTED;
switch (action) { case M_PROPERTY_SET: { float value = *(float *)arg; ao_control_vol_t vol = {value, value}; if (ao_control(ao, AOCONTROL_SET_VOLUME, &vol) != CONTROL_OK) return M_PROPERTY_UNAVAILABLE; return M_PROPERTY_OK; } case M_PROPERTY_GET: { ao_control_vol_t vol = {0}; if (ao_control(ao, AOCONTROL_GET_VOLUME, &vol) != CONTROL_OK) return M_PROPERTY_UNAVAILABLE; *(float *)arg = (vol.left + vol.right) / 2.0f; return M_PROPERTY_OK; } case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){ .type = CONF_TYPE_FLOAT, .flags = M_OPT_RANGE, .min = 0, .max = 100, }; return M_PROPERTY_OK; case M_PROPERTY_PRINT: { ao_control_vol_t vol = {0}; if (ao_control(ao, AOCONTROL_GET_VOLUME, &vol) != CONTROL_OK) return M_PROPERTY_UNAVAILABLE; *(char **)arg = talloc_asprintf(NULL, "%.f", (vol.left + vol.right) / 2.0f); return M_PROPERTY_OK; } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_ao_mute(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct ao *ao = mpctx->ao; if (!ao) return M_PROPERTY_NOT_IMPLEMENTED;
switch (action) { case M_PROPERTY_SET: { bool value = *(int *)arg; if (ao_control(ao, AOCONTROL_SET_MUTE, &value) != CONTROL_OK) return M_PROPERTY_UNAVAILABLE; return M_PROPERTY_OK; } case M_PROPERTY_GET: { bool value = false; if (ao_control(ao, AOCONTROL_GET_MUTE, &value) != CONTROL_OK) return M_PROPERTY_UNAVAILABLE; *(int *)arg = value; return M_PROPERTY_OK; } case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_FLAG}; return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
static int get_device_entry(int item, int action, void *arg, void *ctx){ struct ao_device_list *list = ctx; struct ao_device_desc *entry = &list->devices[item];
struct m_sub_property props[] = { {"name", SUB_PROP_STR(entry->name)}, {"description", SUB_PROP_STR(entry->desc)}, {0} };
return m_property_read_sub(props, action, arg);}
static void create_hotplug(struct MPContext *mpctx){ struct command_ctx *cmd = mpctx->command_ctx;
if (!cmd->hotplug) { cmd->hotplug = ao_hotplug_create(mpctx->global, mp_wakeup_core_cb, mpctx); }}
static int mp_property_audio_device(void *ctx, struct m_property *prop, int action, void *arg){ struct MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx; if (action == M_PROPERTY_PRINT) { create_hotplug(mpctx);
char *name = NULL; if (mp_property_generic_option(mpctx, prop, M_PROPERTY_GET, &name) < 1) name = NULL;
struct ao_device_list *list = ao_hotplug_get_device_list(cmd->hotplug); for (int n = 0; n < list->num_devices; n++) { struct ao_device_desc *dev = &list->devices[n]; if (dev->name && name && strcmp(dev->name, name) == 0) { *(char **)arg = talloc_strdup(NULL, dev->desc ? dev->desc : "?"); talloc_free(name); return M_PROPERTY_OK; } }
talloc_free(name); } return mp_property_generic_option(mpctx, prop, action, arg);}
static int mp_property_audio_devices(void *ctx, struct m_property *prop, int action, void *arg){ struct MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx; create_hotplug(mpctx);
struct ao_device_list *list = ao_hotplug_get_device_list(cmd->hotplug); return m_property_read_list(action, arg, list->num_devices, get_device_entry, list);}
static int mp_property_ao(void *ctx, struct m_property *p, int action, void *arg){ MPContext *mpctx = ctx; return m_property_strdup_ro(action, arg, mpctx->ao ? ao_get_name(mpctx->ao) : NULL);}
/// Audio delay (RW)static int mp_property_audio_delay(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (action == M_PROPERTY_PRINT) { *(char **)arg = format_delay(mpctx->opts->audio_delay); return M_PROPERTY_OK; } return mp_property_generic_option(mpctx, prop, action, arg);}
/// Audio codec tag (RO)static int mp_property_audio_codec_name(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct track *track = mpctx->current_track[0][STREAM_AUDIO]; const char *c = track && track->stream ? track->stream->codec->codec : NULL; return m_property_strdup_ro(action, arg, c);}
/// Audio codec name (RO)static int mp_property_audio_codec(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct track *track = mpctx->current_track[0][STREAM_AUDIO]; const char *c = track && track->dec ? track->dec->decoder_desc : NULL; return m_property_strdup_ro(action, arg, c);}
static int property_audiofmt(struct mp_aframe *fmt, int action, void *arg){ if (!fmt || !mp_aframe_config_is_valid(fmt)) return M_PROPERTY_UNAVAILABLE;
struct mp_chmap chmap = {0}; mp_aframe_get_chmap(fmt, &chmap);
struct m_sub_property props[] = { {"samplerate", SUB_PROP_INT(mp_aframe_get_rate(fmt))}, {"channel-count", SUB_PROP_INT(chmap.num)}, {"channels", SUB_PROP_STR(mp_chmap_to_str(&chmap))}, {"hr-channels", SUB_PROP_STR(mp_chmap_to_str_hr(&chmap))}, {"format", SUB_PROP_STR(af_fmt_to_str(mp_aframe_get_format(fmt)))}, {0} };
return m_property_read_sub(props, action, arg);}
static int mp_property_audio_params(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; return property_audiofmt(mpctx->ao_chain ? mpctx->ao_chain->filter->input_aformat : NULL, action, arg);}
static int mp_property_audio_out_params(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct mp_aframe *frame = NULL; if (mpctx->ao) { frame = mp_aframe_create(); int samplerate; int format; struct mp_chmap channels; ao_get_format(mpctx->ao, &samplerate, &format, &channels); mp_aframe_set_rate(frame, samplerate); mp_aframe_set_format(frame, format); mp_aframe_set_chmap(frame, &channels); } int r = property_audiofmt(frame, action, arg); talloc_free(frame); return r;}
static struct track* track_next(struct MPContext *mpctx, enum stream_type type, int direction, struct track *track){ assert(direction == -1 || direction == +1); struct track *prev = NULL, *next = NULL; bool seen = track == NULL; for (int n = 0; n < mpctx->num_tracks; n++) { struct track *cur = mpctx->tracks[n]; if (cur->type == type) { if (cur == track) { seen = true; } else if (!cur->selected) { if (seen && !next) { next = cur; } if (!seen || !track) { prev = cur; } } } } return direction > 0 ? next : prev;}
static int property_switch_track(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; const int *def = prop->priv; int order = def[0]; enum stream_type type = def[1];
struct track *track = mpctx->current_track[order][type];
switch (action) { case M_PROPERTY_GET: if (mpctx->playback_initialized) { *(int *)arg = track ? track->user_tid : -2; } else { *(int *)arg = mpctx->opts->stream_id[order][type]; } return M_PROPERTY_OK; case M_PROPERTY_PRINT: if (track) { char *lang = track->lang; if (!lang) lang = "unknown";
if (track->title) { *(char **)arg = talloc_asprintf(NULL, "(%d) %s (\"%s\")", track->user_tid, lang, track->title); } else { *(char **)arg = talloc_asprintf(NULL, "(%d) %s", track->user_tid, lang); } } else { const char *msg = "no"; if (!mpctx->playback_initialized && mpctx->opts->stream_id[order][type] == -1) msg = "auto"; *(char **) arg = talloc_strdup(NULL, msg); } return M_PROPERTY_OK;
case M_PROPERTY_SWITCH: { if (mpctx->playback_initialized) { struct m_property_switch_arg *sarg = arg; do { track = track_next(mpctx, type, sarg->inc >= 0 ? +1 : -1, track); mp_switch_track_n(mpctx, order, type, track, FLAG_MARK_SELECTION); } while (mpctx->current_track[order][type] != track); print_track_list(mpctx, "Track switched:"); } else { // Simply cycle between "no" and "auto". It's possible that this does // not always do what the user means, but keep the complexity low. mpctx->opts->stream_id[order][type] = mpctx->opts->stream_id[order][type] == -1 ? -2 : -1; m_config_notify_change_opt_ptr(mpctx->mconfig, &mpctx->opts->stream_id[order][type]); } return M_PROPERTY_OK; } } return mp_property_generic_option(mpctx, prop, action, arg);}
static int track_channels(struct track *track){ return track->stream ? track->stream->codec->channels.num : 0;}
static int get_track_entry(int item, int action, void *arg, void *ctx){ struct MPContext *mpctx = ctx; struct track *track = mpctx->tracks[item];
struct mp_codec_params p = track->stream ? *track->stream->codec : (struct mp_codec_params){0};
const char *decoder_desc = NULL; if (track->dec) decoder_desc = track->dec->decoder_desc;
bool has_rg = track->stream && track->stream->codec->replaygain_data; struct replaygain_data rg = has_rg ? *track->stream->codec->replaygain_data : (struct replaygain_data){0};
double par = 0.0; if (p.par_h) par = p.par_w / (double) p.par_h;
struct m_sub_property props[] = { {"id", SUB_PROP_INT(track->user_tid)}, {"type", SUB_PROP_STR(stream_type_name(track->type)), .unavailable = !stream_type_name(track->type)}, {"src-id", SUB_PROP_INT(track->demuxer_id), .unavailable = track->demuxer_id == -1}, {"title", SUB_PROP_STR(track->title), .unavailable = !track->title}, {"lang", SUB_PROP_STR(track->lang), .unavailable = !track->lang}, {"audio-channels", SUB_PROP_INT(track_channels(track)), .unavailable = track_channels(track) <= 0}, {"albumart", SUB_PROP_FLAG(track->attached_picture)}, {"default", SUB_PROP_FLAG(track->default_track)}, {"forced", SUB_PROP_FLAG(track->forced_track)}, {"dependent", SUB_PROP_FLAG(track->dependent_track)}, {"visual-impaired", SUB_PROP_FLAG(track->visual_impaired_track)}, {"hearing-impaired", SUB_PROP_FLAG(track->hearing_impaired_track)}, {"external", SUB_PROP_FLAG(track->is_external)}, {"selected", SUB_PROP_FLAG(track->selected)}, {"external-filename", SUB_PROP_STR(track->external_filename), .unavailable = !track->external_filename}, {"ff-index", SUB_PROP_INT(track->ff_index)}, {"decoder-desc", SUB_PROP_STR(decoder_desc), .unavailable = !decoder_desc}, {"codec", SUB_PROP_STR(p.codec), .unavailable = !p.codec}, {"demux-w", SUB_PROP_INT(p.disp_w), .unavailable = !p.disp_w}, {"demux-h", SUB_PROP_INT(p.disp_h), .unavailable = !p.disp_h}, {"demux-channel-count", SUB_PROP_INT(p.channels.num), .unavailable = !p.channels.num}, {"demux-channels", SUB_PROP_STR(mp_chmap_to_str(&p.channels)), .unavailable = !p.channels.num}, {"demux-samplerate", SUB_PROP_INT(p.samplerate), .unavailable = !p.samplerate}, {"demux-fps", SUB_PROP_DOUBLE(p.fps), .unavailable = p.fps <= 0}, {"demux-bitrate", SUB_PROP_INT(p.bitrate), .unavailable = p.bitrate <= 0}, {"demux-rotation", SUB_PROP_INT(p.rotate), .unavailable = p.rotate <= 0}, {"demux-par", SUB_PROP_DOUBLE(par), .unavailable = par <= 0}, {"replaygain-track-peak", SUB_PROP_FLOAT(rg.track_peak), .unavailable = !has_rg}, {"replaygain-track-gain", SUB_PROP_FLOAT(rg.track_gain), .unavailable = !has_rg}, {"replaygain-album-peak", SUB_PROP_FLOAT(rg.album_peak), .unavailable = !has_rg}, {"replaygain-album-gain", SUB_PROP_FLOAT(rg.album_gain), .unavailable = !has_rg}, {0} };
return m_property_read_sub(props, action, arg);}
static const char *track_type_name(enum stream_type t){ switch (t) { case STREAM_VIDEO: return "Video"; case STREAM_AUDIO: return "Audio"; case STREAM_SUB: return "Sub"; } return NULL;}
static int property_list_tracks(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (action == M_PROPERTY_PRINT) { char *res = NULL;
for (int type = 0; type < STREAM_TYPE_COUNT; type++) { for (int n = 0; n < mpctx->num_tracks; n++) { struct track *track = mpctx->tracks[n]; if (track->type != type) continue;
res = talloc_asprintf_append(res, "%s: ", track_type_name(track->type)); res = talloc_strdup_append(res, track->selected ? list_current : list_normal); res = talloc_asprintf_append(res, "(%d) ", track->user_tid); if (track->title) res = talloc_asprintf_append(res, "'%s' ", track->title); if (track->lang) res = talloc_asprintf_append(res, "(%s) ", track->lang); if (track->is_external) res = talloc_asprintf_append(res, "(external) "); res = talloc_asprintf_append(res, "\n"); }
res = talloc_asprintf_append(res, "\n"); }
struct demuxer *demuxer = mpctx->demuxer; if (demuxer && demuxer->num_editions > 1) res = talloc_asprintf_append(res, "\nEdition: %d of %d\n", demuxer->edition + 1, demuxer->num_editions);
*(char **)arg = res; return M_PROPERTY_OK; } return m_property_read_list(action, arg, mpctx->num_tracks, get_track_entry, mpctx);}
static int mp_property_hwdec_current(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct track *track = mpctx->current_track[0][STREAM_VIDEO]; struct mp_decoder_wrapper *dec = track ? track->dec : NULL;
if (!dec) return M_PROPERTY_UNAVAILABLE;
char *current = NULL; mp_decoder_wrapper_control(dec, VDCTRL_GET_HWDEC, ¤t); if (!current) current = "no"; return m_property_strdup_ro(action, arg, current);}
static int mp_property_hwdec_interop(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->video_out || !mpctx->video_out->hwdec_devs) return M_PROPERTY_UNAVAILABLE;
char *names = hwdec_devices_get_names(mpctx->video_out->hwdec_devs); int res = m_property_strdup_ro(action, arg, names); talloc_free(names); return res;}
static int get_frame_count(struct MPContext *mpctx){ struct demuxer *demuxer = mpctx->demuxer; if (!demuxer) return -1; if (!mpctx->vo_chain) return -1; double len = get_time_length(mpctx); double fps = mpctx->vo_chain->filter->container_fps; if (len < 0 || fps <= 0) return 0;
return len * fps;}
static int mp_property_frame_number(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; int frames = get_frame_count(mpctx); if (frames < 0) return M_PROPERTY_UNAVAILABLE;
return m_property_int_ro(action, arg, lrint(get_current_pos_ratio(mpctx, false) * frames));}
static int mp_property_frame_count(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; int frames = get_frame_count(mpctx); if (frames < 0) return M_PROPERTY_UNAVAILABLE;
return m_property_int_ro(action, arg, frames);}
/// Video codec tag (RO)static int mp_property_video_format(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct track *track = mpctx->current_track[0][STREAM_VIDEO]; const char *c = track && track->stream ? track->stream->codec->codec : NULL; return m_property_strdup_ro(action, arg, c);}
/// Video codec name (RO)static int mp_property_video_codec(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct track *track = mpctx->current_track[0][STREAM_VIDEO]; const char *c = track && track->dec ? track->dec->decoder_desc : NULL; return m_property_strdup_ro(action, arg, c);}
static int property_imgparams(struct mp_image_params p, int action, void *arg){ if (!p.imgfmt) return M_PROPERTY_UNAVAILABLE;
int d_w, d_h; mp_image_params_get_dsize(&p, &d_w, &d_h);
struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(p.imgfmt); int bpp = 0; for (int i = 0; i < desc.num_planes; i++) bpp += desc.bpp[i] >> (desc.xs[i] + desc.ys[i]);
struct m_sub_property props[] = { {"pixelformat", SUB_PROP_STR(mp_imgfmt_to_name(p.imgfmt))}, {"average-bpp", SUB_PROP_INT(bpp), .unavailable = !bpp}, {"plane-depth", SUB_PROP_INT(desc.plane_bits), .unavailable = !(desc.flags & MP_IMGFLAG_YUV_P)}, {"w", SUB_PROP_INT(p.w)}, {"h", SUB_PROP_INT(p.h)}, {"dw", SUB_PROP_INT(d_w)}, {"dh", SUB_PROP_INT(d_h)}, {"aspect", SUB_PROP_FLOAT(d_w / (double)d_h)}, {"par", SUB_PROP_FLOAT(p.p_w / (double)p.p_h)}, {"colormatrix", SUB_PROP_STR(m_opt_choice_str(mp_csp_names, p.color.space))}, {"colorlevels", SUB_PROP_STR(m_opt_choice_str(mp_csp_levels_names, p.color.levels))}, {"primaries", SUB_PROP_STR(m_opt_choice_str(mp_csp_prim_names, p.color.primaries))}, {"gamma", SUB_PROP_STR(m_opt_choice_str(mp_csp_trc_names, p.color.gamma))}, {"sig-peak", SUB_PROP_FLOAT(p.color.sig_peak)}, {"light", SUB_PROP_STR(m_opt_choice_str(mp_csp_light_names, p.color.light))}, {"chroma-location", SUB_PROP_STR(m_opt_choice_str(mp_chroma_names, p.chroma_location))}, {"stereo-in", SUB_PROP_STR(m_opt_choice_str(mp_stereo3d_names, p.stereo3d))}, {"rotate", SUB_PROP_INT(p.rotate)}, {0} };
return m_property_read_sub(props, action, arg);}
static struct mp_image_params get_video_out_params(struct MPContext *mpctx){ if (!mpctx->vo_chain) return (struct mp_image_params){0};
return mpctx->vo_chain->filter->output_params;}
static int mp_property_vo_imgparams(void *ctx, struct m_property *prop, int action, void *arg){ return property_imgparams(get_video_out_params(ctx), action, arg);}
static int mp_property_dec_imgparams(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct mp_image_params p = {0}; struct vo_chain *vo_c = mpctx->vo_chain; if (vo_c && vo_c->track) mp_decoder_wrapper_get_video_dec_params(vo_c->track->dec, &p); if (!p.imgfmt) return M_PROPERTY_UNAVAILABLE; return property_imgparams(p, action, arg);}
static int mp_property_vd_imgparams(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct vo_chain *vo_c = mpctx->vo_chain; if (!vo_c) return M_PROPERTY_UNAVAILABLE; struct track *track = mpctx->current_track[0][STREAM_VIDEO]; struct mp_codec_params *c = track && track->stream ? track->stream->codec : NULL; if (vo_c->filter->input_params.imgfmt) { return property_imgparams(vo_c->filter->input_params, action, arg); } else if (c && c->disp_w && c->disp_h) { // Simplistic fallback for stupid scripts querying "width"/"height" // before the first frame is decoded. struct m_sub_property props[] = { {"w", SUB_PROP_INT(c->disp_w)}, {"h", SUB_PROP_INT(c->disp_h)}, {0} }; return m_property_read_sub(props, action, arg); } return M_PROPERTY_UNAVAILABLE;}
static int mp_property_video_frame_info(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct mp_image *f = mpctx->video_out ? vo_get_current_frame(mpctx->video_out) : NULL; if (!f) return M_PROPERTY_UNAVAILABLE;
const char *pict_types[] = {0, "I", "P", "B"}; const char *pict_type = f->pict_type >= 1 && f->pict_type <= 3 ? pict_types[f->pict_type] : NULL;
struct m_sub_property props[] = { {"picture-type", SUB_PROP_STR(pict_type), .unavailable = !pict_type}, {"interlaced", SUB_PROP_FLAG(!!(f->fields & MP_IMGFIELD_INTERLACED))}, {"tff", SUB_PROP_FLAG(!!(f->fields & MP_IMGFIELD_TOP_FIRST))}, {"repeat", SUB_PROP_FLAG(!!(f->fields & MP_IMGFIELD_REPEAT_FIRST))}, {0} };
talloc_free(f); return m_property_read_sub(props, action, arg);}
static int mp_property_current_window_scale(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct vo *vo = mpctx->video_out; if (!vo) return M_PROPERTY_UNAVAILABLE;
struct mp_image_params params = get_video_out_params(mpctx); int vid_w, vid_h; mp_image_params_get_dsize(¶ms, &vid_w, &vid_h); if (vid_w < 1 || vid_h < 1) return M_PROPERTY_UNAVAILABLE;
int s[2]; if (vo_control(vo, VOCTRL_GET_UNFS_WINDOW_SIZE, s) <= 0 || s[0] < 1 || s[1] < 1) return M_PROPERTY_UNAVAILABLE;
double xs = (double)s[0] / vid_w; double ys = (double)s[1] / vid_h; return m_property_double_ro(action, arg, (xs + ys) / 2);}
static void update_window_scale(struct MPContext *mpctx){ struct vo *vo = mpctx->video_out; if (!vo) return;
struct mp_image_params params = get_video_out_params(mpctx); int vid_w, vid_h; mp_image_params_get_dsize(¶ms, &vid_w, &vid_h); if (vid_w < 1 || vid_h < 1) return;
double scale = mpctx->opts->vo->window_scale; int s[2] = {vid_w * scale, vid_h * scale}; if (s[0] > 0 && s[1] > 0) vo_control(vo, VOCTRL_SET_UNFS_WINDOW_SIZE, s);}
static int mp_property_display_fps(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; double fps = mpctx->video_out ? vo_get_display_fps(mpctx->video_out) : 0; switch (action) { case M_PROPERTY_SET: { MP_WARN(mpctx, "Setting the display-fps property is deprecated; set " "the override-display-fps property instead.\n"); struct mpv_node val = { .format = MPV_FORMAT_DOUBLE, .u.double_ = *(double *)arg, }; return m_config_set_option_node(mpctx->mconfig, bstr0("override-display-fps"), &val, 0) >= 0 ? M_PROPERTY_OK : M_PROPERTY_ERROR; } case M_PROPERTY_GET: if (fps <= 0) return M_PROPERTY_UNAVAILABLE; return m_property_double_ro(action, arg, fps); case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_DOUBLE}; return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_estimated_display_fps(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct vo *vo = mpctx->video_out; if (!vo) return M_PROPERTY_UNAVAILABLE; double interval = vo_get_estimated_vsync_interval(vo); if (interval <= 0) return M_PROPERTY_UNAVAILABLE; return m_property_double_ro(action, arg, 1.0 / interval);}
static int mp_property_vsync_jitter(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct vo *vo = mpctx->video_out; if (!vo) return M_PROPERTY_UNAVAILABLE; double stddev = vo_get_estimated_vsync_jitter(vo); if (stddev < 0) return M_PROPERTY_UNAVAILABLE; return m_property_double_ro(action, arg, stddev);}
static int mp_property_hidpi_scale(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx; struct vo *vo = mpctx->video_out; if (!vo) return M_PROPERTY_UNAVAILABLE; if (!cmd->cached_window_scale) { double scale = 0; if (vo_control(vo, VOCTRL_GET_HIDPI_SCALE, &scale) < 1 || !scale) scale = -1; cmd->cached_window_scale = scale; } if (cmd->cached_window_scale < 0) return M_PROPERTY_UNAVAILABLE; return m_property_double_ro(action, arg, cmd->cached_window_scale);}
static int mp_property_display_names(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct vo *vo = mpctx->video_out; if (!vo) return M_PROPERTY_UNAVAILABLE;
switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING_LIST}; return M_PROPERTY_OK; case M_PROPERTY_GET: { char** display_names; if (vo_control(vo, VOCTRL_GET_DISPLAY_NAMES, &display_names) < 1) return M_PROPERTY_UNAVAILABLE;
*(char ***)arg = display_names; return M_PROPERTY_OK; } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_vo_configured(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; return m_property_flag_ro(action, arg, mpctx->video_out && mpctx->video_out->config_ok);}
static void get_frame_perf(struct mpv_node *node, struct mp_frame_perf *perf){ for (int i = 0; i < perf->count; i++) { struct mp_pass_perf *data = &perf->perf[i]; struct mpv_node *pass = node_array_add(node, MPV_FORMAT_NODE_MAP);
node_map_add_string(pass, "desc", perf->desc[i]); node_map_add(pass, "last", MPV_FORMAT_INT64)->u.int64 = data->last; node_map_add(pass, "avg", MPV_FORMAT_INT64)->u.int64 = data->avg; node_map_add(pass, "peak", MPV_FORMAT_INT64)->u.int64 = data->peak; node_map_add(pass, "count", MPV_FORMAT_INT64)->u.int64 = data->count; struct mpv_node *samples = node_map_add(pass, "samples", MPV_FORMAT_NODE_ARRAY); for (int n = 0; n < data->count; n++) node_array_add(samples, MPV_FORMAT_INT64)->u.int64 = data->samples[n]; }}
static char *asprint_perf(char *res, struct mp_frame_perf *perf){ for (int i = 0; i < perf->count; i++) { struct mp_pass_perf *pass = &perf->perf[i]; res = talloc_asprintf_append(res, "- %s: last %dus avg %dus peak %dus\n", perf->desc[i], (int)pass->last/1000, (int)pass->avg/1000, (int)pass->peak/1000); }
return res;}
static int mp_property_vo_passes(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->video_out) return M_PROPERTY_UNAVAILABLE;
// Return the type right away if requested, to avoid having to // go through a completely unnecessary VOCTRL if (action == M_PROPERTY_GET_TYPE) { *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE}; return M_PROPERTY_OK; }
int ret = M_PROPERTY_UNAVAILABLE; struct voctrl_performance_data *data = talloc_ptrtype(NULL, data); if (vo_control(mpctx->video_out, VOCTRL_PERFORMANCE_DATA, data) <= 0) goto out;
switch (action) { case M_PROPERTY_PRINT: { char *res = NULL; res = talloc_asprintf_append(res, "fresh:\n"); res = asprint_perf(res, &data->fresh); res = talloc_asprintf_append(res, "\nredraw:\n"); res = asprint_perf(res, &data->redraw); *(char **)arg = res; ret = M_PROPERTY_OK; goto out; }
case M_PROPERTY_GET: { struct mpv_node node; node_init(&node, MPV_FORMAT_NODE_MAP, NULL); struct mpv_node *fresh = node_map_add(&node, "fresh", MPV_FORMAT_NODE_ARRAY); struct mpv_node *redraw = node_map_add(&node, "redraw", MPV_FORMAT_NODE_ARRAY); get_frame_perf(fresh, &data->fresh); get_frame_perf(redraw, &data->redraw); *(struct mpv_node *)arg = node; ret = M_PROPERTY_OK; goto out; } }
ret = M_PROPERTY_NOT_IMPLEMENTED;
out: talloc_free(data); return ret;}
static int mp_property_vo(void *ctx, struct m_property *p, int action, void *arg){ MPContext *mpctx = ctx; return m_property_strdup_ro(action, arg, mpctx->video_out ? mpctx->video_out->driver->name : NULL);}
static int mp_property_osd_dim(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
if (!mpctx->video_out || !mpctx->video_out->config_ok) vo_res = (struct mp_osd_res){0};
double aspect = 1.0 * vo_res.w / MPMAX(vo_res.h, 1) / (vo_res.display_par ? vo_res.display_par : 1);
struct m_sub_property props[] = { {"w", SUB_PROP_DOUBLE(vo_res.w)}, {"h", SUB_PROP_DOUBLE(vo_res.h)}, {"par", SUB_PROP_DOUBLE(vo_res.display_par)}, {"aspect", SUB_PROP_DOUBLE(aspect)}, {"mt", SUB_PROP_DOUBLE(vo_res.mt)}, {"mb", SUB_PROP_DOUBLE(vo_res.mb)}, {"ml", SUB_PROP_DOUBLE(vo_res.ml)}, {"mr", SUB_PROP_DOUBLE(vo_res.mr)}, {0} };
return m_property_read_sub(props, action, arg);}
static int mp_property_osd_sym(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; char temp[20]; get_current_osd_sym(mpctx, temp, sizeof(temp)); return m_property_strdup_ro(action, arg, temp);}
static int mp_property_osd_ass(void *ctx, struct m_property *prop, int action, void *arg){ struct m_sub_property props[] = { {"0", SUB_PROP_STR(OSD_ASS_0)}, {"1", SUB_PROP_STR(OSD_ASS_1)}, {0} }; return m_property_read_sub(props, action, arg);}
/// Video fps (RO)static int mp_property_fps(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; float fps = mpctx->vo_chain ? mpctx->vo_chain->filter->container_fps : 0; if (fps < 0.1 || !isfinite(fps)) return M_PROPERTY_UNAVAILABLE;; return m_property_float_ro(action, arg, fps);}
static int mp_property_vf_fps(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (!mpctx->vo_chain) return M_PROPERTY_UNAVAILABLE; double avg = calc_average_frame_duration(mpctx); if (avg <= 0) return M_PROPERTY_UNAVAILABLE; return m_property_double_ro(action, arg, 1.0 / avg);}
/// Video aspect (RW) (deprecated)// FIXME: please delete this mess as soon as the deprecation period is overstatic int mp_property_aspect(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct m_config_option *opt; opt = m_config_get_co_raw(mpctx->mconfig, bstr0("video-aspect-override"));
struct command_ctx *cmd = mpctx->command_ctx; for (int n = 0; n < cmd->num_warned_deprecated; n++) { if (strcmp(cmd->warned_deprecated[n], prop->name) == 0) goto skip_warn; }
MP_WARN(mpctx, "Warning: property 'video-aspect' is deprecated, refer to " "'video-params/aspect' and 'video-aspect-override'.\n"); MP_TARRAY_APPEND(cmd, cmd->warned_deprecated, cmd->num_warned_deprecated, (char *)prop->name);
skip_warn: ;
float aspect = mpctx->opts->movie_aspect; if (mpctx->vo_chain && aspect <= 0) { struct mp_image_params *params = &mpctx->vo_chain->filter->input_params; if (params && params->p_w > 0 && params->p_h > 0) { int d_w, d_h; mp_image_params_get_dsize(params, &d_w, &d_h); aspect = (float)d_w / d_h; } } struct track *track = mpctx->current_track[0][STREAM_VIDEO]; if (track && track->stream && aspect <= 0) { struct mp_codec_params *c = track->stream->codec; if (c->disp_w && c->disp_h) aspect = (float)c->disp_w / c->disp_h; }
switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = *(opt->opt); return M_PROPERTY_OK; case M_PROPERTY_PRINT: { if (mpctx->opts->movie_aspect < 0) { *(char **)arg = talloc_asprintf(NULL, "%.3f (original)", aspect); return M_PROPERTY_OK; } break; } case M_PROPERTY_GET: { *(float *)arg = aspect; return M_PROPERTY_OK; } case M_PROPERTY_SET: if (m_config_set_option_raw(mpctx->mconfig, opt, arg, 0) < 0) return M_PROPERTY_ERROR; return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
static bool floats_equal(float x, float y) { float TOLERANCE = 0.001; float difference = fabsf(x - y); return difference <= TOLERANCE;}
static int mp_property_video_aspect_override(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (action == M_PROPERTY_PRINT) { float aspect_ratio; mp_property_generic_option(mpctx, prop, M_PROPERTY_GET, &aspect_ratio);
if (floats_equal(aspect_ratio, 2.35F / 1.0F)) *(char **)arg = talloc_asprintf(NULL, "2.35:1"); else if (floats_equal(aspect_ratio, 16.0F / 9.0F)) *(char **)arg = talloc_asprintf(NULL, "16:9"); else if (floats_equal(aspect_ratio, 16.0F / 10.0F)) *(char **)arg = talloc_asprintf(NULL, "16:10"); else if (floats_equal(aspect_ratio, 4.0F / 3.0F)) *(char **)arg = talloc_asprintf(NULL, "4:3"); else if (floats_equal(aspect_ratio, -1.0F)) *(char **)arg = talloc_asprintf(NULL, "Original"); else *(char **)arg = talloc_asprintf(NULL, "%.3f", aspect_ratio);
return M_PROPERTY_OK; } return mp_property_generic_option(mpctx, prop, action, arg);}
/// Subtitle delay (RW)static int mp_property_sub_delay(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct MPOpts *opts = mpctx->opts; switch (action) { case M_PROPERTY_PRINT: *(char **)arg = format_delay(opts->subs_rend->sub_delay); return M_PROPERTY_OK; } return mp_property_generic_option(mpctx, prop, action, arg);}
/// Subtitle speed (RW)static int mp_property_sub_speed(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct MPOpts *opts = mpctx->opts; if (action == M_PROPERTY_PRINT) { *(char **)arg = talloc_asprintf(NULL, "%4.1f%%", 100 * opts->subs_rend->sub_speed); return M_PROPERTY_OK; } return mp_property_generic_option(mpctx, prop, action, arg);}
static int mp_property_sub_pos(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct MPOpts *opts = mpctx->opts; if (action == M_PROPERTY_PRINT) { *(char **)arg = talloc_asprintf(NULL, "%d/100", opts->subs_rend->sub_pos); return M_PROPERTY_OK; } return mp_property_generic_option(mpctx, prop, action, arg);}
static int mp_property_sub_text(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct track *track = mpctx->current_track[0][STREAM_SUB]; struct dec_sub *sub = track ? track->d_sub : NULL; double pts = mpctx->playback_pts; if (!sub || pts == MP_NOPTS_VALUE) return M_PROPERTY_UNAVAILABLE;
char *text = sub_get_text(sub, pts); if (!text) text = "";
return m_property_strdup_ro(action, arg, text);}
static struct sd_times get_times(void *ctx, struct m_property *prop, int action, void *arg){ struct sd_times res = { .start = MP_NOPTS_VALUE, .end = MP_NOPTS_VALUE }; MPContext *mpctx = ctx; struct track *track = mpctx->current_track[0][STREAM_SUB]; struct dec_sub *sub = track ? track->d_sub : NULL; double pts = mpctx->playback_pts; if (!sub || pts == MP_NOPTS_VALUE) return res; return sub_get_times(sub, pts);}
static int mp_property_sub_start(void *ctx, struct m_property *prop, int action, void *arg){ double start = get_times(ctx, prop, action, arg).start; if (start == MP_NOPTS_VALUE) return M_PROPERTY_UNAVAILABLE; return m_property_double_ro(action, arg, start);}
static int mp_property_sub_end(void *ctx, struct m_property *prop, int action, void *arg){ double end = get_times(ctx, prop, action, arg).end; if (end == MP_NOPTS_VALUE) return M_PROPERTY_UNAVAILABLE; return m_property_double_ro(action, arg, end);}
static int mp_property_playlist_pos_x(void *ctx, struct m_property *prop, int action, void *arg, int base){ MPContext *mpctx = ctx; struct playlist *pl = mpctx->playlist; if (!pl->num_entries) return M_PROPERTY_UNAVAILABLE;
switch (action) { case M_PROPERTY_GET: { int pos = playlist_entry_to_index(pl, pl->current); if (pos < 0) return M_PROPERTY_UNAVAILABLE; *(int *)arg = pos + base; return M_PROPERTY_OK; } case M_PROPERTY_SET: { int pos = *(int *)arg - base; struct playlist_entry *e = playlist_entry_from_index(pl, pos); if (!e) return M_PROPERTY_ERROR; mp_set_playlist_entry(mpctx, e); return M_PROPERTY_OK; } case M_PROPERTY_GET_TYPE: { struct m_option opt = { .type = CONF_TYPE_INT, .flags = CONF_RANGE, .min = base, .max = playlist_entry_count(pl) - 1 + base, }; *(struct m_option *)arg = opt; return M_PROPERTY_OK; } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_playlist_pos(void *ctx, struct m_property *prop, int action, void *arg){ return mp_property_playlist_pos_x(ctx, prop, action, arg, 0);}
static int mp_property_playlist_pos_1(void *ctx, struct m_property *prop, int action, void *arg){ return mp_property_playlist_pos_x(ctx, prop, action, arg, 1);}
static int get_playlist_entry(int item, int action, void *arg, void *ctx){ struct MPContext *mpctx = ctx;
struct playlist_entry *e = playlist_entry_from_index(mpctx->playlist, item); if (!e) return M_PROPERTY_ERROR;
bool current = mpctx->playlist->current == e; bool playing = mpctx->playing == e; struct m_sub_property props[] = { {"filename", SUB_PROP_STR(e->filename)}, {"current", SUB_PROP_FLAG(1), .unavailable = !current}, {"playing", SUB_PROP_FLAG(1), .unavailable = !playing}, {"title", SUB_PROP_STR(e->title), .unavailable = !e->title}, {0} };
return m_property_read_sub(props, action, arg);}
static int mp_property_playlist(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; if (action == M_PROPERTY_PRINT) { struct playlist *pl = mpctx->playlist; char *res = talloc_strdup(NULL, "");
for (int n = 0; n < pl->num_entries; n++) { struct playlist_entry *e = pl->entries[n]; char *p = e->title; if (!p) { p = e->filename; if (!mp_is_url(bstr0(p))) { char *s = mp_basename(e->filename); if (s[0]) p = s; } } const char *m = pl->current == e ? list_current : list_normal; res = talloc_asprintf_append(res, "%s%s\n", m, p); }
*(char **)arg = cut_osd_list(mpctx, res, playlist_entry_to_index(pl, pl->current)); return M_PROPERTY_OK; }
return m_property_read_list(action, arg, playlist_entry_count(mpctx->playlist), get_playlist_entry, mpctx);}
static char *print_obj_osd_list(struct m_obj_settings *list){ char *res = NULL; for (int n = 0; list && list[n].name; n++) { res = talloc_asprintf_append(res, "%s [", list[n].name); for (int i = 0; list[n].attribs && list[n].attribs[i]; i += 2) { res = talloc_asprintf_append(res, "%s%s=%s", i > 0 ? " " : "", list[n].attribs[i], list[n].attribs[i + 1]); } res = talloc_asprintf_append(res, "]"); if (!list[n].enabled) res = talloc_strdup_append(res, " (disabled)"); res = talloc_strdup_append(res, "\n"); } if (!res) res = talloc_strdup(NULL, "(empty)"); return res;}
static int property_filter(struct m_property *prop, int action, void *arg, MPContext *mpctx, enum stream_type mt){ if (action == M_PROPERTY_PRINT) { struct m_config_option *opt = m_config_get_co(mpctx->mconfig, bstr0(prop->name)); *(char **)arg = print_obj_osd_list(*(struct m_obj_settings **)opt->data); return M_PROPERTY_OK; } return mp_property_generic_option(mpctx, prop, action, arg);}
static int mp_property_vf(void *ctx, struct m_property *prop, int action, void *arg){ return property_filter(prop, action, arg, ctx, STREAM_VIDEO);}
static int mp_property_af(void *ctx, struct m_property *prop, int action, void *arg){ return property_filter(prop, action, arg, ctx, STREAM_AUDIO);}
static int mp_property_ab_loop(void *ctx, struct m_property *prop, int action, void *arg){ struct MPContext *mpctx = ctx; if (action == M_PROPERTY_KEY_ACTION) { double val; if (mp_property_generic_option(mpctx, prop, M_PROPERTY_GET, &val) < 1) return M_PROPERTY_ERROR;
return property_time(action, arg, val); } return mp_property_generic_option(mpctx, prop, action, arg);}
static int mp_property_packet_bitrate(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; int type = (uintptr_t)prop->priv & ~0x100; bool old = (uintptr_t)prop->priv & 0x100;
struct demuxer *demuxer = NULL; if (mpctx->current_track[0][type]) demuxer = mpctx->current_track[0][type]->demuxer; if (!demuxer) demuxer = mpctx->demuxer; if (!demuxer) return M_PROPERTY_UNAVAILABLE;
double r[STREAM_TYPE_COUNT]; demux_get_bitrate_stats(demuxer, r); if (r[type] < 0) return M_PROPERTY_UNAVAILABLE;
// r[type] is in bytes/second -> bits double rate = r[type] * 8;
// Same story, but used kilobits for some reason. if (old) return m_property_int64_ro(action, arg, llrint(rate / 1000.0));
if (action == M_PROPERTY_PRINT) { rate /= 1000; if (rate < 1000) { *(char **)arg = talloc_asprintf(NULL, "%d kbps", (int)rate); } else { *(char **)arg = talloc_asprintf(NULL, "%.3f mbps", rate / 1000.0); } return M_PROPERTY_OK; } return m_property_int64_ro(action, arg, llrint(rate));}
static int mp_property_cwd(void *ctx, struct m_property *prop, int action, void *arg){ switch (action) { case M_PROPERTY_GET: { char *cwd = mp_getcwd(NULL); if (!cwd) return M_PROPERTY_ERROR; *(char **)arg = cwd; return M_PROPERTY_OK; } case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING}; return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_protocols(void *ctx, struct m_property *prop, int action, void *arg){ switch (action) { case M_PROPERTY_GET: *(char ***)arg = stream_get_proto_list(); return M_PROPERTY_OK; case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING_LIST}; return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
static int get_decoder_entry(int item, int action, void *arg, void *ctx){ struct mp_decoder_list *codecs = ctx; struct mp_decoder_entry *c = &codecs->entries[item];
struct m_sub_property props[] = { {"codec", SUB_PROP_STR(c->codec)}, {"driver" , SUB_PROP_STR(c->decoder)}, {"description", SUB_PROP_STR(c->desc)}, {0} };
return m_property_read_sub(props, action, arg);}
static int mp_property_decoders(void *ctx, struct m_property *prop, int action, void *arg){ struct mp_decoder_list *codecs = talloc_zero(NULL, struct mp_decoder_list); struct mp_decoder_list *v = talloc_steal(codecs, video_decoder_list()); struct mp_decoder_list *a = talloc_steal(codecs, audio_decoder_list()); mp_append_decoders(codecs, v); mp_append_decoders(codecs, a); int r = m_property_read_list(action, arg, codecs->num_entries, get_decoder_entry, codecs); talloc_free(codecs); return r;}
static int mp_property_encoders(void *ctx, struct m_property *prop, int action, void *arg){ struct mp_decoder_list *codecs = talloc_zero(NULL, struct mp_decoder_list); mp_add_lavc_encoders(codecs); int r = m_property_read_list(action, arg, codecs->num_entries, get_decoder_entry, codecs); talloc_free(codecs); return r;}
static int mp_property_lavf_demuxers(void *ctx, struct m_property *prop, int action, void *arg){ switch (action) { case M_PROPERTY_GET: *(char ***)arg = mp_get_lavf_demuxers(); return M_PROPERTY_OK; case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING_LIST}; return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_version(void *ctx, struct m_property *prop, int action, void *arg){ return m_property_strdup_ro(action, arg, mpv_version);}
static int mp_property_configuration(void *ctx, struct m_property *prop, int action, void *arg){ return m_property_strdup_ro(action, arg, CONFIGURATION);}
static int mp_property_ffmpeg(void *ctx, struct m_property *prop, int action, void *arg){ return m_property_strdup_ro(action, arg, av_version_info());}
static int mp_property_alias(void *ctx, struct m_property *prop, int action, void *arg){ const char *real_property = prop->priv; return mp_property_do(real_property, action, arg, ctx);}
static int mp_property_deprecated_alias(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx; const char *real_property = prop->priv; for (int n = 0; n < cmd->num_warned_deprecated; n++) { if (strcmp(cmd->warned_deprecated[n], prop->name) == 0) goto done; } MP_WARN(mpctx, "Warning: property '%s' was replaced with '%s' and " "might be removed in the future.\n", prop->name, real_property); MP_TARRAY_APPEND(cmd, cmd->warned_deprecated, cmd->num_warned_deprecated, (char *)prop->name);
done: return mp_property_do(real_property, action, arg, ctx);}
static int access_options(struct m_property_action_arg *ka, bool local, MPContext *mpctx){ struct m_config_option *opt = m_config_get_co(mpctx->mconfig, bstr0(ka->key)); if (!opt) return M_PROPERTY_UNKNOWN; if (!opt->data) return M_PROPERTY_UNAVAILABLE;
switch (ka->action) { case M_PROPERTY_GET: m_option_copy(opt->opt, ka->arg, opt->data); return M_PROPERTY_OK; case M_PROPERTY_SET: { if (local && !mpctx->playing) return M_PROPERTY_ERROR; int flags = local ? M_SETOPT_BACKUP : 0; int r = m_config_set_option_raw(mpctx->mconfig, opt, ka->arg, flags); mp_wakeup_core(mpctx); return r < 0 ? M_PROPERTY_ERROR : M_PROPERTY_OK; } case M_PROPERTY_GET_TYPE: *(struct m_option *)ka->arg = *opt->opt; return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
static int access_option_list(int action, void *arg, bool local, MPContext *mpctx){ switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING_LIST}; return M_PROPERTY_OK; case M_PROPERTY_GET: *(char ***)arg = m_config_list_options(NULL, mpctx->mconfig); return M_PROPERTY_OK; case M_PROPERTY_KEY_ACTION: return access_options(arg, local, mpctx); } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_options(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; return access_option_list(action, arg, false, mpctx);}
static int mp_property_local_options(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; return access_option_list(action, arg, true, mpctx);}
static int mp_property_option_info(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; switch (action) { case M_PROPERTY_KEY_ACTION: { struct m_property_action_arg *ka = arg; bstr key; char *rem; m_property_split_path(ka->key, &key, &rem); struct m_config_option *co = m_config_get_co(mpctx->mconfig, key); if (!co) return M_PROPERTY_UNKNOWN; const struct m_option *opt = co->opt;
union m_option_value def = {0}; const void *def_ptr = m_config_get_co_default(mpctx->mconfig, co); if (def_ptr && opt->type->size > 0) memcpy(&def, def_ptr, opt->type->size);
bool has_minmax = opt->type == &m_option_type_int || opt->type == &m_option_type_int64 || opt->type == &m_option_type_float || opt->type == &m_option_type_double; char **choices = NULL;
if (opt->type == &m_option_type_choice) { has_minmax = true; struct m_opt_choice_alternatives *alt = opt->priv; int num = 0; for ( ; alt->name; alt++) MP_TARRAY_APPEND(NULL, choices, num, alt->name); MP_TARRAY_APPEND(NULL, choices, num, NULL); } if (opt->type == &m_option_type_obj_settings_list) { struct m_obj_list *objs = opt->priv; int num = 0; for (int n = 0; ; n++) { struct m_obj_desc desc = {0}; if (!objs->get_desc(&desc, n)) break; MP_TARRAY_APPEND(NULL, choices, num, (char *)desc.name); } MP_TARRAY_APPEND(NULL, choices, num, NULL); }
struct m_sub_property props[] = { {"name", SUB_PROP_STR(co->name)}, {"type", SUB_PROP_STR(opt->type->name)}, {"set-from-commandline", SUB_PROP_FLAG(co->is_set_from_cmdline)}, {"set-locally", SUB_PROP_FLAG(co->is_set_locally)}, {"default-value", *opt, def}, {"min", SUB_PROP_DOUBLE(opt->min), .unavailable = !(has_minmax && (opt->flags & M_OPT_MIN))}, {"max", SUB_PROP_DOUBLE(opt->max), .unavailable = !(has_minmax && (opt->flags & M_OPT_MAX))}, {"choices", .type = {.type = CONF_TYPE_STRING_LIST}, .value = {.string_list = choices}, .unavailable = !choices}, {0} };
struct m_property_action_arg next_ka = *ka; next_ka.key = rem; int r = m_property_read_sub(props, M_PROPERTY_KEY_ACTION, &next_ka); talloc_free(choices); return r; } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_list(void *ctx, struct m_property *prop, int action, void *arg){ struct MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx;
switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_STRING_LIST}; return M_PROPERTY_OK; case M_PROPERTY_GET: { char **list = NULL; int num = 0; for (int n = 0; cmd->properties[n].name; n++) { MP_TARRAY_APPEND(NULL, list, num, talloc_strdup(NULL, cmd->properties[n].name)); } MP_TARRAY_APPEND(NULL, list, num, NULL); *(char ***)arg = list; return M_PROPERTY_OK; } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_profile_list(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE}; return M_PROPERTY_OK; case M_PROPERTY_GET: { *(struct mpv_node *)arg = m_config_get_profiles(mpctx->mconfig); return M_PROPERTY_OK; } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_commands(void *ctx, struct m_property *prop, int action, void *arg){ switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE}; return M_PROPERTY_OK; case M_PROPERTY_GET: { struct mpv_node *root = arg; node_init(root, MPV_FORMAT_NODE_ARRAY, NULL);
for (int n = 0; mp_cmds[n].name; n++) { const struct mp_cmd_def *cmd = &mp_cmds[n]; struct mpv_node *entry = node_array_add(root, MPV_FORMAT_NODE_MAP);
node_map_add_string(entry, "name", cmd->name);
struct mpv_node *args = node_map_add(entry, "args", MPV_FORMAT_NODE_ARRAY); for (int i = 0; i < MP_CMD_DEF_MAX_ARGS; i++) { const struct m_option *a = &cmd->args[i]; if (!a->type) break; struct mpv_node *ae = node_array_add(args, MPV_FORMAT_NODE_MAP); node_map_add_string(ae, "name", a->name); node_map_add_string(ae, "type", a->type->name); node_map_add_flag(ae, "optional", a->flags & MP_CMD_OPT_ARG); }
node_map_add_flag(entry, "vararg", cmd->vararg); }
return M_PROPERTY_OK; } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_bindings(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_NODE}; return M_PROPERTY_OK; case M_PROPERTY_GET: { *(struct mpv_node *)arg = mp_input_get_bindings(mpctx->input); return M_PROPERTY_OK; } } return M_PROPERTY_NOT_IMPLEMENTED;}
static int mp_property_script_props(void *ctx, struct m_property *prop, int action, void *arg){ MPContext *mpctx = ctx; struct command_ctx *cmd = mpctx->command_ctx; switch (action) { case M_PROPERTY_GET_TYPE: *(struct m_option *)arg = script_props_type; return M_PROPERTY_OK; case M_PROPERTY_GET: m_option_copy(&script_props_type, arg, &cmd->script_props); return M_PROPERTY_OK; case M_PROPERTY_SET: m_option_copy(&script_props_type, &cmd->script_props, arg); mp_notify_property(mpctx, prop->name); return M_PROPERTY_OK; } return M_PROPERTY_NOT_IMPLEMENTED;}
// Redirect a property name to another#define M_PROPERTY_ALIAS(name, real_property) \ {(name), mp_property_alias, .priv = (real_property)}
#define M_PROPERTY_DEPRECATED_ALIAS(name, real_property) \ {(name), mp_property_deprecated_alias, .priv = (real_property)}
// Base list of properties. This does not include option-mapped properties.static const struct m_property mp_properties_base[] = { // General {"speed", mp_property_playback_speed}, {"audio-speed-correction", mp_property_av_speed_correction, .priv = "a"}, {"video-speed-correction", mp_property_av_speed_correction, .priv = "v"}, {"display-sync-active", mp_property_display_sync_active}, {"filename", mp_property_filename}, {"stream-open-filename", mp_property_stream_open_filename}, {"file-size", mp_property_file_size}, {"path", mp_property_path}, {"media-title", mp_property_media_title}, {"stream-path", mp_property_stream_path}, {"current-demuxer", mp_property_demuxer}, {"file-format", mp_property_file_format}, {"stream-pos", mp_property_stream_pos}, {"stream-end", mp_property_stream_end}, {"duration", mp_property_duration}, {"avsync", mp_property_avsync}, {"total-avsync-change", mp_property_total_avsync_change}, {"mistimed-frame-count", mp_property_mistimed_frame_count}, {"vsync-ratio", mp_property_vsync_ratio}, {"decoder-frame-drop-count", mp_property_frame_drop_dec}, {"frame-drop-count", mp_property_frame_drop_vo}, {"vo-delayed-frame-count", mp_property_vo_delayed_frame_count}, {"percent-pos", mp_property_percent_pos}, {"time-start", mp_property_time_start}, {"time-pos", mp_property_time_pos}, {"time-remaining", mp_property_remaining}, {"audio-pts", mp_property_audio_pts}, {"playtime-remaining", mp_property_playtime_remaining}, {"playback-time", mp_property_playback_time}, {"chapter", mp_property_chapter}, {"edition", mp_property_edition}, {"current-edition", mp_property_current_edition}, {"chapters", mp_property_chapters}, {"editions", mp_property_editions}, {"metadata", mp_property_metadata}, {"filtered-metadata", mp_property_filtered_metadata}, {"chapter-metadata", mp_property_chapter_metadata}, {"vf-metadata", mp_property_filter_metadata, .priv = "vf"}, {"af-metadata", mp_property_filter_metadata, .priv = "af"}, {"core-idle", mp_property_core_idle}, {"eof-reached", mp_property_eof_reached}, {"seeking", mp_property_seeking}, {"playback-abort", mp_property_playback_abort}, {"cache-speed", mp_property_cache_speed}, {"demuxer-cache-duration", mp_property_demuxer_cache_duration}, {"demuxer-cache-time", mp_property_demuxer_cache_time}, {"demuxer-cache-idle", mp_property_demuxer_cache_idle}, {"demuxer-start-time", mp_property_demuxer_start_time}, {"demuxer-cache-state", mp_property_demuxer_cache_state}, {"cache-buffering-state", mp_property_cache_buffering}, {"paused-for-cache", mp_property_paused_for_cache}, {"demuxer-via-network", mp_property_demuxer_is_network}, {"clock", mp_property_clock}, {"seekable", mp_property_seekable}, {"partially-seekable", mp_property_partially_seekable}, {"idle-active", mp_property_idle},
{"chapter-list", mp_property_list_chapters}, {"track-list", property_list_tracks}, {"edition-list", property_list_editions},
{"playlist", mp_property_playlist}, {"playlist-pos", mp_property_playlist_pos}, {"playlist-pos-1", mp_property_playlist_pos_1}, M_PROPERTY_ALIAS("playlist-count", "playlist/count"),
// Audio {"mixer-active", mp_property_mixer_active}, {"volume", mp_property_volume}, {"ao-volume", mp_property_ao_volume}, {"ao-mute", mp_property_ao_mute}, {"audio-delay", mp_property_audio_delay}, {"audio-codec-name", mp_property_audio_codec_name}, {"audio-codec", mp_property_audio_codec}, {"audio-params", mp_property_audio_params}, {"audio-out-params", mp_property_audio_out_params}, {"aid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_AUDIO}}, {"audio-device", mp_property_audio_device}, {"audio-device-list", mp_property_audio_devices}, {"current-ao", mp_property_ao},
// Video {"video-out-params", mp_property_vo_imgparams}, {"video-dec-params", mp_property_dec_imgparams}, {"video-params", mp_property_vd_imgparams}, {"video-format", mp_property_video_format}, {"video-frame-info", mp_property_video_frame_info}, {"video-codec", mp_property_video_codec}, M_PROPERTY_ALIAS("dwidth", "video-out-params/dw"), M_PROPERTY_ALIAS("dheight", "video-out-params/dh"), M_PROPERTY_ALIAS("width", "video-params/w"), M_PROPERTY_ALIAS("height", "video-params/h"), {"current-window-scale", mp_property_current_window_scale}, {"vo-configured", mp_property_vo_configured}, {"vo-passes", mp_property_vo_passes}, {"current-vo", mp_property_vo}, {"container-fps", mp_property_fps}, {"estimated-vf-fps", mp_property_vf_fps}, {"video-aspect", mp_property_aspect}, {"video-aspect-override", mp_property_video_aspect_override}, {"vid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_VIDEO}}, {"hwdec-current", mp_property_hwdec_current}, {"hwdec-interop", mp_property_hwdec_interop},
{"estimated-frame-count", mp_property_frame_count}, {"estimated-frame-number", mp_property_frame_number},
{"osd-dimensions", mp_property_osd_dim}, M_PROPERTY_ALIAS("osd-width", "osd-dimensions/w"), M_PROPERTY_ALIAS("osd-height", "osd-dimensions/h"), M_PROPERTY_ALIAS("osd-par", "osd-dimensions/par"),
{"osd-sym-cc", mp_property_osd_sym}, {"osd-ass-cc", mp_property_osd_ass},
// Subs {"sid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_SUB}}, {"secondary-sid", property_switch_track, .priv = (void *)(const int[]){1, STREAM_SUB}}, {"sub-delay", mp_property_sub_delay}, {"sub-speed", mp_property_sub_speed}, {"sub-pos", mp_property_sub_pos}, {"sub-text", mp_property_sub_text}, {"sub-start", mp_property_sub_start}, {"sub-end", mp_property_sub_end},
{"vf", mp_property_vf}, {"af", mp_property_af},
{"ab-loop-a", mp_property_ab_loop}, {"ab-loop-b", mp_property_ab_loop},
#define PROPERTY_BITRATE(name, old, type) \ {name, mp_property_packet_bitrate, (void *)(uintptr_t)((type)|(old?0x100:0))} PROPERTY_BITRATE("packet-video-bitrate", true, STREAM_VIDEO), PROPERTY_BITRATE("packet-audio-bitrate", true, STREAM_AUDIO), PROPERTY_BITRATE("packet-sub-bitrate", true, STREAM_SUB),
PROPERTY_BITRATE("video-bitrate", false, STREAM_VIDEO), PROPERTY_BITRATE("audio-bitrate", false, STREAM_AUDIO), PROPERTY_BITRATE("sub-bitrate", false, STREAM_SUB),
{"display-names", mp_property_display_names}, {"display-fps", mp_property_display_fps}, {"estimated-display-fps", mp_property_estimated_display_fps}, {"vsync-jitter", mp_property_vsync_jitter}, {"display-hidpi-scale", mp_property_hidpi_scale},
{"working-directory", mp_property_cwd},
{"protocol-list", mp_property_protocols}, {"decoder-list", mp_property_decoders}, {"encoder-list", mp_property_encoders}, {"demuxer-lavf-list", mp_property_lavf_demuxers},
{"mpv-version", mp_property_version}, {"mpv-configuration", mp_property_configuration}, {"ffmpeg-version", mp_property_ffmpeg},
{"options", mp_property_options}, {"file-local-options", mp_property_local_options}, {"option-info", mp_property_option_info}, {"property-list", mp_property_list}, {"profile-list", mp_profile_list}, {"command-list", mp_property_commands}, {"input-bindings", mp_property_bindings},
{"shared-script-properties", mp_property_script_props},
M_PROPERTY_ALIAS("video", "vid"), M_PROPERTY_ALIAS("audio", "aid"), M_PROPERTY_ALIAS("sub", "sid"),
// compatibility M_PROPERTY_ALIAS("colormatrix", "video-params/colormatrix"), M_PROPERTY_ALIAS("colormatrix-input-range", "video-params/colorlevels"), M_PROPERTY_ALIAS("colormatrix-primaries", "video-params/primaries"), M_PROPERTY_ALIAS("colormatrix-gamma", "video-params/gamma"),
M_PROPERTY_DEPRECATED_ALIAS("drop-frame-count", "decoder-frame-drop-count"), M_PROPERTY_DEPRECATED_ALIAS("vo-drop-frame-count", "frame-drop-count"),};
// Each entry describes which properties an event (possibly) changes.#define E(x, ...) [x] = (const char*const[]){__VA_ARGS__, NULL}static const char *const *const mp_event_property_change[] = { E(MPV_EVENT_START_FILE, "*"), E(MPV_EVENT_END_FILE, "*"), E(MPV_EVENT_FILE_LOADED, "*"), E(MP_EVENT_CHANGE_ALL, "*"), E(MPV_EVENT_TRACKS_CHANGED, "track-list"), E(MPV_EVENT_IDLE, "*"), E(MPV_EVENT_TICK, "time-pos", "audio-pts", "stream-pos", "avsync", "percent-pos", "time-remaining", "playtime-remaining", "playback-time", "estimated-vf-fps", "drop-frame-count", "vo-drop-frame-count", "total-avsync-change", "audio-speed-correction", "video-speed-correction", "vo-delayed-frame-count", "mistimed-frame-count", "vsync-ratio", "estimated-display-fps", "vsync-jitter", "sub-text", "audio-bitrate", "video-bitrate", "sub-bitrate", "decoder-frame-drop-count", "frame-drop-count", "video-frame-info", "vf-metadata", "af-metadata"), E(MP_EVENT_DURATION_UPDATE, "duration"), E(MPV_EVENT_VIDEO_RECONFIG, "video-out-params", "video-params", "video-format", "video-codec", "video-bitrate", "dwidth", "dheight", "width", "height", "fps", "aspect", "vo-configured", "current-vo", "video-aspect", "video-dec-params", "osd-dimensions", "hwdec", "hwdec-current", "hwdec-interop"), E(MPV_EVENT_AUDIO_RECONFIG, "audio-format", "audio-codec", "audio-bitrate", "samplerate", "channels", "audio", "volume", "mute", "current-ao", "audio-codec-name", "audio-params", "audio-out-params", "volume-max", "mixer-active"), E(MPV_EVENT_SEEK, "seeking", "core-idle", "eof-reached"), E(MPV_EVENT_PLAYBACK_RESTART, "seeking", "core-idle", "eof-reached"), E(MPV_EVENT_METADATA_UPDATE, "metadata", "filtered-metadata", "media-title"), E(MPV_EVENT_CHAPTER_CHANGE, "chapter", "chapter-metadata"), E(MP_EVENT_CACHE_UPDATE, "demuxer-cache-duration", "demuxer-cache-idle", "paused-for-cache", "demuxer-cache-time", "cache-buffering-state", "cache-speed", "demuxer-cache-state"), E(MP_EVENT_WIN_RESIZE, "current-window-scale", "osd-width", "osd-height", "osd-par", "osd-dimensions"), E(MP_EVENT_WIN_STATE, "display-names", "display-fps"), E(MP_EVENT_WIN_STATE2, "display-hidpi-scale"), E(MP_EVENT_CHANGE_PLAYLIST, "playlist", "playlist-pos", "playlist-pos-1", "playlist-count", "playlist/count"), E(MP_EVENT_CORE_IDLE, "core-idle", "eof-reached"),};#undef E
// If there is no prefix, return length+1 (avoids matching full name as prefix).static int prefix_len(const char *p){ const char *end = strchr(p, '/'); return end ? end - p : strlen(p) + 1;}
static bool match_property(const char *a, const char *b){ if (strcmp(a, "*") == 0) return true; // Give options and properties the same ID each, so change notifications // work both way. if (strncmp(a, "options/", 8) == 0) a += 8; if (strncmp(b, "options/", 8) == 0) b += 8; int len_a = prefix_len(a); int len_b = prefix_len(b); return strncmp(a, b, MPMIN(len_a, len_b)) == 0;}
// Return a bitset of events which change the property.uint64_t mp_get_property_event_mask(const char *name){ uint64_t mask = 0; for (int n = 0; n < MP_ARRAY_SIZE(mp_event_property_change); n++) { const char *const *const list = mp_event_property_change[n]; for (int i = 0; list && list[i]; i++) { if (match_property(list[i], name)) mask |= 1ULL << n; } } return mask;}
// Return an ID for the property. It might not be unique, but is good enough// for property change handling. Return -1 if property unknown.int mp_get_property_id(struct MPContext *mpctx, const char *name){ struct command_ctx *ctx = mpctx->command_ctx; for (int n = 0; ctx->properties[n].name; n++) { if (match_property(ctx->properties[n].name, name)) return n; } return -1;}
static bool is_property_set(int action, void *val){ switch (action) { case M_PROPERTY_SET: case M_PROPERTY_SWITCH: case M_PROPERTY_SET_STRING: case M_PROPERTY_SET_NODE: case M_PROPERTY_MULTIPLY: return true; case M_PROPERTY_KEY_ACTION: { struct m_property_action_arg *key = val; return is_property_set(key->action, key->arg); } default: return false; }}
int mp_property_do(const char *name, int action, void *val, struct MPContext *ctx){ struct command_ctx *cmd = ctx->command_ctx; int r = m_property_do(ctx->log, cmd->properties, name, action, val, ctx);
if (mp_msg_test(ctx->log, MSGL_V) && is_property_set(action, val)) { struct m_option ot = {0}; void *data = val; switch (action) { case M_PROPERTY_SET_NODE: ot.type = &m_option_type_node; break; case M_PROPERTY_SET_STRING: ot.type = &m_option_type_string; data = &val; break; } char *t = ot.type ? m_option_print(&ot, data) : NULL; MP_VERBOSE(ctx, "Set property: %s%s%s -> %d\n", name, t ? "=" : "", t ? t : "", r); talloc_free(t); } return r;}
char *mp_property_expand_string(struct MPContext *mpctx, const char *str){ struct command_ctx *ctx = mpctx->command_ctx; return m_properties_expand_string(ctx->properties, str, mpctx);}
// Before expanding properties, parse C-style escapes like "\n"char *mp_property_expand_escaped_string(struct MPContext *mpctx, const char *str){ void *tmp = talloc_new(NULL); bstr strb = bstr0(str); bstr dst = {0}; while (strb.len) { if (!mp_append_escaped_string(tmp, &dst, &strb)) { talloc_free(tmp); return talloc_strdup(NULL, "(broken escape sequences)"); } // pass " through literally if (!bstr_eatstart0(&strb, "\"")) break; bstr_xappend(tmp, &dst, bstr0("\"")); } char *r = mp_property_expand_string(mpctx, dst.start); talloc_free(tmp); return r;}
void property_print_help(struct MPContext *mpctx){ struct command_ctx *ctx = mpctx->command_ctx; m_properties_print_help_list(mpctx->log, ctx->properties);}
/* List of default ways to show a property on OSD. * * If osd_progbar is set, a bar showing the current position between min/max * values of the property is shown. In this case osd_msg is only used for * terminal output if there is no video; it'll be a label shown together with * percentage. */static const struct property_osd_display { // property name const char *name; // name used on OSD const char *osd_name; // progressbar type int osd_progbar; // Needs special ways to display the new value (seeks are delayed) int seek_msg, seek_bar; // Show a marker thing on OSD bar. Ignored if osd_progbar==0. float marker; // Free-form message (if NULL, osd_name or the property name is used) const char *msg;} property_osd_display[] = { // general {"loop-playlist", "Loop"}, {"loop-file", "Loop current file"}, {"chapter", .seek_msg = OSD_SEEK_INFO_CHAPTER_TEXT, .seek_bar = OSD_SEEK_INFO_BAR}, {"hr-seek", "hr-seek"}, {"speed", "Speed"}, {"clock", "Clock"}, // audio {"volume", "Volume", .msg = "Volume: ${?volume:${volume}% ${?mute==yes:(Muted)}}${!volume:${volume}}", .osd_progbar = OSD_VOLUME, .marker = 100}, {"ao-volume", "AO Volume", .msg = "AO Volume: ${?ao-volume:${ao-volume}% ${?ao-mute==yes:(Muted)}}${!ao-volume:${ao-volume}}", .osd_progbar = OSD_VOLUME, .marker = 100}, {"mute", "Mute"}, {"ao-mute", "AO Mute"}, {"audio-delay", "A-V delay"}, {"audio", "Audio"}, // video {"panscan", "Panscan", .osd_progbar = OSD_PANSCAN}, {"taskbar-progress", "Progress in taskbar"}, {"snap-window", "Snap to screen edges"}, {"ontop", "Stay on top"}, {"border", "Border"}, {"framedrop", "Framedrop"}, {"deinterlace", "Deinterlace"}, {"gamma", "Gamma", .osd_progbar = OSD_BRIGHTNESS }, {"brightness", "Brightness", .osd_progbar = OSD_BRIGHTNESS}, {"contrast", "Contrast", .osd_progbar = OSD_CONTRAST}, {"saturation", "Saturation", .osd_progbar = OSD_SATURATION}, {"hue", "Hue", .osd_progbar = OSD_HUE}, {"angle", "Angle"}, // subs {"sub", "Subtitles"}, {"secondary-sid", "Secondary subtitles"}, {"sub-pos", "Sub position"}, {"sub-delay", "Sub delay"}, {"sub-speed", "Sub speed"}, {"sub-visibility", .msg = "Subtitles ${!sub-visibility==yes:hidden}" "${?sub-visibility==yes:visible${?sub==no: (but no subtitles selected)}}"}, {"sub-forced-only", "Forced sub only"}, {"sub-scale", "Sub Scale"}, {"sub-ass-vsfilter-aspect-compat", "Subtitle VSFilter aspect compat"}, {"sub-ass-override", "ASS subtitle style override"}, {"vf", "Video filters", .msg = "Video filters:\n${vf}"}, {"af", "Audio filters", .msg = "Audio filters:\n${af}"}, {"ab-loop-a", "A-B loop start"}, {"ab-loop-b", .msg = "A-B loop: ${ab-loop-a} - ${ab-loop-b}" "${?=ab-loop-count==0: (disabled)}"}, {"audio-device", "Audio device"}, {"hwdec", .msg = "Hardware decoding: ${hwdec-current}"}, {"video-aspect-override", "Aspect ratio override"}, // By default, don't display the following properties on OSD {"pause", NULL}, {"fullscreen", NULL}, {"window-minimized", NULL}, {"window-maximized", NULL}, {0}};
static void show_property_osd(MPContext *mpctx, const char *name, int osd_mode){ struct MPOpts *opts = mpctx->opts; struct property_osd_display disp = {.name = name, .osd_name = name};
if (!osd_mode) return;
// look for the command for (const struct property_osd_display *p = property_osd_display; p->name; p++) { if (!strcmp(p->name, name)) { disp = *p; break; } }
if (osd_mode == MP_ON_OSD_AUTO) { osd_mode = ((disp.msg || disp.osd_name || disp.seek_msg) ? MP_ON_OSD_MSG : 0) | ((disp.osd_progbar || disp.seek_bar) ? MP_ON_OSD_BAR : 0); }
if (!disp.osd_progbar) disp.osd_progbar = ' ';
if (!disp.osd_name) disp.osd_name = name;
if (disp.seek_msg || disp.seek_bar) { mpctx->add_osd_seek_info |= (osd_mode & MP_ON_OSD_MSG ? disp.seek_msg : 0) | (osd_mode & MP_ON_OSD_BAR ? disp.seek_bar : 0); return; }
struct m_option prop = {0}; mp_property_do(name, M_PROPERTY_GET_CONSTRICTED_TYPE, &prop, mpctx); if ((osd_mode & MP_ON_OSD_BAR) && (prop.flags & CONF_RANGE) == CONF_RANGE) { if (prop.type == CONF_TYPE_INT) { int n = prop.min; if (disp.osd_progbar) n = disp.marker; int i; if (mp_property_do(name, M_PROPERTY_GET, &i, mpctx) > 0) set_osd_bar(mpctx, disp.osd_progbar, prop.min, prop.max, n, i); } else if (prop.type == CONF_TYPE_FLOAT) { float n = prop.min; if (disp.osd_progbar) n = disp.marker; float f; if (mp_property_do(name, M_PROPERTY_GET, &f, mpctx) > 0) set_osd_bar(mpctx, disp.osd_progbar, prop.min, prop.max, n, f); } }
if (osd_mode & MP_ON_OSD_MSG) { void *tmp = talloc_new(NULL);
const char *msg = disp.msg; if (!msg) msg = talloc_asprintf(tmp, "%s: ${%s}", disp.osd_name, name);
char *osd_msg = talloc_steal(tmp, mp_property_expand_string(mpctx, msg));
if (osd_msg && osd_msg[0]) set_osd_msg(mpctx, 1, opts->osd_duration, "%s", osd_msg);
talloc_free(tmp); }}
static bool reinit_filters(MPContext *mpctx, enum stream_type mediatype){ switch (mediatype) { case STREAM_VIDEO: return reinit_video_filters(mpctx) >= 0; case STREAM_AUDIO: return reinit_audio_filters(mpctx) >= 0; } return false;}
static const char *const filter_opt[STREAM_TYPE_COUNT] = { [STREAM_VIDEO] = "vf", [STREAM_AUDIO] = "af",};
static int set_filters(struct MPContext *mpctx, enum stream_type mediatype, struct m_obj_settings *new_chain){ bstr option = bstr0(filter_opt[mediatype]); struct m_config_option *co = m_config_get_co(mpctx->mconfig, option); if (!co) return -1;
struct m_obj_settings **list = co->data; struct m_obj_settings *old_settings = *list; *list = NULL; m_option_copy(co->opt, list, &new_chain);
bool success = reinit_filters(mpctx, mediatype);
if (success) { m_option_free(co->opt, &old_settings); m_config_notify_change_opt_ptr(mpctx->mconfig, list); } else { m_option_free(co->opt, list); *list = old_settings; }
return success ? 0 : -1;}
static int edit_filters(struct MPContext *mpctx, struct mp_log *log, enum stream_type mediatype, const char *cmd, const char *arg){ bstr option = bstr0(filter_opt[mediatype]); struct m_config_option *co = m_config_get_co(mpctx->mconfig, option); if (!co) return -1;
// The option parser is used to modify the filter list itself. char optname[20]; snprintf(optname, sizeof(optname), "%.*s-%s", BSTR_P(option), cmd);
struct m_obj_settings *new_chain = NULL; m_option_copy(co->opt, &new_chain, co->data);
int r = m_option_parse(log, co->opt, bstr0(optname), bstr0(arg), &new_chain); if (r >= 0) r = set_filters(mpctx, mediatype, new_chain);
m_option_free(co->opt, &new_chain);
return r >= 0 ? 0 : -1;}
static int edit_filters_osd(struct MPContext *mpctx, enum stream_type mediatype, const char *cmd, const char *arg, bool on_osd){ int r = edit_filters(mpctx, mpctx->log, mediatype, cmd, arg); if (on_osd) { if (r >= 0) { const char *prop = filter_opt[mediatype]; show_property_osd(mpctx, prop, MP_ON_OSD_MSG); } else { set_osd_msg(mpctx, 1, mpctx->opts->osd_duration, "Changing filters failed!"); } } return r;}
static void recreate_overlays(struct MPContext *mpctx){ struct command_ctx *cmd = mpctx->command_ctx; int overlay_next = !cmd->overlay_osd_current; struct sub_bitmaps *new = &cmd->overlay_osd[overlay_next]; new->format = SUBBITMAP_RGBA; new->change_id = 1;
bool valid = false;
new->num_parts = 0; for (int n = 0; n < cmd->num_overlays; n++) { struct overlay *o = &cmd->overlays[n]; if (o->source) { struct mp_image *s = o->source; struct sub_bitmap b = { .bitmap = s->planes[0], .stride = s->stride[0], .w = s->w, .dw = s->w, .h = s->h, .dh = s->h, .x = o->x, .y = o->y, }; MP_TARRAY_APPEND(cmd, new->parts, new->num_parts, b); } }
if (!cmd->overlay_packer) cmd->overlay_packer = talloc_zero(cmd, struct bitmap_packer);
cmd->overlay_packer->padding = 1; // assume bilinear scaling packer_set_size(cmd->overlay_packer, new->num_parts);
for (int n = 0; n < new->num_parts; n++) cmd->overlay_packer->in[n] = (struct pos){new->parts[n].w, new->parts[n].h};
if (packer_pack(cmd->overlay_packer) < 0 || new->num_parts == 0) goto done;
struct pos bb[2]; packer_get_bb(cmd->overlay_packer, bb);
new->packed_w = bb[1].x; new->packed_h = bb[1].y;
if (!new->packed || new->packed->w < new->packed_w || new->packed->h < new->packed_h) { talloc_free(new->packed); new->packed = mp_image_alloc(IMGFMT_BGRA, cmd->overlay_packer->w, cmd->overlay_packer->h); if (!new->packed) goto done; }
// clear padding mp_image_clear(new->packed, 0, 0, new->packed->w, new->packed->h);
for (int n = 0; n < new->num_parts; n++) { struct sub_bitmap *b = &new->parts[n]; struct pos pos = cmd->overlay_packer->result[n];
int stride = new->packed->stride[0]; void *pdata = (uint8_t *)new->packed->planes[0] + pos.y * stride + pos.x * 4; memcpy_pic(pdata, b->bitmap, b->w * 4, b->h, stride, b->stride);
b->bitmap = pdata; b->stride = stride;
b->src_x = pos.x; b->src_y = pos.y; }
valid = true;done: if (!valid) { new->format = SUBBITMAP_EMPTY; new->num_parts = 0; }
osd_set_external2(mpctx->osd, new); mp_wakeup_core(mpctx); cmd->overlay_osd_current = overlay_next;}
// Set overlay with the given ID to the contents as described by "new".static void replace_overlay(struct MPContext *mpctx, int id, struct overlay *new){ struct command_ctx *cmd = mpctx->command_ctx; assert(id >= 0); if (id >= cmd->num_overlays) { MP_TARRAY_GROW(cmd, cmd->overlays, id); while (cmd->num_overlays <= id) cmd->overlays[cmd->num_overlays++] = (struct overlay){0}; }
struct overlay *ptr = &cmd->overlays[id];
talloc_free(ptr->source); *ptr = *new;
recreate_overlays(mpctx);}
static void cmd_overlay_add(void *pcmd){ struct mp_cmd_ctx *cmd = pcmd; struct MPContext *mpctx = cmd->mpctx; int id = cmd->args[0].v.i, x = cmd->args[1].v.i, y = cmd->args[2].v.i; char *file = cmd->args[3].v.s; int offset = cmd->args[4].v.i; char *fmt = cmd->args[5].v.s; int w = cmd->args[6].v.i, h = cmd->args[7].v.i, stride = cmd->args[8].v.i;
if (strcmp(fmt, "bgra") != 0) { MP_ERR(mpctx, "overlay-add: unsupported OSD format '%s'\n", fmt); goto error; } if (id < 0 || id >= 64) { // arbitrary upper limit MP_ERR(mpctx, "overlay-add: invalid id %d\n", id); goto error; } if (w <= 0 || h <= 0 || stride < w * 4 || (stride % 4)) { MP_ERR(mpctx, "overlay-add: inconsistent parameters\n"); goto error; } struct overlay overlay = { .source = mp_image_alloc(IMGFMT_BGRA, w, h), .x = x, .y = y, }; if (!overlay.source) goto error; int fd = -1; bool close_fd = true; void *p = NULL; if (file[0] == '@') { char *end; fd = strtol(&file[1], &end, 10); if (!file[1] || end[0]) fd = -1; close_fd = false; } else if (file[0] == '&') { char *end; unsigned long long addr = strtoull(&file[1], &end, 0); if (!file[1] || end[0]) addr = 0; p = (void *)(uintptr_t)addr; } else { fd = open(file, O_RDONLY | O_BINARY | O_CLOEXEC); } int map_size = 0; if (fd >= 0) { map_size = offset + h * stride; void *m = mmap(NULL, map_size, PROT_READ, MAP_SHARED, fd, 0); if (close_fd) close(fd); if (m && m != MAP_FAILED) p = m; } if (!p) { MP_ERR(mpctx, "overlay-add: could not open or map '%s'\n", file); talloc_free(overlay.source); goto error; } memcpy_pic(overlay.source->planes[0], (char *)p + offset, w * 4, h, overlay.source->stride[0], stride); if (map_size) munmap(p, map_size);
replace_overlay(mpctx, id, &overlay); return;error: cmd->success = false;}
static void cmd_overlay_remove(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; struct command_ctx *cmdctx = mpctx->command_ctx; int id = cmd->args[0].v.i; if (id >= 0 && id < cmdctx->num_overlays) replace_overlay(mpctx, id, &(struct overlay){0});}
static void overlay_uninit(struct MPContext *mpctx){ struct command_ctx *cmd = mpctx->command_ctx; if (!mpctx->osd) return; for (int id = 0; id < cmd->num_overlays; id++) replace_overlay(mpctx, id, &(struct overlay){0}); osd_set_external2(mpctx->osd, NULL); for (int n = 0; n < 2; n++) mp_image_unrefp(&cmd->overlay_osd[n].packed);}
static void cmd_osd_overlay(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
struct osd_external_ass ov = { .owner = cmd->cmd->sender, .id = cmd->args[0].v.i64, .format = cmd->args[1].v.i, .data = cmd->args[2].v.s, .res_x = cmd->args[3].v.i, .res_y = cmd->args[4].v.i, .z = cmd->args[5].v.i, };
osd_set_external(mpctx->osd, &ov); mp_wakeup_core(mpctx);}
static struct track *find_track_with_url(struct MPContext *mpctx, int type, const char *url){ for (int n = 0; n < mpctx->num_tracks; n++) { struct track *track = mpctx->tracks[n]; if (track && track->type == type && track->is_external && strcmp(track->external_filename, url) == 0) return track; } return NULL;}
// Whether this property should react to key events generated by auto-repeat.static bool check_property_autorepeat(char *property, struct MPContext *mpctx){ struct m_option prop = {0}; if (mp_property_do(property, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0) return true;
// This is a heuristic at best. if (prop.type == &m_option_type_flag || prop.type == &m_option_type_choice) return false;
return true;}
// Whether changes to this property (add/cycle cmds) benefit from cmd->scalestatic bool check_property_scalable(char *property, struct MPContext *mpctx){ struct m_option prop = {0}; if (mp_property_do(property, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0) return true;
// These properties are backed by a floating-point number return prop.type == &m_option_type_float || prop.type == &m_option_type_double || prop.type == &m_option_type_time || prop.type == &m_option_type_aspect;}
static void show_property_status(struct mp_cmd_ctx *cmd, const char *name, int r){ struct MPContext *mpctx = cmd->mpctx; struct MPOpts *opts = mpctx->opts; int osd_duration = opts->osd_duration; int osdl = cmd->msg_osd ? 1 : OSD_LEVEL_INVISIBLE;
if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) { show_property_osd(mpctx, name, cmd->on_osd); if (r == M_PROPERTY_UNAVAILABLE) cmd->success = false; } else if (r == M_PROPERTY_UNKNOWN) { set_osd_msg(mpctx, osdl, osd_duration, "Unknown property: '%s'", name); cmd->success = false; } else if (r <= 0) { set_osd_msg(mpctx, osdl, osd_duration, "Failed to set property '%s'", name); cmd->success = false; }}
static void change_property_cmd(struct mp_cmd_ctx *cmd, const char *name, int action, void *arg){ int r = mp_property_do(name, action, arg, cmd->mpctx); show_property_status(cmd, name, r);}
static void cmd_cycle_values(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int first = 0, dir = 1;
if (strcmp(cmd->args[first].v.s, "!reverse") == 0) { first += 1; dir = -1; }
const char *name = cmd->args[first].v.s; first += 1;
if (first >= cmd->num_args) { MP_ERR(mpctx, "cycle-values command does not have any value arguments.\n"); cmd->success = false; return; }
struct m_option prop = {0}; int r = mp_property_do(name, M_PROPERTY_GET_TYPE, &prop, mpctx); if (r <= 0) { show_property_status(cmd, name, r); return; }
union m_option_value curval = {0}; r = mp_property_do(name, M_PROPERTY_GET, &curval, mpctx); if (r <= 0) { show_property_status(cmd, name, r); return; }
int current = -1; for (int n = first; n < cmd->num_args; n++) { union m_option_value val = {0}; if (m_option_parse(mpctx->log, &prop, bstr0(name), bstr0(cmd->args[n].v.s), &val) < 0) continue;
if (m_option_equal(&prop, &curval, &val)) current = n;
m_option_free(&prop, &val);
if (current >= 0) break; }
m_option_free(&prop, &curval);
if (current >= 0) { current += dir; if (current < first) current = cmd->num_args - 1; if (current >= cmd->num_args) current = first; } else { MP_VERBOSE(mpctx, "Current value not found. Picking default.\n"); current = dir > 0 ? first : cmd->num_args - 1; }
change_property_cmd(cmd, name, M_PROPERTY_SET_STRING, cmd->args[current].v.s);}
struct cmd_list_ctx { struct MPContext *mpctx;
// actual list command struct mp_cmd_ctx *parent;
bool current_valid; pthread_t current; bool completed_recursive;
// list of sub commands yet to run struct mp_cmd **sub; int num_sub;};
static void continue_cmd_list(struct cmd_list_ctx *list);
static void on_cmd_list_sub_completion(struct mp_cmd_ctx *cmd){ struct cmd_list_ctx *list = cmd->on_completion_priv;
if (list->current_valid && pthread_equal(list->current, pthread_self())) { list->completed_recursive = true; } else { continue_cmd_list(list); }}
static void continue_cmd_list(struct cmd_list_ctx *list){ while (list->parent->args[0].v.p) { struct mp_cmd *sub = list->parent->args[0].v.p; list->parent->args[0].v.p = sub->queue_next;
ta_xset_parent(sub, NULL);
if (sub->flags & MP_ASYNC_CMD) { // We run it "detached" (fire & forget) run_command(list->mpctx, sub, NULL, NULL, NULL); } else { // Run the next command once this one completes.
list->completed_recursive = false; list->current_valid = true; list->current = pthread_self();
run_command(list->mpctx, sub, NULL, on_cmd_list_sub_completion, list);
list->current_valid = false;
// run_command() either recursively calls the completion function, // or lets the command continue run in the background. If it was // completed recursively, we can just continue our loop. Otherwise // the completion handler will invoke this loop again elsewhere. // We could unconditionally call continue_cmd_list() in the handler // instead, but then stack depth would grow with list length. if (!list->completed_recursive) return; } }
mp_cmd_ctx_complete(list->parent); talloc_free(list);}
static void cmd_list(void *p){ struct mp_cmd_ctx *cmd = p;
cmd->completed = false;
struct cmd_list_ctx *list = talloc_zero(NULL, struct cmd_list_ctx); list->mpctx = cmd->mpctx; list->parent = p;
continue_cmd_list(list);}
const struct mp_cmd_def mp_cmd_list = { "list", cmd_list, .exec_async = true };
// Signal that the command is complete now. This also deallocates cmd.// You must call this function in a state where the core is locked for the// current thread (e.g. from the main thread, or from within mp_dispatch_lock()).// Completion means the command is finished, even if it errored or never ran.// Keep in mind that calling this can execute further user command that can// change arbitrary state (due to cmd_list).void mp_cmd_ctx_complete(struct mp_cmd_ctx *cmd){ cmd->completed = true; if (!cmd->success) mpv_free_node_contents(&cmd->result); if (cmd->on_completion) cmd->on_completion(cmd); if (cmd->abort) mp_abort_remove(cmd->mpctx, cmd->abort); mpv_free_node_contents(&cmd->result); talloc_free(cmd);}
static void run_command_on_worker_thread(void *p){ struct mp_cmd_ctx *ctx = p; struct MPContext *mpctx = ctx->mpctx;
mp_core_lock(mpctx);
bool exec_async = ctx->cmd->def->exec_async; ctx->cmd->def->handler(ctx); if (!exec_async) mp_cmd_ctx_complete(ctx);
mpctx->outstanding_async -= 1; if (!mpctx->outstanding_async && mp_is_shutting_down(mpctx)) mp_wakeup_core(mpctx);
mp_core_unlock(mpctx);}
// Run the given command. Upon command completion, on_completion is called. This// can happen within the function, or for async commands, some time after the// function returns (the caller is supposed to be able to handle both cases). In// both cases, the callback will be called while the core is locked (i.e. you// can access the core freely).// If abort is non-NULL, then the caller creates the abort object. It must have// been allocated with talloc. run_command() will register/unregister/destroy// it. Must not be set if cmd->def->can_abort==false.// on_completion_priv is copied to mp_cmd_ctx.on_completion_priv and can be// accessed from the completion callback.// The completion callback is invoked exactly once. If it's NULL, it's ignored.// Ownership of cmd goes to the caller.void run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mp_abort_entry *abort, void (*on_completion)(struct mp_cmd_ctx *cmd), void *on_completion_priv){ struct mp_cmd_ctx *ctx = talloc(NULL, struct mp_cmd_ctx); *ctx = (struct mp_cmd_ctx){ .mpctx = mpctx, .cmd = talloc_steal(ctx, cmd), .args = cmd->args, .num_args = cmd->nargs, .priv = cmd->def->priv, .abort = talloc_steal(ctx, abort), .success = true, .completed = true, .on_completion = on_completion, .on_completion_priv = on_completion_priv, };
if (!ctx->abort && cmd->def->can_abort) ctx->abort = talloc_zero(ctx, struct mp_abort_entry);
assert(cmd->def->can_abort == !!ctx->abort);
if (ctx->abort) { ctx->abort->coupled_to_playback |= cmd->def->abort_on_playback_end; mp_abort_add(mpctx, ctx->abort); }
struct MPOpts *opts = mpctx->opts; ctx->on_osd = cmd->flags & MP_ON_OSD_FLAGS; bool auto_osd = ctx->on_osd == MP_ON_OSD_AUTO; ctx->msg_osd = auto_osd || (ctx->on_osd & MP_ON_OSD_MSG); ctx->bar_osd = auto_osd || (ctx->on_osd & MP_ON_OSD_BAR); ctx->seek_msg_osd = auto_osd ? opts->osd_on_seek & 2 : ctx->msg_osd; ctx->seek_bar_osd = auto_osd ? opts->osd_on_seek & 1 : ctx->bar_osd;
bool noise = cmd->def->is_noisy || cmd->mouse_move; mp_cmd_dump(mpctx->log, noise ? MSGL_TRACE : MSGL_DEBUG, "Run command:", cmd);
if (cmd->flags & MP_EXPAND_PROPERTIES) { for (int n = 0; n < cmd->nargs; n++) { if (cmd->args[n].type->type == CONF_TYPE_STRING) { char *s = mp_property_expand_string(mpctx, cmd->args[n].v.s); if (!s) { ctx->success = false; mp_cmd_ctx_complete(ctx); return; } talloc_free(cmd->args[n].v.s); cmd->args[n].v.s = s; } } }
if (cmd->def->spawn_thread) { mpctx->outstanding_async += 1; // prevent that core disappears if (!mp_thread_pool_queue(mpctx->thread_pool, run_command_on_worker_thread, ctx)) { mpctx->outstanding_async -= 1; ctx->success = false; mp_cmd_ctx_complete(ctx); } } else { bool exec_async = cmd->def->exec_async; cmd->def->handler(ctx); if (!exec_async) mp_cmd_ctx_complete(ctx); }}
// When a command shows a message. status is the level (e.g. MSGL_INFO), and// msg+vararg is as in printf (don't include a trailing "\n").void mp_cmd_msg(struct mp_cmd_ctx *cmd, int status, const char *msg, ...){ va_list ap; char *s;
va_start(ap, msg); s = talloc_vasprintf(NULL, msg, ap); va_end(ap);
MP_MSG(cmd->mpctx, status, "%s\n", s); if (cmd->msg_osd && status <= MSGL_INFO) set_osd_msg(cmd->mpctx, 1, cmd->mpctx->opts->osd_duration, "%s", s);
talloc_free(s);}
static void cmd_seek(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
double v = cmd->args[0].v.d * cmd->cmd->scale; int abs = cmd->args[1].v.i & 3; enum seek_precision precision = MPSEEK_DEFAULT; switch (((cmd->args[2].v.i | cmd->args[1].v.i) >> 3) & 3) { case 1: precision = MPSEEK_KEYFRAME; break; case 2: precision = MPSEEK_EXACT; break; } if (!mpctx->playback_initialized) { cmd->success = false; return; }
mark_seek(mpctx); switch (abs) { case 0: { // Relative seek queue_seek(mpctx, MPSEEK_RELATIVE, v, precision, MPSEEK_FLAG_DELAY); set_osd_function(mpctx, (v > 0) ? OSD_FFW : OSD_REW); break; } case 1: { // Absolute seek by percentage double ratio = v / 100.0; double cur_pos = get_current_pos_ratio(mpctx, false); queue_seek(mpctx, MPSEEK_FACTOR, ratio, precision, MPSEEK_FLAG_DELAY); set_osd_function(mpctx, cur_pos < ratio ? OSD_FFW : OSD_REW); break; } case 2: { // Absolute seek to a timestamp in seconds if (v < 0) { // Seek from end double len = get_time_length(mpctx); if (len < 0) { cmd->success = false; return; } v = MPMAX(0, len + v); } queue_seek(mpctx, MPSEEK_ABSOLUTE, v, precision, MPSEEK_FLAG_DELAY); set_osd_function(mpctx, v > get_current_time(mpctx) ? OSD_FFW : OSD_REW); break; } case 3: { // Relative seek by percentage queue_seek(mpctx, MPSEEK_FACTOR, get_current_pos_ratio(mpctx, false) + v / 100.0, precision, MPSEEK_FLAG_DELAY); set_osd_function(mpctx, v > 0 ? OSD_FFW : OSD_REW); break; }} if (cmd->seek_bar_osd) mpctx->add_osd_seek_info |= OSD_SEEK_INFO_BAR; if (cmd->seek_msg_osd) mpctx->add_osd_seek_info |= OSD_SEEK_INFO_TEXT;}
static void cmd_revert_seek(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; struct command_ctx *cmdctx = mpctx->command_ctx;
if (!mpctx->playback_initialized) { cmd->success = false; return; }
double oldpts = cmdctx->last_seek_pts; if (cmdctx->marked_pts != MP_NOPTS_VALUE) oldpts = cmdctx->marked_pts; if (cmd->args[0].v.i == 1) { cmdctx->marked_pts = get_current_time(mpctx); } else if (oldpts != MP_NOPTS_VALUE) { cmdctx->last_seek_pts = get_current_time(mpctx); cmdctx->marked_pts = MP_NOPTS_VALUE; queue_seek(mpctx, MPSEEK_ABSOLUTE, oldpts, MPSEEK_EXACT, MPSEEK_FLAG_DELAY); set_osd_function(mpctx, OSD_REW); if (cmd->seek_bar_osd) mpctx->add_osd_seek_info |= OSD_SEEK_INFO_BAR; if (cmd->seek_msg_osd) mpctx->add_osd_seek_info |= OSD_SEEK_INFO_TEXT; } else { cmd->success = false; }}
static void cmd_set(void *p){ struct mp_cmd_ctx *cmd = p;
change_property_cmd(cmd, cmd->args[0].v.s, M_PROPERTY_SET_STRING, cmd->args[1].v.s);}
static void cmd_change_list(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; char *name = cmd->args[0].v.s; char *op = cmd->args[1].v.s; char *value = cmd->args[2].v.s; int osd_duration = mpctx->opts->osd_duration; int osdl = cmd->msg_osd ? 1 : OSD_LEVEL_INVISIBLE;
struct m_option prop = {0}; if (mp_property_do(name, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0) { set_osd_msg(mpctx, osdl, osd_duration, "Unknown option: '%s'", name); cmd->success = false; return; }
const struct m_option_type *type = prop.type; bool found = false; for (int i = 0; type->actions && type->actions[i].name; i++) { const struct m_option_action *action = &type->actions[i]; if (strcmp(action->name, op) == 0) found = true; } if (!found) { set_osd_msg(mpctx, osdl, osd_duration, "Unknown action: '%s'", op); cmd->success = false; return; }
union m_option_value val = {0}; if (mp_property_do(name, M_PROPERTY_GET, &val, mpctx) <= 0) { set_osd_msg(mpctx, osdl, osd_duration, "Could not read: '%s'", name); cmd->success = false; return; }
char *optname = mp_tprintf(80, "%s-%s", name, op); // the dirty truth int r = m_option_parse(mpctx->log, &prop, bstr0(optname), bstr0(value), &val); if (r >= 0 && mp_property_do(name, M_PROPERTY_SET, &val, mpctx) <= 0) r = -1; m_option_free(&prop, &val); if (r < 0) { set_osd_msg(mpctx, osdl, osd_duration, "Failed setting option: '%s'", name); cmd->success = false; return; }
show_property_osd(mpctx, name, cmd->on_osd);}
static void cmd_add_cycle(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; bool is_cycle = !!cmd->priv;
char *property = cmd->args[0].v.s; if (cmd->cmd->repeated && !check_property_autorepeat(property, mpctx)) { MP_VERBOSE(mpctx, "Dropping command '%s' from auto-repeated key.\n", cmd->cmd->original); return; }
double scale = 1; int scale_units = cmd->cmd->scale_units; if (check_property_scalable(property, mpctx)) { scale = cmd->cmd->scale; scale_units = 1; }
for (int i = 0; i < scale_units; i++) { struct m_property_switch_arg s = { .inc = cmd->args[1].v.d * scale, .wrap = is_cycle, }; change_property_cmd(cmd, property, M_PROPERTY_SWITCH, &s); if (!cmd->success) return; }}
static void cmd_multiply(void *p){ struct mp_cmd_ctx *cmd = p;
change_property_cmd(cmd, cmd->args[0].v.s, M_PROPERTY_MULTIPLY, &cmd->args[1].v.d);}
static void cmd_frame_step(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
if (!mpctx->playback_initialized) { cmd->success = false; return; }
if (cmd->cmd->is_up_down) { if (cmd->cmd->is_up) { if (mpctx->step_frames < 1) set_pause_state(mpctx, true); } else { if (cmd->cmd->repeated) { set_pause_state(mpctx, false); } else { add_step_frame(mpctx, 1); } } } else { add_step_frame(mpctx, 1); }}
static void cmd_frame_back_step(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
if (!mpctx->playback_initialized) { cmd->success = false; return; }
add_step_frame(mpctx, -1);}
static void cmd_quit(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; bool write_watch_later = *(bool *)cmd->priv; if (write_watch_later || mpctx->opts->position_save_on_quit) mp_write_watch_later_conf(mpctx); mpctx->stop_play = PT_QUIT; mpctx->quit_custom_rc = cmd->args[0].v.i; mpctx->has_quit_custom_rc = true; mp_wakeup_core(mpctx);}
static void cmd_playlist_next_prev(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int dir = *(int *)cmd->priv; int force = cmd->args[0].v.i;
struct playlist_entry *e = mp_next_file(mpctx, dir, force, true); if (!e && !force) { cmd->success = false; return; }
mp_set_playlist_entry(mpctx, e); if (cmd->on_osd & MP_ON_OSD_MSG) mpctx->add_osd_seek_info |= OSD_SEEK_INFO_CURRENT_FILE;}
static void cmd_sub_step_seek(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; bool step = *(bool *)cmd->priv;
if (!mpctx->playback_initialized) { cmd->success = false; return; }
struct track *track = mpctx->current_track[0][STREAM_SUB]; struct dec_sub *sub = track ? track->d_sub : NULL; double refpts = get_current_time(mpctx); if (sub && refpts != MP_NOPTS_VALUE) { double a[2]; a[0] = refpts; a[1] = cmd->args[0].v.i; if (sub_control(sub, SD_CTRL_SUB_STEP, a) > 0) { if (step) { mpctx->opts->subs_rend->sub_delay -= a[0] - refpts; m_config_notify_change_opt_ptr_notify(mpctx->mconfig, &mpctx->opts->subs_rend->sub_delay); show_property_osd(mpctx, "sub-delay", cmd->on_osd); } else { // We can easily get stuck by failing to seek to the video // frame which actually shows the sub first (because video // frame PTS and sub PTS rarely match exactly). Add some // rounding for the mess of it. a[0] += 0.01 * (a[1] >= 0 ? 1 : -1); mark_seek(mpctx); queue_seek(mpctx, MPSEEK_ABSOLUTE, a[0], MPSEEK_EXACT, MPSEEK_FLAG_DELAY); set_osd_function(mpctx, (a[0] > refpts) ? OSD_FFW : OSD_REW); if (cmd->seek_bar_osd) mpctx->add_osd_seek_info |= OSD_SEEK_INFO_BAR; if (cmd->seek_msg_osd) mpctx->add_osd_seek_info |= OSD_SEEK_INFO_TEXT; } } }}
static void cmd_print_text(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
MP_INFO(mpctx, "%s\n", cmd->args[0].v.s);}
static void cmd_show_text(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int osd_duration = mpctx->opts->osd_duration;
// if no argument supplied use default osd_duration, else <arg> ms. set_osd_msg(mpctx, cmd->args[2].v.i, (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i), "%s", cmd->args[0].v.s);}
static void cmd_expand_text(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
cmd->result = (mpv_node){ .format = MPV_FORMAT_STRING, .u.string = mp_property_expand_string(mpctx, cmd->args[0].v.s) };}
static void cmd_expand_path(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
cmd->result = (mpv_node){ .format = MPV_FORMAT_STRING, .u.string = mp_get_user_path(NULL, mpctx->global, cmd->args[0].v.s) };}
static void cmd_loadfile(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; char *filename = cmd->args[0].v.s; int append = cmd->args[1].v.i;
if (!append) playlist_clear(mpctx->playlist);
struct playlist_entry *entry = playlist_entry_new(filename); if (cmd->args[2].v.str_list) { char **pairs = cmd->args[2].v.str_list; for (int i = 0; pairs[i] && pairs[i + 1]; i += 2) playlist_entry_add_param(entry, bstr0(pairs[i]), bstr0(pairs[i + 1])); } playlist_add(mpctx->playlist, entry);
if (!append || (append == 2 && !mpctx->playlist->current)) { if (mpctx->opts->position_save_on_quit) // requested in issue #1148 mp_write_watch_later_conf(mpctx); mp_set_playlist_entry(mpctx, entry); } mp_notify(mpctx, MP_EVENT_CHANGE_PLAYLIST, NULL); mp_wakeup_core(mpctx);}
static void cmd_loadlist(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; char *filename = cmd->args[0].v.s; bool append = cmd->args[1].v.i;
struct playlist *pl = playlist_parse_file(filename, cmd->abort->cancel, mpctx->global); if (pl) { prepare_playlist(mpctx, pl); struct playlist_entry *new = pl->current; if (!append) playlist_clear(mpctx->playlist); playlist_append_entries(mpctx->playlist, pl); talloc_free(pl);
if (!new) new = playlist_get_first(mpctx->playlist);
if (!append && new) mp_set_playlist_entry(mpctx, new);
mp_notify(mpctx, MP_EVENT_CHANGE_PLAYLIST, NULL); mp_wakeup_core(mpctx); } else { MP_ERR(mpctx, "Unable to load playlist %s.\n", filename); cmd->success = false; }}
static void cmd_playlist_clear(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
// Supposed to clear the playlist, except the currently played item. if (mpctx->playlist->current_was_replaced) mpctx->playlist->current = NULL; playlist_clear_except_current(mpctx->playlist); mp_notify(mpctx, MP_EVENT_CHANGE_PLAYLIST, NULL); mp_wakeup_core(mpctx);}
static void cmd_playlist_remove(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
struct playlist_entry *e = playlist_entry_from_index(mpctx->playlist, cmd->args[0].v.i); if (cmd->args[0].v.i < 0) e = mpctx->playlist->current; if (!e) { cmd->success = false; return; }
// Can't play a removed entry if (mpctx->playlist->current == e && !mpctx->stop_play) mpctx->stop_play = PT_NEXT_ENTRY; playlist_remove(mpctx->playlist, e); mp_notify(mpctx, MP_EVENT_CHANGE_PLAYLIST, NULL); mp_wakeup_core(mpctx);}
static void cmd_playlist_move(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
struct playlist_entry *e1 = playlist_entry_from_index(mpctx->playlist, cmd->args[0].v.i); struct playlist_entry *e2 = playlist_entry_from_index(mpctx->playlist, cmd->args[1].v.i); if (!e1) { cmd->success = false; return; }
playlist_move(mpctx->playlist, e1, e2); mp_notify(mpctx, MP_EVENT_CHANGE_PLAYLIST, NULL);}
static void cmd_playlist_shuffle(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
playlist_shuffle(mpctx->playlist); mp_notify(mpctx, MP_EVENT_CHANGE_PLAYLIST, NULL);}
static void cmd_playlist_unshuffle(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
playlist_unshuffle(mpctx->playlist); mp_notify(mpctx, MP_EVENT_CHANGE_PLAYLIST, NULL);}
static void cmd_stop(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
playlist_clear(mpctx->playlist); if (mpctx->stop_play != PT_QUIT) mpctx->stop_play = PT_STOP; mp_wakeup_core(mpctx);}
static void cmd_show_progress(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
mpctx->add_osd_seek_info |= (cmd->msg_osd ? OSD_SEEK_INFO_TEXT : 0) | (cmd->bar_osd ? OSD_SEEK_INFO_BAR : 0); mpctx->osd_force_update = true; mp_wakeup_core(mpctx);}
static void cmd_track_add(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int type = *(int *)cmd->priv;
if (mpctx->stop_play) { cmd->success = false; return; }
if (cmd->args[1].v.i == 2) { struct track *t = find_track_with_url(mpctx, type, cmd->args[0].v.s); if (t) { if (mpctx->playback_initialized) { mp_switch_track(mpctx, t->type, t, FLAG_MARK_SELECTION); print_track_list(mpctx, "Track switched:"); } else { mpctx->opts->stream_id[0][t->type] = t->user_tid; m_config_notify_change_opt_ptr(mpctx->mconfig, &mpctx->opts->stream_id[0][t->type]); } return; } } int first = mp_add_external_file(mpctx, cmd->args[0].v.s, type, cmd->abort->cancel); if (first < 0) { cmd->success = false; return; }
for (int n = first; n < mpctx->num_tracks; n++) { struct track *t = mpctx->tracks[n]; if (cmd->args[1].v.i == 1) { t->no_default = true; } else if (n == first) { if (mpctx->playback_initialized) { mp_switch_track(mpctx, t->type, t, FLAG_MARK_SELECTION); } else { mpctx->opts->stream_id[0][t->type] = t->user_tid; m_config_notify_change_opt_ptr(mpctx->mconfig, &mpctx->opts->stream_id[0][t->type]); } } char *title = cmd->args[2].v.s; if (title && title[0]) t->title = talloc_strdup(t, title); char *lang = cmd->args[3].v.s; if (lang && lang[0]) t->lang = talloc_strdup(t, lang); }
if (mpctx->playback_initialized) print_track_list(mpctx, "Track added:");}
static void cmd_track_remove(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int type = *(int *)cmd->priv;
struct track *t = mp_track_by_tid(mpctx, type, cmd->args[0].v.i); if (!t) { cmd->success = false; return; }
mp_remove_track(mpctx, t); if (mpctx->playback_initialized) print_track_list(mpctx, "Track removed:");}
static void cmd_track_reload(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int type = *(int *)cmd->priv;
if (!mpctx->playback_initialized) { MP_ERR(mpctx, "Cannot reload while not initialized.\n"); cmd->success = false; return; }
struct track *t = mp_track_by_tid(mpctx, type, cmd->args[0].v.i); int nt_num = -1;
if (t && t->is_external && t->external_filename) { char *filename = talloc_strdup(NULL, t->external_filename); mp_remove_track(mpctx, t); nt_num = mp_add_external_file(mpctx, filename, type, cmd->abort->cancel); talloc_free(filename); }
if (nt_num < 0) { cmd->success = false; return; }
struct track *nt = mpctx->tracks[nt_num]; mp_switch_track(mpctx, nt->type, nt, 0); print_track_list(mpctx, "Reloaded:");}
static void cmd_rescan_external_files(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
if (mpctx->stop_play) { cmd->success = false; return; }
autoload_external_files(mpctx, cmd->abort->cancel); if (!cmd->args[0].v.i && mpctx->playback_initialized) { // somewhat fuzzy and not ideal struct track *a = select_default_track(mpctx, 0, STREAM_AUDIO); if (a && a->is_external) mp_switch_track(mpctx, STREAM_AUDIO, a, 0); struct track *s = select_default_track(mpctx, 0, STREAM_SUB); if (s && s->is_external) mp_switch_track(mpctx, STREAM_SUB, s, 0);
print_track_list(mpctx, "Track list:\n"); }}
static void cmd_run(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; char **args = talloc_zero_array(NULL, char *, cmd->num_args + 1); for (int n = 0; n < cmd->num_args; n++) args[n] = cmd->args[n].v.s; mp_subprocess_detached(mpctx->log, args); talloc_free(args);}
struct subprocess_cb_ctx { struct mp_log *log; void* talloc_ctx; int64_t max_size; bool capture[3]; bstr output[3];};
static void subprocess_output(struct subprocess_cb_ctx *ctx, int fd, char *data, size_t size){ if (ctx->capture[fd]) { if (ctx->output[fd].len < ctx->max_size) bstr_xappend(ctx->talloc_ctx, &ctx->output[fd], (bstr){data, size}); } else { int msgl = fd == 2 ? MSGL_ERR : MSGL_INFO; mp_msg(ctx->log, msgl, "%.*s", (int)size, data); }}
static void subprocess_stdout(void *p, char *data, size_t size){ struct subprocess_cb_ctx *ctx = p; subprocess_output(ctx, 1, data, size);}
static void subprocess_stderr(void *p, char *data, size_t size){ struct subprocess_cb_ctx *ctx = p; subprocess_output(ctx, 2, data, size);}
static void cmd_subprocess(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; char **args = cmd->args[0].v.str_list; bool playback_only = cmd->args[1].v.i;
if (!args || !args[0]) { MP_ERR(mpctx, "program name missing\n"); cmd->success = false; return; }
void *tmp = talloc_new(NULL); struct subprocess_cb_ctx ctx = { .log = mp_log_new(tmp, mpctx->log, cmd->cmd->sender), .talloc_ctx = tmp, .max_size = cmd->args[2].v.i, .capture = {0, cmd->args[3].v.i, cmd->args[4].v.i}, };
pthread_mutex_lock(&mpctx->abort_lock); cmd->abort->coupled_to_playback = playback_only; mp_abort_recheck_locked(mpctx, cmd->abort); pthread_mutex_unlock(&mpctx->abort_lock);
mp_core_unlock(mpctx);
char *error = NULL; int status = mp_subprocess(args, cmd->abort->cancel, &ctx, subprocess_stdout, subprocess_stderr, &error);
mp_core_lock(mpctx);
struct mpv_node *res = &cmd->result; node_init(res, MPV_FORMAT_NODE_MAP, NULL); node_map_add_int64(res, "status", status); node_map_add_flag(res, "killed_by_us", status == MP_SUBPROCESS_EKILLED_BY_US); node_map_add_string(res, "error_string", error ? error : ""); const char *sname[] = {NULL, "stdout", "stderr"}; for (int n = 1; n < 3; n++) { if (!ctx.capture[n]) continue; struct mpv_byte_array *ba = node_map_add(res, sname[n], MPV_FORMAT_BYTE_ARRAY)->u.ba; *ba = (struct mpv_byte_array){ .data = talloc_steal(ba, ctx.output[n].start), .size = ctx.output[n].len, }; }
talloc_free(tmp);}
static void cmd_enable_input_section(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; mp_input_enable_section(mpctx->input, cmd->args[0].v.s, cmd->args[1].v.i);}
static void cmd_disable_input_section(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; mp_input_disable_section(mpctx->input, cmd->args[0].v.s);}
static void cmd_define_input_section(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; mp_input_define_section(mpctx->input, cmd->args[0].v.s, "<api>", cmd->args[1].v.s, !cmd->args[2].v.i, cmd->cmd->sender);}
static void cmd_ab_loop(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int osd_duration = mpctx->opts->osd_duration; int osdl = cmd->msg_osd ? 1 : OSD_LEVEL_INVISIBLE;
double now = get_current_time(mpctx); if (mpctx->opts->ab_loop[0] == MP_NOPTS_VALUE) { mp_property_do("ab-loop-a", M_PROPERTY_SET, &now, mpctx); show_property_osd(mpctx, "ab-loop-a", cmd->on_osd); } else if (mpctx->opts->ab_loop[1] == MP_NOPTS_VALUE) { mp_property_do("ab-loop-b", M_PROPERTY_SET, &now, mpctx); show_property_osd(mpctx, "ab-loop-b", cmd->on_osd); } else { now = MP_NOPTS_VALUE; mp_property_do("ab-loop-a", M_PROPERTY_SET, &now, mpctx); mp_property_do("ab-loop-b", M_PROPERTY_SET, &now, mpctx); set_osd_msg(mpctx, osdl, osd_duration, "Clear A-B loop"); }}
static void cmd_align_cache_ab(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
if (!mpctx->demuxer) return;
double a = demux_probe_cache_dump_target(mpctx->demuxer, mpctx->opts->ab_loop[0], false); double b = demux_probe_cache_dump_target(mpctx->demuxer, mpctx->opts->ab_loop[1], true);
mp_property_do("ab-loop-a", M_PROPERTY_SET, &a, mpctx); mp_property_do("ab-loop-b", M_PROPERTY_SET, &b, mpctx);
// Happens to cover both properties. show_property_osd(mpctx, "ab-loop-b", cmd->on_osd);}
static void cmd_drop_buffers(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
reset_audio_state(mpctx); reset_video_state(mpctx);
if (mpctx->demuxer) demux_flush(mpctx->demuxer);}
static void cmd_ao_reload(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; reload_audio_output(mpctx);}
static void cmd_filter(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int type = *(int *)cmd->priv; cmd->success = edit_filters_osd(mpctx, type, cmd->args[0].v.s, cmd->args[1].v.s, cmd->msg_osd) >= 0;}
static void cmd_filter_command(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int type = *(int *)cmd->priv;
struct mp_output_chain *chain = NULL; if (type == STREAM_VIDEO) chain = mpctx->vo_chain ? mpctx->vo_chain->filter : NULL; if (type == STREAM_AUDIO) chain = mpctx->ao_chain ? mpctx->ao_chain->filter : NULL; if (!chain) { cmd->success = false; return; } struct mp_filter_command filter_cmd = { .type = MP_FILTER_COMMAND_TEXT, .cmd = cmd->args[1].v.s, .arg = cmd->args[2].v.s, }; cmd->success = mp_output_chain_command(chain, cmd->args[0].v.s, &filter_cmd);}
static void cmd_script_binding(void *p){ struct mp_cmd_ctx *cmd = p; struct mp_cmd *incmd = cmd->cmd; struct MPContext *mpctx = cmd->mpctx;
mpv_event_client_message event = {0}; char *name = cmd->args[0].v.s; if (!name || !name[0]) { cmd->success = false; return; }
char *sep = strchr(name, '/'); char *target = NULL; char space[MAX_CLIENT_NAME]; if (sep) { snprintf(space, sizeof(space), "%.*s", (int)(sep - name), name); target = space; name = sep + 1; } char state[3] = {'p', incmd->is_mouse_button ? 'm' : '-'}; if (incmd->is_up_down) state[0] = incmd->repeated ? 'r' : (incmd->is_up ? 'u' : 'd'); event.num_args = 5; event.args = (const char*[5]){"key-binding", name, state, incmd->key_name ? incmd->key_name : "", incmd->key_text ? incmd->key_text : ""}; if (mp_client_send_event_dup(mpctx, target, MPV_EVENT_CLIENT_MESSAGE, &event) < 0) { MP_VERBOSE(mpctx, "Can't find script '%s' when handling input.\n", target ? target : "-"); cmd->success = false; }}
static void cmd_script_message_to(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
mpv_event_client_message *event = talloc_ptrtype(NULL, event); *event = (mpv_event_client_message){0}; for (int n = 1; n < cmd->num_args; n++) { MP_TARRAY_APPEND(event, event->args, event->num_args, talloc_strdup(event, cmd->args[n].v.s)); } if (mp_client_send_event(mpctx, cmd->args[0].v.s, 0, MPV_EVENT_CLIENT_MESSAGE, event) < 0) { MP_VERBOSE(mpctx, "Can't find script '%s' to send message to.\n", cmd->args[0].v.s); cmd->success = false; }}
static void cmd_script_message(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
const char **args = talloc_array(NULL, const char *, cmd->num_args); mpv_event_client_message event = {.args = args}; for (int n = 0; n < cmd->num_args; n++) event.args[event.num_args++] = cmd->args[n].v.s; mp_client_broadcast_event(mpctx, MPV_EVENT_CLIENT_MESSAGE, &event); talloc_free(args);}
static void cmd_ignore(void *p){}
static void cmd_write_watch_later_config(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
mp_write_watch_later_conf(mpctx);}
static void cmd_hook_add(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
if (!cmd->cmd->sender) { MP_ERR(mpctx, "Can be used from client API only.\n"); cmd->success = false; return; } mp_hook_add(mpctx, cmd->cmd->sender, cmd->args[0].v.s, cmd->args[1].v.i, cmd->args[2].v.i, true);}
static void cmd_hook_ack(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
if (!cmd->cmd->sender) { MP_ERR(mpctx, "Can be used from client API only.\n"); cmd->success = false; return; } mp_hook_continue(mpctx, cmd->cmd->sender, cmd->args[0].v.i);}
static void cmd_mouse(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
const int x = cmd->args[0].v.i, y = cmd->args[1].v.i; int button = cmd->args[2].v.i; if (button == -1) {// no button mp_input_set_mouse_pos_artificial(mpctx->input, x, y); return; } if (button < 0 || button >= MP_KEY_MOUSE_BTN_COUNT) {// invalid button MP_ERR(mpctx, "%d is not a valid mouse button number.\n", button); cmd->success = false; return; } const bool dbc = cmd->args[3].v.i; if (dbc && button > (MP_MBTN_RIGHT - MP_MBTN_BASE)) { MP_ERR(mpctx, "%d is not a valid mouse button for double-clicks.\n", button); cmd->success = false; return; } button += dbc ? MP_MBTN_DBL_BASE : MP_MBTN_BASE; mp_input_set_mouse_pos_artificial(mpctx->input, x, y); mp_input_put_key_artificial(mpctx->input, button);}
static void cmd_key(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx; int action = *(int *)cmd->priv;
const char *key_name = cmd->args[0].v.s; if (key_name[0] == '\0' && action == MP_KEY_STATE_UP) { mp_input_put_key_artificial(mpctx->input, MP_INPUT_RELEASE_ALL); } else { int code = mp_input_get_key_from_name(key_name); if (code < 0) { MP_ERR(mpctx, "%s is not a valid input name.\n", key_name); cmd->success = false; return; } mp_input_put_key_artificial(mpctx->input, code | action); }}
static void cmd_key_bind(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
int code = mp_input_get_key_from_name(cmd->args[0].v.s); if (code < 0) { MP_ERR(mpctx, "%s is not a valid input name.\n", cmd->args[0].v.s); cmd->success = false; return; } const char *target_cmd = cmd->args[1].v.s; mp_input_bind_key(mpctx->input, code, bstr0(target_cmd));}
static void cmd_apply_profile(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
char *profile = cmd->args[0].v.s; if (m_config_set_profile(mpctx->mconfig, profile, 0) < 0) cmd->success = false;}
static void cmd_load_script(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
char *script = cmd->args[0].v.s; if (mp_load_user_script(mpctx, script) < 0) cmd->success = false;}
static void cache_dump_poll(struct MPContext *mpctx){ struct command_ctx *ctx = mpctx->command_ctx; struct mp_cmd_ctx *cmd = ctx->cache_dump_cmd;
if (!cmd) return;
// Can't close demuxer without stopping dumping. assert(mpctx->demuxer);
if (mp_cancel_test(cmd->abort->cancel)) { // Synchronous abort. In particular, the dump command shall not report // completion to the user before the dump target file was closed. demux_cache_dump_set(mpctx->demuxer, 0, 0, NULL); assert(demux_cache_dump_get_status(mpctx->demuxer) <= 0); }
int status = demux_cache_dump_get_status(mpctx->demuxer); if (status <= 0) { if (status < 0) { mp_cmd_msg(cmd, MSGL_ERR, "Cache dumping stopped due to error."); cmd->success = false; } else { mp_cmd_msg(cmd, MSGL_INFO, "Cache dumping successfully ended."); cmd->success = true; } ctx->cache_dump_cmd = NULL; mp_cmd_ctx_complete(cmd); }}
void mp_abort_cache_dumping(struct MPContext *mpctx){ struct command_ctx *ctx = mpctx->command_ctx;
if (ctx->cache_dump_cmd) mp_cancel_trigger(ctx->cache_dump_cmd->abort->cancel); cache_dump_poll(mpctx); assert(!ctx->cache_dump_cmd); // synchronous abort, must have worked}
static void run_dump_cmd(struct mp_cmd_ctx *cmd, double start, double end, char *filename){ struct MPContext *mpctx = cmd->mpctx; struct command_ctx *ctx = mpctx->command_ctx;
mp_abort_cache_dumping(mpctx);
if (!mpctx->demuxer) { mp_cmd_msg(cmd, MSGL_ERR, "No demuxer open."); cmd->success = false; mp_cmd_ctx_complete(cmd); return; }
mp_cmd_msg(cmd, MSGL_INFO, "Cache dumping started.");
if (!demux_cache_dump_set(mpctx->demuxer, start, end, filename)) { mp_cmd_msg(cmd, MSGL_INFO, "Cache dumping stopped."); mp_cmd_ctx_complete(cmd); return; }
ctx->cache_dump_cmd = cmd; cache_dump_poll(mpctx);}
static void cmd_dump_cache(void *p){ struct mp_cmd_ctx *cmd = p;
run_dump_cmd(cmd, cmd->args[0].v.d, cmd->args[1].v.d, cmd->args[2].v.s);}
static void cmd_dump_cache_ab(void *p){ struct mp_cmd_ctx *cmd = p; struct MPContext *mpctx = cmd->mpctx;
run_dump_cmd(cmd, mpctx->opts->ab_loop[0], mpctx->opts->ab_loop[1], cmd->args[0].v.s);}
/* This array defines all known commands. * The first field the command name used in libmpv and input.conf. * The second field is the handler function (see mp_cmd_def.handler and * run_command()). * Then comes the definition of each argument. They are defined like options, * except that the result is parsed into mp_cmd.args[] (thus the option variable * is a field in the mp_cmd_arg union field). Arguments are optional if either * defval is set (usually via OPTDEF_ macros), or the MP_CMD_OPT_ARG flag is * set, or if it's the last argument and .vararg is set. If .vararg is set, the * command has an arbitrary number of arguments, all using the type indicated by * the last argument (they are appended to mp_cmd.args[] starting at the last * argument's index). * Arguments have names, which can be used by named argument functions, e.g. in * Lua with mp.command_native(). */
// This does not specify the real destination of the command parameter values,// it just provides a dummy for the OPT_ macros. The real destination is an// array item in mp_cmd.args[], using the index of the option definition.#define OPT_BASE_STRUCT struct mp_cmd_arg
const struct mp_cmd_def mp_cmds[] = { { "ignore", cmd_ignore, .is_ignore = true, .is_noisy = true, },
{ "seek", cmd_seek, { OPT_TIME("target", v.d, 0), OPT_FLAGS("flags", v.i, 0, ({"relative", 4|0}, {"-", 4|0}, {"absolute-percent", 4|1}, {"absolute", 4|2}, {"relative-percent", 4|3}, {"keyframes", 32|8}, {"exact", 32|16}), OPTDEF_INT(4|0)), // backwards compatibility only OPT_CHOICE("legacy", v.i, MP_CMD_OPT_ARG, ({"unused", 0}, {"default-precise", 0}, {"keyframes", 32|8}, {"exact", 32|16})), }, .allow_auto_repeat = true, .scalable = true, }, { "revert-seek", cmd_revert_seek, {OPT_FLAGS("flags", v.i, MP_CMD_OPT_ARG, ({"mark", 1}))}, }, { "quit", cmd_quit, { OPT_INT("code", v.i, MP_CMD_OPT_ARG) }, .priv = &(const bool){0} }, { "quit-watch-later", cmd_quit, { OPT_INT("code", v.i, MP_CMD_OPT_ARG) }, .priv = &(const bool){1} }, { "stop", cmd_stop, }, { "frame-step", cmd_frame_step, .allow_auto_repeat = true, .on_updown = true }, { "frame-back-step", cmd_frame_back_step, .allow_auto_repeat = true }, { "playlist-next", cmd_playlist_next_prev, { OPT_CHOICE("flags", v.i, MP_CMD_OPT_ARG, ({"weak", 0}, {"force", 1})), }, .priv = &(const int){1}, }, { "playlist-prev", cmd_playlist_next_prev, { OPT_CHOICE("flags", v.i, MP_CMD_OPT_ARG, ({"weak", 0}, {"force", 1})), }, .priv = &(const int){-1}, }, { "playlist-shuffle", cmd_playlist_shuffle, }, { "playlist-unshuffle", cmd_playlist_unshuffle, }, { "sub-step", cmd_sub_step_seek, { OPT_INT("skip", v.i, 0) }, .allow_auto_repeat = true, .priv = &(const bool){true} }, { "sub-seek", cmd_sub_step_seek, { OPT_INT("skip", v.i, 0) }, .allow_auto_repeat = true, .priv = &(const bool){false} }, { "print-text", cmd_print_text, { OPT_STRING("text", v.s, 0) }, .is_noisy = true, .allow_auto_repeat = true }, { "show-text", cmd_show_text, { OPT_STRING("text", v.s, 0), OPT_INT("duration", v.i, 0, OPTDEF_INT(-1)), OPT_INT("level", v.i, MP_CMD_OPT_ARG), }, .is_noisy = true, .allow_auto_repeat = true}, { "expand-text", cmd_expand_text, { OPT_STRING("text", v.s, 0) }, .is_noisy = true }, { "expand-path", cmd_expand_path, { OPT_STRING("text", v.s, 0) }, .is_noisy = true }, { "show-progress", cmd_show_progress, .allow_auto_repeat = true, .is_noisy = true },
{ "sub-add", cmd_track_add, { OPT_STRING("url", v.s, 0), OPT_CHOICE("flags", v.i, MP_CMD_OPT_ARG, ({"select", 0}, {"auto", 1}, {"cached", 2})), OPT_STRING("title", v.s, MP_CMD_OPT_ARG), OPT_STRING("lang", v.s, MP_CMD_OPT_ARG), }, .priv = &(const int){STREAM_SUB}, .spawn_thread = true, .can_abort = true, .abort_on_playback_end = true, }, { "audio-add", cmd_track_add, { OPT_STRING("url", v.s, 0), OPT_CHOICE("flags", v.i, MP_CMD_OPT_ARG, ({"select", 0}, {"auto", 1}, {"cached", 2})), OPT_STRING("title", v.s, MP_CMD_OPT_ARG), OPT_STRING("lang", v.s, MP_CMD_OPT_ARG), }, .priv = &(const int){STREAM_AUDIO}, .spawn_thread = true, .can_abort = true, .abort_on_playback_end = true, }, { "video-add", cmd_track_add, { OPT_STRING("url", v.s, 0), OPT_CHOICE("flags", v.i, MP_CMD_OPT_ARG, ({"select", 0}, {"auto", 1}, {"cached", 2})), OPT_STRING("title", v.s, MP_CMD_OPT_ARG), OPT_STRING("lang", v.s, MP_CMD_OPT_ARG), }, .priv = &(const int){STREAM_VIDEO}, .spawn_thread = true, .can_abort = true, .abort_on_playback_end = true, },
{ "sub-remove", cmd_track_remove, { OPT_INT("id", v.i, 0, OPTDEF_INT(-1)) }, .priv = &(const int){STREAM_SUB}, }, { "audio-remove", cmd_track_remove, { OPT_INT("id", v.i, 0, OPTDEF_INT(-1)) }, .priv = &(const int){STREAM_AUDIO}, }, { "video-remove", cmd_track_remove, { OPT_INT("id", v.i, 0, OPTDEF_INT(-1)) }, .priv = &(const int){STREAM_VIDEO}, },
{ "sub-reload", cmd_track_reload, { OPT_INT("id", v.i, 0, OPTDEF_INT(-1)) }, .priv = &(const int){STREAM_SUB}, .spawn_thread = true, .can_abort = true, .abort_on_playback_end = true, }, { "audio-reload", cmd_track_reload, { OPT_INT("id", v.i, 0, OPTDEF_INT(-1)) }, .priv = &(const int){STREAM_AUDIO}, .spawn_thread = true, .can_abort = true, .abort_on_playback_end = true, }, { "video-reload", cmd_track_reload, { OPT_INT("id", v.i, 0, OPTDEF_INT(-1)) }, .priv = &(const int){STREAM_VIDEO}, .spawn_thread = true, .can_abort = true, .abort_on_playback_end = true, },
{ "rescan-external-files", cmd_rescan_external_files, { OPT_CHOICE("flags", v.i, MP_CMD_OPT_ARG, ({"keep-selection", 1}, {"reselect", 0})), }, .spawn_thread = true, .can_abort = true, .abort_on_playback_end = true, },
{ "screenshot", cmd_screenshot, { OPT_FLAGS("flags", v.i, 0, ({"video", 4|0}, {"-", 4|0}, {"window", 4|1}, {"subtitles", 4|2}, {"each-frame", 8}), OPTDEF_INT(4|2)), // backwards compatibility OPT_CHOICE("legacy", v.i, MP_CMD_OPT_ARG, ({"unused", 0}, {"single", 0}, {"each-frame", 8})), }, .spawn_thread = true, }, { "screenshot-to-file", cmd_screenshot_to_file, { OPT_STRING("filename", v.s, 0), OPT_CHOICE("flags", v.i, 0, ({"video", 0}, {"window", 1}, {"subtitles", 2}), OPTDEF_INT(2)), }, .spawn_thread = true, }, { "screenshot-raw", cmd_screenshot_raw, { OPT_CHOICE("flags", v.i, 0, ({"video", 0}, {"window", 1}, {"subtitles", 2}), OPTDEF_INT(2)), }, }, { "loadfile", cmd_loadfile, { OPT_STRING("url", v.s, 0), OPT_CHOICE("flags", v.i, MP_CMD_OPT_ARG, ({"replace", 0}, {"append", 1}, {"append-play", 2})), OPT_KEYVALUELIST("options", v.str_list, MP_CMD_OPT_ARG), }, }, { "loadlist", cmd_loadlist, { OPT_STRING("url", v.s, 0), OPT_CHOICE("flags", v.i, MP_CMD_OPT_ARG, ({"replace", 0}, {"append", 1})), }, .spawn_thread = true, .can_abort = true, }, { "playlist-clear", cmd_playlist_clear }, { "playlist-remove", cmd_playlist_remove, {OPT_CHOICE_OR_INT("index", v.i, MP_CMD_OPT_ARG, 0, INT_MAX, ({"current", -1}))}, }, { "playlist-move", cmd_playlist_move, { OPT_INT("index1", v.i, 0), OPT_INT("index2", v.i, 0), }}, { "run", cmd_run, { OPT_STRING("command", v.s, 0), OPT_STRING("args", v.s, 0), }, .vararg = true, }, { "subprocess", cmd_subprocess, { OPT_STRINGLIST("args", v.str_list, 0), OPT_FLAG("playback_only", v.i, 0, OPTDEF_INT(1)), OPT_BYTE_SIZE("capture_size", v.i64, 0, 0, INT_MAX, OPTDEF_INT64(64 * 1024 * 1024)), OPT_FLAG("capture_stdout", v.i, MP_CMD_OPT_ARG), OPT_FLAG("capture_stderr", v.i, MP_CMD_OPT_ARG), }, .spawn_thread = true, .can_abort = true, },
{ "set", cmd_set, {OPT_STRING("name", v.s, 0), OPT_STRING("value", v.s, 0)}}, { "change-list", cmd_change_list, { OPT_STRING("name", v.s, 0), OPT_STRING("operation", v.s, 0), OPT_STRING("value", v.s, 0) }}, { "add", cmd_add_cycle, { OPT_STRING("name", v.s, 0), OPT_DOUBLE("value", v.d, 0, OPTDEF_DOUBLE(1)), }, .allow_auto_repeat = true, .scalable = true, }, { "cycle", cmd_add_cycle, { OPT_STRING("name", v.s, 0), OPT_CYCLEDIR("value", v.d, 0, OPTDEF_DOUBLE(1)), }, .allow_auto_repeat = true, .scalable = true, .priv = "", }, { "multiply", cmd_multiply, { OPT_STRING("name", v.s, 0), OPT_DOUBLE("value", v.d, 0)}, .allow_auto_repeat = true},
{ "cycle-values", cmd_cycle_values, { OPT_STRING("arg0", v.s, 0), OPT_STRING("arg1", v.s, 0), OPT_STRING("argN", v.s, 0), }, .vararg = true},
{ "enable-section", cmd_enable_input_section, { OPT_STRING("name", v.s, 0), OPT_FLAGS("flags", v.i, MP_CMD_OPT_ARG, ({"default", 0}, {"exclusive", MP_INPUT_EXCLUSIVE}, {"allow-hide-cursor", MP_INPUT_ALLOW_HIDE_CURSOR}, {"allow-vo-dragging", MP_INPUT_ALLOW_VO_DRAGGING})), } }, { "disable-section", cmd_disable_input_section, {OPT_STRING("name", v.s, 0) }}, { "define-section", cmd_define_input_section, { OPT_STRING("name", v.s, 0), OPT_STRING("contents", v.s, 0), OPT_CHOICE("flags", v.i, MP_CMD_OPT_ARG, ({"default", 0}, {"force", 1})), }, },
{ "ab-loop", cmd_ab_loop },
{ "drop-buffers", cmd_drop_buffers, },
{ "af", cmd_filter, { OPT_STRING("operation", v.s, 0), OPT_STRING("value", v.s, 0), }, .priv = &(const int){STREAM_AUDIO} }, { "vf", cmd_filter, { OPT_STRING("operation", v.s, 0), OPT_STRING("value", v.s, 0), }, .priv = &(const int){STREAM_VIDEO} },
{ "af-command", cmd_filter_command, { OPT_STRING("label", v.s, 0), OPT_STRING("command", v.s, 0), OPT_STRING("argument", v.s, 0), }, .priv = &(const int){STREAM_AUDIO} }, { "vf-command", cmd_filter_command, { OPT_STRING("label", v.s, 0), OPT_STRING("command", v.s, 0), OPT_STRING("argument", v.s, 0), }, .priv = &(const int){STREAM_VIDEO} },
{ "ao-reload", cmd_ao_reload },
{ "script-binding", cmd_script_binding, { OPT_STRING("name", v.s, 0) }, .allow_auto_repeat = true, .on_updown = true},
{ "script-message", cmd_script_message, { OPT_STRING("args", v.s, 0) }, .vararg = true }, { "script-message-to", cmd_script_message_to, { OPT_STRING("target", v.s, 0), OPT_STRING("args", v.s, 0) }, .vararg = true },
{ "overlay-add", cmd_overlay_add, { OPT_INT("id", v.i, 0), OPT_INT("x", v.i, 0), OPT_INT("y", v.i, 0), OPT_STRING("file", v.s, 0), OPT_INT("offset", v.i, 0), OPT_STRING("fmt", v.s, 0), OPT_INT("w", v.i, 0), OPT_INT("h", v.i, 0), OPT_INT("stride", v.i, 0), }}, { "overlay-remove", cmd_overlay_remove, { OPT_INT("id", v.i, 0) } },
{ "osd-overlay", cmd_osd_overlay, { OPT_INT64("id", v.i64, 0), OPT_CHOICE("format", v.i, 0, ({"none", 0}, {"ass-events", 1})), OPT_STRING("data", v.s, 0), OPT_INT("res_x", v.i, 0, OPTDEF_INT(0)), OPT_INT("res_y", v.i, 0, OPTDEF_INT(720)), OPT_INT("z", v.i, 0, OPTDEF_INT(0)), }, .is_noisy = true, },
{ "write-watch-later-config", cmd_write_watch_later_config },
{ "hook-add", cmd_hook_add, { OPT_STRING("arg0", v.s, 0), OPT_INT("arg1", v.i, 0), OPT_INT("arg2", v.i, 0) }}, { "hook-ack", cmd_hook_ack, { OPT_INT("arg0", v.i, 0) }},
{ "mouse", cmd_mouse, { OPT_INT("x", v.i, 0), OPT_INT("y", v.i, 0), OPT_INT("button", v.i, 0, OPTDEF_INT(-1)), OPT_CHOICE("mode", v.i, MP_CMD_OPT_ARG, ({"single", 0}, {"double", 1})), }}, { "keybind", cmd_key_bind, { OPT_STRING("name", v.s, 0), OPT_STRING("cmd", v.s, 0) }}, { "keypress", cmd_key, { OPT_STRING("name", v.s, 0) }, .priv = &(const int){0}}, { "keydown", cmd_key, { OPT_STRING("name", v.s, 0) }, .priv = &(const int){MP_KEY_STATE_DOWN}}, { "keyup", cmd_key, { OPT_STRING("name", v.s, MP_CMD_OPT_ARG) }, .priv = &(const int){MP_KEY_STATE_UP}},
{ "apply-profile", cmd_apply_profile, {OPT_STRING("name", v.s, 0)} },
{ "load-script", cmd_load_script, {OPT_STRING("filename", v.s, 0)} },
{ "dump-cache", cmd_dump_cache, { OPT_TIME("start", v.d, 0, .min = MP_NOPTS_VALUE), OPT_TIME("end", v.d, 0, .min = MP_NOPTS_VALUE), OPT_STRING("filename", v.s, 0) }, .exec_async = true, .can_abort = true, },
{ "ab-loop-dump-cache", cmd_dump_cache_ab, { OPT_STRING("filename", v.s, 0) }, .exec_async = true, .can_abort = true, },
{ "ab-loop-align-cache", cmd_align_cache_ab },
{0}};
#undef OPT_BASE_STRUCT#undef ARG
void command_uninit(struct MPContext *mpctx){ struct command_ctx *ctx = mpctx->command_ctx;
assert(!ctx->cache_dump_cmd); // closing the demuxer must have aborted it
overlay_uninit(mpctx); ao_hotplug_destroy(ctx->hotplug);
m_option_free(&script_props_type, &ctx->script_props);
talloc_free(mpctx->command_ctx); mpctx->command_ctx = NULL;}
void command_init(struct MPContext *mpctx){ struct command_ctx *ctx = talloc(NULL, struct command_ctx); *ctx = (struct command_ctx){ .last_seek_pts = MP_NOPTS_VALUE, }; mpctx->command_ctx = ctx;
int num_base = MP_ARRAY_SIZE(mp_properties_base); int num_opts = m_config_get_co_count(mpctx->mconfig); ctx->properties = talloc_zero_array(ctx, struct m_property, num_base + num_opts + 1); memcpy(ctx->properties, mp_properties_base, sizeof(mp_properties_base));
int count = num_base; for (int n = 0; n < num_opts; n++) { struct m_config_option *co = m_config_get_co_index(mpctx->mconfig, n); assert(co->name[0]); if (co->opt->flags & M_OPT_NOPROP) continue;
struct m_property prop = { .name = co->name, .call = mp_property_generic_option, .is_option = true, };
if (co->opt->type == &m_option_type_alias) { prop.priv = co->opt->priv;
prop.call = co->opt->deprecation_message ? mp_property_deprecated_alias : mp_property_alias;
// Check whether this eventually arrives at a real option. If not, // it's some CLI special handling thing. For example, "nosound" is // mapped to "no-audio", which has CLI special-handling, and cannot // be set as property. struct m_config_option *co2 = co; while (co2 && co2->opt->type == &m_option_type_alias) { const char *alias = (const char *)co2->opt->priv; co2 = m_config_get_co_raw(mpctx->mconfig, bstr0(alias)); } if (!co2) continue; }
// The option might be covered by a manual property already. if (m_property_list_find(ctx->properties, prop.name)) continue;
ctx->properties[count++] = prop; }}
static void command_event(struct MPContext *mpctx, int event, void *arg){ struct command_ctx *ctx = mpctx->command_ctx;
if (event == MPV_EVENT_START_FILE) { ctx->last_seek_pts = MP_NOPTS_VALUE; ctx->marked_pts = MP_NOPTS_VALUE; }
if (event == MPV_EVENT_IDLE) ctx->is_idle = true; if (event == MPV_EVENT_START_FILE) ctx->is_idle = false; if (event == MPV_EVENT_END_FILE || event == MPV_EVENT_FILE_LOADED) { // Update chapters - does nothing if something else is visible. set_osd_bar_chapters(mpctx, OSD_BAR_SEEK); } if (event == MP_EVENT_WIN_STATE2) ctx->cached_window_scale = 0;}
void handle_command_updates(struct MPContext *mpctx){ struct command_ctx *ctx = mpctx->command_ctx;
// This is a bit messy: ao_hotplug wakes up the player, and then we have // to recheck the state. Then the client(s) will read the property. if (ctx->hotplug && ao_hotplug_check_update(ctx->hotplug)) mp_notify_property(mpctx, "audio-device-list");
// Depends on polling demuxer wakeup callback notifications. cache_dump_poll(mpctx);}
void mp_notify(struct MPContext *mpctx, int event, void *arg){ // The OSD can implicitly reference some properties. mpctx->osd_idle_update = true;
command_event(mpctx, event, arg);
mp_client_broadcast_event(mpctx, event, arg);}
static void update_priority(struct MPContext *mpctx){#if HAVE_WIN32_DESKTOP struct MPOpts *opts = mpctx->opts; if (opts->w32_priority > 0) SetPriorityClass(GetCurrentProcess(), opts->w32_priority);#endif}
void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, bool self_update){ struct MPContext *mpctx = ctx; struct MPOpts *opts = mpctx->opts; bool init = !co; void *opt_ptr = init ? NULL : co->data; // NULL on start
if (co) mp_notify_property(mpctx, co->name);
if (opt_ptr == &opts->pause) mp_notify(mpctx, opts->pause ? MPV_EVENT_PAUSE : MPV_EVENT_UNPAUSE, 0);
if (self_update) return;
if (flags & UPDATE_TERM) mp_update_logging(mpctx, false);
if (flags & UPDATE_OSD) { for (int n = 0; n < NUM_PTRACKS; n++) { struct track *track = mpctx->current_track[n][STREAM_SUB]; struct dec_sub *sub = track ? track->d_sub : NULL; if (sub) sub_update_opts(track->d_sub); } osd_changed(mpctx->osd); mp_wakeup_core(mpctx); }
if (flags & UPDATE_BUILTIN_SCRIPTS) mp_load_builtin_scripts(mpctx);
if (flags & UPDATE_IMGPAR) { struct track *track = mpctx->current_track[0][STREAM_VIDEO]; if (track && track->dec) { mp_decoder_wrapper_reset_params(track->dec); mp_force_video_refresh(mpctx); } }
if (flags & UPDATE_INPUT) mp_input_update_opts(mpctx->input);
if (init || opt_ptr == &opts->ipc_path || opt_ptr == &opts->input_file) { mp_uninit_ipc(mpctx->ipc_ctx); mpctx->ipc_ctx = mp_init_ipc(mpctx->clients, mpctx->global); }
if (flags & UPDATE_AUDIO) reload_audio_output(mpctx);
if (flags & UPDATE_PRIORITY) update_priority(mpctx);
if (flags & UPDATE_SCREENSAVER) update_screensaver_state(mpctx);
if (flags & UPDATE_VOL) audio_update_volume(mpctx);
if (flags & UPDATE_LAVFI_COMPLEX) update_lavfi_complex(mpctx);
if (flags & UPDATE_VO_RESIZE) { if (mpctx->video_out) vo_control(mpctx->video_out, VOCTRL_EXTERNAL_RESIZE, NULL); }
if (opt_ptr == &opts->playback_speed) { update_playback_speed(mpctx); mp_wakeup_core(mpctx); }
if (opt_ptr == &opts->play_dir) { if (mpctx->play_dir != opts->play_dir) { queue_seek(mpctx, MPSEEK_ABSOLUTE, get_current_time(mpctx), MPSEEK_EXACT, 0); } }
if (opt_ptr == &opts->edition_id) { struct demuxer *demuxer = mpctx->demuxer; if (mpctx->playback_initialized && demuxer && demuxer->num_editions > 0) { if (opts->edition_id != demuxer->edition) { if (!mpctx->stop_play) mpctx->stop_play = PT_CURRENT_ENTRY; mp_wakeup_core(mpctx); } } }
if (opt_ptr == &opts->pause) { if (mpctx->playback_initialized) { int val = opts->pause; opts->pause = !val; // temporary hack to force update set_pause_state(mpctx, val); } }
if (opt_ptr == &opts->audio_delay) { if (mpctx->ao_chain) { mpctx->delay += mpctx->opts->audio_delay - mpctx->ao_chain->delay; mpctx->ao_chain->delay = mpctx->opts->audio_delay; } mp_wakeup_core(mpctx); }
if (flags & UPDATE_HWDEC) { struct track *track = mpctx->current_track[0][STREAM_VIDEO]; struct mp_decoder_wrapper *dec = track ? track->dec : NULL; if (dec) { mp_decoder_wrapper_control(dec, VDCTRL_REINIT, NULL); double last_pts = mpctx->last_vo_pts; if (last_pts != MP_NOPTS_VALUE) queue_seek(mpctx, MPSEEK_ABSOLUTE, last_pts, MPSEEK_EXACT, 0); } }
if (opt_ptr == &opts->vo->window_scale) update_window_scale(mpctx);
if (opt_ptr == &opts->cursor_autohide_delay) mpctx->mouse_timer = 0;
if (flags & UPDATE_DVB_PROG) { if (!mpctx->stop_play) mpctx->stop_play = PT_CURRENT_ENTRY; }
if (opt_ptr == &opts->ab_loop[0] || opt_ptr == &opts->ab_loop[1]) { update_ab_loop_clip(mpctx); // Update if visible set_osd_bar_chapters(mpctx, OSD_BAR_SEEK); mp_wakeup_core(mpctx); }
if (opt_ptr == &opts->record_file) open_recorder(mpctx, false);
if (opt_ptr == &opts->vf_settings) set_filters(mpctx, STREAM_VIDEO, opts->vf_settings);
if (opt_ptr == &opts->af_settings) set_filters(mpctx, STREAM_AUDIO, opts->af_settings);
for (int order = 0; order < NUM_PTRACKS; order++) { for (int type = 0; type < STREAM_TYPE_COUNT; type++) { if (opt_ptr == &opts->stream_id[order][type] && mpctx->playback_initialized) { struct track *track = mp_track_by_tid(mpctx, type, opts->stream_id[order][type]); mp_switch_track_n(mpctx, order, type, track, FLAG_MARK_SELECTION); print_track_list(mpctx, "Track switched:"); mp_wakeup_core(mpctx); } } }
if (opt_ptr == &opts->vo->fullscreen && !opts->vo->fullscreen) mpctx->mouse_event_ts--; // Show mouse cursor
if (opt_ptr == &opts->vo->taskbar_progress) update_vo_playback_state(mpctx);}
void mp_notify_property(struct MPContext *mpctx, const char *property){ mp_client_property_change(mpctx, property);}