#include #include #include #include #define NUM_BUFFERS 16 using namespace Argus; bool createBuffer(){ int m_dmaBuffer[NUM_BUFFERS]; EGLImageKHR m_image[NUM_BUFFERS]; printf("Allocate buffers...\n"); for (size_t i = 0; i < NUM_BUFFERS; i++) { NvBufferCreateParams params; params.width = 1920; params.height = 1080; params.layout = NvBufferLayout_Pitch; params.colorFormat = NvBufferColorFormat_NV12; params.payloadType = NvBufferPayload_SurfArray; params.nvbuf_tag = NvBufferTag_CAMERA; printf("Allocate buffer %ld", i); int ret = NvBufferCreateEx(&m_dmaBuffer[i], ¶ms); printf(" -> return: %d\n", ret); if (ret) { printf("Failed to allocate NativeBuffer '%ld'\n", i); return false; } printf("Allocate image %ld", i); m_image[i] = NvEGLImageFromFd(EGL_NO_DISPLAY, m_dmaBuffer[i]); printf(" -> return: %p\n", m_image[i]); if (m_image[i] == EGL_NO_IMAGE_KHR) { printf("Failed to allocate EGLImage '%ld'\n", i); return false; } } printf("Clear buffers...\n"); for (size_t i = 0; i < NUM_BUFFERS; i++) { printf("Clear Buffer %ld", i); int ret = NvBufferDestroy(m_dmaBuffer[i]); printf(" -> return: %d\n", ret); } } static void* pthread(void* data){ createBuffer(); pthread_exit(NULL); } int main(int argc, char *argv[]) { printf("Create Buffer in main thread:\n\n"); createBuffer(); printf("\n\nCreate Buffer in sub thread:\n\n"); pthread_t thread; pthread_attr_t tAttributes; pthread_attr_init(&tAttributes); pthread_attr_setdetachstate(&tAttributes, PTHREAD_CREATE_DETACHED); pthread_create(&thread, &tAttributes, &pthread, NULL); pthread_join(thread, NULL); }