diff --git a/libdce.c b/libdce.c
index fc507c62e3cc51772ffbbc2f574bc7924f320bb9..b781972c2b2b475a7bc310d85574f0ff9aa0564e 100644 (file)
--- a/libdce.c
+++ b/libdce.c
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <pthread.h>
#include <errno.h>
-
-#include <xdc/std.h>
-
-#if defined(BUILDOS_LINUX)
-#include <xf86drm.h>
-#include <omap_drm.h>
-#include <omap_drmif.h>
-#endif /* BUILDOS_LINUX */
+#include <fcntl.h> /* For O_* constants */
+#include <sys/stat.h> /* For mode constants */
+#include <semaphore.h>
/* IPC Headers */
#include <MmRpc.h>
#include "memplugin.h"
-#if defined(BUILDOS_LINUX)
-#ifdef HAVE_X11
-// Defined from configure.ac
-extern int dce_auth_x11(int *fd);
-#endif /* HAVE_X11 */
-#ifdef HAVE_WAYLAND // Defined from configure.ac
-extern int dce_auth_wayland(int *fd);
-#endif /* HAVE_WAYLAND */
-
-int fd = -1;
-struct omap_device *dev = 0;
-uint32_t dce_debug = 3;
-#endif /* BUILDOS_LINUX */
-
-
/********************* GLOBALS ***********************/
/* Hande used for Remote Communication */
-static MmRpc_Handle MmRpcHandle = NULL;
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-static int count = 0;
-
+MmRpc_Handle MmRpcHandle = NULL;
+sem_t *dce_semaphore = NULL;
+static int count = 0;
+int dce_debug = DCE_DEBUG_LEVEL;
/****************** INLINE FUNCTIONS ********************/
@@ -119,12 +98,21 @@ static inline void Fill_MmRpc_fxnCtx(MmRpc_FxnCtx *fxnCtx, int fxn_id, int num_p
fxnCtx->xltAry = xltAry;
}
-static inline void Fill_MmRpc_fxnCtx_Ptr_Params(MmRpc_Param *mmrpc_params, int size, void *addr, void *handle)
+static inline void Fill_MmRpc_fxnCtx_OffPtr_Params(MmRpc_Param *mmrpc_params, int size, void *base, int offset, size_t handle)
+{
+ mmrpc_params->type = MmRpc_ParamType_OffPtr;
+ mmrpc_params->param.offPtr.size = (size_t)size;
+ mmrpc_params->param.offPtr.base = (size_t)base;
+ mmrpc_params->param.offPtr.offset = (size_t)offset;
+ mmrpc_params->param.offPtr.handle = handle;
+}
+
+static inline void Fill_MmRpc_fxnCtx_Ptr_Params(MmRpc_Param *mmrpc_params, int size, void *addr, size_t handle)
{
mmrpc_params->type = MmRpc_ParamType_Ptr;
mmrpc_params->param.ptr.size = size;
mmrpc_params->param.ptr.addr = (size_t)addr;
- mmrpc_params->param.ptr.handle = (size_t)handle;
+ mmrpc_params->param.ptr.handle = handle;
}
static inline void Fill_MmRpc_fxnCtx_Scalar_Params(MmRpc_Param *mmrpc_params, int size, int data)
@@ -134,18 +122,19 @@ static inline void Fill_MmRpc_fxnCtx_Scalar_Params(MmRpc_Param *mmrpc_params, in
mmrpc_params->param.scalar.data = (size_t)data;
}
-static inline void Fill_MmRpc_fxnCtx_Xlt_Array(MmRpc_Xlt *mmrpc_xlt, int index, int32_t base, int32_t addr, void *handle)
+static inline void Fill_MmRpc_fxnCtx_Xlt_Array(MmRpc_Xlt *mmrpc_xlt, int index, int32_t base, int32_t addr, size_t handle)
{
/* index : index of params filled in FxnCtx */
/* offset : calculated from address of index */
mmrpc_xlt->index = index;
mmrpc_xlt->offset = MmRpc_OFFSET(base, addr);
- mmrpc_xlt->handle = (size_t)handle;
+ mmrpc_xlt->base = handle;
+ mmrpc_xlt->handle = handle;
}
/************************ FUNCTIONS **************************/
-/* Interface for QNX for parameter buffer allocation */
-/* These interfaces are implemented to maintain Backward Compatability */
+/* Interface for QNX for parameter buffer allocation */
+/* These interfaces are implemented to maintain Backward Compatability */
void *dce_alloc(int sz)
{
return (memplugin_alloc(sz, 0, TILER_1D_BUFFER));
memplugin_free(ptr, TILER_1D_BUFFER);
}
-/*************** Startup/Shutdown Functions ***********************/
-static int dce_init(void)
+/*=====================================================================================*/
+/** dce_ipc_init : Initialize MmRpc. This function is called within Engine_open().
+ *
+ * @ return : Error Status.
+ */
+static int dce_ipc_init(void)
{
- dce_error_status eError = DCE_EOK;
MmRpc_Params args;
+ dce_error_status eError = DCE_EOK;
- printf(" >> dce_init\n");
-
- pthread_mutex_lock(&mutex);
+ printf(" >> dce_ipc_init\n");
count++;
/* Check if already Initialized */
printf("open(/dev/" DCE_DEVICE_NAME ") -> 0x%x\n", (int)MmRpcHandle);
-#if defined(BUILDOS_LINUX)
- /* Open omapdrm device */
- int authenticated = 0;
-
-#ifdef HAVE_X11
- /*If X11 server is running*/
- if( !authenticated ) {
- int ret = dce_auth_x11(&fd);
- if( !ret ) {
- authenticated = 1;
- }
- }
-#endif
-#ifdef HAVE_WAYLAND
- /*If Wayland windowing is supported*/
- if( !authenticated ) {
- int ret = dce_auth_wayland(&fd);
- if( !ret ) {
- authenticated = 1;
- }
- }
-#endif
- if((fd == -1) && !authenticated ) {
- printf("no X11/wayland, fallback to opening DRM device directly\n");
- fd = drmOpen("omapdrm", "platform:omapdrm:00");
- }
- if( fd >= 0 ) {
- dev = omap_device_new(fd);
- } else {
- printf("Error opening omapdrm : drmOpen failed");
- goto EXIT;
- }
-#endif /* BUILDOS_LINUX */
-
-
EXIT:
- pthread_mutex_unlock(&mutex);
return (eError);
}
-static void dce_deinit(void)
+/*=====================================================================================*/
+/** dce_ipc_deinit : DeInitialize MmRpc. This function is called within
+ * Engine_close().
+ */
+static void dce_ipc_deinit()
{
- pthread_mutex_lock(&mutex);
-
count--;
if( count > 0 ) {
goto EXIT;
}
MmRpcHandle = NULL;
-#if defined(BUILDOS_LINUX)
- omap_device_del(dev);
- dev = NULL;
- close(fd);
- fd = -1;
-#endif /* BUILDOS_LINUX */
-
-
EXIT:
- pthread_mutex_unlock(&mutex);
return;
}
-/* Incase of X11 or Wayland the fd can be shared to libdce using this call */
-#if defined(BUILDOS_LINUX)
-void dce_set_fd(int dce_fd)
-{
- fd = dce_fd;
-}
-
-int dce_get_fd(void)
-{
- return (fd);
-}
-
-#endif /* BUILDOS_LINUX */
-
/*===============================================================*/
/** Engine_open : Open Codec Engine.
*
_ASSERT(name != '\0', DCE_EINVALID_INPUT);
- /* Initialize DCE and IPC. In case of Error Deinitialize them */
- _ASSERT_AND_EXECUTE(dce_init() == DCE_EOK, DCE_EIPC_CREATE_FAIL, dce_deinit());
+ if( dce_semaphore == NULL ) {
+ _ASSERT((dce_semaphore = sem_open("/dce_semaphore", O_CREAT, S_IRWXU | S_IRWXO | S_IRWXG, 1)) != SEM_FAILED, DCE_ESEMAPHORE_FAIL);
+ }
+ /* Lock dce_ipc_init() and Engine_open() IPU call to prevent hang*/
+ _ASSERT(sem_wait(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL);
+
+ /* Initialize IPC. In case of Error Deinitialize them */
+ _ASSERT_AND_EXECUTE(dce_ipc_init() == DCE_EOK, DCE_EIPC_CREATE_FAIL, dce_ipc_deinit());
printf(">> Engine_open Params::name = %s size = %d\n", name, strlen(name));
/* Allocate Shared memory for the engine_open rpc msg structure*/
/* Marshall function arguments into the send buffer */
Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_ENGINE_OPEN, 1, 0, NULL);
- Fill_MmRpc_fxnCtx_Ptr_Params(fxnCtx.params, sizeof(dce_engine_open), engine_open_msg, NULL);
+ Fill_MmRpc_fxnCtx_OffPtr_Params(fxnCtx.params, GetSz(engine_open_msg), (void *)P2H(engine_open_msg),
+ sizeof(MemHeader), memplugin_share(engine_open_msg));
/* Invoke the Remote function through MmRpc */
eError = MmRpc_call(MmRpcHandle, &fxnCtx, (int32_t *)(&engine_handle));
if( ec ) {
*ec = engine_open_msg->error_code;
}
+
EXIT:
+ /* Unlock dce_ipc_init() and Engine_open() IPU call */
+ _ASSERT(sem_post(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL);
+
memplugin_free(engine_open_msg, TILER_1D_BUFFER);
if( engine_attrs ) {
memplugin_free(engine_attrs, TILER_1D_BUFFER);
_ASSERT(engine != NULL, DCE_EINVALID_INPUT);
+ /* Lock dce_ipc_deinit() and Engine_close() IPU call */
+ _ASSERT(sem_wait(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL);
+
/* Marshall function arguments into the send buffer */
Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_ENGINE_CLOSE, 1, 0, NULL);
Fill_MmRpc_fxnCtx_Scalar_Params(fxnCtx.params, sizeof(Engine_Handle), (int32_t)engine);
_ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
EXIT:
- dce_deinit();
+ dce_ipc_deinit();
+
+ /* Unlock dce_ipc_deinit() and Engine_close() IPU call */
+ _ASSERT(sem_post(dce_semaphore) == DCE_EOK, DCE_ESEMAPHORE_FAIL);
+ sem_close(dce_semaphore);
+
return;
}
@@ -381,9 +334,10 @@ static void *create(Engine_Handle engine, String name, void *params, dce_codec_t
Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_CREATE, 4, 0, NULL);
Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[0]), sizeof(int32_t), codec_id);
Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[1]), sizeof(Engine_Handle), (int32_t)engine);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[2]), (P2H(codec_name))->size, codec_name, NULL);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[3]), (P2H(params))->size, params, NULL);
-
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[2]), GetSz(codec_name), P2H(codec_name),
+ sizeof(MemHeader), memplugin_share(codec_name));
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[3]), GetSz(params), P2H(params),
+ sizeof(MemHeader), memplugin_share(params));
/* Invoke the Remote function through MmRpc */
eError = MmRpc_call(MmRpcHandle, &fxnCtx, (int32_t *)(&codec_handle));
@@ -425,8 +379,10 @@ static XDAS_Int32 control(void *codec, int id, void *dynParams, void *status, dc
Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[0]), sizeof(int32_t), codec_id);
Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[1]), sizeof(int32_t), (int32_t)codec);
Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[2]), sizeof(int32_t), (int32_t)id);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[3]), (P2H(dynParams))->size, dynParams, NULL);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[4]), (P2H(status))->size, status, NULL);
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[3]), GetSz(dynParams), P2H(dynParams),
+ sizeof(MemHeader), memplugin_share(dynParams));
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[4]), GetSz(status), P2H(status),
+ sizeof(MemHeader), memplugin_share(status));
/* Invoke the Remote function through MmRpc */
eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
@@ -478,11 +434,13 @@ static XDAS_Int32 get_version(void *codec, void *dynParams, void *status, dce_co
Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_GET_VERSION, 4, 1, &xltAry);
Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[0]), sizeof(int32_t), codec_id);
Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[1]), sizeof(int32_t), (int32_t)codec);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[2]), (P2H(dynParams))->size, dynParams, NULL);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[3]), (P2H(status))->size, status, NULL);
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[2]), GetSz(dynParams), P2H(dynParams),
+ sizeof(MemHeader), memplugin_share(dynParams));
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[3]), GetSz(status), P2H(status),
+ sizeof(MemHeader), memplugin_share(status));
/* Address Translation needed for buffer for version Info */
- Fill_MmRpc_fxnCtx_Xlt_Array(fxnCtx.xltAry, 3, (int32_t)status, (int32_t)version_buf, NULL);
+ Fill_MmRpc_fxnCtx_Xlt_Array(fxnCtx.xltAry, 3, (int32_t)status, (int32_t)version_buf, memplugin_share(*version_buf));
/* Invoke the Remote function through MmRpc */
eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
OUTARGS_INDEX
} process_call_params;
+#define LUMA_BUF 0
+#define CHROMA_BUF 1
/*===============================================================*/
/** process : Encode/Decode process.
*
{
MmRpc_FxnCtx fxnCtx;
MmRpc_Xlt xltAry[MAX_TOTAl_BUF];
- int fxnRet, count, total_count, numInBufs = 0, numOutBufs = 0, sz[OUTARGS_INDEX + 1] = { 0 };
+ int fxnRet, count, total_count, numInBufs = 0, numOutBufs = 0;
dce_error_status eError = DCE_EOK;
+ void * *data_buf = NULL;
_ASSERT(codec != NULL, DCE_EINVALID_INPUT);
_ASSERT(inBufs != NULL, DCE_EINVALID_INPUT);
if( codec_id == OMAP_DCE_VIDDEC3 ) {
numInBufs = ((XDM2_BufDesc *)inBufs)->numBufs;
numOutBufs = ((XDM2_BufDesc *)outBufs)->numBufs;
- sz[INBUFS_INDEX] = sizeof(XDM2_BufDesc);
- sz[OUTBUFS_INDEX] = sizeof(XDM2_BufDesc);
- sz[INARGS_INDEX] = sizeof(VIDDEC3_InArgs);
- sz[OUTARGS_INDEX] = sizeof(VIDDEC3_OutArgs);
} else if( codec_id == OMAP_DCE_VIDENC2 ) {
numInBufs = ((IVIDEO2_BufDesc *)inBufs)->numPlanes;
numOutBufs = ((XDM2_BufDesc *)outBufs)->numBufs;
- sz[INBUFS_INDEX] = sizeof(IVIDEO2_BufDesc);
- sz[OUTBUFS_INDEX] = sizeof(XDM2_BufDesc);
- sz[INARGS_INDEX] = sizeof(VIDENC2_InArgs);
- sz[OUTARGS_INDEX] = sizeof(VIDENC2_OutArgs);
}
/* marshall function arguments into the send buffer */
Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_PROCESS, 6, numInBufs + numOutBufs, xltAry);
Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[CODEC_ID_INDEX]), sizeof(int32_t), codec_id);
Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[CODEC_HANDLE_INDEX]), sizeof(int32_t), (int32_t)codec);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[INBUFS_INDEX]), sz[INBUFS_INDEX], inBufs, NULL);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[OUTBUFS_INDEX]), sz[OUTBUFS_INDEX], outBufs, NULL);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[INARGS_INDEX]), sz[INARGS_INDEX], inArgs, NULL);
- Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[OUTARGS_INDEX]), sz[OUTARGS_INDEX], outArgs, NULL);
+
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[INBUFS_INDEX]), GetSz(inBufs), P2H(inBufs),
+ sizeof(MemHeader), memplugin_share(inBufs));
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[OUTBUFS_INDEX]), GetSz(outBufs), P2H(outBufs),
+ sizeof(MemHeader), memplugin_share(outBufs));
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[INARGS_INDEX]), GetSz(inArgs), P2H(inArgs),
+ sizeof(MemHeader), memplugin_share(inArgs));
+ Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[OUTARGS_INDEX]), GetSz(outArgs), P2H(outArgs),
+ sizeof(MemHeader), memplugin_share(outArgs));
/* InBufs, OutBufs, InArgs, OutArgs buffer need translation but since they have been */
/* individually mentioned as fxnCtx Params, they need not be mentioned below again */
/* Input and Output Buffers have to be mentioned for translation */
for( count = 0, total_count = 0; count < numInBufs; count++, total_count++ ) {
if( codec_id == OMAP_DCE_VIDDEC3 ) {
- Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)inBufs, (int32_t)&(((XDM2_BufDesc *)inBufs)->descs[count].buf), NULL);
+ data_buf = (void * *)(&(((XDM2_BufDesc *)inBufs)->descs[count].buf));
+ Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)inBufs,
+ (int32_t)data_buf, (size_t)*data_buf);
} else if( codec_id == OMAP_DCE_VIDENC2 ) {
- Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)inBufs, (int32_t)&(((IVIDEO2_BufDesc *)inBufs)->planeDesc[count].buf), NULL);
+ data_buf = (void * *)(&(((IVIDEO2_BufDesc *)inBufs)->planeDesc[count].buf));
+ Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)inBufs,
+ (int32_t)data_buf, (size_t)*data_buf);
}
}
+ /* Output Buffers */
for( count = 0; count < numOutBufs; count++, total_count++ ) {
- Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), OUTBUFS_INDEX, (int32_t)outBufs, (int32_t)&(((XDM2_BufDesc *)outBufs)->descs[count].buf), NULL);
+ if(((XDM2_BufDesc *)outBufs)->descs[LUMA_BUF].buf != ((XDM2_BufDesc *)outBufs)->descs[CHROMA_BUF].buf ) {
+ /* Either Encode usecase or MultiPlanar Buffers for Decode usecase */
+ data_buf = (void * *)(&(((XDM2_BufDesc *)outBufs)->descs[count].buf));
+ Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), OUTBUFS_INDEX, (int32_t)outBufs,
+ (int32_t)data_buf, (size_t)*data_buf);
+ }
+#if defined(BUILDOS_LINUX)
+ else {
+ /* SinglePlanar Buffers for Decode usecase*/
+ data_buf = (void * *)(&(((XDM2_BufDesc *)outBufs)->descs[count].buf));
+ Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), OUTBUFS_INDEX, (int32_t)outBufs,
+ (int32_t)data_buf, (size_t)*data_buf);
+ if( count == CHROMA_BUF ) {
+ if(((XDM2_BufDesc *)outBufs)->descs[count].memType == XDM_MEMTYPE_RAW ||
+ ((XDM2_BufDesc *)outBufs)->descs[count].memType == XDM_MEMTYPE_TILEDPAGE ) {
+ *data_buf += ((XDM2_BufDesc *)outBufs)->descs[LUMA_BUF].bufSize.bytes;
+ } else {
+ *data_buf += ((XDM2_BufDesc *)outBufs)->descs[LUMA_BUF].bufSize.tileMem.width *
+ ((XDM2_BufDesc *)outBufs)->descs[LUMA_BUF].bufSize.tileMem.height;
+ }
+ }
+ }
+#endif
}
/* Invoke the Remote function through MmRpc */