Exemplo n.º 1
0
/*****************************************************************************
 Prototype    : jpg_enc_exit
 Description  : free resources of this alg
 Input        : Ptr algHandle  
 Output       : None
 Return Value : static
 Calls        : 
 Called By    : 
 
  History        :
  1.Date         : 2012/2/1
    Author       : Sun
    Modification : Created function

*****************************************************************************/
static Int32 jpg_encode_exit(Ptr algHandle)
{
	JpgEncodeHandle hJpgEnc = (JpgEncodeHandle)algHandle;

	if(!hJpgEnc || !hJpgEnc->algHandle)
		return E_INVAL;

	IMGENC1_delete(hJpgEnc->algHandle);
	free(hJpgEnc);

	return E_NO;
}
Exemplo n.º 2
0
/*****************************************************************************
 Prototype    : jpg_enc_init
 Description  : init alg module
 Input        : Ptr *init  
                Ptr *dyn   
 Output       : None
 Return Value : static
 Calls        : 
 Called By    : 
 
  History        :
  1.Date         : 2012/2/1
    Author       : Sun
    Modification : Created function

*****************************************************************************/
static Ptr jpg_encode_init(const Ptr init, const Ptr dyn)
{
	JpgEncInitParams *initParams = (JpgEncInitParams *)init;

	if(!init || initParams->size != sizeof(JpgEncInitParams))
		return NULL;

	/* Init params */
	IIMGENC1_Params imgEncParams;
	IMGENC1_Handle 	handle = NULL;
	JpgEncodeHandle    hJpgEnc = calloc(1, sizeof(JpgEncObj));
	if(!hJpgEnc)
		goto exit;
	
	imgEncParams.maxHeight = initParams->maxHeight;
	imgEncParams.maxWidth = initParams->maxWidth;
	imgEncParams.maxScans = 0;
	imgEncParams.dataEndianness = XDM_BYTE;
	imgEncParams.forceChromaFormat = XDM_YUV_420P;
	imgEncParams.size = sizeof(imgEncParams);

	/* Create  alg instance */
	handle = IMGENC1_create(g_hEngine, 
							JPGENC_NAME,
                       		&imgEncParams);
	if(!handle) {
        ERR("Failed to Create Instance...");
        goto exit;
    }

	/* Set fields of the handle */
	hJpgEnc->algHandle = handle;
	hJpgEnc->status.size = sizeof(IJPEGENC_Status);

	/* Set dynamic params */
	int err = jpg_enc_set_dyn_params(hJpgEnc, (JpgEncDynParams *)dyn);
	if(err) {
		ERR("Failed to set dyn params.");
		goto exit;
	}

	return hJpgEnc;
    
exit:

	if(handle)
		IMGENC1_delete(handle);

	if(hJpgEnc)
		free(hJpgEnc);
	return NULL;
}
Exemplo n.º 3
0
int ALG_jpgEncDelete(void *hndl)
{
  ALG_JpgEncObj *pObj=(ALG_JpgEncObj *)hndl;

  if(pObj==NULL)
    return OSA_EFAIL;

  if(pObj->hEncode)
    IMGENC1_delete(pObj->hEncode);

  OSA_memFree(pObj);

  return OSA_SOK;
}
/*
 *  ======== smain ========
 */
Int smain(Int argc, String argv[])
{
    Engine_Handle ce = NULL;
    IMGDEC1_Handle dec = NULL;
    IMGENC1_Handle enc = NULL;
    FILE *in = NULL;
    FILE *out = NULL;
    String inFile, outFile;
    Memory_AllocParams allocParams;

    if (argc <= 1) {
        inFile = "./in.dat";
        outFile = "./out.dat";
        createInFileIfMissing(inFile);
    }
    else if (argc >= 3) {
        progName = argv[0];
        inFile = argv[1];
        outFile = argv[2];
    }
    else {
        fprintf(stderr, usage, argv[0]);
        exit(1);
    }

    if ((argc == 4) && (argv[3][0] == '1')) {
        appPause = 1;
    }


    GT_0trace(curMask, GT_1CLASS, "App-> Application started.\n");

    /* allocate buffers */
    allocParams.type = Memory_CONTIGPOOL;
    allocParams.flags = Memory_NONCACHED;
    allocParams.align = BUFALIGN;
    allocParams.seg = 0;

    inBuf = (XDAS_Int8 *)Memory_alloc(IFRAMESIZE, &allocParams);
    encodedBuf = (XDAS_Int8 *)Memory_alloc(EFRAMESIZE, &allocParams);
    outBuf = (XDAS_Int8 *)Memory_alloc(OFRAMESIZE, &allocParams);
    versionBuf = (XDAS_Int8 *)Memory_alloc(MAXVERSIONSIZE, &allocParams);

    if ((inBuf == NULL) || (encodedBuf == NULL) || (outBuf == NULL) ||
        (versionBuf == NULL)) {

        goto end;
    }

    /* open file streams for input and output */
    if ((in = fopen(inFile, "rb")) == NULL) {
        printf("App-> ERROR: can't read file %s\n", inFile);
        goto end;
    }
    if ((out = fopen(outFile, "wb")) == NULL) {
        printf("App-> ERROR: can't write to file %s\n", outFile);
        goto end;
    }

    /* reset, load, and start DSP Engine */
    if ((ce = Engine_open(engineName, NULL, NULL)) == NULL) {
        fprintf(stderr, "%s: error: can't open engine %s\n",
            progName, engineName);
        goto end;
    }

    /* allocate and initialize video decoder on the engine */
    dec = IMGDEC1_create(ce, decoderName, NULL);
    if (dec == NULL) {
        printf( "App-> ERROR: can't open codec %s\n", decoderName);
        goto end;
    }

    /* allocate and initialize video encoder on the engine */
    enc = IMGENC1_create(ce, encoderName, NULL);
    if (enc == NULL) {
        fprintf(stderr, "%s: error: can't open codec %s\n",
            progName, encoderName);
        goto end;
    }

#ifdef USE_POWER_MANAGEMENT
    /* open local power manager */
    if (Global_usePowerManagement) {
       LPM_Status  lpmStat = LPM_SOK;
       lpmStat = LPM_open("/dev/lpm0", &lpmHandle);

       if (lpmStat != LPM_SOK) {
            fprintf(stderr, "%s: error: LPM_open() failed\n", progName);
            goto end;
       }
    }
#endif

    /* use engine to encode, then decode the data */
    encode_decode(enc, dec, in, out);

end:
#ifdef USE_POWER_MANAGEMENT
    /* close local power manager */
    if (lpmHandle != NULL) {
       LPM_close(lpmHandle);
    }
#endif

    /* teardown the codecs */
    if (enc) {
        IMGENC1_delete(enc);
    }
    if (dec) {
        IMGDEC1_delete(dec);
    }

    /* close the engine */
    if (ce) {
        Engine_close(ce);
    }

    /* close the files */
    if (in) {
        fclose(in);
    }
    if (out) {
        fclose(out);
    }

    /* free buffers */
    if (inBuf) {
        Memory_free(inBuf, IFRAMESIZE, &allocParams);
    }
    if (encodedBuf) {
        Memory_free(encodedBuf, EFRAMESIZE, &allocParams);
    }
    if (outBuf) {
        Memory_free(outBuf, OFRAMESIZE, &allocParams);
    }
    if (versionBuf) {
        Memory_free(versionBuf, MAXVERSIONSIZE, &allocParams);
    }

    GT_0trace(curMask, GT_1CLASS, "app done.\n");
    return (0);
}