Beispiel #1
0
/*****************************************************************************
 Prototype    : jpg_enc_process
 Description  : Run alg for jpeg encode
 Input        : Ptr algHandle   
                AlgBuf *inBuf   
                Ptr inArgsPtr   
                AlgBuf *outBuf  
                Ptr outArgsPtr  
 Output       : None
 Return Value : static
 Calls        : 
 Called By    : 
 
  History        :
  1.Date         : 2012/2/1
    Author       : Sun
    Modification : Created function

*****************************************************************************/
static Int32 jpg_encode_process(Ptr algHandle, AlgBuf *inBuf, Ptr inArgsPtr, AlgBuf *outBuf, Ptr outArgsPtr)
{
	JpgEncodeHandle hJpgEnc = (JpgEncodeHandle)algHandle;
	
	if(!algHandle || !hJpgEnc->algHandle || !inBuf || !outBuf || !inArgsPtr || !outArgsPtr)
		return E_INVAL;

	JpgEncInArgs 	*inArgs = (JpgEncInArgs *)inArgsPtr;
	JpgEncOutArgs	*outArgs =(JpgEncOutArgs *)outArgsPtr;
	
	if(inArgs->size != sizeof(JpgEncInArgs) || outArgs->size != sizeof(JpgEncOutArgs)) {
		ERR("Invaild in/out args size.");
		return E_INVAL;
	}

	/* Setup input and output args */
	IIMGENC1_InArgs		inEncArgs;
	IIMGENC1_OutArgs 	outEncArgs;

	inEncArgs.size = sizeof(IIMGENC1_InArgs);
	outEncArgs.size = sizeof(IIMGENC1_OutArgs);
	outEncArgs.bytesGenerated = 0;
	outEncArgs.currentAU = 0;
	outEncArgs.extendedError = 0;

	/* Setup buffer descriptors */
	Int32 i, offset = 0;
	
	for(i = 0; i < hJpgEnc->inBufDesc.numBufs; i++) {
		hJpgEnc->inBufDesc.descs[i].buf = (XDAS_Int8 *)(inBuf->buf + offset);
		offset +=  hJpgEnc->status.bufInfo.minInBufSize[i];
	}

	hJpgEnc->outBufDesc.descs[0].buf = (XDAS_Int8 *)(outBuf->buf);

	Int32 status;
	status = IMGENC1_process(hJpgEnc->algHandle, 
							&hJpgEnc->inBufDesc, 
							&hJpgEnc->outBufDesc,
							&inEncArgs, &outEncArgs);

	if(status != IIMGENC1_EOK) {
		ERR("process error: %d", (int)status);
		return E_IO;
	}

	/* Fill out args */
	if(inArgs->appendData) {
		/* Append data to the end of jpeg image */
		outArgs->bytesGenerated = jpg_append_data(outBuf, outEncArgs.bytesGenerated, inArgs);
	} else {
		outArgs->bytesGenerated = outEncArgs.bytesGenerated;
	}

	return E_NO;
	
}
/*
 *  ======== encode_decode ========
 */
static Void encode_decode(IMGENC1_Handle enc, IMGDEC1_Handle dec, FILE *in,
    FILE *out)
{
    Int                         n;
    Int32                       status;

    IMGDEC1_InArgs              decInArgs;
    IMGDEC1_OutArgs             decOutArgs;
    IMGDEC1_DynamicParams       decDynParams;
    IMGDEC1_Status              decStatus;

    IMGENC1_InArgs              encInArgs;
    IMGENC1_OutArgs             encOutArgs;
    IMGENC1_DynamicParams       encDynParams;
    IMGENC1_Status              encStatus;

    XDM1_BufDesc                inBufDesc;
    XDM1_BufDesc                encodedBufDesc;
    XDM1_BufDesc                outBufDesc;

    /* initialize the buffer descriptors */
    inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1;
    inBufDesc.descs[0].bufSize = encodedBufDesc.descs[0].bufSize =
        outBufDesc.descs[0].bufSize = NSAMPLES;

    inBufDesc.descs[0].buf      = inBuf;
    encodedBufDesc.descs[0].buf = encodedBuf;
    outBufDesc.descs[0].buf     = outBuf;

    /* initialize all "sized" fields */
    encInArgs.size    = sizeof(encInArgs);
    decInArgs.size    = sizeof(decInArgs);
    encOutArgs.size   = sizeof(encOutArgs);
    decOutArgs.size   = sizeof(decOutArgs);
    encDynParams.size = sizeof(encDynParams);
    decDynParams.size = sizeof(decDynParams);
    encStatus.size    = sizeof(encStatus);
    decStatus.size    = sizeof(decStatus);

    /*
     * Note that we use versionBuf in both the encoder and decoder.  In this
     * application, this is okay, as there is always only one user of
     * the buffer.  Not all applications can make this assumption.
     */
    encStatus.data.buf     = decStatus.data.buf     = versionBuf;
    encStatus.data.bufSize = decStatus.data.bufSize = MAXVERSIONSIZE;

    /* if the codecs support it, dump their versions */
    status = IMGDEC1_control(dec, XDM_GETVERSION, &decDynParams, &decStatus);
    GT_1trace(curMask, GT_1CLASS, "Decoder version:  %s\n",
        (status == IMGDEC1_EOK ? ((char *)decStatus.data.buf) : "[unknown]"));

    status = IMGENC1_control(enc, XDM_GETVERSION, &encDynParams, &encStatus);
    GT_1trace(curMask, GT_1CLASS, "Encoder version:  %s\n",
        (status == IMGENC1_EOK ? ((char *)encStatus.data.buf) : "[unknown]"));

    /*
     * This app expects the encoder to accept 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status = IMGENC1_control(enc, XDM_GETBUFINFO, &encDynParams, &encStatus);
    if (status != IMGENC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "encode control status = 0x%x\n", status);
        return;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if ((inBufDesc.numBufs < encStatus.bufInfo.minNumInBufs) ||
        (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) ||
        (encodedBufDesc.numBufs < encStatus.bufInfo.minNumOutBufs) ||
        (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  encoder codec feature conflict\n");
        return;
    }

    status = IMGDEC1_control(dec, XDM_GETBUFINFO, &decDynParams, &decStatus);
    if (status != IMGDEC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "decode control status = 0x%x\n", status);
        return;
    }

    /* Validate this decoder codec will meet our buffer requirements */
    if ((encodedBufDesc.numBufs < decStatus.bufInfo.minNumInBufs) ||
        (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) ||
        (outBufDesc.numBufs < decStatus.bufInfo.minNumOutBufs) ||
        (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "App-> ERROR: decoder does not meet buffer requirements.\n");
        return;
    }

    /*
     * Read complete frames from in, encode, decode, and write to out.
     */
    for (n = 0; fread(inBuf, IFRAMESIZE, 1, in) == 1; n++) {

        if (appPause) {
            printf("About to start frame %d. Press Enter to continue...\n", n);
            appPause = ('c' == getchar() ? 0 : 1);
        }

        /* Deal with cache issues, if necessary */
#ifdef CACHE_ENABLED
#ifdef xdc_target__isaCompatible_64P
        /*
         *  fread() on this processor is implemented using CCS's stdio, which
         *  is known to write into the cache, not physical memory.  To meet
         *  xDAIS DMA Rule 7, we must writeback the cache into physical
         *  memory.  Also, per DMA Rule 7, we must invalidate the buffer's
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(inBuf, IFRAMESIZE);
#else
#error Unvalidated config - add appropriate fread-related cache maintenance
#endif
        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(encodedBuf, EFRAMESIZE);
#endif

        GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", n);

        /* encode the frame */
        status = IMGENC1_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
            &encOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Encoder frame %d process returned - 0x%x)\n",
            n, status);

#ifdef CACHE_ENABLED
        /* Writeback this outBuf from the previous call.  Also, as encodedBuf
         * is an inBuf to the next process call, we must invalidate it also, to
         * clean buffer lines.
         */
        Memory_cacheWbInv(encodedBuf, EFRAMESIZE);

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(outBuf, OFRAMESIZE);
#endif

        if (status != IMGENC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Encoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, encOutArgs.extendedError);
            break;
        }

        /* decode the frame */
        decInArgs.numBytes = encOutArgs.bytesGenerated;
        status = IMGDEC1_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs,
           &decOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Decoder frame %d process returned - 0x%x)\n",
            n, status);

        if (status != IMGDEC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Decoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, decOutArgs.extendedError);
            break;
        }

#ifdef CACHE_ENABLED
        /* Writeback the outBuf. */
        Memory_cacheWb(outBuf, OFRAMESIZE);
#endif
        /* write to file */
        fwrite(outBuf, OFRAMESIZE, 1, out);

#ifdef USE_POWER_MANAGEMENT
        if (Global_usePowerManagement) {
            if (appPause) {
                printf("About to hibernate. Press Enter to continue...\n");
                appPause = ('c' == getchar() ? 0 : 1);
            }

            LPM_Status  lpmStat = LPM_SOK;
            GT_0trace(curMask, GT_2CLASS, "Turning DSP off\n");
            lpmStat = LPM_setPowerState(lpmHandle, LPM_HIBERNATE);
            if (lpmStat != LPM_SOK) {
                fprintf(stderr, "Error: LPM_setPowerState() failed\n");
                return;
            }

            if (appPause) {
                printf("DSP is off: Press Enter to continue...\n");
                appPause = ('c' == getchar() ? 0 : 1);
            }
            else {
                struct timeval tv;
                tv.tv_sec = 0;
                tv.tv_usec = 200000;  /* 200 msec */

                if (select(0, NULL, NULL, NULL, &tv) == -1) {
                    fprintf(stderr, "Error: select() failed\n");
                    return;
                }
            }

            GT_0trace(curMask, GT_1CLASS, "Turning DSP on\n");
            lpmStat = LPM_resume(lpmHandle);
            if (lpmStat != LPM_SOK) {
                fprintf(stderr, "Error: LPM_resume() failed\n");
                return;
            }

            if (appPause) {
                printf("DSP is on: Press Enter to continue...\n");
                appPause = ('c' == getchar() ? 0 : 1);
            }
        }
#endif
    }

    GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n);
}
Beispiel #3
0
//changed by zeng
int ALG_jpgEncRun(void *hndl, ALG_JpgEncRunPrm *prm, ALG_JpgEncRunStatus *runStatus, CallBackSetOSDPixel func)
{
  ALG_JpgEncObj  *pObj = (ALG_JpgEncObj*)hndl;
  XDM1_BufDesc    inBufDesc;
  XDM1_BufDesc    outBufDesc;
  XDAS_Int32      status;
  IMGENC1_InArgs  inArgs;
  IMGENC1_OutArgs outArgs;
  Uint32          bytesPerPixel, offset;

  runStatus->bytesGenerated = 0;

  if(pObj==NULL)
    return OSA_EFAIL;

  offset = pObj->createPrm.offsetH * pObj->createPrm.offsetV;

  if(prm->outDataMaxSize==0)
    prm->outDataMaxSize = pObj->createPrm.width*pObj->createPrm.height*2;

  prm->inStartY = OSA_floor(prm->inStartY, 2);
  prm->inStartX = OSA_floor(prm->inStartX, 2);

  inBufDesc.numBufs       = 1;

  bytesPerPixel = 1;
  if(pObj->createPrm.dataFormat==ALG_VID_DATA_FORMAT_YUV422) {
    bytesPerPixel = 2;
  }

  inBufDesc.descs[0].bufSize    = pObj->createPrm.offsetH*pObj->createPrm.offsetV*bytesPerPixel;
  inBufDesc.descs[0].buf        = (XDAS_Int8*)(prm->inAddr + prm->inStartY*pObj->createPrm.offsetH*bytesPerPixel + prm->inStartX*bytesPerPixel);
  inBufDesc.descs[0].accessMask = 0;

  if(pObj->createPrm.dataFormat==ALG_VID_DATA_FORMAT_YUV420) {
    inBufDesc.numBufs = 2;

    inBufDesc.descs[1].bufSize    = pObj->createPrm.offsetH*pObj->createPrm.offsetV/2;
    inBufDesc.descs[1].buf        = (XDAS_Int8*)(prm->inAddr + offset + prm->inStartY*pObj->createPrm.offsetH/2 + prm->inStartX);
    inBufDesc.descs[1].accessMask = 0;
  }

  if(prm->snapEnable) {
  	OSA_fileWriteVideoData(prm->snapFilename, (Uint8 *)inBufDesc.descs[0].buf, (Uint8 *)inBufDesc.descs[1].buf,
  		pObj->createPrm.width, pObj->createPrm.height, pObj->createPrm.offsetH);
  }

  outBufDesc.numBufs              = 1;
  outBufDesc.descs[0].buf         = (XDAS_Int8*)prm->outAddr;
  outBufDesc.descs[0].bufSize     = prm->outDataMaxSize;
  outBufDesc.descs[0].accessMask  = 0;

  inArgs.size         = sizeof(IMGENC1_InArgs);
  outArgs.size        = sizeof(IMGENC1_OutArgs);

  if( func != NULL ){
	  func(pObj->params.maxWidth, pObj->params.maxHeight, inBufDesc.descs[0].buf, inBufDesc.descs[1].buf);
  }
  status = IMGENC1_process(pObj->hEncode, &inBufDesc, &outBufDesc, &inArgs, &outArgs);

  if (status != IMGENC1_EOK)
    return OSA_EFAIL;

  runStatus->bytesGenerated = outArgs.bytesGenerated;

  return OSA_SOK;
}