cnm_video_helper.c 119 KB

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