/***************************************************************************** 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; }
void *ALG_jpgEncCreate(ALG_JpgEncCreate *create) { ALG_JpgEncObj *pObj; XDAS_Int32 status; if(gALG_hEngine==NULL) return NULL; pObj = OSA_memAlloc(sizeof(ALG_JpgEncObj)); if(pObj==NULL) return NULL; memset(pObj, 0, sizeof(*pObj)); strcpy(pObj->algName, ALG_VID_CODEC_JPEG_ENC_NAME); memcpy(&pObj->createPrm, create, sizeof(pObj->createPrm)); pObj->params.size = sizeof(IMGENC1_Params); pObj->params.maxHeight = create->height; pObj->params.maxWidth = pObj->createPrm.offsetH>create->width?pObj->createPrm.offsetH:create->width; pObj->params.maxScans = 1; pObj->params.dataEndianness = XDM_BYTE; if(create->encDataFormat==ALG_VID_DATA_FORMAT_YUV422) pObj->params.forceChromaFormat = XDM_YUV_422P; else pObj->params.forceChromaFormat = XDM_YUV_420P; pObj->hEncode = IMGENC1_create(gALG_hEngine, pObj->algName, &pObj->params); if (pObj->hEncode == NULL) { OSA_ERROR("Failed to open video encode algorithm: %s (0x%x)\n", pObj->algName, Engine_getLastError(gALG_hEngine)); OSA_memFree(pObj); return NULL; } status = ALG_jpgEncSetQvalue(pObj, create->qValue); if(status!=OSA_SOK) { ALG_jpgEncDelete(pObj); return NULL; } return pObj; }
/* * ======== 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); }