1
0

mp4.cpp 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is MPEG4IP.
  13. *
  14. * The Initial Developer of the Original Code is Cisco Systems Inc.
  15. * Portions created by Cisco Systems Inc. are
  16. * Copyright (C) Cisco Systems Inc. 2001 - 2005. All Rights Reserved.
  17. *
  18. * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
  19. * and was contributed by Ximpo Group Ltd.
  20. *
  21. * Portions created by Ximpo Group Ltd. are
  22. * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Dave Mackie [email protected]
  26. * Alix Marchandise-Franquet [email protected]
  27. * Ximpo Group Ltd. [email protected]
  28. * Bill May [email protected]
  29. */
  30. /*
  31. * MP4 library API functions
  32. *
  33. * These are wrapper functions that provide C linkage conventions
  34. * to the library, and catch any internal errors, ensuring that
  35. * a proper return value is given.
  36. */
  37. #include "mp4common.h"
  38. #define PRINT_ERROR(e) \
  39. VERBOSE_ERROR(((MP4File*)hFile)->GetVerbosity(), e->Print());
  40. /* file operations */
  41. // benski>
  42. extern "C" MP4FileHandle MP4ReadEx (const MP4_FILENAME_CHAR *fileName,
  43. void *user,
  44. struct Virtual_IO *virtual_IO,
  45. u_int32_t verbosity)
  46. {
  47. MP4File* pFile = NULL;
  48. try {
  49. pFile = new MP4File(verbosity);
  50. pFile->ReadEx(fileName, user, virtual_IO);
  51. return (MP4FileHandle)pFile;
  52. } catch (MP4Error* e) {
  53. VERBOSE_ERROR(verbosity, e->Print());
  54. delete e;
  55. delete pFile;
  56. return MP4_INVALID_FILE_HANDLE;
  57. }
  58. }
  59. extern "C" MP4FileHandle MP4Read(const MP4_FILENAME_CHAR *fileName, u_int32_t verbosity)
  60. {
  61. MP4File* pFile = NULL;
  62. try {
  63. pFile = new MP4File(verbosity);
  64. pFile->Read(fileName);
  65. return (MP4FileHandle)pFile;
  66. }
  67. catch (MP4Error* e) {
  68. VERBOSE_ERROR(verbosity, e->Print());
  69. delete e;
  70. delete pFile;
  71. return MP4_INVALID_FILE_HANDLE;
  72. }
  73. }
  74. extern "C" MP4FileHandle MP4Create (const MP4_FILENAME_CHAR *fileName,
  75. u_int32_t verbosity,
  76. u_int32_t flags)
  77. {
  78. return MP4CreateEx(fileName, verbosity, flags);
  79. }
  80. extern "C" MP4FileHandle MP4CreateEx (const MP4_FILENAME_CHAR *fileName,
  81. u_int32_t verbosity,
  82. u_int32_t flags,
  83. int add_ftyp,
  84. int add_iods,
  85. char* majorBrand,
  86. u_int32_t minorVersion,
  87. char** supportedBrands,
  88. u_int32_t supportedBrandsCount)
  89. {
  90. MP4File* pFile = NULL;
  91. try {
  92. pFile = new MP4File(verbosity);
  93. // LATER useExtensibleFormat, moov first, then mvex's
  94. pFile->Create(fileName, flags, add_ftyp, add_iods,
  95. majorBrand, minorVersion,
  96. supportedBrands, supportedBrandsCount);
  97. return (MP4FileHandle)pFile;
  98. }
  99. catch (MP4Error* e) {
  100. VERBOSE_ERROR(verbosity, e->Print());
  101. delete e;
  102. delete pFile;
  103. return MP4_INVALID_FILE_HANDLE;
  104. }
  105. }
  106. extern "C" MP4FileHandle MP4Modify(const MP4_FILENAME_CHAR *fileName,
  107. u_int32_t verbosity, u_int32_t flags)
  108. {
  109. MP4File* pFile = NULL;
  110. try {
  111. pFile = new MP4File(verbosity);
  112. // LATER useExtensibleFormat, moov first, then mvex's
  113. pFile->Modify(fileName);
  114. return (MP4FileHandle)pFile;
  115. }
  116. catch (MP4Error* e) {
  117. VERBOSE_ERROR(verbosity, e->Print());
  118. delete e;
  119. delete pFile;
  120. return MP4_INVALID_FILE_HANDLE;
  121. }
  122. }
  123. extern "C" bool MP4Optimize(const MP4_FILENAME_CHAR* existingFileName,
  124. const MP4_FILENAME_CHAR* newFileName,
  125. u_int32_t verbosity)
  126. {
  127. try {
  128. MP4File* pFile = new MP4File(verbosity);
  129. pFile->Optimize(existingFileName, newFileName);
  130. delete pFile;
  131. return true;
  132. }
  133. catch (MP4Error* e) {
  134. VERBOSE_ERROR(verbosity, e->Print());
  135. delete e;
  136. }
  137. return false;
  138. }
  139. extern "C" void MP4Close(MP4FileHandle hFile)
  140. {
  141. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  142. try {
  143. ((MP4File*)hFile)->Close();
  144. delete (MP4File*)hFile;
  145. return;
  146. }
  147. catch (MP4Error* e) {
  148. PRINT_ERROR(e);
  149. delete e;
  150. }
  151. }
  152. return ;
  153. }
  154. /* specific file properties */
  155. extern "C" u_int32_t MP4GetVerbosity(MP4FileHandle hFile)
  156. {
  157. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  158. try {
  159. return ((MP4File*)hFile)->GetVerbosity();
  160. }
  161. catch (MP4Error* e) {
  162. PRINT_ERROR(e);
  163. delete e;
  164. }
  165. }
  166. return 0;
  167. }
  168. extern "C" void MP4SetVerbosity(MP4FileHandle hFile, u_int32_t verbosity)
  169. {
  170. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  171. try {
  172. ((MP4File*)hFile)->SetVerbosity(verbosity);
  173. return;
  174. }
  175. catch (MP4Error* e) {
  176. PRINT_ERROR(e);
  177. delete e;
  178. }
  179. }
  180. return;
  181. }
  182. extern "C" MP4Duration MP4GetDuration(MP4FileHandle hFile)
  183. {
  184. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  185. try {
  186. return ((MP4File*)hFile)->GetDuration();
  187. }
  188. catch (MP4Error* e) {
  189. PRINT_ERROR(e);
  190. delete e;
  191. }
  192. }
  193. return MP4_INVALID_DURATION;
  194. }
  195. extern "C" u_int32_t MP4GetTimeScale(MP4FileHandle hFile)
  196. {
  197. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  198. try {
  199. return ((MP4File*)hFile)->GetTimeScale();
  200. }
  201. catch (MP4Error* e) {
  202. PRINT_ERROR(e);
  203. delete e;
  204. }
  205. }
  206. return 0;
  207. }
  208. extern "C" bool MP4SetTimeScale(MP4FileHandle hFile, u_int32_t value)
  209. {
  210. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  211. try {
  212. ((MP4File*)hFile)->SetTimeScale(value);
  213. return true;
  214. }
  215. catch (MP4Error* e) {
  216. PRINT_ERROR(e);
  217. delete e;
  218. }
  219. }
  220. return false;
  221. }
  222. extern "C" u_int8_t MP4GetODProfileLevel(MP4FileHandle hFile)
  223. {
  224. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  225. try {
  226. return ((MP4File*)hFile)->GetODProfileLevel();
  227. }
  228. catch (MP4Error* e) {
  229. PRINT_ERROR(e);
  230. delete e;
  231. }
  232. }
  233. return 0;
  234. }
  235. extern "C" bool MP4SetODProfileLevel(MP4FileHandle hFile, u_int8_t value)
  236. {
  237. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  238. try {
  239. ((MP4File*)hFile)->SetODProfileLevel(value);
  240. return true;
  241. }
  242. catch (MP4Error* e) {
  243. PRINT_ERROR(e);
  244. delete e;
  245. }
  246. }
  247. return false;
  248. }
  249. extern "C" u_int8_t MP4GetSceneProfileLevel(MP4FileHandle hFile)
  250. {
  251. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  252. try {
  253. return ((MP4File*)hFile)->GetSceneProfileLevel();
  254. }
  255. catch (MP4Error* e) {
  256. PRINT_ERROR(e);
  257. delete e;
  258. }
  259. }
  260. return 0;
  261. }
  262. extern "C" bool MP4SetSceneProfileLevel(MP4FileHandle hFile, u_int8_t value)
  263. {
  264. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  265. try {
  266. ((MP4File*)hFile)->SetSceneProfileLevel(value);
  267. return true;
  268. }
  269. catch (MP4Error* e) {
  270. PRINT_ERROR(e);
  271. delete e;
  272. }
  273. }
  274. return false;
  275. }
  276. extern "C" u_int8_t MP4GetVideoProfileLevel(MP4FileHandle hFile,
  277. MP4TrackId trackId)
  278. {
  279. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  280. try {
  281. return ((MP4File*)hFile)->GetVideoProfileLevel();
  282. }
  283. catch (MP4Error* e) {
  284. PRINT_ERROR(e);
  285. delete e;
  286. }
  287. if (MP4_IS_VALID_TRACK_ID(trackId)) {
  288. uint8_t *foo;
  289. uint32_t bufsize;
  290. uint8_t type;
  291. // for mpeg4 video tracks, try to look for the VOSH header,
  292. // which has this info.
  293. type = MP4GetTrackEsdsObjectTypeId(hFile, trackId);
  294. if (type == MP4_MPEG4_VIDEO_TYPE) {
  295. if (MP4GetTrackESConfiguration(hFile,
  296. trackId,
  297. &foo,
  298. &bufsize)) {
  299. uint8_t *ptr = foo;
  300. while (bufsize > 0) {
  301. if (htonl(*(uint32_t *)ptr) == 0x1b0) {
  302. uint8_t ret = ptr[4];
  303. free(foo);
  304. return ret;
  305. }
  306. ptr++;
  307. bufsize--;
  308. }
  309. free(foo);
  310. }
  311. }
  312. }
  313. }
  314. return 0;
  315. }
  316. extern "C" void MP4SetVideoProfileLevel(MP4FileHandle hFile, u_int8_t value)
  317. {
  318. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  319. try {
  320. ((MP4File*)hFile)->SetVideoProfileLevel(value);
  321. return ;
  322. }
  323. catch (MP4Error* e) {
  324. PRINT_ERROR(e);
  325. delete e;
  326. }
  327. }
  328. return ;
  329. }
  330. extern "C" u_int8_t MP4GetAudioProfileLevel(MP4FileHandle hFile)
  331. {
  332. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  333. try {
  334. return ((MP4File*)hFile)->GetAudioProfileLevel();
  335. }
  336. catch (MP4Error* e) {
  337. PRINT_ERROR(e);
  338. delete e;
  339. }
  340. }
  341. return 0;
  342. }
  343. extern "C" void MP4SetAudioProfileLevel(MP4FileHandle hFile, u_int8_t value)
  344. {
  345. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  346. try {
  347. ((MP4File*)hFile)->SetAudioProfileLevel(value);
  348. }
  349. catch (MP4Error* e) {
  350. PRINT_ERROR(e);
  351. delete e;
  352. }
  353. }
  354. }
  355. extern "C" u_int8_t MP4GetGraphicsProfileLevel(MP4FileHandle hFile)
  356. {
  357. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  358. try {
  359. return ((MP4File*)hFile)->GetGraphicsProfileLevel();
  360. }
  361. catch (MP4Error* e) {
  362. PRINT_ERROR(e);
  363. delete e;
  364. }
  365. }
  366. return 0;
  367. }
  368. extern "C" bool MP4SetGraphicsProfileLevel(MP4FileHandle hFile, u_int8_t value)
  369. {
  370. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  371. try {
  372. ((MP4File*)hFile)->SetGraphicsProfileLevel(value);
  373. return true;
  374. }
  375. catch (MP4Error* e) {
  376. PRINT_ERROR(e);
  377. delete e;
  378. }
  379. }
  380. return false;
  381. }
  382. /* generic file properties */
  383. extern "C" bool MP4HaveAtom (MP4FileHandle hFile, const char *atomName)
  384. {
  385. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  386. try {
  387. return ((MP4File *)hFile)->FindAtomMP4File(atomName) != NULL;
  388. } catch (MP4Error *e) {
  389. PRINT_ERROR(e);
  390. delete e;
  391. }
  392. }
  393. return false;
  394. }
  395. extern "C" bool MP4GetIntegerProperty(
  396. MP4FileHandle hFile, const char* propName, u_int64_t *retvalue)
  397. {
  398. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  399. try {
  400. *retvalue = ((MP4File*)hFile)->GetIntegerProperty(propName);
  401. return true;
  402. }
  403. catch (MP4Error* e) {
  404. PRINT_ERROR(e);
  405. delete e;
  406. }
  407. }
  408. return false;
  409. }
  410. extern "C" bool MP4GetFloatProperty(
  411. MP4FileHandle hFile, const char* propName, float *retvalue)
  412. {
  413. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  414. try {
  415. *retvalue = ((MP4File*)hFile)->GetFloatProperty(propName);
  416. return true;
  417. }
  418. catch (MP4Error* e) {
  419. PRINT_ERROR(e);
  420. delete e;
  421. }
  422. }
  423. return false;
  424. }
  425. extern "C" bool MP4GetStringProperty(
  426. MP4FileHandle hFile, const char* propName,
  427. const char **retvalue)
  428. {
  429. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  430. try {
  431. *retvalue = ((MP4File*)hFile)->GetStringProperty(propName);
  432. return true;
  433. }
  434. catch (MP4Error* e) {
  435. PRINT_ERROR(e);
  436. delete e;
  437. }
  438. }
  439. return false;
  440. }
  441. extern "C" bool MP4GetBytesProperty(
  442. MP4FileHandle hFile, const char* propName,
  443. u_int8_t** ppValue, u_int32_t* pValueSize)
  444. {
  445. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  446. try {
  447. ((MP4File*)hFile)->GetBytesProperty(propName, ppValue, pValueSize);
  448. return true;
  449. }
  450. catch (MP4Error* e) {
  451. PRINT_ERROR(e);
  452. delete e;
  453. }
  454. }
  455. *ppValue = NULL;
  456. *pValueSize = 0;
  457. return false;
  458. }
  459. extern "C" bool MP4SetIntegerProperty(
  460. MP4FileHandle hFile, const char* propName, int64_t value)
  461. {
  462. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  463. try {
  464. ((MP4File*)hFile)->SetIntegerProperty(propName, value);
  465. return true;
  466. }
  467. catch (MP4Error* e) {
  468. PRINT_ERROR(e);
  469. delete e;
  470. }
  471. }
  472. return false;
  473. }
  474. extern "C" bool MP4SetFloatProperty(
  475. MP4FileHandle hFile, const char* propName, float value)
  476. {
  477. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  478. try {
  479. ((MP4File*)hFile)->SetFloatProperty(propName, value);
  480. return true;
  481. }
  482. catch (MP4Error* e) {
  483. PRINT_ERROR(e);
  484. delete e;
  485. }
  486. }
  487. return false;
  488. }
  489. extern "C" bool MP4SetStringProperty(
  490. MP4FileHandle hFile, const char* propName, const char* value)
  491. {
  492. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  493. try {
  494. ((MP4File*)hFile)->SetStringProperty(propName, value);
  495. return true;
  496. }
  497. catch (MP4Error* e) {
  498. PRINT_ERROR(e);
  499. delete e;
  500. }
  501. }
  502. return false;
  503. }
  504. extern "C" bool MP4SetBytesProperty(
  505. MP4FileHandle hFile, const char* propName,
  506. const u_int8_t* pValue, u_int32_t valueSize)
  507. {
  508. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  509. try {
  510. ((MP4File*)hFile)->SetBytesProperty(propName, pValue, valueSize);
  511. return true;
  512. }
  513. catch (MP4Error* e) {
  514. PRINT_ERROR(e);
  515. delete e;
  516. }
  517. }
  518. return false;
  519. }
  520. /* track operations */
  521. extern "C" MP4TrackId MP4AddTrack(
  522. MP4FileHandle hFile, const char* type)
  523. {
  524. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  525. try {
  526. return ((MP4File*)hFile)->AddSystemsTrack(type);
  527. }
  528. catch (MP4Error* e) {
  529. PRINT_ERROR(e);
  530. delete e;
  531. }
  532. }
  533. return MP4_INVALID_TRACK_ID;
  534. }
  535. extern "C" MP4TrackId MP4AddSystemsTrack(
  536. MP4FileHandle hFile, const char* type)
  537. {
  538. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  539. try {
  540. return ((MP4File*)hFile)->AddSystemsTrack(type);
  541. }
  542. catch (MP4Error* e) {
  543. PRINT_ERROR(e);
  544. delete e;
  545. }
  546. }
  547. return MP4_INVALID_TRACK_ID;
  548. }
  549. extern "C" MP4TrackId MP4AddODTrack(MP4FileHandle hFile)
  550. {
  551. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  552. try {
  553. return ((MP4File*)hFile)->AddODTrack();
  554. }
  555. catch (MP4Error* e) {
  556. PRINT_ERROR(e);
  557. delete e;
  558. }
  559. }
  560. return MP4_INVALID_TRACK_ID;
  561. }
  562. extern "C" MP4TrackId MP4AddSceneTrack(MP4FileHandle hFile)
  563. {
  564. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  565. try {
  566. return ((MP4File*)hFile)->AddSceneTrack();
  567. }
  568. catch (MP4Error* e) {
  569. PRINT_ERROR(e);
  570. delete e;
  571. }
  572. }
  573. return MP4_INVALID_TRACK_ID;
  574. }
  575. extern "C" MP4TrackId MP4AddAudioTrack(
  576. MP4FileHandle hFile,
  577. u_int32_t timeScale,
  578. MP4Duration sampleDuration,
  579. u_int8_t audioType)
  580. {
  581. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  582. try {
  583. return ((MP4File*)hFile)->
  584. AddAudioTrack(timeScale, sampleDuration, audioType);
  585. }
  586. catch (MP4Error* e) {
  587. PRINT_ERROR(e);
  588. delete e;
  589. }
  590. }
  591. return MP4_INVALID_TRACK_ID;
  592. }
  593. //
  594. // API to initialize ismacryp properties to sensible defaults.
  595. // if the input pointer is null then an ismacryp params is malloc'd.
  596. // caller must see to it that it is properly disposed of.
  597. //
  598. extern "C" mp4v2_ismacrypParams *MP4DefaultISMACrypParams(mp4v2_ismacrypParams *ptr)
  599. {
  600. try
  601. {
  602. if (ptr == NULL) {
  603. ptr = (mp4v2_ismacrypParams *)MP4Malloc(sizeof(mp4v2_ismacrypParams));
  604. }
  605. memset(ptr, 0, sizeof(*ptr));
  606. return ptr;
  607. }
  608. catch (...) {
  609. return 0;
  610. }
  611. }
  612. extern "C" MP4TrackId MP4AddEncAudioTrack(MP4FileHandle hFile,
  613. u_int32_t timeScale,
  614. MP4Duration sampleDuration,
  615. mp4v2_ismacrypParams *icPp,
  616. u_int8_t audioType)
  617. {
  618. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  619. try {
  620. if (icPp == NULL) {
  621. return ((MP4File*)hFile)->
  622. AddEncAudioTrack(timeScale, sampleDuration, audioType,
  623. 0, 0,
  624. 0, 0,
  625. false, NULL, false);
  626. } else {
  627. return ((MP4File*)hFile)->
  628. AddEncAudioTrack(timeScale, sampleDuration, audioType,
  629. icPp->scheme_type, icPp->scheme_version,
  630. icPp->key_ind_len, icPp->iv_len,
  631. icPp->selective_enc, icPp->kms_uri, true);
  632. }
  633. } catch (MP4Error* e) {
  634. PRINT_ERROR(e);
  635. delete e;
  636. }
  637. }
  638. return MP4_INVALID_TRACK_ID;
  639. }
  640. extern "C" MP4TrackId MP4AddAmrAudioTrack(
  641. MP4FileHandle hFile,
  642. u_int32_t timeScale,
  643. u_int16_t modeSet,
  644. u_int8_t modeChangePeriod,
  645. u_int8_t framesPerSample,
  646. bool isAmrWB)
  647. {
  648. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  649. try {
  650. return ((MP4File*)hFile)->
  651. AddAmrAudioTrack(timeScale, modeSet, modeChangePeriod, framesPerSample, isAmrWB);
  652. }
  653. catch (MP4Error* e) {
  654. PRINT_ERROR(e);
  655. delete e;
  656. }
  657. }
  658. return MP4_INVALID_TRACK_ID;
  659. }
  660. extern "C" void MP4SetAmrVendor(
  661. MP4FileHandle hFile,
  662. MP4TrackId trackId,
  663. u_int32_t vendor)
  664. {
  665. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  666. try {
  667. ((MP4File*)hFile)->
  668. SetAmrVendor(trackId, vendor);
  669. }
  670. catch (MP4Error* e) {
  671. PRINT_ERROR(e);
  672. delete e;
  673. }
  674. }
  675. }
  676. extern "C" void MP4SetAmrDecoderVersion(
  677. MP4FileHandle hFile,
  678. MP4TrackId trackId,
  679. u_int8_t decoderVersion)
  680. {
  681. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  682. try {
  683. ((MP4File*)hFile)->
  684. SetAmrDecoderVersion(trackId, decoderVersion);
  685. }
  686. catch (MP4Error* e) {
  687. PRINT_ERROR(e);
  688. delete e;
  689. }
  690. }
  691. }
  692. extern "C" void MP4SetAmrModeSet(
  693. MP4FileHandle hFile,
  694. MP4TrackId trackId,
  695. u_int16_t modeSet)
  696. {
  697. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  698. try {
  699. ((MP4File*)hFile)->
  700. SetAmrModeSet(trackId, modeSet);
  701. }
  702. catch (MP4Error* e) {
  703. PRINT_ERROR(e);
  704. delete e;
  705. }
  706. }
  707. }
  708. extern "C" uint16_t MP4GetAmrModeSet(
  709. MP4FileHandle hFile,
  710. MP4TrackId trackId)
  711. {
  712. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  713. try {
  714. return ((MP4File*)hFile)->
  715. GetAmrModeSet(trackId);
  716. }
  717. catch (MP4Error* e) {
  718. PRINT_ERROR(e);
  719. delete e;
  720. }
  721. }
  722. return 0;
  723. }
  724. extern "C" MP4TrackId MP4AddHrefTrack (MP4FileHandle hFile,
  725. uint32_t timeScale,
  726. MP4Duration sampleDuration,
  727. const char *base_url)
  728. {
  729. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  730. try {
  731. MP4File *pFile = (MP4File *)hFile;
  732. return pFile->AddHrefTrack(timeScale,
  733. sampleDuration,
  734. base_url);
  735. }
  736. catch (MP4Error* e) {
  737. PRINT_ERROR(e);
  738. delete e;
  739. }
  740. }
  741. return MP4_INVALID_TRACK_ID;
  742. }
  743. extern "C" const char *MP4GetHrefTrackBaseUrl (MP4FileHandle hFile,
  744. MP4TrackId trackId)
  745. {
  746. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  747. try {
  748. return ((MP4File*)hFile)->GetTrackStringProperty(trackId,
  749. "mdia.minf.stbl.stsd.href.burl.base_url");
  750. }
  751. catch (MP4Error* e) {
  752. PRINT_ERROR(e);
  753. delete e;
  754. }
  755. }
  756. return NULL;
  757. }
  758. extern "C" MP4TrackId MP4AddVideoTrack(
  759. MP4FileHandle hFile,
  760. u_int32_t timeScale,
  761. MP4Duration sampleDuration,
  762. u_int16_t width,
  763. u_int16_t height,
  764. u_int8_t videoType)
  765. {
  766. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  767. try {
  768. MP4File *pFile = (MP4File *)hFile;
  769. return pFile->AddMP4VideoTrack(timeScale,
  770. sampleDuration,
  771. width,
  772. height,
  773. videoType);
  774. }
  775. catch (MP4Error* e) {
  776. PRINT_ERROR(e);
  777. delete e;
  778. }
  779. }
  780. return MP4_INVALID_TRACK_ID;
  781. }
  782. extern "C" MP4TrackId MP4AddEncVideoTrack(MP4FileHandle hFile,
  783. u_int32_t timeScale,
  784. MP4Duration sampleDuration,
  785. u_int16_t width,
  786. u_int16_t height,
  787. mp4v2_ismacrypParams *icPp,
  788. u_int8_t videoType,
  789. const char *oFormat)
  790. {
  791. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  792. try {
  793. // test for valid ismacrypt session descriptor
  794. if (icPp == NULL) {
  795. return MP4_INVALID_TRACK_ID;
  796. }
  797. MP4File *pFile = (MP4File *)hFile;
  798. return pFile->AddEncVideoTrack(timeScale,
  799. sampleDuration,
  800. width,
  801. height,
  802. videoType,
  803. icPp,
  804. oFormat);
  805. } catch (MP4Error* e) {
  806. PRINT_ERROR(e);
  807. delete e;
  808. }
  809. }
  810. return MP4_INVALID_TRACK_ID;
  811. }
  812. extern "C" MP4TrackId MP4AddH264VideoTrack(MP4FileHandle hFile,
  813. u_int32_t timeScale,
  814. MP4Duration sampleDuration,
  815. u_int16_t width,
  816. u_int16_t height,
  817. uint8_t AVCProfileIndication,
  818. uint8_t profile_compat,
  819. uint8_t AVCLevelIndication,
  820. uint8_t sampleLenFieldSizeMinusOne)
  821. {
  822. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  823. try {
  824. MP4File *pFile = (MP4File *)hFile;
  825. return pFile->AddH264VideoTrack(timeScale,
  826. sampleDuration,
  827. width,
  828. height,
  829. AVCProfileIndication,
  830. profile_compat,
  831. AVCLevelIndication,
  832. sampleLenFieldSizeMinusOne);
  833. }
  834. catch (MP4Error* e) {
  835. PRINT_ERROR(e);
  836. delete e;
  837. }
  838. }
  839. return MP4_INVALID_TRACK_ID;
  840. }
  841. extern "C" MP4TrackId MP4AddEncH264VideoTrack(
  842. MP4FileHandle hFile,
  843. u_int32_t timeScale,
  844. MP4Duration sampleDuration,
  845. u_int16_t width,
  846. u_int16_t height,
  847. MP4FileHandle srcFile,
  848. MP4TrackId srcTrackId,
  849. mp4v2_ismacrypParams *icPp
  850. )
  851. {
  852. MP4Atom *srcAtom;
  853. MP4File *pFile;
  854. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  855. try {
  856. pFile = (MP4File *)srcFile;
  857. srcAtom = pFile->FindTrackAtom(srcTrackId, "mdia.minf.stbl.stsd.avc1.avcC");
  858. if (srcAtom == NULL)
  859. return MP4_INVALID_TRACK_ID;
  860. pFile = (MP4File *)hFile;
  861. return pFile->AddEncH264VideoTrack(timeScale,
  862. sampleDuration,
  863. width,
  864. height,
  865. srcAtom,
  866. icPp);
  867. }
  868. catch (MP4Error* e) {
  869. PRINT_ERROR(e);
  870. delete e;
  871. }
  872. }
  873. return MP4_INVALID_TRACK_ID;
  874. }
  875. extern "C" void MP4AddH264SequenceParameterSet (MP4FileHandle hFile,
  876. MP4TrackId trackId,
  877. const uint8_t *pSequence,
  878. uint16_t sequenceLen)
  879. {
  880. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  881. try {
  882. MP4File *pFile = (MP4File *)hFile;
  883. pFile->AddH264SequenceParameterSet(trackId,
  884. pSequence,
  885. sequenceLen);
  886. return;
  887. }
  888. catch (MP4Error* e) {
  889. PRINT_ERROR(e);
  890. delete e;
  891. }
  892. }
  893. return;
  894. }
  895. extern "C" void MP4AddH264PictureParameterSet (MP4FileHandle hFile,
  896. MP4TrackId trackId,
  897. const uint8_t *pPict,
  898. uint16_t pictLen)
  899. {
  900. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  901. try {
  902. MP4File *pFile = (MP4File *)hFile;
  903. pFile->AddH264PictureParameterSet(trackId,
  904. pPict,
  905. pictLen);
  906. return;
  907. }
  908. catch (MP4Error* e) {
  909. PRINT_ERROR(e);
  910. delete e;
  911. }
  912. }
  913. return;
  914. }
  915. extern "C" MP4TrackId MP4AddH263VideoTrack(
  916. MP4FileHandle hFile,
  917. u_int32_t timeScale,
  918. MP4Duration sampleDuration,
  919. u_int16_t width,
  920. u_int16_t height,
  921. u_int8_t h263Level,
  922. u_int8_t h263Profile,
  923. u_int32_t avgBitrate,
  924. u_int32_t maxBitrate)
  925. {
  926. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  927. try {
  928. return ((MP4File*)hFile)->
  929. AddH263VideoTrack(timeScale, sampleDuration, width, height, h263Level, h263Profile, avgBitrate, maxBitrate);
  930. }
  931. catch (MP4Error* e) {
  932. PRINT_ERROR(e);
  933. delete e;
  934. }
  935. }
  936. return MP4_INVALID_TRACK_ID;
  937. }
  938. extern "C" void MP4SetH263Vendor(
  939. MP4FileHandle hFile,
  940. MP4TrackId trackId,
  941. u_int32_t vendor)
  942. {
  943. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  944. try {
  945. ((MP4File*)hFile)->
  946. SetH263Vendor(trackId, vendor);
  947. }
  948. catch (MP4Error* e) {
  949. PRINT_ERROR(e);
  950. delete e;
  951. }
  952. }
  953. }
  954. extern "C" void MP4SetH263DecoderVersion(
  955. MP4FileHandle hFile,
  956. MP4TrackId trackId,
  957. u_int8_t decoderVersion)
  958. {
  959. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  960. try {
  961. ((MP4File*)hFile)->
  962. SetH263DecoderVersion(trackId, decoderVersion);
  963. }
  964. catch (MP4Error* e) {
  965. PRINT_ERROR(e);
  966. delete e;
  967. }
  968. }
  969. }
  970. extern "C" void MP4SetH263Bitrates(
  971. MP4FileHandle hFile,
  972. MP4TrackId trackId,
  973. u_int32_t avgBitrate,
  974. u_int32_t maxBitrate)
  975. {
  976. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  977. try {
  978. ((MP4File*)hFile)->
  979. SetH263Bitrates(trackId, avgBitrate, maxBitrate);
  980. }
  981. catch (MP4Error* e) {
  982. PRINT_ERROR(e);
  983. delete e;
  984. }
  985. }
  986. }
  987. extern "C" MP4TrackId MP4AddHintTrack(
  988. MP4FileHandle hFile, MP4TrackId refTrackId)
  989. {
  990. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  991. try {
  992. return ((MP4File*)hFile)->AddHintTrack(refTrackId);
  993. }
  994. catch (MP4Error* e) {
  995. PRINT_ERROR(e);
  996. delete e;
  997. }
  998. }
  999. return MP4_INVALID_TRACK_ID;
  1000. }
  1001. extern "C" MP4TrackId MP4AddTextTrack(
  1002. MP4FileHandle hFile, MP4TrackId refTrackId)
  1003. {
  1004. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1005. try {
  1006. return ((MP4File*)hFile)->AddTextTrack(refTrackId);
  1007. }
  1008. catch (MP4Error* e) {
  1009. PRINT_ERROR(e);
  1010. delete e;
  1011. }
  1012. }
  1013. return MP4_INVALID_TRACK_ID;
  1014. }
  1015. extern "C" MP4TrackId MP4AddChapterTextTrack(MP4FileHandle hFile, MP4TrackId refTrackId, u_int32_t timescale)
  1016. {
  1017. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1018. try {
  1019. return ((MP4File*)hFile)->AddChapterTextTrack(refTrackId, timescale);
  1020. }
  1021. catch (MP4Error* e) {
  1022. PRINT_ERROR(e);
  1023. delete e;
  1024. }
  1025. }
  1026. return MP4_INVALID_TRACK_ID;
  1027. }
  1028. extern "C" void MP4AddQTChapter(
  1029. MP4FileHandle hFile,
  1030. MP4TrackId chapterTrackId,
  1031. MP4Duration chapterDuration,
  1032. u_int32_t chapterNr,
  1033. const char * chapterTitle)
  1034. {
  1035. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1036. try {
  1037. ((MP4File*)hFile)->AddChapter(chapterTrackId, chapterDuration, chapterNr, chapterTitle);
  1038. }
  1039. catch (MP4Error* e) {
  1040. PRINT_ERROR(e);
  1041. delete e;
  1042. }
  1043. }
  1044. }
  1045. extern "C" void MP4AddChapter(
  1046. MP4FileHandle hFile,
  1047. MP4Timestamp chapterStart,
  1048. const char * chapterTitle)
  1049. {
  1050. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1051. try {
  1052. ((MP4File*)hFile)->AddChapter(chapterStart, chapterTitle);
  1053. }
  1054. catch (MP4Error* e) {
  1055. PRINT_ERROR(e);
  1056. delete e;
  1057. }
  1058. }
  1059. }
  1060. extern "C" void MP4ConvertChapters(
  1061. MP4FileHandle hFile,
  1062. bool toQT)
  1063. {
  1064. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1065. try {
  1066. ((MP4File*)hFile)->ConvertChapters(toQT);
  1067. }
  1068. catch (MP4Error* e) {
  1069. PRINT_ERROR(e);
  1070. delete e;
  1071. }
  1072. }
  1073. }
  1074. extern "C" void MP4DeleteChapters(
  1075. MP4FileHandle hFile,
  1076. MP4TrackId chapterTrackId,
  1077. bool deleteQT)
  1078. {
  1079. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1080. try {
  1081. ((MP4File*)hFile)->DeleteChapters(chapterTrackId, deleteQT);
  1082. }
  1083. catch (MP4Error* e) {
  1084. PRINT_ERROR(e);
  1085. delete e;
  1086. }
  1087. }
  1088. }
  1089. extern "C" void MP4GetChaptersList(
  1090. MP4FileHandle hFile,
  1091. MP4Chapters_t ** chapterList,
  1092. u_int32_t * chapterCount,
  1093. bool getQT)
  1094. {
  1095. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1096. try {
  1097. ((MP4File*)hFile)->GetChaptersList(chapterList, chapterCount, getQT);
  1098. }
  1099. catch (MP4Error* e) {
  1100. PRINT_ERROR(e);
  1101. delete e;
  1102. }
  1103. }
  1104. }
  1105. extern "C" MP4TrackId MP4CloneTrack (MP4FileHandle srcFile,
  1106. MP4TrackId srcTrackId,
  1107. MP4FileHandle dstFile,
  1108. MP4TrackId dstHintTrackReferenceTrack)
  1109. {
  1110. MP4TrackId dstTrackId = MP4_INVALID_TRACK_ID;
  1111. if (dstFile == NULL) {
  1112. dstFile = srcFile;
  1113. }
  1114. const char* trackType =
  1115. MP4GetTrackType(srcFile, srcTrackId);
  1116. if (!trackType) {
  1117. return dstTrackId;
  1118. }
  1119. const char *media_data_name =
  1120. MP4GetTrackMediaDataName(srcFile, srcTrackId);
  1121. if (media_data_name == NULL) return dstTrackId;
  1122. if (MP4_IS_VIDEO_TRACK_TYPE(trackType)) {
  1123. if (ATOMID(media_data_name) == ATOMID("mp4v")) {
  1124. MP4SetVideoProfileLevel(dstFile,
  1125. MP4GetVideoProfileLevel(srcFile));
  1126. dstTrackId = MP4AddVideoTrack(
  1127. dstFile,
  1128. MP4GetTrackTimeScale(srcFile,
  1129. srcTrackId),
  1130. MP4GetTrackFixedSampleDuration(srcFile,
  1131. srcTrackId),
  1132. MP4GetTrackVideoWidth(srcFile,
  1133. srcTrackId),
  1134. MP4GetTrackVideoHeight(srcFile,
  1135. srcTrackId),
  1136. MP4GetTrackEsdsObjectTypeId(srcFile,
  1137. srcTrackId));
  1138. } else if (ATOMID(media_data_name) == ATOMID("avc1")) {
  1139. uint8_t AVCProfileIndication;
  1140. uint8_t profile_compat;
  1141. uint8_t AVCLevelIndication;
  1142. uint32_t sampleLenFieldSizeMinusOne;
  1143. uint64_t temp;
  1144. if (MP4GetTrackH264ProfileLevel(srcFile, srcTrackId,
  1145. &AVCProfileIndication,
  1146. &AVCLevelIndication) == false) {
  1147. return dstTrackId;
  1148. }
  1149. if (MP4GetTrackH264LengthSize(srcFile, srcTrackId,
  1150. &sampleLenFieldSizeMinusOne) == false) {
  1151. return dstTrackId;
  1152. }
  1153. sampleLenFieldSizeMinusOne--;
  1154. if (MP4GetTrackIntegerProperty(srcFile, srcTrackId,
  1155. "mdia.minf.stbl.stsd.*[0].avcC.profile_compatibility",
  1156. &temp) == false) return dstTrackId;
  1157. profile_compat = temp & 0xff;
  1158. dstTrackId = MP4AddH264VideoTrack(dstFile,
  1159. MP4GetTrackTimeScale(srcFile,
  1160. srcTrackId),
  1161. MP4GetTrackFixedSampleDuration(srcFile,
  1162. srcTrackId),
  1163. MP4GetTrackVideoWidth(srcFile,
  1164. srcTrackId),
  1165. MP4GetTrackVideoHeight(srcFile,
  1166. srcTrackId),
  1167. AVCProfileIndication,
  1168. profile_compat,
  1169. AVCLevelIndication,
  1170. sampleLenFieldSizeMinusOne);
  1171. uint8_t **seqheader, **pictheader;
  1172. uint32_t *pictheadersize, *seqheadersize;
  1173. uint32_t ix;
  1174. MP4GetTrackH264SeqPictHeaders(srcFile, srcTrackId,
  1175. &seqheader, &seqheadersize,
  1176. &pictheader, &pictheadersize);
  1177. for (ix = 0; seqheadersize[ix] != 0; ix++) {
  1178. MP4AddH264SequenceParameterSet(dstFile, dstTrackId,
  1179. seqheader[ix], seqheadersize[ix]);
  1180. free(seqheader[ix]);
  1181. }
  1182. free(seqheader);
  1183. free(seqheadersize);
  1184. for (ix = 0; pictheadersize[ix] != 0; ix++) {
  1185. MP4AddH264PictureParameterSet(dstFile, dstTrackId,
  1186. pictheader[ix], pictheadersize[ix]);
  1187. free(pictheader[ix]);
  1188. }
  1189. free(pictheader);
  1190. free(pictheadersize);
  1191. } else
  1192. return dstTrackId;
  1193. } else if (MP4_IS_AUDIO_TRACK_TYPE(trackType)) {
  1194. if (ATOMID(media_data_name) != ATOMID("mp4a")) return dstTrackId;
  1195. MP4SetAudioProfileLevel(dstFile,
  1196. MP4GetAudioProfileLevel(srcFile));
  1197. dstTrackId = MP4AddAudioTrack(
  1198. dstFile,
  1199. MP4GetTrackTimeScale(srcFile, srcTrackId),
  1200. MP4GetTrackFixedSampleDuration(srcFile, srcTrackId),
  1201. MP4GetTrackEsdsObjectTypeId(srcFile, srcTrackId));
  1202. } else if (MP4_IS_OD_TRACK_TYPE(trackType)) {
  1203. dstTrackId = MP4AddODTrack(dstFile);
  1204. } else if (MP4_IS_SCENE_TRACK_TYPE(trackType)) {
  1205. dstTrackId = MP4AddSceneTrack(dstFile);
  1206. } else if (MP4_IS_HINT_TRACK_TYPE(trackType)) {
  1207. if (dstHintTrackReferenceTrack == MP4_INVALID_TRACK_ID) {
  1208. dstTrackId = MP4_INVALID_TRACK_ID;
  1209. } else {
  1210. dstTrackId = MP4AddHintTrack(
  1211. dstFile,
  1212. dstHintTrackReferenceTrack);
  1213. }
  1214. } else if (MP4_IS_SYSTEMS_TRACK_TYPE(trackType)) {
  1215. dstTrackId = MP4AddSystemsTrack(dstFile, trackType);
  1216. } else {
  1217. dstTrackId = MP4AddTrack(dstFile, trackType);
  1218. }
  1219. if (dstTrackId == MP4_INVALID_TRACK_ID) {
  1220. return dstTrackId;
  1221. }
  1222. MP4SetTrackTimeScale(
  1223. dstFile,
  1224. dstTrackId,
  1225. MP4GetTrackTimeScale(srcFile, srcTrackId));
  1226. if (MP4_IS_AUDIO_TRACK_TYPE(trackType)
  1227. || MP4_IS_VIDEO_TRACK_TYPE(trackType)) {
  1228. // copy track ES configuration
  1229. u_int8_t* pConfig = NULL;
  1230. u_int32_t configSize = 0;
  1231. if (MP4GetTrackESConfiguration(
  1232. srcFile,
  1233. srcTrackId,
  1234. &pConfig,
  1235. &configSize) &&
  1236. pConfig != NULL && configSize != 0) {
  1237. if (!MP4SetTrackESConfiguration(
  1238. dstFile,
  1239. dstTrackId,
  1240. pConfig,
  1241. configSize)) {
  1242. free(pConfig);
  1243. MP4DeleteTrack(dstFile, dstTrackId);
  1244. return MP4_INVALID_TRACK_ID;
  1245. }
  1246. free(pConfig);
  1247. }
  1248. }
  1249. if (MP4_IS_HINT_TRACK_TYPE(trackType)) {
  1250. // probably not exactly what is wanted
  1251. // but caller can adjust later to fit their desires
  1252. char* payloadName = NULL;
  1253. char *encodingParms = NULL;
  1254. u_int8_t payloadNumber;
  1255. u_int16_t maxPayloadSize;
  1256. if (MP4GetHintTrackRtpPayload(
  1257. srcFile,
  1258. srcTrackId,
  1259. &payloadName,
  1260. &payloadNumber,
  1261. &maxPayloadSize,
  1262. &encodingParms)) {
  1263. if (MP4SetHintTrackRtpPayload(
  1264. dstFile,
  1265. dstTrackId,
  1266. payloadName,
  1267. &payloadNumber,
  1268. maxPayloadSize,
  1269. encodingParms) == false) {
  1270. MP4DeleteTrack(dstFile, dstTrackId);
  1271. return MP4_INVALID_TRACK_ID;
  1272. }
  1273. }
  1274. #if 0
  1275. MP4SetHintTrackSdp(
  1276. dstFile,
  1277. dstTrackId,
  1278. MP4GetHintTrackSdp(srcFile, srcTrackId));
  1279. #endif
  1280. }
  1281. return dstTrackId;
  1282. }
  1283. // Given a track, make an encrypted clone of it in the dest. file
  1284. extern "C" MP4TrackId MP4EncAndCloneTrack(MP4FileHandle srcFile,
  1285. MP4TrackId srcTrackId,
  1286. mp4v2_ismacrypParams *icPp,
  1287. MP4FileHandle dstFile,
  1288. MP4TrackId dstHintTrackReferenceTrack
  1289. )
  1290. {
  1291. const char *oFormat;
  1292. MP4TrackId dstTrackId = MP4_INVALID_TRACK_ID;
  1293. if (dstFile == NULL) {
  1294. dstFile = srcFile;
  1295. }
  1296. const char* trackType = MP4GetTrackType(srcFile, srcTrackId);
  1297. if (!trackType) {
  1298. return dstTrackId;
  1299. }
  1300. if (MP4_IS_VIDEO_TRACK_TYPE(trackType)) {
  1301. // test source file format for avc1
  1302. oFormat = MP4GetTrackMediaDataName(srcFile, srcTrackId);
  1303. if (!strcasecmp(oFormat, "avc1"))
  1304. {
  1305. dstTrackId = MP4AddEncH264VideoTrack(dstFile,
  1306. MP4GetTrackTimeScale(srcFile, srcTrackId),
  1307. MP4GetTrackFixedSampleDuration(srcFile, srcTrackId),
  1308. MP4GetTrackVideoWidth(srcFile, srcTrackId),
  1309. MP4GetTrackVideoHeight(srcFile, srcTrackId),
  1310. srcFile,
  1311. srcTrackId,
  1312. icPp
  1313. );
  1314. }
  1315. else
  1316. {
  1317. MP4SetVideoProfileLevel(dstFile, MP4GetVideoProfileLevel(srcFile));
  1318. dstTrackId = MP4AddEncVideoTrack(dstFile,
  1319. MP4GetTrackTimeScale(srcFile, srcTrackId),
  1320. MP4GetTrackFixedSampleDuration(srcFile, srcTrackId),
  1321. MP4GetTrackVideoWidth(srcFile, srcTrackId),
  1322. MP4GetTrackVideoHeight(srcFile, srcTrackId),
  1323. icPp,
  1324. MP4GetTrackEsdsObjectTypeId(srcFile, srcTrackId),
  1325. oFormat
  1326. );
  1327. }
  1328. } else if (MP4_IS_AUDIO_TRACK_TYPE(trackType)) {
  1329. MP4SetAudioProfileLevel(dstFile, MP4GetAudioProfileLevel(srcFile));
  1330. dstTrackId = MP4AddEncAudioTrack(dstFile,
  1331. MP4GetTrackTimeScale(srcFile, srcTrackId),
  1332. MP4GetTrackFixedSampleDuration(srcFile,
  1333. srcTrackId),
  1334. icPp,
  1335. MP4GetTrackEsdsObjectTypeId(srcFile,
  1336. srcTrackId)
  1337. );
  1338. } else if (MP4_IS_OD_TRACK_TYPE(trackType)) {
  1339. dstTrackId = MP4AddODTrack(dstFile);
  1340. } else if (MP4_IS_SCENE_TRACK_TYPE(trackType)) {
  1341. dstTrackId = MP4AddSceneTrack(dstFile);
  1342. } else if (MP4_IS_HINT_TRACK_TYPE(trackType)) {
  1343. if (dstHintTrackReferenceTrack == MP4_INVALID_TRACK_ID) {
  1344. dstTrackId = MP4_INVALID_TRACK_ID;
  1345. } else {
  1346. dstTrackId = MP4AddHintTrack(dstFile,
  1347. MP4GetHintTrackReferenceTrackId(srcFile,
  1348. srcTrackId));
  1349. }
  1350. } else if (MP4_IS_SYSTEMS_TRACK_TYPE(trackType)) {
  1351. dstTrackId = MP4AddSystemsTrack(dstFile, trackType);
  1352. } else {
  1353. dstTrackId = MP4AddTrack(dstFile, trackType);
  1354. }
  1355. if (dstTrackId == MP4_INVALID_TRACK_ID) {
  1356. return dstTrackId;
  1357. }
  1358. MP4SetTrackTimeScale(dstFile,
  1359. dstTrackId,
  1360. MP4GetTrackTimeScale(srcFile, srcTrackId));
  1361. if (MP4_IS_AUDIO_TRACK_TYPE(trackType)
  1362. || MP4_IS_VIDEO_TRACK_TYPE(trackType)) {
  1363. // copy track ES configuration
  1364. u_int8_t* pConfig = NULL;
  1365. u_int32_t configSize = 0;
  1366. if (MP4GetTrackESConfiguration(srcFile, srcTrackId,
  1367. &pConfig, &configSize)) {
  1368. if (pConfig != NULL) {
  1369. MP4SetTrackESConfiguration(dstFile, dstTrackId,
  1370. pConfig, configSize);
  1371. }
  1372. }
  1373. if (pConfig != NULL)
  1374. free(pConfig);
  1375. }
  1376. // Bill's change to MP4CloneTrack
  1377. if (MP4_IS_HINT_TRACK_TYPE(trackType)) {
  1378. // probably not exactly what is wanted
  1379. // but caller can adjust later to fit their desires
  1380. char* payloadName = NULL;
  1381. char *encodingParms = NULL;
  1382. u_int8_t payloadNumber;
  1383. u_int16_t maxPayloadSize;
  1384. if (MP4GetHintTrackRtpPayload(
  1385. srcFile,
  1386. srcTrackId,
  1387. &payloadName,
  1388. &payloadNumber,
  1389. &maxPayloadSize,
  1390. &encodingParms)) {
  1391. (void)MP4SetHintTrackRtpPayload(
  1392. dstFile,
  1393. dstTrackId,
  1394. payloadName,
  1395. &payloadNumber,
  1396. maxPayloadSize,
  1397. encodingParms);
  1398. }
  1399. #if 0
  1400. MP4SetHintTrackSdp(
  1401. dstFile,
  1402. dstTrackId,
  1403. MP4GetHintTrackSdp(srcFile, srcTrackId));
  1404. #endif
  1405. }
  1406. return dstTrackId;
  1407. }
  1408. extern "C" MP4TrackId MP4CopyTrack(MP4FileHandle srcFile,
  1409. MP4TrackId srcTrackId,
  1410. MP4FileHandle dstFile,
  1411. bool applyEdits,
  1412. MP4TrackId dstHintTrackReferenceTrack)
  1413. {
  1414. bool copySamples = true; // LATER allow false => reference samples
  1415. MP4TrackId dstTrackId =
  1416. MP4CloneTrack(srcFile, srcTrackId, dstFile, dstHintTrackReferenceTrack);
  1417. if (dstTrackId == MP4_INVALID_TRACK_ID) {
  1418. return dstTrackId;
  1419. }
  1420. bool viaEdits =
  1421. applyEdits && MP4GetTrackNumberOfEdits(srcFile, srcTrackId);
  1422. MP4SampleId sampleId = 0;
  1423. MP4SampleId numSamples =
  1424. MP4GetTrackNumberOfSamples(srcFile, srcTrackId);
  1425. MP4Timestamp when = 0;
  1426. MP4Duration editsDuration =
  1427. MP4GetTrackEditTotalDuration(srcFile, srcTrackId);
  1428. while (true) {
  1429. MP4Duration sampleDuration = MP4_INVALID_DURATION;
  1430. if (viaEdits) {
  1431. sampleId = MP4GetSampleIdFromEditTime(
  1432. srcFile,
  1433. srcTrackId,
  1434. when,
  1435. NULL,
  1436. &sampleDuration);
  1437. // in theory, this shouldn't happen
  1438. if (sampleId == MP4_INVALID_SAMPLE_ID) {
  1439. MP4DeleteTrack(dstFile, dstTrackId);
  1440. return MP4_INVALID_TRACK_ID;
  1441. }
  1442. when += sampleDuration;
  1443. if (when >= editsDuration) {
  1444. break;
  1445. }
  1446. } else {
  1447. sampleId++;
  1448. if (sampleId > numSamples) {
  1449. break;
  1450. }
  1451. }
  1452. bool rc = false;
  1453. if (copySamples) {
  1454. rc = MP4CopySample(
  1455. srcFile,
  1456. srcTrackId,
  1457. sampleId,
  1458. dstFile,
  1459. dstTrackId,
  1460. sampleDuration);
  1461. } else {
  1462. rc = MP4ReferenceSample(
  1463. srcFile,
  1464. srcTrackId,
  1465. sampleId,
  1466. dstFile,
  1467. dstTrackId,
  1468. sampleDuration);
  1469. }
  1470. if (!rc) {
  1471. MP4DeleteTrack(dstFile, dstTrackId);
  1472. return MP4_INVALID_TRACK_ID;
  1473. }
  1474. }
  1475. return dstTrackId;
  1476. }
  1477. // Given a source track in a source file, make an encrypted copy of
  1478. // the track in the destination file, including sample encryption
  1479. extern "C" MP4TrackId MP4EncAndCopyTrack(MP4FileHandle srcFile,
  1480. MP4TrackId srcTrackId,
  1481. mp4v2_ismacrypParams *icPp,
  1482. encryptFunc_t encfcnp,
  1483. u_int32_t encfcnparam1,
  1484. MP4FileHandle dstFile,
  1485. bool applyEdits,
  1486. MP4TrackId dstHintTrackReferenceTrack
  1487. )
  1488. {
  1489. bool copySamples = true; // LATER allow false => reference samples
  1490. MP4TrackId dstTrackId =
  1491. MP4EncAndCloneTrack(srcFile, srcTrackId,
  1492. icPp,
  1493. dstFile, dstHintTrackReferenceTrack);
  1494. if (dstTrackId == MP4_INVALID_TRACK_ID) {
  1495. return dstTrackId;
  1496. }
  1497. bool viaEdits =
  1498. applyEdits && MP4GetTrackNumberOfEdits(srcFile, srcTrackId);
  1499. MP4SampleId sampleId = 0;
  1500. MP4SampleId numSamples =
  1501. MP4GetTrackNumberOfSamples(srcFile, srcTrackId);
  1502. MP4Timestamp when = 0;
  1503. MP4Duration editsDuration =
  1504. MP4GetTrackEditTotalDuration(srcFile, srcTrackId);
  1505. while (true) {
  1506. MP4Duration sampleDuration = MP4_INVALID_DURATION;
  1507. if (viaEdits) {
  1508. sampleId = MP4GetSampleIdFromEditTime(srcFile,
  1509. srcTrackId,
  1510. when,
  1511. NULL,
  1512. &sampleDuration);
  1513. // in theory, this shouldn't happen
  1514. if (sampleId == MP4_INVALID_SAMPLE_ID) {
  1515. MP4DeleteTrack(dstFile, dstTrackId);
  1516. return MP4_INVALID_TRACK_ID;
  1517. }
  1518. when += sampleDuration;
  1519. if (when >= editsDuration) {
  1520. break;
  1521. }
  1522. } else {
  1523. sampleId++;
  1524. if (sampleId > numSamples) {
  1525. break;
  1526. }
  1527. }
  1528. bool rc = false;
  1529. if (copySamples) {
  1530. // encrypt and copy
  1531. rc = MP4EncAndCopySample(srcFile,
  1532. srcTrackId,
  1533. sampleId,
  1534. encfcnp,
  1535. encfcnparam1,
  1536. dstFile,
  1537. dstTrackId,
  1538. sampleDuration);
  1539. } else {
  1540. // not sure what these are - encrypt?
  1541. rc = MP4ReferenceSample(srcFile,
  1542. srcTrackId,
  1543. sampleId,
  1544. dstFile,
  1545. dstTrackId,
  1546. sampleDuration);
  1547. }
  1548. if (!rc) {
  1549. MP4DeleteTrack(dstFile, dstTrackId);
  1550. return MP4_INVALID_TRACK_ID;
  1551. }
  1552. }
  1553. return dstTrackId;
  1554. }
  1555. extern "C" void MP4DeleteTrack(
  1556. MP4FileHandle hFile,
  1557. MP4TrackId trackId)
  1558. {
  1559. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1560. try {
  1561. ((MP4File*)hFile)->DeleteTrack(trackId);
  1562. return ;
  1563. }
  1564. catch (MP4Error* e) {
  1565. PRINT_ERROR(e);
  1566. delete e;
  1567. }
  1568. }
  1569. return;
  1570. }
  1571. extern "C" u_int32_t MP4GetNumberOfTracks(
  1572. MP4FileHandle hFile,
  1573. const char* type,
  1574. u_int8_t subType)
  1575. {
  1576. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1577. try {
  1578. return ((MP4File*)hFile)->GetNumberOfTracks(type, subType);
  1579. }
  1580. catch (MP4Error* e) {
  1581. PRINT_ERROR(e);
  1582. delete e;
  1583. }
  1584. }
  1585. return 0;
  1586. }
  1587. extern "C" MP4TrackId MP4FindTrackId(
  1588. MP4FileHandle hFile,
  1589. u_int16_t index,
  1590. const char* type,
  1591. u_int8_t subType)
  1592. {
  1593. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1594. try {
  1595. return ((MP4File*)hFile)->FindTrackId(index, type, subType);
  1596. }
  1597. catch (MP4Error* e) {
  1598. PRINT_ERROR(e);
  1599. delete e;
  1600. }
  1601. }
  1602. return MP4_INVALID_TRACK_ID;
  1603. }
  1604. extern "C" u_int16_t MP4FindTrackIndex(
  1605. MP4FileHandle hFile, MP4TrackId trackId)
  1606. {
  1607. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1608. try {
  1609. return ((MP4File*)hFile)->FindTrackIndex(trackId);
  1610. }
  1611. catch (MP4Error* e) {
  1612. PRINT_ERROR(e);
  1613. delete e;
  1614. }
  1615. }
  1616. return (u_int16_t)-1;
  1617. }
  1618. /* specific track properties */
  1619. extern "C" const char* MP4GetTrackType(
  1620. MP4FileHandle hFile, MP4TrackId trackId)
  1621. {
  1622. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1623. try {
  1624. return ((MP4File*)hFile)->GetTrackType(trackId);
  1625. }
  1626. catch (MP4Error* e) {
  1627. PRINT_ERROR(e);
  1628. delete e;
  1629. }
  1630. }
  1631. return NULL;
  1632. }
  1633. extern "C" const char* MP4GetTrackMediaDataName(
  1634. MP4FileHandle hFile, MP4TrackId trackId)
  1635. {
  1636. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1637. try {
  1638. return ((MP4File*)hFile)->GetTrackMediaDataName(trackId);
  1639. }
  1640. catch (MP4Error* e) {
  1641. PRINT_ERROR(e);
  1642. delete e;
  1643. }
  1644. }
  1645. return NULL;
  1646. }
  1647. extern "C" bool MP4GetTrackMediaDataOriginalFormat(
  1648. MP4FileHandle hFile, MP4TrackId trackId, char *originalFormat,
  1649. u_int32_t buflen)
  1650. {
  1651. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1652. try {
  1653. return ((MP4File*)hFile)->GetTrackMediaDataOriginalFormat(trackId,
  1654. originalFormat, buflen);
  1655. }
  1656. catch (MP4Error* e) {
  1657. PRINT_ERROR(e);
  1658. delete e;
  1659. }
  1660. }
  1661. return false;
  1662. }
  1663. extern "C" MP4Duration MP4GetTrackDuration(
  1664. MP4FileHandle hFile, MP4TrackId trackId)
  1665. {
  1666. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1667. try {
  1668. return ((MP4File*)hFile)->GetTrackDuration(trackId);
  1669. }
  1670. catch (MP4Error* e) {
  1671. PRINT_ERROR(e);
  1672. delete e;
  1673. }
  1674. }
  1675. return MP4_INVALID_DURATION;
  1676. }
  1677. extern "C" u_int32_t MP4GetTrackTimeScale(
  1678. MP4FileHandle hFile, MP4TrackId trackId)
  1679. {
  1680. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1681. try {
  1682. return ((MP4File*)hFile)->GetTrackTimeScale(trackId);
  1683. }
  1684. catch (MP4Error* e) {
  1685. PRINT_ERROR(e);
  1686. delete e;
  1687. }
  1688. }
  1689. return 0;
  1690. }
  1691. extern "C" void MP4SetTrackTimeScale(
  1692. MP4FileHandle hFile, MP4TrackId trackId, u_int32_t value)
  1693. {
  1694. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1695. try {
  1696. ((MP4File*)hFile)->SetTrackTimeScale(trackId, value);
  1697. return;
  1698. }
  1699. catch (MP4Error* e) {
  1700. PRINT_ERROR(e);
  1701. delete e;
  1702. }
  1703. }
  1704. return;
  1705. }
  1706. extern "C" u_int8_t MP4GetTrackAudioMpeg4Type(
  1707. MP4FileHandle hFile, MP4TrackId trackId)
  1708. {
  1709. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1710. try {
  1711. return ((MP4File*)hFile)->GetTrackAudioMpeg4Type(trackId);
  1712. }
  1713. catch (MP4Error* e) {
  1714. PRINT_ERROR(e);
  1715. delete e;
  1716. }
  1717. }
  1718. return MP4_MPEG4_INVALID_AUDIO_TYPE;
  1719. }
  1720. // Replacement to MP4GetTrackVideoType and MP4GetTrackAudioType
  1721. // Basically does the same thing but with a more self-explanatory name
  1722. extern "C" u_int8_t MP4GetTrackEsdsObjectTypeId(
  1723. MP4FileHandle hFile, MP4TrackId trackId)
  1724. {
  1725. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1726. try {
  1727. return ((MP4File*)hFile)->GetTrackEsdsObjectTypeId(trackId);
  1728. }
  1729. catch (MP4Error* e) {
  1730. PRINT_ERROR(e);
  1731. delete e;
  1732. }
  1733. }
  1734. return MP4_INVALID_AUDIO_TYPE;
  1735. }
  1736. extern "C" MP4Duration MP4GetTrackFixedSampleDuration(
  1737. MP4FileHandle hFile, MP4TrackId trackId)
  1738. {
  1739. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1740. try {
  1741. return ((MP4File*)hFile)->GetTrackFixedSampleDuration(trackId);
  1742. }
  1743. catch (MP4Error* e) {
  1744. PRINT_ERROR(e);
  1745. delete e;
  1746. }
  1747. }
  1748. return MP4_INVALID_DURATION;
  1749. }
  1750. extern "C" u_int32_t MP4GetTrackBitRate(
  1751. MP4FileHandle hFile, MP4TrackId trackId)
  1752. {
  1753. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1754. uint32_t br = 0;
  1755. MP4File *pFile = (MP4File *)hFile;
  1756. try {
  1757. br = pFile->GetTrackIntegerProperty(trackId,
  1758. "mdia.minf.stbl.stsd.*.esds.decConfigDescr.avgBitrate");
  1759. if (br > 16000)
  1760. return br;
  1761. }
  1762. catch (MP4Error* e) {
  1763. PRINT_ERROR(e);
  1764. delete e;
  1765. }
  1766. // if we're here, we can't get the bitrate from above -
  1767. // lets calculate it
  1768. try {
  1769. MP4Duration trackDur;
  1770. trackDur = MP4GetTrackDuration(hFile, trackId);
  1771. uint64_t msDuration =
  1772. pFile->ConvertFromTrackDuration(trackId, trackDur,
  1773. MP4_MSECS_TIME_SCALE);
  1774. if (msDuration == 0) return 0;
  1775. MP4Track *pTrack = pFile->GetTrack(trackId);
  1776. double bytes = pTrack->GetTotalOfSampleSizes();
  1777. //bytes *= TO_U64(8 * 1000);
  1778. //bytes /= msDuration;
  1779. //return (uint32_t)bytes;
  1780. // divide first !!!
  1781. bytes /= (double)msDuration;
  1782. bytes *= TO_U64(8 * 1000);
  1783. return (uint32_t)bytes;
  1784. }
  1785. catch (MP4Error* e) {
  1786. PRINT_ERROR(e);
  1787. delete e;
  1788. }
  1789. }
  1790. return 0;
  1791. }
  1792. extern "C" bool MP4GetTrackESConfiguration(
  1793. MP4FileHandle hFile, MP4TrackId trackId,
  1794. u_int8_t** ppConfig, u_int32_t* pConfigSize)
  1795. {
  1796. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1797. try {
  1798. ((MP4File*)hFile)->GetTrackESConfiguration(
  1799. trackId, ppConfig, pConfigSize);
  1800. return true;
  1801. }
  1802. catch (MP4Error* e) {
  1803. PRINT_ERROR(e);
  1804. delete e;
  1805. }
  1806. }
  1807. *ppConfig = NULL;
  1808. *pConfigSize = 0;
  1809. return false;
  1810. }
  1811. extern "C" bool MP4GetTrackVideoMetadata(
  1812. MP4FileHandle hFile, MP4TrackId trackId,
  1813. u_int8_t** ppConfig, u_int32_t* pConfigSize)
  1814. {
  1815. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1816. try {
  1817. ((MP4File*)hFile)->GetTrackVideoMetadata(
  1818. trackId, ppConfig, pConfigSize);
  1819. return true;
  1820. }
  1821. catch (MP4Error* e) {
  1822. PRINT_ERROR(e);
  1823. delete e;
  1824. }
  1825. }
  1826. *ppConfig = NULL;
  1827. *pConfigSize = 0;
  1828. return false;
  1829. }
  1830. extern "C" bool MP4SetTrackESConfiguration(
  1831. MP4FileHandle hFile, MP4TrackId trackId,
  1832. const u_int8_t* pConfig, u_int32_t configSize)
  1833. {
  1834. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1835. try {
  1836. ((MP4File*)hFile)->SetTrackESConfiguration(
  1837. trackId, pConfig, configSize);
  1838. return true;
  1839. }
  1840. catch (MP4Error* e) {
  1841. PRINT_ERROR(e);
  1842. delete e;
  1843. }
  1844. }
  1845. return false;
  1846. }
  1847. extern "C" bool MP4GetTrackH264ProfileLevel (MP4FileHandle hFile,
  1848. MP4TrackId trackId,
  1849. uint8_t *pProfile,
  1850. uint8_t *pLevel)
  1851. {
  1852. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1853. try {
  1854. *pProfile =
  1855. ((MP4File *)hFile)->GetTrackIntegerProperty(trackId,
  1856. "mdia.minf.stbl.stsd.*[0].avcC.AVCProfileIndication");
  1857. *pLevel =
  1858. ((MP4File *)hFile)->GetTrackIntegerProperty(trackId,
  1859. "mdia.minf.stbl.stsd.*[0].avcC.AVCLevelIndication");
  1860. return true;
  1861. }
  1862. catch (MP4Error* e) {
  1863. PRINT_ERROR(e);
  1864. delete e;
  1865. }
  1866. }
  1867. return false;
  1868. }
  1869. extern "C" void MP4GetTrackH264SeqPictHeaders (MP4FileHandle hFile,
  1870. MP4TrackId trackId,
  1871. uint8_t ***pSeqHeader,
  1872. uint32_t **pSeqHeaderSize,
  1873. uint8_t ***pPictHeader,
  1874. uint32_t **pPictHeaderSize)
  1875. {
  1876. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1877. try {
  1878. ((MP4File*)hFile)->GetTrackH264SeqPictHeaders(trackId,
  1879. pSeqHeader,
  1880. pSeqHeaderSize,
  1881. pPictHeader,
  1882. pPictHeaderSize);
  1883. return;
  1884. }
  1885. catch (MP4Error* e) {
  1886. PRINT_ERROR(e);
  1887. delete e;
  1888. }
  1889. }
  1890. return;
  1891. }
  1892. extern "C" bool MP4GetTrackH264LengthSize (MP4FileHandle hFile,
  1893. MP4TrackId trackId,
  1894. uint32_t *pLength)
  1895. {
  1896. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1897. try {
  1898. *pLength = 1 +
  1899. ((MP4File*) hFile)->GetTrackIntegerProperty(trackId,
  1900. "mdia.minf.stbl.stsd.*[0].avcC.lengthSizeMinusOne");
  1901. return true;
  1902. }
  1903. catch (MP4Error* e) {
  1904. PRINT_ERROR(e);
  1905. delete e;
  1906. }
  1907. }
  1908. return false;
  1909. }
  1910. extern "C" MP4SampleId MP4GetTrackNumberOfSamples(
  1911. MP4FileHandle hFile, MP4TrackId trackId)
  1912. {
  1913. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1914. try {
  1915. return ((MP4File*)hFile)->GetTrackNumberOfSamples(trackId);
  1916. }
  1917. catch (MP4Error* e) {
  1918. PRINT_ERROR(e);
  1919. delete e;
  1920. }
  1921. }
  1922. return 0;
  1923. }
  1924. extern "C" MP4ChunkId MP4GetTrackNumberOfChunks(
  1925. MP4FileHandle hFile, MP4TrackId trackId)
  1926. {
  1927. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1928. try {
  1929. return ((MP4File*)hFile)->GetTrackNumberOfChunks(trackId);
  1930. }
  1931. catch (MP4Error* e) {
  1932. PRINT_ERROR(e);
  1933. delete e;
  1934. }
  1935. }
  1936. return 0;
  1937. }
  1938. extern "C" u_int16_t MP4GetTrackVideoWidth(
  1939. MP4FileHandle hFile, MP4TrackId trackId)
  1940. {
  1941. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1942. try {
  1943. return ((MP4File*)hFile)->GetTrackIntegerProperty(trackId,
  1944. "mdia.minf.stbl.stsd.*.width");
  1945. }
  1946. catch (MP4Error* e) {
  1947. PRINT_ERROR(e);
  1948. delete e;
  1949. }
  1950. }
  1951. return 0;
  1952. }
  1953. extern "C" u_int16_t MP4GetTrackVideoHeight(
  1954. MP4FileHandle hFile, MP4TrackId trackId)
  1955. {
  1956. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1957. try {
  1958. return ((MP4File*)hFile)->GetTrackIntegerProperty(trackId,
  1959. "mdia.minf.stbl.stsd.*.height");
  1960. }
  1961. catch (MP4Error* e) {
  1962. PRINT_ERROR(e);
  1963. delete e;
  1964. }
  1965. }
  1966. return 0;
  1967. }
  1968. extern "C" double MP4GetTrackVideoFrameRate(
  1969. MP4FileHandle hFile, MP4TrackId trackId)
  1970. {
  1971. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1972. try {
  1973. return ((MP4File*)hFile)->GetTrackVideoFrameRate(trackId);
  1974. }
  1975. catch (MP4Error* e) {
  1976. PRINT_ERROR(e);
  1977. delete e;
  1978. }
  1979. }
  1980. return 0.0;
  1981. }
  1982. extern "C" int MP4GetTrackAudioChannels (MP4FileHandle hFile,
  1983. MP4TrackId trackId)
  1984. {
  1985. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  1986. try {
  1987. return ((MP4File*)hFile)->GetTrackAudioChannels(trackId);
  1988. }
  1989. catch (MP4Error* e) {
  1990. PRINT_ERROR(e);
  1991. delete e;
  1992. }
  1993. }
  1994. return -1;
  1995. }
  1996. // returns true if the track is a media track encrypted according to ismacryp
  1997. extern "C" bool MP4IsIsmaCrypMediaTrack(
  1998. MP4FileHandle hFile, MP4TrackId trackId)
  1999. {
  2000. bool retval = false;
  2001. uint32_t verb = MP4GetVerbosity(hFile);
  2002. MP4SetVerbosity(hFile, verb & ~(MP4_DETAILS_ERROR));
  2003. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2004. try {
  2005. retval = ((MP4File*)hFile)->IsIsmaCrypMediaTrack(trackId);
  2006. }
  2007. catch (MP4Error* e) {
  2008. PRINT_ERROR(e);
  2009. delete e;
  2010. }
  2011. }
  2012. MP4SetVerbosity(hFile, verb);
  2013. return retval;
  2014. }
  2015. /* generic track properties */
  2016. extern "C" bool MP4HaveTrackAtom (MP4FileHandle hFile,
  2017. MP4TrackId trackId,
  2018. const char *atomName)
  2019. {
  2020. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2021. try {
  2022. return ((MP4File*)hFile)->FindTrackAtom(trackId, atomName) != NULL;
  2023. }
  2024. catch (MP4Error* e) {
  2025. PRINT_ERROR(e);
  2026. delete e;
  2027. }
  2028. }
  2029. return false;
  2030. }
  2031. extern "C" bool MP4GetTrackIntegerProperty (
  2032. MP4FileHandle hFile, MP4TrackId trackId,
  2033. const char* propName,
  2034. u_int64_t *retvalue)
  2035. {
  2036. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2037. try {
  2038. *retvalue = ((MP4File*)hFile)->GetTrackIntegerProperty(trackId,
  2039. propName);
  2040. return true;
  2041. }
  2042. catch (MP4Error* e) {
  2043. PRINT_ERROR(e);
  2044. delete e;
  2045. }
  2046. }
  2047. return false;
  2048. }
  2049. extern "C" bool MP4GetTrackFloatProperty(
  2050. MP4FileHandle hFile, MP4TrackId trackId,
  2051. const char* propName,
  2052. float *retvalue)
  2053. {
  2054. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2055. try {
  2056. *retvalue = ((MP4File*)hFile)->GetTrackFloatProperty(trackId, propName);
  2057. return true;
  2058. }
  2059. catch (MP4Error* e) {
  2060. PRINT_ERROR(e);
  2061. delete e;
  2062. }
  2063. }
  2064. return false;
  2065. }
  2066. extern "C" bool MP4GetTrackStringProperty(
  2067. MP4FileHandle hFile, MP4TrackId trackId,
  2068. const char* propName,
  2069. const char **retvalue)
  2070. {
  2071. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2072. try {
  2073. *retvalue = ((MP4File*)hFile)->GetTrackStringProperty(trackId, propName);
  2074. return true;
  2075. }
  2076. catch (MP4Error* e) {
  2077. PRINT_ERROR(e);
  2078. delete e;
  2079. }
  2080. }
  2081. return false;
  2082. }
  2083. extern "C" bool MP4GetTrackBytesProperty(
  2084. MP4FileHandle hFile, MP4TrackId trackId, const char* propName,
  2085. u_int8_t** ppValue, u_int32_t* pValueSize)
  2086. {
  2087. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2088. try {
  2089. ((MP4File*)hFile)->GetTrackBytesProperty(
  2090. trackId, propName, ppValue, pValueSize);
  2091. return true;
  2092. }
  2093. catch (MP4Error* e) {
  2094. PRINT_ERROR(e);
  2095. delete e;
  2096. }
  2097. }
  2098. *ppValue = NULL;
  2099. *pValueSize = 0;
  2100. return false;
  2101. }
  2102. extern "C" bool MP4SetTrackIntegerProperty(
  2103. MP4FileHandle hFile, MP4TrackId trackId,
  2104. const char* propName, int64_t value)
  2105. {
  2106. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2107. try {
  2108. ((MP4File*)hFile)->SetTrackIntegerProperty(trackId,
  2109. propName, value);
  2110. return true;
  2111. }
  2112. catch (MP4Error* e) {
  2113. PRINT_ERROR(e);
  2114. delete e;
  2115. }
  2116. }
  2117. return false;
  2118. }
  2119. extern "C" bool MP4SetTrackFloatProperty(
  2120. MP4FileHandle hFile, MP4TrackId trackId,
  2121. const char* propName, float value)
  2122. {
  2123. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2124. try {
  2125. ((MP4File*)hFile)->SetTrackFloatProperty(trackId, propName, value);
  2126. return true;
  2127. }
  2128. catch (MP4Error* e) {
  2129. PRINT_ERROR(e);
  2130. delete e;
  2131. }
  2132. }
  2133. return false;
  2134. }
  2135. extern "C" bool MP4SetTrackStringProperty(
  2136. MP4FileHandle hFile, MP4TrackId trackId,
  2137. const char* propName, const char* value)
  2138. {
  2139. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2140. try {
  2141. ((MP4File*)hFile)->SetTrackStringProperty(trackId, propName, value);
  2142. return true;
  2143. }
  2144. catch (MP4Error* e) {
  2145. PRINT_ERROR(e);
  2146. delete e;
  2147. }
  2148. }
  2149. return false;
  2150. }
  2151. extern "C" bool MP4SetTrackBytesProperty(
  2152. MP4FileHandle hFile, MP4TrackId trackId,
  2153. const char* propName, const u_int8_t* pValue, u_int32_t valueSize)
  2154. {
  2155. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2156. try {
  2157. ((MP4File*)hFile)->SetTrackBytesProperty(
  2158. trackId, propName, pValue, valueSize);
  2159. return true;
  2160. }
  2161. catch (MP4Error* e) {
  2162. PRINT_ERROR(e);
  2163. delete e;
  2164. }
  2165. }
  2166. return false;
  2167. }
  2168. /* sample operations */
  2169. extern "C" bool MP4ReadSample(
  2170. /* input parameters */
  2171. MP4FileHandle hFile,
  2172. MP4TrackId trackId,
  2173. MP4SampleId sampleId,
  2174. /* output parameters */
  2175. u_int8_t** ppBytes,
  2176. u_int32_t* pNumBytes,
  2177. MP4Timestamp* pStartTime,
  2178. MP4Duration* pDuration,
  2179. MP4Duration* pRenderingOffset,
  2180. bool* pIsSyncSample)
  2181. {
  2182. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2183. try {
  2184. ((MP4File*)hFile)->ReadSample(
  2185. trackId,
  2186. sampleId,
  2187. ppBytes,
  2188. pNumBytes,
  2189. pStartTime,
  2190. pDuration,
  2191. pRenderingOffset,
  2192. pIsSyncSample);
  2193. return true;
  2194. }
  2195. catch (MP4Error* e) {
  2196. PRINT_ERROR(e);
  2197. delete e;
  2198. }
  2199. }
  2200. *pNumBytes = 0;
  2201. return false;
  2202. }
  2203. extern "C" bool MP4ReadChunk(
  2204. /* input parameters */
  2205. MP4FileHandle hFile,
  2206. MP4ChunkId trackId,
  2207. MP4SampleId sampleId,
  2208. /* output parameters */
  2209. u_int8_t** ppBytes,
  2210. u_int32_t* pNumBytes,
  2211. MP4Timestamp* pStartTime,
  2212. MP4Duration* pDuration)
  2213. {
  2214. if (MP4_IS_VALID_FILE_HANDLE(hFile))
  2215. {
  2216. try
  2217. {
  2218. ((MP4File*)hFile)->ReadChunk(
  2219. trackId,
  2220. sampleId,
  2221. ppBytes,
  2222. pNumBytes,
  2223. pStartTime,
  2224. pDuration);
  2225. return true;
  2226. }
  2227. catch (MP4Error* e) {
  2228. PRINT_ERROR(e);
  2229. delete e;
  2230. }
  2231. }
  2232. *pNumBytes = 0;
  2233. return false;
  2234. }
  2235. extern "C" bool MP4ReadSampleFromTime(
  2236. /* input parameters */
  2237. MP4FileHandle hFile,
  2238. MP4TrackId trackId,
  2239. MP4Timestamp when,
  2240. /* output parameters */
  2241. u_int8_t** ppBytes,
  2242. u_int32_t* pNumBytes,
  2243. MP4Timestamp* pStartTime,
  2244. MP4Duration* pDuration,
  2245. MP4Duration* pRenderingOffset,
  2246. bool* pIsSyncSample)
  2247. {
  2248. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2249. try {
  2250. MP4SampleId sampleId =
  2251. ((MP4File*)hFile)->GetSampleIdFromTime(
  2252. trackId, when, false);
  2253. ((MP4File*)hFile)->ReadSample(
  2254. trackId,
  2255. sampleId,
  2256. ppBytes,
  2257. pNumBytes,
  2258. pStartTime,
  2259. pDuration,
  2260. pRenderingOffset,
  2261. pIsSyncSample);
  2262. return true;
  2263. }
  2264. catch (MP4Error* e) {
  2265. PRINT_ERROR(e);
  2266. delete e;
  2267. }
  2268. }
  2269. *pNumBytes = 0;
  2270. return false;
  2271. }
  2272. extern "C" bool MP4WriteSample(
  2273. MP4FileHandle hFile,
  2274. MP4TrackId trackId,
  2275. const u_int8_t* pBytes,
  2276. u_int32_t numBytes,
  2277. MP4Duration duration,
  2278. MP4Duration renderingOffset,
  2279. bool isSyncSample)
  2280. {
  2281. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2282. try {
  2283. ((MP4File*)hFile)->WriteSample(
  2284. trackId,
  2285. pBytes,
  2286. numBytes,
  2287. duration,
  2288. renderingOffset,
  2289. isSyncSample);
  2290. return true;
  2291. }
  2292. catch (MP4Error* e) {
  2293. PRINT_ERROR(e);
  2294. delete e;
  2295. }
  2296. }
  2297. return false;
  2298. }
  2299. extern "C" bool MP4CopySample(
  2300. MP4FileHandle srcFile,
  2301. MP4TrackId srcTrackId,
  2302. MP4SampleId srcSampleId,
  2303. MP4FileHandle dstFile,
  2304. MP4TrackId dstTrackId,
  2305. MP4Duration dstSampleDuration)
  2306. {
  2307. bool rc;
  2308. u_int8_t* pBytes = NULL;
  2309. u_int32_t numBytes = 0;
  2310. MP4Duration sampleDuration;
  2311. MP4Duration renderingOffset;
  2312. bool isSyncSample;
  2313. // Note: we leave it up to the caller to ensure that the
  2314. // source and destination tracks are compatible.
  2315. // i.e. copying audio samples into a video track
  2316. // is unlikely to do anything useful
  2317. rc = MP4ReadSample(
  2318. srcFile,
  2319. srcTrackId,
  2320. srcSampleId,
  2321. &pBytes,
  2322. &numBytes,
  2323. NULL,
  2324. &sampleDuration,
  2325. &renderingOffset,
  2326. &isSyncSample);
  2327. if (!rc) {
  2328. return false;
  2329. }
  2330. if (dstFile == MP4_INVALID_FILE_HANDLE) {
  2331. dstFile = srcFile;
  2332. }
  2333. if (dstTrackId == MP4_INVALID_TRACK_ID) {
  2334. dstTrackId = srcTrackId;
  2335. }
  2336. if (dstSampleDuration != MP4_INVALID_DURATION) {
  2337. sampleDuration = dstSampleDuration;
  2338. }
  2339. rc = MP4WriteSample(
  2340. dstFile,
  2341. dstTrackId,
  2342. pBytes,
  2343. numBytes,
  2344. sampleDuration,
  2345. renderingOffset,
  2346. isSyncSample);
  2347. free(pBytes);
  2348. return rc;
  2349. }
  2350. extern "C" bool MP4EncAndCopySample(
  2351. MP4FileHandle srcFile,
  2352. MP4TrackId srcTrackId,
  2353. MP4SampleId srcSampleId,
  2354. encryptFunc_t encfcnp,
  2355. u_int32_t encfcnparam1,
  2356. MP4FileHandle dstFile,
  2357. MP4TrackId dstTrackId,
  2358. MP4Duration dstSampleDuration)
  2359. {
  2360. bool rc;
  2361. u_int8_t* pBytes = NULL;
  2362. u_int32_t numBytes = 0;
  2363. u_int8_t* encSampleData = NULL;
  2364. u_int32_t encSampleLength = 0;
  2365. MP4Duration sampleDuration;
  2366. MP4Duration renderingOffset;
  2367. bool isSyncSample;
  2368. // Note: we leave it up to the caller to ensure that the
  2369. // source and destination tracks are compatible.
  2370. // i.e. copying audio samples into a video track
  2371. // is unlikely to do anything useful
  2372. rc = MP4ReadSample(
  2373. srcFile,
  2374. srcTrackId,
  2375. srcSampleId,
  2376. &pBytes,
  2377. &numBytes,
  2378. NULL,
  2379. &sampleDuration,
  2380. &renderingOffset,
  2381. &isSyncSample);
  2382. if (!rc) {
  2383. return false;
  2384. }
  2385. if (dstFile == MP4_INVALID_FILE_HANDLE) {
  2386. dstFile = srcFile;
  2387. }
  2388. if (dstTrackId == MP4_INVALID_TRACK_ID) {
  2389. dstTrackId = srcTrackId;
  2390. }
  2391. if (dstSampleDuration != MP4_INVALID_DURATION) {
  2392. sampleDuration = dstSampleDuration;
  2393. }
  2394. //if (ismacrypEncryptSampleAddHeader(ismaCryptSId, numBytes, pBytes,
  2395. // &encSampleLength, &encSampleData) != 0) {
  2396. if (encfcnp(encfcnparam1, numBytes, pBytes,
  2397. &encSampleLength, &encSampleData) != 0) {
  2398. fprintf(stderr,
  2399. "Can't encrypt the sample and add its header %u\n",
  2400. srcSampleId);
  2401. }
  2402. rc = MP4WriteSample(
  2403. dstFile,
  2404. dstTrackId,
  2405. encSampleData,
  2406. encSampleLength,
  2407. sampleDuration,
  2408. renderingOffset,
  2409. isSyncSample);
  2410. free(pBytes);
  2411. if (encSampleData != NULL) {
  2412. free(encSampleData);
  2413. }
  2414. return rc;
  2415. }
  2416. extern "C" bool MP4ReferenceSample(
  2417. MP4FileHandle srcFile,
  2418. MP4TrackId srcTrackId,
  2419. MP4SampleId srcSampleId,
  2420. MP4FileHandle dstFile,
  2421. MP4TrackId dstTrackId,
  2422. MP4Duration dstSampleDuration)
  2423. {
  2424. // LATER Not yet implemented
  2425. return false;
  2426. }
  2427. extern "C" u_int32_t MP4GetSampleSize(
  2428. MP4FileHandle hFile,
  2429. MP4TrackId trackId,
  2430. MP4SampleId sampleId)
  2431. {
  2432. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2433. try {
  2434. return ((MP4File*)hFile)->GetSampleSize(
  2435. trackId, sampleId);
  2436. }
  2437. catch (MP4Error* e) {
  2438. PRINT_ERROR(e);
  2439. delete e;
  2440. }
  2441. }
  2442. return 0;
  2443. }
  2444. extern "C" u_int32_t MP4GetTrackMaxSampleSize(
  2445. MP4FileHandle hFile,
  2446. MP4TrackId trackId)
  2447. {
  2448. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2449. try {
  2450. return ((MP4File*)hFile)->GetTrackMaxSampleSize(trackId);
  2451. }
  2452. catch (MP4Error* e) {
  2453. PRINT_ERROR(e);
  2454. delete e;
  2455. }
  2456. }
  2457. return 0;
  2458. }
  2459. extern "C" MP4SampleId MP4GetSampleIdFromTime(
  2460. MP4FileHandle hFile,
  2461. MP4TrackId trackId,
  2462. MP4Timestamp when,
  2463. bool wantSyncSample,
  2464. bool rewind)
  2465. {
  2466. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2467. try {
  2468. return ((MP4File*)hFile)->GetSampleIdFromTime(
  2469. trackId, when, wantSyncSample, rewind);
  2470. }
  2471. catch (MP4Error* e) {
  2472. PRINT_ERROR(e);
  2473. delete e;
  2474. }
  2475. }
  2476. return MP4_INVALID_SAMPLE_ID;
  2477. }
  2478. extern "C" MP4ChunkId MP4GetChunkIdFromTime(
  2479. MP4FileHandle hFile,
  2480. MP4TrackId trackId,
  2481. MP4Timestamp when)
  2482. {
  2483. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2484. try {
  2485. return ((MP4File*)hFile)->GetChunkIdFromTime(
  2486. trackId, when);
  2487. }
  2488. catch (MP4Error* e) {
  2489. PRINT_ERROR(e);
  2490. delete e;
  2491. }
  2492. }
  2493. return MP4_INVALID_SAMPLE_ID;
  2494. }
  2495. extern "C" MP4Timestamp MP4GetSampleTime(
  2496. MP4FileHandle hFile,
  2497. MP4TrackId trackId,
  2498. MP4SampleId sampleId)
  2499. {
  2500. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2501. try {
  2502. return ((MP4File*)hFile)->GetSampleTime(
  2503. trackId, sampleId);
  2504. }
  2505. catch (MP4Error* e) {
  2506. PRINT_ERROR(e);
  2507. delete e;
  2508. }
  2509. }
  2510. return MP4_INVALID_TIMESTAMP;
  2511. }
  2512. extern "C" MP4Duration MP4GetSampleDuration(
  2513. MP4FileHandle hFile,
  2514. MP4TrackId trackId,
  2515. MP4SampleId sampleId)
  2516. {
  2517. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2518. try {
  2519. return ((MP4File*)hFile)->GetSampleDuration(
  2520. trackId, sampleId);
  2521. }
  2522. catch (MP4Error* e) {
  2523. PRINT_ERROR(e);
  2524. delete e;
  2525. }
  2526. }
  2527. return MP4_INVALID_DURATION;
  2528. }
  2529. extern "C" MP4Duration MP4GetSampleRenderingOffset(
  2530. MP4FileHandle hFile,
  2531. MP4TrackId trackId,
  2532. MP4SampleId sampleId)
  2533. {
  2534. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2535. try {
  2536. return ((MP4File*)hFile)->GetSampleRenderingOffset(
  2537. trackId, sampleId);
  2538. }
  2539. catch (MP4Error* e) {
  2540. PRINT_ERROR(e);
  2541. delete e;
  2542. }
  2543. }
  2544. return MP4_INVALID_DURATION;
  2545. }
  2546. extern "C" bool MP4SetSampleRenderingOffset(
  2547. MP4FileHandle hFile,
  2548. MP4TrackId trackId,
  2549. MP4SampleId sampleId,
  2550. MP4Duration renderingOffset)
  2551. {
  2552. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2553. try {
  2554. ((MP4File*)hFile)->SetSampleRenderingOffset(
  2555. trackId, sampleId, renderingOffset);
  2556. return true;
  2557. }
  2558. catch (MP4Error* e) {
  2559. PRINT_ERROR(e);
  2560. delete e;
  2561. }
  2562. }
  2563. return false;
  2564. }
  2565. extern "C" int8_t MP4GetSampleSync(
  2566. MP4FileHandle hFile,
  2567. MP4TrackId trackId,
  2568. MP4SampleId sampleId)
  2569. {
  2570. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2571. try {
  2572. return ((MP4File*)hFile)->GetSampleSync(
  2573. trackId, sampleId);
  2574. }
  2575. catch (MP4Error* e) {
  2576. PRINT_ERROR(e);
  2577. delete e;
  2578. }
  2579. }
  2580. return -1;
  2581. }
  2582. extern "C" u_int64_t MP4ConvertFromMovieDuration(
  2583. MP4FileHandle hFile,
  2584. MP4Duration duration,
  2585. u_int32_t timeScale)
  2586. {
  2587. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2588. try {
  2589. return ((MP4File*)hFile)->ConvertFromMovieDuration(
  2590. duration, timeScale);
  2591. }
  2592. catch (MP4Error* e) {
  2593. PRINT_ERROR(e);
  2594. delete e;
  2595. }
  2596. }
  2597. return (u_int64_t)MP4_INVALID_DURATION;
  2598. }
  2599. extern "C" u_int64_t MP4ConvertFromTrackTimestamp(
  2600. MP4FileHandle hFile,
  2601. MP4TrackId trackId,
  2602. MP4Timestamp timeStamp,
  2603. u_int32_t timeScale)
  2604. {
  2605. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2606. try {
  2607. return ((MP4File*)hFile)->ConvertFromTrackTimestamp(
  2608. trackId, timeStamp, timeScale);
  2609. }
  2610. catch (MP4Error* e) {
  2611. PRINT_ERROR(e);
  2612. delete e;
  2613. }
  2614. }
  2615. return (u_int64_t)MP4_INVALID_TIMESTAMP;
  2616. }
  2617. extern "C" MP4Timestamp MP4ConvertToTrackTimestamp(
  2618. MP4FileHandle hFile,
  2619. MP4TrackId trackId,
  2620. u_int64_t timeStamp,
  2621. u_int32_t timeScale)
  2622. {
  2623. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2624. try {
  2625. return ((MP4File*)hFile)->ConvertToTrackTimestamp(
  2626. trackId, timeStamp, timeScale);
  2627. }
  2628. catch (MP4Error* e) {
  2629. PRINT_ERROR(e);
  2630. delete e;
  2631. }
  2632. }
  2633. return MP4_INVALID_TIMESTAMP;
  2634. }
  2635. extern "C" u_int64_t MP4ConvertFromTrackDuration(
  2636. MP4FileHandle hFile,
  2637. MP4TrackId trackId,
  2638. MP4Duration duration,
  2639. u_int32_t timeScale)
  2640. {
  2641. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2642. try {
  2643. return ((MP4File*)hFile)->ConvertFromTrackDuration(
  2644. trackId, duration, timeScale);
  2645. }
  2646. catch (MP4Error* e) {
  2647. PRINT_ERROR(e);
  2648. delete e;
  2649. }
  2650. }
  2651. return (u_int64_t)MP4_INVALID_DURATION;
  2652. }
  2653. extern "C" MP4Duration MP4ConvertToTrackDuration(
  2654. MP4FileHandle hFile,
  2655. MP4TrackId trackId,
  2656. u_int64_t duration,
  2657. u_int32_t timeScale)
  2658. {
  2659. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2660. try {
  2661. return ((MP4File*)hFile)->ConvertToTrackDuration(
  2662. trackId, duration, timeScale);
  2663. }
  2664. catch (MP4Error* e) {
  2665. PRINT_ERROR(e);
  2666. delete e;
  2667. }
  2668. }
  2669. return MP4_INVALID_DURATION;
  2670. }
  2671. extern "C" bool MP4GetHintTrackRtpPayload(
  2672. MP4FileHandle hFile,
  2673. MP4TrackId hintTrackId,
  2674. char** ppPayloadName,
  2675. u_int8_t* pPayloadNumber,
  2676. u_int16_t* pMaxPayloadSize,
  2677. char **ppEncodingParams)
  2678. {
  2679. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2680. try {
  2681. ((MP4File*)hFile)->GetHintTrackRtpPayload(
  2682. hintTrackId, ppPayloadName, pPayloadNumber, pMaxPayloadSize,
  2683. ppEncodingParams);
  2684. return true;
  2685. }
  2686. catch (MP4Error* e) {
  2687. PRINT_ERROR(e);
  2688. delete e;
  2689. }
  2690. }
  2691. return false;
  2692. }
  2693. extern "C" bool MP4SetHintTrackRtpPayload(
  2694. MP4FileHandle hFile,
  2695. MP4TrackId hintTrackId,
  2696. const char* pPayloadName,
  2697. u_int8_t* pPayloadNumber,
  2698. u_int16_t maxPayloadSize,
  2699. const char *encode_params,
  2700. bool include_rtp_map,
  2701. bool include_mpeg4_esid)
  2702. {
  2703. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2704. try {
  2705. ((MP4File*)hFile)->SetHintTrackRtpPayload(
  2706. hintTrackId, pPayloadName, pPayloadNumber, maxPayloadSize, encode_params,
  2707. include_rtp_map, include_mpeg4_esid);
  2708. return true;
  2709. }
  2710. catch (MP4Error* e) {
  2711. PRINT_ERROR(e);
  2712. delete e;
  2713. }
  2714. }
  2715. return false;
  2716. }
  2717. extern "C" const char* MP4GetSessionSdp(
  2718. MP4FileHandle hFile)
  2719. {
  2720. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2721. try {
  2722. return ((MP4File*)hFile)->GetSessionSdp();
  2723. }
  2724. catch (MP4Error* e) {
  2725. PRINT_ERROR(e);
  2726. delete e;
  2727. }
  2728. }
  2729. return NULL;
  2730. }
  2731. extern "C" bool MP4SetSessionSdp(
  2732. MP4FileHandle hFile,
  2733. const char* sdpString)
  2734. {
  2735. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2736. try {
  2737. ((MP4File*)hFile)->SetSessionSdp(sdpString);
  2738. return true;
  2739. }
  2740. catch (MP4Error* e) {
  2741. PRINT_ERROR(e);
  2742. delete e;
  2743. }
  2744. }
  2745. return false;
  2746. }
  2747. extern "C" bool MP4AppendSessionSdp(
  2748. MP4FileHandle hFile,
  2749. const char* sdpString)
  2750. {
  2751. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2752. try {
  2753. ((MP4File*)hFile)->AppendSessionSdp(sdpString);
  2754. return true;
  2755. }
  2756. catch (MP4Error* e) {
  2757. PRINT_ERROR(e);
  2758. delete e;
  2759. }
  2760. }
  2761. return false;
  2762. }
  2763. extern "C" const char* MP4GetHintTrackSdp(
  2764. MP4FileHandle hFile,
  2765. MP4TrackId hintTrackId)
  2766. {
  2767. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2768. try {
  2769. return ((MP4File*)hFile)->GetHintTrackSdp(hintTrackId);
  2770. }
  2771. catch (MP4Error* e) {
  2772. PRINT_ERROR(e);
  2773. delete e;
  2774. }
  2775. }
  2776. return NULL;
  2777. }
  2778. extern "C" bool MP4SetHintTrackSdp(
  2779. MP4FileHandle hFile,
  2780. MP4TrackId hintTrackId,
  2781. const char* sdpString)
  2782. {
  2783. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2784. try {
  2785. ((MP4File*)hFile)->SetHintTrackSdp(hintTrackId, sdpString);
  2786. return true;
  2787. }
  2788. catch (MP4Error* e) {
  2789. PRINT_ERROR(e);
  2790. delete e;
  2791. }
  2792. }
  2793. return false;
  2794. }
  2795. extern "C" bool MP4AppendHintTrackSdp(
  2796. MP4FileHandle hFile,
  2797. MP4TrackId hintTrackId,
  2798. const char* sdpString)
  2799. {
  2800. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2801. try {
  2802. ((MP4File*)hFile)->AppendHintTrackSdp(hintTrackId, sdpString);
  2803. return true;
  2804. }
  2805. catch (MP4Error* e) {
  2806. PRINT_ERROR(e);
  2807. delete e;
  2808. }
  2809. }
  2810. return false;
  2811. }
  2812. extern "C" MP4TrackId MP4GetHintTrackReferenceTrackId(
  2813. MP4FileHandle hFile,
  2814. MP4TrackId hintTrackId)
  2815. {
  2816. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2817. try {
  2818. return ((MP4File*)hFile)->
  2819. GetHintTrackReferenceTrackId(hintTrackId);
  2820. }
  2821. catch (MP4Error* e) {
  2822. PRINT_ERROR(e);
  2823. delete e;
  2824. }
  2825. }
  2826. return MP4_INVALID_TRACK_ID;
  2827. }
  2828. extern "C" bool MP4ReadRtpHint(
  2829. MP4FileHandle hFile,
  2830. MP4TrackId hintTrackId,
  2831. MP4SampleId hintSampleId,
  2832. u_int16_t* pNumPackets)
  2833. {
  2834. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2835. try {
  2836. ((MP4File*)hFile)->ReadRtpHint(
  2837. hintTrackId, hintSampleId, pNumPackets);
  2838. return true;
  2839. }
  2840. catch (MP4Error* e) {
  2841. PRINT_ERROR(e);
  2842. delete e;
  2843. }
  2844. }
  2845. return false;
  2846. }
  2847. extern "C" u_int16_t MP4GetRtpHintNumberOfPackets(
  2848. MP4FileHandle hFile,
  2849. MP4TrackId hintTrackId)
  2850. {
  2851. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2852. try {
  2853. return ((MP4File*)hFile)->GetRtpHintNumberOfPackets(hintTrackId);
  2854. }
  2855. catch (MP4Error* e) {
  2856. PRINT_ERROR(e);
  2857. delete e;
  2858. }
  2859. }
  2860. return 0;
  2861. }
  2862. extern "C" int8_t MP4GetRtpPacketBFrame(
  2863. MP4FileHandle hFile,
  2864. MP4TrackId hintTrackId,
  2865. u_int16_t packetIndex)
  2866. {
  2867. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2868. try {
  2869. return ((MP4File*)hFile)->
  2870. GetRtpPacketBFrame(hintTrackId, packetIndex);
  2871. }
  2872. catch (MP4Error* e) {
  2873. PRINT_ERROR(e);
  2874. delete e;
  2875. }
  2876. }
  2877. return -1;
  2878. }
  2879. extern "C" int32_t MP4GetRtpPacketTransmitOffset(
  2880. MP4FileHandle hFile,
  2881. MP4TrackId hintTrackId,
  2882. u_int16_t packetIndex)
  2883. {
  2884. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2885. try {
  2886. return ((MP4File*)hFile)->
  2887. GetRtpPacketTransmitOffset(hintTrackId, packetIndex);
  2888. }
  2889. catch (MP4Error* e) {
  2890. PRINT_ERROR(e);
  2891. delete e;
  2892. }
  2893. }
  2894. return 0;
  2895. }
  2896. extern "C" bool MP4ReadRtpPacket(
  2897. MP4FileHandle hFile,
  2898. MP4TrackId hintTrackId,
  2899. u_int16_t packetIndex,
  2900. u_int8_t** ppBytes,
  2901. u_int32_t* pNumBytes,
  2902. u_int32_t ssrc,
  2903. bool includeHeader,
  2904. bool includePayload)
  2905. {
  2906. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2907. try {
  2908. ((MP4File*)hFile)->ReadRtpPacket(
  2909. hintTrackId, packetIndex,
  2910. ppBytes, pNumBytes,
  2911. ssrc, includeHeader, includePayload);
  2912. return true;
  2913. }
  2914. catch (MP4Error* e) {
  2915. PRINT_ERROR(e);
  2916. delete e;
  2917. }
  2918. }
  2919. return false;
  2920. }
  2921. extern "C" MP4Timestamp MP4GetRtpTimestampStart(
  2922. MP4FileHandle hFile,
  2923. MP4TrackId hintTrackId)
  2924. {
  2925. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2926. try {
  2927. return ((MP4File*)hFile)->GetRtpTimestampStart(hintTrackId);
  2928. }
  2929. catch (MP4Error* e) {
  2930. PRINT_ERROR(e);
  2931. delete e;
  2932. }
  2933. }
  2934. return MP4_INVALID_TIMESTAMP;
  2935. }
  2936. extern "C" bool MP4SetRtpTimestampStart(
  2937. MP4FileHandle hFile,
  2938. MP4TrackId hintTrackId,
  2939. MP4Timestamp rtpStart)
  2940. {
  2941. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2942. try {
  2943. ((MP4File*)hFile)->SetRtpTimestampStart(
  2944. hintTrackId, rtpStart);
  2945. return true;
  2946. }
  2947. catch (MP4Error* e) {
  2948. PRINT_ERROR(e);
  2949. delete e;
  2950. }
  2951. }
  2952. return false;
  2953. }
  2954. extern "C" bool MP4AddRtpHint(
  2955. MP4FileHandle hFile,
  2956. MP4TrackId hintTrackId)
  2957. {
  2958. return MP4AddRtpVideoHint(hFile, hintTrackId, false, 0);
  2959. }
  2960. extern "C" bool MP4AddRtpVideoHint(
  2961. MP4FileHandle hFile,
  2962. MP4TrackId hintTrackId,
  2963. bool isBframe,
  2964. u_int32_t timestampOffset)
  2965. {
  2966. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2967. try {
  2968. ((MP4File*)hFile)->AddRtpHint(hintTrackId,
  2969. isBframe, timestampOffset);
  2970. return true;
  2971. }
  2972. catch (MP4Error* e) {
  2973. PRINT_ERROR(e);
  2974. delete e;
  2975. }
  2976. }
  2977. return false;
  2978. }
  2979. extern "C" bool MP4AddRtpPacket(
  2980. MP4FileHandle hFile,
  2981. MP4TrackId hintTrackId,
  2982. bool setMbit,
  2983. int32_t transmitOffset)
  2984. {
  2985. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  2986. try {
  2987. ((MP4File*)hFile)->AddRtpPacket(
  2988. hintTrackId, setMbit, transmitOffset);
  2989. return true;
  2990. }
  2991. catch (MP4Error* e) {
  2992. PRINT_ERROR(e);
  2993. delete e;
  2994. }
  2995. }
  2996. return false;
  2997. }
  2998. extern "C" bool MP4AddRtpImmediateData(
  2999. MP4FileHandle hFile,
  3000. MP4TrackId hintTrackId,
  3001. const u_int8_t* pBytes,
  3002. u_int32_t numBytes)
  3003. {
  3004. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3005. try {
  3006. ((MP4File*)hFile)->AddRtpImmediateData(hintTrackId,
  3007. pBytes, numBytes);
  3008. return true;
  3009. }
  3010. catch (MP4Error* e) {
  3011. PRINT_ERROR(e);
  3012. delete e;
  3013. }
  3014. }
  3015. return false;
  3016. }
  3017. extern "C" bool MP4AddRtpSampleData(
  3018. MP4FileHandle hFile,
  3019. MP4TrackId hintTrackId,
  3020. MP4SampleId sampleId,
  3021. u_int32_t dataOffset,
  3022. u_int32_t dataLength)
  3023. {
  3024. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3025. try {
  3026. ((MP4File*)hFile)->AddRtpSampleData(
  3027. hintTrackId, sampleId, dataOffset, dataLength);
  3028. return true;
  3029. }
  3030. catch (MP4Error* e) {
  3031. PRINT_ERROR(e);
  3032. delete e;
  3033. }
  3034. }
  3035. return false;
  3036. }
  3037. extern "C" bool MP4AddRtpESConfigurationPacket(
  3038. MP4FileHandle hFile,
  3039. MP4TrackId hintTrackId)
  3040. {
  3041. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3042. try {
  3043. ((MP4File*)hFile)->AddRtpESConfigurationPacket(hintTrackId);
  3044. return true;
  3045. }
  3046. catch (MP4Error* e) {
  3047. PRINT_ERROR(e);
  3048. delete e;
  3049. }
  3050. }
  3051. return false;
  3052. }
  3053. extern "C" bool MP4WriteRtpHint(
  3054. MP4FileHandle hFile,
  3055. MP4TrackId hintTrackId,
  3056. MP4Duration duration,
  3057. bool isSyncSample)
  3058. {
  3059. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3060. try {
  3061. ((MP4File*)hFile)->WriteRtpHint(
  3062. hintTrackId, duration, isSyncSample);
  3063. return true;
  3064. }
  3065. catch (MP4Error* e) {
  3066. PRINT_ERROR(e);
  3067. delete e;
  3068. }
  3069. }
  3070. return false;
  3071. }
  3072. /* 3GPP specific operations */
  3073. extern "C" bool MP4Make3GPCompliant(
  3074. const MP4_FILENAME_CHAR* fileName,
  3075. u_int32_t verbosity,
  3076. char* majorBrand,
  3077. u_int32_t minorVersion,
  3078. char** supportedBrands,
  3079. u_int32_t supportedBrandsCount,
  3080. bool deleteIodsAtom)
  3081. {
  3082. MP4File* pFile;
  3083. pFile = NULL;
  3084. try {
  3085. pFile = new MP4File(verbosity);
  3086. pFile->Modify(fileName);
  3087. pFile->Make3GPCompliant(fileName, majorBrand, minorVersion, supportedBrands, supportedBrandsCount, deleteIodsAtom);
  3088. pFile->Close();
  3089. delete pFile;
  3090. return true;
  3091. }
  3092. catch (MP4Error* e) {
  3093. VERBOSE_ERROR(verbosity, e->Print());
  3094. delete e;
  3095. }
  3096. delete pFile;
  3097. return false;
  3098. }
  3099. /* ISMA specific operations */
  3100. extern "C" bool MP4MakeIsmaCompliant(
  3101. const MP4_FILENAME_CHAR* fileName,
  3102. u_int32_t verbosity,
  3103. bool addIsmaComplianceSdp)
  3104. {
  3105. MP4File* pFile;
  3106. pFile = NULL;
  3107. try {
  3108. pFile = new MP4File(verbosity);
  3109. pFile->Modify(fileName);
  3110. pFile->MakeIsmaCompliant(addIsmaComplianceSdp);
  3111. pFile->Close();
  3112. delete pFile;
  3113. return true;
  3114. }
  3115. catch (MP4Error* e) {
  3116. VERBOSE_ERROR(verbosity, e->Print());
  3117. delete e;
  3118. }
  3119. delete pFile;
  3120. return false;
  3121. }
  3122. extern "C" char* MP4MakeIsmaSdpIod(
  3123. u_int8_t videoProfile,
  3124. u_int32_t videoBitrate,
  3125. u_int8_t* videoConfig,
  3126. u_int32_t videoConfigLength,
  3127. u_int8_t audioProfile,
  3128. u_int32_t audioBitrate,
  3129. u_int8_t* audioConfig,
  3130. u_int32_t audioConfigLength,
  3131. u_int32_t verbosity)
  3132. {
  3133. MP4File* pFile = NULL;
  3134. try {
  3135. pFile = new MP4File(verbosity);
  3136. u_int8_t* pBytes = NULL;
  3137. u_int64_t numBytes = 0;
  3138. pFile->CreateIsmaIodFromParams(
  3139. videoProfile,
  3140. videoBitrate,
  3141. videoConfig,
  3142. videoConfigLength,
  3143. audioProfile,
  3144. audioBitrate,
  3145. audioConfig,
  3146. audioConfigLength,
  3147. &pBytes,
  3148. &numBytes);
  3149. char* iodBase64 =
  3150. MP4ToBase64(pBytes, numBytes);
  3151. MP4Free(pBytes);
  3152. char* sdpIod =
  3153. (char*)MP4Malloc(strlen(iodBase64) + 64);
  3154. snprintf(sdpIod, strlen(iodBase64) + 64,
  3155. "a=mpeg4-iod: \042data:application/mpeg4-iod;base64,%s\042",
  3156. iodBase64);
  3157. MP4Free(iodBase64);
  3158. delete pFile;
  3159. return sdpIod;
  3160. }
  3161. catch (MP4Error* e) {
  3162. VERBOSE_ERROR(verbosity, e->Print());
  3163. delete e;
  3164. }
  3165. return NULL;
  3166. }
  3167. /* Edit list */
  3168. extern "C" MP4EditId MP4AddTrackEdit(
  3169. MP4FileHandle hFile,
  3170. MP4TrackId trackId,
  3171. MP4EditId editId,
  3172. MP4Timestamp startTime,
  3173. MP4Duration duration,
  3174. bool dwell)
  3175. {
  3176. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3177. try {
  3178. MP4EditId newEditId =
  3179. ((MP4File*)hFile)->AddTrackEdit(trackId, editId);
  3180. if (newEditId != MP4_INVALID_EDIT_ID) {
  3181. ((MP4File*)hFile)->SetTrackEditMediaStart(
  3182. trackId, newEditId, startTime);
  3183. ((MP4File*)hFile)->SetTrackEditDuration(
  3184. trackId, newEditId, duration);
  3185. ((MP4File*)hFile)->SetTrackEditDwell(
  3186. trackId, newEditId, dwell);
  3187. }
  3188. return newEditId;
  3189. }
  3190. catch (MP4Error* e) {
  3191. PRINT_ERROR(e);
  3192. delete e;
  3193. }
  3194. }
  3195. return MP4_INVALID_EDIT_ID;
  3196. }
  3197. extern "C" bool MP4DeleteTrackEdit(
  3198. MP4FileHandle hFile,
  3199. MP4TrackId trackId,
  3200. MP4EditId editId)
  3201. {
  3202. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3203. try {
  3204. ((MP4File*)hFile)->DeleteTrackEdit(trackId, editId);
  3205. return true;
  3206. }
  3207. catch (MP4Error* e) {
  3208. PRINT_ERROR(e);
  3209. delete e;
  3210. }
  3211. }
  3212. return false;
  3213. }
  3214. extern "C" u_int32_t MP4GetTrackNumberOfEdits(
  3215. MP4FileHandle hFile,
  3216. MP4TrackId trackId)
  3217. {
  3218. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3219. try {
  3220. return ((MP4File*)hFile)->GetTrackNumberOfEdits(trackId);
  3221. }
  3222. catch (MP4Error* e) {
  3223. PRINT_ERROR(e);
  3224. delete e;
  3225. }
  3226. }
  3227. return 0;
  3228. }
  3229. extern "C" MP4Timestamp MP4GetTrackEditMediaStart(
  3230. MP4FileHandle hFile,
  3231. MP4TrackId trackId,
  3232. MP4EditId editId)
  3233. {
  3234. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3235. try {
  3236. return ((MP4File*)hFile)->GetTrackEditMediaStart(
  3237. trackId, editId);
  3238. }
  3239. catch (MP4Error* e) {
  3240. PRINT_ERROR(e);
  3241. delete e;
  3242. }
  3243. }
  3244. return MP4_INVALID_TIMESTAMP;
  3245. }
  3246. extern "C" MP4Duration MP4GetTrackEditTotalDuration(
  3247. MP4FileHandle hFile,
  3248. MP4TrackId trackId,
  3249. MP4EditId editId)
  3250. {
  3251. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3252. try {
  3253. return ((MP4File*)hFile)->GetTrackEditTotalDuration(
  3254. trackId, editId);
  3255. }
  3256. catch (MP4Error* e) {
  3257. PRINT_ERROR(e);
  3258. delete e;
  3259. }
  3260. }
  3261. return MP4_INVALID_DURATION;
  3262. }
  3263. extern "C" bool MP4SetTrackEditMediaStart(
  3264. MP4FileHandle hFile,
  3265. MP4TrackId trackId,
  3266. MP4EditId editId,
  3267. MP4Timestamp startTime)
  3268. {
  3269. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3270. try {
  3271. ((MP4File*)hFile)->SetTrackEditMediaStart(
  3272. trackId, editId, startTime);
  3273. return true;
  3274. }
  3275. catch (MP4Error* e) {
  3276. PRINT_ERROR(e);
  3277. delete e;
  3278. }
  3279. }
  3280. return false;
  3281. }
  3282. extern "C" MP4Duration MP4GetTrackEditDuration(
  3283. MP4FileHandle hFile,
  3284. MP4TrackId trackId,
  3285. MP4EditId editId)
  3286. {
  3287. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3288. try {
  3289. return ((MP4File*)hFile)->GetTrackEditDuration(trackId, editId);
  3290. }
  3291. catch (MP4Error* e) {
  3292. PRINT_ERROR(e);
  3293. delete e;
  3294. }
  3295. }
  3296. return MP4_INVALID_DURATION;
  3297. }
  3298. extern "C" bool MP4SetTrackEditDuration(
  3299. MP4FileHandle hFile,
  3300. MP4TrackId trackId,
  3301. MP4EditId editId,
  3302. MP4Duration duration)
  3303. {
  3304. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3305. try {
  3306. ((MP4File*)hFile)->SetTrackEditDuration(trackId, editId, duration);
  3307. return true;
  3308. }
  3309. catch (MP4Error* e) {
  3310. PRINT_ERROR(e);
  3311. delete e;
  3312. }
  3313. }
  3314. return false;
  3315. }
  3316. extern "C" int8_t MP4GetTrackEditDwell(
  3317. MP4FileHandle hFile,
  3318. MP4TrackId trackId,
  3319. MP4EditId editId)
  3320. {
  3321. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3322. try {
  3323. return ((MP4File*)hFile)->GetTrackEditDwell(trackId, editId);
  3324. }
  3325. catch (MP4Error* e) {
  3326. PRINT_ERROR(e);
  3327. delete e;
  3328. }
  3329. }
  3330. return -1;
  3331. }
  3332. extern "C" bool MP4SetTrackEditDwell(
  3333. MP4FileHandle hFile,
  3334. MP4TrackId trackId,
  3335. MP4EditId editId,
  3336. bool dwell)
  3337. {
  3338. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3339. try {
  3340. ((MP4File*)hFile)->SetTrackEditDwell(trackId, editId, dwell);
  3341. return true;
  3342. }
  3343. catch (MP4Error* e) {
  3344. PRINT_ERROR(e);
  3345. delete e;
  3346. }
  3347. }
  3348. return false;
  3349. }
  3350. extern "C" bool MP4ReadSampleFromEditTime(
  3351. /* input parameters */
  3352. MP4FileHandle hFile,
  3353. MP4TrackId trackId,
  3354. MP4Timestamp when,
  3355. /* output parameters */
  3356. u_int8_t** ppBytes,
  3357. u_int32_t* pNumBytes,
  3358. MP4Timestamp* pStartTime,
  3359. MP4Duration* pDuration,
  3360. MP4Duration* pRenderingOffset,
  3361. bool* pIsSyncSample)
  3362. {
  3363. MP4SampleId sampleId =
  3364. MP4GetSampleIdFromEditTime(
  3365. hFile,
  3366. trackId,
  3367. when,
  3368. pStartTime,
  3369. pDuration);
  3370. return MP4ReadSample(
  3371. hFile,
  3372. trackId,
  3373. sampleId,
  3374. ppBytes,
  3375. pNumBytes,
  3376. NULL,
  3377. NULL,
  3378. pRenderingOffset,
  3379. pIsSyncSample);
  3380. }
  3381. extern "C" MP4SampleId MP4GetSampleIdFromEditTime(
  3382. MP4FileHandle hFile,
  3383. MP4TrackId trackId,
  3384. MP4Timestamp when,
  3385. MP4Timestamp* pStartTime,
  3386. MP4Duration* pDuration)
  3387. {
  3388. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3389. try {
  3390. return ((MP4File*)hFile)->GetSampleIdFromEditTime(
  3391. trackId, when, pStartTime, pDuration);
  3392. }
  3393. catch (MP4Error* e) {
  3394. PRINT_ERROR(e);
  3395. delete e;
  3396. }
  3397. }
  3398. return MP4_INVALID_SAMPLE_ID;
  3399. }
  3400. /* Utlities */
  3401. extern "C" char* MP4BinaryToBase16(
  3402. const u_int8_t* pData,
  3403. u_int32_t dataSize)
  3404. {
  3405. if (pData || dataSize == 0) {
  3406. try {
  3407. return MP4ToBase16(pData, dataSize);
  3408. }
  3409. catch (MP4Error* e) {
  3410. delete e;
  3411. }
  3412. }
  3413. return NULL;
  3414. }
  3415. extern "C" char* MP4BinaryToBase64(
  3416. const u_int8_t* pData,
  3417. u_int32_t dataSize)
  3418. {
  3419. if (pData || dataSize == 0) {
  3420. try {
  3421. return MP4ToBase64(pData, dataSize);
  3422. }
  3423. catch (MP4Error* e) {
  3424. delete e;
  3425. }
  3426. }
  3427. return NULL;
  3428. }
  3429. /* iTunes meta data handling */
  3430. extern "C" bool MP4GetMetadataByIndex(MP4FileHandle hFile, u_int32_t index,
  3431. char** ppName,
  3432. u_int8_t** ppValue, u_int32_t* pValueSize)
  3433. {
  3434. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3435. try {
  3436. return ((MP4File*)hFile)->GetMetadataByIndex(
  3437. index, ppName, ppValue, pValueSize);
  3438. }
  3439. catch (MP4Error* e) {
  3440. PRINT_ERROR(e);
  3441. delete e;
  3442. }
  3443. }
  3444. return false;
  3445. }
  3446. extern "C" bool MP4MetadataDelete(MP4FileHandle hFile)
  3447. {
  3448. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3449. try {
  3450. return ((MP4File*)hFile)->MetadataDelete();
  3451. }
  3452. catch (MP4Error* e) {
  3453. PRINT_ERROR(e);
  3454. delete e;
  3455. }
  3456. }
  3457. return false;
  3458. }
  3459. extern "C" bool MP4SetMetadataName(MP4FileHandle hFile,
  3460. const char* value)
  3461. {
  3462. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3463. try {
  3464. return ((MP4File*)hFile)->SetMetadataString("\251nam", value);
  3465. }
  3466. catch (MP4Error* e) {
  3467. PRINT_ERROR(e);
  3468. delete e;
  3469. }
  3470. }
  3471. return false;
  3472. }
  3473. extern "C" bool MP4GetMetadataName(MP4FileHandle hFile,
  3474. char** value)
  3475. {
  3476. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3477. try {
  3478. return ((MP4File*)hFile)->GetMetadataString("\251nam", value);
  3479. }
  3480. catch (MP4Error* e) {
  3481. PRINT_ERROR(e);
  3482. delete e;
  3483. }
  3484. }
  3485. return false;
  3486. }
  3487. extern "C" bool MP4DeleteMetadataName(MP4FileHandle hFile)
  3488. {
  3489. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3490. try {
  3491. return ((MP4File*)hFile)->DeleteMetadataAtom("\251nam");
  3492. }
  3493. catch (MP4Error* e) {
  3494. PRINT_ERROR(e);
  3495. delete e;
  3496. }
  3497. }
  3498. return false;
  3499. }
  3500. extern "C" bool MP4SetMetadataWriter(MP4FileHandle hFile,
  3501. const char* value)
  3502. {
  3503. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3504. try {
  3505. return ((MP4File*)hFile)->SetMetadataString("\251wrt", value);
  3506. }
  3507. catch (MP4Error* e) {
  3508. PRINT_ERROR(e);
  3509. delete e;
  3510. }
  3511. }
  3512. return false;
  3513. }
  3514. extern "C" bool MP4GetMetadataWriter(MP4FileHandle hFile,
  3515. char** value)
  3516. {
  3517. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3518. try {
  3519. return ((MP4File*)hFile)->GetMetadataString("\251wrt", value);
  3520. }
  3521. catch (MP4Error* e) {
  3522. PRINT_ERROR(e);
  3523. delete e;
  3524. }
  3525. }
  3526. return false;
  3527. }
  3528. extern "C" bool MP4DeleteMetadataWriter(MP4FileHandle hFile)
  3529. {
  3530. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3531. try {
  3532. return ((MP4File*)hFile)->DeleteMetadataAtom("\251wrt");
  3533. }
  3534. catch (MP4Error* e) {
  3535. PRINT_ERROR(e);
  3536. delete e;
  3537. }
  3538. }
  3539. return false;
  3540. }
  3541. extern "C" bool MP4SetMetadataAlbum(MP4FileHandle hFile,
  3542. const char* value)
  3543. {
  3544. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3545. try {
  3546. return ((MP4File*)hFile)->SetMetadataString("\251alb", value);
  3547. }
  3548. catch (MP4Error* e) {
  3549. PRINT_ERROR(e);
  3550. delete e;
  3551. }
  3552. }
  3553. return false;
  3554. }
  3555. extern "C" bool MP4GetMetadataAlbum(MP4FileHandle hFile,
  3556. char** value)
  3557. {
  3558. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3559. try {
  3560. return ((MP4File*)hFile)->GetMetadataString("\251alb", value);
  3561. }
  3562. catch (MP4Error* e) {
  3563. PRINT_ERROR(e);
  3564. delete e;
  3565. }
  3566. }
  3567. return false;
  3568. }
  3569. extern "C" bool MP4DeleteMetadataAlbum(MP4FileHandle hFile)
  3570. {
  3571. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3572. try {
  3573. return ((MP4File*)hFile)->DeleteMetadataAtom("\251alb");
  3574. }
  3575. catch (MP4Error* e) {
  3576. PRINT_ERROR(e);
  3577. delete e;
  3578. }
  3579. }
  3580. return false;
  3581. }
  3582. extern "C" bool MP4SetMetadataArtist(MP4FileHandle hFile,
  3583. const char* value)
  3584. {
  3585. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3586. try {
  3587. return ((MP4File*)hFile)->SetMetadataString("\251ART", value);
  3588. }
  3589. catch (MP4Error* e) {
  3590. PRINT_ERROR(e);
  3591. delete e;
  3592. }
  3593. }
  3594. return false;
  3595. }
  3596. extern "C" bool MP4GetMetadataArtist(MP4FileHandle hFile,
  3597. char** value)
  3598. {
  3599. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3600. try {
  3601. return ((MP4File*)hFile)->GetMetadataString("\251ART", value);
  3602. }
  3603. catch (MP4Error* e) {
  3604. PRINT_ERROR(e);
  3605. delete e;
  3606. }
  3607. }
  3608. return false;
  3609. }
  3610. extern "C" bool MP4DeleteMetadataArtist(MP4FileHandle hFile)
  3611. {
  3612. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3613. try {
  3614. return ((MP4File*)hFile)->DeleteMetadataAtom("\251ART");
  3615. }
  3616. catch (MP4Error* e) {
  3617. PRINT_ERROR(e);
  3618. delete e;
  3619. }
  3620. }
  3621. return false;
  3622. }
  3623. extern "C" bool MP4SetMetadataRating(MP4FileHandle hFile,
  3624. const char* value)
  3625. {
  3626. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3627. try {
  3628. return ((MP4File*)hFile)->SetMetadataString("rate", value);
  3629. }
  3630. catch (MP4Error* e) {
  3631. PRINT_ERROR(e);
  3632. delete e;
  3633. }
  3634. }
  3635. return false;
  3636. }
  3637. extern "C" bool MP4GetMetadataRating(MP4FileHandle hFile,
  3638. char** value)
  3639. {
  3640. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3641. try {
  3642. return ((MP4File*)hFile)->GetMetadataString("rate", value);
  3643. }
  3644. catch (MP4Error* e) {
  3645. PRINT_ERROR(e);
  3646. delete e;
  3647. }
  3648. }
  3649. return false;
  3650. }
  3651. extern "C" bool MP4DeleteMetadataRating(MP4FileHandle hFile)
  3652. {
  3653. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3654. try {
  3655. return ((MP4File*)hFile)->DeleteMetadataAtom("rate");
  3656. }
  3657. catch (MP4Error* e) {
  3658. PRINT_ERROR(e);
  3659. delete e;
  3660. }
  3661. }
  3662. return false;
  3663. }
  3664. extern "C" bool MP4SetMetadataTool(MP4FileHandle hFile,
  3665. const char* value)
  3666. {
  3667. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3668. try {
  3669. return ((MP4File*)hFile)->SetMetadataString("\251too", value);
  3670. }
  3671. catch (MP4Error* e) {
  3672. PRINT_ERROR(e);
  3673. delete e;
  3674. }
  3675. }
  3676. return false;
  3677. }
  3678. extern "C" bool MP4GetMetadataTool(MP4FileHandle hFile,
  3679. char** value)
  3680. {
  3681. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3682. try {
  3683. return ((MP4File*)hFile)->GetMetadataString("\251too", value);
  3684. }
  3685. catch (MP4Error* e) {
  3686. PRINT_ERROR(e);
  3687. delete e;
  3688. }
  3689. }
  3690. return false;
  3691. }
  3692. extern "C" bool MP4DeleteMetadataTool(MP4FileHandle hFile)
  3693. {
  3694. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3695. try {
  3696. return ((MP4File*)hFile)->DeleteMetadataAtom("\251too");
  3697. }
  3698. catch (MP4Error* e) {
  3699. PRINT_ERROR(e);
  3700. delete e;
  3701. }
  3702. }
  3703. return false;
  3704. }
  3705. extern "C" bool MP4SetMetadataComment(MP4FileHandle hFile,
  3706. const char* value)
  3707. {
  3708. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3709. try {
  3710. return ((MP4File*)hFile)->SetMetadataString("\251cmt", value);
  3711. }
  3712. catch (MP4Error* e) {
  3713. PRINT_ERROR(e);
  3714. delete e;
  3715. }
  3716. }
  3717. return false;
  3718. }
  3719. extern "C" bool MP4GetMetadataComment(MP4FileHandle hFile,
  3720. char** value)
  3721. {
  3722. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3723. try {
  3724. return ((MP4File*)hFile)->GetMetadataString("\251cmt", value);
  3725. }
  3726. catch (MP4Error* e) {
  3727. PRINT_ERROR(e);
  3728. delete e;
  3729. }
  3730. }
  3731. return false;
  3732. }
  3733. extern "C" bool MP4DeleteMetadataComment(MP4FileHandle hFile)
  3734. {
  3735. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3736. try {
  3737. return ((MP4File*)hFile)->DeleteMetadataAtom("\251cmt");
  3738. }
  3739. catch (MP4Error* e) {
  3740. PRINT_ERROR(e);
  3741. delete e;
  3742. }
  3743. }
  3744. return false;
  3745. }
  3746. extern "C" bool MP4SetMetadataYear(MP4FileHandle hFile,
  3747. const char* value)
  3748. {
  3749. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3750. try {
  3751. return ((MP4File*)hFile)->SetMetadataString("\251day", value);
  3752. }
  3753. catch (MP4Error* e) {
  3754. PRINT_ERROR(e);
  3755. delete e;
  3756. }
  3757. }
  3758. return false;
  3759. }
  3760. extern "C" bool MP4GetMetadataYear(MP4FileHandle hFile,
  3761. char** value)
  3762. {
  3763. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3764. try {
  3765. return ((MP4File*)hFile)->GetMetadataString("\251day", value);
  3766. }
  3767. catch (MP4Error* e) {
  3768. PRINT_ERROR(e);
  3769. delete e;
  3770. }
  3771. }
  3772. return false;
  3773. }
  3774. extern "C" bool MP4DeleteMetadataYear(MP4FileHandle hFile)
  3775. {
  3776. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3777. try {
  3778. return ((MP4File*)hFile)->DeleteMetadataAtom("\251day");
  3779. }
  3780. catch (MP4Error* e) {
  3781. PRINT_ERROR(e);
  3782. delete e;
  3783. }
  3784. }
  3785. return false;
  3786. }
  3787. extern "C" bool MP4SetMetadataTrack(MP4FileHandle hFile,
  3788. u_int16_t track, u_int16_t totalTracks)
  3789. {
  3790. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3791. try {
  3792. return ((MP4File*)hFile)->SetMetadataTrack(track, totalTracks);
  3793. }
  3794. catch (MP4Error* e) {
  3795. PRINT_ERROR(e);
  3796. delete e;
  3797. }
  3798. }
  3799. return false;
  3800. }
  3801. extern "C" bool MP4GetMetadataTrack(MP4FileHandle hFile,
  3802. u_int16_t* track, u_int16_t* totalTracks)
  3803. {
  3804. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3805. try {
  3806. return ((MP4File*)hFile)->GetMetadataTrack(track, totalTracks);
  3807. }
  3808. catch (MP4Error* e) {
  3809. PRINT_ERROR(e);
  3810. delete e;
  3811. }
  3812. }
  3813. return false;
  3814. }
  3815. extern "C" bool MP4DeleteMetadataTrack(MP4FileHandle hFile)
  3816. {
  3817. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3818. try {
  3819. return ((MP4File*)hFile)->DeleteMetadataAtom("trkn");
  3820. }
  3821. catch (MP4Error* e) {
  3822. PRINT_ERROR(e);
  3823. delete e;
  3824. }
  3825. }
  3826. return false;
  3827. }
  3828. extern "C" bool MP4SetMetadataDisk(MP4FileHandle hFile,
  3829. u_int16_t disk, u_int16_t totalDisks)
  3830. {
  3831. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3832. try {
  3833. return ((MP4File*)hFile)->SetMetadataDisk(disk, totalDisks);
  3834. }
  3835. catch (MP4Error* e) {
  3836. PRINT_ERROR(e);
  3837. delete e;
  3838. }
  3839. }
  3840. return false;
  3841. }
  3842. extern "C" bool MP4GetMetadataDisk(MP4FileHandle hFile,
  3843. u_int16_t* disk, u_int16_t* totalDisks)
  3844. {
  3845. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3846. try {
  3847. return ((MP4File*)hFile)->GetMetadataDisk(disk, totalDisks);
  3848. }
  3849. catch (MP4Error* e) {
  3850. PRINT_ERROR(e);
  3851. delete e;
  3852. }
  3853. }
  3854. return false;
  3855. }
  3856. extern "C" bool MP4DeleteMetadataDisk(MP4FileHandle hFile)
  3857. {
  3858. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3859. try {
  3860. return ((MP4File*)hFile)->DeleteMetadataAtom("disk");
  3861. }
  3862. catch (MP4Error* e) {
  3863. PRINT_ERROR(e);
  3864. delete e;
  3865. }
  3866. }
  3867. return false;
  3868. }
  3869. extern "C" bool MP4SetMetadataGenre(MP4FileHandle hFile, const char *genre)
  3870. {
  3871. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3872. try {
  3873. return ((MP4File*)hFile)->SetMetadataGenre(genre);
  3874. }
  3875. catch (MP4Error* e) {
  3876. PRINT_ERROR(e);
  3877. delete e;
  3878. }
  3879. }
  3880. return false;
  3881. }
  3882. extern "C" bool MP4GetMetadataGenre(MP4FileHandle hFile, char **genre)
  3883. {
  3884. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3885. try {
  3886. return ((MP4File*)hFile)->GetMetadataGenre(genre);
  3887. }
  3888. catch (MP4Error* e) {
  3889. PRINT_ERROR(e);
  3890. delete e;
  3891. }
  3892. }
  3893. return false;
  3894. }
  3895. extern "C" bool MP4DeleteMetadataGenre(MP4FileHandle hFile)
  3896. {
  3897. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3898. try {
  3899. return ((MP4File*)hFile)->DeleteMetadataGenre();
  3900. }
  3901. catch (MP4Error* e) {
  3902. PRINT_ERROR(e);
  3903. delete e;
  3904. }
  3905. }
  3906. return false;
  3907. }
  3908. extern "C" bool MP4SetMetadataGrouping(MP4FileHandle hFile, const char *grouping)
  3909. {
  3910. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3911. try {
  3912. return ((MP4File*)hFile)->SetMetadataString("\251grp", grouping);
  3913. }
  3914. catch (MP4Error* e) {
  3915. PRINT_ERROR(e);
  3916. delete e;
  3917. }
  3918. }
  3919. return false;
  3920. }
  3921. extern "C" bool MP4GetMetadataGrouping(MP4FileHandle hFile, char **grouping)
  3922. {
  3923. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3924. try {
  3925. return ((MP4File*)hFile)->GetMetadataString("\251grp", grouping);
  3926. }
  3927. catch (MP4Error* e) {
  3928. PRINT_ERROR(e);
  3929. delete e;
  3930. }
  3931. }
  3932. return false;
  3933. }
  3934. extern "C" bool MP4DeleteMetadataGrouping(MP4FileHandle hFile)
  3935. {
  3936. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3937. try {
  3938. return ((MP4File*)hFile)->DeleteMetadataAtom("\251grp");
  3939. }
  3940. catch (MP4Error* e) {
  3941. PRINT_ERROR(e);
  3942. delete e;
  3943. }
  3944. }
  3945. return false;
  3946. }
  3947. extern "C" bool MP4SetMetadataTempo(MP4FileHandle hFile, u_int16_t tempo)
  3948. {
  3949. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3950. try {
  3951. return ((MP4File*)hFile)->SetMetadataTempo(tempo);
  3952. }
  3953. catch (MP4Error* e) {
  3954. PRINT_ERROR(e);
  3955. delete e;
  3956. }
  3957. }
  3958. return false;
  3959. }
  3960. extern "C" bool MP4GetMetadataTempo(MP4FileHandle hFile, u_int16_t* tempo)
  3961. {
  3962. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3963. try {
  3964. return ((MP4File*)hFile)->GetMetadataTempo(tempo);
  3965. }
  3966. catch (MP4Error* e) {
  3967. PRINT_ERROR(e);
  3968. delete e;
  3969. }
  3970. }
  3971. return false;
  3972. }
  3973. extern "C" bool MP4DeleteMetadataTempo(MP4FileHandle hFile)
  3974. {
  3975. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3976. try {
  3977. return ((MP4File*)hFile)->DeleteMetadataAtom("tmpo");
  3978. }
  3979. catch (MP4Error* e) {
  3980. PRINT_ERROR(e);
  3981. delete e;
  3982. }
  3983. }
  3984. return false;
  3985. }
  3986. extern "C" bool MP4SetMetadataCompilation(MP4FileHandle hFile, u_int8_t cpl)
  3987. {
  3988. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  3989. try {
  3990. return ((MP4File*)hFile)->SetMetadataUint8("cpil", cpl & 0x1);
  3991. }
  3992. catch (MP4Error* e) {
  3993. PRINT_ERROR(e);
  3994. delete e;
  3995. }
  3996. }
  3997. return false;
  3998. }
  3999. extern "C" bool MP4GetMetadataCompilation(MP4FileHandle hFile, u_int8_t* cpl)
  4000. {
  4001. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4002. try {
  4003. return ((MP4File*)hFile)->GetMetadataUint8("cpil", cpl);
  4004. }
  4005. catch (MP4Error* e) {
  4006. PRINT_ERROR(e);
  4007. delete e;
  4008. }
  4009. }
  4010. return false;
  4011. }
  4012. extern "C" bool MP4DeleteMetadataCompilation(MP4FileHandle hFile)
  4013. {
  4014. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4015. try {
  4016. return ((MP4File*)hFile)->DeleteMetadataAtom("cpil");
  4017. }
  4018. catch (MP4Error* e) {
  4019. PRINT_ERROR(e);
  4020. delete e;
  4021. }
  4022. }
  4023. return false;
  4024. }
  4025. extern "C" bool MP4SetMetadataPartOfGaplessAlbum (MP4FileHandle hFile,
  4026. u_int8_t pgap)
  4027. {
  4028. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4029. try {
  4030. return ((MP4File*)hFile)->SetMetadataUint8("pgap", pgap & 0x1);
  4031. }
  4032. catch (MP4Error* e) {
  4033. PRINT_ERROR(e);
  4034. delete e;
  4035. }
  4036. }
  4037. return false;
  4038. }
  4039. extern "C" bool MP4GetMetadataPartOfGaplessAlbum (MP4FileHandle hFile,
  4040. u_int8_t* pgap)
  4041. {
  4042. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4043. try {
  4044. return ((MP4File*)hFile)->GetMetadataUint8("pgap", pgap);
  4045. }
  4046. catch (MP4Error* e) {
  4047. PRINT_ERROR(e);
  4048. delete e;
  4049. }
  4050. }
  4051. return false;
  4052. }
  4053. extern "C" bool MP4DeleteMetadataPartOfGaplessAlbum (MP4FileHandle hFile)
  4054. {
  4055. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4056. try {
  4057. return ((MP4File*)hFile)->DeleteMetadataAtom("pgap");
  4058. }
  4059. catch (MP4Error* e) {
  4060. PRINT_ERROR(e);
  4061. delete e;
  4062. }
  4063. }
  4064. return false;
  4065. }
  4066. extern "C" bool MP4SetMetadataCoverArt(MP4FileHandle hFile, u_int8_t *coverArt, u_int32_t size, int flags)
  4067. {
  4068. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4069. try {
  4070. return ((MP4File*)hFile)->SetMetadataCoverArt(coverArt, size, flags);
  4071. }
  4072. catch (MP4Error* e) {
  4073. PRINT_ERROR(e);
  4074. delete e;
  4075. }
  4076. }
  4077. return false;
  4078. }
  4079. extern "C" bool MP4GetMetadataCoverArt(MP4FileHandle hFile, u_int8_t **coverArt, u_int32_t* size, int *flags, uint32_t index)
  4080. {
  4081. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4082. try {
  4083. return ((MP4File*)hFile)->GetMetadataCoverArt(coverArt, size, index);
  4084. }
  4085. catch (MP4Error* e) {
  4086. PRINT_ERROR(e);
  4087. delete e;
  4088. }
  4089. }
  4090. return false;
  4091. }
  4092. extern "C" u_int32_t MP4GetMetadataCoverArtCount(MP4FileHandle hFile)
  4093. {
  4094. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4095. try {
  4096. return ((MP4File*)hFile)->GetMetadataCoverArtCount();
  4097. }
  4098. catch (MP4Error* e) {
  4099. PRINT_ERROR(e);
  4100. delete e;
  4101. }
  4102. }
  4103. return false;
  4104. }
  4105. extern "C" bool MP4DeleteMetadataCoverArt(MP4FileHandle hFile)
  4106. {
  4107. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4108. try {
  4109. return ((MP4File*)hFile)->DeleteMetadataAtom("covr");
  4110. }
  4111. catch (MP4Error* e) {
  4112. PRINT_ERROR(e);
  4113. delete e;
  4114. }
  4115. }
  4116. return false;
  4117. }
  4118. extern "C" bool MP4SetMetadataAlbumArtist (MP4FileHandle hFile,
  4119. const char* value)
  4120. {
  4121. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4122. try {
  4123. return ((MP4File*)hFile)->SetMetadataString("aART", value);
  4124. }
  4125. catch (MP4Error* e) {
  4126. PRINT_ERROR(e);
  4127. delete e;
  4128. }
  4129. }
  4130. return false;
  4131. }
  4132. extern "C" bool MP4GetMetadataAlbumArtist (MP4FileHandle hFile,
  4133. char** value)
  4134. {
  4135. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4136. try {
  4137. return ((MP4File*)hFile)->GetMetadataString("aART", value);
  4138. }
  4139. catch (MP4Error* e) {
  4140. PRINT_ERROR(e);
  4141. delete e;
  4142. }
  4143. }
  4144. return false;
  4145. }
  4146. extern "C" bool MP4DeleteMetadataAlbumArtist (MP4FileHandle hFile)
  4147. {
  4148. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4149. try {
  4150. return ((MP4File*)hFile)->DeleteMetadataAtom("aART");
  4151. }
  4152. catch (MP4Error* e) {
  4153. PRINT_ERROR(e);
  4154. delete e;
  4155. }
  4156. }
  4157. return false;
  4158. }
  4159. extern "C" bool MP4SetMetadataFreeForm(MP4FileHandle hFile,
  4160. const char *name,
  4161. const u_int8_t* pValue,
  4162. u_int32_t valueSize,
  4163. const char *owner)
  4164. {
  4165. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4166. try {
  4167. return ((MP4File*)hFile)->SetMetadataFreeForm(name, pValue, valueSize, owner);
  4168. }
  4169. catch (MP4Error* e) {
  4170. PRINT_ERROR(e);
  4171. delete e;
  4172. }
  4173. }
  4174. return false;
  4175. }
  4176. extern "C" bool MP4GetMetadataFreeForm(MP4FileHandle hFile, const char *name,
  4177. u_int8_t** pValue, u_int32_t* valueSize, const char *owner)
  4178. {
  4179. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4180. try {
  4181. return ((MP4File*)hFile)->GetMetadataFreeForm(name, pValue, valueSize, owner);
  4182. }
  4183. catch (MP4Error* e) {
  4184. PRINT_ERROR(e);
  4185. delete e;
  4186. }
  4187. }
  4188. return false;
  4189. }
  4190. extern "C" bool MP4DeleteMetadataFreeForm(MP4FileHandle hFile, const char *name, const char *owner)
  4191. {
  4192. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4193. try {
  4194. return ((MP4File*)hFile)->DeleteMetadataFreeForm(name, owner);
  4195. }
  4196. catch (MP4Error* e) {
  4197. PRINT_ERROR(e);
  4198. delete e;
  4199. }
  4200. }
  4201. return false;
  4202. }
  4203. extern "C" bool MP4Get3GPMetadata(MP4FileHandle hFile, const char *name, uint16_t **value)
  4204. {
  4205. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4206. try {
  4207. return ((MP4File*)hFile)->Get3GPMetadataString(name, value);
  4208. }
  4209. catch (MP4Error* e) {
  4210. PRINT_ERROR(e);
  4211. delete e;
  4212. }
  4213. }
  4214. return false;
  4215. }
  4216. extern "C" bool MP4Set3GPMetadata(MP4FileHandle hFile, const char *name, const uint16_t* value)
  4217. {
  4218. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4219. try {
  4220. return ((MP4File*)hFile)->Set3GPMetadataString(name, value);
  4221. }
  4222. catch (MP4Error* e) {
  4223. PRINT_ERROR(e);
  4224. delete e;
  4225. }
  4226. }
  4227. return false;
  4228. }
  4229. extern "C" bool MP4Get3GPMetadataInteger(MP4FileHandle hFile, const char *name, uint64_t *value)
  4230. {
  4231. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4232. try {
  4233. return ((MP4File*)hFile)->Get3GPMetadataInteger(name, value);
  4234. }
  4235. catch (MP4Error* e) {
  4236. PRINT_ERROR(e);
  4237. delete e;
  4238. }
  4239. }
  4240. return false;
  4241. }
  4242. bool MP4Set3GPMetadataInteger(MP4FileHandle hFile, const char *name, uint64_t value)
  4243. {
  4244. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4245. try {
  4246. return ((MP4File*)hFile)->Set3GPMetadataInteger(name, value);
  4247. }
  4248. catch (MP4Error* e) {
  4249. PRINT_ERROR(e);
  4250. delete e;
  4251. }
  4252. }
  4253. return false;
  4254. }
  4255. extern "C" bool MP4Delete3GPMetadata(MP4FileHandle hFile, const char *name)
  4256. {
  4257. if (MP4_IS_VALID_FILE_HANDLE(hFile)) {
  4258. try {
  4259. return ((MP4File*)hFile)->Delete3GPMetadataAtom(name);
  4260. }
  4261. catch (MP4Error* e) {
  4262. PRINT_ERROR(e);
  4263. delete e;
  4264. }
  4265. }
  4266. return false;
  4267. }
  4268. extern "C" void MP4Free (void *p)
  4269. {
  4270. if (p != NULL)
  4271. free(p);
  4272. }