1
0

mp4decvopp.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. /* ///////////////////////////////////////////////////////////////////////
  2. //
  3. // INTEL CORPORATION PROPRIETARY INFORMATION
  4. // This software is supplied under the terms of a license agreement or
  5. // nondisclosure agreement with Intel Corporation and may not be copied
  6. // or disclosed except in accordance with the terms of that agreement.
  7. // Copyright (c) 2001-2008 Intel Corporation. All Rights Reserved.
  8. //
  9. // Description: Decodes P-VOPs
  10. //
  11. */
  12. #include "mp4def.h"
  13. #include "mp4dec.h"
  14. /*
  15. // used for short_viseo_header
  16. */
  17. /*static*/ mp4_Status mp4_PredictDecodeMV(mp4_Info *pInfo, mp4_MacroBlock *MBcurr, int32_t frGOB, int32_t y, int32_t x)
  18. {
  19. IppMotionVector *mvLeft, *mvTop, *mvRight, *mvCurr;
  20. int32_t mbInRow = pInfo->VisualObject.VideoObject.MacroBlockPerRow;
  21. mvCurr = MBcurr[0].mv;
  22. mvLeft = MBcurr[-1].mv;
  23. mvTop = MBcurr[-mbInRow].mv;
  24. mvRight = MBcurr[-mbInRow+1].mv;
  25. if (y == frGOB && x == 0) {
  26. mvCurr->dx = mvCurr->dy = 0;
  27. } else if (x == 0) {
  28. mvCurr->dx = mp4_Median(0, mvTop[0].dx, mvRight[0].dx);
  29. mvCurr->dy = mp4_Median(0, mvTop[0].dy, mvRight[0].dy);
  30. } else if (y == frGOB) {
  31. MBcurr->mv[0] = mvLeft[0];
  32. } else if (x == mbInRow - 1) {
  33. mvCurr->dx = mp4_Median(0, mvLeft[0].dx, mvTop[0].dx);
  34. mvCurr->dy = mp4_Median(0, mvLeft[0].dy, mvTop[0].dy);
  35. } else {
  36. mvCurr->dx = mp4_Median(mvLeft[0].dx, mvTop[0].dx, mvRight[0].dx);
  37. mvCurr->dy = mp4_Median(mvLeft[0].dy, mvTop[0].dy, mvRight[0].dy);
  38. }
  39. return mp4_DecodeMV(pInfo, mvCurr, 1);
  40. }
  41. /*
  42. // decode MPEG-4 PVOP
  43. */
  44. mp4_Status mp4_DecodeVOP_P(mp4_Info* pInfo)
  45. {
  46. __ALIGN16(int16_t, coeffMB, 64*6);
  47. int32_t stepYr, stepYc, stepCbr, stepCbc, stepCrr, stepCrc, stepFc[6];
  48. int32_t i, j, nmb, nmbgob, dx, dy, mbCurr, mbInVideoPacket, colNum, rowNum, mbPerRow, mbPerCol;
  49. uint8_t *pYr, *pCbr, *pCrr;
  50. uint8_t *pYc, *pCbc, *pCrc, *pFc[6];
  51. int32_t mb_not_coded, mb_type, cbpc, cbpy, ac_pred_flag, cbpyPrev;
  52. int32_t dcVLC, quant, quantPred, rvlc, scan, obmc_disable, rt, quarter_sample;
  53. IppiRect limitRectL, limitRectC;
  54. IppMotionVector mvCur[4], mvPrev[4], mvTmp[4], mvCbCr;
  55. mp4_MacroBlock *pMBinfo;
  56. mp4_Status sts;
  57. #ifdef USE_NOTCODED_STATE
  58. uint8_t *ncState = pInfo->VisualObject.VideoObject.ncState;
  59. #endif
  60. if (!pInfo->VisualObject.cFrame)
  61. pInfo->VisualObject.cFrame = CreateFrame(&pInfo->VisualObject);
  62. mbPerRow = pInfo->VisualObject.VideoObject.MacroBlockPerRow;
  63. mbPerCol = pInfo->VisualObject.VideoObject.MacroBlockPerCol;
  64. stepYc = pInfo->VisualObject.cFrame->stepY;
  65. stepYr = pInfo->VisualObject.rFrame->stepY;
  66. stepCbc = pInfo->VisualObject.cFrame->stepCb;
  67. stepCbr = pInfo->VisualObject.rFrame->stepCb;
  68. stepCrc = pInfo->VisualObject.cFrame->stepCr;
  69. stepCrr = pInfo->VisualObject.rFrame->stepCr;
  70. pYc = pInfo->VisualObject.cFrame->pY;
  71. pCbc = pInfo->VisualObject.cFrame->pCb;
  72. pCrc = pInfo->VisualObject.cFrame->pCr;
  73. pYr = pInfo->VisualObject.rFrame->pY;
  74. pCbr = pInfo->VisualObject.rFrame->pCb;
  75. pCrr = pInfo->VisualObject.rFrame->pCr;
  76. stepFc[0] = stepFc[1] = stepFc[2] = stepFc[3] = stepYc; stepFc[4] = stepCbc; stepFc[5] = stepCrc;
  77. // Bounding rectangle for MV limitation
  78. limitRectL.x = - 16 * MP4_NUM_EXT_MB;
  79. limitRectL.y = - 16 * MP4_NUM_EXT_MB;
  80. limitRectL.width = pInfo->VisualObject.VideoObject.width + 16 * 2 * MP4_NUM_EXT_MB;
  81. limitRectL.height = pInfo->VisualObject.VideoObject.height + 16 * 2 * MP4_NUM_EXT_MB;
  82. pMBinfo = pInfo->VisualObject.VideoObject.MBinfo;
  83. // warning "variable may be used without having been initialized"
  84. cbpc = cbpy = mb_type = 0;
  85. nmb = pInfo->VisualObject.VideoObject.MacroBlockPerVOP;
  86. mbCurr = colNum = rowNum = 0;
  87. sts = MP4_STATUS_OK;
  88. // decode short_video_header P-VOP
  89. if (pInfo->VisualObject.VideoObject.short_video_header)
  90. {
  91. int32_t frGOB;
  92. IppMotionVector mvCur;
  93. quant = pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.vop_quant;
  94. nmbgob = 0;
  95. pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_number = 0;
  96. frGOB = 0;
  97. for (;;)
  98. {
  99. do
  100. {
  101. mb_not_coded = mp4_GetBit(pInfo);
  102. if (mb_not_coded)
  103. break;
  104. if (mp4_DecodeMCBPC_P(pInfo, &mb_type, &cbpc, 1) != MP4_STATUS_OK)
  105. goto Err_1;
  106. } while (mb_type == IPPVC_MB_STUFFING);
  107. if (mb_not_coded)
  108. {
  109. #ifdef USE_NOTCODED_STATE
  110. if (!(*ncState))
  111. {
  112. *ncState = 1;
  113. #endif
  114. ippiCopy16x16_8u_C1R(pYr, stepYr, pYc, stepYc);
  115. ippiCopy8x8_8u_C1R(pCbr, stepCbr, pCbc, stepCbc);
  116. ippiCopy8x8_8u_C1R(pCrr, stepCrr, pCrc, stepCrc);
  117. #ifdef USE_NOTCODED_STATE
  118. }
  119. #endif
  120. pMBinfo->mv[0].dx = pMBinfo->mv[0].dy = 0;
  121. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nMB_NOTCODED);
  122. }
  123. else
  124. {
  125. #ifdef USE_NOTCODED_STATE
  126. // clear not_coded MB state
  127. *ncState = 0;
  128. #endif
  129. if (mb_type == IPPVC_MBTYPE_INTER4V || mb_type == IPPVC_MBTYPE_INTER4V_Q)
  130. {
  131. mp4_Error("Error: 4MV shall not be used for short_video_header");
  132. goto Err_1;
  133. }
  134. if (mp4_DecodeCBPY_P(pInfo, &cbpy, mb_type) != MP4_STATUS_OK)
  135. goto Err_1;
  136. if (mb_type == IPPVC_MBTYPE_INTER_Q || mb_type == IPPVC_MBTYPE_INTRA_Q)
  137. mp4_UpdateQuant(pInfo, quant);
  138. if (mb_type >= IPPVC_MBTYPE_INTRA)
  139. {
  140. pFc[0] = pYc; pFc[1] = pYc + 8; pFc[2] = pYc + 8 * stepYc; pFc[3] = pYc + 8 * stepYc + 8; pFc[4] = pCbc; pFc[5] = pCrc;
  141. if (mp4_DecodeIntraMB_SVH(pInfo, (cbpy << 2) + cbpc, quant, pFc, stepFc) != MP4_STATUS_OK)
  142. goto Err_1;
  143. pMBinfo->mv[0].dx = pMBinfo->mv[0].dy = 0;
  144. }
  145. else
  146. {
  147. if (mp4_PredictDecodeMV(pInfo, pMBinfo, frGOB, rowNum, colNum) != MP4_STATUS_OK)
  148. goto Err_1;
  149. mp4_LimitMV(&pMBinfo->mv[0], &mvCur, &limitRectL, colNum * 16, rowNum * 16, 16);
  150. mp4_ComputeChromaMV(&mvCur, &mvCbCr);
  151. // decode and MC blocks
  152. if (cbpy)
  153. {
  154. mp4_DecodeMCInterBlock_SVH(pInfo, quant, cbpy & 8, pYr, pYc, stepYr, coeffMB, &mvCur, Err_1);
  155. mp4_DecodeMCInterBlock_SVH(pInfo, quant, cbpy & 4, pYr+8, pYc+8, stepYr, coeffMB, &mvCur, Err_1);
  156. mp4_DecodeMCInterBlock_SVH(pInfo, quant, cbpy & 2, pYr+stepYr*8, pYc+stepYc*8, stepYr, coeffMB, &mvCur, Err_1);
  157. mp4_DecodeMCInterBlock_SVH(pInfo, quant, cbpy & 1, pYr+8+stepYr*8, pYc+8+stepYc*8, stepYr, coeffMB, &mvCur, Err_1);
  158. }
  159. else
  160. {
  161. mp4_Copy16x16HP_8u(pYr, stepYr, pYc, stepYc, &mvCur, 0);
  162. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  163. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  164. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  165. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  166. }
  167. mp4_DecodeMCInterBlock_SVH(pInfo, quant, cbpc & 2, pCbr, pCbc, stepCbr, coeffMB, &mvCbCr, Err_1);
  168. mp4_DecodeMCInterBlock_SVH(pInfo, quant, cbpc & 1, pCrr, pCrc, stepCrr, coeffMB, &mvCbCr, Err_1);
  169. }
  170. }
  171. pMBinfo ++;
  172. #ifdef USE_NOTCODED_STATE
  173. ncState ++;
  174. #endif
  175. colNum ++;
  176. if (colNum == mbPerRow)
  177. {
  178. colNum = 0;
  179. rowNum ++;
  180. if (rowNum == mbPerCol)
  181. break;
  182. pYc += (2 * MP4_NUM_EXT_MB + 1) * 16 + (stepYc << 4) - stepYc;
  183. pCbc += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCbc << 3) - stepCbc;
  184. pCrc += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCrc << 3) - stepCrc;
  185. pYr += (2 * MP4_NUM_EXT_MB + 1) * 16 + (stepYr << 4) - stepYr;
  186. pCbr += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCbr << 3) - stepCbr;
  187. pCrr += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCrr << 3) - stepCrr;
  188. }
  189. else
  190. {
  191. pYc += 16; pCrc += 8; pCbc += 8;
  192. pYr += 16; pCrr += 8; pCbr += 8;
  193. }
  194. nmbgob ++;
  195. if (nmbgob == pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.num_macroblocks_in_gob && pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_number < (pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.num_gobs_in_vop - 1))
  196. {
  197. ErrRet_1:
  198. if (mp4_CheckDecodeGOB_SVH(pInfo) != MP4_STATUS_OK)
  199. goto Err_1;
  200. if (!pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_header_empty)
  201. {
  202. quant = pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.quant_scale;
  203. i = pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_number * pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.num_rows_in_gob;
  204. frGOB = i;
  205. mp4_CopyMacroBlocks(pInfo->VisualObject.rFrame, pInfo->VisualObject.cFrame, mbPerRow, rowNum, colNum, (i - rowNum) * mbPerRow - colNum);
  206. rowNum = i;
  207. colNum = 0;
  208. pYc = pInfo->VisualObject.cFrame->pY + i * stepYc * 16; pCbc = pInfo->VisualObject.cFrame->pCb + i * stepCbc * 8; pCrc = pInfo->VisualObject.cFrame->pCr + i * stepCrc * 8;
  209. pYr = pInfo->VisualObject.rFrame->pY + i * stepYr * 16; pCbr = pInfo->VisualObject.rFrame->pCb + i * stepCbr * 8; pCrr = pInfo->VisualObject.rFrame->pCr + i * stepCrr * 8;
  210. pMBinfo = pInfo->VisualObject.VideoObject.MBinfo + i * mbPerRow;
  211. #ifdef USE_NOTCODED_STATE
  212. ncState = pInfo->VisualObject.VideoObject.ncState + i * mbPerRow;
  213. #endif
  214. }
  215. nmbgob = 0;
  216. }
  217. }
  218. mp4_AlignBits(pInfo);
  219. return sts;
  220. Err_1:
  221. sts = MP4_STATUS_ERROR;
  222. if (pInfo->stopOnErr)
  223. return sts;
  224. if (!mp4_SeekGOBMarker(pInfo))
  225. {
  226. mp4_CopyMacroBlocks(pInfo->VisualObject.rFrame, pInfo->VisualObject.cFrame, mbPerRow, rowNum, colNum, pInfo->VisualObject.VideoObject.MacroBlockPerVOP - rowNum * mbPerRow - colNum);
  227. return sts;
  228. }
  229. goto ErrRet_1;
  230. }
  231. rt = pInfo->VisualObject.VideoObject.VideoObjectPlane.rounding_type;
  232. quarter_sample = pInfo->VisualObject.VideoObject.quarter_sample;
  233. obmc_disable = pInfo->VisualObject.VideoObject.obmc_disable;
  234. rvlc = pInfo->VisualObject.VideoObject.reversible_vlc;
  235. scan = pInfo->VisualObject.VideoObject.VideoObjectPlane.alternate_vertical_scan_flag ? IPPVC_SCAN_VERTICAL : IPPVC_SCAN_ZIGZAG;
  236. // Bounding rectangles for MV limitation
  237. limitRectC.x = -8 * MP4_NUM_EXT_MB;
  238. limitRectC.y = -8 * MP4_NUM_EXT_MB;
  239. limitRectC.width = (pInfo->VisualObject.VideoObject.width >> 1) + 8 * 2 * MP4_NUM_EXT_MB;
  240. limitRectC.height = (pInfo->VisualObject.VideoObject.height >> 1) + 8 * 2 * MP4_NUM_EXT_MB;
  241. quant = quantPred = pInfo->VisualObject.VideoObject.VideoObjectPlane.quant;
  242. // warning "variable may be used without having been initialized"
  243. ac_pred_flag = cbpyPrev = 0;
  244. mvCbCr.dx = mvCbCr.dy = 0;
  245. //ippsZero_8u((uint8_t*)pInfo->VisualObject.VideoObject.MBinfo, nmb * sizeof(mp4_MacroBlock));
  246. // decode data_partitioned P-VOP
  247. if (pInfo->VisualObject.VideoObject.data_partitioned) {
  248. for (;;) {
  249. mp4_DataPartMacroBlock *pMBdp;
  250. int32_t x, y;
  251. x = colNum;
  252. y = rowNum;
  253. // reset Intra prediction buffer on new Video_packet
  254. mp4_ResetIntraPredBuffer(pInfo);
  255. pMBdp = &pInfo->VisualObject.VideoObject.DataPartBuff[mbCurr];
  256. pMBinfo = &pInfo->VisualObject.VideoObject.MBinfo[mbCurr];
  257. mbInVideoPacket = 0;
  258. // decode not_coded/mb_type/cbpc/MV part
  259. for (;;) {
  260. mb_not_coded = mp4_GetBit(pInfo);
  261. if (mb_not_coded) {
  262. mb_type = IPPVC_MBTYPE_INTER;
  263. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nMB_NOTCODED);
  264. } else {
  265. if (mp4_DecodeMCBPC_P(pInfo, &mb_type, &cbpc, 1) != MP4_STATUS_OK)
  266. goto Err_2;
  267. }
  268. if (mb_type != IPPVC_MB_STUFFING) {
  269. if (mbInVideoPacket == nmb - mbCurr) {
  270. mp4_Error("DC Marker missed");
  271. goto Err_2;
  272. }
  273. pMBinfo->validPred = 1;
  274. if (!mb_not_coded && (mb_type <= IPPVC_MBTYPE_INTER4V)) {
  275. if (mb_type != IPPVC_MBTYPE_INTER4V) {
  276. if (mp4_PredictDecode1MV(pInfo, pMBinfo, y, x) != MP4_STATUS_OK)
  277. goto Err_2;
  278. pMBinfo->mv[1] = pMBinfo->mv[2] = pMBinfo->mv[3] = pMBinfo->mv[0];
  279. } else {
  280. if (mp4_PredictDecode4MV(pInfo, pMBinfo, y, x) != MP4_STATUS_OK)
  281. goto Err_2;
  282. }
  283. } else {
  284. mp4_Zero4MV(pMBinfo->mv);
  285. }
  286. pMBinfo->not_coded = (uint8_t)mb_not_coded;
  287. pMBinfo->type = (uint8_t)mb_type;
  288. pMBinfo ++;
  289. pMBdp->pat = (uint8_t)cbpc;
  290. pMBdp ++;
  291. mbInVideoPacket ++;
  292. x ++;
  293. if (x == mbPerRow) {
  294. x = 0;
  295. y ++;
  296. }
  297. }
  298. if (mp4_ShowBits(pInfo, 17) == MP4_MV_MARKER) {
  299. mp4_GetBits(pInfo, 17);
  300. break;
  301. }
  302. }
  303. pMBdp = &pInfo->VisualObject.VideoObject.DataPartBuff[mbCurr];
  304. pMBinfo = &pInfo->VisualObject.VideoObject.MBinfo[mbCurr];
  305. // decode ac_pred_flag/cbpy/dquant/IntraDC part
  306. for (i = 0; i < mbInVideoPacket; i ++) {
  307. if (!pMBinfo->not_coded) {
  308. mb_type = pMBinfo->type;
  309. if (mb_type >= IPPVC_MBTYPE_INTRA)
  310. pMBdp->ac_pred_flag = (uint8_t)mp4_GetBit(pInfo);
  311. if (mp4_DecodeCBPY_P(pInfo, &cbpy, mb_type) != MP4_STATUS_OK)
  312. goto Err_2;
  313. pMBdp->pat = (uint8_t)((cbpy << 2) + pMBdp->pat);
  314. quantPred = quant;
  315. if (mb_type == IPPVC_MBTYPE_INTER_Q || mb_type == IPPVC_MBTYPE_INTRA_Q)
  316. mp4_UpdateQuant(pInfo, quant);
  317. pMBdp->quant = (uint8_t)quant;
  318. if (i == 0)
  319. quantPred = quant;
  320. // decode DC coefficient of Intra blocks
  321. dcVLC = (quantPred < mp4_DC_vlc_Threshold[pInfo->VisualObject.VideoObject.VideoObjectPlane.intra_dc_vlc_thr]) ? 1 : 0;
  322. if ((mb_type >= IPPVC_MBTYPE_INTRA) && dcVLC) {
  323. for (j = 0; j < 6; j ++) {
  324. if (ippiDecodeDCIntra_MPEG4_1u16s(&pInfo->bufptr, &pInfo->bitoff, &pMBdp->dct_dc[j], j < 4 ? IPPVC_BLOCK_LUMA : IPPVC_BLOCK_CHROMA) != ippStsNoErr)
  325. goto Err_2;
  326. }
  327. }
  328. }
  329. pMBdp ++;
  330. pMBinfo ++;
  331. }
  332. if (mbCurr + mbInVideoPacket < nmb)
  333. pMBinfo->type = IPPVC_MBTYPE_INTRA; // for OBMC set first MB of the next videopacket as invalid for right MV
  334. pMBdp = &pInfo->VisualObject.VideoObject.DataPartBuff[mbCurr];
  335. pMBinfo = &pInfo->VisualObject.VideoObject.MBinfo[mbCurr];
  336. // decode coeffs and reconstruct macroblocks
  337. for (i = 0; i < mbInVideoPacket; i ++) {
  338. if (colNum == 0) {
  339. // reset B-prediction blocks on new row
  340. mp4_ResetIntraPredBblock(pInfo);
  341. }
  342. quant = pMBdp->quant;
  343. mb_type = pMBinfo->type;
  344. if (mb_type >= IPPVC_MBTYPE_INTRA) {
  345. quantPred = (i == 0) ? quant : pMBdp[-1].quant;
  346. dcVLC = (quantPred < mp4_DC_vlc_Threshold[pInfo->VisualObject.VideoObject.VideoObjectPlane.intra_dc_vlc_thr]) ? 1 : 0;
  347. pFc[0] = pYc; pFc[1] = pYc + 8; pFc[2] = pYc + 8 * stepYc; pFc[3] = pYc + 8 * stepYc + 8; pFc[4] = pCbc; pFc[5] = pCrc;
  348. if (mp4_DecodeIntraMB_DP(pInfo, pMBdp->dct_dc, colNum, pMBdp->pat, quant, dcVLC, pMBdp->ac_pred_flag, pFc, stepFc) != MP4_STATUS_OK)
  349. goto Err_2;
  350. } else {
  351. mp4_UpdateIntraPredBuffInvalid(pInfo, colNum);
  352. mb_not_coded = pMBinfo->not_coded;
  353. if (!mb_not_coded) {
  354. dx = colNum * 16;
  355. dy = rowNum * 16;
  356. cbpy = pMBdp->pat >> 2;
  357. cbpc = pMBdp->pat & 3;
  358. if (mb_type == IPPVC_MBTYPE_INTER4V) {
  359. if (quarter_sample) {
  360. mp4_Limit4MVQ(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 8);
  361. mp4_ComputeChroma4MVQ(pMBinfo->mv, &mvCbCr);
  362. } else {
  363. mp4_Limit4MV(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 8);
  364. mp4_ComputeChroma4MV(pMBinfo->mv, &mvCbCr);
  365. }
  366. mp4_LimitMV(&mvCbCr, &mvCbCr, &limitRectC, dx >> 1, dy >> 1, 8);
  367. } else {
  368. if (quarter_sample) {
  369. mp4_LimitMVQ(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 16);
  370. mp4_ComputeChromaMVQ(mvCur, &mvCbCr);
  371. } else {
  372. mp4_LimitMV(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 16);
  373. mp4_ComputeChromaMV(mvCur, &mvCbCr);
  374. }
  375. mvCur[1] = mvCur[2] = mvCur[3] = mvCur[0];
  376. }
  377. }
  378. if (obmc_disable) {
  379. if (mb_not_coded) {
  380. ippiCopy16x16_8u_C1R(pYr, stepYr, pYc, stepYc);
  381. ippiCopy8x8_8u_C1R(pCbr, stepCbr, pCbc, stepCbc);
  382. ippiCopy8x8_8u_C1R(pCrr, stepCrr, pCrc, stepCrc);
  383. } else {
  384. if (quarter_sample) {
  385. if (mb_type == IPPVC_MBTYPE_INTER4V) {
  386. mp4_Copy8x8QP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  387. mp4_Copy8x8QP_8u(pYr+8, stepYr, pYc+8, stepYc, &mvCur[1], rt);
  388. mp4_Copy8x8QP_8u(pYr+8*stepYr, stepYr, pYc+8*stepYc, stepYc, &mvCur[2], rt);
  389. mp4_Copy8x8QP_8u(pYr+8*stepYr+8, stepYr, pYc+8*stepYc+8, stepYc, &mvCur[3], rt);
  390. } else
  391. mp4_Copy16x16QP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  392. mp4_DecodeReconBlockInter_MPEG4(cbpy & 8, pYc, stepYc, Err_2);
  393. mp4_DecodeReconBlockInter_MPEG4(cbpy & 4, pYc+8, stepYc, Err_2);
  394. mp4_DecodeReconBlockInter_MPEG4(cbpy & 2, pYc+8*stepYc, stepYc, Err_2);
  395. mp4_DecodeReconBlockInter_MPEG4(cbpy & 1, pYc+8*stepYc+8, stepYc, Err_2);
  396. } else {
  397. if (cbpy || mb_type == IPPVC_MBTYPE_INTER4V) {
  398. mp4_DecodeMCBlockInter_MPEG4(cbpy & 8, pYr, stepYr, pYc, stepYc, mvCur[0], rt, Err_2);
  399. mp4_DecodeMCBlockInter_MPEG4(cbpy & 4, pYr+8, stepYr, pYc+8, stepYc, mvCur[1], rt, Err_2);
  400. mp4_DecodeMCBlockInter_MPEG4(cbpy & 2, pYr+8*stepYr, stepYr, pYc+8*stepYc, stepYc, mvCur[2], rt, Err_2);
  401. mp4_DecodeMCBlockInter_MPEG4(cbpy & 1, pYr+8*stepYr+8, stepYr, pYc+8*stepYc+8, stepYc, mvCur[3], rt, Err_2);
  402. } else {
  403. mp4_Copy16x16HP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  404. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  405. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  406. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  407. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  408. }
  409. }
  410. mp4_DecodeMCBlockInter_MPEG4(cbpc & 2, pCbr, stepCbr, pCbc, stepCbc, mvCbCr, rt, Err_2);
  411. mp4_DecodeMCBlockInter_MPEG4(cbpc & 1, pCrr, stepCrr, pCrc, stepCrc, mvCbCr, rt, Err_2);
  412. }
  413. } else {
  414. if (mb_not_coded) {
  415. cbpy = 0;
  416. mp4_Zero4MV(mvCur);
  417. ippiCopy8x8_8u_C1R(pCbr, stepCbr, pCbc, stepCbc);
  418. ippiCopy8x8_8u_C1R(pCrr, stepCrr, pCrc, stepCrc);
  419. } else {
  420. if (mp4_DecodeInterMB(pInfo, coeffMB, quant, (cbpy << 2) + cbpc, scan) != MP4_STATUS_OK)
  421. goto Err_2;
  422. mp4_MC_HP(cbpc & 2, pCbr, stepCbr, pCbc, stepCbc, coeffMB+256, &mvCbCr, rt);
  423. mp4_MC_HP(cbpc & 1, pCrr, stepCrr, pCrc, stepCrc, coeffMB+320, &mvCbCr, rt);
  424. }
  425. mp4_OBMC(pInfo, pMBinfo, mvCur, colNum, rowNum, limitRectL, pYc, stepYc, pYr, stepYr, cbpy, coeffMB, 0);
  426. }
  427. }
  428. pMBinfo ++;
  429. pMBdp ++;
  430. colNum ++;
  431. if (colNum == mbPerRow) {
  432. colNum = 0;
  433. rowNum ++;
  434. if (rowNum == mbPerCol)
  435. return sts;
  436. pYc += (2 * MP4_NUM_EXT_MB + 1) * 16 + (stepYc << 4) - stepYc;
  437. pCbc += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCbc << 3) - stepCbc;
  438. pCrc += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCrc << 3) - stepCrc;
  439. pYr += (2 * MP4_NUM_EXT_MB + 1) * 16 + (stepYr << 4) - stepYr;
  440. pCbr += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCbr << 3) - stepCbr;
  441. pCrr += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCrr << 3) - stepCrr;
  442. }
  443. else
  444. {
  445. pYc += 16; pCrc += 8; pCbc += 8;
  446. pYr += 16; pCrr += 8; pCbr += 8;
  447. }
  448. }
  449. //mbCurr += mbInVideoPacket;
  450. if (!pInfo->VisualObject.VideoObject.resync_marker_disable)
  451. {
  452. int32_t found;
  453. ErrRet_2:
  454. if (mp4_CheckDecodeVideoPacket(pInfo, &found) == MP4_STATUS_OK)
  455. {
  456. if (found)
  457. {
  458. quant = pInfo->VisualObject.VideoObject.VideoObjectPlane.quant_scale;
  459. mbInVideoPacket = pInfo->VisualObject.VideoObject.VideoObjectPlane.macroblock_num - mbCurr;
  460. mbCurr = pInfo->VisualObject.VideoObject.VideoObjectPlane.macroblock_num;
  461. mp4_CopyMacroBlocks(pInfo->VisualObject.rFrame, pInfo->VisualObject.cFrame, mbPerRow, rowNum, colNum, mbCurr - rowNum * mbPerRow - colNum);
  462. rowNum = mbCurr / mbPerRow;
  463. colNum = mbCurr % mbPerRow;
  464. pYc = pInfo->VisualObject.cFrame->pY + (rowNum * stepYc + colNum) * 16; pCbc = pInfo->VisualObject.cFrame->pCb + (rowNum * stepCbc + colNum) * 8; pCrc = pInfo->VisualObject.cFrame->pCr + (rowNum * stepCrc + colNum) * 8;
  465. pYr = pInfo->VisualObject.rFrame->pY + (rowNum * stepYr + colNum) * 16; pCbr = pInfo->VisualObject.rFrame->pCb + (rowNum * stepCbr + colNum) * 8; pCrr = pInfo->VisualObject.rFrame->pCr + (rowNum * stepCrr + colNum) * 8;
  466. pMBinfo = pInfo->VisualObject.VideoObject.MBinfo + mbCurr;
  467. }
  468. else
  469. goto Err_2;
  470. }
  471. else
  472. goto Err_2;
  473. }
  474. // mark MBs the previous videopacket as invalid for prediction
  475. for (i = 1; i <= IPP_MIN(mbInVideoPacket, mbPerRow + 1); i ++)
  476. pMBinfo[-i].validPred = 0;
  477. }
  478. Err_2:
  479. sts = MP4_STATUS_ERROR;
  480. if (pInfo->stopOnErr)
  481. return sts;
  482. if (pInfo->VisualObject.VideoObject.resync_marker_disable || !mp4_SeekResyncMarker(pInfo))
  483. {
  484. mp4_CopyMacroBlocks(pInfo->VisualObject.rFrame, pInfo->VisualObject.cFrame, mbPerRow, rowNum, colNum, pInfo->VisualObject.VideoObject.MacroBlockPerVOP - rowNum * mbPerRow - colNum);
  485. return sts;
  486. }
  487. goto ErrRet_2;
  488. }
  489. // decode interlaced P-VOP
  490. if (pInfo->VisualObject.VideoObject.interlaced)
  491. {
  492. int32_t stepY, pYoff23, field_prediction, dct_type, dct_typePrev, mb_ftfr, mb_fbfr;
  493. IppMotionVector mvCbCrT, mvCbCrB, *mvField = pInfo->VisualObject.VideoObject.FieldMV;
  494. // warning "variable may be used without having been initialized"
  495. dct_type = dct_typePrev = mb_ftfr = mb_fbfr = 0;
  496. mvCbCrT.dx = mvCbCrT.dy = mvCbCrB.dx = mvCbCrB.dy = 0;
  497. for (;;) {
  498. // reset Intra prediction buffer on new Video_packet
  499. mp4_ResetIntraPredBuffer(pInfo);
  500. mbInVideoPacket = 0;
  501. // decode blocks
  502. for (;;)
  503. {
  504. if (colNum == 0)
  505. {
  506. // reset B-prediction blocks on new row
  507. mp4_ResetIntraPredBblock(pInfo);
  508. }
  509. mb_not_coded = mp4_GetBit(pInfo);
  510. mb_type = IPPVC_MBTYPE_INTER;
  511. if (!mb_not_coded)
  512. {
  513. if (mp4_DecodeMCBPC_P(pInfo, &mb_type, &cbpc, 1) != MP4_STATUS_OK)
  514. goto Err_3;
  515. }
  516. if (mb_type != IPPVC_MB_STUFFING)
  517. {
  518. if (!mb_not_coded)
  519. {
  520. if (mb_type >= IPPVC_MBTYPE_INTRA)
  521. ac_pred_flag = mp4_GetBit(pInfo);
  522. if (mp4_DecodeCBPY_P(pInfo, &cbpy, mb_type) != MP4_STATUS_OK)
  523. goto Err_3;
  524. quantPred = quant;
  525. if (mb_type == IPPVC_MBTYPE_INTER_Q || mb_type == IPPVC_MBTYPE_INTRA_Q)
  526. mp4_UpdateQuant(pInfo, quant);
  527. dct_type = 0;
  528. field_prediction = 0;
  529. if (mb_type >= IPPVC_MBTYPE_INTRA || (cbpy + cbpc) != 0)
  530. dct_type = mp4_GetBit(pInfo);
  531. if (mb_type == IPPVC_MBTYPE_INTER || mb_type == IPPVC_MBTYPE_INTER_Q) {
  532. field_prediction = mp4_GetBit(pInfo);
  533. if (field_prediction) {
  534. mb_ftfr = mp4_GetBit(pInfo);
  535. mb_fbfr = mp4_GetBit(pInfo);
  536. }
  537. }
  538. }
  539. else
  540. {
  541. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nMB_NOTCODED);
  542. mp4_Zero4MV(pMBinfo->mv);
  543. field_prediction = 0;
  544. }
  545. pMBinfo->validPred = 1;
  546. pMBinfo->not_coded = (uint8_t)mb_not_coded;
  547. pMBinfo->type = (uint8_t)mb_type;
  548. pMBinfo->field_info = (uint8_t)(field_prediction + (mb_ftfr << 1) + (mb_fbfr << 2));
  549. if (mb_type >= IPPVC_MBTYPE_INTRA)
  550. {
  551. if (mbInVideoPacket == 0)
  552. quantPred = quant;
  553. dcVLC = (quantPred < mp4_DC_vlc_Threshold[pInfo->VisualObject.VideoObject.VideoObjectPlane.intra_dc_vlc_thr]) ? 1 : 0;
  554. if (dct_type)
  555. {
  556. stepY = stepYc * 2;
  557. pYoff23 = stepYc;
  558. }
  559. else
  560. {
  561. stepY = stepYc;
  562. pYoff23 = 8 * stepYc;
  563. }
  564. stepFc[0] = stepFc[1] = stepFc[2] = stepFc[3] = stepY;
  565. pFc[0] = pYc; pFc[1] = pYc + 8; pFc[2] = pYc + pYoff23; pFc[3] = pYc + pYoff23 + 8; pFc[4] = pCbc; pFc[5] = pCrc;
  566. if (mp4_DecodeIntraMB(pInfo, colNum, (cbpy << 2) + cbpc, quant, dcVLC, ac_pred_flag, pFc, stepFc) != MP4_STATUS_OK)
  567. goto Err_3;
  568. mp4_Zero4MV(pMBinfo->mv);
  569. #ifdef USE_NOTCODED_STATE
  570. // clear not_coded MB state
  571. *ncState = 0;
  572. #endif
  573. }
  574. else
  575. {
  576. mp4_UpdateIntraPredBuffInvalid(pInfo, colNum);
  577. if (!mb_not_coded)
  578. {
  579. dx = colNum * 16;
  580. dy = rowNum * 16;
  581. if (!field_prediction)
  582. {
  583. if (mb_type != IPPVC_MBTYPE_INTER4V)
  584. {
  585. if (mp4_PredictDecode1MV(pInfo, pMBinfo, rowNum, colNum) != MP4_STATUS_OK)
  586. goto Err_3;
  587. pMBinfo->mv[1] = pMBinfo->mv[2] = pMBinfo->mv[3] = pMBinfo->mv[0];
  588. if (quarter_sample)
  589. {
  590. mp4_LimitMVQ(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 16);
  591. mp4_ComputeChromaMVQ(mvCur, &mvCbCr);
  592. }
  593. else
  594. {
  595. mp4_LimitMV(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 16);
  596. mp4_ComputeChromaMV(mvCur, &mvCbCr);
  597. }
  598. mvCur[1] = mvCur[2] = mvCur[3] = mvCur[0];
  599. }
  600. else
  601. {
  602. if (mp4_PredictDecode4MV(pInfo, pMBinfo, rowNum, colNum) != MP4_STATUS_OK)
  603. goto Err_3;
  604. if (quarter_sample)
  605. {
  606. mp4_Limit4MVQ(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 8);
  607. mp4_ComputeChroma4MVQ(pMBinfo->mv, &mvCbCr);
  608. }
  609. else
  610. {
  611. mp4_Limit4MV(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 8);
  612. mp4_ComputeChroma4MV(pMBinfo->mv, &mvCbCr);
  613. }
  614. mp4_LimitMV(&mvCbCr, &mvCbCr, &limitRectC, dx >> 1, dy >> 1, 8);
  615. }
  616. }
  617. else
  618. {
  619. IppMotionVector mvFT, mvFB;
  620. if (mp4_PredictDecodeFMV(pInfo, pMBinfo, rowNum, colNum, &mvFT, &mvFB) != MP4_STATUS_OK)
  621. goto Err_3;
  622. mvField[0] = mvFT; mvField[1] = mvFB;
  623. if (quarter_sample)
  624. {
  625. mp4_LimitFMVQ(&mvFT, &mvCur[0], &limitRectL, dx, dy, 16);
  626. mp4_LimitFMVQ(&mvFB, &mvCur[2], &limitRectL, dx, dy, 16);
  627. mvTmp[0].dx = (int16_t)mp4_Div2(mvCur[0].dx);
  628. mvTmp[0].dy = (int16_t)(mp4_Div2(mvCur[0].dy << 1) >> 1);
  629. mvTmp[2].dx = (int16_t)mp4_Div2(mvCur[2].dx);
  630. mvTmp[2].dy = (int16_t)(mp4_Div2(mvCur[2].dy << 1) >> 1);
  631. mp4_ComputeChromaMV(&mvTmp[0], &mvCbCrT);
  632. mp4_ComputeChromaMV(&mvTmp[2], &mvCbCrB);
  633. }
  634. else
  635. {
  636. mp4_LimitFMV(&mvFT, &mvCur[0], &limitRectL, dx, dy, 16);
  637. mp4_LimitFMV(&mvFB, &mvCur[2], &limitRectL, dx, dy, 16);
  638. mp4_ComputeChromaMV(&mvCur[0], &mvCbCrT);
  639. mp4_ComputeChromaMV(&mvCur[2], &mvCbCrB);
  640. }
  641. }
  642. }
  643. }
  644. if (!obmc_disable)
  645. {
  646. // OBMC for previous MB
  647. if (colNum > 0)
  648. if (pMBinfo[-1].type < IPPVC_MBTYPE_INTRA && !(pMBinfo[-1].field_info & 1))
  649. mp4_OBMC(pInfo, pMBinfo - 1, mvPrev, colNum - 1, rowNum, limitRectL, pYc - 16, stepYc, pYr - 16, stepYr, cbpyPrev, coeffMB, dct_typePrev);
  650. if (mb_type < IPPVC_MBTYPE_INTRA && !field_prediction)
  651. {
  652. if (mb_not_coded)
  653. {
  654. cbpyPrev = 0;
  655. mp4_Zero4MV(mvPrev);
  656. ippiCopy8x8_8u_C1R(pCbr, stepCbr, pCbc, stepCbc);
  657. ippiCopy8x8_8u_C1R(pCrr, stepCrr, pCrc, stepCrc);
  658. }
  659. else
  660. {
  661. cbpyPrev = cbpy;
  662. dct_typePrev = dct_type;
  663. mvPrev[0] = mvCur[0]; mvPrev[1] = mvCur[1]; mvPrev[2] = mvCur[2]; mvPrev[3] = mvCur[3];
  664. if (mp4_DecodeInterMB(pInfo, coeffMB, quant, (cbpy << 2) + cbpc, scan) != MP4_STATUS_OK)
  665. goto Err_3;
  666. mp4_MC_HP(cbpc & 2, pCbr, stepCbr, pCbc, stepCbc, coeffMB+256, &mvCbCr, rt);
  667. mp4_MC_HP(cbpc & 1, pCrr, stepCrr, pCrc, stepCrc, coeffMB+320, &mvCbCr, rt);
  668. }
  669. // OBMC current MB if it is the last in the row
  670. if (colNum == mbPerRow - 1)
  671. mp4_OBMC(pInfo, pMBinfo, mvPrev, colNum, rowNum, limitRectL, pYc, stepYc, pYr, stepYr, cbpyPrev, coeffMB, dct_typePrev);
  672. }
  673. }
  674. if (mb_type < IPPVC_MBTYPE_INTRA && (obmc_disable || field_prediction))
  675. {
  676. if (mb_not_coded)
  677. {
  678. #ifdef USE_NOTCODED_STATE
  679. if (!(*ncState))
  680. {
  681. *ncState = 1;
  682. #endif
  683. ippiCopy16x16_8u_C1R(pYr, stepYr, pYc, stepYc);
  684. ippiCopy8x8_8u_C1R(pCbr, stepCbr, pCbc, stepCbc);
  685. ippiCopy8x8_8u_C1R(pCrr, stepCrr, pCrc, stepCrc);
  686. #ifdef USE_NOTCODED_STATE
  687. }
  688. #endif
  689. }
  690. else
  691. {
  692. #ifdef USE_NOTCODED_STATE
  693. // clear not_coded MB state
  694. *ncState = 0;
  695. #endif
  696. if (mp4_DecodeInterMB(pInfo, coeffMB, quant, (cbpy << 2) + cbpc, scan) != MP4_STATUS_OK)
  697. goto Err_3;
  698. if (quarter_sample)
  699. {
  700. if (!field_prediction)
  701. {
  702. if (mb_type == IPPVC_MBTYPE_INTER4V)
  703. {
  704. mp4_Copy8x8QP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  705. mp4_Copy8x8QP_8u(pYr+8, stepYr, pYc+8, stepYc, &mvCur[1], rt);
  706. mp4_Copy8x8QP_8u(pYr+stepYr*8, stepYr, pYc+stepYc*8, stepYc, &mvCur[2], rt);
  707. mp4_Copy8x8QP_8u(pYr+8+stepYr*8, stepYr, pYc+8+stepYc*8, stepYc, &mvCur[3], rt);
  708. }
  709. else
  710. mp4_Copy16x16QP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  711. }
  712. else
  713. {
  714. mp4_Copy16x8QP_8u(pYr+stepYr*mb_ftfr, stepYr*2, pYc, stepYc*2, &mvCur[0], rt);
  715. mp4_Copy16x8QP_8u(pYr+stepYr*mb_fbfr, stepYr*2, pYc+stepYc, stepYc*2, &mvCur[2], rt);
  716. }
  717. }
  718. else
  719. {
  720. if (!field_prediction)
  721. {
  722. if (mb_type == IPPVC_MBTYPE_INTER4V)
  723. {
  724. mp4_Copy8x8HP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  725. mp4_Copy8x8HP_8u(pYr+8, stepYr, pYc+8, stepYc, &mvCur[1], rt);
  726. mp4_Copy8x8HP_8u(pYr+stepYr*8, stepYr, pYc+stepYc*8, stepYc, &mvCur[2], rt);
  727. mp4_Copy8x8HP_8u(pYr+8+stepYr*8, stepYr, pYc+8+stepYc*8, stepYc, &mvCur[3], rt);
  728. }
  729. else
  730. {
  731. mp4_Copy16x16HP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  732. }
  733. }
  734. else
  735. {
  736. mp4_Copy16x8HP_8u(pYr+stepYr*mb_ftfr, stepYr*2, pYc, stepYc*2, &mvCur[0], rt);
  737. mp4_Copy16x8HP_8u(pYr+stepYr*mb_fbfr, stepYr*2, pYc+stepYc, stepYc*2, &mvCur[2], rt);
  738. }
  739. }
  740. if (!dct_type)
  741. {
  742. mp4_AddResidual(cbpy & 8, pYc, stepYc, coeffMB);
  743. mp4_AddResidual(cbpy & 4, pYc+8, stepYc, coeffMB+64);
  744. mp4_AddResidual(cbpy & 2, pYc+stepYc*8, stepYc, coeffMB+128);
  745. mp4_AddResidual(cbpy & 1, pYc+stepYc*8+8, stepYc, coeffMB+192);
  746. } else {
  747. mp4_AddResidual(cbpy & 8, pYc, stepYc*2, coeffMB);
  748. mp4_AddResidual(cbpy & 4, pYc+8, stepYc*2, coeffMB+64);
  749. mp4_AddResidual(cbpy & 2, pYc+stepYc, stepYc*2, coeffMB+128);
  750. mp4_AddResidual(cbpy & 1, pYc+stepYc+8, stepYc*2, coeffMB+192);
  751. }
  752. if (!field_prediction) {
  753. mp4_MC_HP(cbpc & 2, pCbr, stepCbr, pCbc, stepCbc, coeffMB+256, &mvCbCr, rt);
  754. mp4_MC_HP(cbpc & 1, pCrr, stepCrr, pCrc, stepCrc, coeffMB+320, &mvCbCr, rt);
  755. } else {
  756. mp4_Copy8x4HP_8u(pCbr+(mb_ftfr ? stepCbr : 0), stepCbr*2, pCbc, stepCbc*2, &mvCbCrT, rt);
  757. mp4_Copy8x4HP_8u(pCrr+(mb_ftfr ? stepCrr : 0), stepCrr*2, pCrc, stepCrc*2, &mvCbCrT, rt);
  758. mp4_Copy8x4HP_8u(pCbr+(mb_fbfr ? stepCbr : 0), stepCbr*2, pCbc+stepCbc, stepCbc*2, &mvCbCrB, rt);
  759. mp4_Copy8x4HP_8u(pCrr+(mb_fbfr ? stepCrr : 0), stepCrr*2, pCrc+stepCrc, stepCrc*2, &mvCbCrB, rt);
  760. mp4_AddResidual(cbpc & 2, pCbc, stepCbc, coeffMB+256);
  761. mp4_AddResidual(cbpc & 1, pCrc, stepCrc, coeffMB+320);
  762. }
  763. }
  764. }
  765. #ifdef USE_NOTCODED_STATE
  766. ncState ++;
  767. #endif
  768. pMBinfo ++;
  769. mvField += 2;
  770. mbInVideoPacket ++;
  771. colNum ++;
  772. if (colNum == mbPerRow) {
  773. colNum = 0;
  774. rowNum ++;
  775. if (rowNum == mbPerCol) {
  776. // skip stuffing
  777. while (mp4_ShowBits(pInfo, 10) == 1)
  778. mp4_FlushBits(pInfo, 10);
  779. return sts;
  780. }
  781. pYc += (2 * MP4_NUM_EXT_MB + 1) * 16 + (stepYc << 4) - stepYc;
  782. pCbc += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCbc << 3) - stepCbc;
  783. pCrc += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCrc << 3) - stepCrc;
  784. pYr += (2 * MP4_NUM_EXT_MB + 1) * 16 + (stepYr << 4) - stepYr;
  785. pCbr += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCbr << 3) - stepCbr;
  786. pCrr += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCrr << 3) - stepCrr;
  787. } else {
  788. pYc += 16; pCrc += 8; pCbc += 8;
  789. pYr += 16; pCrr += 8; pCbr += 8;
  790. }
  791. }
  792. if (!pInfo->VisualObject.VideoObject.resync_marker_disable) {
  793. int32_t found;
  794. ErrRet_3:
  795. if (mp4_CheckDecodeVideoPacket(pInfo, &found) == MP4_STATUS_OK) {
  796. if (found) {
  797. mbInVideoPacket = pInfo->VisualObject.VideoObject.VideoObjectPlane.macroblock_num - mbCurr;
  798. quant = pInfo->VisualObject.VideoObject.VideoObjectPlane.quant_scale;
  799. mbCurr = pInfo->VisualObject.VideoObject.VideoObjectPlane.macroblock_num;
  800. mp4_CopyMacroBlocks(pInfo->VisualObject.rFrame, pInfo->VisualObject.cFrame, mbPerRow, rowNum, colNum, mbCurr - rowNum * mbPerRow - colNum);
  801. rowNum = mbCurr / mbPerRow;
  802. colNum = mbCurr % mbPerRow;
  803. pYc = pInfo->VisualObject.cFrame->pY + (rowNum * stepYc + colNum) * 16; pCbc = pInfo->VisualObject.cFrame->pCb + (rowNum * stepCbc + colNum) * 8; pCrc = pInfo->VisualObject.cFrame->pCr + (rowNum * stepCrc + colNum) * 8;
  804. pYr = pInfo->VisualObject.rFrame->pY + (rowNum * stepYr + colNum) * 16; pCbr = pInfo->VisualObject.rFrame->pCb + (rowNum * stepCbr + colNum) * 8; pCrr = pInfo->VisualObject.rFrame->pCr + (rowNum * stepCrr + colNum) * 8;
  805. pMBinfo = pInfo->VisualObject.VideoObject.MBinfo + mbCurr;
  806. #ifdef USE_NOTCODED_STATE
  807. ncState = pInfo->VisualObject.VideoObject.ncState + mbCurr;
  808. #endif
  809. mvField = pInfo->VisualObject.VideoObject.FieldMV + 2 * mbCurr;
  810. break;
  811. }
  812. } else
  813. goto Err_3;
  814. }
  815. }
  816. // mark MBs the previous videopacket as invalid for prediction
  817. for (i = 1; i <= IPP_MIN(mbInVideoPacket, mbPerRow + 1); i ++) {
  818. pMBinfo[-i].validPred = 0;
  819. }
  820. }
  821. Err_3:
  822. sts = MP4_STATUS_ERROR;
  823. if (pInfo->stopOnErr)
  824. return sts;
  825. if (pInfo->VisualObject.VideoObject.resync_marker_disable || !mp4_SeekResyncMarker(pInfo))
  826. {
  827. mp4_CopyMacroBlocks(pInfo->VisualObject.rFrame, pInfo->VisualObject.cFrame, mbPerRow, rowNum, colNum, pInfo->VisualObject.VideoObject.MacroBlockPerVOP - rowNum * mbPerRow - colNum);
  828. return sts;
  829. }
  830. goto ErrRet_3;
  831. }
  832. // decode usual P-VOP
  833. {
  834. for (;;)
  835. {
  836. // reset Intra prediction buffer on new Video_packet
  837. mp4_ResetIntraPredBuffer(pInfo);
  838. mbInVideoPacket = 0;
  839. // decode blocks
  840. for (;;)
  841. {
  842. if (colNum == 0)
  843. {
  844. // reset B-prediction blocks on new row
  845. mp4_ResetIntraPredBblock(pInfo);
  846. }
  847. mb_not_coded = mp4_GetBit(pInfo);
  848. mb_type = IPPVC_MBTYPE_INTER;
  849. if (!mb_not_coded)
  850. if (mp4_DecodeMCBPC_P(pInfo, &mb_type, &cbpc, 1) != MP4_STATUS_OK)
  851. goto Err_4;
  852. if (mb_type != IPPVC_MB_STUFFING)
  853. {
  854. if (!mb_not_coded)
  855. {
  856. if (mb_type >= IPPVC_MBTYPE_INTRA)
  857. ac_pred_flag = mp4_GetBit(pInfo);
  858. if (mp4_DecodeCBPY_P(pInfo, &cbpy, mb_type) != MP4_STATUS_OK)
  859. goto Err_4;
  860. quantPred = quant;
  861. if (mb_type == IPPVC_MBTYPE_INTER_Q || mb_type == IPPVC_MBTYPE_INTRA_Q)
  862. mp4_UpdateQuant(pInfo, quant);
  863. }
  864. else
  865. {
  866. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nMB_NOTCODED);
  867. mp4_Zero4MV(pMBinfo->mv);
  868. }
  869. pMBinfo->validPred = 1;
  870. pMBinfo->not_coded = (uint8_t)mb_not_coded;
  871. pMBinfo->type = (uint8_t)mb_type;
  872. if (mb_type >= IPPVC_MBTYPE_INTRA) {
  873. if (mbInVideoPacket == 0)
  874. quantPred = quant;
  875. dcVLC = (quantPred < mp4_DC_vlc_Threshold[pInfo->VisualObject.VideoObject.VideoObjectPlane.intra_dc_vlc_thr]) ? 1 : 0;
  876. pFc[0] = pYc; pFc[1] = pYc + 8; pFc[2] = pYc + 8 * stepYc; pFc[3] = pYc + 8 * stepYc + 8; pFc[4] = pCbc; pFc[5] = pCrc;
  877. if (mp4_DecodeIntraMB(pInfo, colNum, (cbpy << 2) + cbpc, quant, dcVLC, ac_pred_flag, pFc, stepFc) != MP4_STATUS_OK)
  878. goto Err_4;
  879. mp4_Zero4MV(pMBinfo->mv);
  880. #ifdef USE_NOTCODED_STATE
  881. // clear not_coded MB state
  882. *ncState = 0;
  883. #endif
  884. } else {
  885. mp4_UpdateIntraPredBuffInvalid(pInfo, colNum);
  886. if (!mb_not_coded) {
  887. dx = colNum * 16;
  888. dy = rowNum * 16;
  889. if (mb_type != IPPVC_MBTYPE_INTER4V) {
  890. if (mp4_PredictDecode1MV(pInfo, pMBinfo, rowNum, colNum) != MP4_STATUS_OK)
  891. goto Err_4;
  892. pMBinfo->mv[1] = pMBinfo->mv[2] = pMBinfo->mv[3] = pMBinfo->mv[0];
  893. if (quarter_sample) {
  894. mp4_LimitMVQ(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 16);
  895. mp4_ComputeChromaMVQ(mvCur, &mvCbCr);
  896. } else {
  897. mp4_LimitMV(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 16);
  898. mp4_ComputeChromaMV(mvCur, &mvCbCr);
  899. }
  900. mvCur[1] = mvCur[2] = mvCur[3] = mvCur[0];
  901. } else {
  902. if (mp4_PredictDecode4MV(pInfo, pMBinfo, rowNum, colNum) != MP4_STATUS_OK)
  903. goto Err_4;
  904. if (quarter_sample) {
  905. mp4_Limit4MVQ(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 8);
  906. mp4_ComputeChroma4MVQ(pMBinfo->mv, &mvCbCr);
  907. } else {
  908. mp4_Limit4MV(pMBinfo->mv, mvCur, &limitRectL, dx, dy, 8);
  909. mp4_ComputeChroma4MV(pMBinfo->mv, &mvCbCr);
  910. }
  911. mp4_LimitMV(&mvCbCr, &mvCbCr, &limitRectC, dx >> 1, dy >> 1, 8);
  912. }
  913. }
  914. if (obmc_disable) {
  915. if (mb_not_coded) {
  916. #ifdef USE_NOTCODED_STATE
  917. if (!(*ncState)) {
  918. *ncState = 1;
  919. #endif
  920. ippiCopy16x16_8u_C1R(pYr, stepYr, pYc, stepYc);
  921. ippiCopy8x8_8u_C1R(pCbr, stepCbr, pCbc, stepCbc);
  922. ippiCopy8x8_8u_C1R(pCrr, stepCrr, pCrc, stepCrc);
  923. #ifdef USE_NOTCODED_STATE
  924. }
  925. #endif
  926. } else {
  927. #ifdef USE_NOTCODED_STATE
  928. // clear not_coded MB state
  929. *ncState = 0;
  930. #endif
  931. if (quarter_sample) {
  932. if (mb_type == IPPVC_MBTYPE_INTER4V) {
  933. mp4_Copy8x8QP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  934. mp4_Copy8x8QP_8u(pYr+8, stepYr, pYc+8, stepYc, &mvCur[1], rt);
  935. mp4_Copy8x8QP_8u(pYr+8*stepYr, stepYr, pYc+8*stepYc, stepYc, &mvCur[2], rt);
  936. mp4_Copy8x8QP_8u(pYr+8*stepYr+8, stepYr, pYc+8*stepYc+8, stepYc, &mvCur[3], rt);
  937. } else
  938. mp4_Copy16x16QP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  939. mp4_DecodeReconBlockInter_MPEG4(cbpy & 8, pYc, stepYc, Err_4);
  940. mp4_DecodeReconBlockInter_MPEG4(cbpy & 4, pYc+8, stepYc, Err_4);
  941. mp4_DecodeReconBlockInter_MPEG4(cbpy & 2, pYc+8*stepYc, stepYc, Err_4);
  942. mp4_DecodeReconBlockInter_MPEG4(cbpy & 1, pYc+8*stepYc+8, stepYc, Err_4);
  943. } else {
  944. if (cbpy || mb_type == IPPVC_MBTYPE_INTER4V) {
  945. mp4_DecodeMCBlockInter_MPEG4(cbpy & 8, pYr, stepYr, pYc, stepYc, mvCur[0], rt, Err_4);
  946. mp4_DecodeMCBlockInter_MPEG4(cbpy & 4, pYr+8, stepYr, pYc+8, stepYc, mvCur[1], rt, Err_4);
  947. mp4_DecodeMCBlockInter_MPEG4(cbpy & 2, pYr+8*stepYr, stepYr, pYc+8*stepYc, stepYc, mvCur[2], rt, Err_4);
  948. mp4_DecodeMCBlockInter_MPEG4(cbpy & 1, pYr+8*stepYr+8, stepYr, pYc+8*stepYc+8, stepYc, mvCur[3], rt, Err_4);
  949. } else {
  950. mp4_Copy16x16HP_8u(pYr, stepYr, pYc, stepYc, &mvCur[0], rt);
  951. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  952. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  953. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  954. mp4_StatisticInc_(&pInfo->VisualObject.Statistic.nB_INTER_NC);
  955. //if (cbpy) {
  956. // mp4_DecodeReconBlockInter_MPEG4(cbpy & 8, pYc, stepYc);
  957. // mp4_DecodeReconBlockInter_MPEG4(cbpy & 4, pYc+8, stepYc);
  958. // mp4_DecodeReconBlockInter_MPEG4(cbpy & 2, pYc+8*stepYc, stepYc);
  959. // mp4_DecodeReconBlockInter_MPEG4(cbpy & 1, pYc+8*stepYc+8, stepYc);
  960. //}
  961. }
  962. }
  963. mp4_DecodeMCBlockInter_MPEG4(cbpc & 2, pCbr, stepCbr, pCbc, stepCbc, mvCbCr, rt, Err_4);
  964. mp4_DecodeMCBlockInter_MPEG4(cbpc & 1, pCrr, stepCrr, pCrc, stepCrc, mvCbCr, rt, Err_4);
  965. }
  966. }
  967. }
  968. if (!obmc_disable) {
  969. // OBMC for previous MB
  970. if (colNum > 0)
  971. if (pMBinfo[-1].type < IPPVC_MBTYPE_INTRA)
  972. mp4_OBMC(pInfo, pMBinfo - 1, mvPrev, colNum - 1, rowNum, limitRectL, pYc - 16, stepYc, pYr - 16, stepYr, cbpyPrev, coeffMB, 0);
  973. if (mb_type < IPPVC_MBTYPE_INTRA) {
  974. if (mb_not_coded)
  975. {
  976. cbpyPrev = 0;
  977. mp4_Zero4MV(mvPrev);
  978. ippiCopy8x8_8u_C1R(pCbr, stepCbr, pCbc, stepCbc);
  979. ippiCopy8x8_8u_C1R(pCrr, stepCrr, pCrc, stepCrc);
  980. }
  981. else
  982. {
  983. cbpyPrev = cbpy;
  984. mvPrev[0] = mvCur[0]; mvPrev[1] = mvCur[1]; mvPrev[2] = mvCur[2]; mvPrev[3] = mvCur[3];
  985. if (mp4_DecodeInterMB(pInfo, coeffMB, quant, (cbpy << 2) + cbpc, scan) != MP4_STATUS_OK)
  986. goto Err_4;
  987. mp4_MC_HP(cbpc & 2, pCbr, stepCbr, pCbc, stepCbc, coeffMB+256, &mvCbCr, rt);
  988. mp4_MC_HP(cbpc & 1, pCrr, stepCrr, pCrc, stepCrc, coeffMB+320, &mvCbCr, rt);
  989. }
  990. // OBMC current MB if it is the last in the row
  991. if (colNum == mbPerRow - 1)
  992. mp4_OBMC(pInfo, pMBinfo, mvPrev, colNum, rowNum, limitRectL, pYc, stepYc, pYr, stepYr, cbpyPrev, coeffMB, 0);
  993. }
  994. }
  995. #ifdef USE_NOTCODED_STATE
  996. ncState ++;
  997. #endif
  998. pMBinfo ++;
  999. mbInVideoPacket ++;
  1000. colNum ++;
  1001. if (colNum == mbPerRow)
  1002. {
  1003. colNum = 0;
  1004. rowNum ++;
  1005. if (rowNum == mbPerCol)
  1006. {
  1007. // skip stuffing
  1008. while (mp4_ShowBits(pInfo, 10) == 1)
  1009. mp4_FlushBits(pInfo, 10);
  1010. return sts;
  1011. }
  1012. pYc += (2 * MP4_NUM_EXT_MB + 1) * 16 + (stepYc << 4) - stepYc;
  1013. pCbc += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCbc << 3) - stepCbc;
  1014. pCrc += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCrc << 3) - stepCrc;
  1015. pYr += (2 * MP4_NUM_EXT_MB + 1) * 16 + (stepYr << 4) - stepYr;
  1016. pCbr += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCbr << 3) - stepCbr;
  1017. pCrr += (2 * MP4_NUM_EXT_MB + 1) * 8 + (stepCrr << 3) - stepCrr;
  1018. }
  1019. else
  1020. {
  1021. pYc += 16; pCrc += 8; pCbc += 8;
  1022. pYr += 16; pCrr += 8; pCbr += 8;
  1023. }
  1024. }
  1025. if (!pInfo->VisualObject.VideoObject.resync_marker_disable)
  1026. {
  1027. int32_t found;
  1028. ErrRet_4:
  1029. if (mp4_CheckDecodeVideoPacket(pInfo, &found) == MP4_STATUS_OK)
  1030. {
  1031. if (found) {
  1032. mbInVideoPacket = pInfo->VisualObject.VideoObject.VideoObjectPlane.macroblock_num - mbCurr;
  1033. quant = pInfo->VisualObject.VideoObject.VideoObjectPlane.quant_scale;
  1034. mbCurr = pInfo->VisualObject.VideoObject.VideoObjectPlane.macroblock_num;
  1035. mp4_CopyMacroBlocks(pInfo->VisualObject.rFrame, pInfo->VisualObject.cFrame, mbPerRow, rowNum, colNum, mbCurr - rowNum * mbPerRow - colNum);
  1036. rowNum = mbCurr / mbPerRow;
  1037. colNum = mbCurr % mbPerRow;
  1038. pYc = pInfo->VisualObject.cFrame->pY + (rowNum * stepYc + colNum) * 16; pCbc = pInfo->VisualObject.cFrame->pCb + (rowNum * stepCbc + colNum) * 8; pCrc = pInfo->VisualObject.cFrame->pCr + (rowNum * stepCrc + colNum) * 8;
  1039. pYr = pInfo->VisualObject.rFrame->pY + (rowNum * stepYr + colNum) * 16; pCbr = pInfo->VisualObject.rFrame->pCb + (rowNum * stepCbr + colNum) * 8; pCrr = pInfo->VisualObject.rFrame->pCr + (rowNum * stepCrr + colNum) * 8;
  1040. pMBinfo = pInfo->VisualObject.VideoObject.MBinfo + mbCurr;
  1041. #ifdef USE_NOTCODED_STATE
  1042. ncState = pInfo->VisualObject.VideoObject.ncState + mbCurr;
  1043. #endif
  1044. break;
  1045. }
  1046. }
  1047. else
  1048. goto Err_4;
  1049. }
  1050. }
  1051. // mark MBs the previous videopacket as invalid for prediction
  1052. for (i = 1; i <= IPP_MIN(mbInVideoPacket, mbPerRow + 1); i ++)
  1053. {
  1054. pMBinfo[-i].validPred = 0;
  1055. }
  1056. }
  1057. Err_4:
  1058. sts = MP4_STATUS_ERROR;
  1059. if (pInfo->stopOnErr)
  1060. return sts;
  1061. if (pInfo->VisualObject.VideoObject.resync_marker_disable || !mp4_SeekResyncMarker(pInfo))
  1062. {
  1063. mp4_CopyMacroBlocks(pInfo->VisualObject.rFrame, pInfo->VisualObject.cFrame, mbPerRow, rowNum, colNum, pInfo->VisualObject.VideoObject.MacroBlockPerVOP - rowNum * mbPerRow - colNum);
  1064. return sts;
  1065. }
  1066. goto ErrRet_4;
  1067. }
  1068. }