DvevmStRetCode dvtb_h264Dec2Decode(DvevmStH264Dec2Info *vd, int *decDuration) { int status = -1; DvevmStTime timeStmpBfrDec, timeStmpAftrDec; DvevmStRetCode retCode = DVEVM_ST_SUCCESS; ASSERT(vd != NULL); ASSERT(vd->vdec2Hdl != NULL); vd->skipFrame = DVEVM_ST_FALSE; dvtb_h264UpdateSEIVUIBuffers(vd); timeStmpBfrDec = dvtb_getTime( ); status = VIDDEC2_process(vd->vdec2Hdl, &vd->inBufDesc, &vd->outBufDesc,(VIDDEC2_InArgs *)&vd->vdec2InArgs,(VIDDEC2_OutArgs *)&vd->vdec2OutArgs); timeStmpAftrDec = dvtb_getTime( ); *decDuration = ((timeStmpAftrDec.tv_sec * NUM_MICROSECS_IN_SEC) + timeStmpAftrDec.tv_usec) - ((timeStmpBfrDec.tv_sec * NUM_MICROSECS_IN_SEC) + timeStmpBfrDec.tv_usec); if (status != VIDDEC2_EOK) { SYS_ERROR("Video Decode Process Failed (%d)\n", (int) status); vd->vdec2Cmd = XDM_GETSTATUS; if (DVEVM_ST_FAIL == dvtb_h264Dec2Control(vd)) { SYS_ERROR("Unable to get the status \n"); retCode = DVEVM_ST_FAIL; } else { SYS_ERROR("Codec Error = %d\n", (int) vd->vdec2Status.viddecStatus.extendedError); if (XDM_ISFATALERROR(vd->vdec2Status.viddecStatus.extendedError)) { SYS_ERROR("Video Decode Process failed (%d) with a Codec fatal error %x. Exiting.\n", (int) status, (int) vd->vdec2Status.viddecStatus.extendedError); retCode = DVEVM_ST_FAIL; } SYS_ERROR("Video Decode Process failed (%d) with a Codec non fatal error %x. Continuing.\n", (int) status, (int) vd->vdec2Status.viddecStatus.extendedError); } } if(vd->vdec2DynParams.Sei_Vui_parse_flag) { if(XDM_YUV_420P == vd->vdec2Params.viddecParams.forceChromaFormat) { vd->outBufDesc.bufs[4] = NULL; vd->outBufDesc.bufSizes[4] = 0; } else if(XDM_YUV_422ILE == vd->vdec2Params.viddecParams.forceChromaFormat) { vd->outBufDesc.bufs[2] = NULL; vd->outBufDesc.bufSizes[2] = 0; } } return retCode; }
DvevmStRetCode dvtb_vc1Dec2Decode(DvevmStVC1Dec2Info *vd, int nFrames, int *decDuration) { XDAS_Int32 status = -1; int i = 0; DvevmStTime timeStmpBfrDec, timeStmpAftrDec; DvevmStRetCode retCode = DVEVM_ST_SUCCESS; ASSERT(vd != NULL); ASSERT((VIDDEC2_Handle) vd->vdec2Hdl != NULL); vd->skipFrame = DVEVM_ST_FALSE; vd->inBufDesc.numBufs = vd->inBuf.numBufs; for (i = 0; i < vd->inBuf.numBufs; i++) { vd->inBufDesc.descs[i].buf = (XDAS_Int8 *) vd->inBuf.bufs[i]; vd->inBufDesc.descs[i].bufSize = (XDAS_Int32) vd->inBuf.bufSizes[i]; } timeStmpBfrDec = dvtb_getTime(); status = VIDDEC2_process((VIDDEC2_Handle) vd->vdec2Hdl, &vd->inBufDesc, &vd->outBufDesc, (VIDDEC2_InArgs *) &vd->vdec2InArgs, (VIDDEC2_OutArgs*) &vd->vdec2OutArgs); timeStmpAftrDec = dvtb_getTime(); *decDuration = ((timeStmpAftrDec.tv_sec * NUM_MICROSECS_IN_SEC) + timeStmpAftrDec.tv_usec) - ((timeStmpBfrDec.tv_sec * NUM_MICROSECS_IN_SEC) + timeStmpBfrDec.tv_usec); if (status != VIDDEC2_EOK) { SYS_ERROR("Video Decode Process Failed (%d)\n", (int) status); vd->vdec2Cmd = XDM_GETSTATUS; if (DVEVM_ST_FAIL == dvtb_vc1Dec2Control(vd)) { SYS_ERROR("Unable to get the status for frame # %d\n", nFrames); retCode = DVEVM_ST_FAIL; } else { if (XDM_ISFATALERROR(vd->vdec2Status.viddecStatus.extendedError)) { SYS_ERROR("Video Decode Process failed (%d) with a Codec fatal error %x. Exiting.\n", (int) status, (int) vd->vdec2Status.viddecStatus.extendedError); return DVEVM_ST_FAIL; } SYS_ERROR("Video Decode Process failed (%d) with a Codec non fatal error %d. Continuing.\n", (int) status, (int) vd->vdec2Status.viddecStatus.extendedError); } } return retCode; }
/* * ======== encode_decode ======== */ static Void encode_decode(VIDENC1_Handle enc, VIDDEC2_Handle dec, FILE *in, FILE *out) { Int n; Int32 status; VIDDEC2_InArgs decInArgs; VIDDEC2_OutArgs decOutArgs; VIDDEC2_DynamicParams decDynParams; VIDDEC2_Status decStatus; VIDENC1_InArgs encInArgs; VIDENC1_OutArgs encOutArgs; VIDENC1_DynamicParams encDynParams; VIDENC1_Status encStatus; IVIDEO1_BufDescIn encInBufDesc; XDM_BufDesc encOutBufDesc; XDAS_Int8 *encoded[XDM_MAX_IO_BUFFERS]; XDAS_Int32 encBufSizes[XDM_MAX_IO_BUFFERS]; XDM1_BufDesc decInBufDesc; XDM_BufDesc decOutBufDesc; XDAS_Int8 *dst[XDM_MAX_IO_BUFFERS]; XDAS_Int32 outBufSizes[XDM_MAX_IO_BUFFERS]; /* clear and initialize the buffer descriptors */ memset(encoded, 0, sizeof(encoded[0]) * XDM_MAX_IO_BUFFERS); memset(dst, 0, sizeof(dst[0]) * XDM_MAX_IO_BUFFERS); encoded[0] = encodedBuf; dst[0] = outBuf; encInBufDesc.numBufs = encOutBufDesc.numBufs = decInBufDesc.numBufs = decOutBufDesc.numBufs = 1; encOutBufDesc.bufSizes = encBufSizes; decOutBufDesc.bufSizes = outBufSizes; encInBufDesc.bufDesc[0].bufSize = encBufSizes[0] = decInBufDesc.descs[0].bufSize = outBufSizes[0] = NSAMPLES; encInBufDesc.bufDesc[0].buf = inBuf; encOutBufDesc.bufs = encoded; decInBufDesc.descs[0].buf = encoded[0]; decOutBufDesc.bufs = dst; encInBufDesc.frameWidth = 0; /* TODO */ encInBufDesc.frameHeight = 0; /* TODO */ encInBufDesc.framePitch = 0; /* TODO */ /* 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 = VIDDEC2_control(dec, XDM_GETVERSION, &decDynParams, &decStatus); Log_print1(Diags_USER1, "[+1] Decoder version: %s", (IArg)((status == VIDDEC2_EOK ? ((char *)decStatus.data.buf) : "[unknown]"))); status = VIDENC1_control(enc, XDM_GETVERSION, &encDynParams, &encStatus); Log_print1(Diags_USER1, "[+1] Encoder version: %s", (IArg)((status == VIDENC1_EOK ? ((char *)encStatus.data.buf) : "[unknown]"))); /* * This app expects the encoder to provide 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 = VIDENC1_control(enc, XDM_GETSTATUS, &encDynParams, &encStatus); if (status != VIDENC1_EOK) { /* failure, report error and exit */ Log_print1(Diags_USER7, "[+7] encode control status = %ld", (IArg)status); return; } /* Validate this encoder codec will meet our buffer requirements */ if ((encInBufDesc.numBufs < encStatus.bufInfo.minNumInBufs) || (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) || (encOutBufDesc.numBufs < encStatus.bufInfo.minNumOutBufs) || (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) { /* failure, report error and exit */ Log_print0(Diags_USER7, "[+7] Error: encoder codec feature conflict"); return; } status = VIDDEC2_control(dec, XDM_GETSTATUS, &decDynParams, &decStatus); if (status != VIDDEC2_EOK) { /* failure, report error and exit */ Log_print1(Diags_USER7, "[+7] decode control status = %ld", (IArg)status); return; } /* Validate this decoder codec will meet our buffer requirements */ if ((decInBufDesc.numBufs < decStatus.bufInfo.minNumInBufs) || (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) || (decOutBufDesc.numBufs < decStatus.bufInfo.minNumOutBufs) || (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) { /* failure, report error and exit */ Log_print0(Diags_USER7, "[+7] App-> ERROR: decoder does not meet buffer requirements."); return; } /* * Read complete frames from in, encode, decode, and write to out. */ for (n = 0; fread(inBuf, IFRAMESIZE, 1, in) == 1; n++) { #ifdef CACHE_ENABLED #if defined(xdc_target__isaCompatible_64P) || \ defined(xdc_target__isaCompatible_64T) /* * 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 Log_print1(Diags_USER1, "[+1] App-> Processing frame %d...", (IArg)n); /* * Encode the frame. * * Note, inputID == 0 is an error. This example doesn't account * for the case where 'n + 1' wraps to zero. */ encInArgs.inputID = n + 1; status = VIDENC1_process(enc, &encInBufDesc, &encOutBufDesc, &encInArgs, &encOutArgs); Log_print2(Diags_USER2, "[+2] App-> Encoder frame %d process returned - 0x%x)", (IArg)n, (IArg)status); if (status != VIDENC1_EOK) { Log_print3(Diags_USER7, "[+7] App-> Encoder frame %d processing FAILED, status = 0x%x, " "extendedError = 0x%x", (IArg)n, (IArg)status, (IArg)(encOutArgs.extendedError)); break; } /* * So far, so good. Validate our assumption that the encoder * provided encodedBuf as it's encOutArgs->encodedBuf.buf. If * that's not the case, we may be dealing with a codec that's * giving us out of order frames... and this simple app * doesn't support that. */ if (encOutArgs.encodedBuf.buf != encodedBuf) { Log_print0(Diags_USER7, "[+7] App-> Internal error. Unsupported encoder"); break; } #ifdef CACHE_ENABLED /* * Conditionally writeback the encoded buf from the previous * call. Also, as encodedBuf is an inBuf to the next process * call, conditionally invalidate it as well. */ if (XDM_ISACCESSMODE_WRITE(encOutArgs.encodedBuf.accessMask)) { Memory_cacheWbInv(encodedBuf, EFRAMESIZE); } /* * Per DMA Rule 7, our output buffer cache lines (for the * upcoming decoder) must be cleaned. */ Memory_cacheInv(outBuf, OFRAMESIZE); #endif /* decode the frame */ decInArgs.numBytes = EFRAMESIZE; decInArgs.inputID = 1; /* typically this varies by each frame */ status = VIDDEC2_process(dec, &decInBufDesc, &decOutBufDesc, &decInArgs, &decOutArgs); Log_print2(Diags_USER2, "[+2] App-> Decoder frame %d process returned - 0x%x)", (IArg)n, (IArg)status); if (status != VIDDEC2_EOK) { Log_print2(Diags_USER7, "[+7] App-> Decoder frame %d processing FAILED, status =" " 0x%x", (IArg)n, (IArg)status); break; } /* again, validate our assumption that we don't get out-of-order bufs */ if (decOutArgs.decodedBufs.bufDesc[0].buf != outBuf) { Log_print0(Diags_USER7, "[+7] App-> Internal error. Unsupported decoder"); break; } #ifdef CACHE_ENABLED /* Conditionally writeback the decoded buf */ if (XDM_ISACCESSMODE_WRITE( decOutArgs.decodedBufs.bufDesc[0].accessMask)) { Memory_cacheWb(outBuf, OFRAMESIZE); } #endif /* write to file */ fwrite(dst[0], OFRAMESIZE, 1, out); } Log_print1(Diags_USER1, "[+1] %d frames encoded/decoded", (IArg)n); }