cnm_video_helper.c 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358
  1. /*
  2. * Copyright (c) 2019, Chips&Media
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "main_helper.h"
  26. #include <libavformat/avformat.h>
  27. // include in the ffmpeg header
  28. typedef struct {
  29. CodStd codStd;
  30. Uint32 mp4Class;
  31. Uint32 codecId;
  32. Uint32 fourcc;
  33. } CodStdTab;
  34. #ifndef MKTAG
  35. #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
  36. #endif
  37. static const CodStdTab codstd_tab[] = {
  38. { STD_AVC, 0, AV_CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
  39. { STD_AVC, 0, AV_CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
  40. { STD_AVC, 0, AV_CODEC_ID_H264, MKTAG('A', 'V', 'C', '1') },
  41. { STD_AVC, 0, AV_CODEC_ID_H264, MKTAG('V', 'S', 'S', 'H') },
  42. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
  43. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('X', '2', '6', '3') },
  44. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('T', '2', '6', '3') },
  45. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('L', '2', '6', '3') },
  46. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('V', 'X', '1', 'K') },
  47. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('Z', 'y', 'G', 'o') },
  48. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
  49. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('I', '2', '6', '3') }, /* intel h263 */
  50. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('H', '2', '6', '1') },
  51. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('U', '2', '6', '3') },
  52. { STD_H263, 0, AV_CODEC_ID_H263, MKTAG('V', 'I', 'V', '1') },
  53. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4') },
  54. { STD_MPEG4, 5, AV_CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') }, // DivX 4
  55. { STD_MPEG4, 1, AV_CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0') },
  56. { STD_MPEG4, 2, AV_CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
  57. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
  58. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') }, //MPEG-4 version 2 simple profile
  59. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG( 4 , 0 , 0 , 0 ) }, /* some broken avi use this */
  60. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', '1') },
  61. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('B', 'L', 'Z', '0') },
  62. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'V') },
  63. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('U', 'M', 'P', '4') },
  64. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('W', 'V', '1', 'F') },
  65. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('S', 'E', 'D', 'G') },
  66. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('R', 'M', 'P', '4') },
  67. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('3', 'I', 'V', '2') },
  68. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('F', 'F', 'D', 'S') },
  69. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('F', 'V', 'F', 'W') },
  70. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('D', 'C', 'O', 'D') },
  71. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('M', 'V', 'X', 'M') },
  72. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('P', 'M', '4', 'V') },
  73. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('S', 'M', 'P', '4') },
  74. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('D', 'X', 'G', 'M') },
  75. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('V', 'I', 'D', 'M') },
  76. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'T', '3') },
  77. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'X') },
  78. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('H', 'D', 'X', '4') }, /* flipped video */
  79. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('D', 'M', 'K', '2') },
  80. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('D', 'I', 'G', 'I') },
  81. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('I', 'N', 'M', 'C') },
  82. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('E', 'P', 'H', 'V') }, /* Ephv MPEG-4 */
  83. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('E', 'M', '4', 'A') },
  84. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('M', '4', 'C', 'C') }, /* Divio MPEG-4 */
  85. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('S', 'N', '4', '0') },
  86. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('V', 'S', 'P', 'X') },
  87. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('U', 'L', 'D', 'X') },
  88. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'V') },
  89. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG('S', 'I', 'P', 'P') }, /* Samsung SHR-6040 */
  90. { STD_DIV3, 0, AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') }, /* default signature when using MSMPEG4 */
  91. { STD_DIV3, 0, AV_CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
  92. { STD_DIV3, 0, AV_CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') },
  93. { STD_MPEG4, 1, AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') },
  94. { STD_MPEG4, 1, AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '6') },
  95. { STD_MPEG4, 5, AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '4') },
  96. { STD_DIV3, 0, AV_CODEC_ID_MSMPEG4V3, MKTAG('D', 'V', 'X', '3') },
  97. { STD_DIV3, 0, AV_CODEC_ID_MSMPEG4V3, MKTAG('A', 'P', '4', '1') }, //Another hacked version of Microsoft's MP43 codec.
  98. { STD_MPEG4, 0, AV_CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '1') },
  99. { STD_MPEG4, 0, AV_CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '0') }, // not support ms mpeg4 v1, 2
  100. { STD_MPEG4, 256, AV_CODEC_ID_FLV1, MKTAG('F', 'L', 'V', '1') }, /* Sorenson spark */
  101. { STD_VC1, 0, AV_CODEC_ID_WMV1, MKTAG('W', 'M', 'V', '1') },
  102. { STD_VC1, 0, AV_CODEC_ID_WMV2, MKTAG('W', 'M', 'V', '2') },
  103. { STD_MPEG2, 0, AV_CODEC_ID_MPEG1VIDEO, MKTAG('M', 'P', 'G', '1') },
  104. { STD_MPEG2, 0, AV_CODEC_ID_MPEG1VIDEO, MKTAG('M', 'P', 'G', '2') },
  105. { STD_MPEG2, 0, AV_CODEC_ID_MPEG2VIDEO, MKTAG('M', 'P', 'G', '2') },
  106. { STD_MPEG2, 0, AV_CODEC_ID_MPEG2VIDEO, MKTAG('M', 'P', 'E', 'G') },
  107. { STD_MPEG2, 0, AV_CODEC_ID_MPEG1VIDEO, MKTAG('M', 'P', '2', 'V') },
  108. { STD_MPEG2, 0, AV_CODEC_ID_MPEG1VIDEO, MKTAG('P', 'I', 'M', '1') },
  109. { STD_MPEG2, 0, AV_CODEC_ID_MPEG2VIDEO, MKTAG('P', 'I', 'M', '2') },
  110. { STD_MPEG2, 0, AV_CODEC_ID_MPEG1VIDEO, MKTAG('V', 'C', 'R', '2') },
  111. { STD_MPEG2, 0, AV_CODEC_ID_MPEG1VIDEO, MKTAG( 1 , 0 , 0 , 16) },
  112. { STD_MPEG2, 0, AV_CODEC_ID_MPEG2VIDEO, MKTAG( 2 , 0 , 0 , 16) },
  113. { STD_MPEG4, 0, AV_CODEC_ID_MPEG4, MKTAG( 4 , 0 , 0 , 16) },
  114. { STD_MPEG2, 0, AV_CODEC_ID_MPEG2VIDEO, MKTAG('D', 'V', 'R', ' ') },
  115. { STD_MPEG2, 0, AV_CODEC_ID_MPEG2VIDEO, MKTAG('M', 'M', 'E', 'S') },
  116. { STD_MPEG2, 0, AV_CODEC_ID_MPEG2VIDEO, MKTAG('L', 'M', 'P', '2') }, /* Lead MPEG2 in avi */
  117. { STD_MPEG2, 0, AV_CODEC_ID_MPEG2VIDEO, MKTAG('S', 'L', 'I', 'F') },
  118. { STD_MPEG2, 0, AV_CODEC_ID_MPEG2VIDEO, MKTAG('E', 'M', '2', 'V') },
  119. { STD_VC1, 0, AV_CODEC_ID_WMV3, MKTAG('W', 'M', 'V', '3') },
  120. { STD_VC1, 0, AV_CODEC_ID_VC1, MKTAG('W', 'V', 'C', '1') },
  121. { STD_VC1, 0, AV_CODEC_ID_VC1, MKTAG('W', 'M', 'V', 'A') },
  122. { STD_RV, 0, AV_CODEC_ID_RV30, MKTAG('R','V','3','0') },
  123. { STD_RV, 0, AV_CODEC_ID_RV40, MKTAG('R','V','4','0') },
  124. { STD_AVS, 0, AV_CODEC_ID_CAVS, MKTAG('C','A','V','S') },
  125. { STD_AVS, 0, AV_CODEC_ID_AVS, MKTAG('A','V','S','2') },
  126. { STD_VP3, 0, AV_CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
  127. { STD_VP3, 0, AV_CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
  128. { STD_THO, 0, AV_CODEC_ID_THEORA, MKTAG('T', 'H', 'E', 'O') },
  129. { STD_VP8, 0, AV_CODEC_ID_VP8, MKTAG('V', 'P', '8', '0') },
  130. { STD_VP9, 0, AV_CODEC_ID_VP9, MKTAG('V', 'P', '9', '0') },
  131. // { STD_VP6, 0, AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', '0') },
  132. // { STD_VP6, 0, AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', '1') },
  133. // { STD_VP6, 0, AV_CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') },
  134. // { STD_VP6, 0, AV_CODEC_ID_VP6F, MKTAG('V', 'P', '6', 'F') },
  135. // { STD_VP6, 0, AV_CODEC_ID_VP6F, MKTAG('F', 'L', 'V', '4') },
  136. { STD_HEVC, 0, AV_CODEC_ID_HEVC, MKTAG('H', 'E', 'V', 'C') },
  137. { STD_HEVC, 0, AV_CODEC_ID_HEVC, MKTAG('H', 'E', 'V', '1') },
  138. { STD_HEVC, 0, AV_CODEC_ID_HEVC, MKTAG('H', 'V', 'C', '1') },
  139. { STD_HEVC, 0, AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', 'c') },
  140. { STD_HEVC, 0, AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', '1') },
  141. { STD_HEVC, 0, AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1') }
  142. };
  143. static BOOL CalcYuvSize_412(
  144. Int32 format,
  145. Int32 picWidth,
  146. Int32 picHeight,
  147. Int32 cbcrInterleave,
  148. size_t *lumaSize,
  149. size_t *chromaSize,
  150. size_t *frameSize,
  151. Int32 *bitDepth,
  152. Int32 *packedFormat,
  153. Int32 *yuv3p4b);
  154. static void GeneratePicParam(
  155. FrameBuffer* fbSrc,
  156. VpuRect cropRect,
  157. BOOL enableCrop,
  158. Uint32* is422,
  159. Uint32* isPack,
  160. Uint32* PackMode,
  161. Uint32* is10bit,
  162. Uint32* isMSB,
  163. Uint32* is3pxl4byte,
  164. Uint32* srcWidthY,
  165. Uint32* srcHeightY,
  166. Uint32* srcWidthC,
  167. Uint32* srcHeightC,
  168. Uint32* chroma_stride,
  169. Uint32* dstWidthY,
  170. Uint32* dstHeightY,
  171. Uint32* dstWidthC,
  172. Uint32* dstHeightC);
  173. static void LoadSrcYUV(
  174. Uint32 coreIdx,
  175. TiledMapConfig mapCfg,
  176. Uint8* pSrc,
  177. FrameBuffer* fbSrc,
  178. VpuRect cropRect,
  179. BOOL enableCrop,
  180. Uint32 is10bit,
  181. Uint32 is3pxl4byte,
  182. Uint32 isMSB,
  183. Uint32 srcWidthY,
  184. Uint32 srcHeightY,
  185. Uint32 srcWidthC,
  186. Uint32 srcHeightC,
  187. Uint32 chroma_stride);
  188. void LoadSrcYUV2(
  189. Uint32 coreIdx,
  190. TiledMapConfig mapCfg,
  191. Uint8* pSrc,
  192. Uint8** pSrc2,
  193. FrameBuffer* fbSrc,
  194. VpuRect cropRect,
  195. BOOL enableCrop,
  196. Uint32 is10bit,
  197. Uint32 is3pxl4byte,
  198. Uint32 isMSB,
  199. Uint32 srcWidthY,
  200. Uint32 srcHeightY,
  201. Uint32 srcWidthC,
  202. Uint32 srcHeightC,
  203. Uint32 chroma_stride
  204. );
  205. static void DePackedYUV(
  206. Uint32 is10bit,
  207. Uint32 PackMode,
  208. Uint32 srcWidthY,
  209. Uint32 srcHeightY,
  210. Uint8* pSrc,
  211. Uint32 dstWidthY,
  212. Uint32 dstHeightY,
  213. Uint32 dstWidthC,
  214. Uint32 dstHeightC,
  215. Uint8* pDst);
  216. static void Convert422to420(
  217. Uint8* pSrc,
  218. Uint32 dstWidthY,
  219. Uint32 dstHeightY,
  220. Uint32 dstWidthC,
  221. Uint32 dstHeightC,
  222. Uint8* pDst);
  223. static void DeFormatYUV(
  224. Uint32 is3pixel4byte,
  225. Uint32 isMSB,
  226. Uint32 interleave,
  227. Uint32 srcWidthY,
  228. Uint32 srcHeightY,
  229. Uint32 srcWidthC,
  230. Uint32 srcHeightC,
  231. Uint32 dstWidthY,
  232. Uint32 dstWidthC,
  233. Uint8* pSrc,
  234. Uint8* pDst);
  235. static void ByteSwap10bit(
  236. Uint32 DstSize,
  237. Uint8* pSrc,
  238. Uint8* pDst);
  239. static void DeInterLeave(
  240. Uint32 is10bit,
  241. BOOL nv21,
  242. Uint32 srcWidthY,
  243. Uint32 srcHeightY,
  244. Uint32 srcWidthC,
  245. Uint32 srcHeightC,
  246. Uint8* pSrc,
  247. Uint8* pDst);
  248. Int32 ConvFOURCCToMp4Class(
  249. Int32 fourcc
  250. )
  251. {
  252. Uint32 i;
  253. Int32 mp4Class = -1;
  254. unsigned char str[5];
  255. str[0] = toupper((Int32)fourcc);
  256. str[1] = toupper((Int32)(fourcc>>8));
  257. str[2] = toupper((Int32)(fourcc>>16));
  258. str[3] = toupper((Int32)(fourcc>>24));
  259. str[4] = '\0';
  260. for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
  261. if (codstd_tab[i].fourcc == (Int32)MKTAG(str[0], str[1], str[2], str[3]) ) {
  262. mp4Class = codstd_tab[i].mp4Class;
  263. break;
  264. }
  265. }
  266. return mp4Class;
  267. }
  268. Int32 ConvFOURCCToCodStd(
  269. Uint32 fourcc
  270. )
  271. {
  272. Int32 codStd = -1;
  273. Uint32 i;
  274. char str[5];
  275. str[0] = toupper((Int32)fourcc);
  276. str[1] = toupper((Int32)(fourcc>>8));
  277. str[2] = toupper((Int32)(fourcc>>16));
  278. str[3] = toupper((Int32)(fourcc>>24));
  279. str[4] = '\0';
  280. for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
  281. if (codstd_tab[i].fourcc == (Uint32)MKTAG(str[0], str[1], str[2], str[3])) {
  282. codStd = codstd_tab[i].codStd;
  283. break;
  284. }
  285. }
  286. return codStd;
  287. }
  288. Int32 ConvCodecIdToMp4Class(
  289. Uint32 codecId
  290. )
  291. {
  292. Int32 mp4Class = -1;
  293. Uint32 i;
  294. for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
  295. if (codstd_tab[i].codecId == codecId) {
  296. mp4Class = codstd_tab[i].mp4Class;
  297. break;
  298. }
  299. }
  300. return mp4Class;
  301. }
  302. Int32 ConvCodecIdToCodStd(
  303. Int32 codecId
  304. )
  305. {
  306. Int32 codStd = -1;
  307. Uint32 i;
  308. for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
  309. if (codstd_tab[i].codecId == codecId) {
  310. codStd = codstd_tab[i].codStd;
  311. break;
  312. }
  313. }
  314. return codStd;
  315. }
  316. Int32 ConvCodecIdToFourcc(
  317. Int32 codecId
  318. )
  319. {
  320. Int32 fourcc = 0;
  321. Uint32 i;
  322. for(i=0; i<sizeof(codstd_tab)/sizeof(codstd_tab[0]); i++) {
  323. if (codstd_tab[i].codecId == codecId) {
  324. fourcc = codstd_tab[i].fourcc;
  325. break;
  326. }
  327. }
  328. return fourcc;
  329. }
  330. BOOL LoadYuvImageByYCbCrLine(
  331. EncHandle handle,
  332. Uint32 coreIdx,
  333. Uint8* src,
  334. size_t picWidth,
  335. size_t picHeight,
  336. FrameBuffer* fb,
  337. Uint32 srcFbIndex
  338. )
  339. {
  340. Int32 y, nY, nCb;
  341. PhysicalAddress addrY, addrCb, addrCr;
  342. size_t lumaSize, chromaSize=0, chromaStride = 0, chromaWidth=0;
  343. Uint8 *srcY, *srcCb, *srcCr;
  344. size_t stride = fb->stride;
  345. EndianMode endian = (EndianMode)fb->endian;
  346. FrameBufferFormat format = fb->format;
  347. BOOL interLeave = fb->cbcrInterleave;
  348. int twice = 1 << interLeave;
  349. int cnt=0;
  350. Uint32 YStartPos=0;
  351. switch (format) {
  352. case FORMAT_420:
  353. nY = picHeight;
  354. nCb = picHeight / 2;
  355. chromaSize = picWidth * picHeight / 4;
  356. chromaStride = stride / 2;
  357. chromaWidth = picWidth / 2;
  358. break;
  359. case FORMAT_224:
  360. nY = picHeight;
  361. nCb = picHeight / 2;
  362. chromaSize = picWidth * picHeight / 2;
  363. chromaStride = stride;
  364. chromaWidth = picWidth;
  365. break;
  366. case FORMAT_422:
  367. nY = picHeight;
  368. nCb = picHeight;
  369. chromaSize = picWidth * picHeight / 2;
  370. chromaStride = stride / 2;
  371. chromaWidth = picWidth / 2;
  372. break;
  373. case FORMAT_444:
  374. nY = picHeight;
  375. nCb = picHeight;
  376. chromaSize = picWidth * picHeight;
  377. chromaStride = stride;
  378. chromaWidth = picWidth;
  379. break;
  380. case FORMAT_400:
  381. nY = picHeight;
  382. nCb = 0;
  383. chromaSize = picWidth * picHeight / 4;
  384. chromaStride = stride / 2;
  385. chromaWidth = picWidth / 2;
  386. break;
  387. case FORMAT_YUYV:
  388. case FORMAT_YVYU:
  389. case FORMAT_UYVY:
  390. case FORMAT_VYUY:
  391. case FORMAT_YUYV_P10_16BIT_MSB:
  392. case FORMAT_YUYV_P10_16BIT_LSB:
  393. case FORMAT_YUYV_P10_32BIT_MSB:
  394. case FORMAT_YUYV_P10_32BIT_LSB:
  395. case FORMAT_YVYU_P10_16BIT_MSB:
  396. case FORMAT_YVYU_P10_16BIT_LSB:
  397. case FORMAT_YVYU_P10_32BIT_MSB:
  398. case FORMAT_YVYU_P10_32BIT_LSB:
  399. case FORMAT_UYVY_P10_16BIT_MSB:
  400. case FORMAT_UYVY_P10_16BIT_LSB:
  401. case FORMAT_UYVY_P10_32BIT_MSB:
  402. case FORMAT_UYVY_P10_32BIT_LSB:
  403. case FORMAT_VYUY_P10_16BIT_MSB:
  404. case FORMAT_VYUY_P10_16BIT_LSB:
  405. case FORMAT_VYUY_P10_32BIT_MSB:
  406. case FORMAT_VYUY_P10_32BIT_LSB:
  407. nY = picHeight;
  408. nCb = 0;
  409. break;
  410. case FORMAT_420_P10_16BIT_LSB:
  411. case FORMAT_420_P10_16BIT_MSB:
  412. nY = picHeight;
  413. nCb = picHeight/2;
  414. chromaSize = picWidth * picHeight/2;
  415. chromaStride = stride / 2;
  416. chromaWidth = picWidth;
  417. picWidth *= 2;
  418. break;
  419. case FORMAT_420_P10_32BIT_LSB:
  420. case FORMAT_420_P10_32BIT_MSB:
  421. nY = picHeight;
  422. nCb = picHeight/2;
  423. picWidth = VPU_ALIGN32(picWidth);
  424. chromaWidth = ((VPU_ALIGN16(picWidth/2*twice)+2)/3*4);
  425. chromaStride = VPU_ALIGN16(stride/2)*twice;
  426. if ( interLeave == 1)
  427. chromaStride = stride;
  428. chromaSize = chromaWidth * picHeight/2;
  429. picWidth = ((VPU_ALIGN16(picWidth)+2)/3)*4;
  430. break;
  431. default:
  432. nY = picHeight;
  433. nCb = picHeight / 2;
  434. chromaSize = picWidth * picHeight / 4;
  435. chromaStride = stride / 2;
  436. chromaWidth = picWidth / 2;
  437. break;
  438. }
  439. lumaSize = picWidth * picHeight;
  440. srcY = src;
  441. srcCb = src + lumaSize;
  442. srcCr = src + lumaSize + chromaSize;
  443. addrY = fb->bufY;
  444. addrCb = fb->bufCb;
  445. addrCr = fb->bufCr;
  446. if ( nCb )
  447. cnt = nY / nCb;
  448. for (y = YStartPos; y < nY; ++y) {
  449. vdi_write_memory(coreIdx, addrY + stride * y, (Uint8 *)(srcY + y * picWidth), picWidth, endian);
  450. if (format == FORMAT_400) {
  451. continue;
  452. }
  453. if (format >= FORMAT_YUYV && format <= FORMAT_VYUY_P10_32BIT_LSB) {
  454. continue;
  455. }
  456. if (interLeave == TRUE) {
  457. if (cnt == 2 && ((y%2)==0))
  458. vdi_write_memory(coreIdx, addrCb + stride * y/cnt, (Uint8 *)(srcCb+ y/cnt * picWidth), picWidth, endian);
  459. }
  460. else {
  461. if (cnt == 2 && ((y%2)==0)) {
  462. vdi_write_memory(coreIdx, addrCb + chromaStride * y/cnt, (Uint8 *)(srcCb + y/cnt * chromaWidth), chromaWidth, endian);
  463. vdi_write_memory(coreIdx, addrCr + chromaStride * y/cnt, (Uint8 *)(srcCr + y/cnt * chromaWidth), chromaWidth, endian);
  464. }
  465. }
  466. }
  467. return TRUE;//lint !e438
  468. }
  469. //////////////////// DRAM Read/Write helper Function ////////////////////////////
  470. BOOL LoadYuvImageBurstFormat(
  471. Uint32 coreIdx,
  472. Uint8* src,
  473. size_t picWidth,
  474. size_t picHeight,
  475. FrameBuffer* fb,
  476. BOOL convertCbcrIntl
  477. )
  478. {
  479. Int32 y, nY, nCb, nCr;
  480. PhysicalAddress addr;
  481. size_t lumaSize, chromaSize=0, chromaStride = 0, chromaWidth=0;
  482. Uint8* puc;
  483. size_t stride = fb->stride;
  484. EndianMode endian = (EndianMode)fb->endian;
  485. FrameBufferFormat format = fb->format;
  486. BOOL interLeave = fb->cbcrInterleave;
  487. int twice = 1 << interLeave;
  488. switch (format) {
  489. case FORMAT_420:
  490. nY = picHeight;
  491. nCb = nCr = picHeight / 2;
  492. chromaSize = picWidth * picHeight / 4;
  493. chromaStride = stride / 2;
  494. chromaWidth = picWidth / 2;
  495. break;
  496. case FORMAT_224:
  497. nY = picHeight;
  498. nCb = nCr = picHeight / 2;
  499. chromaSize = picWidth * picHeight / 2;
  500. chromaStride = stride;
  501. chromaWidth = picWidth;
  502. break;
  503. case FORMAT_422:
  504. nY = picHeight;
  505. nCb = nCr = picHeight;
  506. chromaSize = picWidth * picHeight / 2;
  507. chromaStride = stride / 2;
  508. chromaWidth = picWidth / 2;
  509. break;
  510. case FORMAT_444:
  511. nY = picHeight;
  512. nCb = nCr = picHeight;
  513. chromaSize = picWidth * picHeight;
  514. chromaStride = stride;
  515. chromaWidth = picWidth;
  516. break;
  517. case FORMAT_400:
  518. nY = picHeight;
  519. nCb = nCr = 0;
  520. chromaSize = picWidth * picHeight / 4;
  521. chromaStride = stride / 2;
  522. chromaWidth = picWidth / 2;
  523. break;
  524. case FORMAT_YUYV:
  525. case FORMAT_YVYU:
  526. case FORMAT_UYVY:
  527. case FORMAT_VYUY:
  528. case FORMAT_YUYV_P10_16BIT_MSB:
  529. case FORMAT_YUYV_P10_16BIT_LSB:
  530. case FORMAT_YUYV_P10_32BIT_MSB:
  531. case FORMAT_YUYV_P10_32BIT_LSB:
  532. case FORMAT_YVYU_P10_16BIT_MSB:
  533. case FORMAT_YVYU_P10_16BIT_LSB:
  534. case FORMAT_YVYU_P10_32BIT_MSB:
  535. case FORMAT_YVYU_P10_32BIT_LSB:
  536. case FORMAT_UYVY_P10_16BIT_MSB:
  537. case FORMAT_UYVY_P10_16BIT_LSB:
  538. case FORMAT_UYVY_P10_32BIT_MSB:
  539. case FORMAT_UYVY_P10_32BIT_LSB:
  540. case FORMAT_VYUY_P10_16BIT_MSB:
  541. case FORMAT_VYUY_P10_16BIT_LSB:
  542. case FORMAT_VYUY_P10_32BIT_MSB:
  543. case FORMAT_VYUY_P10_32BIT_LSB:
  544. nY = picHeight;
  545. nCb = nCr = 0;
  546. break;
  547. case FORMAT_420_P10_16BIT_LSB:
  548. case FORMAT_420_P10_16BIT_MSB:
  549. nY = picHeight;
  550. nCb = nCr = picHeight/2;
  551. chromaSize = picWidth * picHeight/2;
  552. chromaStride = stride / 2;
  553. chromaWidth = picWidth;
  554. picWidth *= 2;
  555. break;
  556. case FORMAT_420_P10_32BIT_LSB:
  557. case FORMAT_420_P10_32BIT_MSB:
  558. nY = picHeight;
  559. nCb = nCr = picHeight/2;
  560. picWidth = VPU_ALIGN32(picWidth);
  561. chromaWidth = ((VPU_ALIGN16(picWidth/2*twice)+2)/3*4);
  562. chromaStride = VPU_ALIGN16(stride/2)*twice;
  563. if ( interLeave == 1)
  564. chromaStride = stride;
  565. chromaSize = chromaWidth * picHeight/2;
  566. picWidth = ((VPU_ALIGN16(picWidth)+2)/3)*4;
  567. break;
  568. default:
  569. nY = picHeight;
  570. nCb = nCr = picHeight / 2;
  571. chromaSize = picWidth * picHeight / 4;
  572. chromaStride = stride / 2;
  573. chromaWidth = picWidth / 2;
  574. break;
  575. }
  576. puc = src;
  577. addr = fb->bufY;
  578. lumaSize = picWidth * picHeight;
  579. if( picWidth == stride) { // for fast write
  580. vdi_write_memory(coreIdx, addr, (Uint8 *)( puc ), lumaSize, endian);
  581. if( format == FORMAT_400)
  582. return FALSE;
  583. if (format >= FORMAT_YUYV && format <= FORMAT_VYUY_P10_32BIT_LSB)
  584. return FALSE;
  585. if (interLeave == TRUE) {
  586. UNREFERENCED_PARAMETER(convertCbcrIntl);
  587. puc = src + lumaSize;
  588. addr = fb->bufCb;
  589. vdi_write_memory(coreIdx, addr, (Uint8 *)puc, chromaSize*2, endian);
  590. }
  591. else {
  592. if ( chromaWidth == chromaStride )
  593. {
  594. puc = src + lumaSize;
  595. addr = fb->bufCb;
  596. vdi_write_memory(coreIdx, addr, (Uint8 *)puc, chromaSize, endian);
  597. puc = src + lumaSize + chromaSize;
  598. addr = fb->bufCr;
  599. vdi_write_memory(coreIdx, addr, (Uint8 *)puc, chromaSize, endian);
  600. }
  601. else
  602. {
  603. puc = src + lumaSize;
  604. addr = fb->bufCb;
  605. for (y = 0; y < nCb; ++y) {
  606. vdi_write_memory(coreIdx, addr + chromaStride * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
  607. }
  608. puc = src + lumaSize + chromaSize;
  609. addr = fb->bufCr;
  610. for (y = 0; y < nCr; ++y) {
  611. vdi_write_memory(coreIdx, addr + chromaStride * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
  612. }
  613. }
  614. }
  615. }
  616. else {
  617. for (y = 0; y < nY; ++y) {
  618. vdi_write_memory(coreIdx, addr + stride * y, (Uint8 *)(puc + y * picWidth), picWidth, endian);
  619. }
  620. if (format == FORMAT_400) {
  621. return FALSE;
  622. }
  623. if (format >= FORMAT_YUYV && format <= FORMAT_VYUY_P10_32BIT_LSB) {
  624. return FALSE;
  625. }
  626. if (interLeave == TRUE) {
  627. UNREFERENCED_PARAMETER(convertCbcrIntl);
  628. puc = src + lumaSize;
  629. addr = fb->bufCb;
  630. for (y = 0; y < nCb; ++y) {
  631. vdi_write_memory(coreIdx, addr + stride * y, (Uint8 *)(puc + y * picWidth), picWidth, endian);
  632. }
  633. }
  634. else {
  635. puc = src + lumaSize;
  636. addr = fb->bufCb;
  637. for (y = 0; y < nCb; ++y) {
  638. vdi_write_memory(coreIdx, addr + chromaStride * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
  639. }
  640. puc = src + lumaSize + chromaSize;
  641. addr = fb->bufCr;
  642. for (y = 0; y < nCr; ++y) {
  643. vdi_write_memory(coreIdx, addr + chromaStride * y, (Uint8 *)(puc + y * chromaWidth), chromaWidth, endian);
  644. }
  645. }
  646. }
  647. return TRUE;//lint !e438
  648. }
  649. BOOL LoadTiledImageYuvBurst(
  650. VpuHandle handle,
  651. Uint32 coreIdx,
  652. BYTE* pYuv,
  653. size_t picWidth,
  654. size_t picHeight,
  655. FrameBuffer* fb,
  656. TiledMapConfig mapCfg
  657. )
  658. {
  659. BYTE *pSrc;
  660. size_t divX, divY;
  661. PhysicalAddress pix_addr;
  662. size_t rrow, ccol;
  663. size_t offsetX,offsetY;
  664. size_t stride_c;
  665. size_t stride = fb->stride;
  666. EndianMode endian = (EndianMode)fb->endian;
  667. FrameBufferFormat format = fb->format;
  668. BOOL interLeave = fb->cbcrInterleave;
  669. Int32 productId;
  670. Int32 dramBusWidth = 8;
  671. productId = VPU_GetProductId(coreIdx);
  672. if (PRODUCT_ID_W_SERIES(productId)) {
  673. dramBusWidth = 16;
  674. }
  675. offsetX = offsetY = 0;
  676. divX = format == FORMAT_420 || format == FORMAT_422 ? 2 : 1;
  677. divY = format == FORMAT_420 || format == FORMAT_224 ? 2 : 1;
  678. switch (format) {
  679. case FORMAT_400:
  680. stride_c = 0;
  681. break;
  682. case FORMAT_420:
  683. case FORMAT_422:
  684. stride_c = stride / 2;
  685. break;
  686. case FORMAT_224:
  687. case FORMAT_444:
  688. stride_c = stride;
  689. break;
  690. default:
  691. stride_c = stride / 2;
  692. break;
  693. }
  694. // Y
  695. pSrc = pYuv;
  696. // no opt code
  697. for (rrow=0; rrow <picHeight; rrow=rrow+1)
  698. {
  699. for (ccol=0; ccol<picWidth; ccol=ccol+dramBusWidth)
  700. {
  701. pix_addr = GetXY2AXIAddr(&mapCfg, 0/*luma*/, rrow +offsetY, ccol + offsetX, stride, fb);
  702. vdi_write_memory(coreIdx, pix_addr, pSrc+rrow*picWidth+ccol, 8, endian);
  703. }
  704. }
  705. if (format == FORMAT_400) {
  706. return 1;
  707. }
  708. if (interLeave == FALSE) {
  709. // CB
  710. pSrc = pYuv + picWidth*picHeight;
  711. for (rrow=0; rrow <(picHeight/divY) ; rrow=rrow+1) {
  712. for (ccol=0; ccol<(picWidth/divX); ccol=ccol+dramBusWidth) {
  713. pix_addr = GetXY2AXIAddr(&mapCfg, 2, rrow + offsetY, ccol +offsetX, stride_c, fb);
  714. vdi_write_memory(coreIdx, pix_addr, pSrc+rrow*picWidth/divX+ccol, 8, endian);
  715. }
  716. }
  717. // CR
  718. pSrc = pYuv + picWidth*picHeight+ (picWidth/divX)*(picHeight/divY);
  719. for (rrow=0; rrow <picHeight/divY ; rrow=rrow+1) {
  720. for (ccol=0; ccol<picWidth/divX; ccol=ccol+dramBusWidth) {
  721. pix_addr = GetXY2AXIAddr(&mapCfg, 3, rrow + offsetY ,ccol +offsetX, stride_c, fb);
  722. vdi_write_memory(coreIdx, pix_addr, pSrc+rrow*picWidth/divX+ccol, 8, endian);
  723. }
  724. }
  725. }
  726. else {
  727. BYTE * pTemp;
  728. BYTE * srcAddrCb;
  729. BYTE * srcAddrCr;
  730. size_t cbcr_x;
  731. switch( format) {
  732. case FORMAT_444 :
  733. cbcr_x = picWidth*2;
  734. break;
  735. case FORMAT_420 :
  736. cbcr_x = picWidth ;
  737. break;
  738. case FORMAT_422 :
  739. cbcr_x = picWidth ;
  740. break;
  741. case FORMAT_224 :
  742. cbcr_x = picWidth*2;
  743. break;
  744. default:
  745. cbcr_x = picWidth ;
  746. break;
  747. }
  748. stride = stride_c * 2;
  749. srcAddrCb = pYuv + picWidth*picHeight;
  750. srcAddrCr = pYuv + picWidth*picHeight + picWidth/divX*picHeight/divY;
  751. pTemp = (BYTE*)osal_malloc(sizeof(char)*8);
  752. if (!pTemp) {
  753. return FALSE;
  754. }
  755. for (rrow=0; rrow <picHeight/divY; rrow=rrow+1) {
  756. for (ccol=0; ccol<cbcr_x ; ccol=ccol+dramBusWidth) {
  757. pTemp[0 ] = *srcAddrCb++;
  758. pTemp[0+2] = *srcAddrCb++;
  759. pTemp[0+4] = *srcAddrCb++;
  760. pTemp[0+6] = *srcAddrCb++;
  761. pTemp[0+1] = *srcAddrCr++;
  762. pTemp[0+3] = *srcAddrCr++;
  763. pTemp[0+5] = *srcAddrCr++;
  764. pTemp[0+7] = *srcAddrCr++;
  765. pix_addr = GetXY2AXIAddr(&mapCfg, 2, rrow + offsetY ,ccol + (offsetX*2), stride, fb);
  766. vdi_write_memory(coreIdx, pix_addr, (unsigned char *)pTemp, 8, endian);
  767. }
  768. }
  769. osal_free(pTemp);
  770. }
  771. return TRUE;
  772. }
  773. static void SwapDword(unsigned char* data, int len)
  774. {
  775. Uint32 temp;
  776. Uint32* ptr = (Uint32*)data;
  777. Int32 i, size = len/sizeof(Uint32);
  778. for (i=0; i<size; i+=2) {
  779. temp = ptr[i];
  780. ptr[i] = ptr[i+1];
  781. ptr[i+1] = temp;
  782. }
  783. }
  784. static void SwapLword(unsigned char* data, int len)
  785. {
  786. Uint64 temp;
  787. Uint64* ptr = (Uint64*)data;
  788. Int32 i, size = len/sizeof(Uint64);
  789. for (i=0; i<size; i+=2) {
  790. temp = ptr[i];
  791. ptr[i] = ptr[i+1];
  792. ptr[i+1] = temp;
  793. }
  794. }
  795. static void SwapPixelOrder(
  796. Uint8* data
  797. )
  798. {
  799. Uint32* temp;
  800. Uint32 temp2[4]={0,};
  801. Int32 i,j;
  802. for (i=0, j=3 ; i < 16 ; i+=4, j--) {
  803. temp = (Uint32*)(data+i);
  804. temp2[j] = (*temp & 0xffc00000)>>20;
  805. temp2[j] |= (*temp & 0x003ff000);
  806. temp2[j] |= (*temp & 0x00000ffc)<<20;
  807. }
  808. osal_memcpy(data, temp2, 16);
  809. //for matching with Ref-C
  810. SwapDword(data, 16);
  811. SwapLword(data, 16);
  812. }
  813. Uint32 StoreYuvImageBurst(
  814. Uint32 coreIdx,
  815. FrameBuffer *fbSrc,
  816. TiledMapConfig mapCfg,
  817. Uint8 *pDst,
  818. VpuRect cropRect,
  819. BOOL enableCrop
  820. )
  821. {
  822. int interLeave = fbSrc->cbcrInterleave;
  823. BOOL nv21 = fbSrc->nv21;
  824. Uint32 totSize = 0;
  825. Uint32 is422;
  826. Uint32 isPack;
  827. Uint32 PackMode;
  828. Uint32 is10bit;
  829. Uint32 isMSB;
  830. Uint32 is3pxl4byte;
  831. Uint32 srcWidthY;
  832. Uint32 srcHeightY;
  833. Uint32 srcWidthC;
  834. Uint32 srcHeightC;
  835. Uint32 chroma_stride;
  836. Uint32 dstWidthY;
  837. Uint32 dstHeightY;
  838. Uint32 dstWidthC;
  839. Uint32 dstHeightC;
  840. Uint32 DstSize = 0;
  841. Uint32 SrcSize = 0;
  842. Uint8* pSrc = NULL;
  843. Uint8* pSrcFormat;
  844. Uint8* pDstFormat = NULL;
  845. Uint32 deFormatSize = 0;
  846. Uint8* pFormat = NULL;
  847. Uint8* pSrcInterLeave;
  848. Uint8* pDstInterLeave = NULL;
  849. Uint32 InterLeaveSize = 0;
  850. Uint8* pInterLeave = NULL;
  851. Uint8* pSrcPack;
  852. Uint8* pDstPack = NULL;
  853. Uint32 PackSize = 0;
  854. Uint8* pPack = NULL;
  855. Uint8* pSrc422;
  856. Uint8* pDst422 = NULL;
  857. Uint8* pSrcSwap;
  858. Uint8* pDstSwap;
  859. GeneratePicParam(fbSrc, cropRect, enableCrop,
  860. &is422, &isPack, &PackMode, &is10bit, &isMSB, &is3pxl4byte,
  861. &srcWidthY, &srcHeightY, &srcWidthC, &srcHeightC, &chroma_stride,
  862. &dstWidthY, &dstHeightY, &dstWidthC, &dstHeightC);
  863. //1. Source YUV memory allocation
  864. SrcSize = srcWidthY*srcHeightY + srcWidthC*srcHeightC;
  865. if (interLeave != TRUE)
  866. SrcSize += srcWidthC*srcHeightC;
  867. pSrc = (Uint8*)osal_malloc(SrcSize);
  868. if (!pSrc)
  869. return 0;
  870. //2. Destination YUV size
  871. DstSize = dstWidthY*dstHeightY + dstWidthC*dstHeightC * 2;
  872. totSize = DstSize;
  873. //3. Source YUV Load
  874. LoadSrcYUV(coreIdx, mapCfg, pSrc, fbSrc, cropRect, enableCrop,
  875. is10bit, is3pxl4byte, isMSB,
  876. srcWidthY, srcHeightY, srcWidthC, srcHeightC, chroma_stride);
  877. //4. osal_memcpy and termination for 8bit, 420, normal(non packed) YUV
  878. //SrcYUV => DstYUV
  879. #if defined(SAVE_YUV)
  880. osal_memcpy(pDst, pSrc, SrcSize);
  881. totSize = SrcSize;
  882. osal_free(pSrc);
  883. return totSize;
  884. #else
  885. // if dec video format is I420 NV21 NV12, just dump it
  886. if (is10bit != TRUE && is422 != TRUE && isPack != TRUE) {
  887. osal_memcpy(pDst, pSrc, SrcSize);
  888. osal_free(pSrc);
  889. return totSize;
  890. }
  891. #endif
  892. //5. deFormat
  893. //all format for 10bit => 1 pixel 2byte LSB
  894. if (is10bit == TRUE) {
  895. if (is3pxl4byte == TRUE) {
  896. deFormatSize = dstWidthY*srcHeightY + (dstWidthC*srcHeightY * 2);
  897. pFormat = (Uint8*)osal_malloc(deFormatSize);
  898. }
  899. pSrcFormat = pSrc;
  900. pDstFormat = (is3pxl4byte == TRUE) ? pFormat : pSrc;
  901. DeFormatYUV( is3pxl4byte, isMSB, interLeave, srcWidthY, srcHeightY, srcWidthC, srcHeightC,
  902. dstWidthY, dstWidthC, pSrcFormat, pDstFormat);
  903. }
  904. //6. dePack or interleave
  905. //Pack => Normal
  906. //interleave => Normal
  907. if (isPack) {
  908. //pPack allocation
  909. PackSize = dstWidthY*dstHeightY + dstWidthC*dstHeightY * 2;
  910. pPack = (Uint8*)osal_malloc(PackSize);
  911. if ( !pPack )
  912. return 0;
  913. pSrcPack = pSrc; //3pixel4byte no support
  914. pDstPack = pPack;
  915. DePackedYUV(is10bit, PackMode, srcWidthY, srcHeightY, pSrcPack,
  916. dstWidthY, dstHeightY, dstWidthC, dstHeightY/*Pack : 422*/, pDstPack);
  917. }
  918. else if (interLeave == TRUE) {
  919. pSrcInterLeave = (is10bit) ? pDstFormat : pSrc;
  920. if (is422) {
  921. InterLeaveSize = dstWidthY*srcHeightY + dstWidthC*srcHeightC * 2;
  922. pInterLeave = (Uint8*)osal_malloc(InterLeaveSize);
  923. if ( !pInterLeave )
  924. return 0;
  925. pDstInterLeave = pInterLeave;
  926. }
  927. else
  928. pDstInterLeave = pDst;
  929. DeInterLeave(is10bit, nv21, dstWidthY, srcHeightY, dstWidthC*2, srcHeightC, pSrcInterLeave, pDstInterLeave);
  930. }
  931. //7. 422 => 420
  932. if (is422 || isPack) {
  933. pSrc422 = (isPack) ? pDstPack :
  934. ((interLeave) ? pDstInterLeave :
  935. ((is10bit) ? pDstFormat : pSrc));
  936. pDst422 = pDst;
  937. Convert422to420(pSrc422, dstWidthY, dstHeightY, dstWidthC, dstHeightC, pDst422);
  938. }
  939. //8.byte swap for short-type for Windows
  940. if (is10bit) {
  941. pSrcSwap = (is422 || isPack) ? pDst422 :
  942. ((interLeave == TRUE) ? pDstInterLeave : pDstFormat);
  943. pDstSwap = pDst;
  944. ByteSwap10bit(DstSize, pSrcSwap, pDstSwap);
  945. }
  946. //9: free memories
  947. osal_free(pSrc);
  948. if (pFormat != NULL)
  949. osal_free(pFormat);
  950. if (pPack != NULL)
  951. osal_free(pPack);
  952. if (pInterLeave != NULL)
  953. osal_free(pInterLeave);
  954. return totSize;
  955. }
  956. Uint32 StoreYuvImageBurst2(
  957. Uint32 coreIdx,
  958. FrameBuffer *fbSrc,
  959. TiledMapConfig mapCfg,
  960. Uint8 *pDst,
  961. Uint8 **pDst2,
  962. VpuRect cropRect,
  963. BOOL enableCrop
  964. )
  965. {
  966. int interLeave = fbSrc->cbcrInterleave;
  967. BOOL nv21 = fbSrc->nv21;
  968. Uint32 totSize = 0;
  969. Uint32 is422;
  970. Uint32 isPack;
  971. Uint32 PackMode;
  972. Uint32 is10bit;
  973. Uint32 isMSB;
  974. Uint32 is3pxl4byte;
  975. Uint32 srcWidthY;
  976. Uint32 srcHeightY;
  977. Uint32 srcWidthC;
  978. Uint32 srcHeightC;
  979. Uint32 chroma_stride;
  980. Uint32 dstWidthY;
  981. Uint32 dstHeightY;
  982. Uint32 dstWidthC;
  983. Uint32 dstHeightC;
  984. Uint32 DstSize = 0;
  985. Uint32 SrcSize = 0;
  986. //Uint8* pSrc = NULL;
  987. Uint8* pSrcFormat;
  988. Uint8* pDstFormat = NULL;
  989. Uint32 deFormatSize = 0;
  990. Uint8* pFormat = NULL;
  991. Uint8* pSrcInterLeave;
  992. Uint8* pDstInterLeave = NULL;
  993. Uint32 InterLeaveSize = 0;
  994. Uint8* pInterLeave = NULL;
  995. Uint8* pSrcPack;
  996. Uint8* pDstPack = NULL;
  997. Uint32 PackSize = 0;
  998. Uint8* pPack = NULL;
  999. Uint8* pSrc422;
  1000. Uint8* pDst422 = NULL;
  1001. Uint8* pSrcSwap;
  1002. Uint8* pDstSwap;
  1003. GeneratePicParam(fbSrc, cropRect, enableCrop,
  1004. &is422, &isPack, &PackMode, &is10bit, &isMSB, &is3pxl4byte,
  1005. &srcWidthY, &srcHeightY, &srcWidthC, &srcHeightC, &chroma_stride,
  1006. &dstWidthY, &dstHeightY, &dstWidthC, &dstHeightC);
  1007. //1. Source YUV memory allocation
  1008. SrcSize = srcWidthY*srcHeightY + srcWidthC*srcHeightC;
  1009. if (interLeave != TRUE)
  1010. SrcSize += srcWidthC*srcHeightC;
  1011. //pSrc = (Uint8*)osal_malloc(SrcSize);
  1012. //if (!pSrc)
  1013. // return 0;
  1014. //2. Destination YUV size
  1015. DstSize = dstWidthY*dstHeightY + dstWidthC*dstHeightC * 2;
  1016. totSize = DstSize;
  1017. //3. Source YUV Load
  1018. LoadSrcYUV2(coreIdx, mapCfg, pDst, pDst2, fbSrc, cropRect, enableCrop,
  1019. is10bit, is3pxl4byte, isMSB,
  1020. srcWidthY, srcHeightY, srcWidthC, srcHeightC, chroma_stride);
  1021. //4. osal_memcpy and termination for 8bit, 420, normal(non packed) YUV
  1022. //SrcYUV => DstYUV
  1023. #if defined(SAVE_YUV)
  1024. //osal_memcpy(pDst, pSrc, SrcSize);
  1025. totSize = SrcSize;
  1026. //osal_free(pSrc);
  1027. return totSize;
  1028. #else
  1029. // if dec video format is I420 NV21 NV12, just dump it
  1030. if (is10bit != TRUE && is422 != TRUE && isPack != TRUE) {
  1031. //osal_memcpy(pDst, pSrc, SrcSize);
  1032. //osal_free(pSrc);
  1033. return totSize;
  1034. }
  1035. #endif
  1036. //5. deFormat
  1037. //all format for 10bit => 1 pixel 2byte LSB
  1038. if (is10bit == TRUE) {
  1039. if (is3pxl4byte == TRUE) {
  1040. deFormatSize = dstWidthY*srcHeightY + (dstWidthC*srcHeightY * 2);
  1041. pFormat = (Uint8*)osal_malloc(deFormatSize);
  1042. }
  1043. pSrcFormat = pDst;
  1044. pDstFormat = (is3pxl4byte == TRUE) ? pFormat : pDst;
  1045. DeFormatYUV( is3pxl4byte, isMSB, interLeave, srcWidthY, srcHeightY, srcWidthC, srcHeightC,
  1046. dstWidthY, dstWidthC, pSrcFormat, pDstFormat);
  1047. }
  1048. //6. dePack or interleave
  1049. //Pack => Normal
  1050. //interleave => Normal
  1051. if (isPack) {
  1052. //pPack allocation
  1053. PackSize = dstWidthY*dstHeightY + dstWidthC*dstHeightY * 2;
  1054. pPack = (Uint8*)osal_malloc(PackSize);
  1055. if ( !pPack )
  1056. return 0;
  1057. pSrcPack = pDst; //3pixel4byte no support
  1058. pDstPack = pPack;
  1059. DePackedYUV(is10bit, PackMode, srcWidthY, srcHeightY, pSrcPack,
  1060. dstWidthY, dstHeightY, dstWidthC, dstHeightY/*Pack : 422*/, pDstPack);
  1061. }
  1062. else if (interLeave == TRUE) {
  1063. pSrcInterLeave = (is10bit) ? pDstFormat : pDst;
  1064. if (is422) {
  1065. InterLeaveSize = dstWidthY*srcHeightY + dstWidthC*srcHeightC * 2;
  1066. pInterLeave = (Uint8*)osal_malloc(InterLeaveSize);
  1067. if ( !pInterLeave )
  1068. return 0;
  1069. pDstInterLeave = pInterLeave;
  1070. }
  1071. else
  1072. pDstInterLeave = pDst;
  1073. DeInterLeave(is10bit, nv21, dstWidthY, srcHeightY, dstWidthC*2, srcHeightC, pSrcInterLeave, pDstInterLeave);
  1074. }
  1075. //7. 422 => 420
  1076. if (is422 || isPack) {
  1077. pSrc422 = (isPack) ? pDstPack :
  1078. ((interLeave) ? pDstInterLeave :
  1079. ((is10bit) ? pDstFormat : pDst));
  1080. pDst422 = pDst;
  1081. Convert422to420(pSrc422, dstWidthY, dstHeightY, dstWidthC, dstHeightC, pDst422);
  1082. }
  1083. //8.byte swap for short-type for Windows
  1084. if (is10bit) {
  1085. pSrcSwap = (is422 || isPack) ? pDst422 :
  1086. ((interLeave == TRUE) ? pDstInterLeave : pDstFormat);
  1087. pDstSwap = pDst;
  1088. ByteSwap10bit(DstSize, pSrcSwap, pDstSwap);
  1089. }
  1090. //9: free memories
  1091. //osal_free(pSrc);
  1092. if (pFormat != NULL)
  1093. osal_free(pFormat);
  1094. if (pPack != NULL)
  1095. osal_free(pPack);
  1096. if (pInterLeave != NULL)
  1097. osal_free(pInterLeave);
  1098. return totSize;
  1099. }
  1100. static void DeInterLeave(
  1101. Uint32 is10bit,
  1102. BOOL nv21,
  1103. Uint32 srcWidthY,
  1104. Uint32 srcHeightY,
  1105. Uint32 srcWidthC,
  1106. Uint32 srcHeightC,
  1107. Uint8* pSrc,
  1108. Uint8* pDst
  1109. )
  1110. {
  1111. int x, y;
  1112. int src_stride;
  1113. int dst_stride;
  1114. if (!pSrc)
  1115. return ;
  1116. if (!pDst)
  1117. return ;
  1118. //luma copy
  1119. osal_memcpy(pDst, pSrc, srcWidthY*srcHeightY);
  1120. //interleave => normal
  1121. if (is10bit) {
  1122. Uint16 *pSrcChroma;
  1123. Uint16 *pDstCb, *pDstCr;
  1124. src_stride = srcWidthC / 2;
  1125. dst_stride = srcWidthC / 4;
  1126. pSrcChroma = (Uint16*)(pSrc + srcWidthY*srcHeightY);
  1127. pDstCb = (Uint16*)(pDst + srcWidthY*srcHeightY);
  1128. pDstCr = (Uint16*)(pDstCb + dst_stride*srcHeightC);
  1129. for (y = 0; y < (int)srcHeightC; y++) {
  1130. for (x = 0; x < (int)src_stride; x += 2) {
  1131. if (nv21) {
  1132. pDstCr[x / 2] = pSrcChroma[x + 0];
  1133. pDstCb[x / 2] = pSrcChroma[x + 1];
  1134. }
  1135. else {
  1136. pDstCb[x / 2] = pSrcChroma[x + 0];
  1137. pDstCr[x / 2] = pSrcChroma[x + 1];
  1138. }
  1139. }
  1140. pSrcChroma += src_stride;
  1141. pDstCb += dst_stride;
  1142. pDstCr += dst_stride;
  1143. }
  1144. }
  1145. else {
  1146. Uint8 *pSrcChroma;
  1147. Uint8 *pDstCb, *pDstCr;
  1148. src_stride = srcWidthC;
  1149. dst_stride = srcWidthC / 2;
  1150. pSrcChroma = pSrc + srcWidthY*srcHeightY;
  1151. pDstCb = pDst + srcWidthY*srcHeightY;
  1152. pDstCr = pDstCb + dst_stride*srcHeightC;
  1153. for (y = 0; y < (int)srcHeightC; y++) {
  1154. for (x = 0; x < (int)src_stride; x += 2) {
  1155. if (nv21) {
  1156. pDstCr[x / 2] = pSrcChroma[x + 0];
  1157. pDstCb[x / 2] = pSrcChroma[x + 1];
  1158. }
  1159. else {
  1160. pDstCb[x / 2] = pSrcChroma[x + 0];
  1161. pDstCr[x / 2] = pSrcChroma[x + 1];
  1162. }
  1163. }
  1164. pSrcChroma += src_stride;
  1165. pDstCb += dst_stride;
  1166. pDstCr += dst_stride;
  1167. }
  1168. }
  1169. }
  1170. void ByteSwap10bit(
  1171. Uint32 DstSize,
  1172. Uint8* pSrc,
  1173. Uint8* pDst
  1174. )
  1175. {
  1176. int x;
  1177. if (!pSrc)
  1178. return;
  1179. for (x = 0; x < (int)DstSize; x += 2) {
  1180. Uint8 temp0 = pSrc[x + 0];
  1181. Uint8 temp1 = pSrc[x + 1];
  1182. pDst[x + 0] = temp1;
  1183. pDst[x + 1] = temp0;
  1184. }
  1185. }
  1186. void DeFormatYUV(
  1187. Uint32 is3pixel4byte,
  1188. Uint32 isMSB,
  1189. Uint32 interLeave,
  1190. Uint32 srcWidthY,
  1191. Uint32 srcHeightY,
  1192. Uint32 srcWidthC,
  1193. Uint32 srcHeightC,
  1194. Uint32 dstWidthY,
  1195. Uint32 dstWidthC,
  1196. Uint8* pSrc,
  1197. Uint8* pDst
  1198. )
  1199. {
  1200. int x, y;
  1201. Uint8 *pSrcY, *pSrcCb, *pSrcCr;
  1202. Uint8 *pDstY, *pDstCb, *pDstCr;
  1203. if (!pSrc)
  1204. return;
  1205. if (!pDst)
  1206. return;
  1207. if (is3pixel4byte) {
  1208. int src_luma_stride = srcWidthY;
  1209. int src_chroma_stride = srcWidthC;
  1210. int dst_luma_stride = dstWidthY;
  1211. int dst_chroma_stride = (interLeave) ? dstWidthC * 2 : dstWidthC;
  1212. int i;
  1213. //luma
  1214. pSrcY = pSrc;
  1215. pDstY = pDst;
  1216. for (y = 0; y < (int)srcHeightY; y++) {
  1217. i = 0;
  1218. for (x = 0; x < (int)src_luma_stride; x += 4) {
  1219. Uint32 temp0 = pSrcY[x + 3];
  1220. Uint32 temp1 = pSrcY[x + 2];
  1221. Uint32 temp2 = pSrcY[x + 1];
  1222. Uint32 temp3 = pSrcY[x + 0];
  1223. Uint32 temp = (temp3 << 24) + (temp2 << 16) + (temp1 << 8) + temp0;
  1224. if (isMSB) {
  1225. temp = temp >> 2;
  1226. temp0 = (temp >> 20) & 0x3ff;
  1227. temp1 = (temp >> 10) & 0x3ff;
  1228. temp2 = (temp >> 0) & 0x3ff;
  1229. }
  1230. else {
  1231. temp2 = (temp >> 20) & 0x3ff;
  1232. temp1 = (temp >> 10) & 0x3ff;
  1233. temp0 = (temp >> 0) & 0x3ff;
  1234. }
  1235. //first pixel
  1236. pDstY[i] = (temp0 >> 2) & 0xff; i++;
  1237. pDstY[i] = (temp0 << 6) & 0xc0; i++;
  1238. if (i < dst_luma_stride) {
  1239. pDstY[i] = (temp1 >> 2) & 0xff; i++;
  1240. pDstY[i] = (temp1 << 6) & 0xc0; i++;
  1241. }
  1242. if (i < dst_luma_stride) {
  1243. pDstY[i] = (temp2 >> 2) & 0xff; i++;
  1244. pDstY[i] = (temp2 << 6) & 0xc0; i++;
  1245. }
  1246. }
  1247. pDstY += dst_luma_stride;
  1248. pSrcY += src_luma_stride;
  1249. }
  1250. pSrcCb = pSrc + srcWidthY*srcHeightY;
  1251. pDstCb = pDst + dstWidthY*srcHeightY;
  1252. for (y = 0; y < (int)srcHeightC; y++) {
  1253. i = 0;
  1254. for (x = 0; x < (int)src_chroma_stride; x += 4) {
  1255. Uint32 temp0 = pSrcCb[x + 3];
  1256. Uint32 temp1 = pSrcCb[x + 2];
  1257. Uint32 temp2 = pSrcCb[x + 1];
  1258. Uint32 temp3 = pSrcCb[x + 0];
  1259. Uint32 temp = (temp3 << 24) + (temp2 << 16) + (temp1 << 8) + temp0;
  1260. if (isMSB) {
  1261. temp = temp >> 2;
  1262. temp0 = (temp >> 20) & 0x3ff;
  1263. temp1 = (temp >> 10) & 0x3ff;
  1264. temp2 = (temp >> 0) & 0x3ff;
  1265. }
  1266. else {
  1267. temp2 = (temp >> 20) & 0x3ff;
  1268. temp1 = (temp >> 10) & 0x3ff;
  1269. temp0 = (temp >> 0) & 0x3ff;
  1270. }
  1271. //first pixel
  1272. pDstCb[i] = (temp0 >> 2) & 0xff; i++;
  1273. pDstCb[i] = (temp0 << 6) & 0xc0; i++;
  1274. if (i < dst_chroma_stride) {
  1275. pDstCb[i] = (temp1 >> 2) & 0xff; i++;
  1276. pDstCb[i] = (temp1 << 6) & 0xc0; i++;
  1277. }
  1278. if (i < dst_chroma_stride) {
  1279. pDstCb[i] = (temp2 >> 2) & 0xff; i++;
  1280. pDstCb[i] = (temp2 << 6) & 0xc0; i++;
  1281. }
  1282. }
  1283. pDstCb += dst_chroma_stride;
  1284. pSrcCb += src_chroma_stride;
  1285. }
  1286. if (interLeave != TRUE) {
  1287. pSrcCr = pSrc + srcWidthY*srcHeightY + srcWidthC*srcHeightC;
  1288. pDstCr = pDst + dstWidthY*srcHeightY + dstWidthC*srcHeightC;
  1289. for (y = 0; y < (int)srcHeightC; y++) {
  1290. i = 0;
  1291. for (x = 0; x < (int)src_chroma_stride; x += 4) {
  1292. Uint32 temp0 = pSrcCr[x + 3];
  1293. Uint32 temp1 = pSrcCr[x + 2];
  1294. Uint32 temp2 = pSrcCr[x + 1];
  1295. Uint32 temp3 = pSrcCr[x + 0];
  1296. Uint32 temp = (temp3 << 24) + (temp2 << 16) + (temp1 << 8) + temp0;
  1297. if (isMSB) {
  1298. temp = temp >> 2;
  1299. temp0 = (temp >> 20) & 0x3ff;
  1300. temp1 = (temp >> 10) & 0x3ff;
  1301. temp2 = (temp >> 0) & 0x3ff;
  1302. }
  1303. else {
  1304. temp2 = (temp >> 20) & 0x3ff;
  1305. temp1 = (temp >> 10) & 0x3ff;
  1306. temp0 = (temp >> 0) & 0x3ff;
  1307. }
  1308. //first pixel
  1309. pDstCr[i] = (temp0 >> 2) & 0xff; i++;
  1310. pDstCr[i] = (temp0 << 6) & 0xc0; i++;
  1311. if (i < dst_chroma_stride) {
  1312. pDstCr[i] = (temp1 >> 2) & 0xff; i++;
  1313. pDstCr[i] = (temp1 << 6) & 0xc0; i++;
  1314. }
  1315. if (i < dst_chroma_stride) {
  1316. pDstCr[i] = (temp2 >> 2) & 0xff; i++;
  1317. pDstCr[i] = (temp2 << 6) & 0xc0; i++;
  1318. }
  1319. }
  1320. pDstCr += dst_chroma_stride;
  1321. pSrcCr += src_chroma_stride;
  1322. }
  1323. }
  1324. }
  1325. else if (isMSB != TRUE) {
  1326. int luma_stride = srcWidthY;
  1327. int chroma_stride = srcWidthC;
  1328. //luma
  1329. pSrcY = pSrc;
  1330. pDstY = pDst;
  1331. for (y = 0; y < (int)srcHeightY; y++) {
  1332. for (x = 0; x < (int)luma_stride; x += 2) {
  1333. Uint16 temp0 = pSrcY[x + 0];
  1334. Uint16 temp1 = pSrcY[x + 1];
  1335. Uint16 temp = (temp0 << (8 + 6)) + (temp1 << 6);
  1336. Uint16 pxl8bit1 = (temp >> 0) & 0xc0;
  1337. Uint16 pxl8bit0 = (temp >> 8) & 0xff;
  1338. pDstY[x + 0] = (Uint8)pxl8bit0;
  1339. pDstY[x + 1] = (Uint8)pxl8bit1;
  1340. }
  1341. pDstY += luma_stride;
  1342. pSrcY += luma_stride;
  1343. }
  1344. pSrcCb = (pSrc + srcWidthY*srcHeightY);
  1345. pDstCb = (pDst + srcWidthY*srcHeightY);
  1346. for (y = 0; y < (int)srcHeightC; y++) {
  1347. for (x = 0; x < (int)chroma_stride; x += 2) {
  1348. Uint16 temp0 = pSrcCb[x + 0];
  1349. Uint16 temp1 = pSrcCb[x + 1];
  1350. Uint16 temp = (temp0 << (8 + 6)) + (temp1 << 6);
  1351. Uint16 pxl8bit1 = (temp >> 0) & 0xc0;
  1352. Uint16 pxl8bit0 = (temp >> 8) & 0xff;
  1353. pDstCb[x + 0] = (Uint8)pxl8bit0;
  1354. pDstCb[x + 1] = (Uint8)pxl8bit1;
  1355. }
  1356. pDstCb += chroma_stride;
  1357. pSrcCb += chroma_stride;
  1358. }
  1359. if (interLeave != TRUE) {
  1360. pSrcCr = (pSrc + srcWidthY*srcHeightY + srcHeightC*srcWidthC);
  1361. pDstCr = (pDst + srcWidthY*srcHeightY + srcHeightC*srcWidthC);
  1362. for (y = 0; y < (int)srcHeightC; y++) {
  1363. for (x = 0; x < (int)chroma_stride; x += 2) {
  1364. Uint16 temp0 = pSrcCr[x + 0];
  1365. Uint16 temp1 = pSrcCr[x + 1];
  1366. Uint16 temp = (temp0 << (8 + 6)) + (temp1 << 6);
  1367. Uint16 pxl8bit1 = (temp >> 0) & 0xc0;
  1368. Uint16 pxl8bit0 = (temp >> 8) & 0xff;
  1369. pDstCr[x + 0] = (Uint8)pxl8bit0;
  1370. pDstCr[x + 1] = (Uint8)pxl8bit1;
  1371. }
  1372. pDstCr += chroma_stride;
  1373. pSrcCr += chroma_stride;
  1374. }
  1375. }
  1376. }
  1377. }
  1378. void Convert422to420(
  1379. Uint8* pSrc,
  1380. Uint32 dstWidthY,
  1381. Uint32 dstHeightY,
  1382. Uint32 dstWidthC,
  1383. Uint32 dstHeightC,
  1384. Uint8* pDst
  1385. )
  1386. {
  1387. int y;
  1388. int x;
  1389. int luma_stride;
  1390. int chroma_stride;
  1391. Uint8* pSrcCb;
  1392. Uint8* pSrcCr;
  1393. Uint8* pDstCb;
  1394. Uint8* pDstCr;
  1395. luma_stride = dstWidthY;
  1396. chroma_stride = dstWidthC;
  1397. if(!pSrc)
  1398. return ;
  1399. if(!pDst)
  1400. return ;
  1401. //1. luma osal_memcpy
  1402. osal_memcpy(pDst, pSrc, luma_stride*dstHeightY);
  1403. //2.1 chroma copy :Cb
  1404. pSrcCb = pSrc + luma_stride*dstHeightY;
  1405. pDstCb = pDst + luma_stride*dstHeightY;
  1406. for (y = 0; y < (int)dstHeightY; y += 2) {
  1407. //checek SrcCb
  1408. for (x = 0; x < (int)chroma_stride; x++)
  1409. if (pSrcCb[x] != pSrcCb[x + chroma_stride])
  1410. pSrcCb[x] = pSrcCb[x]; //assert
  1411. osal_memcpy(pDstCb, pSrcCb, chroma_stride);
  1412. pDstCb += chroma_stride;
  1413. pSrcCb += 2*chroma_stride;
  1414. }
  1415. //2.2 chroma copy : Cr
  1416. pSrcCr = pSrc + luma_stride*dstHeightY + chroma_stride*dstHeightY;
  1417. pDstCr = pDst + luma_stride*dstHeightY + chroma_stride*dstHeightC;
  1418. for (y = 0; y < (int)dstHeightY; y += 2) {
  1419. //checek SrcCr
  1420. for (x = 0; x < (int)chroma_stride; x++)
  1421. if (pSrcCr[x] != pSrcCr[x + chroma_stride])
  1422. pSrcCr[x] = pSrcCr[x]; //assert
  1423. osal_memcpy(pDstCr, pSrcCr, chroma_stride);
  1424. pDstCr += chroma_stride;
  1425. pSrcCr += 2*chroma_stride;
  1426. }
  1427. }
  1428. void DePackedYUV(
  1429. Uint32 is10bit,
  1430. Uint32 PackMode,
  1431. Uint32 srcWidthY,
  1432. Uint32 srcHeightY,
  1433. Uint8* pSrc,
  1434. Uint32 dstWidthY,
  1435. Uint32 dstHeightY,
  1436. Uint32 dstWidthC,
  1437. Uint32 dstHeightC,
  1438. Uint8* pDst
  1439. )
  1440. {
  1441. int x, y;
  1442. int stride;
  1443. int dst_strideY;
  1444. int dst_strideC;
  1445. if (is10bit) {
  1446. Uint16* pSrcPack;
  1447. Uint16* pDstY;
  1448. Uint16* pDstCb;
  1449. Uint16* pDstCr;
  1450. Uint16 Y0, Y1, U, V;
  1451. stride = srcWidthY / 2;
  1452. dst_strideY = dstWidthY / 2;
  1453. dst_strideC = dstWidthC / 2;
  1454. pDstY = (Uint16*)pDst;
  1455. pDstCb = (Uint16*)(pDst + dstWidthY * dstHeightY);
  1456. pDstCr = (Uint16*)(pDst + dstWidthY * dstHeightY + dstWidthC * dstHeightC);
  1457. for (y = 0; y < (int)srcHeightY; y++) {
  1458. pSrcPack = ((Uint16*)pSrc) + y*stride;
  1459. for (x = 0; x < stride; x += 4) {
  1460. switch (PackMode) {
  1461. case 0 : //YUYV
  1462. Y0 = pSrcPack[x + 0];
  1463. U = pSrcPack[x + 1];
  1464. Y1 = pSrcPack[x + 2];
  1465. V = pSrcPack[x + 3];
  1466. break;
  1467. case 1 : //YVYU
  1468. Y0 = pSrcPack[x + 0];
  1469. V = pSrcPack[x + 1];
  1470. Y1 = pSrcPack[x + 2];
  1471. U = pSrcPack[x + 3];
  1472. break;
  1473. case 2 : //UYVY
  1474. U = pSrcPack[x + 0];
  1475. Y0 = pSrcPack[x + 1];
  1476. V = pSrcPack[x + 2];
  1477. Y1 = pSrcPack[x + 3];
  1478. break;
  1479. default : //VYUY
  1480. V = pSrcPack[x + 0];
  1481. Y0 = pSrcPack[x + 1];
  1482. U = pSrcPack[x + 2];
  1483. Y1 = pSrcPack[x + 3];
  1484. break;
  1485. }
  1486. pDstY[x / 2 + 0] = Y0;
  1487. pDstY[x / 2 + 1] = Y1;
  1488. pDstCb[x / 4] = U;
  1489. pDstCr[x / 4] = V;
  1490. }
  1491. pSrcPack += stride;
  1492. pDstY += dst_strideY;
  1493. pDstCb += dst_strideC;
  1494. pDstCr += dst_strideC;
  1495. }
  1496. }
  1497. else {
  1498. Uint8* pSrcPack;
  1499. Uint8* pDstY;
  1500. Uint8* pDstCb;
  1501. Uint8* pDstCr;
  1502. Uint8 Y0, Y1, U, V;
  1503. stride = srcWidthY;
  1504. dst_strideY = dstWidthY;
  1505. dst_strideC = dstWidthC;
  1506. pDstY = pDst;
  1507. pDstCb = pDst + dstWidthY * dstHeightY;
  1508. pDstCr = pDst + dstWidthY * dstHeightY + dstWidthC * dstHeightC;
  1509. for (y = 0; y < (int)srcHeightY; y++) {
  1510. pSrcPack = pSrc + y*stride;
  1511. for (x = 0; x < (int)stride; x += 4) {
  1512. switch (PackMode) {
  1513. case 0 : //YUYV
  1514. Y0 = pSrcPack[x + 0];
  1515. U = pSrcPack[x + 1];
  1516. Y1 = pSrcPack[x + 2];
  1517. V = pSrcPack[x + 3];
  1518. break;
  1519. case 1 : //YVYU
  1520. Y0 = pSrcPack[x + 0];
  1521. V = pSrcPack[x + 1];
  1522. Y1 = pSrcPack[x + 2];
  1523. U = pSrcPack[x + 3];
  1524. break;
  1525. case 2 : //UYVY
  1526. U = pSrcPack[x + 0];
  1527. Y0 = pSrcPack[x + 1];
  1528. V = pSrcPack[x + 2];
  1529. Y1 = pSrcPack[x + 3];
  1530. break;
  1531. default : //VYUY
  1532. V = pSrcPack[x + 0];
  1533. Y0 = pSrcPack[x + 1];
  1534. U = pSrcPack[x + 2];
  1535. Y1 = pSrcPack[x + 3];
  1536. break;
  1537. }
  1538. pDstY[x / 2 + 0] = Y0;
  1539. pDstY[x / 2 + 1] = Y1;
  1540. pDstCb[x / 4] = U;
  1541. pDstCr[x / 4] = V;
  1542. }
  1543. pSrcPack += stride;
  1544. pDstY += dst_strideY;
  1545. pDstCb += dst_strideC;
  1546. pDstCr += dst_strideC;
  1547. }
  1548. }
  1549. }
  1550. void DePxlOrder8bit(Uint8* pPxl16Src, Uint8* pPxl16Dst)
  1551. {
  1552. #if 1
  1553. //-------------8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit-
  1554. //mode 1: | p15 | p14 | p13 | p12 | p11 | p10 | p09 | p08 | p07 | p06 | p05 | p04 | p03 | p02 | p01 | p00 |
  1555. //HW output: | p00 | p01 | p02 | p03 | p04 | p05 | p06 | p07 | p08 | p09 | p10 | p11 | p12 | p13 | p14 | p15 |
  1556. //mode 0: | p00 | p01 | p02 | p03 | p04 | p05 | p06 | p07 | p08 | p09 | p10 | p11 | p12 | p13 | p14 | p15 |
  1557. // mode 1 vs HW output : endian swap
  1558. // HW output = mode 0
  1559. //1) no change
  1560. #else
  1561. //-------------8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit--8bit-
  1562. //mode 1: | p15 | p14 | p13 | p12 | p11 | p10 | p09 | p08 | p07 | p06 | p05 | p04 | p03 | p02 | p01 | p00 |
  1563. //HW output: | p15 | p14 | p13 | p12 | p11 | p10 | p09 | p08 | p07 | p06 | p05 | p04 | p03 | p02 | p01 | p00 |
  1564. //mode 0: | p00 | p01 | p02 | p03 | p04 | p05 | p06 | p07 | p08 | p09 | p10 | p11 | p12 | p13 | p14 | p15 |
  1565. // mode 1 = HW output
  1566. // HW output vs mode 0 : endian swap
  1567. //1) swap pixels
  1568. int i;
  1569. for (i = 0; i < 16; i++)
  1570. pPxl16Dst[15 - i] = pPxl16Src[i];
  1571. #endif
  1572. }
  1573. void DePxlOrder1pxl2byte(Uint8* pPxl16Src, Uint8* pPxl16Dst)
  1574. {
  1575. #if 1
  1576. //MSB
  1577. //-----------|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|
  1578. //mode 1: | p7[9:2] | p7[1:0],6'b0 | p6[9:2] | p6[1:0],6'b0 | p5[9:2] | p5[1:0],6'b0 | p4[9:2] | p4[1:0],6'b0 | p3[9:2] | p3[1:0],6'b0 | p2[9:2] | p2[1:0],6'b0 | p1[9:2] | p1[1:0],6'b0 | p0[9:2] | p0[1:0],6'b0 |
  1579. //HW output: | p0[1:0],6'b0 | p0[9:2] | p1[1:0],6'b0 | p1[9:2] | p2[1:0],6'b0 | p2[9:2] | p3[1:0],6'b0 | p3[9:2] | p4[1:0],6'b0 | p4[9:2] | p5[1:0],6'b0 | p5[9:2] | p6[1:0],6'b0 | p6[9:2] | p7[1:0],6'b0 | p7[9:2] |
  1580. //mode 0: | p0[9:2] | p0[1:0],6'b0 | p1[9:2] | p1[1:0],6'b0 | p2[9:2] | p2[1:0],6'b0 | p3[9:2] | p3[1:0],6'b0 | p4[9:2] | p4[1:0],6'b0 | p5[9:2] | p5[1:0],6'b0 | p6[9:2] | p6[1:0],6'b0 | p7[9:2] | p7[1:0],6'b0 |
  1581. //LSB
  1582. //-----------|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|
  1583. //mode 1: | 6'b0,p7[9:8] | p7[7:0] | 6'b0,p6[9:8] | p6[7:0] | 6'b0,p5[9:8] | p5[7:0] | 6'b0,p4[9:8] | p4[7:0] | 6'b0,p3[9:8] | p3[7:0] | 6'b0,p2[9:8] | p2[7:0] | 6'b0,p1[9:8] | p1[7:0] | 6'b0,p0[9:8] | p0[7:0] |
  1584. //HW output: | p0[7:0] | 6'b0,p0[9:8] | p1[7:0] | 6'b0,p1[9:8] | p2[7:0] | 6'b0,p2[9:8] | p3[7:0] | 6'b0,p3[9:8] | p4[7:0] | 6'b0,p4[9:8] | p5[7:0] | 6'b0,p5[9:8] | p6[7:0] | 6'b0,p6[9:8] | p7[7:0] | 6'b0,p7[9:8] |
  1585. //mode 0: | 6'b0,p0[9:8] | p0[7:0] | 6'b0,p1[9:8] | p1[7:0] | 6'b0,p2[9:8] | p2[7:0] | 6'b0,p3[9:8] | p3[7:0] | 6'b0,p4[9:8] | p4[7:0] | 6'b0,p5[9:8] | p5[7:0] | 6'b0,p6[9:8] | p6[7:0] | 6'b0,p7[9:8] | p7[7:0] |
  1586. // mode 1 vs HW output : endian swap
  1587. // HW output vs mode 1 : byte swap in 2 bytes
  1588. //1) byte swap in 2 bytes
  1589. int i;
  1590. Uint8* pSrc = pPxl16Src;
  1591. Uint8* pDst = pPxl16Dst;
  1592. for (i = 0; i < 8; i++) {
  1593. pDst[i * 2 + 1] = pSrc[i * 2 + 0];
  1594. pDst[i * 2 + 0] = pSrc[i * 2 + 1];
  1595. }
  1596. #else
  1597. //MSB
  1598. //-----------|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|
  1599. //mode 1: | p7[9:2] | p7[1:0],6'b0 | p6[9:2] | p6[1:0],6'b0 | p5[9:2] | p5[1:0],6'b0 | p4[9:2] | p4[1:0],6'b0 | p3[9:2] | p3[1:0],6'b0 | p2[9:2] | p2[1:0],6'b0 | p1[9:2] | p1[1:0],6'b0 | p0[9:2] | p0[1:0],6'b0 |
  1600. //HW output: | p7[9:2] | p7[1:0],6'b0 | p6[9:2] | p6[1:0],6'b0 | p5[9:2] | p5[1:0],6'b0 | p4[9:2] | p4[1:0],6'b0 | p3[9:2] | p3[1:0],6'b0 | p2[9:2] | p2[1:0],6'b0 | p1[9:2] | p1[1:0],6'b0 | p0[9:2] | p0[1:0],6'b0 |
  1601. //mode 0: | p0[9:2] | p0[1:0],6'b0 | p1[9:2] | p1[1:0],6'b0 | p2[9:2] | p2[1:0],6'b0 | p3[9:2] | p3[1:0],6'b0 | p4[9:2] | p4[1:0],6'b0 | p5[9:2] | p5[1:0],6'b0 | p6[9:2] | p6[1:0],6'b0 | p7[9:2] | p7[1:0],6'b0 |
  1602. //LSB
  1603. //-----------|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|-----8bit-----|
  1604. //mode 1: | 6'b0,p7[9:8] | p7[7:0] | 6'b0,p6[9:8] | p6[7:0] | 6'b0,p5[9:8] | p5[7:0] | 6'b0,p4[9:8] | p4[7:0] | 6'b0,p3[9:8] | p3[7:0] | 6'b0,p2[9:8] | p2[7:0] | 6'b0,p1[9:8] | p1[7:0] | 6'b0,p0[9:8] | p0[7:0] |
  1605. //HW output: | 6'b0,p7[9:8] | p7[7:0] | 6'b0,p6[9:8] | p6[7:0] | 6'b0,p5[9:8] | p5[7:0] | 6'b0,p4[9:8] | p4[7:0] | 6'b0,p3[9:8] | p3[7:0] | 6'b0,p2[9:8] | p2[7:0] | 6'b0,p1[9:8] | p1[7:0] | 6'b0,p0[9:8] | p0[7:0] |
  1606. //mode 0: | 6'b0,p0[9:8] | p0[7:0] | 6'b0,p1[9:8] | p1[7:0] | 6'b0,p2[9:8] | p2[7:0] | 6'b0,p3[9:8] | p3[7:0] | 6'b0,p4[9:8] | p4[7:0] | 6'b0,p5[9:8] | p5[7:0] | 6'b0,p6[9:8] | p6[7:0] | 6'b0,p7[9:8] | p7[7:0] |
  1607. // mode 1 = HW output
  1608. // HW output vs mode 0 : 2-byte word swap
  1609. //1) 2-byte word swap
  1610. int i;
  1611. Uint16* pSrc = (Uint16*) pPxl16Src;
  1612. Uint16* pDst = (Uint16*) pPxl16Dst;
  1613. for (i = 0; i < 8; i++)
  1614. pDst[7 - i] = pSrc[i];
  1615. #endif
  1616. }
  1617. void DePxlOrder3pxl4byteLSB(Uint8* pPxl16Src, Uint8* pPxl16Dst)
  1618. {
  1619. #if 1
  1620. //-----------|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|
  1621. //mode 1: | 2'b0,p11[9:4] | p11[3:0],p10[9:6] | p10[5:0],p09[9:8] | p09[7:0] | 2'b0,p08[9:4] | p08[3:0],p07[9:6] | p07[5:0],p06[9:8] | p06[7:0] | 2'b0,p05[9:4] | p05[3:0],p04[9:6] | p04[5:0],p03[9:8] | p03[7:0] | 2'b0,p02[9:4] | p02[3:0],p01[9:6] | p01[5:0],p00[9:8] | p00[7:0] |
  1622. // | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P |
  1623. //-----------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|
  1624. //HW output: | p00[7:0] | p01[5:0],p00[9:8] | p02[3:0],p01[9:6] | 2'b0,p02[9:4] | p03[7:0] | p04[5:0],p03[9:8] | p05[3:0],p04[9:6] | 2'b0,p05[9:4] | p06[7:0] | p07[5:0],p06[9:8] | p08[3:0],p07[9:6] | 2'b0,p08[9:4] | p09[7:0] | p10[5:0],p09[9:8] | p11[3:0],p10[9:6] | 2'b0,p11[9:4] |
  1625. // | P | O | N | M | L | K | J | I | H | G | F | E | D | C | B | A |
  1626. //-----------|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|
  1627. //mode 0: | 2'b0,p02[9:4] | p02[3:0],p01[9:6] | p01[5:0],p00[9:8] | p00[7:0] | 2'b0,p05[9:4] | p05[3:0],p04[9:6] | p04[5:0],p03[9:8] | p03[7:0] | 2'b0,p08[9:4] | p08[3:0],p07[9:6] | p07[5:0],p06[9:8] | p06[7:0] | 2'b0,p11[9:4] | p11[3:0],p10[9:6] | p10[5:0],p09[9:8] | p09[7:0] |
  1628. // | M | N | O | P | I | J | K | L | E | F | G | H | A | B | C | D |
  1629. // mode 1 vs HW output : endian swap
  1630. // HW output vs mode 1 : byte swap in 4 bytes
  1631. //1) byte swap in 4 bytes
  1632. int i;
  1633. Uint8* pSrc = pPxl16Src;
  1634. Uint8* pDst = pPxl16Dst;
  1635. for (i = 0; i < 4; i++) {
  1636. pDst[i * 4 + 3] = pSrc[i * 4 + 0];
  1637. pDst[i * 4 + 2] = pSrc[i * 4 + 1];
  1638. pDst[i * 4 + 1] = pSrc[i * 4 + 2];
  1639. pDst[i * 4 + 0] = pSrc[i * 4 + 3];
  1640. }
  1641. #else
  1642. //-----------|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|
  1643. //mode 1: | 2'b0,p11[9:4] | p11[3:0],p10[9:6] | p10[5:0],p09[9:8] | p09[7:0] | 2'b0,p08[9:4] | p08[3:0],p07[9:6] | p07[5:0],p06[9:8] | p06[7:0] | 2'b0,p05[9:4] | p05[3:0],p04[9:6] | p04[5:0],p03[9:8] | p03[7:0] | 2'b0,p02[9:4] | p02[3:0],p01[9:6] | p01[5:0],p00[9:8] | p00[7:0] |
  1644. // | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P |
  1645. //HW output: | 2'b0,p11[9:4] | p11[3:0],p10[9:6] | p10[5:0],p09[9:8] | p09[7:0] | 2'b0,p08[9:4] | p08[3:0],p07[9:6] | p07[5:0],p06[9:8] | p06[7:0] | 2'b0,p05[9:4] | p05[3:0],p04[9:6] | p04[5:0],p03[9:8] | p03[7:0] | 2'b0,p02[9:4] | p02[3:0],p01[9:6] | p01[5:0],p00[9:8] | p00[7:0] |
  1646. // | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P |
  1647. //mode 0: | 2'b0,p02[9:4] | p02[3:0],p01[9:6] | p01[5:0],p00[9:8] | p00[7:0] | 2'b0,p05[9:4] | p05[3:0],p04[9:6] | p04[5:0],p03[9:8] | p03[7:0] | 2'b0,p08[9:4] | p08[3:0],p07[9:6] | p07[5:0],p06[9:8] | p06[7:0] | 2'b0,p11[9:4] | p11[3:0],p10[9:6] | p10[5:0],p09[9:8] | p09[7:0] |
  1648. // | M | N | O | P | I | J | K | L | E | F | G | H | A | B | C | D |
  1649. // mode 1 = HW output
  1650. // HW output vs mode 0 : 4-byte word swap
  1651. //1) 4-byte word swap
  1652. int i;
  1653. Uint32* pSrc = (Uint32*) pPxl16Src;
  1654. Uint32* pDst = (Uint32*) pPxl16Dst;
  1655. for (i = 0; i < 4; i++)
  1656. pDst[3 - i] = pSrc[i];
  1657. #endif
  1658. }
  1659. void DePxlOrder3pxl4byteMSB(Uint8* pPxl16Src, Uint8* pPxl16Dst)
  1660. {
  1661. #if 1
  1662. //-----------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|
  1663. //mode 1: | p11[9:2] | p11[1:0],p10[9:4] | p10[3:0],p09[9:6] | p09[5:0],2'b0 | p08[9:2] | p08[1:0],p07[9:4] | p07[3:0],p06[9:6] | p06[5:0],2'b0 | p05[9:2] | p05[1:0],p04[9:4] | p04[3:0],p03[9:6] | p03[5:0],2'b0 | p02[9:2] | p02[1:0],p01[9:4] | p01[3:0],p00[9:6] | p00[5:0],2'b0 |
  1664. // | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P |
  1665. //-----------|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|-----8bit------|-------8bit--------|-------8bit--------|---8bit---|
  1666. //HW output: | p00[5:0],2'b0 | p01[3:0],p00[9:6] | p02[1:0],p01[9:4] | p02[9:2] | p03[5:0],2'b0 | p04[3:0],p03[9:6] | p05[1:0],p04[9:4] | p05[9:2] | p06[5:0],2'b0 | p07[3:0],p06[9:6] | p08[1:0],p07[9:4] | p08[9:2] | p09[5:0],2'b0 | p10[3:0],p09[9:6] | p11[1:0],p10[9:4] | p11[9:2] |
  1667. // | P | O | N | M | L | K | J | I | H | G | F | E | D | C | B | A |
  1668. //-----------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|
  1669. //mode 0: | p00[9:2] | p00[1:0],p01[9:4] | p01[3:0],p02[9:6] | p02[5:0],2'b0 | p03[9:2] | p03[1:0],p04[9:4] | p04[3:0],p05[9:6] | p05[5:0],2'b0 | p06[9:2] | p06[1:0],p07[9:4] | p07[3:0],p08[9:6] | p08[5:0],2'b0 | p09[9:2] | p09[1:0],p10[9:4] | p10[3:0],p11[9:6] | p11[5:0],2'b0 |
  1670. // mode 1 vs HW output : endian swap
  1671. // HW output vs mode 1 : byte swap in 4 bytes & pixel swap in 3 pixels
  1672. //1) byte swap in 4 bytes
  1673. //2) pixel swap in 3 pixels
  1674. int i;
  1675. Uint8* pSrc = pPxl16Src;
  1676. Uint8* pDst = pPxl16Dst;
  1677. Uint32 temp ;
  1678. Uint32 temp0;
  1679. Uint32 temp1;
  1680. Uint32 temp2;
  1681. for (i = 0; i < 4; i++) {
  1682. pDst[i * 4 + 3] = pSrc[i * 4 + 0];
  1683. pDst[i * 4 + 2] = pSrc[i * 4 + 1];
  1684. pDst[i * 4 + 1] = pSrc[i * 4 + 2];
  1685. pDst[i * 4 + 0] = pSrc[i * 4 + 3]; //| p02[9:2] | p02[1:0],p01[9:4] | p01[3:0],p00[9:6] | p00[5:0],2'b0 |
  1686. temp = (pDst[4*i + 0] << 24) + (pDst[4*i + 1] << 16) + (pDst[4*i + 2] << 8) + (pDst[4*i + 3] << 0);
  1687. temp0 = (temp >> 2) & 0x3ff;
  1688. temp1 = (temp >> 12) & 0x3ff;
  1689. temp2 = (temp >> 22) & 0x3ff;
  1690. temp = (temp2 << 2) + (temp1 << 12) + (temp0 << 22);
  1691. pDst[i * 4 + 0] = (temp >> 24) & 0xff;
  1692. pDst[i * 4 + 1] = (temp >> 16) & 0xff;
  1693. pDst[i * 4 + 2] = (temp >> 8) & 0xff;
  1694. pDst[i * 4 + 3] = (temp >> 0) & 0xff; //| p00[9:2] | p00[1:0],p01[9:4] | p01[3:0],p02[9:6] | p02[5:0],2'b0 |
  1695. }
  1696. #else
  1697. //-----------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|---8bit---|-------8bit--------|-------8bit--------|-----8bit------|
  1698. //mode 1: | p11[9:2] | p11[1:0],p10[9:4] | p10[3:0],p09[9:6] | p09[5:0],2'b0 | p08[9:2] | p08[1:0],p07[9:4] | p07[3:0],p06[9:6] | p06[5:0],2'b0 | p05[9:2] | p05[1:0],p04[9:4] | p04[3:0],p03[9:6] | p03[5:0],2'b0 | p02[9:2] | p02[1:0],p01[9:4] | p01[3:0],p00[9:6] | p00[5:0],2'b0 |
  1699. // | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P |
  1700. //HW output: | p11[9:2] | p11[1:0],p10[9:4] | p10[3:0],p09[9:6] | p09[5:0],2'b0 | p08[9:2] | p08[1:0],p07[9:4] | p07[3:0],p06[9:6] | p06[5:0],2'b0 | p05[9:2] | p05[1:0],p04[9:4] | p04[3:0],p03[9:6] | p03[5:0],2'b0 | p02[9:2] | p02[1:0],p01[9:4] | p01[3:0],p00[9:6] | p00[5:0],2'b0 |
  1701. // | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P |
  1702. //mode 0: | p00[9:2] | p00[1:0],p01[9:4] | p01[3:0],p02[9:6] | p02[5:0],2'b0 | p03[9:2] | p03[1:0],p04[9:4] | p04[3:0],p05[9:6] | p05[5:0],2'b0 | p06[9:2] | p06[1:0],p07[9:4] | p07[3:0],p08[9:6] | p08[5:0],2'b0 | p09[9:2] | p09[1:0],p10[9:4] | p10[3:0],p11[9:6] | p11[5:0],2'b0 |
  1703. // mode 1 = HW output
  1704. // HW output vs mode 0 : 4-byte word swap & pixel swap in 3 pixels
  1705. //1) 4-byte word swap
  1706. //2) pixel swap in 3 pixels
  1707. int i;
  1708. Uint8* pSrc = pPxl16Src;
  1709. Uint8* pDst = pPxl16Dst;
  1710. for (i = 0; i < 4; i++) {
  1711. Uint32 temp = (pSrc[4*i + 0] << 24) + (pSrc[4*i + 1] << 16) + (pSrc[4*i + 2] << 8) + (pSrc[4*i + 3] << 0);
  1712. Uint32 temp0 = (temp >> 2) & 0x3ff;
  1713. Uint32 temp1 = (temp >> 12) & 0x3ff;
  1714. Uint32 temp2 = (temp >> 22) & 0x3ff;
  1715. temp = (temp2 << 2) + (temp1 << 12) + (temp0 << 22);
  1716. pDst[4*(3 - i) + 0] = (temp >> 24) & 0xff;
  1717. pDst[4*(3 - i) + 1] = (temp >> 16) & 0xff;
  1718. pDst[4*(3 - i) + 2] = (temp >> 8) & 0xff;
  1719. pDst[4*(3 - i) + 3] = (temp >> 0) & 0xff;
  1720. }
  1721. #endif
  1722. }
  1723. //srcWidthY and srcWidthC must be alinged with 16 pixels
  1724. void DePxlOrder(
  1725. Uint32 srcWidthY,
  1726. Uint32 srcHeightY,
  1727. Uint32 srcWidthC,
  1728. Uint32 srcHeightC,
  1729. Uint32 interLeave,
  1730. Uint32 is10bit,
  1731. Uint32 is3pxl4byte,
  1732. Uint32 isMSB,
  1733. Uint8* pY,
  1734. Uint8* pCb,
  1735. Uint8* pCr
  1736. )
  1737. {
  1738. //srcWidthY and srcWidthC must be alinged with 16 pixels
  1739. int x, y, i, uv;
  1740. int uv_num;
  1741. Uint8* pChroma;
  1742. Uint8 temp[16];
  1743. for (y = 0; y < (int)srcHeightY; y++) {
  1744. for (x = 0; x < (int)srcWidthY; x += 16) {
  1745. for (i = 0; i < 16; i++)
  1746. temp[i] = pY[x + i];
  1747. if (is10bit != TRUE) //8bit
  1748. DePxlOrder8bit(temp, &(pY[x]));
  1749. else if (is3pxl4byte != TRUE) //10bit : 1pxl2 byte
  1750. DePxlOrder1pxl2byte(temp, &(pY[x]));
  1751. else if (isMSB) //10bit : is3pxl4byte and MSB
  1752. DePxlOrder3pxl4byteMSB(temp, &(pY[x]));
  1753. else //10bit : is3pxl4byte and LSB
  1754. DePxlOrder3pxl4byteLSB(temp, &(pY[x]));
  1755. }
  1756. pY += srcWidthY;
  1757. }
  1758. if (srcHeightC == 0)
  1759. return;
  1760. uv_num = (interLeave) ? 1 : 2;
  1761. for (uv = 0; uv < uv_num; uv++) {
  1762. if (uv == 0)
  1763. pChroma = pCb;
  1764. else
  1765. pChroma = pCr;
  1766. for (y = 0; y < (int)srcHeightC; y++) {
  1767. for (x = 0; x < (int)srcWidthC; x += 16) {
  1768. for (i = 0; i < 16; i++)
  1769. temp[i] = pChroma[x + i];
  1770. if (is10bit != TRUE) //8bit
  1771. DePxlOrder8bit(temp, &(pChroma[x]));
  1772. else if (is3pxl4byte != TRUE) //10bit : 1pxl2 byte
  1773. DePxlOrder1pxl2byte(temp, &(pChroma[x]));
  1774. else if (isMSB) //10bit : is3pxl4byte and MSB
  1775. DePxlOrder3pxl4byteMSB(temp, &(pChroma[x]));
  1776. else //10bit : is3pxl4byte and LSB
  1777. DePxlOrder3pxl4byteLSB(temp, &(pChroma[x]));
  1778. }
  1779. pChroma += srcWidthC;
  1780. }
  1781. }
  1782. }
  1783. void LoadSrcYUV(
  1784. Uint32 coreIdx,
  1785. TiledMapConfig mapCfg,
  1786. Uint8* pSrc,
  1787. FrameBuffer* fbSrc,
  1788. VpuRect cropRect,
  1789. BOOL enableCrop,
  1790. Uint32 is10bit,
  1791. Uint32 is3pxl4byte,
  1792. Uint32 isMSB,
  1793. Uint32 srcWidthY,
  1794. Uint32 srcHeightY,
  1795. Uint32 srcWidthC,
  1796. Uint32 srcHeightC,
  1797. Uint32 chroma_stride
  1798. )
  1799. {
  1800. Uint32 y;
  1801. Uint32 pix_addr;
  1802. Uint8* puc;
  1803. Uint8* rowBufferY, *rowBufferCb, *rowBufferCr;
  1804. Int32 baseY;
  1805. Int32 baseCb;
  1806. Int32 baseCr;
  1807. Uint8 *pY = NULL;
  1808. Uint8 *pCb = NULL;
  1809. Uint8 *pCr = NULL;
  1810. Uint32 offsetX, offsetY;
  1811. int interLeave = fbSrc->cbcrInterleave;
  1812. Uint32 stride = fbSrc->stride;
  1813. #ifdef SAVE_YUV
  1814. EndianMode endian = 31;
  1815. #else
  1816. EndianMode endian = (EndianMode)fbSrc->endian;
  1817. #endif
  1818. offsetX = (enableCrop == TRUE ? cropRect.left : 0);
  1819. offsetY = (enableCrop == TRUE ? cropRect.top : 0);
  1820. //base address
  1821. baseY = fbSrc->bufY;
  1822. baseCb = fbSrc->bufCb;
  1823. baseCr = fbSrc->bufCr;
  1824. //1. memory allocation for FPGA YUV frame
  1825. pY = (Uint8*)osal_malloc(stride * srcHeightY);
  1826. if (!pY)
  1827. return ;
  1828. if (srcHeightC != 0) {
  1829. pCb = (Uint8*)osal_malloc(chroma_stride * srcHeightC);
  1830. if (!pCb)
  1831. return ;
  1832. if (interLeave != TRUE) {
  1833. pCr = (Uint8*)osal_malloc(chroma_stride * srcHeightC);
  1834. if (!pCr)
  1835. return ;
  1836. }
  1837. }
  1838. //2.1 load data from FPGA memory + endian
  1839. vdi_read_memory(coreIdx, fbSrc->bufY, pY, stride * srcHeightY, endian);
  1840. if (srcHeightC != 0) {
  1841. if (!pCb)
  1842. return ;
  1843. vdi_read_memory(coreIdx, fbSrc->bufCb, pCb, chroma_stride * srcHeightC, endian);
  1844. if (interLeave != TRUE) {
  1845. if (!pCr)
  1846. return ;
  1847. vdi_read_memory(coreIdx, fbSrc->bufCr, pCr, chroma_stride * srcHeightC, endian);
  1848. }
  1849. }
  1850. #if defined(SAVE_YUV)
  1851. #else
  1852. DePxlOrder(stride, srcHeightY, chroma_stride, srcHeightC,
  1853. interLeave, is10bit, is3pxl4byte, isMSB, pY, pCb, pCr);
  1854. #endif
  1855. //3.1 : Luma YUV source generate
  1856. puc = pSrc;
  1857. for (y = 0; y < srcHeightY; y += 1) {
  1858. pix_addr = GetXY2AXIAddr(&mapCfg, 0, y + offsetY, 0, stride, fbSrc);
  1859. rowBufferY = pY + (pix_addr - baseY);
  1860. osal_memcpy(puc + y*srcWidthY, rowBufferY + offsetX, srcWidthY);
  1861. }
  1862. //3.2 : Chroma YUV source generate
  1863. if (srcHeightC != 0) {
  1864. //Cb
  1865. puc = pSrc + srcWidthY*srcHeightY;
  1866. if ( !pCb )
  1867. return ;
  1868. for (y = 0; y < srcHeightC; y += 1) {
  1869. pix_addr = GetXY2AXIAddr(&mapCfg, 2, y + (offsetY / 2), 0, chroma_stride, fbSrc);
  1870. rowBufferCb = pCb + (pix_addr - baseCb);
  1871. osal_memcpy(puc + (y*srcWidthC), rowBufferCb + (offsetX / 2), srcWidthC);
  1872. }
  1873. //Cr
  1874. if (interLeave != TRUE) {
  1875. if ( !pCr )
  1876. return ;
  1877. puc = puc + srcWidthC*srcHeightC;
  1878. for (y = 0; y < srcHeightC; y += 1) {
  1879. pix_addr = GetXY2AXIAddr(&mapCfg, 3, y + (offsetY / 2), 0, chroma_stride, fbSrc);
  1880. rowBufferCr = pCr + (pix_addr - baseCr);
  1881. osal_memcpy(puc + (y*srcWidthC), rowBufferCr + (offsetX / 2), srcWidthC);
  1882. }
  1883. }
  1884. }
  1885. if (pY)
  1886. osal_free(pY);
  1887. if (pCb)
  1888. osal_free(pCb);
  1889. if (pCr)
  1890. osal_free(pCr);
  1891. }
  1892. void LoadSrcYUV2(
  1893. Uint32 coreIdx,
  1894. TiledMapConfig mapCfg,
  1895. Uint8* pSrc,
  1896. Uint8** pSrc2,
  1897. FrameBuffer* fbSrc,
  1898. VpuRect cropRect,
  1899. BOOL enableCrop,
  1900. Uint32 is10bit,
  1901. Uint32 is3pxl4byte,
  1902. Uint32 isMSB,
  1903. Uint32 srcWidthY,
  1904. Uint32 srcHeightY,
  1905. Uint32 srcWidthC,
  1906. Uint32 srcHeightC,
  1907. Uint32 chroma_stride
  1908. )
  1909. {
  1910. Uint32 pix_addr;
  1911. Uint8* rowBufferY;
  1912. Int32 baseY;
  1913. Uint8 *pY = NULL;
  1914. Uint8 *pCb = NULL;
  1915. Uint8 *pCr = NULL;
  1916. int interLeave = fbSrc->cbcrInterleave;
  1917. Uint32 stride = fbSrc->stride;
  1918. #ifdef SAVE_YUV
  1919. EndianMode endian = 31;
  1920. #else
  1921. EndianMode endian = (EndianMode)fbSrc->endian;
  1922. #endif
  1923. //base address
  1924. baseY = fbSrc->bufY;
  1925. VLOG(DEBUG, "%s %d baseY = %x stride = %d srcHeightY = %d endian = %d\r\n",
  1926. __FUNCTION__, __LINE__, baseY, stride, srcHeightY, endian);
  1927. int ret = vdi_read_memory2(coreIdx, fbSrc->bufY, &pY, stride * srcHeightY, endian);
  1928. #if defined(SAVE_YUV)
  1929. #else
  1930. // not used here for 8bit
  1931. if (is10bit) {
  1932. DePxlOrder(stride, srcHeightY, chroma_stride, srcHeightC,
  1933. interLeave, is10bit, is3pxl4byte, isMSB, pY, pCb, pCr);
  1934. }
  1935. #endif
  1936. pix_addr = fbSrc->bufY + 0xffffffff00000000;
  1937. rowBufferY = pY + (pix_addr - baseY);
  1938. VLOG(DEBUG, "%s %d ret = %d, pix_addr = %lx, pY = %p, rowBufferY = %p pSrc = %p pSrc2 = %p\n",
  1939. __FUNCTION__, __LINE__, ret, pix_addr, pY, rowBufferY, pSrc, pSrc2);
  1940. if (pSrc) {
  1941. osal_memcpy(pSrc, rowBufferY, srcHeightY*srcWidthY*3/2);
  1942. }
  1943. if (pSrc2) {
  1944. *pSrc2 = rowBufferY;
  1945. }
  1946. // following code store output buffers
  1947. #if 0
  1948. {
  1949. void *virt_addr = vdi_map_virt2(coreIdx, srcHeightY*srcWidthY*3/2, fbSrc->bufY);
  1950. VLOG(INFO, "------=-==-=-=-==%p, %d\r\n", virt_addr, srcHeightY*srcWidthY*3/2);
  1951. FILE *fb = fopen("./out_vpu.bcp", "ab+");
  1952. fwrite(virt_addr, 1, srcHeightY*srcWidthY*3/2, fb);
  1953. fclose(fb);
  1954. }
  1955. #endif
  1956. }
  1957. BOOL CalcYuvSize_412(
  1958. Int32 format,
  1959. Int32 picWidth,
  1960. Int32 picHeight,
  1961. Int32 cbcrInterleave,
  1962. size_t *lumaSize,
  1963. size_t *chromaSize,
  1964. size_t *frameSize,
  1965. Int32 *bitDepth,
  1966. Int32 *packedFormat,
  1967. Int32 *yuv3p4b
  1968. )
  1969. {
  1970. #if defined(SAVE_YUV)
  1971. return CalcYuvSize(format, picWidth, picHeight, cbcrInterleave, lumaSize, chromaSize, frameSize, NULL, NULL, NULL);
  1972. #else
  1973. if (format >= FORMAT_YUYV) {
  1974. if (format == FORMAT_YUYV || format == FORMAT_YVYU || format == FORMAT_UYVY || format == FORMAT_VYUY)
  1975. format = FORMAT_420;
  1976. else
  1977. format = FORMAT_420_P10_16BIT_LSB;
  1978. }
  1979. else if (format == FORMAT_422_P10_16BIT_LSB || format == FORMAT_422_P10_16BIT_MSB)
  1980. format = FORMAT_420_P10_16BIT_LSB;
  1981. else if (format == FORMAT_422_P10_32BIT_LSB || format == FORMAT_422_P10_32BIT_MSB)
  1982. format = FORMAT_420_P10_16BIT_LSB;
  1983. else if (format == FORMAT_420_P10_32BIT_LSB || format == FORMAT_420_P10_32BIT_MSB)
  1984. format = FORMAT_420_P10_16BIT_LSB;
  1985. else if (format == FORMAT_422)
  1986. format = FORMAT_420;
  1987. return CalcYuvSize(format, picWidth, picHeight, 0/*fb->cbcrInterleave*/, lumaSize, chromaSize, frameSize, NULL, NULL, NULL);
  1988. #endif
  1989. }
  1990. void GeneratePicParam(
  1991. FrameBuffer* fbSrc,
  1992. VpuRect cropRect,
  1993. BOOL enableCrop,
  1994. Uint32* is422,
  1995. Uint32* isPack,
  1996. Uint32* PackMode,
  1997. Uint32* is10bit,
  1998. Uint32* isMSB,
  1999. Uint32* is3pxl4byte,
  2000. Uint32* srcWidthY,
  2001. Uint32* srcHeightY,
  2002. Uint32* srcWidthC,
  2003. Uint32* srcHeightC,
  2004. Uint32* chroma_stride,
  2005. Uint32* dstWidthY,
  2006. Uint32* dstHeightY,
  2007. Uint32* dstWidthC,
  2008. Uint32* dstHeightC
  2009. )
  2010. {
  2011. Uint32 cropWidth;
  2012. Uint32 cropHeight;
  2013. Uint32 stride = fbSrc->stride;
  2014. Uint32 height = fbSrc->height;
  2015. int interLeave = fbSrc->cbcrInterleave;
  2016. cropWidth = (enableCrop == TRUE ? cropRect.right - cropRect.left : stride);
  2017. cropHeight = (enableCrop == TRUE ? cropRect.bottom - cropRect.top : height);
  2018. //initial setting
  2019. *isPack = 0;
  2020. *PackMode = 0;
  2021. *is10bit = 0;
  2022. *isMSB = 0;
  2023. *is3pxl4byte = 0;
  2024. *is422 = 0;
  2025. *srcWidthY = cropWidth;
  2026. *srcHeightY = cropHeight;
  2027. *srcWidthC = cropWidth / 2;
  2028. *srcHeightC = cropHeight / 2;
  2029. *dstWidthY = cropWidth;
  2030. *dstHeightY = cropHeight;
  2031. *dstWidthC = cropWidth / 2;
  2032. *dstHeightC = cropHeight / 2;
  2033. switch (fbSrc->format) {
  2034. case FORMAT_420 :
  2035. break;
  2036. case FORMAT_420_P10_16BIT_LSB :
  2037. *is10bit = 1;
  2038. break;
  2039. case FORMAT_420_P10_16BIT_MSB :
  2040. *is10bit = 1;
  2041. *isMSB = 1;
  2042. break;
  2043. case FORMAT_420_P10_32BIT_LSB :
  2044. *is3pxl4byte = 1;
  2045. *is10bit = 1;
  2046. break;
  2047. case FORMAT_420_P10_32BIT_MSB :
  2048. *is3pxl4byte = 1;
  2049. *is10bit = 1;
  2050. *isMSB = 1;
  2051. break;
  2052. case FORMAT_422 :
  2053. *is422 = 1;
  2054. break;
  2055. case FORMAT_422_P10_16BIT_MSB :
  2056. *is422 = 1;
  2057. *is10bit = 1;
  2058. *isMSB = 1;
  2059. break;
  2060. case FORMAT_422_P10_16BIT_LSB :
  2061. *is422 = 1;
  2062. *is10bit = 1;
  2063. break;
  2064. case FORMAT_422_P10_32BIT_MSB :
  2065. *is422 = 1;
  2066. *is3pxl4byte = 1;
  2067. *is10bit = 1;
  2068. *isMSB = 1;
  2069. break;
  2070. case FORMAT_422_P10_32BIT_LSB :
  2071. *is422 = 1;
  2072. *is3pxl4byte = 1;
  2073. *is10bit = 1;
  2074. break;
  2075. case FORMAT_YUYV :
  2076. *isPack = 1;
  2077. break;
  2078. case FORMAT_YVYU :
  2079. *isPack = 1;
  2080. *PackMode = 1;
  2081. break;
  2082. case FORMAT_UYVY :
  2083. *isPack = 1;
  2084. *PackMode = 2;
  2085. break;
  2086. case FORMAT_VYUY :
  2087. *isPack = 1;
  2088. *PackMode = 3;
  2089. break;
  2090. case FORMAT_YUYV_P10_16BIT_LSB:
  2091. *is10bit = 1;
  2092. *isPack = 1;
  2093. break;
  2094. case FORMAT_YUYV_P10_16BIT_MSB:
  2095. *is10bit = 1;
  2096. *isMSB = 1;
  2097. *isPack = 1;
  2098. break;
  2099. case FORMAT_YVYU_P10_16BIT_LSB:
  2100. *is10bit = 1;
  2101. *isPack = 1;
  2102. *PackMode = 1;
  2103. break;
  2104. case FORMAT_YVYU_P10_16BIT_MSB:
  2105. *is10bit = 1;
  2106. *isMSB = 1;
  2107. *isPack = 1;
  2108. *PackMode = 1;
  2109. break;
  2110. case FORMAT_UYVY_P10_16BIT_LSB:
  2111. *is10bit = 1;
  2112. *isPack = 1;
  2113. *PackMode = 2;
  2114. break;
  2115. case FORMAT_UYVY_P10_16BIT_MSB:
  2116. *is10bit = 1;
  2117. *isMSB = 1;
  2118. *isPack = 1;
  2119. *PackMode = 2;
  2120. break;
  2121. case FORMAT_VYUY_P10_16BIT_LSB:
  2122. *is10bit = 1;
  2123. *isPack = 1;
  2124. *PackMode = 3;
  2125. break;
  2126. case FORMAT_VYUY_P10_16BIT_MSB:
  2127. *is10bit = 1;
  2128. *isMSB = 1;
  2129. *isPack = 1;
  2130. *PackMode = 3;
  2131. break;
  2132. case FORMAT_YUYV_P10_32BIT_LSB:
  2133. *is3pxl4byte = 1;
  2134. *is10bit = 1;
  2135. *isPack = 1;
  2136. break;
  2137. case FORMAT_YUYV_P10_32BIT_MSB:
  2138. *is3pxl4byte = 1;
  2139. *isMSB = 1;
  2140. *is10bit = 1;
  2141. *isPack = 1;
  2142. break;
  2143. case FORMAT_YVYU_P10_32BIT_LSB:
  2144. *is3pxl4byte = 1;
  2145. *is10bit = 1;
  2146. *isPack = 1;
  2147. *PackMode = 1;
  2148. break;
  2149. case FORMAT_YVYU_P10_32BIT_MSB:
  2150. *is3pxl4byte = 1;
  2151. *isMSB = 1;
  2152. *is10bit = 1;
  2153. *isPack = 1;
  2154. *PackMode = 1;
  2155. break;
  2156. case FORMAT_UYVY_P10_32BIT_LSB:
  2157. *is3pxl4byte = 1;
  2158. *is10bit = 1;
  2159. *isPack = 1;
  2160. *PackMode = 2;
  2161. break;
  2162. case FORMAT_UYVY_P10_32BIT_MSB:
  2163. *is3pxl4byte = 1;
  2164. *isMSB = 1;
  2165. *is10bit = 1;
  2166. *isPack = 1;
  2167. *PackMode = 2;
  2168. break;
  2169. case FORMAT_VYUY_P10_32BIT_LSB:
  2170. *is3pxl4byte = 1;
  2171. *is10bit = 1;
  2172. *isPack = 1;
  2173. *PackMode = 3;
  2174. break;
  2175. case FORMAT_VYUY_P10_32BIT_MSB:
  2176. *is3pxl4byte = 1;
  2177. *isMSB = 1;
  2178. *is10bit = 1;
  2179. *isPack = 1;
  2180. *PackMode = 3;
  2181. break;
  2182. default:
  2183. break;
  2184. }
  2185. //Luma src width
  2186. if (*is10bit) {
  2187. if (*is3pxl4byte)
  2188. *srcWidthY = ((cropWidth + 2) / 3 * 4);
  2189. else
  2190. *srcWidthY = cropWidth * 2;
  2191. }
  2192. if (*isPack)
  2193. *srcWidthY = *srcWidthY * 2;
  2194. //Chroma src width
  2195. if (interLeave == TRUE) {
  2196. if (*is10bit) {
  2197. if (*is3pxl4byte)
  2198. *srcWidthC = ((cropWidth + 2) / 3 * 4);
  2199. else
  2200. *srcWidthC = cropWidth * 2;
  2201. }
  2202. else
  2203. *srcWidthC = cropWidth;
  2204. }
  2205. else {
  2206. if (*is10bit) {
  2207. if (*is3pxl4byte)
  2208. *srcWidthC = (((cropWidth / 2) + 2) / 3 * 4);
  2209. else
  2210. *srcWidthC = cropWidth;
  2211. }
  2212. }
  2213. //Chroma src height
  2214. if (*is422 == TRUE)
  2215. *srcHeightC = cropHeight;
  2216. else if (*isPack)
  2217. *srcHeightC = 0;
  2218. //Chroma stride
  2219. if (interLeave == TRUE)
  2220. *chroma_stride = stride;
  2221. else
  2222. *chroma_stride = stride / 2;
  2223. //Chroma dst height
  2224. *dstHeightC = cropHeight / 2;
  2225. if (*is10bit == TRUE) {
  2226. *dstWidthY = cropWidth * 2;
  2227. *dstWidthC = cropWidth;
  2228. }
  2229. }
  2230. Uint32 StoreYuvImageBurstLinear(
  2231. Uint32 coreIdx,
  2232. FrameBuffer *fbSrc,
  2233. TiledMapConfig mapCfg,
  2234. Uint8 *pDst,
  2235. VpuRect cropRect,
  2236. BOOL enableCrop,
  2237. BOOL isVP9
  2238. )
  2239. {
  2240. Uint32 y, x;
  2241. Uint32 pix_addr, div_x, div_y, chroma_stride=0;
  2242. Uint8* puc;
  2243. Uint8* rowBufferY, *rowBufferCb, *rowBufferCr;
  2244. Uint32 stride = fbSrc->stride;
  2245. Uint32 height = fbSrc->height;
  2246. int interLeave = fbSrc->cbcrInterleave;
  2247. BOOL nv21 = fbSrc->nv21;
  2248. EndianMode endian = (EndianMode)fbSrc->endian;
  2249. FrameBufferFormat format = (FrameBufferFormat)fbSrc->format;
  2250. Uint32 width;
  2251. Uint32 dstWidth=0, dstHeight=0;
  2252. Uint32 offsetX, offsetY;
  2253. Uint32 dstChromaHeight = 0;
  2254. Uint32 dstChromaWidth = 0;
  2255. Uint32 chromaHeight = 0;
  2256. Uint32 bpp=8;
  2257. Uint32 p10_32bit_interleave = 0;
  2258. Int32 productId;
  2259. Int32 dramBusWidth = 8;
  2260. Uint32 totSize = 0;
  2261. BOOL copyLumaOnly = FALSE;
  2262. //Int32 addr;
  2263. Int32 baseY;
  2264. Int32 baseCb;
  2265. Int32 baseCr;
  2266. Uint8 *pY;
  2267. Uint8 *pCbTemp;
  2268. Uint8 *pCb;
  2269. Uint8 *pCr;
  2270. productId = VPU_GetProductId(coreIdx);
  2271. if (PRODUCT_ID_W_SERIES(productId)) {
  2272. dramBusWidth = 16;
  2273. }
  2274. switch (fbSrc->format) {
  2275. case FORMAT_420:
  2276. case FORMAT_420_P10_16BIT_LSB:
  2277. case FORMAT_420_P10_16BIT_MSB:
  2278. case FORMAT_420_P10_32BIT_LSB:
  2279. case FORMAT_420_P10_32BIT_MSB:
  2280. case FORMAT_422:
  2281. case FORMAT_422_P10_16BIT_LSB:
  2282. case FORMAT_422_P10_16BIT_MSB:
  2283. case FORMAT_422_P10_32BIT_LSB:
  2284. case FORMAT_422_P10_32BIT_MSB:
  2285. div_x = 2;
  2286. break;
  2287. default:
  2288. div_x = 1;
  2289. }
  2290. switch (fbSrc->format) {
  2291. case FORMAT_420:
  2292. case FORMAT_420_P10_16BIT_LSB:
  2293. case FORMAT_420_P10_16BIT_MSB:
  2294. case FORMAT_420_P10_32BIT_LSB:
  2295. case FORMAT_420_P10_32BIT_MSB:
  2296. case FORMAT_224:
  2297. div_y = 2;
  2298. break;
  2299. default:
  2300. div_y = 1;
  2301. }
  2302. //for matching with Ref-C
  2303. width = (enableCrop == TRUE ? cropRect.right - cropRect.left : stride);
  2304. dstHeight = (enableCrop == TRUE ? cropRect.bottom - cropRect.top : height);
  2305. offsetX = (enableCrop == TRUE ? cropRect.left : 0);
  2306. offsetY = (enableCrop == TRUE ? cropRect.top : 0);
  2307. switch (fbSrc->format) {
  2308. case FORMAT_400:
  2309. copyLumaOnly = TRUE;
  2310. break;
  2311. case FORMAT_YUYV:
  2312. case FORMAT_YVYU:
  2313. case FORMAT_UYVY:
  2314. case FORMAT_VYUY:
  2315. copyLumaOnly = TRUE;
  2316. dstWidth = width * 2;
  2317. dstChromaHeight = 0;
  2318. chromaHeight = 0;
  2319. break;
  2320. case FORMAT_YUYV_P10_16BIT_LSB:
  2321. case FORMAT_YUYV_P10_16BIT_MSB:
  2322. case FORMAT_YVYU_P10_16BIT_LSB:
  2323. case FORMAT_YVYU_P10_16BIT_MSB:
  2324. case FORMAT_UYVY_P10_16BIT_LSB:
  2325. case FORMAT_UYVY_P10_16BIT_MSB:
  2326. case FORMAT_VYUY_P10_16BIT_LSB:
  2327. case FORMAT_VYUY_P10_16BIT_MSB:
  2328. copyLumaOnly = TRUE;
  2329. dstWidth = (width * 2)*2;
  2330. dstChromaHeight = 0;
  2331. chromaHeight = 0;
  2332. break;
  2333. case FORMAT_YUYV_P10_32BIT_LSB:
  2334. case FORMAT_YUYV_P10_32BIT_MSB:
  2335. case FORMAT_YVYU_P10_32BIT_LSB:
  2336. case FORMAT_YVYU_P10_32BIT_MSB:
  2337. case FORMAT_UYVY_P10_32BIT_LSB:
  2338. case FORMAT_UYVY_P10_32BIT_MSB:
  2339. case FORMAT_VYUY_P10_32BIT_LSB:
  2340. case FORMAT_VYUY_P10_32BIT_MSB:
  2341. copyLumaOnly = TRUE;
  2342. dstWidth = ((width+2)/3*4)*2;
  2343. dstChromaHeight = 0;
  2344. chromaHeight = 0;
  2345. break;
  2346. case FORMAT_422_P10_16BIT_LSB:
  2347. case FORMAT_422_P10_16BIT_MSB:
  2348. dstWidth = width * 2;
  2349. bpp = 16;
  2350. dstChromaWidth = dstWidth / div_x;
  2351. dstChromaHeight = dstHeight / div_y;
  2352. chromaHeight = height / div_y;
  2353. chroma_stride = (stride / div_x);
  2354. break;
  2355. case FORMAT_420_P10_16BIT_LSB:
  2356. case FORMAT_420_P10_16BIT_MSB:
  2357. dstWidth = width * 2;
  2358. bpp = 16;
  2359. dstChromaWidth = dstWidth / div_x;
  2360. dstChromaHeight = dstHeight / div_y;
  2361. chromaHeight = height / div_y;
  2362. chroma_stride = (stride / div_x);
  2363. break;
  2364. case FORMAT_420_P10_32BIT_LSB:
  2365. case FORMAT_420_P10_32BIT_MSB:
  2366. #ifdef DUMP_YUV_WHOLE_DATA
  2367. if (interLeave)
  2368. {
  2369. dstChromaWidth = ((VPU_ALIGN16(width/div_x))*2+11)/12*16;
  2370. dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
  2371. dstChromaHeight = dstHeight / div_y;
  2372. stride = stride;
  2373. chroma_stride = stride;
  2374. dstWidth = (VPU_ALIGN16(width)+11)/12*16;
  2375. interLeave = 0;
  2376. }
  2377. else
  2378. {
  2379. dstChromaWidth = ((VPU_ALIGN16(width/div_x))+11)/12*16;
  2380. dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
  2381. dstChromaHeight = dstHeight / div_y;
  2382. chroma_stride = dstChromaWidth;
  2383. stride = (VPU_ALIGN16(stride)+11)/12*16;
  2384. dstWidth = (VPU_ALIGN16(dstWidth)+11)/12*16;
  2385. }
  2386. break;
  2387. #else
  2388. if (interLeave) {
  2389. dstChromaWidth = ((VPU_ALIGN16(width*2/div_x))+11)/12*16;
  2390. dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
  2391. if(isVP9 == TRUE) {
  2392. dstChromaWidth = VPU_ALIGN32(dstChromaWidth);
  2393. }
  2394. chroma_stride = stride;
  2395. dstChromaWidth = (width/div_x+2)/3*4;
  2396. dstChromaHeight = dstHeight / div_y;
  2397. chromaHeight = height / div_y;
  2398. dstWidth = (width+2)/3*4;
  2399. interLeave = 0;
  2400. p10_32bit_interleave = 1;
  2401. }
  2402. else {
  2403. //dstChromaWidth = ((VPU_ALIGN16(width/div_x))+11)/12*16;
  2404. // dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
  2405. //chroma_stride = dstChromaWidth;
  2406. chroma_stride = stride / 2;
  2407. dstChromaWidth = (width/2+2)/3*4;
  2408. dstChromaHeight = dstHeight / div_y;
  2409. chromaHeight = height / div_y;
  2410. dstWidth = (width+2)/3*4;
  2411. }
  2412. break;
  2413. #endif
  2414. default:
  2415. dstWidth = width;
  2416. dstChromaWidth = width / div_x;
  2417. dstChromaHeight = dstHeight / div_y;
  2418. chromaHeight = height / div_y;
  2419. chroma_stride = (stride / div_x);
  2420. break;
  2421. }
  2422. puc = pDst;
  2423. pY = (Uint8*)osal_malloc(stride * height);
  2424. if ( !pY )
  2425. return 0;
  2426. pCbTemp = (Uint8*)osal_malloc(stride*4 * chromaHeight);
  2427. if ( !pCbTemp )
  2428. return 0;
  2429. pCb = (Uint8*)osal_malloc(stride*4 * chromaHeight);
  2430. if ( !pCb )
  2431. return 0;
  2432. pCr = (Uint8*)osal_malloc(stride*2 * chromaHeight);
  2433. if ( !pCr )
  2434. return 0;
  2435. baseY = fbSrc->bufY;
  2436. baseCb = fbSrc->bufCb;
  2437. baseCr = fbSrc->bufCr;
  2438. vdi_read_memory(coreIdx, fbSrc->bufY, pY, stride * height, endian);
  2439. for (y=0 ; y<dstHeight ; y+=1) {
  2440. pix_addr = GetXY2AXIAddr(&mapCfg, 0, y+offsetY, 0, stride, fbSrc);
  2441. rowBufferY = pY + (pix_addr - baseY);
  2442. // CHECK POINT
  2443. for (x=0; x<stride ; x+=dramBusWidth) {
  2444. if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
  2445. SwapPixelOrder(rowBufferY+x);
  2446. }
  2447. // CHECK POINT
  2448. osal_memcpy(puc+y*dstWidth, rowBufferY+offsetX, dstWidth);
  2449. totSize += dstWidth;
  2450. }
  2451. if (copyLumaOnly == TRUE) {
  2452. osal_free(pY);
  2453. osal_free(pCb);
  2454. osal_free(pCr);
  2455. osal_free(pCbTemp);
  2456. return totSize;
  2457. }
  2458. if (interLeave || p10_32bit_interleave) {
  2459. Int32 cbcr_per_2pix=1;
  2460. cbcr_per_2pix = (format==FORMAT_224||format==FORMAT_444) ? 2 : 1;
  2461. vdi_read_memory(coreIdx, fbSrc->bufCb, pCbTemp, stride*cbcr_per_2pix * chromaHeight, endian);
  2462. } else {
  2463. vdi_read_memory(coreIdx, fbSrc->bufCb, pCb, chroma_stride * chromaHeight, endian);
  2464. if ( (fbSrc->format == FORMAT_420_P10_32BIT_LSB || fbSrc->format == FORMAT_420_P10_32BIT_MSB) &&
  2465. p10_32bit_interleave == 1) {
  2466. // Nothing to do
  2467. }
  2468. else {
  2469. vdi_read_memory(coreIdx, fbSrc->bufCr, pCr, chroma_stride * chromaHeight, endian);
  2470. }
  2471. }
  2472. if (interLeave == TRUE || p10_32bit_interleave == TRUE) {
  2473. //Uint8 pTemp[16];
  2474. Uint8* pTemp;
  2475. Uint8* dstAddrCb;
  2476. Uint8* dstAddrCr;
  2477. Uint8* ptrCb, *ptrCr;
  2478. Int32 cbcr_per_2pix=1, k;
  2479. Uint32* pTempLeft32, *pTempRight32;
  2480. Uint32 temp_32;
  2481. dstAddrCb = pDst + dstWidth*dstHeight;
  2482. dstAddrCr = dstAddrCb + dstChromaWidth*dstChromaHeight;
  2483. cbcr_per_2pix = (format==FORMAT_224||format==FORMAT_444) ? 2 : 1;
  2484. for ( y = 0 ; y < dstChromaHeight; ++y ) {
  2485. ptrCb = pCb;
  2486. ptrCr = pCr;
  2487. for ( x = 0 ; x < stride*cbcr_per_2pix ; x += dramBusWidth ) {
  2488. pix_addr = GetXY2AXIAddr(&mapCfg, 2, y+(offsetY/div_y), x, stride, fbSrc);
  2489. pTemp = pCbTemp + (pix_addr - baseCb);
  2490. // CHECK POINT
  2491. if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
  2492. SwapPixelOrder(pTemp);
  2493. // CHECK POINT
  2494. if (interLeave == TRUE) {
  2495. for (k=0; k<dramBusWidth && (x+k) < stride; k+=(2*bpp/8)) {
  2496. if (bpp == 8) {
  2497. if (nv21) {
  2498. *ptrCr++ = pTemp[k];
  2499. *ptrCb++ = pTemp[k+1];
  2500. }
  2501. else {
  2502. *ptrCb++ = pTemp[k];
  2503. *ptrCr++ = pTemp[k+1];
  2504. }
  2505. }
  2506. else {
  2507. if (nv21) {
  2508. *ptrCr++ = pTemp[k];
  2509. *ptrCr++ = pTemp[k+1];
  2510. *ptrCb++ = pTemp[k+2];
  2511. *ptrCb++ = pTemp[k+3];
  2512. }
  2513. else {
  2514. *ptrCb++ = pTemp[k];
  2515. *ptrCb++ = pTemp[k+1];
  2516. *ptrCr++ = pTemp[k+2];
  2517. *ptrCr++ = pTemp[k+3];
  2518. }
  2519. }
  2520. }
  2521. }
  2522. else {
  2523. for (k=0; k<dramBusWidth && (x+k) < stride; k+=8) {//(2*bpp/8)) {
  2524. pTempLeft32 = (Uint32*)&pTemp[k];
  2525. pTempRight32 = (Uint32*)&pTemp[k+4];
  2526. if (format==FORMAT_420_P10_32BIT_MSB) {
  2527. temp_32 = *pTempLeft32 & 0x003ff000;
  2528. *pTempLeft32 = (*pTempLeft32 & 0xffc00000)
  2529. | (*pTempLeft32 & 0x00000ffc) << 10
  2530. | (*pTempRight32 & 0x003ff000) >> 10;
  2531. *pTempRight32 = (temp_32) << 10
  2532. | (*pTempRight32 & 0xffc00000) >> 10
  2533. | (*pTempRight32 & 0x00000ffc);
  2534. }
  2535. else if (format==FORMAT_420_P10_32BIT_LSB) {
  2536. temp_32 = *pTempLeft32 & 0x000ffc00;
  2537. *pTempLeft32 = (*pTempLeft32 & 0x000003ff)
  2538. | (*pTempLeft32 & 0x3ff00000) >> 10
  2539. | (*pTempRight32 & 0x000ffc00) << 10;
  2540. *pTempRight32 = (temp_32) >> 10
  2541. | (*pTempRight32 & 0x000003ff) << 10
  2542. | (*pTempRight32 & 0x3ff00000);
  2543. }
  2544. if (nv21) {
  2545. *ptrCr++ = pTemp[k];
  2546. *ptrCr++ = pTemp[k+1];
  2547. *ptrCr++ = pTemp[k+2];
  2548. *ptrCr++ = pTemp[k+3];
  2549. *ptrCb++ = pTemp[k+4];
  2550. *ptrCb++ = pTemp[k+5];
  2551. *ptrCb++ = pTemp[k+6];
  2552. *ptrCb++ = pTemp[k+7];
  2553. }
  2554. else {
  2555. *ptrCb++ = pTemp[k];
  2556. *ptrCb++ = pTemp[k+1];
  2557. *ptrCb++ = pTemp[k+2];
  2558. *ptrCb++ = pTemp[k+3];
  2559. *ptrCr++ = pTemp[k+4];
  2560. *ptrCr++ = pTemp[k+5];
  2561. *ptrCr++ = pTemp[k+6];
  2562. *ptrCr++ = pTemp[k+7];
  2563. }
  2564. }
  2565. }
  2566. }
  2567. osal_memcpy(dstAddrCb+y*dstChromaWidth, pCb+offsetX/div_x, dstChromaWidth);
  2568. totSize += dstChromaWidth;
  2569. osal_memcpy(dstAddrCr+y*dstChromaWidth, pCr+offsetX/div_x, dstChromaWidth);
  2570. totSize += dstChromaWidth;
  2571. }
  2572. }
  2573. else {
  2574. puc = pDst + dstWidth*dstHeight;
  2575. for (y = 0 ; y < dstChromaHeight; y += 1) {
  2576. x = 0;
  2577. pix_addr = GetXY2AXIAddr(&mapCfg, 2, y+(offsetY/div_y), x, chroma_stride, fbSrc);
  2578. rowBufferCb = pCb + (pix_addr - baseCb);
  2579. // CHECK POINT
  2580. for (x = 0 ; x < chroma_stride; x += dramBusWidth) {
  2581. if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
  2582. SwapPixelOrder(rowBufferCb+x);
  2583. }
  2584. // CHECK POINT
  2585. osal_memcpy(puc + (y*dstChromaWidth), rowBufferCb+offsetX/div_x, dstChromaWidth);
  2586. totSize += dstChromaWidth;
  2587. }
  2588. puc += dstChromaWidth * dstChromaHeight;
  2589. if ( (fbSrc->format == FORMAT_420_P10_32BIT_LSB || fbSrc->format == FORMAT_420_P10_32BIT_MSB) &&
  2590. p10_32bit_interleave == 1)
  2591. {
  2592. }
  2593. else
  2594. {
  2595. for (y = 0 ; y < dstChromaHeight; y += 1) {
  2596. x = 0;
  2597. pix_addr = GetXY2AXIAddr(&mapCfg, 3, y+(offsetY/div_y), x, chroma_stride, fbSrc);
  2598. //vdi_read_memory(coreIdx, pix_addr, rowBufferCr+x, dramBusWidth, endian);
  2599. rowBufferCr = pCr + (pix_addr - baseCr);
  2600. // CHECK POINT
  2601. for ( x = 0 ; x < chroma_stride; x += dramBusWidth ) {
  2602. if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
  2603. SwapPixelOrder(rowBufferCr+x);
  2604. }
  2605. // CHECK POINT
  2606. osal_memcpy(puc + (y*dstChromaWidth), rowBufferCr+offsetX/div_x, dstChromaWidth);
  2607. totSize += dstChromaWidth;
  2608. }
  2609. }
  2610. }
  2611. osal_free(pY);
  2612. osal_free(pCb);
  2613. osal_free(pCr);
  2614. osal_free(pCbTemp);
  2615. return totSize;
  2616. }
  2617. Uint32 StoreYuvImageBurstFormat(
  2618. Uint32 coreIdx,
  2619. FrameBuffer* fbSrc,
  2620. TiledMapConfig mapCfg,
  2621. Uint8* pDst,
  2622. VpuRect cropRect,
  2623. BOOL enableCrop
  2624. )
  2625. {
  2626. Uint32 y, x;
  2627. Uint32 pix_addr, div_x, div_y, chroma_stride;
  2628. Uint8* puc;
  2629. Uint8* rowBufferY, *rowBufferCb, *rowBufferCr;
  2630. Uint32 stride = fbSrc->stride;
  2631. Uint32 height = fbSrc->height;
  2632. int interLeave = fbSrc->cbcrInterleave;
  2633. BOOL nv21 = fbSrc->nv21;
  2634. EndianMode endian = (EndianMode)fbSrc->endian;
  2635. FrameBufferFormat format = (FrameBufferFormat)fbSrc->format;
  2636. Uint32 width;
  2637. Uint32 dstWidth, dstHeight;
  2638. Uint32 offsetX, offsetY;
  2639. Uint32 dstChromaHeight;
  2640. Uint32 dstChromaWidth;
  2641. Uint32 bpp=8;
  2642. Uint32 p10_32bit_interleave = 0;
  2643. Int32 productId;
  2644. Int32 dramBusWidth = 8;
  2645. Uint32 totSize = 0;
  2646. productId = VPU_GetProductId(coreIdx);
  2647. if (PRODUCT_ID_W_SERIES(productId)) {
  2648. dramBusWidth = 16;
  2649. }
  2650. switch (fbSrc->format) {
  2651. case FORMAT_420:
  2652. case FORMAT_420_P10_16BIT_LSB:
  2653. case FORMAT_420_P10_16BIT_MSB:
  2654. case FORMAT_420_P10_32BIT_LSB:
  2655. case FORMAT_420_P10_32BIT_MSB:
  2656. case FORMAT_422:
  2657. case FORMAT_422_P10_16BIT_LSB:
  2658. case FORMAT_422_P10_16BIT_MSB:
  2659. case FORMAT_422_P10_32BIT_LSB:
  2660. case FORMAT_422_P10_32BIT_MSB:
  2661. div_x = 2;
  2662. break;
  2663. default:
  2664. div_x = 1;
  2665. }
  2666. switch (fbSrc->format) {
  2667. case FORMAT_420:
  2668. case FORMAT_420_P10_16BIT_LSB:
  2669. case FORMAT_420_P10_16BIT_MSB:
  2670. case FORMAT_420_P10_32BIT_LSB:
  2671. case FORMAT_420_P10_32BIT_MSB:
  2672. case FORMAT_224:
  2673. div_y = 2;
  2674. break;
  2675. default:
  2676. div_y = 1;
  2677. }
  2678. width = (enableCrop == TRUE ? cropRect.right - cropRect.left : stride);
  2679. dstHeight = (enableCrop == TRUE ? cropRect.bottom - cropRect.top : height);
  2680. offsetX = (enableCrop == TRUE ? cropRect.left : 0);
  2681. offsetY = (enableCrop == TRUE ? cropRect.top : 0);
  2682. switch (fbSrc->format) {
  2683. case FORMAT_420_P10_16BIT_LSB:
  2684. case FORMAT_420_P10_16BIT_MSB:
  2685. dstWidth = width * 2;
  2686. bpp = 16;
  2687. dstChromaWidth = dstWidth / div_x;
  2688. dstChromaHeight = dstHeight / div_y;
  2689. chroma_stride = (stride / div_x);
  2690. break;
  2691. case FORMAT_420_P10_32BIT_LSB:
  2692. case FORMAT_420_P10_32BIT_MSB:
  2693. #ifdef DUMP_YUV_WHOLE_DATA
  2694. if (interLeave)
  2695. {
  2696. dstChromaWidth = ((VPU_ALIGN16(width/div_x))*2+11)/12*16;
  2697. dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
  2698. dstChromaHeight = dstHeight / div_y;
  2699. stride = stride;
  2700. chroma_stride = stride;
  2701. dstWidth = (VPU_ALIGN16(width)+11)/12*16;
  2702. interLeave = 0;
  2703. }
  2704. else
  2705. {
  2706. dstChromaWidth = ((VPU_ALIGN16(width/div_x))+11)/12*16;
  2707. dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
  2708. dstChromaHeight = dstHeight / div_y;
  2709. chroma_stride = dstChromaWidth;
  2710. stride = (VPU_ALIGN16(stride)+11)/12*16;
  2711. dstWidth = (VPU_ALIGN16(dstWidth)+11)/12*16;
  2712. }
  2713. break;
  2714. #else
  2715. if (interLeave)
  2716. {
  2717. dstChromaWidth = ((VPU_ALIGN16(width*2/div_x))+11)/12*16;
  2718. dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
  2719. chroma_stride = stride;
  2720. dstChromaWidth = (width+2)/3*4;
  2721. dstChromaHeight = dstHeight / div_y;
  2722. dstWidth = (width+2)/3*4;
  2723. interLeave = 0;
  2724. p10_32bit_interleave = 1;
  2725. }
  2726. else
  2727. {
  2728. dstChromaWidth = ((VPU_ALIGN16(width/div_x))+11)/12*16;
  2729. dstChromaWidth = VPU_ALIGN16(dstChromaWidth);
  2730. chroma_stride = dstChromaWidth;
  2731. dstChromaWidth = (width/2+2)/3*4;
  2732. dstChromaHeight = dstHeight / div_y;
  2733. dstWidth = (width+2)/3*4;
  2734. }
  2735. break;
  2736. #endif
  2737. case FORMAT_YUYV:
  2738. case FORMAT_YUYV_P10_16BIT_MSB:
  2739. case FORMAT_YUYV_P10_16BIT_LSB:
  2740. case FORMAT_YUYV_P10_32BIT_MSB:
  2741. case FORMAT_YUYV_P10_32BIT_LSB:
  2742. case FORMAT_YVYU:
  2743. case FORMAT_YVYU_P10_16BIT_MSB:
  2744. case FORMAT_YVYU_P10_16BIT_LSB:
  2745. case FORMAT_YVYU_P10_32BIT_MSB:
  2746. case FORMAT_YVYU_P10_32BIT_LSB:
  2747. case FORMAT_UYVY:
  2748. case FORMAT_UYVY_P10_16BIT_MSB:
  2749. case FORMAT_UYVY_P10_16BIT_LSB:
  2750. case FORMAT_UYVY_P10_32BIT_MSB:
  2751. case FORMAT_UYVY_P10_32BIT_LSB:
  2752. case FORMAT_VYUY:
  2753. case FORMAT_VYUY_P10_16BIT_MSB:
  2754. case FORMAT_VYUY_P10_16BIT_LSB:
  2755. case FORMAT_VYUY_P10_32BIT_MSB:
  2756. case FORMAT_VYUY_P10_32BIT_LSB:
  2757. dstWidth = stride;
  2758. dstChromaWidth = 0;
  2759. dstChromaHeight = 0;
  2760. chroma_stride = 0;
  2761. break;
  2762. default:
  2763. dstWidth = width;
  2764. dstChromaWidth = width / div_x;
  2765. dstChromaHeight = dstHeight / div_y;
  2766. chroma_stride = (stride / div_x);
  2767. break;
  2768. }
  2769. puc = pDst;
  2770. rowBufferY = (Uint8*)osal_malloc(stride);
  2771. if ( !rowBufferY )
  2772. return 0;
  2773. rowBufferCb = (Uint8*)osal_malloc(stride*4);
  2774. if ( !rowBufferCb )
  2775. return 0;
  2776. rowBufferCr = (Uint8*)osal_malloc(stride*2);
  2777. if ( !rowBufferCr )
  2778. return 0;
  2779. for ( y=0 ; y<dstHeight ; y+=1 )
  2780. {
  2781. for ( x=0; x<stride ; x+=dramBusWidth )
  2782. {
  2783. pix_addr = GetXY2AXIAddr(&mapCfg, 0, y+offsetY, x, stride, fbSrc);
  2784. vdi_read_memory(coreIdx, pix_addr, rowBufferY+x, dramBusWidth, endian);
  2785. }
  2786. osal_memcpy(puc+y*dstWidth, rowBufferY+offsetX, dstWidth);
  2787. totSize += dstWidth;
  2788. }
  2789. if (format == FORMAT_400) {
  2790. osal_free(rowBufferY);
  2791. osal_free(rowBufferCb);
  2792. osal_free(rowBufferCr);
  2793. return totSize;
  2794. }
  2795. if (interLeave == TRUE) {
  2796. Uint8 pTemp[16];
  2797. Uint8* dstAddrCb;
  2798. Uint8* dstAddrCr;
  2799. Uint8* ptrCb, *ptrCr;
  2800. Int32 cbcr_per_2pix=1, k;
  2801. dstAddrCb = pDst + dstWidth*dstHeight;
  2802. dstAddrCr = dstAddrCb + dstChromaWidth*dstChromaHeight;
  2803. cbcr_per_2pix = (format==FORMAT_224||format==FORMAT_444) ? 2 : 1;
  2804. for ( y = 0 ; y < dstChromaHeight; ++y ) {
  2805. ptrCb = rowBufferCb;
  2806. ptrCr = rowBufferCr;
  2807. for ( x = 0 ; x < stride*cbcr_per_2pix ; x += dramBusWidth ) {
  2808. pix_addr = GetXY2AXIAddr(&mapCfg, 2, y+(offsetY/div_y), x, stride, fbSrc);
  2809. vdi_read_memory(coreIdx, pix_addr, pTemp, dramBusWidth, endian);
  2810. // CHECK POINT
  2811. if ( fbSrc->format == FORMAT_420_P10_32BIT_MSB )
  2812. SwapPixelOrder(pTemp);
  2813. // CHECK POINT
  2814. for (k=0; k<dramBusWidth && (x+k) < stride; k+=(2*bpp/8)) {
  2815. if (bpp == 8) {
  2816. if (nv21) {
  2817. *ptrCr++ = pTemp[k];
  2818. *ptrCb++ = pTemp[k+1];
  2819. }
  2820. else {
  2821. *ptrCb++ = pTemp[k];
  2822. *ptrCr++ = pTemp[k+1];
  2823. }
  2824. }
  2825. else {
  2826. if (nv21) {
  2827. *ptrCr++ = pTemp[k];
  2828. *ptrCr++ = pTemp[k+1];
  2829. *ptrCb++ = pTemp[k+2];
  2830. *ptrCb++ = pTemp[k+3];
  2831. }
  2832. else {
  2833. *ptrCb++ = pTemp[k];
  2834. *ptrCb++ = pTemp[k+1];
  2835. *ptrCr++ = pTemp[k+2];
  2836. *ptrCr++ = pTemp[k+3];
  2837. }
  2838. }
  2839. }
  2840. }
  2841. osal_memcpy(dstAddrCb+y*dstChromaWidth, rowBufferCb+offsetX/div_x, dstChromaWidth);
  2842. totSize += dstChromaWidth;
  2843. osal_memcpy(dstAddrCr+y*dstChromaWidth, rowBufferCr+offsetX/div_x, dstChromaWidth);
  2844. totSize += dstChromaWidth;
  2845. }
  2846. }
  2847. else {
  2848. puc = pDst + dstWidth*dstHeight;
  2849. for (y = 0 ; y < dstChromaHeight; y += 1) {
  2850. for (x = 0 ; x < chroma_stride; x += dramBusWidth) {
  2851. pix_addr = GetXY2AXIAddr(&mapCfg, 2, y+(offsetY/div_y), x, chroma_stride, fbSrc);
  2852. vdi_read_memory(coreIdx, pix_addr, rowBufferCb+x, dramBusWidth, endian);
  2853. }
  2854. osal_memcpy(puc + (y*dstChromaWidth), rowBufferCb+offsetX/div_x, dstChromaWidth);
  2855. totSize += dstChromaWidth;
  2856. }
  2857. puc += dstChromaWidth * dstChromaHeight;
  2858. if ( (fbSrc->format == FORMAT_420_P10_32BIT_LSB || fbSrc->format == FORMAT_420_P10_32BIT_MSB) &&
  2859. p10_32bit_interleave == 1)
  2860. {
  2861. }
  2862. else
  2863. {
  2864. for (y = 0 ; y < dstChromaHeight; y += 1) {
  2865. for ( x = 0 ; x < chroma_stride; x += dramBusWidth ) {
  2866. pix_addr = GetXY2AXIAddr(&mapCfg, 3, y+(offsetY/div_y), x, chroma_stride, fbSrc);
  2867. vdi_read_memory(coreIdx, pix_addr, rowBufferCr+x, dramBusWidth, endian);
  2868. }
  2869. osal_memcpy(puc + (y*dstChromaWidth), rowBufferCr+offsetX/div_x, dstChromaWidth);
  2870. totSize += dstChromaWidth;
  2871. }
  2872. }
  2873. }
  2874. osal_free(rowBufferY);
  2875. osal_free(rowBufferCb);
  2876. osal_free(rowBufferCr);
  2877. return totSize;
  2878. }
  2879. Uint8* GetYUVFromFrameBuffer(
  2880. DecHandle decHandle,
  2881. FrameBuffer* fb,
  2882. VpuRect rcFrame,
  2883. Uint32* retWidth,
  2884. Uint32* retHeight,
  2885. Uint32* retBpp,
  2886. size_t* retSize
  2887. )
  2888. {
  2889. Uint32 coreIdx = VPU_HANDLE_CORE_INDEX(decHandle);
  2890. size_t frameSizeY; // the size of luma
  2891. size_t frameSizeC; // the size of chroma
  2892. size_t frameSize; // the size of frame
  2893. Uint32 Bpp = 1; //!<< Byte per pixel
  2894. Uint32 picWidth, picHeight;
  2895. Uint8* pYuv;
  2896. TiledMapConfig mapCfg;
  2897. picWidth = rcFrame.right - rcFrame.left;
  2898. picHeight = rcFrame.bottom - rcFrame.top;
  2899. CalcYuvSize_412(fb->format, picWidth, fb->height, fb->cbcrInterleave, &frameSizeY, &frameSizeC, &frameSize, NULL, NULL, NULL);
  2900. switch (fb->format) {
  2901. case FORMAT_422_P10_16BIT_MSB:
  2902. case FORMAT_422_P10_16BIT_LSB:
  2903. case FORMAT_420_P10_16BIT_LSB:
  2904. case FORMAT_420_P10_16BIT_MSB:
  2905. Bpp = 2;
  2906. break;
  2907. case FORMAT_420_P10_32BIT_LSB:
  2908. case FORMAT_420_P10_32BIT_MSB:
  2909. picWidth = (picWidth/3)*4 + ((picWidth%3) ? 4 : 0);
  2910. Bpp = 1;
  2911. break;
  2912. case FORMAT_422:
  2913. case FORMAT_422_P10_32BIT_MSB:
  2914. case FORMAT_422_P10_32BIT_LSB:
  2915. break;
  2916. default:
  2917. Bpp = 1;
  2918. break;
  2919. }
  2920. if ((pYuv=(Uint8*)osal_malloc(frameSize)) == NULL) {
  2921. VLOG(ERR, "%s:%d Failed to allocate memory\n", __FUNCTION__, __LINE__);
  2922. return NULL;
  2923. }
  2924. VPU_DecGiveCommand(decHandle, GET_TILEDMAP_CONFIG, &mapCfg);
  2925. *retSize = StoreYuvImageBurst(coreIdx, fb, mapCfg, pYuv, rcFrame, TRUE);
  2926. *retWidth = picWidth;
  2927. *retHeight = picHeight;
  2928. *retBpp = Bpp;
  2929. return pYuv;
  2930. }
  2931. BOOL GetYUVFromFrameBuffer2(
  2932. Uint8* pYuv,
  2933. Uint8** pYuv2,
  2934. Uint32 size,
  2935. DecHandle decHandle,
  2936. FrameBuffer* fb,
  2937. VpuRect rcFrame,
  2938. Uint32* retWidth,
  2939. Uint32* retHeight,
  2940. Uint32* retBpp,
  2941. size_t* retSize
  2942. )
  2943. {
  2944. Uint32 coreIdx = VPU_HANDLE_CORE_INDEX(decHandle);
  2945. size_t frameSizeY; // the size of luma
  2946. size_t frameSizeC; // the size of chroma
  2947. size_t frameSize; // the size of frame
  2948. Uint32 Bpp = 1; //!<< Byte per pixel
  2949. Uint32 picWidth, picHeight;
  2950. TiledMapConfig mapCfg;
  2951. if (pYuv == NULL && pYuv2 == NULL) {
  2952. return FALSE;
  2953. }
  2954. picWidth = rcFrame.right - rcFrame.left;
  2955. picHeight = rcFrame.bottom - rcFrame.top;
  2956. CalcYuvSize_412(fb->format, picWidth, fb->height, fb->cbcrInterleave, &frameSizeY, &frameSizeC, &frameSize, NULL, NULL, NULL);
  2957. if (size < frameSize) {
  2958. VLOG(ERR, "Buffer is not long enough, expect:%d, give:%d\n", frameSize, size);
  2959. *retSize = 0;
  2960. return FALSE;
  2961. }
  2962. switch (fb->format) {
  2963. case FORMAT_422_P10_16BIT_MSB:
  2964. case FORMAT_422_P10_16BIT_LSB:
  2965. case FORMAT_420_P10_16BIT_LSB:
  2966. case FORMAT_420_P10_16BIT_MSB:
  2967. Bpp = 2;
  2968. break;
  2969. case FORMAT_420_P10_32BIT_LSB:
  2970. case FORMAT_420_P10_32BIT_MSB:
  2971. picWidth = (picWidth/3)*4 + ((picWidth%3) ? 4 : 0);
  2972. Bpp = 1;
  2973. break;
  2974. case FORMAT_422:
  2975. case FORMAT_422_P10_32BIT_MSB:
  2976. case FORMAT_422_P10_32BIT_LSB:
  2977. break;
  2978. default:
  2979. Bpp = 1;
  2980. break;
  2981. }
  2982. VPU_DecGiveCommand(decHandle, GET_TILEDMAP_CONFIG, &mapCfg);
  2983. *retSize = StoreYuvImageBurst2(coreIdx, fb, mapCfg, pYuv, pYuv2, rcFrame, TRUE);
  2984. *retWidth = picWidth;
  2985. *retHeight = picHeight;
  2986. *retBpp = Bpp;
  2987. return TRUE;
  2988. }
  2989. void PrepareDecoderTest(
  2990. DecHandle decHandle
  2991. )
  2992. {
  2993. UNREFERENCED_PARAMETER(decHandle);
  2994. }
  2995. int ProcessEncodedBitstreamBurst(Uint32 coreIdx, osal_file_t fp, int targetAddr,
  2996. PhysicalAddress bsBufStartAddr, PhysicalAddress bsBufEndAddr,
  2997. int size, int endian, Comparator comparator)
  2998. {
  2999. Uint8 * buffer = 0;
  3000. int room = 0;
  3001. int file_wr_size = 0;
  3002. buffer = (Uint8 *)osal_malloc(size);
  3003. if( ( targetAddr + size ) > (int)bsBufEndAddr )
  3004. {
  3005. room = bsBufEndAddr - targetAddr;
  3006. vdi_read_memory(coreIdx, targetAddr, buffer, room, endian);
  3007. vdi_read_memory(coreIdx, bsBufStartAddr, buffer+room, (size-room), endian);
  3008. }
  3009. else
  3010. {
  3011. vdi_read_memory(coreIdx, targetAddr, buffer, size, endian);
  3012. }
  3013. if ( comparator) {
  3014. if (Comparator_Act(comparator, buffer, size) == FALSE) {
  3015. osal_free(buffer);
  3016. return 0;
  3017. }
  3018. }
  3019. if (fp) {
  3020. file_wr_size = osal_fwrite(buffer, sizeof(Uint8), size, fp);
  3021. osal_fflush(fp);
  3022. }
  3023. osal_free( buffer );
  3024. return file_wr_size;
  3025. }
  3026. #ifdef HLS_TEST
  3027. #endif
  3028. Uint32 CalcScaleDown(
  3029. Uint32 origin,
  3030. Uint32 scaledValue
  3031. )
  3032. {
  3033. Uint32 minScaleValue;
  3034. Uint32 retVal;
  3035. minScaleValue = ((origin/8)+7)&~7;
  3036. minScaleValue = (minScaleValue < 8) ? 8 : minScaleValue;
  3037. if (origin == 99) {
  3038. retVal = GetRandom(minScaleValue, origin);
  3039. retVal = VPU_ALIGN8(retVal);
  3040. }
  3041. else {
  3042. if (scaledValue == 0) {
  3043. retVal = origin;
  3044. }
  3045. else {
  3046. if ( scaledValue < origin ) {
  3047. retVal = VPU_ALIGN8(scaledValue);
  3048. if (retVal < minScaleValue) {
  3049. retVal = minScaleValue;
  3050. }
  3051. } else {
  3052. retVal = origin;
  3053. }
  3054. }
  3055. }
  3056. return retVal;
  3057. }