arxstatus_t ImageBuffer::free() { if (mRemote) { if (mImage.memType == DVP_MTYPE_GRALLOC_2DTILED || mImage.memType == DVP_MTYPE_DISPLAY_2DTILED) { native_handle_t *handle = reinterpret_cast<native_handle_t *>(mImage.reserved); if (!mUsingTexture) { GraphicBufferMapper &mapper = GraphicBufferMapper::get(); mapper.unlock(handle); mapper.unregisterBuffer(handle); } native_handle_close(handle); native_handle_delete(handle); } else { DVP_Image_Free_Import(mDvp, &mImage, mImportHdls); if (mImage.memType != DVP_MTYPE_MPUCACHED_VIRTUAL_SHARED) { for (uint32_t i = 0; i < mImage.planes; i++) { close(mSharedFds[i]); } } } return NOERROR; } if (mAnw) { anativewindow_release(mAnw, &(mImage.reserved)); } else { DVP_Image_Free(mDvp, &mImage); if (mImage.memType != DVP_MTYPE_MPUCACHED_VIRTUAL_SHARED) { for (uint32_t i = 0; i < mImage.planes; i++) { close(mSharedFds[i]); } } } return NOERROR; }
int main(int argc, char *argv[]) { int width = 320; int height = 240; int numNodes = 3; DVP_Handle hDVP = 0; DVP_KernelNode_t *pNodes = NULL; struct timespec stop,start; hDVP = DVP_KernelGraph_Init(); DVP_Image_t input; width = 11; height = sizeof(packedfield) / width; DVP_Image_Init(&input, width, height, FOURCC_Y800); if (DVP_Image_Alloc(hDVP, &input, DVP_MTYPE_DEFAULT) == DVP_FALSE) { fprintf(stderr,"could not allocate buffer\n"); exit(1); } unsigned char* ptr = packedfield; for (int j = input.y_start; j < input.height; j++ ) for (int i = input.x_start; i < input.width; i++) input.pData[0][j*input.y_stride + i*input.x_stride] = *ptr++; PrintMatrix("Input",&input); // Create the output buffer DVP_Image_t output; CreateMatrix(hDVP, &output, FOURCC_Y800, width, height, 0x66); // setupt the parameters pNodes = DVP_KernelGraph_Alloc(hDVP, numNodes); if (pNodes) { DVP_U32 orders[] = {0,0,0}; DVP_KernelGraphSection_t sections[] = { {&pNodes[0], 1, DVP_PERF_INIT, DVP_CORE_LOAD_INIT, DVP_TRUE}, }; DVP_KernelGraph_t graph = { sections, 1, orders, DVP_PERF_INIT, }; pNodes[0].affinity = DVP_CORE_DSP; pNodes[0].kernel = DVP_KN_HP_UNPACK; pNodes[0].data.io.input = input; pNodes[0].data.io.output = output; // Call the graph sections[0].skipSection = DVP_FALSE; clock_gettime(CLOCK_REALTIME, &start); int ret = DVP_KernelGraphs(hDVP, &graph, (void*)0x01, tellMe); clock_gettime(CLOCK_REALTIME, &stop); double fstart, fstop; fstart = (double)start.tv_sec + ((double)start.tv_nsec / 1000000000.0); fstop = (double)stop.tv_sec + ((double)stop.tv_nsec / 1000000000.0); printf("time %gms\n", (fstop-fstart)*1000.0); sections[0].skipSection = DVP_TRUE; // Print the results PrintMatrix("Output",&output); DVP_PrintPerformanceGraph(hDVP, &graph); DVP_KernelGraph_Free(hDVP, pNodes, numNodes); } else fprintf(stderr,"could not allocate nodes\n"); // free the image memory DVP_Image_Free(hDVP, &input); DVP_Image_Free(hDVP, &output); // tear down the graph resources DVP_KernelGraph_Deinit(hDVP); return 0; }