Skip to content

Commit

Permalink
replace the reconstruct surface to be variant
Browse files Browse the repository at this point in the history
replace the reconstruct surface to be variant surface for HEVC REXT encoding
it could make the difference between recon/raw to be transparent to application
pay attention , the surface should be not read or write.

Signed-off-by: XinfengZhang <[email protected]>
  • Loading branch information
XinfengZhang committed Apr 22, 2020
1 parent ebfd24b commit fbfb950
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
15 changes: 14 additions & 1 deletion media_driver/linux/common/codec/ddi/media_ddi_encode_hevc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,20 @@ VAStatus DdiEncodeHevc::ParseSlcParams(
hevcSlcParams->chroma_offset[1][i][1] = MOS_CLAMP_MIN_MAX(vaEncSlcParamsHEVC->chroma_offset_l1[i][1], minChromaOffset, maxChromaOffset);
hevcSlcParams->delta_chroma_weight[1][i][1] = vaEncSlcParamsHEVC->delta_chroma_weight_l1[i][1];
}

for (uint32_t i = 0; i < numMaxRefFrame; i++)
{
if(m_encodeCtx->vaEntrypoint==VAEntrypointEncSliceLP && (m_encodeCtx->vaProfile == VAProfileHEVCMain444 || m_encodeCtx->vaProfile == VAProfileHEVCMain444_10 || m_encodeCtx->vaProfile == VAProfileHEVCMain444_12))
{
if(vaEncSlcParamsHEVC->ref_pic_list0[i].picture_id != VA_INVALID_SURFACE)
{
DdiMedia_ReplaceSurfaceWithVariant(DdiMedia_GetSurfaceFromVASurfaceID(mediaCtx, vaEncSlcParamsHEVC->ref_pic_list0[i].picture_id));
}
if(vaEncSlcParamsHEVC->ref_pic_list1[i].picture_id != VA_INVALID_SURFACE)
{
DdiMedia_ReplaceSurfaceWithVariant(DdiMedia_GetSurfaceFromVASurfaceID(mediaCtx, vaEncSlcParamsHEVC->ref_pic_list1[i].picture_id));
}
}
}
for (uint32_t i = 0; i < numMaxRefFrame; i++)
{
if(i > hevcSlcParams->num_ref_idx_l0_active_minus1)
Expand Down
81 changes: 81 additions & 0 deletions media_driver/linux/common/ddi/media_libva_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,87 @@ PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithNewFormat(PDDI_MEDIA_SURFACE surfa
return dstSurface;
}

PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithVariant(PDDI_MEDIA_SURFACE surface)
{
DDI_CHK_NULL(surface, "nullptr surface", nullptr);

PDDI_MEDIA_SURFACE_HEAP_ELEMENT surfaceElement = (PDDI_MEDIA_SURFACE_HEAP_ELEMENT)surface->pMediaCtx->pSurfaceHeap->pHeapBase;
PDDI_MEDIA_CONTEXT mediaCtx = surface->pMediaCtx;
uint32_t aligned_width, aligned_height;

//check some conditions
if(surface->uiVariantFlag)
{
return surface;
}
if (nullptr == surfaceElement)
{
return nullptr;
}

switch (surface->format)
{
case Media_Format_AYUV:
aligned_width = MOS_ALIGN_CEIL(surface->iWidth, 128);
aligned_height = MOS_ALIGN_CEIL(surface->iHeight * 3 / 4, 64);
break;
case Media_Format_Y410:
aligned_width = MOS_ALIGN_CEIL(surface->iWidth, 64);
aligned_height = MOS_ALIGN_CEIL(surface->iHeight * 3 / 2, 64);
break;
default:
return surface;
}

//create new dst surface and copy the structure
PDDI_MEDIA_SURFACE dstSurface = (DDI_MEDIA_SURFACE *)MOS_AllocAndZeroMemory(sizeof(DDI_MEDIA_SURFACE));

MOS_SecureMemcpy(dstSurface,sizeof(DDI_MEDIA_SURFACE),surface,sizeof(DDI_MEDIA_SURFACE));
DDI_CHK_NULL(dstSurface, "nullptr dstSurface", nullptr);

dstSurface->uiLockedBufID = VA_INVALID_ID;
dstSurface->uiLockedImageID = VA_INVALID_ID;
dstSurface->pSurfDesc = nullptr;
dstSurface->uiVariantFlag = 1;
dstSurface->iWidth = aligned_width;
dstSurface->iHeight = aligned_height;
//CreateNewSurface
if(DdiMediaUtil_CreateSurface(dstSurface,mediaCtx) != VA_STATUS_SUCCESS)
{
MOS_FreeMemory(dstSurface);
return surface;
}
//lock surface heap
DdiMediaUtil_LockMutex(&mediaCtx->SurfaceMutex);
uint32_t i;
//get current element heap and index
for(i = 0; i < mediaCtx->pSurfaceHeap->uiAllocatedHeapElements; i ++)
{
if(surface == surfaceElement->pSurface)
{
break;
}
surfaceElement ++;
}
//if cant find
if(i == surface->pMediaCtx->pSurfaceHeap->uiAllocatedHeapElements)
{
DdiMediaUtil_LockMutex(&mediaCtx->SurfaceMutex);
DdiMediaUtil_FreeSurface(dstSurface);
MOS_FreeMemory(dstSurface);
return nullptr;
}
//replace the surface
surfaceElement->pSurface = dstSurface;
//unlock the heap
DdiMediaUtil_UnLockMutex(&mediaCtx->SurfaceMutex);
//FreeSurface
DdiMediaUtil_FreeSurface(surface);
MOS_FreeMemory(surface);

return dstSurface;
}

DDI_MEDIA_BUFFER* DdiMedia_GetBufferFromVABufferID (PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID)
{
uint32_t i = 0;
Expand Down
14 changes: 13 additions & 1 deletion media_driver/linux/common/ddi/media_libva_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ typedef struct _DDI_MEDIA_SURFACE
uint8_t *pSystemShadow; // Shadow surface in system memory

uint32_t uiMapFlag;

uint32_t uiVariantFlag;
} DDI_MEDIA_SURFACE, *PDDI_MEDIA_SURFACE;

typedef struct _DDI_MEDIA_BUFFER
Expand Down Expand Up @@ -558,7 +560,6 @@ void* DdiMedia_GetContextFromContextID (VADriverContextP ctx, VAContextID vaCtxI
//!
DDI_MEDIA_SURFACE* DdiMedia_GetSurfaceFromVASurfaceID (PDDI_MEDIA_CONTEXT mediaCtx, VASurfaceID surfaceID);


//!
//! \brief replace the surface with given format
//!
Expand All @@ -572,6 +573,17 @@ DDI_MEDIA_SURFACE* DdiMedia_GetSurfaceFromVASurfaceID (PDDI_MEDIA_CONTEXT mediaC
//!
PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithNewFormat(PDDI_MEDIA_SURFACE surface, DDI_MEDIA_FORMAT expectedFormat);

//!
//! \brief replace the surface with correlation variant format
//!
//! \param [in] surface
//! Pointer to the old surface
//!
//! \return DDI_MEDIA_SURFACE*
//! Pointer to new ddi media surface
//!
PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithVariant(PDDI_MEDIA_SURFACE surface);

//!
//! \brief Get VA surface ID from surface
//!
Expand Down

0 comments on commit fbfb950

Please sign in to comment.