mirror of
git://nv-tegra.nvidia.com/tegra/v4l2-src/libv4l2_nvargus.git
synced 2025-12-22 09:23:09 +03:00
8e62a0e398b15aa8ea7ad8b63a8e55a2d34c22d4 - libv4l2_nvargus/libv4l2_nvargus.cpp 08591e4e7c932d134ab3b5de5608f79817f25b10 - libv4l2_nvargus/Makefile e5896289dc5cf1a1be97cd111bef4715314a657d - libv4l2_nvargus/README 430402509552450f933f97376dbb547425dc6a1e - libv4l2_nvargus/nvargusv4l2_argus.cpp 592bab81439af0cb17984e0b0e1d1b4b1a498ea2 - libv4l2_nvargus/nvargusv4l2_nvqueue.cpp 62ff489fd24d7e62098d8bd0b681f017a3f1ed89 - libv4l2_nvargus/nvargusv4l2_os.cpp 1600ff6fb81d3a5f53ed343576eae3fb530a7135 - libv4l2_nvargus/LICENSE.libv4l2_nvargus 2a8f761ddbd0acd63d41333cfd33c0130a68f986 - libv4l2_nvargus/nvargusv4l2.cpp 1b22fa15e66aeb472a541aa4fa9ee68b6f631fdf - libv4l2_nvargus/nvargusv4l2_context.cpp 138a72695eb516d82dba17bf87260fe5a692ec74 - libv4l2_nvargus/nvargusv4l2_ioctl.cpp 1522ea0088250fb7ce0c9f77c75dbca5d0f511f4 - libv4l2_nvargus/inc/nvargusv4l2.h 25353aa29a931dfc9f52054852b50d690716a64c - libv4l2_nvargus/inc/nvargusv4l2_nvqueue.h e0025b2f87abda4cd744e356e26cef85246a1fdc - libv4l2_nvargus/inc/nvargusv4l2_os.h d1c5f6e8cd188bbd39c99c32d4e4e68ee85e0f8b - libv4l2_nvargus/inc/nvargusv4l2_argus.h ebcc91d051727ba390d71db0887f788ffcfd8091 - libv4l2_nvargus/inc/nvargusv4l2_ioctl.h 553b571fc97552659847ad0b2bc6e34384724d29 - libv4l2_nvargus/inc/nvargusv4l2_context.h Change-Id: I73b0a66e76ad1efdadcd8ad249783ded6958131d
209 lines
5.2 KiB
C++
209 lines
5.2 KiB
C++
/*
|
|
* Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
* DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
#include "nvargusv4l2_nvqueue.h"
|
|
|
|
int32_t NvQueueCreate(NvQueueHandle *phQueue, u_int32_t maxEntries, u_int32_t entrySize)
|
|
{
|
|
NvQueue *pQueue;
|
|
int32_t retval = 0;
|
|
|
|
if (maxEntries == 0)
|
|
return EINVAL;
|
|
|
|
pQueue = (NvQueue *)malloc(sizeof(NvQueue));
|
|
if (!pQueue)
|
|
return ENOMEM;
|
|
|
|
memset(pQueue, 0x0, sizeof(NvQueue));
|
|
pQueue->pEntryList = 0;
|
|
pQueue->pushIndex = 0;
|
|
pQueue->popIndex = 0;
|
|
pQueue->maxEntries = maxEntries + 1;
|
|
pQueue->entrySize = entrySize;
|
|
|
|
retval = NvMutexCreate(&pQueue->mutexLock);
|
|
if (retval != 0)
|
|
goto nvqueue_exit;
|
|
|
|
pQueue->pEntryList = (u_int8_t *)malloc(pQueue->maxEntries * entrySize);
|
|
if (!pQueue->pEntryList)
|
|
{
|
|
retval = ENOMEM;
|
|
goto nvqueue_exit;
|
|
}
|
|
|
|
*phQueue = pQueue;
|
|
return 0;
|
|
|
|
nvqueue_exit:
|
|
if (pQueue)
|
|
{
|
|
NvMutexDestroy(pQueue->mutexLock);
|
|
free(pQueue);
|
|
}
|
|
|
|
*phQueue = 0;
|
|
return retval;
|
|
}
|
|
|
|
int32_t NvQueueEnQ(NvQueueHandle hQueue, void *pElem)
|
|
{
|
|
NvQueue *pQueue = hQueue;
|
|
int32_t retval = 0;
|
|
u_int32_t pushIdx, popIdx;
|
|
|
|
NvMutexAcquire(pQueue->mutexLock);
|
|
|
|
if (pElem == NULL)
|
|
{
|
|
retval = EINVAL;
|
|
goto nvqueue_exit;
|
|
}
|
|
|
|
pushIdx = pQueue->pushIndex;
|
|
popIdx = pQueue->popIndex;
|
|
|
|
/* Check if space available */
|
|
if (pushIdx + 1 == popIdx || pushIdx + 1 == popIdx + pQueue->maxEntries)
|
|
{
|
|
retval = ENOMEM;
|
|
goto nvqueue_exit;
|
|
}
|
|
|
|
memcpy(&pQueue->pEntryList[pushIdx * pQueue->entrySize], pElem,
|
|
pQueue->entrySize);
|
|
|
|
if (++pushIdx >= pQueue->maxEntries)
|
|
pushIdx = 0;
|
|
pQueue->pushIndex = pushIdx;
|
|
|
|
nvqueue_exit:
|
|
NvMutexRelease(pQueue->mutexLock);
|
|
return retval;
|
|
}
|
|
|
|
int32_t NvQueueDeQ(NvQueueHandle hQueue, void *pElem)
|
|
{
|
|
NvQueue *pQueue = hQueue;
|
|
int32_t retval = 0;
|
|
u_int32_t popIdx;
|
|
|
|
NvMutexAcquire(pQueue->mutexLock);
|
|
|
|
popIdx = pQueue->popIndex;
|
|
if (pQueue->pushIndex == popIdx)
|
|
{
|
|
retval = EINVAL;
|
|
goto nvqueue_exit;
|
|
}
|
|
|
|
memcpy(pElem, &pQueue->pEntryList[popIdx * pQueue->entrySize],
|
|
pQueue->entrySize);
|
|
|
|
if (++popIdx >= pQueue->maxEntries)
|
|
popIdx = 0;
|
|
pQueue->popIndex = popIdx;
|
|
|
|
nvqueue_exit:
|
|
NvMutexRelease(pQueue->mutexLock);
|
|
return retval;
|
|
}
|
|
|
|
int32_t NvQueuePeek(NvQueueHandle hQueue, void *pElem)
|
|
{
|
|
NvQueue *pQueue = hQueue;
|
|
int32_t retval = 0;
|
|
u_int32_t popIdx;
|
|
|
|
NvMutexAcquire(pQueue->mutexLock);
|
|
|
|
popIdx = pQueue->popIndex;
|
|
if (pQueue->pushIndex == popIdx)
|
|
{
|
|
retval = EINVAL;
|
|
goto nvqueue_exit;
|
|
}
|
|
|
|
memcpy(pElem, &pQueue->pEntryList[popIdx * pQueue->entrySize],
|
|
pQueue->entrySize);
|
|
|
|
nvqueue_exit:
|
|
NvMutexRelease(pQueue->mutexLock);
|
|
return retval;
|
|
}
|
|
|
|
int32_t NvQueuePeekEntry(NvQueueHandle hQueue, void *pElem, u_int32_t nEntry)
|
|
{
|
|
NvQueue *pQueue = hQueue;
|
|
int32_t err = 0;
|
|
u_int32_t entry, pushIdx, popIdx, numEntries;
|
|
|
|
NvMutexAcquire(pQueue->mutexLock);
|
|
|
|
pushIdx = pQueue->pushIndex;
|
|
popIdx = pQueue->popIndex;
|
|
|
|
numEntries = (pushIdx >= popIdx) ? pushIdx - popIdx : pQueue->maxEntries - popIdx + pushIdx;
|
|
|
|
if ((numEntries == 0) || (numEntries <= nEntry))
|
|
{
|
|
err = EINVAL;
|
|
goto nvqueue_exit;
|
|
}
|
|
|
|
entry = popIdx + nEntry;
|
|
if (entry >= pQueue->maxEntries)
|
|
entry -= pQueue->maxEntries;
|
|
|
|
memcpy(pElem, &pQueue->pEntryList[entry * pQueue->entrySize],
|
|
pQueue->entrySize);
|
|
|
|
nvqueue_exit:
|
|
NvMutexRelease(pQueue->mutexLock);
|
|
return err;
|
|
}
|
|
|
|
void NvQueueDestroy(NvQueueHandle *phQueue)
|
|
{
|
|
NvQueue *pQueue = *phQueue;
|
|
if (!pQueue)
|
|
return;
|
|
NvMutexDestroy(pQueue->mutexLock);
|
|
free(pQueue->pEntryList);
|
|
free(pQueue);
|
|
*phQueue = NULL;
|
|
}
|
|
|
|
u_int32_t NvQueueGetNumEntries(NvQueueHandle hQueue)
|
|
{
|
|
NvQueue *pQueue = hQueue;
|
|
u_int32_t pushIdx = pQueue->pushIndex;
|
|
u_int32_t popIdx = pQueue->popIndex;
|
|
u_int32_t numEntries = (pushIdx >= popIdx) ? pushIdx - popIdx : pQueue->maxEntries - popIdx + pushIdx;
|
|
|
|
return numEntries;
|
|
}
|