/***************************************************************************** Prototype : jpg_enc_set_dyn_params Description : Set dynamic params for jpg encode Input : JpgEncodeHandle hJpgEnc JpgEncDynParams *dynParams Output : None Return Value : static Calls : Called By : History : 1.Date : 2012/2/1 Author : Sun Modification : Created function *****************************************************************************/ static Int32 jpg_enc_set_dyn_params(JpgEncodeHandle hJpgEnc, JpgEncDynParams *dynParams) { /** Set up dynamic parameters (can be changed before each call to jpeg processing) * Parameters in structure dynamicParams are default image encode parameters required by XDM */ if(!dynParams || dynParams->size != sizeof(JpgEncDynParams)) return E_INVAL; IJPEGENC_DynamicParams *jpgEncDynParams = &hJpgEnc->dynParams; jpgEncDynParams->imgencDynamicParams.inputChromaFormat = dynParams->inputFormat; jpgEncDynParams->imgencDynamicParams.qValue = dynParams->quality; jpgEncDynParams->imgencDynamicParams.inputWidth = dynParams->width; jpgEncDynParams->imgencDynamicParams.inputHeight = dynParams->height; jpgEncDynParams->rotation = dynParams->rotation; jpgEncDynParams->imgencDynamicParams.size = sizeof(IJPEGENC_DynamicParams); Int32 status; status = IMGENC1_control(hJpgEnc->algHandle, XDM_SETPARAMS, (IIMGENC1_DynamicParams *)jpgEncDynParams, (IIMGENC1_Status *)&hJpgEnc->status); if(status == XDM_EFAIL) { ERR("set dynamic params failed: %d", (int)hJpgEnc->status.extendedError); return E_IO; } /* Get buffer info */ status = IMGENC1_control(hJpgEnc->algHandle, XDM_GETBUFINFO, (IIMGENC1_DynamicParams *)jpgEncDynParams, (IIMGENC1_Status *)&hJpgEnc->status); if(status == XDM_EFAIL) { ERR("get buf info failed: %d", (int)status); return E_IO; } /* Init buffer descriptor */ hJpgEnc->inBufDesc.numBufs = hJpgEnc->status.bufInfo.minNumInBufs; hJpgEnc->outBufDesc.numBufs = hJpgEnc->status.bufInfo.minNumOutBufs; //DBG("jpg enc, min in buf num: %d, min out buf num: %d", //hJpgEnc->inBufDesc.numBufs, hJpgEnc->outBufDesc.numBufs); /* Set up buffer size, so we need not set them when process */ int i; for(i = 0; i < hJpgEnc->inBufDesc.numBufs; i++) { hJpgEnc->inBufDesc.descs[i].bufSize = hJpgEnc->status.bufInfo.minInBufSize[i]; } //for(i = 0; i < hJpgEnc->outBufDesc.numBufs; i++) { //hJpgEnc->outBufDesc.descs[i].bufSize = hJpgEnc->status.bufInfo.minOutBufSize[i]; //} hJpgEnc->outBufDesc.descs[0].bufSize = hJpgEnc->status.bufInfo.minOutBufSize[0]; return E_NO; }
int ALG_jpgEncSetQvalue(void *hndl, int qValue) { ALG_JpgEncObj *pObj = (ALG_JpgEncObj*)hndl; XDAS_Int32 status; if(pObj==NULL) return OSA_EFAIL; pObj->dynamicParams.size = sizeof(IMGENC1_DynamicParams); pObj->dynamicParams.numAU = XDM_DEFAULT; if(pObj->createPrm.dataFormat==ALG_VID_DATA_FORMAT_YUV422) pObj->dynamicParams.inputChromaFormat = XDM_YUV_422ILE; else pObj->dynamicParams.inputChromaFormat = XDM_YUV_420SP; if(qValue < ALG_JPG_ENC_Q_VALUE_MIN) qValue = ALG_JPG_ENC_Q_VALUE_MIN; if(qValue > ALG_JPG_ENC_Q_VALUE_MAX) qValue = ALG_JPG_ENC_Q_VALUE_MAX; pObj->dynamicParams.inputWidth = pObj->createPrm.width; pObj->dynamicParams.inputHeight = pObj->createPrm.height; pObj->dynamicParams.captureWidth = (pObj->createPrm.offsetH>pObj->createPrm.width)?pObj->createPrm.offsetH:pObj->createPrm.width; pObj->dynamicParams.generateHeader = XDM_ENCODE_AU; pObj->dynamicParams.qValue = qValue; /* Set video encoder dynamic parameters */ pObj->encStatus.size = sizeof(pObj->encStatus); pObj->encStatus.data.buf = NULL; status = IMGENC1_control(pObj->hEncode, XDM_SETPARAMS, &pObj->dynamicParams, &pObj->encStatus); if (status != IMGENC1_EOK) { OSA_ERROR("XDM_SETPARAMS failed, status=%ld\n", status); return OSA_EFAIL; } pObj->encStatus.data.buf = NULL; status = IMGENC1_control(pObj->hEncode, XDM_GETBUFINFO, &pObj->dynamicParams, &pObj->encStatus); if (status != IMGENC1_EOK) { OSA_ERROR("XDM_GETBUFINFO failed, status=%ld\n", status); return OSA_EFAIL; } #ifdef ALG_DEBUG OSA_printf(" ALG: ImgEnc: XDM_GETBUFINFO: min in bufs:%ld buf(0):%ld buf(1):%ld\n",pObj->encStatus.bufInfo.minNumInBufs,pObj->encStatus.bufInfo.minInBufSize[0], pObj->encStatus.bufInfo.minInBufSize[1]); #endif return OSA_SOK; }
/* * ======== 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); }