123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- #include <stdio.h>
- #include <cuda_runtime_api.h>
- #include <EGL/egl.h>
- #include <EGL/eglext.h>
- #include <GLES2/gl2.h>
- #include <GLES2/gl2ext.h>
- #include <cuda.h>
- #include <cuda_runtime.h>
- #include "cudaEGL.h"
- #include "NvAnalysis.h"
- #include "NvCudaProc.h"
- static void
- Handle_EGLImage(EGLImageKHR image);
- void
- HandleEGLImage(void *pEGLImage)
- {
- EGLImageKHR *pImage = (EGLImageKHR *)pEGLImage;
- Handle_EGLImage(*pImage);
- }
- static void
- Handle_EGLImage(EGLImageKHR image)
- {
- CUresult status;
- CUeglFrame eglFrame;
- CUgraphicsResource pResource = NULL;
- cudaFree(0);
- status = cuGraphicsEGLRegisterImage(&pResource, image,
- CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
- if (status != CUDA_SUCCESS)
- {
- printf("cuGraphicsEGLRegisterImage failed: %d, cuda process stop\n",
- status);
- return;
- }
- status = cuGraphicsResourceGetMappedEglFrame(&eglFrame, pResource, 0, 0);
- if (status != CUDA_SUCCESS)
- {
- printf("cuGraphicsSubResourceGetMappedArray failed\n");
- }
- status = cuCtxSynchronize();
- if (status != CUDA_SUCCESS)
- {
- printf("cuCtxSynchronize failed\n");
- }
- if (eglFrame.frameType == CU_EGL_FRAME_TYPE_PITCH)
- {
-
- addLabels((CUdeviceptr) eglFrame.frame.pPitch[0], eglFrame.pitch);
- }
- status = cuCtxSynchronize();
- if (status != CUDA_SUCCESS)
- {
- printf("cuCtxSynchronize failed after memcpy\n");
- }
- status = cuGraphicsUnregisterResource(pResource);
- if (status != CUDA_SUCCESS)
- {
- printf("cuGraphicsEGLUnRegisterResource failed: %d\n", status);
- }
- }
- void mapEGLImage2Float(void* pEGLImage, int width, int height,
- COLOR_FORMAT color_format,
- void* cuda_buf,
- void* offsets,
- void* scales)
- {
- CUresult status;
- CUeglFrame eglFrame;
- CUgraphicsResource pResource = NULL;
- EGLImageKHR *pImage = (EGLImageKHR *)pEGLImage;
- cudaFree(0);
- status = cuGraphicsEGLRegisterImage(&pResource, *pImage,
- CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
- if (status != CUDA_SUCCESS)
- {
- printf("cuGraphicsEGLRegisterImage failed: %d, cuda process stop\n",
- status);
- return;
- }
- status = cuGraphicsResourceGetMappedEglFrame(&eglFrame, pResource, 0, 0);
- if (status != CUDA_SUCCESS)
- {
- printf("cuGraphicsSubResourceGetMappedArray failed\n");
- }
- status = cuCtxSynchronize();
- if (status != CUDA_SUCCESS)
- {
- printf("cuCtxSynchronize failed\n");
- }
- if (eglFrame.frameType == CU_EGL_FRAME_TYPE_PITCH)
- {
-
- convertIntToFloat((CUdeviceptr) eglFrame.frame.pPitch[0],
- width,
- height,
- eglFrame.pitch,
- color_format,
- offsets,
- scales,
- cuda_buf);
- }
- status = cuCtxSynchronize();
- if (status != CUDA_SUCCESS)
- {
- printf("cuCtxSynchronize failed after memcpy\n");
- }
- status = cuGraphicsUnregisterResource(pResource);
- if (status != CUDA_SUCCESS)
- {
- printf("cuGraphicsEGLUnRegisterResource failed: %d\n", status);
- }
- }
- void convertEglFrameIntToFloat(void* pEglFrame, int width, int height,
- COLOR_FORMAT color_format,
- void* cuda_buf,
- void* offsets,
- void* scales, void* pstream)
- {
- CUeglFrame eglFrame = *(CUeglFrame*)pEglFrame;
- if (eglFrame.frameType == CU_EGL_FRAME_TYPE_PITCH)
- {
-
- convertIntToFloat((CUdeviceptr) eglFrame.frame.pPitch[0],
- width,
- height,
- eglFrame.pitch,
- color_format,
- offsets,
- scales,
- cuda_buf, pstream);
- }
- }
|