Skip to content

Commit

Permalink
change surface format for jpeg 444 file decode
Browse files Browse the repository at this point in the history
fix for #43

Signed-off-by: XinfengZhang <carl.zhang@intel.com>
  • Loading branch information
XinfengZhang authored and intel-mediadev committed Aug 10, 2018
1 parent 5fcf173 commit 94e0dd5
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
7 changes: 7 additions & 0 deletions media_driver/linux/common/codec/ddi/media_ddi_decode_jpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,13 @@ VAStatus DdiDecodeJPEG::SetDecodeParams()
m_destSurface.dwOffset = 0;
m_destSurface.Format = Format_NV12;

CodecDecodeJpegPicParams *jpegPicParam = (CodecDecodeJpegPicParams *)(m_ddiDecodeCtx->DecodeParams.m_picParams);
if((m_ddiDecodeCtx->RTtbl.pCurrentRT->format == Media_Format_NV12)
&&(jpegPicParam->m_chromaType == jpegYUV444))
{
m_ddiDecodeCtx->RTtbl.pCurrentRT = DdiMedia_ReplaceSurfaceWithNewFormat(m_ddiDecodeCtx->RTtbl.pCurrentRT, Media_Format_444P);
}

DdiMedia_MediaSurfaceToMosResource((&(m_ddiDecodeCtx->RTtbl))->pCurrentRT, &(m_destSurface.OsResource));

(&m_ddiDecodeCtx->DecodeParams)->m_destSurface = &m_destSurface;
Expand Down
66 changes: 66 additions & 0 deletions media_driver/linux/common/ddi/media_libva_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,72 @@ DDI_MEDIA_SURFACE* DdiMedia_GetSurfaceFromVASurfaceID (PDDI_MEDIA_CONTEXT mediaC
return surface;
}

VASurfaceID DdiMedia_GetVASurfaceIDFromSurface(PDDI_MEDIA_SURFACE surface)
{
PDDI_MEDIA_SURFACE_HEAP_ELEMENT surfaceElement = (PDDI_MEDIA_SURFACE_HEAP_ELEMENT)surface->pMediaCtx->pSurfaceHeap->pHeapBase;
for(uint32_t i = 0; i < surface->pMediaCtx->pSurfaceHeap->uiAllocatedHeapElements; i ++)
{
if(surface == surfaceElement->pSurface)
{
return surfaceElement->uiVaSurfaceID;
}
surfaceElement ++;
}
return VA_INVALID_SURFACE;
}

PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithNewFormat(PDDI_MEDIA_SURFACE surface, DDI_MEDIA_FORMAT expectedFormat)
{
PDDI_MEDIA_SURFACE_HEAP_ELEMENT surfaceElement = (PDDI_MEDIA_SURFACE_HEAP_ELEMENT)surface->pMediaCtx->pSurfaceHeap->pHeapBase;
PDDI_MEDIA_CONTEXT mediaCtx = surface->pMediaCtx;

//check some conditions
if(expectedFormat == surface->format)
{
return surface;
}
//create new dst surface and copy the structure
PDDI_MEDIA_SURFACE dstSurface = (DDI_MEDIA_SURFACE *)MOS_AllocAndZeroMemory(sizeof(DDI_MEDIA_SURFACE));
if (nullptr == surfaceElement)
{
return nullptr;
}
MOS_SecureMemcpy(dstSurface,sizeof(DDI_MEDIA_SURFACE),surface,sizeof(DDI_MEDIA_SURFACE));
dstSurface->format = expectedFormat;
dstSurface->uiLockedBufID = VA_INVALID_ID;
dstSurface->uiLockedImageID = VA_INVALID_ID;
dstSurface->pSurfDesc = nullptr;
//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);
MOS_FreeMemory(dstSurface);
return nullptr;
}
//FreeSurface
DdiMediaUtil_FreeSurface(surface);
MOS_FreeMemory(surface);
//CreateNewSurface
DdiMediaUtil_CreateSurface(dstSurface,mediaCtx);
surfaceElement->pSurface = dstSurface;

DdiMediaUtil_UnLockMutex(&mediaCtx->SurfaceMutex);

return dstSurface;
}

DDI_MEDIA_BUFFER* DdiMedia_GetBufferFromVABufferID (PDDI_MEDIA_CONTEXT mediaCtx, VABufferID bufferID)
{
uint32_t i;
Expand Down
25 changes: 25 additions & 0 deletions media_driver/linux/common/ddi/media_libva_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,31 @@ 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
//!
//! \param [in] surface
//! Pointer to the old surface
//! \param [in] expectedFormat
//! VA surface ID
//!
//! \return DDI_MEDIA_SURFACE*
//! Pointer to new ddi media surface
//!
PDDI_MEDIA_SURFACE DdiMedia_ReplaceSurfaceWithNewFormat(PDDI_MEDIA_SURFACE surface, DDI_MEDIA_FORMAT expectedFormat);

//!
//! \brief Get VA surface ID from surface
//!
//! \param [in] surface
//! surface
//!
//! \return VASurfaceID
//! VA Surface ID
//!
VASurfaceID DdiMedia_GetVASurfaceIDFromSurface(PDDI_MEDIA_SURFACE surface);

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

0 comments on commit 94e0dd5

Please sign in to comment.