Skip to content

Commit

Permalink
[Encode] Fix AV1 MB coded buffer overflow issue
Browse files Browse the repository at this point in the history
Currently there is page fault at the right bound of AV1 MB coded buffer. This patch is to fix this issue by calculating the correct max coded data size.
  • Loading branch information
chenhao5-Intel authored and intel-mediadev committed Nov 13, 2024
1 parent dbfb86c commit 9553d1c
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,20 @@ MOS_STATUS Av1BasicFeature::UpdateTrackedBufferParameters()

m_trackedBuf->OnSizeChange();

// The MB code size here, it is from Arch's suggestion
const uint32_t numOfCU = MOS_ROUNDUP_DIVIDE(m_frameWidth, 8) * MOS_ROUNDUP_DIVIDE(m_frameHeight, 8);

m_mbCodeSize = MOS_ALIGN_CEIL((numOfCU * CODECHAL_PAK_OBJ_EACH_CU), CODECHAL_PAGE_SIZE);
// Here to calculate the max coded data size needed for one frame according to LCU and CU partitions
//
// 1.LCU and CU num:
// LCU size is 64x64 so we can get the LCU num according to frame width and hight
// The restrict min CU size is 8x8 so we can get totally max 64 CUs per LCU
//
// 2.LCU and CU data size:
// LCU header size 5DW, CU size 8DW. And a DW size is 64bits(2 * sizeof(uint32_t))
//
// 3.Calculate the max coded data size needed
//
// 4.Finally need to do page align for CL alignment at the end of the frame
uint32_t numOfLCU = MOS_ROUNDUP_DIVIDE(m_frameWidth, av1SuperBlockWidth) * MOS_ROUNDUP_DIVIDE(m_frameHeight, av1SuperBlockHeight);
m_mbCodeSize = MOS_ALIGN_CEIL(2 * sizeof(uint32_t) * (numOfLCU * 5 + numOfLCU * 64 * 8), CODECHAL_PAGE_SIZE);
m_mvDataSize = 0;

uint32_t downscaledWidthInMb4x =
Expand Down

0 comments on commit 9553d1c

Please sign in to comment.