/*
* Copyright 2006
* Texas Instruments Incorporated
*
* All rights reserved. Property of Texas Instruments Incorporated
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
*/
/*
* ======== videnc_copy.c ========
* Video Encoder "copy" algorithm.
*
* This file contains an implementation of the IALG interface
* required by XDAS.
*/
#include <xdc/std.h>
#include <string.h>
#include <ti/xdais/dm/ividenc.h>
#include <ti/sdo/ce/trace/gt.h>
#include "videnc_copy_ti.h"
#include "videnc_copy_ti_priv.h"
/* buffer definitions */
#define MININBUFS 1
#define MINOUTBUFS 1
#define MININBUFSIZE 1
#define MINOUTBUFSIZE 1
extern IALG_Fxns VIDENCCOPY_TI_IALG;
#define IALGFXNS \
&VIDENCCOPY_TI_IALG, /* module ID */ \
VIDENCCOPY_TI_activate, /* activate */ \
VIDENCCOPY_TI_alloc, /* alloc */ \
NULL, /* control (NULL => no control ops) */ \
VIDENCCOPY_TI_deactivate, /* deactivate */ \
VIDENCCOPY_TI_free, /* free */ \
VIDENCCOPY_TI_initObj, /* init */ \
NULL, /* moved */ \
NULL /* numAlloc (NULL => IALG_MAXMEMRECS) */
/*
* ======== VIDENCCOPY_TI_IVIDENC ========
* This structure defines TI's implementation of the IVIDENC interface
* for the VIDENCCOPY_TI module.
*/
IVIDENC_Fxns VIDENCCOPY_TI_VIDENCCOPY = { /* module_vendor_interface */
{IALGFXNS},
VIDENCCOPY_TI_process,
VIDENCCOPY_TI_control,
};
/*
* ======== VIDENC_TI_IALG ========
* This structure defines TI's implementation of the IALG interface
* for the VIDENCCOPY_TI module.
*/
#ifdef _TI_
/* satisfy xDAIS symbol requirement without any overhead */
asm("_VIDENCCOPY_TI_IALG .set _VIDENCCOPY_TI_VIDENCCOPY");
#else
/*
* We duplicate the structure here to allow this code to be compiled and
* run non-DSP platforms at the expense of unnecessary data space
* consumed by the definition below.
*/
IALG_Fxns VIDENCCOPY_TI_IALG = { /* module_vendor_interface */
IALGFXNS
};
#endif
/* tracing information */
#define GTNAME "codecs.videnc_copy"
static GT_Mask curTrace = {NULL,NULL};
#ifdef USE_ACPY3
/* Implementation of IDMA3 interface functions & IDMA3_Fxns vtable */
#include <ti/bios/include/std.h>
#include <ti/xdais/idma3.h>
#include <ti/sdo/fc/acpy3/acpy3.h>
#define NUM_LOGICAL_CH 1
/*
* ======== VIDENCCOPY_TI_dmaChangeChannels ========
* Update instance object with new logical channel.
*/
Void VIDENCCOPY_TI_dmaChangeChannels(IALG_Handle handle,
IDMA3_ChannelRec dmaTab[])
{
VIDENCCOPY_TI_Obj *videncObj = (Void *)handle;
GT_2trace(curTrace, GT_ENTER,
"VIDENCCOPY_TI_dmaChangeChannels(0x%x, 0x%x)\n", handle, dmaTab);
videncObj->dmaHandle1D1D8B = dmaTab[0].handle;
}
/*
* ======== VIDENCCOPY_TI_dmaGetChannelCnt ========
* Return max number of logical channels requested.
*/
Uns VIDENCCOPY_TI_dmaGetChannelCnt(Void)
{
GT_0trace(curTrace, GT_ENTER, "VIDENCCOPY_TI_dmaGetChannelCnt()\n");
return (NUM_LOGICAL_CH);
}
/*
* ======== VIDENCCOPY_TI_dmaGetChannels ========
* Declare DMA resource requirement/holdings.
*/
Uns VIDENCCOPY_TI_dmaGetChannels(IALG_Handle handle, IDMA3_ChannelRec dmaTab[])
{
VIDENCCOPY_TI_Obj *videncObj = (Void *)handle;
int i;
GT_2trace(curTrace, GT_ENTER,
"VIDENCCOPY_TI_dmaGetChannels(0x%x, 0x%x)\n", handle, dmaTab);
/* Initial values on logical channels */
dmaTab[0].handle = videncObj->dmaHandle1D1D8B;
dmaTab[0].numTransfers = 1;
dmaTab[0].numWaits = 1;
/*
* Request logical DMA channels for use with ACPY3
* AND with environment size obtained from ACPY3 implementation
* AND with low priority.
*/
for (i=0; i<NUM_LOGICAL_CH; i++) {
dmaTab[i].priority = IDMA3_PRIORITY_LOW;
dmaTab[i].persistent = FALSE;
dmaTab[i].protocol = &ACPY3_PROTOCOL;
}
return (NUM_LOGICAL_CH);
}
/*
* ======== VIDENCCOPY_TI_dmaInit ========
* Initialize instance object with granted logical channel.
*/
Int VIDENCCOPY_TI_dmaInit(IALG_Handle handle, IDMA3_ChannelRec dmaTab[])
{
VIDENCCOPY_TI_Obj *videncObj = (Void *)handle;
GT_2trace(curTrace, GT_ENTER, "VIDENCCOPY_TI_dmaInit(0x%x, 0x%x)\n",
handle, dmaTab);
videncObj->dmaHandle1D1D8B = dmaTab[0].handle;
return (IALG_EOK);
}
/*
* ======== VIDENCCOPY_TI_IDMA3 ========
* This structure defines TI's implementation of the IDMA3 interface
* for the VIDENCCOPY_TI module.
*/
IDMA3_Fxns VIDENCCOPY_TI_IDMA3 = { /* module_vendor_interface */
&VIDENCCOPY_TI_IALG, /* IALG functions */
VIDENCCOPY_TI_dmaChangeChannels, /* ChangeChannels */
VIDENCCOPY_TI_dmaGetChannelCnt, /* GetChannelCnt */
VIDENCCOPY_TI_dmaGetChannels, /* GetChannels */
VIDENCCOPY_TI_dmaInit /* initialize logical channels */
};
#endif
/*
* ======== VIDENCCOPY_TI_activate ========
*/
Void VIDENCCOPY_TI_activate(IALG_Handle handle)
{
GT_1trace(curTrace, GT_ENTER, "VIDENCCOPY_TI_activate(0x%x)\n", handle);
}
/*
* ======== VIDENCCOPY_TI_deactivate ========
*/
Void VIDENCCOPY_TI_deactivate(IALG_Handle handle)
{
GT_1trace(curTrace, GT_ENTER, "VIDENCCOPY_TI_deactivate(0x%x)\n", handle);
}
/*
* ======== VIDENCCOPY_TI_alloc ========
*/
Int VIDENCCOPY_TI_alloc(const IALG_Params *algParams,
IALG_Fxns **pf, IALG_MemRec memTab[])
{
if (curTrace.modName == NULL) { /* initialize GT (tracing) */
GT_create(&curTrace, GTNAME);
}
GT_3trace(curTrace, GT_ENTER, "VIDENCCOPY_TI_alloc(0x%x, 0x%x, 0x%x)\n",
algParams, pf, memTab);
/* Request memory for my object */
memTab[0].size = sizeof(VIDENCCOPY_TI_Obj);
memTab[0].alignment = 0;
memTab[0].space = IALG_EXTERNAL;
memTab[0].attrs = IALG_PERSIST;
return (1);
}
/*
* ======== VIDENCCOPY_TI_free ========
*/
Int VIDENCCOPY_TI_free(IALG_Handle handle, IALG_MemRec memTab[])
{
GT_2trace(curTrace, GT_ENTER, "VIDENCCOPY_TI_free(0x%lx, 0x%lx)\n",
handle, memTab);
VIDENCCOPY_TI_alloc(NULL, NULL, memTab);
return (1);
}
/*
* ======== VIDENCCOPY_TI_initObj ========
*/
Int VIDENCCOPY_TI_initObj(IALG_Handle handle,
const IALG_MemRec memTab[], IALG_Handle p,
const IALG_Params *algParams)
{
GT_4trace(curTrace, GT_ENTER,
"VIDENCCOPY_TI_initObj(0x%x, 0x%x, 0x%x, 0x%x)\n", handle, memTab,
p, algParams);
return (IALG_EOK);
}
/*
* ======== VIDENCCOPY_TI_process ========
*/
XDAS_Int32 VIDENCCOPY_TI_process(IVIDENC_Handle h, XDM_BufDesc *inBufs,
XDM_BufDesc *outBufs, IVIDENC_InArgs *inArgs, IVIDENC_OutArgs *outArgs)
{
XDAS_Int32 curBuf;
XDAS_UInt32 minSamples;
#ifdef USE_ACPY3
const Uint32 maxTransferChunkSize = 0xffff;
Uint32 thisTransferChunkSize = 0x0;
Uint32 remainingTransferChunkSize;
Uint32 thisTransferSrcAddr, thisTransferDstAddr;
ACPY3_Params params;
VIDENCCOPY_TI_Obj *videncObj = (VIDENCCOPY_TI_Obj *)h;
#endif
GT_5trace(curTrace, GT_ENTER, "VIDENCCOPY_TI_process(0x%x, 0x%x, 0x%x, "
"0x%x, 0x%x)\n", h, inBufs, outBufs, inArgs, outArgs);
/* validate arguments - this codec only supports "base" xDM. */
if ((inArgs->size != sizeof(*inArgs)) ||
(outArgs->size != sizeof(*outArgs))) {
GT_2trace(curTrace, GT_ENTER,
"VIDENCCOPY_TI_process, unsupported size "
"(0x%x, 0x%x)\n", inArgs->size, outArgs->size);
return (IVIDENC_EFAIL);
}
#ifdef USE_ACPY3
/*
* Activate Channel scratch DMA channels.
*/
ACPY3_activate(videncObj->dmaHandle1D1D8B);
#endif
/* outArgs->bytesGenerated reports the total number of bytes generated */
outArgs->bytes