diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 63cc20a..2882778 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,8 @@ jobs: run: | bash build.sh osd-goke bash build.sh osd-hisi - bash build.sh osd-star + bash build.sh osd-star6b0 + bash build.sh osd-star6e - name: Upload files uses: softprops/action-gh-release@v2 @@ -28,4 +29,5 @@ jobs: files: | osd/osd-goke osd/osd-hisi - osd/osd-star + osd/osd-star6b0 + osd/osd-star6e diff --git a/.gitignore b/.gitignore index bcb3cb2..221b275 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /firmware /toolchain -/osd/osd* +/osd/osd-* diff --git a/build.sh b/build.sh index 605695f..ed7fe26 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,11 @@ #!/bin/bash DL="https://github.com/openipc/firmware/releases/download/latest" -if [ "$1" = "osd-star" ]; then +if [ "$1" = "osd-inge" ]; then + CC=mips_xburst-gcc13-musl-3_10 +elif [[ "$1" == *"-star6b0" ]]; then + CC=cortex_a7_thumb2_hf-gcc13-musl-4_9 +elif [[ "$1" == *"-star6e" ]]; then CC=cortex_a7_thumb2_hf-gcc13-glibc-4_9 else CC=cortex_a7_thumb2-gcc13-musl-4_9 @@ -26,10 +30,17 @@ if [ "$1" = "osd-goke" ]; then elif [ "$1" = "osd-hisi" ]; then DRV=$PWD/firmware/general/package/hisilicon-osdrv-hi3516ev200/files/lib make -C osd -B CC=$GCC DRV=$DRV $1 -elif [ "$1" = "osd-star" ]; then +elif [ "$1" = "osd-inge" ]; then + DRV=$PWD/firmware/general/package/ingenic-osdrv-t31/files/lib + GCC=$PWD/toolchain/$CC/bin/mipsel-linux-gcc + make -C osd -B CC=$GCC DRV=$DRV $1 +elif [ "$1" = "osd-star6b0" ]; then + DRV=$PWD/firmware/general/package/sigmastar-osdrv-infinity6b0/files/lib + make -C osd -B CC=$GCC DRV=$DRV $1 +elif [ "$1" = "osd-star6e" ]; then DRV=$PWD/firmware/general/package/sigmastar-osdrv-infinity6e/files/lib make -C osd -B CC=$GCC DRV=$DRV $1 else - echo "Usage: $0 [osd-goke|osd-hisi|osd-star]" + echo "Usage: $0 [osd-goke|osd-hisi|osd-inge|osd-star6b0|osd-star6e]" exit 1 fi diff --git a/osd/Makefile b/osd/Makefile index 9034f1c..c4e4969 100644 --- a/osd/Makefile +++ b/osd/Makefile @@ -3,15 +3,25 @@ BUILD = $(CC) $(SRCS) -I $(SDK)/include -L $(DRV) $(LIB) -Os -s -o $(or $(TARGET osd-goke: $(eval SDK = ../sdk/gk7205v300) - $(eval LIB = -lhi_mpi -lgk_api -ldnvqe -lupvqe -lvoice_engine -lsecurec) + $(eval LIB = -ldnvqe -lgk_api -lhi_mpi -lsecurec -lupvqe -lvoice_engine) $(BUILD) osd-hisi: $(eval SDK = ../sdk/hi3516ev300) - $(eval LIB = -lmpi -ldnvqe -lupvqe -lVoiceEngine -lsecurec) + $(eval LIB = -ldnvqe -lmpi -lsecurec -lupvqe -lVoiceEngine) $(BUILD) -osd-star: +osd-inge: + $(eval SDK = ../sdk/ingenic) + $(eval LIB = -D__INGENIC__ -lalog -limp) + $(BUILD) + +osd-star6b0: $(eval SDK = ../sdk/infinity6) - $(eval LIB = -D__SIGMASTAR__ -lcam_os_wrapper -lm -lmi_rgn -lmi_sys) + $(eval LIB = -D__SIGMASTAR__ -D__INFINITY6__ -lcam_os_wrapper -lm -lmi_rgn -lmi_sys) $(BUILD) + +osd-star6e: + $(eval SDK = ../sdk/infinity6) + $(eval LIB = -D__SIGMASTAR__ -D__INFINITY6__ -D__INFINITY6E__ -lcam_os_wrapper -lm -lmi_rgn -lmi_sys) + $(BUILD) \ No newline at end of file diff --git a/osd/common.h b/osd/common.h index 98b86cd..a2c907e 100644 --- a/osd/common.h +++ b/osd/common.h @@ -7,6 +7,7 @@ #include // getopt, optarg, opterr #include // isdigit #include // clock_(get|set)time, timespec +#include // ceil #include #include @@ -38,6 +39,15 @@ extern "C" #define PIXEL_FORMAT_1555 E_MI_RGN_PIXEL_FORMAT_ARGB1555 #define PIXEL_FORMAT_2BPP E_MI_RGN_PIXEL_FORMAT_I2 #define PIXEL_FORMAT_8888 E_MI_RGN_PIXEL_FORMAT_ARGB8888 +#elif defined(__INGENIC__) +#include "imp_system.h" +#include "imp_osd.h" +#include "imp_isp.h" + +#define PIXEL_FORMAT_4444 0 +#define PIXEL_FORMAT_1555 PIX_FMT_RGB555LE +#define PIXEL_FORMAT_2BPP PIX_FMT_0RGB +#define PIXEL_FORMAT_8888 PIX_FMT_ARGB #else #include "hi_common.h" #include "hi_math.h" @@ -72,6 +82,7 @@ extern "C" typedef struct osd { double size; + int hand; short posx, posy; char updt; char font[32]; diff --git a/osd/compat.c b/osd/compat.c index 629bbe6..b241c1d 100644 --- a/osd/compat.c +++ b/osd/compat.c @@ -1,6 +1,11 @@ #include -int __ctype_b; +#ifdef __INGENIC__ +#include +#include +#endif + +void __ctype_b(void) {} int __fgetc_unlocked(FILE *stream) { return fgetc(stream); @@ -8,4 +13,15 @@ int __fgetc_unlocked(FILE *stream) { size_t _stdlib_mb_cur_max(void) { return 0; -} \ No newline at end of file +} + +#ifdef __INGENIC__ +void __assert(void) {} +void __ctype_tolower(void) {} +void __pthread_register_cancel(void) {} +void __pthread_unregister_cancel(void) {} + +void *mmap(void *start, size_t len, int prot, int flags, int fd, unsigned int off) { + return (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off >> 12); +} +#endif \ No newline at end of file diff --git a/osd/main.c b/osd/main.c index 9b41f0d..6339833 100644 --- a/osd/main.c +++ b/osd/main.c @@ -89,6 +89,7 @@ static void fill(char* str) strcat(out, s); opos += strlen(s); } +#ifndef __INGENIC__ else if (str[ipos + 1] == 'T') { ipos++; @@ -104,6 +105,7 @@ static void fill(char* str) strcat(out, t); opos += strlen(t); } +#endif else if (str[ipos + 1] == '$') { ipos++; strcat(out, "$"); @@ -131,18 +133,18 @@ void overlays() } if (osds[id].updt) { - RECT rect = measure_text(osds[id].font, osds[id].size, out); - create_region(id, osds[id].posx, osds[id].posy, rect.width, rect.height); - - BITMAP bitmap = raster_text(osds[id].font, osds[id].size, out); -#ifdef __SIGMASTAR__ - int s32Ret = MI_RGN_SetBitMap(id, (MI_RGN_Bitmap_t *)(&bitmap)); -#else - int s32Ret = HI_MPI_RGN_SetBitMap(id, (BITMAP_S *)(&bitmap)); -#endif - if (s32Ret) - fprintf(stderr, "[%s:%d]RGN_SetBitMap failed with %#x %d!\n", __func__, __LINE__, s32Ret, id); - free(bitmap.pData); + char *font; + asprintf(&font, "/usr/share/fonts/truetype/%s.ttf", osds[id].font); + if (!access(font, F_OK)) { + RECT rect = measure_text(font, osds[id].size, out); + create_region( + &osds[id].hand, + osds[id].posx, osds[id].posy, + rect.width, rect.height); + BITMAP bitmap = raster_text(font, osds[id].size, out); + set_bitmap(osds[id].hand, &bitmap); + free(bitmap.pData); + } } } else if (empty(osds[id].text) && osds[id].updt) @@ -154,13 +156,13 @@ void overlays() BITMAP bitmap; if (!(prepare_bitmap(img, &bitmap, 0, 0, PIXEL_FORMAT_1555))) { - create_region(id, osds[id].posx, osds[id].posy, bitmap.u32Width, bitmap.u32Height); - set_bitmap(id, &bitmap); + create_region(&osds[id].hand, osds[id].posx, osds[id].posy, bitmap.u32Width, bitmap.u32Height); + set_bitmap(osds[id].hand, &bitmap); free(bitmap.pData); } } else - unload_region(id); + unload_region(&osds[id].hand); osds[id].updt = 0; } } @@ -294,10 +296,20 @@ void route() ); } +#ifdef __INGENIC__ +extern int IMP_OSD_SetPoolSize(int size); +#endif + int main(int argc, char *argv[]) { +#ifndef __INGENIC__ int fd_mem = open("/dev/mem", O_RDWR); io_map = mmap(NULL, IO_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd_mem, IO_BASE); +#else + fprintf(stderr, "IMP_System_Init ret:%d\n", IMP_System_Init()); + fprintf(stderr, "IMP_OSD_SetPoolSize ret:%d\n", IMP_OSD_SetPoolSize(512 * 1024)); + fprintf(stderr, "IMP_OSD_CreateGroup ret:%d\n", IMP_OSD_CreateGroup(0)); +#endif #ifdef __SIGMASTAR__ static MI_RGN_PaletteTable_t g_stPaletteTable = {{{0, 0, 0, 0}}}; @@ -310,6 +322,7 @@ int main(int argc, char *argv[]) PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); for (int id = 0; id < MAX_OSD; id++) { + osds[id].hand = -1; osds[id].size = DEF_SIZE; osds[id].posx = DEF_POSX; osds[id].posy = DEF_POSY; @@ -331,8 +344,13 @@ int main(int argc, char *argv[]) printf("[%s:%d]RGN_DeInit failed with %#x!\n", __func__, __LINE__, s32Ret); #endif +#ifndef __INGENIC__ munmap(io_map, IO_SIZE); close(fd_mem); +#else + IMP_OSD_DestroyGroup(0); + fprintf(stderr, "IMP_System_Exit ret:%d\n", IMP_System_Exit()); +#endif return 0; } \ No newline at end of file diff --git a/osd/region.c b/osd/region.c index 8da8092..caf4af7 100644 --- a/osd/region.c +++ b/osd/region.c @@ -2,9 +2,9 @@ const double inv16 = 1.0 / 16.0; -int create_region(int handle, int x, int y, int width, int height) +int create_region(int *handle, int x, int y, int width, int height) { - int s32Ret; + int s32Ret = -1; #ifdef __SIGMASTAR__ MI_RGN_ChnPort_t stChn; @@ -15,6 +15,38 @@ int create_region(int handle, int x, int y, int width, int height) MI_RGN_ChnPortParam_t stChnAttrCurrent; stChn.eModId = E_MI_RGN_MODID_VPE; + stChn.s32DevId = 0; + stChn.s32ChnId = 0; + + stRegion.eType = E_MI_RGN_TYPE_OSD; + stRegion.stOsdInitParam.stSize.u32Height = height; + stRegion.stOsdInitParam.stSize.u32Width = width; + stRegion.stOsdInitParam.ePixelFmt = PIXEL_FORMAT_1555; + + s32Ret = MI_RGN_GetAttr(*handle, &stRegionCurrent); +#elif defined(__INGENIC__) + IMPOSDRgnAttr stRegionCurrent; + IMPOSDRgnAttr stRegion; + + IMPOSDGrpRgnAttr stChnAttr; + IMPOSDGrpRgnAttr stChnAttrCurrent; + + stRegion.type = OSD_REG_PIC; + stRegion.rect.p0.x = x; + stRegion.rect.p0.y = y; + stRegion.rect.p1.x = x + width - 1; + stRegion.rect.p1.y = y + height - 1; + stRegion.fmt = PIXEL_FORMAT_1555; + stRegion.data.picData.pData = NULL; + + if (*handle != -1) + s32Ret = IMP_OSD_GetRgnAttr(*handle, &stRegionCurrent); + else + { + *handle = IMP_OSD_CreateRgn(NULL); + fprintf(stderr, "handle=%d\n", *handle); + IMP_OSD_RegisterRgn(*handle, 0, NULL); + } #else MPP_CHN_S stChn; @@ -25,39 +57,27 @@ int create_region(int handle, int x, int y, int width, int height) RGN_CHN_ATTR_S stChnAttrCurrent; stChn.enModId = HI_ID_VENC; -#endif stChn.s32DevId = 0; stChn.s32ChnId = 0; -#ifdef __SIGMASTAR__ - stRegion.eType = E_MI_RGN_TYPE_OSD; - stRegion.stOsdInitParam.stSize.u32Height = height; - stRegion.stOsdInitParam.stSize.u32Width = width; - stRegion.stOsdInitParam.ePixelFmt = PIXEL_FORMAT_1555; -#else + stRegion.enType = OVERLAY_RGN; stRegion.unAttr.stOverlay.stSize.u32Height = height; stRegion.unAttr.stOverlay.stSize.u32Width = width; stRegion.unAttr.stOverlay.u32CanvasNum = 2; stRegion.unAttr.stOverlay.enPixelFmt = PIXEL_FORMAT_1555; stRegion.unAttr.stOverlay.u32BgColor = (unsigned int[]){0xffffffff, 0x00000000, 1}; -#endif -#ifdef __SIGMASTAR__ - // MI_RGN_DetachFromChn(handle, &stChn); - // MI_RGN_Destroy(handle); - s32Ret = MI_RGN_GetAttr(handle, &stRegionCurrent); -#else - // HI_MPI_RGN_DetachFromChn(HandleNum,&stChn); - // HI_MPI_RGN_Destroy(HandleNum); - s32Ret = HI_MPI_RGN_GetAttr(handle, &stRegionCurrent); + s32Ret = HI_MPI_RGN_GetAttr(*handle, &stRegionCurrent); #endif if (s32Ret) { - fprintf(stderr, "[%s:%d]RGN_GetAttr failed with %#x , creating region %d...\n", __func__, __LINE__, s32Ret, handle); + fprintf(stderr, "[%s:%d]RGN_GetAttr failed with %#x , creating region %d...\n", __func__, __LINE__, s32Ret, *handle); #ifdef __SIGMASTAR__ - s32Ret = MI_RGN_Create(handle, &stRegion); + s32Ret = MI_RGN_Create(*handle, &stRegion); +#elif defined(__INGENIC__) + s32Ret = IMP_OSD_SetRgnAttr(*handle, &stRegion); #else - s32Ret = HI_MPI_RGN_Create(handle, &stRegion); + s32Ret = HI_MPI_RGN_Create(*handle, &stRegion); #endif if (s32Ret) { @@ -69,6 +89,8 @@ int create_region(int handle, int x, int y, int width, int height) { #ifdef __SIGMASTAR__ if (stRegionCurrent.stOsdInitParam.stSize.u32Height != stRegion.stOsdInitParam.stSize.u32Height || stRegionCurrent.stOsdInitParam.stSize.u32Width != stRegion.stOsdInitParam.stSize.u32Width) +#elif defined(__INGENIC__) + if (stRegionCurrent.rect.p1.x - stRegionCurrent.rect.p0.x != width || stRegionCurrent.rect.p1.y - stRegionCurrent.rect.p0.y != height) #else if (stRegionCurrent.unAttr.stOverlay.stSize.u32Height != stRegion.unAttr.stOverlay.stSize.u32Height || stRegionCurrent.unAttr.stOverlay.stSize.u32Width != stRegion.unAttr.stOverlay.stSize.u32Width) #endif @@ -76,15 +98,17 @@ int create_region(int handle, int x, int y, int width, int height) fprintf(stderr, "[%s:%d] Region parameters are different, recreating ... \n", __func__, __LINE__); #ifdef __SIGMASTAR__ stChn.s32OutputPortId = 1; - MI_RGN_DetachFromChn(handle, &stChn); + MI_RGN_DetachFromChn(*handle, &stChn); stChn.s32OutputPortId = 0; - MI_RGN_DetachFromChn(handle, &stChn); - MI_RGN_Destroy(handle); - s32Ret = MI_RGN_Create(handle, &stRegion); + MI_RGN_DetachFromChn(*handle, &stChn); + MI_RGN_Destroy(*handle); + s32Ret = MI_RGN_Create(*handle, &stRegion); +#elif defined(__INGENIC__) + s32Ret = IMP_OSD_SetRgnAttr(*handle, &stRegion); #else - HI_MPI_RGN_DetachFromChn(handle, &stChn); - HI_MPI_RGN_Destroy(handle); - s32Ret = HI_MPI_RGN_Create(handle, &stRegion); + HI_MPI_RGN_DetachFromChn(*handle, &stChn); + HI_MPI_RGN_Destroy(*handle); + s32Ret = HI_MPI_RGN_Create(*handle, &stRegion); #endif if (s32Ret) { @@ -95,28 +119,32 @@ int create_region(int handle, int x, int y, int width, int height) } #ifdef __SIGMASTAR__ - s32Ret = MI_RGN_GetDisplayAttr(handle, &stChn, &stChnAttrCurrent); + s32Ret = MI_RGN_GetDisplayAttr(*handle, &stChn, &stChnAttrCurrent); +#elif defined(__INGENIC__) + s32Ret = IMP_OSD_GetGrpRgnAttr(*handle, 0, &stChnAttrCurrent); #else - s32Ret = HI_MPI_RGN_GetDisplayAttr(handle, &stChn, &stChnAttrCurrent); + s32Ret = HI_MPI_RGN_GetDisplayAttr(*handle, &stChn, &stChnAttrCurrent); #endif if (s32Ret) - fprintf(stderr, "[%s:%d]RGN_GetDisplayAttr failed with %#x %d, attaching...\n", __func__, __LINE__, s32Ret, handle); + fprintf(stderr, "[%s:%d]RGN_GetDisplayAttr failed with %#x %d, attaching...\n", __func__, __LINE__, s32Ret, *handle); +#ifndef __INGENIC__ #ifdef __SIGMASTAR__ else if (stChnAttrCurrent.stPoint.u32X != x || stChnAttrCurrent.stPoint.u32Y != y) #else else if (stChnAttrCurrent.unChnAttr.stOverlayChn.stPoint.s32X != x || stChnAttrCurrent.unChnAttr.stOverlayChn.stPoint.s32Y != y) #endif { - fprintf(stderr, "[%s:%d] Position has changed, detaching handle %d from channel %d...\n", __func__, __LINE__, s32Ret, handle, &stChn.s32ChnId); + fprintf(stderr, "[%s:%d] Position has changed, detaching handle %d from channel %d...\n", __func__, __LINE__, *handle, &stChn.s32ChnId); #ifdef __SIGMASTAR__ stChn.s32OutputPortId = 1; - MI_RGN_DetachFromChn(handle, &stChn); + MI_RGN_DetachFromChn(*handle, &stChn); stChn.s32OutputPortId = 0; - MI_RGN_DetachFromChn(handle, &stChn); + MI_RGN_DetachFromChn(*handle, &stChn); #else - HI_MPI_RGN_DetachFromChn(handle, &stChn); + HI_MPI_RGN_DetachFromChn(*handle, &stChn); #endif } +#endif #ifdef __SIGMASTAR__ memset(&stChnAttr, 0, sizeof(MI_RGN_ChnPortParam_t)); @@ -127,11 +155,19 @@ int create_region(int handle, int x, int y, int width, int height) stChnAttr.unPara.stOsdChnPort.stOsdAlphaAttr.eAlphaMode = E_MI_RGN_PIXEL_ALPHA; stChnAttr.unPara.stOsdChnPort.stOsdAlphaAttr.stAlphaPara.stArgb1555Alpha.u8BgAlpha = 0; stChnAttr.unPara.stOsdChnPort.stOsdAlphaAttr.stAlphaPara.stArgb1555Alpha.u8FgAlpha = 255; - // stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.bEnableColorInv = 0; - // stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.eInvertColorMode = E_MI_RGN_BELOW_LUMA_THRESHOLD; - // stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.u16LumaThreshold = 128; - // stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.u16WDivNum = stRegion.stOsdInitParam.stSize.u32Width * inv16; - // stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.u16HDivNum = stRegion.stOsdInitParam.stSize.u32Height * inv16; + + stChn.s32OutputPortId = 0; + MI_RGN_AttachToChn(*handle, &stChn, &stChnAttr); + stChn.s32OutputPortId = 1; + MI_RGN_AttachToChn(*handle, &stChn, &stChnAttr); +#elif defined(__INGENIC__) + memset(&stChnAttr, 0, sizeof(IMPOSDGrpRgnAttr)); + stChnAttr.show = 1; + stChnAttr.gAlphaEn = 1; + stChnAttr.fgAlhpa = 255; + + IMP_OSD_RegisterRgn(*handle, 0, &stChnAttr); + IMP_OSD_Start(0); #else memset(&stChnAttr, 0, sizeof(RGN_CHN_ATTR_S)); stChnAttr.bShow = 1; @@ -141,11 +177,6 @@ int create_region(int handle, int x, int y, int width, int height) stChnAttr.unChnAttr.stOverlayChn.stQpInfo.bQpDisable = 0; stChnAttr.unChnAttr.stOverlayChn.stQpInfo.bAbsQp = 0; stChnAttr.unChnAttr.stOverlayChn.stQpInfo.s32Qp = 0; - // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Height = width; - // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Width = height; - // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.u32LumThresh = 128; - // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.enChgMod = LESSTHAN_LUM_THRESH; - // stChnAttr.unChnAttr.stOverlayChn.stInvertColor.bInvColEn = 0; #ifndef __16CV300__ stChnAttr.unChnAttr.stOverlayChn.u16ColorLUT[0] = 0x3e0; stChnAttr.unChnAttr.stOverlayChn.u16ColorLUT[1] = 0x7FFF; @@ -154,15 +185,8 @@ int create_region(int handle, int x, int y, int width, int height) stChnAttr.unChnAttr.stOverlayChn.stPoint.s32X = x; stChnAttr.unChnAttr.stOverlayChn.stPoint.s32Y = y; stChnAttr.unChnAttr.stOverlayChn.u32Layer = 7; -#endif -#ifdef __SIGMASTAR__ - stChn.s32OutputPortId = 0; - MI_RGN_AttachToChn(handle, &stChn, &stChnAttr); - stChn.s32OutputPortId = 1; - MI_RGN_AttachToChn(handle, &stChn, &stChnAttr); -#else - HI_MPI_RGN_AttachToChn(handle, &stChn, &stChnAttr); + HI_MPI_RGN_AttachToChn(*handle, &stChn, &stChnAttr); #endif return s32Ret; @@ -293,10 +317,19 @@ int prepare_bitmap(const char *filename, BITMAP *bitmap, int bFil, unsigned int return 0; } -int set_bitmap(unsigned int handle, BITMAP *bitmap) +int set_bitmap(int handle, BITMAP *bitmap) { #ifdef __SIGMASTAR__ int s32Ret = MI_RGN_SetBitMap(handle, (MI_RGN_Bitmap_t *)(bitmap)); +#elif defined(__INGENIC__) + IMPOSDRgnAttr stRegion; + IMP_OSD_GetRgnAttr(handle, &stRegion); + stRegion.type = OSD_REG_PIC; + stRegion.rect.p1.x = stRegion.rect.p0.x + bitmap->u32Width - 1; + stRegion.rect.p1.y = stRegion.rect.p0.y + bitmap->u32Height - 1; + stRegion.fmt = bitmap->enPixelFormat; + stRegion.data.picData.pData = bitmap->pData; + int s32Ret = IMP_OSD_SetRgnAttr(handle, &stRegion); #else int s32Ret = HI_MPI_RGN_SetBitMap(handle, (BITMAP_S *)(bitmap)); #endif @@ -308,28 +341,33 @@ int set_bitmap(unsigned int handle, BITMAP *bitmap) return s32Ret; } -void unload_region(unsigned int handle) +void unload_region(int *handle) { #ifdef __SIGMASTAR__ MI_RGN_ChnPort_t stChn; -#else - MPP_CHN_S stChn; -#endif stChn.s32DevId = 0; stChn.s32ChnId = 0; -#ifdef __SIGMASTAR__ + stChn.eModId = E_MI_RGN_MODID_VPE; stChn.s32OutputPortId = 1; - MI_RGN_DetachFromChn(handle, &stChn); + MI_RGN_DetachFromChn(*handle, &stChn); stChn.s32OutputPortId = 0; - MI_RGN_DetachFromChn(handle, &stChn); - int s32Ret = MI_RGN_Destroy(handle); + MI_RGN_DetachFromChn(*handle, &stChn); + int s32Ret = MI_RGN_Destroy(*handle); +#elif defined(__INGENIC__) + IMP_OSD_UnRegisterRgn(*handle, 0); + IMP_OSD_DestroyRgn(*handle); + *handle = -1; + int s32Ret = 0; #else + MPP_CHN_S stChn; + stChn.s32DevId = 0; + stChn.s32ChnId = 0; + stChn.enModId = HI_ID_VENC; - HI_MPI_RGN_DetachFromChn(handle, &stChn); - int s32Ret = HI_MPI_RGN_Destroy(handle); + HI_MPI_RGN_DetachFromChn(*handle, &stChn); + int s32Ret = HI_MPI_RGN_Destroy(*handle); #endif - if (s32Ret) - fprintf(stderr, "[%s:%d]RGN_Destroy failed with %#x %d!\n", __func__, __LINE__, s32Ret, handle); + fprintf(stderr, "[%s:%d]RGN_Destroy failed with %#x %d!\n", __func__, __LINE__, s32Ret, *handle); } \ No newline at end of file diff --git a/osd/region.h b/osd/region.h index db40515..be12b30 100644 --- a/osd/region.h +++ b/osd/region.h @@ -11,10 +11,10 @@ extern "C" #include "common.h" #include "bitmap.h" - int create_region(int handle, int x, int y, int width, int height); + int create_region(int *handle, int x, int y, int width, int height); int prepare_bitmap(const char *filename, BITMAP *bitmap, int bFil, unsigned int u16FilColor, int enPixelFmt); - int set_bitmap(unsigned int handle, BITMAP *bitmap); - void unload_region(unsigned int handle); + int set_bitmap(int handle, BITMAP *bitmap); + void unload_region(int *handle); #ifdef __cplusplus #if __cplusplus diff --git a/osd/text.c b/osd/text.c index a6c1f4a..6def62c 100644 --- a/osd/text.c +++ b/osd/text.c @@ -102,9 +102,7 @@ static inline void calcdim(double *margin, double *height, double *width, const RECT measure_text(const char *font, double size, const char *text) { - char *path; - asprintf(&path, "/usr/share/fonts/truetype/%s.ttf", font); - loadfont(&sft, path, size, &lmtx); + loadfont(&sft, font, size, &lmtx); double margin, height, width; calcdim(&margin, &height, &width, text); @@ -120,9 +118,7 @@ RECT measure_text(const char *font, double size, const char *text) BITMAP raster_text(const char *font, double size, const char *text) { - char *path; - asprintf(&path, "/usr/share/fonts/truetype/%s.ttf", font); - loadfont(&sft, path, size, &lmtx); + loadfont(&sft, font, size, &lmtx); double margin, height, width; calcdim(&margin, &height, &width, text); diff --git a/sdk/infinity6/include/mi_sys.h b/sdk/infinity6/include/mi_sys.h index 5d39d02..3d89980 100644 --- a/sdk/infinity6/include/mi_sys.h +++ b/sdk/infinity6/include/mi_sys.h @@ -18,7 +18,7 @@ #include "mi_sys_datatype.h" #define SYS_MAJOR_VERSION 2 -#define SYS_SUB_VERSION 18.1 +#define SYS_SUB_VERSION 19 #define MACRO_TO_STR(macro) #macro #define SYS_VERSION_STR(major_version,sub_version) ({char *tmp = sub_version/100 ? \ "mi_sys_version_" MACRO_TO_STR(major_version)"." MACRO_TO_STR(sub_version) : sub_version/10 ? \ diff --git a/sdk/infinity6/include/mi_sys_datatype.h b/sdk/infinity6/include/mi_sys_datatype.h index 0777628..7c8c9a3 100644 --- a/sdk/infinity6/include/mi_sys_datatype.h +++ b/sdk/infinity6/include/mi_sys_datatype.h @@ -19,6 +19,9 @@ #define MI_SYS_MAX_OUTPUT_PORT_CNT (5) #define MI_SYS_MAX_DEV_CHN_CNT (48) #define MI_SYS_INVLAID_SEQUENCE_NUM ((MI_U32)-1) +#ifdef __INFINITY6E__ +#define MI_SYS_MAX_SUB_PLANE_CNT (4) +#endif //ensure that sizeof(MI_VB_PoolListConf_t) is less that 4096 !!! @@ -183,6 +186,9 @@ typedef enum E_MI_SYS_COMPRESS_MODE_SEG,//compress unit is 256 bytes as a segment E_MI_SYS_COMPRESS_MODE_LINE,//compress unit is the whole line E_MI_SYS_COMPRESS_MODE_FRAME,//compress unit is the whole frame +#ifdef __INFINITY6E__ + E_MI_SYS_COMPRESS_MODE_TO_8BIT, +#endif E_MI_SYS_COMPRESS_MODE_BUTT, //number }MI_SYS_CompressMode_e; @@ -217,6 +223,9 @@ typedef enum E_MI_SYS_BUFDATA_RAW = 0, E_MI_SYS_BUFDATA_FRAME, E_MI_SYS_BUFDATA_META, +#ifdef __INFINITY6E__ + E_MI_SYS_BUFDATA_MULTIPLANE +#endif } MI_SYS_BufDataType_e; typedef enum @@ -343,6 +352,28 @@ typedef struct MI_SYS_FrameData_s MI_SYS_WindowRect_t stContentCropWindow; } MI_SYS_FrameData_t; +#ifdef __INFINITY6E__ +typedef struct MI_SYS_FrameDataSubPlane_s +{ + MI_SYS_PixelFormat_e ePixelFormat; + MI_SYS_CompressMode_e eCompressMode; + MI_U64 u64FrameId; + + MI_U16 u16Width; + MI_U16 u16Height; + void* pVirAddr[2]; + MI_PHY phyAddr[2]; + MI_U16 u16Stride[2]; + MI_U32 u32BufSize; +} MI_SYS_FrameDataSubPlane_t; + +typedef struct MI_SYS_FrameDataMultiPlane_s +{ + MI_U8 u8SubPlaneNum; + MI_SYS_FrameDataSubPlane_t stSubPlanes[MI_SYS_MAX_SUB_PLANE_CNT]; +} MI_SYS_FrameDataMultiPlane_t; +#endif + typedef struct MI_SYS_BufInfo_s { MI_U64 u64Pts; diff --git a/sdk/ingenic/include/imp_audio.h b/sdk/ingenic/include/imp_audio.h new file mode 100644 index 0000000..8c85afc --- /dev/null +++ b/sdk/ingenic/include/imp_audio.h @@ -0,0 +1,1807 @@ +/* + * Audio utils header file. + * + * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __IMP_AUDIO_H__ +#define __IMP_AUDIO_H__ + +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * IMP audio input and output header file + */ + +/** + * @defgroup IMP_Audio + * @ingroup imp + * @brief audio module, including audio record and playback, audio encoding and decoding, volume and gain setting, (audio) echo cancellation, automatic gain function and so on + * + * @section audio_summary 1 overview + * Audio function includes 5 modules: audio input, audio output, audio echo cancellation, audio encoding and audio decoding. \n + * The existence of the audio input and audio output is the concept of the equipment and the channel, we all know that a MIC is a Device, and also can have multiple Channel input. \n + * Similarly a SPK is a playback Device, and can also have multiple Channel output. \n + * One Device supports only one Channel in this current version of the audio API. \n + * Audio echo cancellation is located in the audio input interface, explicit explanation is embodied in the functional description. \n + * Audio encoding, the current audio API can support such format audio coding: PT_G711A, PT_G711U and PT_G726 , when it comes to add a new encoding method, it is a must to register the encoder. \n +* Audio decoding, the current audio API can support such format audio coding: PT_G711A, PT_G711U and PT_G726 , when it comes to add a new decoding method, it is a must to register the decoder. \n + + * @section audio_function_description 2 + * The following is a detailed description of each module + + * @subsection audio_in 2.1 Audio input + * Audio input Device ID correspondence, 0: corresponding digital MIC; 1: corresponding simulation MIC \n + * Audio input Channel, the current API only supports single channel. \n + * Set the audio input volume, volume range: [-30 ~ 120]. - 30 represents mute, 120 represents the amplification of sound to 30dB, step 0.5dB. 60 means that the volume is set to a critical point,\n + * in that case ,software does not increase or decrease the volume, when the volume value is less than 60, for each drop of 1, the volume is reduced by 0.5dB; when the volume value is greater than 60, for each rise of 1 the volume is increased by 0.5dB. + + * @subsection audio_out 2.2 Audio output + * Audio output Device ID correspondence, 0: corresponding to the default SPK; 1: MIC corresponding to other SPK \n + * Audio output Channel,the current API only supports single channel. \n + * Set the audio output volume, volume range: [-30 ~ 120]. - 30 represents mute, 120 represents the amplification of sound to 30dB, step 0.5dB. 60 means that the volume is set to a critical point,\n + * in that case ,software does not increase or decrease the volume, when the volume value is less than 60, for each drop of 1, the volume is reduced by 0.5dB; when the volume value is greater than 60, for each rise of 1 the volume is increased by 0.5dB. + + * @subsection audio_aec 2.3 Audio echo cancellation(AEC) + * Audio echo cancellation function belongs to the audio input interface, so to enable echo cancellation, you must first enable audio input device and channel. \n + * Audio echo cancellation currently supports audio sampling rate of 8K and 16K. A frame data sample number is the multiple of 10ms audio data (e.g., 8K sampling rate, the data fed into: 8000 x 2 / 100 = 160byte integer multiple).\n + * Audio echo cancellation for different devices and different packages will have different sound effects. \n + * Adaptive support is not available in Audio Echo Cancellation (the AEC is not automatically configured), so for different devices there will be different echo cancellation parameters, \n + * The parameter file of the Audio echo cancellation is located in the /etc/webrtc_profile.ini configuration file. \n + + * The profile format is as follows (Main need to debug the three parameters): \n + * [Set_Far_Frame] \n + * Frame_V=0.3 \n + * [Set_Near_Frame] \n + * Frame_V=0.1 \n + * delay_ms=150 \n + * + * [Set_Far_Frame] represents the remote(far-end) parameter, the SPK represents the playback data parameters. \n + * Fram_V represents audio amplitude scaling, the playback data can be adjusted by adjusting these parameters (this is used only for echo cancellation). \n + * [Set_Near_Frame] represents the proximal(near-end) parameter, the MIC represents record data parameters. \n + * Fram_V represents the audio amplitude ratio, the adjustment of these parameters can adjust the amplitude of the recording data (this is only used for echo cancellation). \n + * Delay_ms, because of the delay between software and hardware, and the position between the SPK and MIC(they are placed at a certain distance), the SPK playback data will be processed by the MIC again. So, there will be some delay because the SPK data will have some impact on the MIC data. \n + * This time represents the time difference of the playback data in data recording. (delay to assure that there won't be any echo at all). \n + + * @subsection audio_enc 2.4 Audio encoding + * The current audio API supports PT_G711A, PT_G711U and PT_G726 format audio coding, if you need to add a new encoding method, you need to call the IMP_AENC_RegisterEncoder interface to register the encoder. + + * @subsection audio_dec 2.5 Audio decoding + * The current audio API supports PT_G711A, PT_G711U and PT_G726 format audio decoding, if you need to add a new decoding method, you need to call the IMP_ADEC_RegisterDecoder interface to register the decoder. + * @{ + */ + +/** + * Maximum number of audio frames + */ +#define MAX_AUDIO_FRAME_NUM 50 + +/** + * Audio stream blocking type + */ +typedef enum { + BLOCK = 0, /**< block */ + NOBLOCK = 1, /**< not block */ +} IMPBlock; + +/** + * Audio sampling rate definition. + */ +typedef enum { + AUDIO_SAMPLE_RATE_8000 = 8000, /**< 8KHz sampling rate */ + AUDIO_SAMPLE_RATE_16000 = 16000, /**< 16KHz sampling rate */ + AUDIO_SAMPLE_RATE_24000 = 24000, /**< 24KHz sampling rate */ + AUDIO_SAMPLE_RATE_32000 = 32000, /**< 32KHz sampling rate */ + AUDIO_SAMPLE_RATE_44100 = 44100, /**< 44.1KHz sampling rate */ + AUDIO_SAMPLE_RATE_48000 = 48000, /**< 48KHz sampling rate */ + AUDIO_SAMPLE_RATE_96000 = 96000, /**< 96KHz sampling rate */ +} IMPAudioSampleRate; + +/** + * Audio sampling precision definition. + */ +typedef enum { + AUDIO_BIT_WIDTH_16 = 16, /**< 16bit sampling precision*/ +} IMPAudioBitWidth; + +/** + * Audio channel mode definition. + */ +typedef enum { + AUDIO_SOUND_MODE_MONO = 1, /**< Single channel*/ + AUDIO_SOUND_MODE_STEREO = 2, /**< Double channel*/ +} IMPAudioSoundMode; + +/** + * Define audio payload type enumeration. + */ +typedef enum { + PT_PCM = 0, + PT_G711A = 1, + PT_G711U = 2, + PT_G726 = 3, + PT_AEC = 4, + PT_ADPCM = 5, + PT_MAX = 6, +} IMPAudioPalyloadType; + +/** + * Define the decoding method. + */ +typedef enum { + ADEC_MODE_PACK = 0, /**< Pack decoding*/ + ADEC_MODE_STREAM = 1, /**< Stream decoding*/ +} IMPAudioDecMode; + +/** + * Audio input and output device attribute. + */ +typedef struct { + IMPAudioSampleRate samplerate; /**< Audio sampling rate*/ + IMPAudioBitWidth bitwidth; /**< Audio sampling precision*/ + IMPAudioSoundMode soundmode; /**< Audio channel mode*/ + int frmNum; /**< Number of cached frames, range: [2, MAX_AUDIO_FRAME_NUM]*/ + int numPerFrm; /**< Number of sample points per frame */ + int chnCnt; /**< Number of channels supported*/ +} IMPAudioIOAttr; + +/** + * Audio frame structure. + */ +typedef struct { + IMPAudioBitWidth bitwidth; /**< Audio sampling precision*/ + IMPAudioSoundMode soundmode; /**< Audio channel mode*/ + uint32_t *virAddr; /**< Audio frame data virtual address*/ + uint32_t phyAddr; /**< Audio frame data physical address*/ + int64_t timeStamp; /**< Audio frame data time stamp*/ + int seq; /**< Audio frame data serial number*/ + int len; /**< Audio frame data length*/ +} IMPAudioFrame; + +/** + * Audio channel parameter structure. + */ +typedef struct { + int usrFrmDepth; /**< Audio frame buffer depth*/ + int Rev; /**< retain*/ +} IMPAudioIChnParam; + +/** + * Data cache state structure of audio output channel. + */ +typedef struct { + int chnTotalNum; /**< The total number of cached output channel*/ + int chnFreeNum; /**< Free cache blocks*/ + int chnBusyNum; /**< The number of cache be used*/ +} IMPAudioOChnState; + +/** + * Define audio stream structure. + */ +typedef struct { + uint8_t *stream; /**< Data stream pointer*/ + uint32_t phyAddr; /**< Data stream physical address*/ + int len; /**< Audio stream length*/ + int64_t timeStamp; /**< time stamp*/ + int seq; /**< Audio stream serial number*/ +} IMPAudioStream; + +/** + * Define audio encoding channel attribute structure. + */ +typedef struct { + IMPAudioPalyloadType type; /**< Audio payload data type*/ + int bufSize; /**< buf size, in order to frame the unit, [2 ~ MAX_AUDIO_FRAME_NUM]*/ + uint32_t *value; /**< Protocol attribute pointer*/ +} IMPAudioEncChnAttr; + +/** + * Define the encoder attribute structure. + */ +typedef struct { + IMPAudioPalyloadType type; /**< Encoding protocol type*/ + int maxFrmLen; /**< Maximum code stream length*/ + char name[16]; /**< encoder name */ + int (*openEncoder)(void *encoderAttr, void + *encoder); + int (*encoderFrm)(void *encoder, IMPAudioFrame + *data, unsigned char *outbuf,int *outLen); + int (*closeEncoder)(void *encoder); +} IMPAudioEncEncoder; + +/** + * Define the decoded channel attribute structure. + */ +typedef struct { + IMPAudioPalyloadType type; /**< Audio decoding protocol type*/ + int bufSize; /**< Audio decoder cache size*/ + IMPAudioDecMode mode; /**< Decoding mode*/ + void *value; /**< Specific protocol attribute pointer*/ +} IMPAudioDecChnAttr; + +/** + * Define decoder attribute structure. + */ +typedef struct { + IMPAudioPalyloadType type; /**< Audio decoding protocol type*/ + char name[16]; /**< Audio encoder name*/ + int (*openDecoder)(void *decoderAttr, void + *decoder); + int (*decodeFrm)(void *decoder, unsigned char + *inbuf,int inLen, unsigned short *outbuf,int + *outLen,int *chns); + int (*getFrmInfo)(void *decoder, void *info); + int (*closeDecoder)(void *decoder); +} IMPAudioDecDecoder; + +/** + * Define AGC gain structure. + */ +typedef struct { + int TargetLevelDbfs; /**< Gain level, the value of [0, 31], this refers to the target volume level, the unit is dB, is negative value. The smaller the value, the greater the volume.*/ + int CompressionGaindB; /**< Set the maximum gain value, [0, 90], 0 represents no gain, the greater the value, the higher the gain.*/ +} IMPAudioAgcConfig; + +enum Agc_mode { + kAgcModeAdaptiveAnalog = 1, + kAgcModeAdaptiveDigital, + kAgcModeFixedDigital +}; + +/** + * Defines level of noise suppression. + */ +enum Level_ns { + NS_LOW, /**< Low level noise suppression*/ + NS_MODERATE, /**< Medium level noise suppression*/ + NS_HIGH, /**< High level noise suppression*/ + NS_VERYHIGH /**< Maximum level noise suppression*/ +}; + +/** + * @fn int IMP_AI_SetPubAttr(int audioDevId, IMPAudioIOAttr *attr) + * + * Set audio input device attribute. + * + * @param[in] audioDevId Audio device number + * @param[in] attr Audio device attribute pointer + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks Sample code + * @code + * int devID = 1; + * IMPAudioIOAttr attr; + * attr.samplerate = AUDIO_SAMPLE_RATE_8000; + * attr.bitwidth = AUDIO_BIT_WIDTH_16; + * attr.soundmode = AUDIO_SOUND_MODE_MONO; + * attr.frmNum = 20; + * attr.numPerFrm = 400; + * attr.chnCnt = 1; + * ret = IMP_AI_SetPubAttr(devID, &attr); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "Set Audio in %d attr err: %d\n", devID, ret); + * return ret; + * } + * @endcode + * + * @attention Need to be called before IMP_AI_Enable. + */ +int IMP_AI_SetPubAttr(int audioDevId, IMPAudioIOAttr *attr); + +/** + * @fn int IMP_AI_GetPubAttr(int audioDevId, IMPAudioIOAttr *attr) + * + * Get the attribute of the audio input device + * + * @param[in] audioDevId Audio device number + * @param[out] attr Audio device attribute pointer + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AI_GetPubAttr(int audioDevId, IMPAudioIOAttr *attr); + +/** + * @fn int IMP_AI_Enable(int audioDevId) + * + * Enable audio input device. + * + * @param[in] audioDevId Audio device number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AI_Enable(int audioDevId); + +/** + * @fn int IMP_AI_Disable(int audioDevId) + * + * Disable audio input device + * + * @param[in] audioDevId Audio device number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention It supports the use of IMP_AI_Enable. IMP_AI_Disable must be performed before putting the system in sleeping mode. + */ +int IMP_AI_Disable(int audioDevId); + +/** + * @fn int IMP_AI_EnableChn(int audioDevId, int aiChn) + * + * Enable audio input channel + * + * @param[in] audioDevId Audio device number + * @param[in] aiChn Audio input channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention Must first enable device. + */ +int IMP_AI_EnableChn(int audioDevId, int aiChn); + +/** + * @fn int IMP_AI_DisableChn(int audioDevId, int aiChn) + * + * Disable audio input channel + * + * @param[in] audioDevId Audio device number + * @param[in] aiChn Audio input channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention It supports the use of IMP_AI_EnableChn. + */ +int IMP_AI_DisableChn(int audioDevId, int aiChn); + +/** + * @fn int IMP_AI_PollingFrame(int audioDevId, int aiChn, unsigned int timeout_ms) + * + * Polling audio stream cache. + * + * @param[in] audioDevId Audio device number + * @param[in] aiChn Audio input channel number + * @param[in] timeout_ms Polling timeout time. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention Use the interface before using IMP_AI_GetFrame, and when the interface is called successfully, then the audio data is ready, and you can use IMP_AI_GetFrame to get audio data. + */ +int IMP_AI_PollingFrame(int audioDevId, int aiChn, unsigned int timeout_ms); + +/** + * @fn int IMP_AI_GetFrame(int audioDevId, int aiChn, IMPAudioFrame *frm, IMPBlock block) + * + * Get audio frame. + * + * @param[in] audioDevId Audio device number + * @param[in] aiChn Audio input channel number + * @param[out] frm Audio frame structure pointer. + * @param[in] block Blocking / non blocking identifier. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks Sample code + * @code + * IMPAudioFrame frm; + * // Get audio frame + * ret = IMP_AI_GetFrame(devID, chnID, &frm, BLOCK); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "Audio Get Frame Data error\n"); + * return ret; + * } + * + * fwrite(frm.virAddr, 1, frm.len, record_file); // use audio frame data + * + * // Release audio frame + * ret = IMP_AI_ReleaseFrame(devID, chnID, &frm); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "Audio release frame data error\n"); + * return ret; + * } + * @endcode + * + * @attention no. + */ +int IMP_AI_GetFrame(int audioDevId, int aiChn, IMPAudioFrame *frm, IMPBlock block); + +/** + * @fn int IMP_AI_ReleaseFrame(int audioDevId, int aiChn, IMPAudioFrame *frm) + * + * Release audio frame + * + * @param[in] audioDevId Audio device number + * @param[in] aiChn Audio input channel number + * @param[in] frm Audio frame structure pointer + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention It supports the use of IMP_AI_GetFrame. + */ +int IMP_AI_ReleaseFrame(int audioDevId, int aiChn, IMPAudioFrame *frm); + +/** + * @fn int IMP_AI_SetChnParam(int audioDevId, int aiChn, IMPAudioIChnParam *chnParam) + * + * Set audio input channel parameters. + * + * @param[in] audioDevId Audio device number + * @param[in] aiChn audio input channel number + * @param[in] chnParam audio frame structure pointer + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks sample code + * @code + * int chnID = 0; + * IMPAudioIChnParam chnParam; + * chnParam.usrFrmDepth = 20; + * ret = IMP_AI_SetChnParam(devID, chnID, &chnParam); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "set ai %d channel %d attr err: %d\n", devID, chnID, ret); + * return ret; + * } + * @endcode + * + * @attention Supporting the use of IMP_AI_EnableChn. + */ +int IMP_AI_SetChnParam(int audioDevId, int aiChn, IMPAudioIChnParam *chnParam); + +/** + * @fn int IMP_AI_GetChnParam(int audioDevId, int aiChn, IMPAudioIChnParam *chnParam) + * + * Set audio input channel parameters + * + * @param[in] audioDevId audio device number + * @param[in] aiChn audio input channel number + * @param[out] chnParam audio channel parameters + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AI_GetChnParam(int audioDevId, int aiChn, IMPAudioIChnParam *chnParam); + +/** + * @fn int IMP_AI_EnableAec(int aiDevId, int aiChn, int aoDevId, int aoChn) + * + * Enable audio echo cancellation feature of the specified audio input and audio output. + * + * @param[in] aiDevId Need to perform audio echo cancellation of the audio input device number. + * @param[in] aiChn Need to perform audio echo cancellation of the audio input channel number. + * @param[in] aoDevId Need to perform audio echo cancellation of the audio output device number. + * @param[in] aoChn Need to perform audio echo cancellation of the audio output channel number. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks The Audio echo cancellation for different devices and different packages will have different sound effects. + * @remarks Adaptive support is not available in Audio Echo Cancellation (the AEC is not automatically configured), so for different devices there will be different echo cancellation parameters, \n + * @remarks Only use the functional effect is not really good. + * @remarks The parameter file of the Audio echo cancellation is located in the /etc/webrtc_profile.ini configuration file. \n + + * @remarks The profile format is as follows (Main need to debug the three parameters): \n + * @remarks [Set_Far_Frame] \n + * @remarks Frame_V=0.3 \n + * @remarks [Set_Near_Frame] \n + * @remarks Frame_V=0.1 \n + * @remarks delay_ms=150 \n + * + * @remarks [Set_Far_Frame] represents the remote(far-end) parameter, the SPK represents the playback data parameters. \n + * @remarks Fram_V represents audio amplitude scaling, the playback data can be adjusted by adjusting these parameters (this is used only for echo cancellation). \n + * @remarks [Set_Near_Frame] represents the proximal(near-end) parameter, the MIC represents record data parameters. \n + * @remarks Fram_V represents the audio amplitude ratio, the adjustment of these parameters can adjust the amplitude of the recording data (this is only used for echo cancellation). \n + * @remarks Delay_ms, because of the delay between software and hardware, and the position between the SPK and MIC(they are placed at a certain distance), the SPK playback data will be processed by the MIC again. So, there will be some delay because the SPK data will have some impact on the MIC data. \n + * @remarks This time represents the time difference of the playback data in data recording. (delay to assure that there won't be any echo at all). \n + * + * @attention In fact, the interface will only check for aiDevId and aiChn, but it is better to enabele these two channels at the same time and then call the current one. \n + * when the audio input channel is closed, the Audio Echo Cancellation feature also is turned off. In case of using it again, you will have to turn it on. + */ +int IMP_AI_EnableAec(int aiDevId, int aiChn, int aoDevId, int aoChn); + +/** +@fn int IMP_AI_Set_WebrtcProfileIni_Path(char *path) +*Set AEC profile " webrtc_profile.ini" pass. + +*path parameter:It is used to set the path of the configuration file. + +For example, the user wants to place the configuration file in the /system directory: IMP_AI_Set_WebrtcProfileIni_Path("/system"); + +*This function must be in IMP_AI_EnableAec(int aiDevId, int aiChn, int aoDevId, int aoChn)before used。 + +*return value 0 +*/ +int IMP_AI_Set_WebrtcProfileIni_Path(char *path); + +/** + * @fn int IMP_AI_DisableAec(int aiDevId, int aiChn) + * + * Disable audio echo cancellation feature. + * + * @param[in] aiDevId Audio input device number + * @param[in] aiChn audio input channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AI_DisableAec(int aiDevId, int aiChn); + +/** + * @fn int IMP_AI_EnableNs(IMPAudioIOAttr *attr, int mode) + * + * Enable specified audio input noise suppression. + * + * @param[in] attr Noise suppression is required for the audio attribute. + * @param[in] mode Noise suppression level 0 ~ 3, see Level_ns. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks The mode parameter of noise suppression represents the noise suppression level (range [0 ~ 3]), the higher the level, the cleaner the noise suppression. + * @remarks However, The cleaner the noise is, more details of the sound will be lost, here we have a contradiction so we need to make tradeoff while processing the noise suppression. + * + * @attention Audio echo cancellation contains the noise suppression function, if the audio echo cancellation is enabled, it is not required to enable the noise suppression. + */ +int IMP_AI_EnableNs(IMPAudioIOAttr *attr, int mode); + +/** + * @fn int IMP_AI_DisableNs(void) + * + * Disable noise suppression + * + * @param no. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AI_DisableNs(void); + +/** + * @fn int IMP_AI_SetAgcMode(int mode); + + * Set the agc working mode. + + * @param[in] mode agc working mode selection, see Agc_mode definition. + + * @retval 0 success. + * @retval non-0 failure. + + * @remarks It should be noted that the agcmode setting needs to be enabled before the agc function. + + */ +int IMP_AI_SetAgcMode(int mode); + +/** + * @fn int IMP_AI_EnableAgc(IMPAudioIOAttr *attr, IMPAudioAgcConfig agcConfig) + * + * Enable automatic gain of audio input. + * + * @param[in] attr Requires automatic gain of the audio attribute. + * @param[in] agcConfig Automatic gain parameter configuration, configuration magnification. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks Note the configuration of the AGC. agcConfig amplification's main parameters have their own configuration, check the specific gain IMPAudioAgcConfig instructions. + * @remarks Note that AGC can gain sound amplification, but if the gain parameter is not appropriate, it will lead to broken noise, please adjust carefully the parameters. + * + * @attention Audio echo cancellation contains the AGC function, which means it is not required to perform automatic gain if the echo cancellation is enabled. + */ +int IMP_AI_EnableAgc(IMPAudioIOAttr *attr, IMPAudioAgcConfig agcConfig); + +/** + * @fn int IMP_AI_DisableAgc(void) + * + * Disable AI automatic gain feature. + * + * @param no. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AI_DisableAgc(void); + +/** + * @fn int IMP_AO_EnableAgc(IMPAudioIOAttr *attr, IMPAudioAgcConfig agcConfig) + * + * Enable audio output automatic gain feature. + * + * @param[in] attr need automatic gain of the audio attribute. + * @param[in] agcConfig automatic gain parameter configuration, configuration magnification. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks agcConfig amplification's main parameters have their own configuration, check the specific gain IMPAudioAgcConfig instructions. + * @remarks Note that AGC can gain sound amplification, but if the gain parameter is not appropriate, it will lead to broken noise, please adjust carefully the parameters. + * + * @attention Audio echo cancellation contains the AGC function, which means it is not required to perform automatic gain if the echo cancellation is enabled. + */ +int IMP_AO_EnableAgc(IMPAudioIOAttr *attr, IMPAudioAgcConfig agcConfig); + +/** + * @fn int IMP_AO_DisableAgc(void) + * + * Disable AO automatic gain feature. + * + * @param no. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_DisableAgc(void); + +/** + * @fn int IMP_AI_EnableHpf(IMPAudioIOAttr *attr) + * + * Enable audio input for high pass filtering. + * + * @param[in] attr need high pass filtering of audio attribute. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention Audio echo cancellation contains the HPF function, if Audio Echo Cancellation is enabled, so HPF will be automatically enabled. + */ +int IMP_AI_EnableHpf(IMPAudioIOAttr *attr); + +/** + * @fn int IMP_AI_SetHpfCoFrequency(int cofrequency) + * + * Set the cut-off frequency of high pass filtering for audio input. + * + * @param[in] cofrequency the cut-off frequency of high pass filter. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention while enabling the high-pass filter for audio input,setting the cut-off frequency of the high-pass filter first. + */ +int IMP_AI_SetHpfCoFrequency(int cofrequency); + +/** + * @fn int IMP_AI_DisableHpf(void) + * + * Disable AI high pass filtering function. + * + * @param no. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AI_DisableHpf(void); + +/** + * @fn int IMP_AO_EnableHpf(IMPAudioIOAttr *attr) + * + * Enable audio output for high pass filtering. + * + * @param[in] attr need high pass filtering of audio attribute. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention Audio echo cancellation contains the HPF function, if audio echo cancellation is enabled, so you do not need to enable HPF. + */ +int IMP_AO_EnableHpf(IMPAudioIOAttr *attr); + +/** + * @fn int IMP_AO_SetHpfCoFrequency(int cofrequency) + * + * Set the cut-off frequency of high pass filtering for audio output. + * + * @param[in] cofrequency the cut-off frequency of high pass filter. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention while enabling the high-pass filter for audio output,setting the cut-off frequency of the high-pass filter first. + */ +int IMP_AO_SetHpfCoFrequency(int cofrequency); + +/** + * @fn int IMP_AO_DisableHpf(void) + * + * Disable AO high pass filtering function. + * + * @param no. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_DisableHpf(void); + +/** + * @fn int IMP_AO_SetPubAttr(int audioDevId, IMPAudioIOAttr *attr) + * + * Set audio input and output device attribute. + * + * @param[in] audioDevId audio device number + * @param[in] attr audio output device attribute pointer + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_SetPubAttr(int audioDevId, IMPAudioIOAttr *attr); + +/** + * @fn int IMP_AO_GetPubAttr(int audioDevId, IMPAudioIOAttr *attr) + * + * Get audio input and output device attribute. + * + * @param[in] audioDevId audio device number + * @param[out] attr audio output device attribute pointer + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_GetPubAttr(int audioDevId, IMPAudioIOAttr *attr); + +/** + * @fn int IMP_AO_Enable(int audioDevId) + * + * Enable audio output device + * + * @param[in] audioDevId audio device number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention The IMP_AO_SetPubAttr. must be called before + */ +int IMP_AO_Enable(int audioDevId); + +/** + * @fn int IMP_AO_Disable(int audioDevId) + * + * Disable audio output device + * + * @param[in] audioDevId audio device number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_Disable(int audioDevId); + +/** + * @fn int IMP_AO_EnableChn(int audioDevId, int aoChn) + * + * Enable audio output channel + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_EnableChn(int audioDevId, int aoChn); + +/** + * @fn int IMP_AO_DisableChn(int audioDevId, int aoChn) + * + * Disable audio output channel + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_DisableChn(int audioDevId, int aoChn); + +/** + * @fn int IMP_AO_SendFrame(int audioDevId, int aoChn, IMPAudioFrame *data, IMPBlock block) + * + * Send audio output frame. + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * @param[in] data audio frame sturcture pointer + * @param[in] block Blocking / non blocking identifier. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks sample code + * @code + * while(1) { + * size = fread(buf, 1, IMP_AUDIO_BUF_SIZE, play_file); + * if(size < IMP_AUDIO_BUF_SIZE) + * break; + * + * IMPAudioFrame frm; + * frm.virAddr = (uint32_t *)buf; + * frm.len = size; + * ret = IMP_AO_SendFrame(devID, chnID, &frm, BLOCK); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "send Frame Data error\n"); + * return ret; + * } + * } + * @endcode + * + * @attention no. + */ +int IMP_AO_SendFrame(int audioDevId, int aoChn, IMPAudioFrame *data, IMPBlock block); + +/** + * @fn int IMP_AO_PauseChn(int audioDevId, int aoChn) + * + * Pause audio output channel + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_PauseChn(int audioDevId, int aoChn); + +/** + * @fn int IMP_AO_ResumeChn(int audioDevId, int aoChn) + * + * Resume audio output channel + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_ResumeChn(int audioDevId, int aoChn); + +/** + * @fn int IMP_AO_ClearChnBuf(int audioDevId, int aoChn) + * + * Clear the current audio data cache in the audio output channel. + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_ClearChnBuf(int audioDevId, int aoChn); + +/** + * @fn int IMP_AO_QueryChnStat(int audioDevId, int aoChn, IMPAudioOChnState *status) + * + * Query the current audio data cache status in the audio output channel. + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * @param[out] status Cache state structure pointer. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ +int IMP_AO_QueryChnStat(int audioDevId, int aoChn, IMPAudioOChnState *status); + +/** + * @fn int IMP_AENC_CreateChn(int aeChn, IMPAudioEncChnAttr *attr) + * + * Create audio encode channel. + * + * @param[in] aeChn channel number + * @param[in] attr Audio encode channel attribute pointer. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks sample code + * @code + * int AeChn = 0; + * IMPAudioEncChnAttr attr; + * attr.type = PT_G711A; + * attr.bufSize = 20; + * ret = IMP_AENC_CreateChn(AeChn, &attr); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "Audio encode create channel failed\n"); + * return ret; + * } + * @endcode + * + * @attention The Current SDK supports PT_G711A, PT_G711U and PT_G726 encoding. \n + * So the use of SDK encoding, only needs attr.type = PT_G711A. \n + * How to use a custom encoder? You need to register the encoder, the sample code is in the registration interface instructions. + */ + int IMP_AENC_CreateChn(int aeChn, IMPAudioEncChnAttr *attr); + +/** + * @fn int IMP_AENC_DestroyChn(int aeChn) + * + * Destory audio encode channel + * + * @param[in] aeChn channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention Supporting the use of IMP_AENC_CreateChn. + */ + int IMP_AENC_DestroyChn(int aeChn); + +/** + * @fn int IMP_AENC_SendFrame(int aeChn, IMPAudioFrame *frm) + * + * Send audio encoding audio frame + * + * @param[in] aeChn channel number + * @param[in] frm Audio frame structure pointer. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks sample code + * @code + * while(1) { + * // Read a frame of data + * ret = fread(buf_pcm, 1, IMP_AUDIO_BUF_SIZE, file_pcm); + * if(ret < IMP_AUDIO_BUF_SIZE) + * break; + * + * // encode + * IMPAudioFrame frm; + * frm.virAddr = (uint32_t *)buf_pcm; + * frm.len = ret; + * ret = IMP_AENC_SendFrame(AeChn, &frm); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "imp audio encode send frame failed\n"); + * return ret; + * } + * + * // Get encode stream + * IMPAudioStream stream; + * ret = IMP_AENC_GetStream(AeChn, &stream, BLOCK); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "imp audio encode get stream failed\n"); + * return ret; + * } + * + * // Use encode stream + * fwrite(stream.stream, 1, stream.len, file_g711); + * + * // Release encode stream + * ret = IMP_AENC_ReleaseStream(AeChn, &stream); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "imp audio encode release stream failed\n"); + * return ret; + * } + * } + * @endcode + * + * @attention no. + */ + int IMP_AENC_SendFrame(int aeChn, IMPAudioFrame *frm); + +/** + * @fn int IMP_AENC_PollingStream(int AeChn, unsigned int timeout_ms) + * + * Polling encoded audio stream cache. + * + * @param[in] AeChn Audio encoding input channel number. + * @param[in] timeout_ms Polling timeout time + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention The current interface is used before using IMP_AENC_GetStream. After calling successfully the current interface, we will have the audio encoding data ready then you can use the IMP_AENC_GetStream to get the encoded data. + */ +int IMP_AENC_PollingStream(int AeChn, unsigned int timeout_ms); + +/** + * @fn int IMP_AENC_GetStream(int aeChn, IMPAudioStream *stream ,IMPBlock block) + * + * Get the encoded stream. + * + * @param[in] aeChn channel number + * @param[in] stream Get audio encoding + * @param[in] block Blocking / non blocking identifier. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks see the IMP_AENC_SendFrame function description for deeper understanding. + * + * @attention no. + */ + int IMP_AENC_GetStream(int aeChn, IMPAudioStream *stream ,IMPBlock block); + +/** + * @fn int IMP_AENC_ReleaseStream(int aeChn,IMPAudioStream *stream) + * + * Releases the stream from the audio encoding channel. + * + * @param[in] aeChn channel number + * @param[in] stream Get audio stream pointer + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks see the IMP_AENC_SendFrame function description. + * + * @attention no. + */ + int IMP_AENC_ReleaseStream(int aeChn,IMPAudioStream *stream); + +/** + * @fn int IMP_AENC_RegisterEncoder(int *handle, IMPAudioEncEncoder *encoder) + * + * Register encoder + * + * @param[in] ps32handle register handle + * @param[in] encoder Encoder attribute structure. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks sample code + * @code + * int handle_g711a = 0; + * IMPAudioEncEncoder my_encoder; + * my_encoder.maxFrmLen = 1024; + * sprintf(my_encoder.name, "%s", "MY_G711A"); + * my_encoder.openEncoder = NULL; // Encoder callback function + * my_encoder.encoderFrm = MY_G711A_Encode_Frm; // Encoder callback function + * my_encoder.closeEncoder = NULL; // Encoder callback function + * + * ret = IMP_AENC_RegisterEncoder(&handle_g711a, &my_encoder); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "IMP_AENC_RegisterEncoder failed\n"); + * return ret; + * } + * + * // use encoder + * int AeChn = 0; + * IMPAudioEncChnAttr attr; + * attr.type = handle_g711a; // The encoder type is equal to the value of the handle_g711a returned by the successfully registered. + * attr.bufSize = 20; + * ret = IMP_AENC_CreateChn(AeChn, &attr); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "imp audio encode create channel failed\n"); + * return ret; + * } + * @endcode + * + * @attention After registration, the use of the method and the use of SDK in the encoder are all the same. (After registration, clients' methods and SDK prebuilt functions are considered as the SDK functions, that means the clients can change the content of the SDK as they wish) + */ + int IMP_AENC_RegisterEncoder(int *handle, IMPAudioEncEncoder *encoder); + +/** + * @fn int IMP_AENC_UnRegisterEncoder(int *handle) + * + * Release encoder + * + * @param[in] ps32handle Register handle (the handle obtained at the time of registration of the encoder). + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ + int IMP_AENC_UnRegisterEncoder(int *handle); + +/** + * @fn int IMP_ADEC_CreateChn(int adChn, IMPAudioDecChnAttr *attr) + * + * Create audio decode channel + * + * @param[in] adChn channel number + * @param[in] attr Channel attribute pointer. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks sample code + * @code + * int adChn = 0; + * IMPAudioDecChnAttr attr; + * attr.type = PT_G711A; + * attr.bufSize = 20; + * attr.mode = ADEC_MODE_PACK; + * ret = IMP_ADEC_CreateChn(adChn, &attr); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "imp audio decoder create channel failed\n"); + * return ret; + * } + * @endcode + * + * @attention no. + */ + int IMP_ADEC_CreateChn(int adChn, IMPAudioDecChnAttr *attr); + +/** + * @fn int IMP_ADEC_DestroyChn(int adChn) + * + * Destory audio decoding channel + * + * @param[in] adChn channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ + int IMP_ADEC_DestroyChn(int adChn); + +/** + * @fn int IMP_ADEC_SendStream(int adChn, IMPAudioStream *stream, IMPBlock block) + * + * Send audio stream to audio decoding channel. + * + * @param[in] adChn channel number + * @param[in] stream audio stream + * @param[in] block Blocking / non blocking identifier. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks sample code + * @code + * while(1) { + * // Get the data that needs to be decoded + * ret = fread(buf_g711, 1, IMP_AUDIO_BUF_SIZE/2, file_g711); + * if(ret < IMP_AUDIO_BUF_SIZE/2) + * break; + * + * // Send decoding stream + * IMPAudioStream stream_in; + * stream_in.stream = (uint8_t *)buf_g711; + * stream_in.len = ret; + * ret = IMP_ADEC_SendStream(adChn, &stream_in, BLOCK); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "imp audio encode send frame failed\n"); + * return ret; + * } + * + * // Get decoded data + * IMPAudioStream stream_out; + * ret = IMP_ADEC_GetStream(adChn, &stream_out, BLOCK); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "imp audio decoder get stream failed\n"); + * return ret; + * } + * + * // Use decoded data + * fwrite(stream_out.stream, 1, stream_out.len, file_pcm); + * + * // Release decoded data + * ret = IMP_ADEC_ReleaseStream(adChn, &stream_out); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "imp audio decoder release stream failed\n"); + * return ret; + * } + * } + * @endcode + * + * @attention no. + */ + int IMP_ADEC_SendStream(int adChn, IMPAudioStream *stream, IMPBlock block); + +/** + * @fn int IMP_ADEC_PollingStream(int AdChn, unsigned int timeout_ms) + * + * Polling decode audio stream cache. + * + * @param[in] AdChn audio decode input channel number + * @param[in] timeout_ms polling timeout time + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention The current interface is used before using IMP_ADEC_GetStream. After calling successfully the current interface, we will have the audio encoding data ready then you can use the IMP_ADEC_GetStream to get the encoded data. + */ +int IMP_ADEC_PollingStream(int AdChn, unsigned int timeout_ms); + +/** + * @fn int IMP_ADEC_GetStream(int adChn, IMPAudioStream *stream ,IMPBlock block) + * + * Get the decoded stream. + * + * @param[in] adChn channel number + * @param[in] stream Get decoded stream + * @param[in] block Blocking / non blocking identifier. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks See the IMP_ADEC_SendFrame function description for further instructions. + * + * @attention no. + */ +int IMP_ADEC_GetStream(int adChn, IMPAudioStream *stream ,IMPBlock block); + +/** + * @fn int IMP_ADEC_ReleaseStream(int adChn,IMPAudioStream *stream) + * + * Release of the stream from the audio decoding channel. + * + * @param[in] adChn channel number + * @param[in] stream audio stream pointer + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks See the IMP_ADEC_SendFrame function description. + * + * @attention no. + */ +int IMP_ADEC_ReleaseStream(int adChn,IMPAudioStream *stream); + +/** + * @fn int IMP_ADEC_ClearChnBuf(int adChn) + * + * Clears the current audio data cache in the audio decode channel. + * + * @param[in] adChn channel number + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ + int IMP_ADEC_ClearChnBuf(int adChn); + +/** + * @fn int IMP_ADEC_RegisterDecoder(int *handle, IMPAudioDecDecoder *decoder) + * + * Register decoder + * + * @param[in] ps32handle register handle + * @param[in] decoder Decoder attributes structure. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks sample code + * @code + * int handle_g711a = 0; + * IMPAudioDecDecoder my_decoder; + * sprintf(my_decoder.name, "%s", "MY_G711A"); + * my_decoder.openDecoder = NULL; // Decoder callback function + * my_decoder.decodeFrm = MY_G711A_Decode_Frm; // Decoder callback function + * my_decoder.getFrmInfo = NULL; // Decoder callback function + * my_decoder.closeDecoder = NULL; // Decoder callback function + * + * // Register decoder + * ret = IMP_ADEC_RegisterDecoder(&handle_g711a, &my_decoder); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "IMP_ADEC_RegisterDecoder failed\n"); + * return ret; + * } + * + * // use decoder + * int adChn = 0; + * IMPAudioDecChnAttr attr; + * attr.type = handle_g711a; // The encoder type is equal to the value of the handle_g711a returned by the successfully registered. + * attr.bufSize = 20; + * attr.mode = ADEC_MODE_PACK; + * // create decode channel + * ret = IMP_ADEC_CreateChn(adChn, &attr); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "imp audio decoder create channel failed\n"); + * return ret; + * } + * @endcode + * + * @attention After registration, the use of the method as well as the use of SDK comes with an decoder. + * @attention After registration, the use of the method and the use of SDK in the decoder are all the same. (After registration, clients' methods and SDK prebuilt functions are considered as the SDK functions, that means the clients can change the content of the SDK as they wish) + */ + int IMP_ADEC_RegisterDecoder(int *handle, IMPAudioDecDecoder *decoder); + +/** + * @fn int IMP_ADEC_UnRegisterDecoder(int *handle) + * + * Unregister Decoder + * + * @param[in] ps32handle Register handle (the handle obtained at the time of registration of the decoder). + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ + int IMP_ADEC_UnRegisterDecoder(int *handle); + +/** + * ACODEC configuration. + */ +/** + * @fn int IMP_AI_SetVol(int audioDevId, int aiChn, int aiVol) + * + * Set audio input volume. + * + * @param[in] aiDevId audio input device number + * @param[in] aiChn audio input channel number + * @param[in] aiVol audio input volume + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks volume in the range of [-30 ~ 120]. - 30 represents mute, 120 is to amplify the sound of to 30dB, step 0.5dB. + * @remarks 60 is to set the volume to a critical point. In this case, the software does not increase or decrease the volume, when the volume value is less than 60, for each drop of 1, the volume is decreased by 0.5dB; when the volume value is greater than 60, for each rise of 1, the volume is increased by 0.5dB. + * + * sample code + * @code + * int volume = 60; + * ret = IMP_AI_SetVol(devID, chnID, volume); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "Audio Record set volume failed\n"); + * return ret; + * } + * @endcode + * @attention If the input of the aiVol exceeds the range of [-30 ~ 120]. when it is less than -30 it will take -30 as value, more than 120 it will be considered as 120. + */ + int IMP_AI_SetVol(int audioDevId, int aiChn, int aiVol); + +/** + * @fn int IMP_AI_GetVol(int audioDevId, int aiChn, int *vol) + * + * Get the volume of the audio input. + * + * @param[in] aiDevId Audio input device number + * @param[in] aiChn Audio input channel number + * @param[out] vol audio input volume + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ + int IMP_AI_GetVol(int audioDevId, int aiChn, int *vol); + +/** + * @fn int IMP_AI_SetVolMute(int audioDevId, int aiChn, int mute) + * + * Set audio input mute. + * + * @param[in] aiDevId Audio input device number + * @param[in] aiChn Audio input channel number + * @param[out] mute Audio input mute flag, mute = 0: off mute, mute = 1: on mute. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks By calling the interface, it can be muted immediately. + * + * @attention no. + */ + int IMP_AI_SetVolMute(int audioDevId, int aiChn, int mute); + +/** + * @fn int IMP_AO_SetVol(int audioDevId, int aoChn, int aoVol) + * + * Set audio output channel volume. + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * @param[in] aoVol audio output volume + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks volume in the range of [-30 ~ 120]. - 30 represents mute, 120 is to amplify the sound of to 30dB, step 0.5dB. + * @remarks 60 is to set the volume to a critical point. In this case, the software does not increase or decrease the volume, when the volume value is less than 60, for each drop of 1, the volume is decreased by 0.5dB; when the volume value is greater than 60, for each rise of 1, the volume is increased by 0.5dB. + * + * @attention If the input of the aiVol exceeds the range of [-30 ~ 120], when it is less than -30 it will take -30 as value , more than 120 it will be 120. + */ + int IMP_AO_SetVol(int audioDevId, int aoChn, int aoVol); + +/** + * @fn int IMP_AO_GetVol(int audioDevId, int aoChn, int *vol) + * + * Get audio output channel volume. + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * @param[out] aoVol audio output volume + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ + int IMP_AO_GetVol(int audioDevId, int aoChn, int *vol); + +/** + * @fn int IMP_AO_SetVolMute(int audioDevId, int aoChn, int mute) + * + * Set audio output mute + * + * @param[in] audioDevId audio device number + * @param[in] aoChn audio output channel number + * @param[out] mute Audio output mute flag, mute = 0: off mute, mute = 1: on mute. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks By calling the interface, it can be muted immediately. + * + * @attention no. + */ + int IMP_AO_SetVolMute(int audioDevId, int aoChn, int mute); + +/** + * @fn int IMP_AI_SetGain(int audioDevId, int aiChn, int aiGain) + * + * Set audio input gain. + * + * @param[in] audioDevId Audio input device number + * @param[in] aiChn Audio input channel number + * @param[out] aiGain Audio input gain, range [0 ~ 31], correspond to [-18dB ~ 28.5dB], step is 1.5dB. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention aiGain range of [0 ~ 31], if the input value is less than 0, then the value of aiGain will be set to 0 if the value is greater than 31, the value of aiGain will be set to 31 + * + */ + int IMP_AI_SetGain(int audioDevId, int aiChn, int aiGain); + +/** + * @fn int IMP_AI_GetGain(int audioDevId, int aiChn, int *aiGain) + * + * Get AI gain value + * + * @param[in] audioDevId Audio input device number + * @param[in] aiChn Audio input channel number + * @param[out] aiGain audio input gain + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ + int IMP_AI_GetGain(int audioDevId, int aiChn, int *aiGain); + +/** + * @fn int IMP_AI_SetAlcGain(int audioDevId, int aiChn, int aiPgaGain) + * + * Set AI alc gain value + * + * @param[in] audioDevId audioDevId Audio input device number. + * @param[in] aiChn aiChn Audio input channel number + * @param[in] aiPgaGain Audio input gain, range [0 ~ 7],correspond to [-13.5dB, +28.5dB], step is 6dB. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention aiGain range of [0 ~ 7], if the input value is less than 0, then the value of aiGain will be set to 0 if the value is greater than 7, the value of aiGain will be set to 7 + * + */ + int IMP_AI_SetAlcGain(int audioDevId, int aiChn, int aiPgaGain); + +/** + * @fn int IMP_AI_GetAlcGain(int audioDevId, int aiChn, int *aiPgaGain) + * + * Get AI alc gain value + * + * @param[in] audioDevId audioDevId Audio input device number. + * @param[in] audioDevId audioDevId Audio input device number + * @param[out] aiPgaGain audio input gain + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ + int IMP_AI_GetAlcGain(int audioDevId, int aiChn, int *aiPgaGain); + +/** + * @fn int IMP_AO_SetGain(int audioDevId, int aoChn, int aoGain) + * + * Set audio output gain. + * + * @param[in] audioDevId Audio output device number + * @param[in] aoChn audio output channel number + * @param[out] aoGain Audio output gain, range [0 ~ 0x1f], correspond to [-39dB ~ 6dB], step is 1.5dB. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention aoGain range of [0 ~ 31], if the input value is less than 0, then the value of aoGain will be set to 0.\n + * aoGain if the value is greater than 31, the value of aiGain will be set to 31 + * + */ + int IMP_AO_SetGain(int audioDevId, int aoChn, int aoGain); + +/** + * @fn int IMP_AO_GetGain(int audioDevId, int aoChn, int *aoGain) + * + * Get audio output gain. + * + * @param[in] audioDevId audio output device number. + * @param[in] aoChn audio output channel number. + * @param[out] aoGain audio output gain. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * + * @attention no. + */ + int IMP_AO_GetGain(int audioDevId, int aoChn, int *aoGain); + +/** + * @fn int IMP_AO_Soft_Mute(int audioDevId, int aoChn) + * + * Output soft mute control. + * + * @param[in] audioDevId Audio output device number. + * @param[in] aoChn Audio input channel number. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks when this interface is called, it wil not be directly in silence mode from normal playback state. It will slow down gradually, until it reaches the silence mode. + * + * @attention no. + */ + int IMP_AO_Soft_Mute(int audioDevId, int aoChn); + +/** + * @fn int IMP_AO_Soft_UNMute(int audioDevId, int aoChn) + * + * Output soft unmute control. + * + * @param[in] audioDevId Audio output device number. + * @param[in] aoChn Audio input channel number. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks when this interface is called, it will not directly restore the current volume. It will gradually increase the volume from silence mode until the volume reaches a set of good volume. + * + * @attention no. + */ + int IMP_AO_Soft_UNMute(int audioDevId, int aoChn); + +/** + * @fn int IMP_AI_GetFrameAndRef(int audioDevId, int aiChn, IMPAudioFrame *frm, IMPAudioFrame *ref, IMPBlock block) + * + * Get audio frame and output reference frame. + * + * @param[in] audioDevId audio device number. + * @param[in] aiChn audio input channel number. + * @param[out] frm audio frame structure pointer. + * @param[out] ref reference frame structure pointer. + * @param[in] block block and non-block identitifier. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks Sample code + * @code + * IMPAudioFrame frm; + * IMPAudioFrame ref; + * // Get audio frame and output reference frame + * ret = IMP_AI_GetFrameAndRef(devID, chnID, &frm, &ref, BLOCK); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "Audio Get Frame Data error\n"); + * return ret; + * } + * + * fwrite(frm.virAddr, 1, frm.len, record_file); // Use audio frame data + * fwrite(ref.virAddr, 1, ref.len, ref_file); // Use audio reference frame + * + * // Release audio frame + * ret = IMP_AI_ReleaseFrame(devID, chnID, &frm); + * if(ret != 0) { + * IMP_LOG_ERR(TAG, "Audio release frame data error\n"); + * return ret; + * } + * @endcode + * + * @attention no. + */ + int IMP_AI_GetFrameAndRef(int audioDevId, int aiChn, IMPAudioFrame *frm, IMPAudioFrame *ref, IMPBlock block); + +/** + * @fn int IMP_AI_EnableAecRefFrame(int audioDevId, int aiChn, int audioAoDevId, int aoChn) + * + * Open access reference frame. + * + * @param[in] audioDevId audio device number. + * @param[in] aiChn audio input channel number. + * @param[in] audioAoDevId audio output device number. + * @param[in] aoChn audio output channel number. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks Use this current interface before using IMP_AI_GetFrameAndRef. + * @attention no. + */ + int IMP_AI_EnableAecRefFrame(int audioDevId, int aiChn, int audioAoDevId, int aoChn); + +/** + * @fn int IMP_AI_DisableAecRefFrame(int audioDevId, int aiChn, int audioAoDevId, int aoChn) + * + * Close access to the reference frame. + * + * @param[in] audioDevId audio device number. + * @param[in] aiChn audio input channel number. + * @param[in] audioAoDevId audio output device number. + * @param[in] aoChn audio output channel number. + * + * @retval 0 success. + * @retval non-0 failure. + * + * @remarks no. + * @attention no. + */ + int IMP_AI_DisableAecRefFrame(int audioDevId, int aiChn, int audioAoDevId, int aoChn); + +/** + * @fn int IMP_AO_CacheSwitch(int audioDevId, int aoChn, int cache_en) + * close audio play cache + * @param[in] audioDevId audio device number. + * @param[in] aoChn audio output channel number. + * @param[in] cache_en switch of control cache. + * + * @retval 0 success + * @retval non-0 failure. + * + * @remarks no + * @attention no. + */ + int IMP_AO_CacheSwitch(int audioDevId, int aoChn, int cache_en); + +/** + * @fn int IMP_AO_FlushChnBuf(int audioDevId, int aoChn); + * Wait for last audio data to play. + * @param[in] audioDevId audio device number. + * @param[in] aoChn audio output channel number. + * + * @retval 0 success + * @retval non-0 failure. + * + * @remarks no + * @attention no. + */ + int IMP_AO_FlushChnBuf(int audioDevId, int aoChn); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* __IMP_AUDIO_H__ */ diff --git a/sdk/ingenic/include/imp_common.h b/sdk/ingenic/include/imp_common.h new file mode 100644 index 0000000..561ca03 --- /dev/null +++ b/sdk/ingenic/include/imp_common.h @@ -0,0 +1,210 @@ +/* + * IMP common data structure header file. + * + * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __IMP_COMMON_H__ +#define __IMP_COMMON_H__ + +#include +#include +#include +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * SDK-T15 Public data structure header file + */ + +/** + * IMP Device ID enumeration definition + */ +typedef enum { + DEV_ID_FS, /**< Video Source */ + DEV_ID_ENC, /**< Encoder */ + DEV_ID_DEC, /**< Decoder */ + DEV_ID_IVS, /**< Algorithm */ + DEV_ID_OSD, /**< Image Overlay */ + DEV_ID_FG1DIRECT, /**< FB FG1Direct */ + DEV_ID_RESERVED_START, + DEV_ID_RESERVED_END = 23, + NR_MAX_DEVICES, +} IMPDeviceID; + +/** + * IMPCell enumeration definition + */ +typedef struct { + IMPDeviceID deviceID; /**< Device ID */ + int groupID; /**< Group ID */ + int outputID; /**< output ID */ +} IMPCell; + +/** + * IMP frame image information definition + */ +typedef struct { + int index; /**< frame index */ + int pool_idx; /**< frame Pool's ID */ + + uint32_t width; /**< frame's width */ + uint32_t height; /**< frame's height */ + uint32_t pixfmt; /**< frame's image format */ + uint32_t size; /**< frame's occupied space */ + + uint32_t phyAddr; /**< frame's physical address */ + uint32_t virAddr; /**< frame's virtual address */ + + int64_t timeStamp; /**< frame time stamp*/ + int rotate_osdflag; + uint32_t priv[0]; /* private data */ +} IMPFrameInfo; + +/** + * IMP Frame time parameter. + */ +typedef struct { + uint64_t ts; /**< time */ + uint64_t minus; /**< time to min */ + uint64_t plus; /**< max to time */ +} IMPFrameTimestamp; + +/** + * Encoding and decoding protocol type + */ +typedef enum { + PT_JPEG, /**< JPEG image protocol type */ + PT_H264, /**< H264 video protocol type*/ + PT_H265, /**< H265 video protocol type*/ +} IMPPayloadType; + +/** + * IMP image format definition. + */ +typedef enum { + PIX_FMT_YUV420P, /**< planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples) */ + PIX_FMT_YUYV422, /**< packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr */ + PIX_FMT_UYVY422, /**< packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1 */ + PIX_FMT_YUV422P, /**< planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples) */ + PIX_FMT_YUV444P, /**< planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples) */ + PIX_FMT_YUV410P, /**< planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples) */ + PIX_FMT_YUV411P, /**< planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) */ + PIX_FMT_GRAY8, /**< Y , 8bpp */ + PIX_FMT_MONOWHITE, /**< Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb */ + PIX_FMT_MONOBLACK, /**< Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb */ + + PIX_FMT_NV12, /**< planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (first byte U and the following byte V) */ + PIX_FMT_NV21, /**< as above, but U and V bytes are swapped */ + + PIX_FMT_RGB24, /**< packed RGB 8:8:8, 24bpp, RGBRGB... */ + PIX_FMT_BGR24, /**< packed RGB 8:8:8, 24bpp, BGRBGR... */ + + PIX_FMT_ARGB, /**< packed ARGB 8:8:8:8, 32bpp, ARGBARGB... */ + PIX_FMT_RGBA, /**< packed RGBA 8:8:8:8, 32bpp, RGBARGBA... */ + PIX_FMT_ABGR, /**< packed ABGR 8:8:8:8, 32bpp, ABGRABGR... */ + PIX_FMT_BGRA, /**< packed BGRA 8:8:8:8, 32bpp, BGRABGRA... */ + + PIX_FMT_RGB565BE, /**< packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian */ + PIX_FMT_RGB565LE, /**< packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian */ + PIX_FMT_RGB555BE, /**< packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0 */ + PIX_FMT_RGB555LE, /**< packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), little-endian, most significant bit to 0 */ + + PIX_FMT_BGR565BE, /**< packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian */ + PIX_FMT_BGR565LE, /**< packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian */ + PIX_FMT_BGR555BE, /**< packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), big-endian, most significant bit to 1 */ + PIX_FMT_BGR555LE, /**< packed BGR 5:5:5, 16bpp, (msb)1A 5B 5G 5R(lsb), little-endian, most significant bit to 1 */ + + PIX_FMT_0RGB, /**< packed RGB 8:8:8, 32bpp, 0RGB0RGB... */ + PIX_FMT_RGB0, /**< packed RGB 8:8:8, 32bpp, RGB0RGB0... */ + PIX_FMT_0BGR, /**< packed BGR 8:8:8, 32bpp, 0BGR0BGR... */ + PIX_FMT_BGR0, /**< packed BGR 8:8:8, 32bpp, BGR0BGR0... */ + + PIX_FMT_BAYER_BGGR8, /**< bayer, BGBG..(odd line), GRGR..(even line), 8-bit samples */ + PIX_FMT_BAYER_RGGB8, /**< bayer, RGRG..(odd line), GBGB..(even line), 8-bit samples */ + PIX_FMT_BAYER_GBRG8, /**< bayer, GBGB..(odd line), RGRG..(even line), 8-bit samples */ + PIX_FMT_BAYER_GRBG8, /**< bayer, GRGR..(odd line), BGBG..(even line), 8-bit samples */ + + PIX_FMT_RAW, + + PIX_FMT_HSV, + + PIX_FMT_NB, /**< number of pixel formats. */ +} IMPPixelFormat; + +/** + * IMP point coordinate information + */ +typedef struct { + int x; /**< X-axis */ + int y; /**< Y-axis */ +} IMPPoint; + +/** + * IMP Rectangle area information + * + * According to the image down there, if P0(100,100) is the start point, and we'd like that the width and height are both 100,then P1(199,199) + * width = abs(P1.x-P0.x)+1 height = abs(P1.y-P0.y)+1, Point coordinates are both equal to distance +1. + * P0(100,100) _____100______ + * | | + * | | + * 100| | + * | | + * |______________| + * P1(199,199) + * + */ +typedef struct { + IMPPoint p0; /** +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * IMP Decoder header file + */ + +/** + * @defgroup IMP_Decoder + * @ingroup imp + * @brief Video Decoder modules, only support JEPG decode for now. + * @{ + */ + +/** + * Attribute of Decoder + */ +typedef struct { + IMPPayloadType decType; /**< Stream payload type */ + uint32_t maxWidth; /**< Max width of frame */ + uint32_t maxHeight; /**< Max hight of frame */ + IMPPixelFormat pixelFormat; /**< Pixel format of Output frame */ + uint32_t nrKeepStream; /**< Number of frames in Decoder FIFO */ + uint32_t frmRateNum; /**< The number of time units within a second, time unitis its unit. The numerator of framerate */ + uint32_t frmRateDen; /**< The number of time units in a frame, time unit is its unit. The denominator of framerate */ +} IMPDecoderAttr; + +/** + * Attribute of Decoder Channel + */ +typedef struct { + IMPDecoderAttr decAttr; /**< Decoder attribute */ +} IMPDecoderCHNAttr; + +/** + * Attribute of decode frame + */ +typedef struct { + int i_payload; /**< Length of decode frame */ + uint8_t *p_payload; /**< Pointer to decode frame */ + int64_t timeStamp; /**< Timestamp of decode frame */ +} IMPDecoderNal; + +/** + * Attribute of decode stream + */ +typedef struct { + IMPDecoderNal decoderNal; /**< decode stream data structure */ +} IMPDecoderStream; + +/** + * @fn int IMP_Decoder_CreateChn(int decChn, const IMPDecoderCHNAttr *attr) + * + * Create Decoder channel. + * + * @param[in] decChn Channel Num. Value range: [0, @ref NR_MAX_DEC_CHN - 1] + * @param[in] attr Pointer to Decoder Channel attribute + * + * @retval 0 Success + * @retval OtherValues Failure + * + * @remarks None. + * @attention None. + */ +int IMP_Decoder_CreateChn(int decChn, const IMPDecoderCHNAttr *attr); + +/** + * @fn int IMP_Decoder_DestroyChn(int decChn) + * + * Destroy Decoder channel. + * + * @param[in] decChn Channel Num. Value range: [0, @ref NR_MAX_DEC_CHN - 1] + * + * @retval 0 Success + * @retval OtherValues Failure + * + * @remarks None. + * @attention None. + */ +int IMP_Decoder_DestroyChn(int decChn); + +/** + * @fn int IMP_Decoder_StartRecvPic(int decChn) + * + * Decoder channel start recieve pictures. + * + * @param[in] decChn Channel Num. Value range: [0, @ref NR_MAX_DEC_CHN - 1] + * + * @retval 0 Success + * @retval OtherValues Failure + * + * @remarks First Open decoding Channel to receive the image then start decoding. + * + * @attention Failed if the channel isn't created. + */ +int IMP_Decoder_StartRecvPic(int decChn); + +/** + * @fn int IMP_Decoder_StopRecvPic(int decChn) + * + * Decoder channel stop recieve pictures. + * + * @param[in] decChn Channel Num. Value range: [0, @ref NR_MAX_DEC_CHN - 1] + * + * @retval 0 Success + * @retval OtherValues Failure + * + * @remarks Stop decoding the Channel to receive image. + * + * @attention Failed if the channel isn't created. + */ +int IMP_Decoder_StopRecvPic(int decChn); + +/** + * @fn int IMP_Decoder_SendStreamTimeout(int decChn, IMPDecoderStream *stream, uint32_t timeoutMsec) + * + * Send frame to Decoder channel. + * + * @param[in] decChn Channel Num. Value range: [0, @ref NR_MAX_DEC_CHN - 1] + * @param[in] stream Pointer to the Data stream structure to be decoded + * @param[in] timeoutMsec Decode timeout value(msec). + * + * @retval 0 Success + * @retval OtherValues Failure + * + * @remarks None. + * + * @attention Failed if the channel isn't created. + */ +int IMP_Decoder_SendStreamTimeout(int decChn, IMPDecoderStream *stream, uint32_t timeoutMsec); + +/** + * @fn int IMP_Decoder_PollingFrame(int decChn, uint32_t timeoutMsec) + * + * Polling Decoder channel, return when decoding finished or timeout. + * + * @param[in] decChn Channel Num. Value range: [0, @ref NR_MAX_DEC_CHN - 1] + * @param[in] timeoutMsec Wait timeout value(msec). + * + * @retval 0 Success + * @retval OtherValues Failure + * + * @remarks None. + * + * @attention Failed if the channel isn't created. + */ +int IMP_Decoder_PollingFrame(int decChn, uint32_t timeoutMsec); + +/** + * @fn int IMP_Decoder_GetFrame(int decChn, IMPFrameInfo **frame) + * + * Get the decoded output frame. + * + * @param[in] decChn Channel Num. Value range: [0, @ref NR_MAX_DEC_CHN - 1] + * @param[out] frame Pointer to output frame's pointer + * + * @retval 0 Success + * @retval OtherValues Failure + * + * @remarks None. + * + * @attention The memory of output buffer is malloced in Decoder, So the input argument is a pointer of a pointer(pointer's address). + +The decoding stream buffer is applied by the decoder, and the current function only needs to be introduced into the structure body pointer. + */ +int IMP_Decoder_GetFrame(int decChn, IMPFrameInfo **frame); + +/** + * @fn int IMP_Decoder_ReleaseFrame(int decChn, IMPFrameInfo *frame) + * + * Release the decoded output frame. + * + * @param[in] decChn Channel Num. Value range: [0, @ref NR_MAX_DEC_CHN - 1] + * @param[in] frame Pointer to output frame + * + * @retval 0 Success + * @retval OtherValues Failure + * + * @remarks None. + * + * @attention None. + */ +int IMP_Decoder_ReleaseFrame(int decChn, IMPFrameInfo *frame); + +/** + * @} + */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* __IMP_DECODER_H__ */ diff --git a/sdk/ingenic/include/imp_dmic.h b/sdk/ingenic/include/imp_dmic.h new file mode 100644 index 0000000..ebb220e --- /dev/null +++ b/sdk/ingenic/include/imp_dmic.h @@ -0,0 +1,378 @@ +#ifndef __IMP_DMIC_H +#define __IMP_DMIC_H + +#include +#include "imp_audio.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +typedef enum { + DMIC_SAMPLE_RATE_8000 = 8000, /**8KHz sampling rate*/ + DMIC_SAMPLE_RATE_16000 = 16000, /*16KHz sampling rate*/ +} IMPDmicSampleRate; + +typedef enum { + DMIC_BIT_WIDTH_16 = 16, /**<16 bit sampling precision*/ +} IMPDmicBitWidth; + +typedef enum { + DMIC_SOUND_MODE_MONO = 1, /*Single channel*/ + DMIC_SOUND_MODE_STEREO = 2, /*Double channel*/ +} IMPDmicSoundMode; + +/*DMIC input device attribut*/ +typedef struct { + IMPDmicSampleRate samplerate; /**< DMIC sampling rate */ + IMPDmicBitWidth bitwidth; /** + */ + +#ifndef __IMP_EMU_FRAMESOURCE_H__ +#define __IMP_EMU_FRAMESOURCE_H__ + +/** + * @file + * Encoder emulator func interface. + */ + +#include +#include +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C"{ +#endif +#endif /* __cplusplus */ +int IMP_EmuFrameSource_GetChnAttr(uint32_t chn_num, IMPFSChnAttr *chn_attr); +int IMP_EmuFrameSource_EnableChn(uint32_t chn_num); +int IMP_EmuFrameSource_DisableChn(uint32_t chn_num); +int IMP_EmuFrameSource_CreateChn(uint32_t chn_num, IMPFSChnAttr *chn_attr); +int IMP_EmuFrameSource_DestroyChn(uint32_t chn_num); +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* __IMP_EMU_FRAMESOURCE_H__ */ diff --git a/sdk/ingenic/include/imp_encoder.h b/sdk/ingenic/include/imp_encoder.h new file mode 100644 index 0000000..f55cd76 --- /dev/null +++ b/sdk/ingenic/include/imp_encoder.h @@ -0,0 +1,1212 @@ +/* + * IMP Encoder func header file. + * + * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __IMP_ENCODER_H__ +#define __IMP_ENCODER_H__ + +#include +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * IMP Video Encoder header file + */ + +/** + * @defgroup IMP_Encoder + * @ingroup imp + * @brief Video Encoder Module(JPEG, H264, H265), it contains encoder channel management, encoder parameter setting and other functions. + * + * @section enc_struct 1 Encoder Module Structure + * The internal structure of the Encoder is as follows: + * @image html encoder_struct.jpg + * As shown in the figure above, The Encoder Module consists of several groups(Two groups are supported on T15), Each group consists of Encoder channels. + * Each Encoder channel is attached with an output stream area, This area consists of multiple buffers. + * + * @section enc_channel 2 Encoder Channel + * A Encoder Channel can realize the encoding of a protocol, Each group can add two encoding channels. + * + * @section enc_rc 3 Rate Control + * @subsection enc_cbr 3.1 CBR + * CBR(Constent Bit Rate), Keep the bitrate constant in the encoding statistics time. + * Take H264 code as an example, Users can set maxQp, minQp, bitrate an so on. + * maxQp, minQp: it is used to control the quality range of an image. + * bitrate: It is used for the average encoding rate in the statistical time of clamp bit rate. + * When the encoding bitrate is greater than the constant bitrate, the image QP will gradually adjust to maxqp. + * When the encoding bitrate is much less than the constant bitrate, the image QP will gradually adjust to minqp. + * When the image QP reaches maxqp, QP is clamped to the maximum, bitrate clamping effect is invalid, and the encoding bitrate may exceed bitrate. + * When the image QP reaches minqp, QP is clamped to the minimum value, and the bitrate of encoding has reached the maximum value and the image quality is the best. + * @subsection enc_FixQP 3.2 FixQP + * Fix Qp, Fixed QP value. + * In the bitrate statistics time, the QP values of all macroblocks in the coded image are the same, and the image QP values set by user. + * @{ + */ + +/** + * Defining the Nalu type of H.264 + */ +typedef enum { + IMP_H264_NAL_UNKNOWN = 0, /**< Undefined */ + IMP_H264_NAL_SLICE = 1, /**< A encoding strip for non IDR image */ + IMP_H264_NAL_SLICE_DPA = 2, /**< Encoding stripe data partition block A */ + IMP_H264_NAL_SLICE_DPB = 3, /**< Encoding stripe data partition block B */ + IMP_H264_NAL_SLICE_DPC = 4, /**< Encoding stripe data partition block C */ + IMP_H264_NAL_SLICE_IDR = 5, /**< Encoding strip of IDR image */ + IMP_H264_NAL_SEI = 6, /**< SEI(Supplemental Enhancement Information) */ + IMP_H264_NAL_SPS = 7, /**< SPS(Sequence Paramater Set) */ + IMP_H264_NAL_PPS = 8, /**< PPS(Picture Paramater Set) */ + IMP_H264_NAL_AUD = 9, /**< Access unit separator */ + IMP_H264_NAL_FILLER = 12, /**< Fill in data */ +} IMPEncoderH264NaluType; + +/** + * Defining the Nalu type of H.265 + */ +typedef enum { + IMP_H265_NAL_SLICE_TRAIL_N = 0, /**< Trailing image without reference information */ + IMP_H265_NAL_SLICE_TRAIL_R = 1, /**< Trailing image with reference information */ + IMP_H265_NAL_SLICE_TSA_N = 2, /**< Sub layer access point image in time domain without reference information */ + IMP_H265_NAL_SLICE_TSA_R = 3, /**< Sub layer access point image in time domain with reference information */ + IMP_H265_NAL_SLICE_STSA_N = 4, /**< Step by step time domain sub layer access point image without reference information */ + IMP_H265_NAL_SLICE_STSA_R = 5, /**< Step by step time domain sub layer access point image with reference information */ + IMP_H265_NAL_SLICE_RADL_N = 6, /**< The front image can be decoded randomly without reference information */ + IMP_H265_NAL_SLICE_RADL_R = 7, /**< The front image can be decoded randomly with reference information */ + IMP_H265_NAL_SLICE_RASL_N = 8, /**< Skip the front image of random access, without reference information */ + IMP_H265_NAL_SLICE_RASL_R = 9, /**< Skip the front image of random access, with reference information */ + IMP_H265_NAL_SLICE_BLA_W_LP = 16, /**< Breakpoint connection access with front image */ + IMP_H265_NAL_SLICE_BLA_W_RADL = 17, /**< Breakpoint connection access with front image RADL */ + IMP_H265_NAL_SLICE_BLA_N_LP = 18, /**< Breakpoint connection access without front image */ + IMP_H265_NAL_SLICE_IDR_W_RADL = 19, /**< Instant decoding refresh with front image RADL */ + IMP_H265_NAL_SLICE_IDR_N_LP = 20, /**< Instant decoding refresh without front image */ + IMP_H265_NAL_SLICE_CRA = 21, /**< Pure random access with front image */ + IMP_H265_NAL_VPS = 32, /**< Video Parameter Set */ + IMP_H265_NAL_SPS = 33, /**< SPS(Sequence Paramater Set) */ + IMP_H265_NAL_PPS = 34, /**< PPS(Picture Paramater Set) */ + IMP_H265_NAL_AUD = 35, /**< Access unit separator */ + IMP_H265_NAL_EOS = 36, /**< End of sequence */ + IMP_H265_NAL_EOB = 37, /**< End of bitstream */ + IMP_H265_NAL_FILLER_DATA = 38, /**< Fill in data */ + IMP_H265_NAL_PREFIX_SEI = 39, /**< SEI(Supplemental Enhancement Information) */ + IMP_H265_NAL_SUFFIX_SEI = 40, /**< SEI(Supplemental Enhancement Information) */ + IMP_H265_NAL_INVALID = 64, /**< Invalid nal type */ +} IMPEncoderH265NaluType; + +/** + * Define the nal type of H.264 and h.265 encoding channel stream + */ +typedef union { + IMPEncoderH264NaluType h264NalType; /**< H264E NALU */ + IMPEncoderH265NaluType h265NalType; /**< H265E NALU */ +} IMPEncoderNalType; + +typedef enum { + IMP_ENC_SLICE_SI = 4, /**< AVC SI Slice */ + IMP_ENC_SLICE_SP = 3, /**< AVC SP Slice */ + IMP_ENC_SLICE_GOLDEN = 3, /**< Golden Slice */ + IMP_ENC_SLICE_I = 2, /**< I Slice (can contain I blocks) */ + IMP_ENC_SLICE_P = 1, /**< P Slice (can contain I and P blocks) */ + IMP_ENC_SLICE_B = 0, /**< B Slice (can contain I, P and B blocks) */ + IMP_ENC_SLICE_CONCEAL = 6, /**< Conceal Slice (slice was concealed) */ + IMP_ENC_SLICE_SKIP = 7, /**< Skip Slice */ + IMP_ENC_SLICE_REPEAT = 8, /**< Repeat Slice (repeats the content of its reference) */ + IMP_ENC_SLICE_MAX_ENUM, /**< sentinel */ +} IMPEncoderSliceType; + +/** + * Define the packet structure of coded frame and stream + */ +typedef struct { + uint32_t offset; /**< Stream packet offset */ + uint32_t length; /**< Stream packet length */ + int64_t timestamp; /**< Time stamp, unit us */ + bool frameEnd; /**< End of frame flag */ + IMPEncoderNalType nalType; /**< Nal type of encoder channel */ + IMPEncoderSliceType sliceType; /**< Nal type of encoder slice */ +} IMPEncoderPack; + +typedef struct { + int32_t iNumBytes; /**< Number of bytes in the stream */ + uint32_t uNumIntra; /**< Number of 8x8 blocks coded with intra mode */ + uint32_t uNumSkip; /**< Number of 8x8 blocks coded with skip mode */ + uint32_t uNumCU8x8; /**< Number of 8x8 CUs */ + uint32_t uNumCU16x16; /**< Number of 16x16 CUs */ + uint32_t uNumCU32x32; /**< Number of 32x32 CUs */ + uint32_t uNumCU64x64; /**< Number of 64x64 CUs */ + int16_t iSliceQP; /**< Slice QP value */ + int16_t iMinQP; /**< Minimum QP value */ + int16_t iMaxQP; /**< Maximum QP value */ +} IMPEncoderStreamInfo; + +typedef struct { + int32_t iNumBytes; /**< Number of bytes in the stream */ + int16_t iQPfactor; /**< JPEG QP param */ +} IMPEncoderJpegInfo; + +/** + * Define the structure of coded frame stream type + */ +typedef struct { + uint32_t phyAddr; /**< Physical address of frame */ + uint32_t virAddr; /**< Virtual address of frame */ + uint32_t streamSize; /**< Size of the allocated virtual address */ + IMPEncoderPack *pack; /**< Frame stream packet */ + uint32_t packCount; /**< The number of all packets in a frame stream */ + uint32_t seq; /**< Sequence number of coded frame */ + bool isVI; + union + { + IMPEncoderStreamInfo streamInfo; + IMPEncoderJpegInfo jpegInfo; + }; +} IMPEncoderStream; + +typedef enum { + IMP_ENC_TYPE_AVC = 0, + IMP_ENC_TYPE_HEVC = 1, + IMP_ENC_TYPE_JPEG = 4, +} IMPEncoderEncType; + +#define IMP_ENC_AVC_PROFILE_IDC_BASELINE 66 +#define IMP_ENC_AVC_PROFILE_IDC_MAIN 77 +#define IMP_ENC_AVC_PROFILE_IDC_HIGH 100 +#define IMP_ENC_HEVC_PROFILE_IDC_MAIN 1 + +typedef enum { + IMP_ENC_PROFILE_AVC_BASELINE = ((IMP_ENC_TYPE_AVC << 24) | (IMP_ENC_AVC_PROFILE_IDC_BASELINE)), + IMP_ENC_PROFILE_AVC_MAIN = ((IMP_ENC_TYPE_AVC << 24) | (IMP_ENC_AVC_PROFILE_IDC_MAIN)), + IMP_ENC_PROFILE_AVC_HIGH = ((IMP_ENC_TYPE_AVC << 24) | (IMP_ENC_AVC_PROFILE_IDC_HIGH)), + IMP_ENC_PROFILE_HEVC_MAIN = ((IMP_ENC_TYPE_HEVC << 24) | (IMP_ENC_HEVC_PROFILE_IDC_MAIN)), + IMP_ENC_PROFILE_JPEG = (IMP_ENC_TYPE_JPEG << 24), +} IMPEncoderProfile; + +typedef enum { + IMP_ENC_PIC_FORMAT_400_8BITS = 0x0088, + IMP_ENC_PIC_FORMAT_420_8BITS = 0x0188, + IMP_ENC_PIC_FORMAT_422_8BITS = 0x0288, +} IMPEncoderPicFormat; + +typedef enum { + IMP_ENC_OPT_QP_TAB_RELATIVE = 0x00000001, + IMP_ENC_OPT_FIX_PREDICTOR = 0x00000002, + IMP_ENC_OPT_CUSTOM_LDA = 0x00000004, + IMP_ENC_OPT_ENABLE_AUTO_QP = 0x00000008, + IMP_ENC_OPT_ADAPT_AUTO_QP = 0x00000010, + IMP_ENC_OPT_COMPRESS = 0x00000020, + IMP_ENC_OPT_FORCE_REC = 0x00000040, + IMP_ENC_OPT_FORCE_MV_OUT = 0x00000080, + IMP_ENC_OPT_HIGH_FREQ = 0x00002000, + IMP_ENC_OPT_SRD = 0x00008000, + IMP_ENC_OPT_FORCE_MV_CLIP = 0x00020000, + IMP_ENC_OPT_RDO_COST_MODE = 0x00040000, +} IMPEncoderEncOptions; + +typedef enum { + IMP_ENC_TOOL_WPP = 0x00000001, + IMP_ENC_TOOL_TILE = 0x00000002, + IMP_ENC_TOOL_LF = 0x00000004, + IMP_ENC_TOOL_LF_X_SLICE = 0x00000008, + IMP_ENC_TOOL_LF_X_TILE = 0x00000010, + IMP_ENC_TOOL_SCL_LST = 0x00000020, + IMP_ENC_TOOL_CONST_INTRA_PRED = 0x00000040, + IMP_ENC_TOOL_TRANSFO_SKIP = 0x00000080, + IMP_ENC_TOOL_PCM = 0x00000800, +} IMPEncoderEncTools; + +/** + * Define encoder croping attributes, image of the input encoder is cropped first, then compared with the size of the encoding channel, and then scaled + */ +typedef struct { + bool enable; /**< Crop or not, range: [FALSE, TRUE], TRUE: crop, FALSE: not crop */ + uint32_t x; /**< The x-coordinate of the upper left corner of the crop region */ + uint32_t y; /**< The y-coordinate of the upper left corner of the crop region */ + uint32_t w; /**< Width of Crop Region */ + uint32_t h; /**< Height of Crop Region */ +} IMPEncoderCropCfg; + +/** + * Define encoder entropy mode + */ +typedef enum { + IMP_ENC_ENTROPY_MODE_CAVLC = 0x1, /* AVC only */ + IMP_ENC_ENTROPY_MODE_CABAC = 0x2, +} IMPEncoderEntropyMode; + +/** + * Define encoder attribute structure + */ +typedef struct { + IMPEncoderProfile eProfile; + uint8_t uLevel; + uint8_t uTier; + uint16_t uWidth; + uint16_t uHeight; + IMPEncoderPicFormat ePicFormat; + uint32_t eEncOptions; + uint32_t eEncTools; + IMPEncoderCropCfg crop; /**< Encoder croping properties */ +} IMPEncoderEncAttr; + +typedef enum { + IMP_ENC_GOP_CTRL_MODE_DEFAULT = 0x02, + IMP_ENC_GOP_CTRL_MODE_PYRAMIDAL = 0x04, + IMP_ENC_GOP_CTRL_MODE_SMARTP = 0xfe, + IMP_ENC_GOP_CTRL_MAX_ENUM = 0xff, +} IMPEncoderGopCtrlMode; + +typedef struct { + IMPEncoderGopCtrlMode uGopCtrlMode; + uint16_t uGopLength; + //uint8_t uNumB; + uint16_t uNotifyUserLTInter; + uint32_t uMaxSameSenceCnt; + bool bEnableLT; + uint32_t uFreqLT; + bool bLTRC; +} IMPEncoderGopAttr; + +typedef enum { + IMP_ENC_RC_MODE_FIXQP = 0x0, + IMP_ENC_RC_MODE_CBR = 0x1, + IMP_ENC_RC_MODE_VBR = 0x2, + IMP_ENC_RC_MODE_CAPPED_VBR = 0x4, + IMP_ENC_RC_MODE_CAPPED_QUALITY = 0x8, + IMP_ENC_RC_MODE_INVALID = 0xff, +} IMPEncoderRcMode; + +typedef enum IMPEncoderRcOptions { + IMP_ENC_RC_OPT_NONE = 0x00000000, + IMP_ENC_RC_SCN_CHG_RES = 0x00000001, + IMP_ENC_RC_DELAYED = 0x00000002, + IMP_ENC_RC_STATIC_SCENE = 0x00000004, + IMP_ENC_RC_ENABLE_SKIP = 0x00000008, + IMP_ENC_RC_OPT_SC_PREVENTION = 0x00000010, + IMP_ENC_RC_MAX_ENUM, +} IMPEncoderRcOptions; + +typedef struct { + int16_t iInitialQP; +} IMPEncoderAttrFixQP; + +typedef struct { + uint32_t uTargetBitRate; + int16_t iInitialQP; + int16_t iMinQP; + int16_t iMaxQP; + int16_t iIPDelta; + int16_t iPBDelta; + uint32_t eRcOptions; + uint32_t uMaxPictureSize; +} IMPEncoderAttrCbr; + +typedef struct { + uint32_t uTargetBitRate; + uint32_t uMaxBitRate; + int16_t iInitialQP; + int16_t iMinQP; + int16_t iMaxQP; + int16_t iIPDelta; + int16_t iPBDelta; + uint32_t eRcOptions; + uint32_t uMaxPictureSize; +} IMPEncoderAttrVbr; + +typedef struct { + uint32_t uTargetBitRate; + uint32_t uMaxBitRate; + int16_t iInitialQP; + int16_t iMinQP; + int16_t iMaxQP; + int16_t iIPDelta; + int16_t iPBDelta; + uint32_t eRcOptions; + uint32_t uMaxPictureSize; + uint16_t uMaxPSNR; +} IMPEncoderAttrCappedVbr; + +typedef IMPEncoderAttrCappedVbr IMPEncoderAttrCappedQuality; + +typedef struct { + IMPEncoderRcMode rcMode; + union { + IMPEncoderAttrFixQP attrFixQp; + IMPEncoderAttrCbr attrCbr; + IMPEncoderAttrVbr attrVbr; + IMPEncoderAttrCappedVbr attrCappedVbr; + IMPEncoderAttrCappedQuality attrCappedQuality; + }; +} IMPEncoderAttrRcMode; + +/** + * Define the frame rate structure of the encoded channel + * The minimum common multiple between frmratenum and frmrateden after the maximum common divisor division cannot exceed 64, preferably by the maximum common divisor before setting + */ +typedef struct { + uint32_t frmRateNum; /**< The number of time units in a second, in units of time. Frame rate molecules */ + uint32_t frmRateDen; /**< The number of time units in a second, in units of time. Frame rate denominator */ +} IMPEncoderFrmRate; + + +typedef struct { + IMPEncoderAttrRcMode attrRcMode; + IMPEncoderFrmRate outFrmRate; +} IMPEncoderRcAttr; + +/** + * Define encoded channel attribute structure + */ +typedef struct { + IMPEncoderEncAttr encAttr; /**< Encoder attribute structure */ + IMPEncoderRcAttr rcAttr; /**< Rate controller attribute structure, only for H264 and H265 */ + IMPEncoderGopAttr gopAttr; /**< Encoder attribute structure */ +} IMPEncoderChnAttr; + +/** + * Define the state structure of encoded channel + */ +typedef struct { + bool registered; /**< Flag registered to the group, range: [TRUE, FALSE], TRUE: registered, FALSE: no registered */ + uint32_t leftPics; /**< Number of images to be encoded */ + uint32_t leftStreamBytes; /**< The number of bytes remaining in the bitstream buffer */ + uint32_t leftStreamFrames; /**< The number of frames remaining in the bitstream buffer */ + uint32_t curPacks; /**< The number of stream packets in the current frame */ + uint32_t work_done; /**< Channel program running status, 0: running, 1: no running */ +} IMPEncoderChnStat; + +/** + * @fn int IMP_Encoder_CreateGroup(int encGroup) + * + * Create Encoding Group. + * + * @param[in] encGroup: Group ID, range: [0, @ref NR_MAX_ENC_GROUPS - 1] + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks One way group only supports one way resolution, and a new group needs to be started for different resolutions + * One way group allows up to 2 coding channels to be registered. + * + * @attention If the group already exists, then return fails. + */ +int IMP_Encoder_CreateGroup(int encGroup); + +/** + * @fn int IMP_Encoder_DestroyGroup(int encGroup) + * + * Destroy Encoding Group. + * + * @param[in] encGroup: Group ID, range: [0, @ref NR_MAX_ENC_GROUPS - 1] + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks When destroying a group, it must be ensured that the group is empty, that is, no channel is registered in the group. + * + * @attention If destroy a nonexistent group, then return fails. + */ +int IMP_Encoder_DestroyGroup(int encGroup); + +/** +* @fn int IMP_Encoder_SetDefaultParam(IMPEncoderChnAttr *chnAttr, IMPEncoderProfile profile, IMPEncoderRcMode rcMode, uint16_t uWidth, uint16_t uHeight, uint32_t frmRateNum, uint32_t frmRat +* +* Set encoding default properties. +* +* @param[out] chnAttr: Struct for encoding. +* @param[in] profile: Encoding profile. +* @param[in] rcMode: Rate control mode. +* @param[in] uWidth: Encoding width. +* @param[in] uHeight: Encoding height. +* @param[in] frmRateNum: Encoding fps num. +* @param[in] frmRateDen: Encoding fps den. +* @param[in] uGopLength: GOP length. +* @param[in] uMaxSameSenceCnt: GOPLength = uGopLength * uMaxSameSenceCnt, Default is 2. +* @param[in] iInitialQP: Initialize QP, Default is -1. +* @param[in] uTargetBitRate: Target bitrate. +* +* @retval 0 success. +* @retval ~0 failed. +* +* @remarks If you are not familiar with coding related parameters, please use the default values. +* +* @attention none. +*/ +int IMP_Encoder_SetDefaultParam(IMPEncoderChnAttr *chnAttr, IMPEncoderProfile profile, IMPEncoderRcMode rcMode, uint16_t uWidth, uint16_t uHeight, uint32_t frmRateNum, uint32_t frmRateDen, uint32_t uGopLength, int uMaxSameSenceCnt, int iInitialQP, uint32_t uTargetBitRate); + +/** + * @fn int IMP_Encoder_CreateChn(int encChn, const IMPEncoderChnAttr *attr) + * + * Create Encoder Channel. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] attr: Encode channel property pointer. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks The coding channel attribute consists of two parts: encoder attribute and rate control attribute. + * @remarks Encoder attributes need to select the coding protocol first, and then assign the corresponding attributes to each protocol. + */ +int IMP_Encoder_CreateChn(int encChn, const IMPEncoderChnAttr *attr); + +/** + * @fn int IMP_Encoder_DestroyChn(int encChn) + * + * Destroy Encoder Channel. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @attention Destroy channels that do not exist, then return fails. + * @attention Before destroying, you must ensure that the channel has been de registered from the group, otherwise it will return fails. + */ +int IMP_Encoder_DestroyChn(int encChn); + +/** + * @fn int IMP_Encoder_GetChnAttr(int encChn, IMPEncoderChnAttr * const attr) + * + * Gets the properties of the encoding channel. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] attr: Encoding channel properties. + * + * @retval 0 success. + * @retval ~0 failed. + */ +int IMP_Encoder_GetChnAttr(int encChn, IMPEncoderChnAttr * const attr); + +/** + * @fn int IMP_Encoder_RegisterChn(int encGroup, int encChn) + * + * Register encoding channel to group. + * + * @param[in] encGroup: Group ID, range: [0, @ref NR_MAX_ENC_GROUPS - 1]. + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @attention If you register a channel that does not exist, then return fails. + * @attention If the channel is registered to a nonexistent group, then return fails. + * @attention The same coding channel can only be registered to one group. If the channel has been registered to a group, then return fails. + * @attention If a group has been registered, it cannot be registered by other channels. + */ + +int IMP_Encoder_RegisterChn(int encGroup, int encChn); +/** + * @fn int IMP_Encoder_UnRegisterChn(int encChn) + * + * Unregister encoding channel to group. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks After the channel is logged off, the encoding channel will be reset and the code stream buffers in the encoding channel will be cleared, + * If the user is still using the bitstream buffer that has not been released in time, the correctness of the buffer data cannot be guaranteed, + * Users can use IMP_Encoder_Query interface to query the status of the code channel buffer, After the register of the bitstream is completed, + * the buffer is retrieved. + * + * @attention Unregister the uncreated channel, then return fails. + * @attention Unregister the unregistered channel, then return fails. + * @attention If the encoding channel does not stop receiving image encoding, then return fails. + */ +int IMP_Encoder_UnRegisterChn(int encChn); + +/** + * @fn int IMP_Encoder_StartRecvPic(int encChn) + * + * Start receiving coded channel image. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * + * @retval 0 success. + * @retval non-0 failed. + * + * @remarks The encoding can only be started after the encoding channel receives the image. + * + * @attention If the channel is not created, then return fails. + * @attention If channel is not registered with group, then return fails. + */ +int IMP_Encoder_StartRecvPic(int encChn); + +/** + * @fn int IMP_Encoder_StopRecvPic(int encChn) + * + * End receiving coded channel image. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks This interface does not determine whether the reception is stopped or not, it allows repeated stop reception without returning errors. + * @remarks Calling this interface only stops receiving the original data encoding, and the stream buffer will not be eliminated. + * + * @attention If the channel is not created, then return fails. + * @attention If channel is not registered with group, then return fails. + */ +int IMP_Encoder_StopRecvPic(int encChn); + +/** + * @fn int IMP_Encoder_Query(int encChn, IMPEncoderChnStat *stat) + * + * Query encoded channel status. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[out] stat: Encoding channel status. + * + * @retval 0 success. + * @retval non-0 failed. + * + * @remarks none. + * + * @attention none. + */ +int IMP_Encoder_Query(int encChn, IMPEncoderChnStat *stat); + +/** + * @fn int IMP_Encoder_GetStream(int encChn, IMPEncoderStream *stream, bool blockFlag) + * + * Get the encoded stream. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] stream: stream structure pointer. + * @param[in] blockFlag: Whether to use blocking method to obtain, 0: no blocking, 1: blocking. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Get the data of one frame at a time. + * @remarks If the user does not get the stream for a long time, the code stream buffer will be full. If a code stream buffer is full, + * a coded channel will lose the image received later, Only when the user obtains the code stream and has enough buffer for coding, can the coding continue. + * It is suggested that the user interface call to acquire the code stream and the interface call to release the code stream appear in pairs, + * and the code stream should be released as soon as possible to prevent the user state from acquiring the code stream, + * If the bit stream buffer is full due to untimely release, the encoding is stopped. + * @remarks For H264 and h265 code streams, call success to get a frame code stream, which may contain multiple packets. + * @remarks For JPEG type code stream, call success to get one frame code stream at a time. This frame code stream only contains one package, + * and this frame contains the complete information of JPEG image file. + * + * example: + * @code + * int ret; + * ret = IMP_Encoder_PollingStream(ENC_H264_CHANNEL, 1000); //Polling Stream Buffer. + * if (ret < 0) { + * printf("Polling stream timeout\n"); + * return -1; + * } + * + * IMPEncoderStream stream; + * ret = IMP_Encoder_GetStream(ENC_H264_CHANNEL, &stream, 1); //Get a frame stream by blocking. + * if (ret < 0) { + * printf("Get Stream failed\n"); + * return -1; + * } + * + * int i, nr_pack = stream.packCount; + * for (i = 0; i < nr_pack; i++) { //Save each packet of this frame stream. + * ret = write(stream_fd, (void *)stream.pack[i].virAddr, + * stream.pack[i].length); + * if (ret != stream.pack[i].length) { + * printf("stream write error:%s\n", strerror(errno)); + * return -1; + * } + * } + * @endcode + * + * @attention If pststream is null, then return fails. + * @attention If the channel is not created, then return fails. + */ +int IMP_Encoder_GetStream(int encChn, IMPEncoderStream *stream, bool blockFlag); + +/** + * @fn int IMP_Encoder_ReleaseStream(int encChn, IMPEncoderStream *stream) + * + * Release the encoded stream. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] stream: stream structure pointer. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks This interface should be with imp_ Encoder_ Getstream pairs to use,user must release the obtained bit stream buffer in time after acquiring the bit stream, + * otherwise the bit stream buffer may be full and the encoder coding will be affected. + * And the user must release the obtained bitstream cache in the order of acquire first and release first. + * @remarks After the de registration of the coding channel, all the unreleased stream packets are invalid and can no longer be used or released. + * + * @attention If pststream is null, then return fails. + * @attention If the channel is not created, then return fails. + * @attention If the invalid stream is released, then return fails. + */ +int IMP_Encoder_ReleaseStream(int encChn, IMPEncoderStream *stream); + +/** + * @fn int IMP_Encoder_PollingStream(int encChn, uint32_t timeoutMsec) + * + * Polling encoded stream. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] timeoutMsec: overtimes, unit: ms. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Before obtaining the code stream, you can use this API to poll. When the code stream cache is not empty or the time is over, the function returns. + * + * @attention none. + */ +int IMP_Encoder_PollingStream(int encChn, uint32_t timeoutMsec); + +/** + * @fn int IMP_Encoder_PollingModuleStream(uint32_t *encChnBitmap, uint32_t timeoutMsec) + * + * Poling the encoded stream of each channel of the whole encoding module. + * + * @param[out] encChnBitmap: Each bits represents the corresponding channel number, If there is a coded stream, the corresponding position 1, otherwise set to 0. + * @param[in] timeoutMsec: overtimes, unit: ms. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Before obtaining the code stream, you can use this API to poll. When the code stream cache is not empty or the time is over, the function returns. + * @remarks *encChnBitmap The bit corresponding to 1 is only used after calling IMP_Encoder_ReleaseStream, + * if it is detected that the channel stream cache corresponding to this bit is not empty, it will be set to zero. + * + * @attention none. + */ +int IMP_Encoder_PollingModuleStream(uint32_t *encChnBitmap, uint32_t timeoutMsec); + +/** + * @fn int IMP_Encoder_GetFd(int encChn) + * + * Get the device file handle corresponding to the encoding channel. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * + * @retval >=0 success, return the device file descriptor. + * @retval < 0 failed. + * + * @remarks If using IMP_Encoder_PollingStream is not suitable, For example, When the coding of multiple coding channels is completed in the same place, + * you can use this file handle to call select, poll and other similar functions to block waiting for encoding to complete. + * @remarks If the channel is not created, then return fails. + * + * @attention none. + */ +int IMP_Encoder_GetFd(int encChn); + +/** + * @fn int IMP_Encoder_SetbufshareChn(int encChn, int shareChn) + * + * Set JPEG channel to share H265/H264 encoding channel. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] sharechn: Shared H264/H265 channel number, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Shared encoding channel created before calling this API. + * @remarks This API needs to be called before the channel is created. + * + * @attention none. + */ +int IMP_Encoder_SetbufshareChn(int encChn, int shareChn); + +/** + * @fn int IMP_Encoder_SetChnResizeMode(int encChn, int en); + * + * Set whether additional rmem memory is required for encoding scaling. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] en: alloc rmem or not, 1: no alloc rmem, 0: alloc rmem. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks This API is only called when the resolution of encoding scaling is less than the original resolution, + * there is no need to call when the resolution of encoding scaling is greater than the original resolution. + * + * @attention none. + */ +int IMP_Encoder_SetChnResizeMode(int encChn, int en); + +/** + * @fn int IMP_Encoder_SetMaxStreamCnt(int encChn, int nrMaxStream) + * + * Set the number of stream buffers. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] nrMaxStream: number of stream buffers, range: [1, @ref NR_MAX_ENC_CHN_STREAM]. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Because the number of Buffer buffers is fixed at the time the channel is created, the secondary API needs to be called before the channel is created. + * @remarks If this API is not called to set the number of buffers in the bitstream cache before the channel is created, the default number of buffers in the SDK is used. + * + * @attention none. + */ +int IMP_Encoder_SetMaxStreamCnt(int encChn, int nrMaxStream); + +/** + * @fn int IMP_Encoder_GetMaxStreamCnt(int encChn, int *nrMaxStream) + * + * Get the number of stream buffers. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[out] nrMaxStream: stream buffer number variable pointer. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks none. + * + * @attention none. + */ +int IMP_Encoder_GetMaxStreamCnt(int encChn, int *nrMaxStream); + +/** + * @fn int IMP_Encoder_RequestIDR(int encChn) + * + * Request IDR frame. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks After calling this API, IDR frame coding will be applied in the latest coding frame. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_RequestIDR(int encChn); + +/** + * @fn int IMP_Encoder_FlushStream(int encChn) + * + * Wipe out old stream in the encoder, and the encoding starts with the IDR frame. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks After calling this API, IDR frame coding will be applied in the latest coding frame. + * + * @attention none. + */ +int IMP_Encoder_FlushStream(int encChn); + +/** + * @fn int IMP_Encoder_GetChnFrmRate(int encChn, IMPEncoderFrmRate *pstFps) + * + * Get frame rate control properties. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[out] pstFpsCfg: Frame rate control attribute parameters. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Calling this API will get the frame rate control property of the channel. Calling this API requires that the channel already exists. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_GetChnFrmRate(int encChn, IMPEncoderFrmRate *pstFps); + +/** + * @fn int IMP_Encoder_SetChnFrmRate(int encChn, const IMPEncoderFrmRate *pstFps) + * + * Set frame rate control properties dynamically. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[out] pstFpsCfg: Frame rate control attribute parameters. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Calling this API will reset the encoder frame rate attribute. The frame rate attribute takes effect in the next GOP with a maximum delay of 1 second. + * Calling this API requires that the channel already exists. + * @remarks If IMP_FRAMESOURCE_SETCHNFPS is called to change frame rate of the system dynamically, then the function is needed to modify the frame rate of the encoder + * and complete the correct parameter configuration. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_SetChnFrmRate(int encChn, const IMPEncoderFrmRate *pstFps); + +/** + * @fn int IMP_Encoder_SetChnBitRate(int encChn, int iTargetBitRate, int iMaxBitRate) + * + * Set bitrate attribute dynamically. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] iTargetBitRate: Target bitrate, iMaxBitRate Max bitrate unit: "bit/s". + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Calling this API will reset the code rate attribute of the encoder. The code rate attribute takes effect in the next GOP with a maximum delay of 1 second. + * Calling this API requires that the channel already exists. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_SetChnBitRate(int encChn, int iTargetBitRate, int iMaxBitRate); + +/** +* @fn int IMP_Encoder_SetChnGopLength(int encChn, int iGopLength); +* +* Set the gopplength property of the encoding channel. +* +* @param[in] encChn Channel ID,range: [0, @ref NR_MAX_ENC_CHN - 1]. +* @param[in] iGopLength GopLength attr. +* +* @retval 0 success. +* @retval ~0 failed. +* +* @remarks none. +* +* @attention none. +*/ +int IMP_Encoder_SetChnGopLength(int encChn, int iGopLength); + +/** + * @fn int IMP_Encoder_GetChnAttrRcMode(int encChn, IMPEncoderAttrRcMode *pstRcModeCfg). + * + * Get the rate control mode attribute. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[out] pstRcCfg: Rate control mode attribute parameters. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Calling this API will get the bit rate control mode property of the channel. Calling this API requires that the channel already exists. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_GetChnAttrRcMode(int encChn, IMPEncoderAttrRcMode *pstRcModeCfg); + +/** + * @fn int IMP_Encoder_SetChnAttrRcMode(int encChn, const IMPEncoderAttrRcMode *pstRcModeCfg). + * + * Set rate control mode properties. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] pstRcCfg: Rate control mode attribute parameters. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Calling this API will set the bit rate control mode property of the channel, and the next IDR will take effect. + * Calling this API requires that the channel already exists. + * + * @attention Currently, the code rate control mode supports ENC_RC_MODE_FIXQP, ENC_RC_MODE_CBR, ENC_RC_MODE_VBR, ENC_RC_MODE_CAPPED_QUALITY. + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_SetChnAttrRcMode(int encChn, const IMPEncoderAttrRcMode *pstRcModeCfg); + +/** +* @fn int IMP_Encoder_GetChnGopAttr(int encChn, IMPEncoderGopAttr *pGopAttr); +* +* Obtain encoding channel GOP properties. +* +* @param[in] encChn: Channel ID,range: [0, @ref NR_MAX_ENC_CHN - 1] +* @param[out] pGopAttr: GOP attr +* +* @retval 0 success +* @retval ~0 failed +* +* @remarks none. +* +* @attention none +*/ +int IMP_Encoder_GetChnGopAttr(int encChn, IMPEncoderGopAttr *pGopAttr); + +/** +* @fn int IMP_Encoder_SetChnGopAttr(int encChn, const IMPEncoderGopAttr *pGopAttr); +* +* Set encoding channel GOP properties. +* +* @param[in] encChn: Channel ID,range: [0, @ref NR_MAX_ENC_CHN - 1] +* @param[in] pGopAttr: GOP attr +* +* @retval 0 success. +* @retval ~0 failed. +* +* @remarks none. +* +* @attention none +*/ +int IMP_Encoder_SetChnGopAttr(int encChn, const IMPEncoderGopAttr *pGopAttr); + +/** + * @fn int IMP_Encoder_SetChnQp(int encChn, int iQP) + * + * Setting the rate control property QP dynamically. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1] + * @param[in] iQP: QP, range: [iMinQP, iMaxQP] + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Calling this API will reset the QP of the next frame, and the set QP will take effect in the next frame. + * Calling this API requires that the channel already exists. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_SetChnQp(int encChn, int iQP); + +/** + * @fn int IMP_Encoder_SetChnQpBounds(int encChn, int iMinQP, int iMaxQP); + * + * Dynamically set the bit rate control attributes maxqp and minqp. + * + * @param[in] encChn: Channel ID,range: [0, @ref NR_MAX_ENC_CHN - 1] + * @param[in] iMinQP: iMinQP value,range: [0, 51] + * @param[in] iMaxQP: iMaxQP value,range: [0, 51] + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Calling this API will reset the QP range of the next frame. + * Calling this API requires that the channel already exists. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_SetChnQpBounds(int encChn, int iMinQP, int iMaxQP); + +/** + * @fn int IMP_Encoder_SetChnQpIPDelta(int encChn, int uIPDelta) + * + * Setting the rate control property IPDelta dynamically. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1] + * @param[in] IPDelta QP difference between I frame and the first P frame after it + * + * @retval 0 success + * @retval ~0 failed + * + * @remarks Calling this API requires that the channel already exists. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_SetChnQpIPDelta(int encChn, int uIPDelta); + +/** + * @fn int IMP_Encoder_SetFisheyeEnableStatus(int encChn, int enable) + * + * Set the enabling state of the fish eye correction algorithm provided by ingenic. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[in] enable: 0: unable(default), 1: enable. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks Because the enabling state of the fisheye correction algorithm is fixed at the time of the creation of the channel, + * the secondary API needs to be called before the channel is created. + * @remarks If this API is not called to set the enable state of the fish eye correction algorithm provided by ingenic before the channel is created, + * it is not enabled by default, the fish eye correction algorithm provided by Junzheng cannot be used. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_SetFisheyeEnableStatus(int encChn, int enable); + +/** + * @fn int IMP_Encoder_GetFisheyeEnableStatus(int encChn, int *enable) + * + * Get the enabling state of the fish eye correction algorithm provided by ingenic. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[out] enable: return Enable state, 0: unable, 1: enable. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @attention This API is only applicable to H264 and H265 encoding channels. + */ +int IMP_Encoder_GetFisheyeEnableStatus(int encChn, int *enable); + +/** + * @fn int IMP_Encoder_GetChnEncType(int encChn, IMPEncoderEncType *encType) + * + * Get image encoding protocol type. + * + * @param[in] encChn: Channel ID, range: [0, @ref NR_MAX_ENC_CHN - 1]. + * @param[out] encType: return encoding protocol type. + * + * @retval 0 success. + * @retval ~0 failed. + * + * @remarks If the channel is not created, then return fails. + * + * @attention none. + */ +int IMP_Encoder_GetChnEncType(int encChn, IMPEncoderEncType *encType); + +/** + * @brief IMP_Encoder_SetPool(int chnNum, int poolID); + * + * bind channel to mempool, let chnNum malloc from pool. + * + * @param[in] chnNum Channel ID. + * @param[in] poolID Pool ID. + * + * @retval 0 success. + * @retval other values failed. + * + * @remarks In order to solve the fragmentation of rmem, the channel encoder is bound to + * the corresponding MemPool. The encoder applies for MEM in the MemPool. If it is not + * called, the encoder will apply in rmem. At this time, there is the possibility of + * fragmentation for rmem. + * + * @attention: chnNum is greater than or equal to 0 and less than 32. + */ +int IMP_Encoder_SetPool(int chnNum, int poolID); + +/** + * @brief IMP_Encoder_GetPool(int chnNum); + * + * Get Pool ID by chnannel ID. + * + * @param[in] chnNum Channel ID. + * + * @retval >=0 && < 32 success. + * @retval other values failed. + * + * @remarks obtains poolid through channelid, which cannot be used by customers temporarily. + * + * @attention none. + */ +int IMP_Encoder_GetPool(int chnNum); + +/** + * @brief IMP_Encoder_SetStreamBufSize(int encChn, uint32_t nrStreamSize); + * + * Set size of Stream buffer. + * + * @param[in] encChn: Channel ID. + * @param[in] nrStreamSize: size of Stream buffer. + * + * @retval >=0 && < 32 success. + * @retval <0 failed. + * + * @remarks This API must be called before the channel is created. + * + * @attention none. + */ +int IMP_Encoder_SetStreamBufSize(int encChn, uint32_t nrStreamSize); + +/** + * @brief IMP_Encoder_GetStreamBufSize(int encChn, uint32_t *nrStreamSize); + * + * Get size of Stream buffer. + * + * @param[in] encChn: Channel ID. + * @param[out] nrStreamSize: size of Stream buffer. + * + * @retval >=0 && < 32 success. + * @retval <0 failed. + * + * @remarks This API must be called after the channel is created. + * + * @attention none. + */ +int IMP_Encoder_GetStreamBufSize(int encChn, uint32_t *nrStreamSize); + +/** + * @brief IMP_Encoder_GetChnAveBitrate(int encChn, IMPEncoderStream *stream, int frames, double *br); + * + * Gets the average bit rate of the specified number of frames. + * + * @param[in] encChn Channel ID. + * @param[in] stream Stream. + * @param[in] frame Count the number of frames(Integral multiple of GOP length). + * @param[out] br Average bitrate. + * + * @retval >=0 && < 32 success. + * @retval <0 failed. + * + * @remarks This API must be called after using IMP_Encoder_GetStream. + * + * @attention none. + */ +int IMP_Encoder_GetChnAveBitrate(int encChn, IMPEncoderStream *stream, int frames, double *br); + +/** + * @brief IMP_Encoder_GetChnEvalInfo(int encChn, void *info); + * + * Obtain the evaluation parameters of each frame in the channel. + * + * @param[in] encChn Channel ID. + * @param[out] info Eval info. + * + * @retval >=0 && < 32 success. + * @retval <0 failed. + * + * @remarks This API must be called after using IMP_Encoder_GetStream. + * + * @attention none. + */ +int IMP_Encoder_GetChnEvalInfo(int encChn, void *info); + +/** + * @fn int IMP_Encoder_SetChnEntropyMode(int encChn,IMPEncoderEntropyMode eEntropyMode) + * + * Set entropy mode in the channel + * + * @param[in] encChn Channel ID. + * @param[in] eEntropyMode Entropy mode. + * + * @retval 0 success. + * @retval <0 failed. + * + * @remarks This API is only applicable to IMP_ENC_PROFILE_AVC_MAIN or IMP_ENC_PROFILE_AVC_HIGH + * @remarks This API needs to be called before the channel is created. + * + * @attention This API is only applicable to H264 encoding channels. + */ +int IMP_Encoder_SetChnEntropyMode(int encChn,IMPEncoderEntropyMode eEntropyMode); + +/** + * @brief IMP_Encoder_SetFrameRelease(int encChn, int num, int den); + * + * Set release frame num and den. + * + * @param[in] encChn: Channnel ID. + * @param[in] num: release num. + * @param[in] den: release den. + * + * @retval >=0 success. + * @retval <0 failed. + * + * @remarks This API must be called after the channel is created. + * + * @attention none. + */ +int IMP_Encoder_SetFrameRelease(int encChn, int num, int den); + +/** + * @} + */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* __IMP_ENCODER_H__ */ diff --git a/sdk/ingenic/include/imp_framesource.h b/sdk/ingenic/include/imp_framesource.h new file mode 100644 index 0000000..a2ed737 --- /dev/null +++ b/sdk/ingenic/include/imp_framesource.h @@ -0,0 +1,600 @@ +/* + * IMP FrameSource header file. + * + * Copyright (C) 2015 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __IMP_FRAMESOURCE_H__ +#define __IMP_FRAMESOURCE_H__ + +#include "imp_common.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * The header file of FrameSource + */ + +/** + * @defgroup IMP_FrameSource + * @ingroup imp + * @brief Video Source is the image source of IMP system, it can set some functions such as setting the image resolution, cropping, scaling and other properties as well as the back-end noise reduction function. + * + * FrameSource is a data flow related to the concept, you can set the image resolution, format, etc., and provide the original image to the back-end. + * + * The scheme of FrameSource is as follow: + * @image html framesource.png + * According to this image above, FrameSource has 3 outputs, all of them can be used for encoding + * *Channel 0 : High clear video stream + * *Channel 1 : Standard clear video stream, or IVS can only do the algorithm of data source + * *Channel 2 : Expands the channel, is is used in special applications, it is not recommended to use it. + * Note: The video that frame channel-1 output maybe used to encode and analyse. \n + * The example of FrameSource's operating instruction is below, + * @code + * IMPFSChnAttr fs_chn_attr; + * fs_chn_attr.pixFmt = PIX_FMT_NV12; + * fs_chn_attr.outFrmRateNum = SENSOR_FRAME_RATE; + * fs_chn_attr.outFrmRateDen = 1; + * fs_chn_attr.nrVBs = 3; + * fs_chn_attr.type = FS_PHY_CHANNEL; + * + * fs_chn_attr.crop.enable = 1; + * fs_chn_attr.crop.top = 0; + * fs_chn_attr.crop.left = 0; + * fs_chn_attr.crop.width = 960; + * fs_chn_attr.crop.height = 640; + * + * fs_chn_attr.scaler.enable = 1; + * fs_chn_attr.scaler.outwidth = 320; + * fs_chn_attr.scaler.outheight = 240; + * + * ret = IMP_FrameSource_CreateChn(0, &fs_chn_attr); //step.1 Create Channel0 + * if (ret < 0) { + * printf("FrameSource_CreateChn(0) error\n"); + * goto createchn_err; + * } + * + * ret = IMP_FrameSource_EnableChn(0); //step.2 Enable Channel 0, Channel 0 starts to output images. + * if (ret < 0) { + * printf("EnableChn(0) error\n"; + * return enablechn_err; + * } + * + * / / so far, FrameSource began to pass data to the back-end Group + * + * + * ret = IMP_FrameSource_DisableChn(0); //step.3 Disable channel 0, Channel 0 stops to output images + * if (ret < 0) { + * printf("FrameSource_DisableChn(0) error\n"); + * return disablechn_err; + * } + * + * ret = IMP_FrameSource_DestroyChn(0); //step.4 destroy channel 0 + * if (ret < 0) { + * printf("FrameSource_DestroyChn error\n"); + * return destorychn_err; + * } + * @endcode + * There are more examples in the content of Samples. + * @{ + */ + +/** +* The structure of cropping operation +*/ +typedef struct { + int enable; /**< Set the parameter to enable/disable cropping */ + int left; /**< the X offset of starting pixel */ + int top; /**< the Y offset of starting pixel */ + int width; /**< the cropped horizontal window size (width) */ + int height; /**< the cropped vertical window size (height) */ +} IMPFSChnCrop; + +/** +* The structure of scaling operation +*/ +typedef struct { + int enable; /**< Set to the parameter to enable/disable scaling */ + int outwidth; /**< the horizontal window size after scaling */ + int outheight; /**< the vertical window size after scaling */ +} IMPFSChnScaler; + +typedef enum { + FS_PHY_CHANNEL, /**< physics frame channel */ + FS_EXT_CHANNEL, /**< virtual frame channel */ +} IMPFSChnType; + +/** +* Channel FIFO Type +*/ +typedef enum { + FIFO_CACHE_PRIORITY = 0, /**< FIFO caches first,then output data */ + FIFO_DATA_PRIORITY, /**< FIFO output data first, then caches */ +} IMPFSChnFifoType; + +typedef enum { + IMP_FSCHANNEL_STATE_CLOSE, /**< fs channel not created or destroied*/ + IMP_FSCHANNEL_STATE_OPEN, /**< fs channel create but not enable*/ + IMP_FSCHANNEL_STATE_RUN, /**=0 && < 32 means success. + * @retval other values mean failure. + * + * @remarks obtains poolid through channelid, which cannot be used by customers temporarily + * + * @attention none. + */ +int IMP_FrameSource_GetPool(int chnNum); + +/** + * @brief IMP_FrameSource_ChnStatQuery(int chnNum, FSChannelState *pstate); + * + * Get framesource by channel ID;0:close,1:open,2:run. + * + * @param[in] chnNum Channel ID. + * + * @retval >=0 means success. + * @retval <0 mean failure. + * + * @remarks + * + * @attention none. + */ +int IMP_FrameSource_ChnStatQuery(int chnNum, IMPFSChannelState *pstate); + +/** + * @fn int IMP_FrameSource_SetChnRotate(int chnNum, uint8_t rotTo90, int width, int height); + * + * Enable FS channel rotation and configure rotation attributes + * + * @param[in] encChn Encoder channel number, value range: [0, @ref NR_MAX_ENC_CHN - 1] + * @param[in] rotTo90 0: disable, 1: rotate 90 ° counterclockwise, 2: rotate 90 ° clockwise + * @param[in] width width Image width before rotation + * @param[in] height height Image height before rotation + * + * @retval >=0 means success. + * @retval <0 mean failure. + * + * @remarks This API needs to be called before channel creation + * @remarks To use this interface, the resolution must be 64 bit aligned + * @remarks After using the modified interface, the width and height of the code should be set to the rotated width and height during the initialization of the coding channel + * @remarks The FS channel rotation function cannot be used together with the encoding soft zoom function + * @remarks Use this function to request an rmem memory to save the rotated frame data + * @remarks The image rotation function is implemented by software, which will occupy computing resources. It is recommended that the resolution be set below 1280 * 704, and the frame rate should not exceed 15 frames + */ +int IMP_FrameSource_SetChnRotate(int chnNum, uint8_t rotTo90, int width, int height); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +/** + * @} + */ + +#endif /* __IMP_FRAMESOURCE_H__ */ diff --git a/sdk/ingenic/include/imp_isp.h b/sdk/ingenic/include/imp_isp.h new file mode 100644 index 0000000..571a3dd --- /dev/null +++ b/sdk/ingenic/include/imp_isp.h @@ -0,0 +1,2849 @@ +/* + * IMP ISP header file. + * + * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __IMP_ISP_H__ +#define __IMP_ISP_H__ + +#include +#include "imp_common.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * The header file of ISP + */ + +/** + * @defgroup IMP_ISP + * @ingroup imp + * @brief Image signal processing unit. It contains several key function, for example, image effects setting, night scene, sensor's operations and so on. + * + * ISP module is not related to the data flow, so no need to process Bind, Only used for effect parameters configuration and sensor controls. + * + * The ISP manipulation is as follow: + * @code + * int ret = 0; + * ret = IMP_ISP_Open(); // step.1 create ISP module + * if(ret < 0){ + * printf("Failed to ISPInit\n"); + * return -1; + * } + * IMPSensorInfo sensor; + * sensor.name = "xxx"; + * sensor.cbus_type = SENSOR_CONTROL_INTERFACE_I2C; // OR SENSOR_CONTROL_INTERFACE_SPI + * sensor.i2c = { + * .type = "xxx", // I2C sets the name, this name has to be the same as the name of the sensor drivers in struct i2c_device_id. + * .addr = xx, // the I2C address + * .i2c_adapter_id = xx, // The value is the I2C adapter ID. + * } + * OR + * sensor.spi = { + * .modalias = "xx", // SPI sets the name, this name has to be the same as the name of the sensor drivers in struct i2c_device_id. + * .bus_num = xx, // It is the address of SPI bus. + * } + * ret = IMP_ISP_AddSensor(&sensor); //step.2, add a sensor. Before the function is called, the sensor driver has to be registered into kernel. + * if (ret < 0) { + * printf("Failed to Register sensor\n"); + * return -1; + * } + * + * ret = IMP_ISP_EnableSensor(void); //step.3, Enable sensor and sensor starts to output image. + * if (ret < 0) { + * printf("Failed to EnableSensor\n"); + * return -1; + * } + * + * ret = IMP_ISP_EnableTuning(); //step.4, Enable ISP tuning, then you can use ISP debug interface. + * if (ret < 0) { + * printf("Failed to EnableTuning\n"); + * return -1; + * } + * + * Debug interface, please refer to the ISP debug interface documentation //step.5 Effect of debugging. + * + * @endcode + * The process which uninstall(disable)ISP is as follows: + * @code + * int ret = 0; + * IMPSensorInfo sensor; + * sensor.name = "xxx"; + * ret = IMP_ISP_DisableTuning(); //step.1 Turn off ISP tuning + * if (ret < 0) { + * printf("Failed to disable tuning\n"); + * return -1; + * } + * + * ret = IMP_ISP_DisableSensor(); //step.2, Turn off sensor, Note that sensor will stop output pictures, so that all FrameSource should be closed. + * if (ret < 0) { + * printf("Failed to disable sensor\n"); + * return -1; + * } + * + * ret = IMP_ISP_DelSensor(&sensor); //step.3, Delete sensor, before that step, the sensor has to be stopped. + * if (ret < 0) { + * printf("Failed to disable sensor\n"); + * return -1; + * } + * + * ret = IMP_ISP_Close(); //step.4, After deleting all sensors, you can run this interface to clean up the ISP module. + * if (ret < 0) { + * printf("Failed to disable sensor\n"); + * return -1; + * } + * @endcode + * There are more examples in the samples. + * @{ + */ + +/** +* The enum is types of sensor control bus. +*/ +typedef enum { + TX_SENSOR_CONTROL_INTERFACE_I2C = 1, /**< I2C control bus */ + TX_SENSOR_CONTROL_INTERFACE_SPI, /**< SPI control bus */ +} IMPSensorControlBusType; + +/** +* Defines I2C bus information +*/ +typedef struct { + char type[20]; /**< Set the name, the value must be match with sensor name in 'struct i2c_device_id' */ + int addr; /**< the I2C address */ + int i2c_adapter_id; /**< I2C adapter ID */ +} IMPI2CInfo; +/** +* Defines SPI bus information +*/ +typedef struct { + char modalias[32]; /**< Set the name, the value must be match with sensor name in 'struct i2c_device_id' */ + int bus_num; /**< Address of SPI bus */ +} IMPSPIInfo; + +/** +* Defines the information of sensor +*/ +typedef struct { + char name[32]; /**< the sensor name */ + IMPSensorControlBusType cbus_type; /**< the sensor control bus type */ + union { + IMPI2CInfo i2c; /**< I2C bus information */ + IMPSPIInfo spi; /**< SPI bus information */ + }; + unsigned short rst_gpio; /**< The reset pin of sensor, but it is invalid now. */ + unsigned short pwdn_gpio; /**< The power down pin of sensor, but it is invalid now. */ + unsigned short power_gpio; /**< The power pin of sensor, but it is invalid now. */ +} IMPSensorInfo; + +/** + * @fn int IMP_ISP_Open(void) + * + * Open the ISP module + * + * @param none + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark After calling the function,it first creates the ISP module, then prepares to add sensor to ISP, and starts the ISP effect debugging function. + * + * @attention Before adding sensor image, this function must be called firstly. + */ +int IMP_ISP_Open(void); + +/** + * @fn int IMP_ISP_Close(void) + * + * Close the ISP module + * + * @param none + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark After calling the function, ISP will stop working. + * + * @attention Before calling this function, make sure that all FrameSources and effect debugging functions are off(disabled), and all sensors are deleted. + */ +int IMP_ISP_Close(void); + +/** + * @fn int32_t IMP_ISP_SetDefaultBinPath(char *path) + * + * Sets the default path to the ISP bin file. + * + * @param[in] path The bin file path property to set. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark Sets the absolute path to the Bin file when the user-defined ISP is started. + * + * @attention This function must be called before adding the sensor and after opening the ISP. + */ +int32_t IMP_ISP_SetDefaultBinPath(char *path); + +/** + * @fn int32_t IMP_ISP_GetDefaultBinPath(char *path) + * + * Gets the default path to the ISP bin file. + * + * @param[out] path The bin file path property to get. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark Get the absolute path to the Bin file when the user-defined ISP is started. + * + * @attention This function must be called after the sensor is added. + * @attention Only bin file path attributes for a single ISP can be retrieved at a time. + */ +int32_t IMP_ISP_GetDefaultBinPath(char *path); + +/** + * @fn int IMP_ISP_AddSensor(IMPSensorInfo *pinfo) + * + * Add a sensor into ISP module. + * + * @param[in] pinfo The pointer for the sensor information. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark The sensor will be used to capture image. + * + * @attention Before using this function, you must ensure that the camera driver has been registered into the kernel. + */ +int IMP_ISP_AddSensor(IMPSensorInfo *pinfo); + +/** + * @fn int IMP_ISP_DelSensor(IMPSensorInfo *pinfo) + * + * Delete a sensor from ISP module. + * + * @param[in] pinfo The pointer for the sensor information + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark Delete a sensor(image sensor which would be a camera) + * + * @attention Before using this function, you must ensure that the sensor has been stopped working, use IMP_ISP_DisableSensor function to do so. + */ +int IMP_ISP_DelSensor(IMPSensorInfo *pinfo); + +/** + * @fn int IMP_ISP_EnableSensor(void) + * + * Enable the registered sensor. + * + * @param none + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark Enable the registered sensor, then FrameSource can ouput image and ISP tuns on the image effects. + * + * @attention Before using this function, you must ensure that the sensor is already registered into ISP module. + */ +int IMP_ISP_EnableSensor(void); + +/** + * @fn int IMP_ISP_DisableSensor(void) + * + * Disable the running sensor. + * + * @param none + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark if a sensor is not used, FrameSource and ISP won't be working either. + * + * @attention Before using this function, you must ensure that the Framesource and ISP have stopped working. + */ +int IMP_ISP_DisableSensor(void); + +/** + * @fn int IMP_ISP_SetSensorRegister(uint32_t reg, uint32_t value) + * + * Set the value of a register of a sensor. + * + * @param[in] reg The address of the register. + * + * @param[in] value The value of the register. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark Value of a register can be directly set. + * + * @attention Before using this function, you must ensure that the sensor is working, so it will be able to be configured or set. + */ +int IMP_ISP_SetSensorRegister(uint32_t reg, uint32_t value); + +/** + * @fn int IMP_ISP_GetSensorRegister(uint32_t reg, uint32_t *value) + * + * Obtain a value of the register of sensor. + * + * @param[in] reg The address of the register. + * + * @param[in] value The pointer of register value. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark You can directly obtain the value of the sensor's register. + * + * @attention Before using this function, you must ensure that the sensor is working. + */ +int IMP_ISP_GetSensorRegister(uint32_t reg, uint32_t *value); + +/** + * ISP OPTION MODE parameter structure. + */ + +typedef enum { + IMPISP_TUNING_OPS_MODE_DISABLE, /**< DISABLE mode of the current module */ + IMPISP_TUNING_OPS_MODE_ENABLE, /**< ENABLE mode of the current module */ + IMPISP_TUNING_OPS_MODE_BUTT, /**< effect paramater, parameters have to be less than this value*/ +} IMPISPTuningOpsMode; + +/** + * ISP MODE property parameter structure. + */ +typedef enum { + IMPISP_TUNING_OPS_TYPE_AUTO, /**< AUTO mode of the current module*/ + IMPISP_TUNING_OPS_TYPE_MANUAL, /**< MANUAL mode of the current module*/ + IMPISP_TUNING_OPS_TYPE_BUTT, /**< effect paramater, parameters have to be less than this value*/ +} IMPISPTuningOpsType; + +typedef struct { + unsigned int zone[15][15]; /**< zone info*/ +} __attribute__((packed, aligned(1))) IMPISPZone; + +/** + * ISP AutoZoom Attribution + */ +typedef struct { + int chan; /** */ + int scaler_enable; /** */ + int scaler_outwidth;/** */ + int scaler_outheight;/** */ + int crop_enable; /** */ + int crop_left; /** */ + int crop_top; /** */ + int crop_width; /** */ + int crop_height; /** */ +} IMPISPAutoZoom; + +/** + * @fn int IMP_ISP_Tuning_SetAutoZoom(IMPISPAutoZoom *ispautozoom) + * + * setting Auto zoom parameters + * + * @param[in] Setting parameters for changing resolution + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using this function, you must ensure that 'IMP_ISP_EnableSensor' is working. + */ +int IMP_ISP_Tuning_SetAutoZoom(IMPISPAutoZoom *ispautozoom); + +/** + * @fn int IMP_ISP_EnableTuning(void) + * + * Enable effect debugging of ISP + * + * @param none + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using this function, you must ensure that 'IMP_ISP_EnableSensor' is working. + */ +int IMP_ISP_EnableTuning(void); + +/** + * @fn int IMP_ISP_DisableTuning(void) + * + * Disable effect debugging of ISP + * + * @param none + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention First you must ensure that ISP is no longer working, then stop the sensor, after that you can use this function. + */ +int IMP_ISP_DisableTuning(void); + +/** + * @fn int IMP_ISP_Tuning_SetSensorFPS(uint32_t fps_num, uint32_t fps_den) + * + * Set the FPS of enabled sensor. + * + * @param[in] fps_num The numerator value of FPS. + * @param[in] fps_den The denominator value of FPS. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using this function, make sure that 'IMP_ISP_EnableSensor' and 'IMP_ISP_EnableTuning' are working properly. + */ +int IMP_ISP_Tuning_SetSensorFPS(uint32_t fps_num, uint32_t fps_den); + +/** + * @fn int IMP_ISP_Tuning_GetSensorFPS(uint32_t *fps_num, uint32_t *fps_den) + * + * Get the FPS of enabled sensor. + * + * @param[in] fps_num The pointer for numerator value of FPS. + * @param[in] fps_den The pointer for denominator value of FPS. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using this function, make sure that 'IMP_ISP_EnableSensor' and 'IMP_ISP_EnableTuning' are working properly. + * @attention Before starting data transmission in a Channel, you must first call this function in order to obtain the sensor's default FPS. + */ +int IMP_ISP_Tuning_GetSensorFPS(uint32_t *fps_num, uint32_t *fps_den); + +/** + * ISP Anti-flicker property parameter structure. + */ +typedef enum { + IMPISP_ANTIFLICKER_DISABLE, /**< Disable antiflicker module */ + IMPISP_ANTIFLICKER_50HZ, /**< Enable antiflicker module and set the frequency to 50HZ */ + IMPISP_ANTIFLICKER_60HZ, /**< Enable antiflicker module and set the frequencye to 60HZ */ + IMPISP_ANTIFLICKER_BUTT, /**< effect parameter, parameters have to be less than this value*/ +} IMPISPAntiflickerAttr; + +/** + * @fn int IMP_ISP_Tuning_SetAntiFlickerAttr(IMPISPAntiflickerAttr attr) + * + * Set the antiflicker parameter. + * + * @param[in] attr The value for antiflicker mode + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before calling this function, make sure that ISP debugging function is working. + */ +int IMP_ISP_Tuning_SetAntiFlickerAttr(IMPISPAntiflickerAttr attr); + +/** + * @fn int IMP_ISP_Tuning_GetAntiFlickerAttr(IMPISPAntiflickerAttr *pattr) + * + * Get the mode of antiflicker + * + * @param[in] pattr The pointer for antiflicker mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before calling this function, make sure that ISP debugging function is working. + */ +int IMP_ISP_Tuning_GetAntiFlickerAttr(IMPISPAntiflickerAttr *pattr); + +/** + * @fn int IMP_ISP_Tuning_SetBrightness(unsigned char bright) + * + * Set the brightness of image effect. + * + * @param[in] bright The value for brightness. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark The default value is 128, more than 128 that means increase brightness, and less than 128 that means decrease brightness.\n + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetBrightness(unsigned char bright); + +/** + * @fn int IMP_ISP_Tuning_GetBrightness(unsigned char *pbright) + * + * Get the brightness of image effect. + * + * @param[in] pbright The pointer for brightness value. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark The default value is 128, more than 128 (increase brightness), and less than 128 (decrease brightness).\n + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetBrightness(unsigned char *pbright); + +/** + * @fn int IMP_ISP_Tuning_SetContrast(unsigned char contrast) + * + * Set the contrast of image effect. + * + * @param[in] contrast The value for contrast. + * + * @retval 0 means success. + * @retval Other value means failure, its value is an error code. + * + * @remark The default value is 128, more than 128 (increase contrast), and less than 128 (decrease contrast). + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetContrast(unsigned char contrast); + +/** + * @fn int IMP_ISP_Tuning_GetContrast(unsigned char *pcontrast) + * + * Get the contrast of image effect. + * + * @param[in] pcontrast The pointer for contrast. + * + * @retval 0 means success. + * @retval Other value means failure, its value is an error code. + * + * @remark The default value is 128, more than 128 (increase contrast), and less than 128 (decrease contrast). + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetContrast(unsigned char *pcontrast); + +/** + * @fn int IMP_ISP_Tuning_SetSharpness(unsigned char sharpness) + * + * Set the sharpness of image effect. + * + * @param[in] sharpness The value for sharpening strength. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark The default value is 128, more than 128 (increase sharpening), and less than 128 (decrease sharpening). + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetSharpness(unsigned char sharpness); + +/** + * @fn int IMP_ISP_Tuning_GetSharpness(unsigned char *psharpness) + * + * Get the sharpness of image effect. + * + * @param[in] psharpness The pointer for sharpness strength. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark The default value is 128, more than 128 (increase sharpening), and less than 128 (decrease sharpening). + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetSharpness(unsigned char *psharpness); + +/** + * @fn int IMP_ISP_Tuning_SetBcshHue(unsigned char hue) + * + * Set the hue of image color. + * + * @param[in] hue The value of hue, range from 0 to 255, default 128. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark The default value is 128, more than 128 that means increase hue, and less than 128 that means decrease hue. + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetBcshHue(unsigned char hue); + +/** + * @fn int IMP_ISP_Tuning_GetBcshHue(unsigned char *hue) + * + * Get the hue of image color. + * + * @param[in] hue The pointer for hue value. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark The default value is 128, more than 128 (increase hue), and less than 128 (decrease hue). + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetBcshHue(unsigned char *hue); + +/** + * @fn int IMP_ISP_Tuning_SetSaturation(unsigned char sat) + * + * Set the saturation of image effect. + * + * @param[in] sat The value for saturation strength. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark The default value is 128, more than 128 (increase saturation), and less than 128 (decrease saturation). + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetSaturation(unsigned char sat); + +/** + * @fn int IMP_ISP_Tuning_GetSaturation(unsigned char *psat) + * + * Get the saturation of image effect. + * + * @param[in] psat The pointer for saturation strength. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark The default value is 128, more than 128 (increase saturation), and less than 128 (decrease saturation). + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetSaturation(unsigned char *psat); + +/** + * @fn int IMP_ISP_Tuning_SetISPBypass(IMPISPTuningOpsMode enable) + * + * Control ISP modules. + * + * @param[in] enable bypass output mode (yes / no) + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark none + * + * @attention Before using it, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetISPBypass(IMPISPTuningOpsMode enable); + +/** + * @fn int IMP_ISP_Tuning_GetTotalGain(uint32_t *gain) + * + * Get the overall gain value of the ISP output image + * + * @param[in] gain The pointer of total gain value, its format is [24.8], 24 (integer), 8(decimal) + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using this function, make sure that 'IMP_ISP_EnableSensor' and 'IMP_ISP_EnableTuning' are working properly. + */ +int IMP_ISP_Tuning_GetTotalGain(uint32_t *gain); + +/** + * @fn int IMP_ISP_Tuning_SetISPHflip(IMPISPTuningOpsMode mode) + * + * Set ISP image mirror(horizontal) effect function (enable/disable) + * + * @param[in] mode The hflip (enable/disable). + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark Left and Right flip. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetISPHflip(IMPISPTuningOpsMode mode); + +/** + * @fn int IMP_ISP_Tuning_GetISPHflip(IMPISPTuningOpsMode *pmode) + * + * Get ISP image mirror(horizontal) effect function (enable/disable) + * + * @param[in] pmode The pointer for the hflip mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark Left and Right flip. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetISPHflip(IMPISPTuningOpsMode *pmode); + +/** + * @fn int IMP_ISP_Tuning_SetISPVflip(IMPISPTuningOpsMode mode) + * + * Set ISP image mirror(vertical) effect function (enable/disable) + * + * @param[in] mode The vflip enable. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark UP and DOWN flip. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetISPVflip(IMPISPTuningOpsMode mode); + +/** + * @fn int IMP_ISP_Tuning_GetISPVflip(IMPISPTuningOpsMode *pmode) + * + * Get ISP image mirror(vertical) effect function (enable/disable) + * + * @param[in] pmode The pointer for the vflip mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark UP and DOWN flip. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetISPVflip(IMPISPTuningOpsMode *pmode); + +/** + * Defines the enumeration of ISP working mode. + */ +typedef enum { + IMPISP_RUNNING_MODE_DAY = 0, /**< ISP day mode */ + IMPISP_RUNNING_MODE_NIGHT = 1, /**< ISP night mode */ + IMPISP_RUNNING_MODE_BUTT, /**< maximum value */ +} IMPISPRunningMode; + +/** + * @fn int IMP_ISP_Tuning_SetISPRunningMode(IMPISPRunningMode mode) + * + * Set ISP running mode, normal mode or night vision mode; default mode: normal mode. + * + * @param[in] mode running mode parameter + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * Example: + * @code + * IMPISPRunningMode mode; + * + * if( it is during a night now){ + mode = IMPISP_RUNNING_MODE_NIGHT + }else{ + mode = IMPISP_RUNNING_MODE_DAY; + } + ret = IMP_ISP_Tuning_SetISPRunningMode(mode); + if(ret){ + IMP_LOG_ERR(TAG, "IMP_ISP_Tuning_SetISPRunningMode error !\n"); + return -1; + } + * + * @endcode + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetISPRunningMode(IMPISPRunningMode mode); + +/** + * @fn int IMP_ISP_Tuning_GetISPRunningMode(IMPISPRunningMode *pmode) + * + * Get ISP running mode, normal mode or night vision mode; + * + * @param[in] pmode The pointer of the running mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetISPRunningMode(IMPISPRunningMode *pmode); + +/** + * @fn int IMP_ISP_Tuning_SetISPCustomMode(IMPISPTuningOpsMode mode) + * + * Enable ISP custom mode, load another set of parameters. + * + * @param[in] mode Custom mode, enable or disable. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetISPCustomMode(IMPISPTuningOpsMode mode); + +/** + * @fn int IMP_ISP_Tuning_GetISPCustomMode(IMPISPTuningOpsMode mode) + * + * get ISP custom mode + * + * @param[out] mode Custom mode, enable or disable. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetISPCustomMode(IMPISPTuningOpsMode *pmode); + +/** + * Defines the attribute of gamma. + */ +typedef struct { + uint16_t gamma[129]; /**< The array of gamma attribute has 129 elements */ +} IMPISPGamma; + +/** +* @fn int IMP_ISP_Tuning_SetGamma(IMPISPGamma *gamma) +* +* Sets the attributes of ISP gamma. +* +* @param[in] gamma The pointer of the attributes. +* +* @retval 0 means success. +* @retval Other values mean failure, its value is an error code. +* +* @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. +*/ +int IMP_ISP_Tuning_SetGamma(IMPISPGamma *gamma); + +/** +* @fn int IMP_ISP_Tuning_GetGamma(IMPISPGamma *gamma) +* +* Obtains the attributes of gamma. +* +* @param[out] gamma The address of the attributes. +* +* @retval 0 means success. +* @retval Other values mean failure, its value is an error code. +* +* @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. +*/ +int IMP_ISP_Tuning_GetGamma(IMPISPGamma *gamma); + +/** +* @fn int IMP_ISP_Tuning_SetAeComp(int comp) +* +* Setting AE compensation.AE compensation parameters can adjust the target of the image AE. +* the recommended value range is from 0 to 255. +* +* @param[in] comp compensation parameter. +* +* @retval 0 means success. +* @retval Other values mean failure, its value is an error code. +* +* @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. +*/ +int IMP_ISP_Tuning_SetAeComp(int comp); + +/** +* @fn int IMP_ISP_Tuning_GetAeComp(int *comp) +* +* Obtains the compensation of AE. +* +* @param[out] comp The pointer of the compensation. +* +* @retval 0 means success. +* @retval Other values mean failure, its value is an error code. +* +* @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. +*/ +int IMP_ISP_Tuning_GetAeComp(int *comp); + +/** +* @fn int IMP_ISP_Tuning_GetAeLuma(int *luma) +* +* Obtains the AE luma of current frame. +* +* @param[out] luma AE luma parameter. +* +* @retval 0 means success. +* @retval Other values mean failure, its value is an error code. +* +* @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. +*/ +int IMP_ISP_Tuning_GetAeLuma(int *luma); + +/** + * @fn int IMP_ISP_Tuning_SetAeFreeze(IMPISPTuningOpsMode mode) + * + * AE Freeze. + * + * @param[in] mode AE Freeze mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAeFreeze(IMPISPTuningOpsMode mode); + +/** + * exposure mode. + */ +enum isp_core_expr_mode { + ISP_CORE_EXPR_MODE_AUTO, /**< Auto exposure mode */ + ISP_CORE_EXPR_MODE_MANUAL, /**< Manual exposure mode */ +}; + +/** + * exposure unit. + */ +enum isp_core_expr_unit { + ISP_CORE_EXPR_UNIT_LINE, /**< The unit is integration line */ + ISP_CORE_EXPR_UNIT_US, /**< The unit is millisecond */ +}; + +/** + * exposure parameters. + */ +typedef union isp_core_expr_attr{ + struct { + enum isp_core_expr_mode mode; /**< set the exposure mode */ + enum isp_core_expr_unit unit; /**< set the exposure unit */ + uint16_t time; + } s_attr; + struct { + enum isp_core_expr_mode mode; /**< exposure mode obtained */ + uint16_t integration_time; /**< The integration time, the unit is line. */ + uint16_t integration_time_min; /**< The min value of integration time, the unit is line. */ + uint16_t integration_time_max; /**< The max value of integration time, the unit is line. */ + uint16_t one_line_expr_in_us; /**< A integration line correspond to the time (ms) */ + } g_attr; +}IMPISPExpr; + + +/** + * @fn int IMP_ISP_Tuning_SetExpr(IMPISPExpr *expr) + * + * Set AE attributes. + * + * @param[in] expr The pointer for exposure attributes. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetExpr(IMPISPExpr *expr); + +/** + * @fn int IMP_ISP_Tuning_GetExpr(IMPISPExpr *expr) + * + * Get AE attributes. + * + * @param[in] expr The pointer for exposure attributes. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetExpr(IMPISPExpr *expr); + +/** + * exposure region of interest. + */ +typedef union isp_core_ae_roi_select{ + struct { + unsigned endy :8; /**< y coordinate(end), the range is from 0 to 255.*/ + unsigned endx :8; /**< x coordinate(end), the range is from 0 to 255.*/ + unsigned starty :8; /**< y coordinate(start), the range is from 0 to 255.*/ + unsigned startx :8; /**< x coordinate(start), the range is from 0 to 255.*/ + }; + uint32_t value; +} IMPISPAERoi; + +/** + * White balance mode. + */ +enum isp_core_wb_mode { + ISP_CORE_WB_MODE_AUTO = 0, /**< Auto WB mode */ + ISP_CORE_WB_MODE_MANUAL, /**< Manual WB mode */ + ISP_CORE_WB_MODE_DAY_LIGHT, /**< Day-light mode */ + ISP_CORE_WB_MODE_CLOUDY, /**< Cloudy day mode */ + ISP_CORE_WB_MODE_INCANDESCENT, /**< Incandescent mode */ + ISP_CORE_WB_MODE_FLOURESCENT, /**< Fluorescent mode */ + ISP_CORE_WB_MODE_TWILIGHT, /**< Twilight mode */ + ISP_CORE_WB_MODE_SHADE, /**< Shade mode */ + ISP_CORE_WB_MODE_WARM_FLOURESCENT, /**< Warm color fluorescent mode */ + ISP_CORE_WB_MODE_CUSTOM, /**< Custom mode */ +}; + +/** + * White balance attributes. + */ +typedef struct isp_core_wb_attr{ + enum isp_core_wb_mode mode; /**< The mode for WB; auto and manual mode */ + uint16_t rgain; /**< red gain attribute, manual mode is effective*/ + uint16_t bgain; /**< blue gain attribute, manual mode is effective*/ +}IMPISPWB; + +/** + * @fn int IMP_ISP_Tuning_SetWB(IMPISPWB *wb) + * + * Set the white balance function settings. You can set the automatic and manual mode, manual mode is achieved mainly through setting of bgain, rgain. + * + * @param[in] wb The pointer for WB attribute. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetWB(IMPISPWB *wb); + +/** + * @fn int IMP_ISP_Tuning_GetWB(IMPISPWB *wb) + * + * Get the white balance function settings + * + * @param[in] wb The pointer for WB attribute. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetWB(IMPISPWB *wb); + +/** + * @fn IMP_ISP_Tuning_GetWB_Statis(IMPISPWB *wb) + * + * Get the white balance statistic value. + * + * @param[out] wb The pointer for the statistic. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetWB_Statis(IMPISPWB *wb); + +/** + * @fn IMP_ISP_Tuning_GetWB_GOL_Statis(IMPISPWB *wb) + * + * Get the white balance global statistic value. + * + * @param[out] wb The pointer for the statistic. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetWB_GOL_Statis(IMPISPWB *wb); + +/* + * ISP AWB CLuster Mode Parameters structure + */ +typedef struct { + IMPISPTuningOpsMode ClusterEn; /* Cluster AWB Enable ctrl*/ + IMPISPTuningOpsMode ToleranceEn; /* AWB Tolerance mode Enable ctrl */ + unsigned int tolerance_th; /* AWB Tolerance Threshold, range 0~64*/ + unsigned int awb_cluster[7]; /* Cluster AWB Parameters Array*/ +}IMPISPAWBCluster; + +/** + * @fn int IMP_ISP_Tuning_SetAwbClust(IMPISPAWBCluster *awb_cluster); + * + * Set Cluster AWB mode Parameters. + * + * @param[in] awb_cluster contains cluster awb mode parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetAwbClust(IMPISPAWBCluster *awb_cluster); + +/** + * @fn int IMP_ISP_Tuning_GetAwbClust(IMPISPAWBCluster *awb_cluster); + * + * Get Cluster AWB mode Parameters. + * + * @param[out] awb_cluster contains cluster awb mode parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetAwbClust(IMPISPAWBCluster *awb_cluster); + +/* + * ISP AWB Ct Trend Parameters + */ +typedef struct { + unsigned int trend_array[6]; /* rg offset & bg offset of hight middle low ct */ +}IMPISPAWBCtTrend; + +/** + * @fn int IMP_ISP_Tuning_SetAwbCtTrend(IMPISPAWBCtTrend *ct_trend); + + * + * Set rg bg offset under different ct. + * + * @param[in] ct_trend contains ct offset parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetAwbCtTrend(IMPISPAWBCtTrend *ct_trend); + +/** + * @fn int IMP_ISP_Tuning_GetAwbCtTrend(IMPISPAWBCtTrend *ct_trend); + + * + * Get rg bg offset under different ct. + * + * @param[out] ct_trend contains current ct offset parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetAwbCtTrend(IMPISPAWBCtTrend *ct_trend); + +/** + * ISP WB COEFFT parameter structure. + */ +typedef struct isp_core_rgb_coefft_wb_attr { + unsigned short rgb_coefft_wb_r; /**< rgain offset */ + unsigned short rgb_coefft_wb_g; /**< ggain offset */ + unsigned short rgb_coefft_wb_b; /**< bgain offset */ + +}IMPISPCOEFFTWB; + +/** + * @fn int IMP_ISP_Tuning_Awb_GetRgbCoefft(IMPISPCOEFFTWB *isp_core_rgb_coefft_wb_attr); + * + * Set the AWB r g b channel offset source in ISP. + * + * @param[out] isp_wb_attr The pointer for the attributes + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_Awb_GetRgbCoefft(IMPISPCOEFFTWB *isp_core_rgb_coefft_wb_attr); + +/** + * @fn int IMP_ISP_Tuning_Awb_SetRgbCoefft(IMPISPCOEFFTWB *isp_core_rgb_coefft_wb_attr) + * + * Sets the Max value of sensor color r g b. + * + * @param[in] gain The value for sensor sensor color r g b.. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_Awb_SetRgbCoefft(IMPISPCOEFFTWB *isp_core_rgb_coefft_wb_attr); + +/** + * @fn int IMP_ISP_Tuning_SetMaxAgain(uint32_t gain) + * + * Sets the Max value of sensor analog gain. + * + * @param[in] gain The value for sensor analog gain. + * The value of 0 corresponds to 1x gain, 32 corresponds to 2x gain and so on. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetMaxAgain(uint32_t gain); + +/** + * @fn int IMP_ISP_Tuning_GetMaxAgain(uint32_t *gain) + * + * Get the Max value of sensor analog gain. + * + * @param[in] gain The pointer for sensor analog gain. + * The value of 0 corresponds to 1x gain, 32 corresponds to 2x gain and so on. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetMaxAgain(uint32_t *gain); + +/** + * @fn int IMP_ISP_Tuning_SetMaxDgain(uint32_t gain) + * + * Set the Max value of sensor Digital gain. + * + * @param[in] gain The pointer for sensor digital gain. + * The value of 0 corresponds to 1x gain, 32 corresponds to 2x gain and so on. + * + * @retval 0 success + * @retval others failure + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + * Sets the Max value of isp digital gain.。 + * + * @param[in] gain The value for isp digital gain. The value of 0 corresponds to 1x gain, 32 corresponds to 2x gain and so on. + * + * @retval 0 means success. + * @retval Other values means failure, its value is an error code. + * + * @attention When the interface is called, 'IMP_ISP_EnableTuning' has returned successfully. + */ +int IMP_ISP_Tuning_SetMaxDgain(uint32_t gain); + +/** + * @fn int IMP_ISP_Tuning_GetMaxDgain(uint32_t *gain) + * + * Get the Max value of sensor Digital gain. + * + * @param[out] gain The pointer for sensor digital gain. + * The value of 0 corresponds to 1x gain, 32 corresponds to 2x gain and so on. + * + * @retval 0 success + * @retval others failure + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetMaxDgain(uint32_t *gain); + +/** + * Obtains the Max value of isp digital gain. + * + * @param[out] gain The pointer for isp digital gain. The value of 0 corresponds to 1x gain, 32 corresponds to 2x gain and so on. + * + * @retval 0 means success. + * @retval Other values means failure, its value is an error code. + * + * @attention When the interface is called, 'IMP_ISP_EnableTuning' has returned successfully. + */ +int IMP_ISP_Tuning_GetMaxDgain(uint32_t *gain); + +/** + * @fn int IMP_ISP_Tuning_SetVideoDrop(void (*cb)(void)) + * + * Set the video loss function. When there is a problem with the connection line of the sensor board, the callback function will be executed. + * + * @param[in] cb The pointer for callback function. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetVideoDrop(void (*cb)(void)); + +/** + * @fn int IMP_ISP_Tuning_SetHiLightDepress(uint32_t strength) + * + * Set highlight intensity controls. + * + * @param[in] strength Highlight control parameter, the value range is [0-10], set to 0 means disable the current function. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetHiLightDepress(uint32_t strength); + +/** + * @fn int IMP_ISP_Tuning_GetHiLightDepress(uint32_t *strength) + * + * Get the strength of high light depress. + * + * @param[out] strength The pointer for hilight depress strength. + * The value of 0 corresponds to disable. + * + * @retval 0 success + * @retval others failure + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetHiLightDepress(uint32_t *strength); + +/** + * @fn int IMP_ISP_Tuning_SetBacklightComp(uint32_t strength) + * + * Set backlight intensity controls. + * + * @param[in] strength Backlight control parameter, the value range is [0-10], set to 0 means disable the current function. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetBacklightComp(uint32_t strength); + +/** + * @fn int IMP_ISP_Tuning_GetBacklightComp(uint32_t *strength) + * + * Get the strength of backlight compensation. + * + * @param[out] strength The pointer for backlight compensation strength. + * The value of 0 corresponds to disable. + * + * @retval 0 success + * @retval others failure + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_GetBacklightComp(uint32_t *strength); + +/** + * @fn int IMP_ISP_Tuning_SetTemperStrength(uint32_t ratio) + * + * Set 3D noise reduction intensity + * + * @param[in] ratio Intensity modulation ratio. Default value is 128.If it is greater than 128, that means increaseing the temper value. If it is less than 128, that means decreaing the temper value. The value range is [0-255]. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetTemperStrength(uint32_t ratio); + +/** + * @fn int IMP_ISP_Tuning_SetSinterStrength(uint32_t ratio) + * + * Set 2D noise reduction intensity + * + * @param[in] ratio Intensity modulation ratio. Default value is 128.If it is greater than 128, that means increaseing the sinter value. If it is less than 128, that means decreaing the sinter value. The value range is [0-255]. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_SetSinterStrength(uint32_t ratio); + +/** + * attributes of ISP exposure value. + */ +typedef struct { + uint32_t ev; /**< exposure value*/ + uint32_t expr_us; /**< exposure time in millisecond */ + uint32_t ev_log2; /**< exposure time in log2 format */ + uint32_t again; /**< Analog gain */ + uint32_t dgain; /**< Digital gain */ + uint32_t gain_log2; /**< Gain in log2 format */ +}IMPISPEVAttr; + +/** +* @fn int IMP_ISP_Tuning_GetEVAttr(IMPISPEVAttr *attr) +* +* Obtains the attributes of exposure value. +* @param[out] attr The pointer for attributes. +* +* @retval 0 means success. +* @retval Other values mean failure, its value is an error code. +* +* @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. +*/ +int IMP_ISP_Tuning_GetEVAttr(IMPISPEVAttr *attr); + +/** +* @fn int IMP_ISP_Tuning_EnableMovestate(void) +* +* When the sensor will motion, it should be called. +* +* @retval 0 means success. +* @retval Other values mean failure, its value is an error code. +* +* @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. +*/ +int IMP_ISP_Tuning_EnableMovestate(void); + +/** +* @fn IMP_ISP_Tuning_DisableMovestate(void) +* +* When the sensor is from motion to still, it should be called. +* +* @retval 0 means success. +* @retval Other values mean failure, its value is an error code. +* +* @attention Before using it, make sure that 'IMP_ISP_Tuning_EnableMovestate' is working properly. +*/ +int IMP_ISP_Tuning_DisableMovestate(void); + + +/** + * Mode selection + */ +typedef enum { + IMPISP_TUNING_MODE_AUTO, /**< AUTO mode of the current module */ + IMPISP_TUNING_MODE_MANUAL, /**< MANUAL mode of the current module */ + IMPISP_TUNING_MODE_RANGE, /**< Set the range of current module */ + IMPISP_TUNING_MODE_BUTT, /**< effect paramater, parameters have to be less than this value */ +} IMPISPTuningMode; + +/** + * Weight information + */ +typedef struct { + unsigned char weight[15][15]; /**< The weight info of each zone [0 ~ 8]*/ +} IMPISPWeight; + +/** + * @fn int IMP_ISP_Tuning_SetAeWeight(IMPISPWeight *ae_weight) + * + * Set zone weighting for AE target + * + * @param[in] ae_weight aexp weight. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAeWeight(IMPISPWeight *ae_weight); + +/** + * @fn int IMP_ISP_Tuning_GetAeWeight(IMPISPWeight *ae_weight) + * + * Get zone weighting for AE target + * + * @param[out] ae_weight aexp weight. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAeWeight(IMPISPWeight *ae_weight); + +/** + * @fn int IMP_ISP_Tuning_AE_GetROI(IMPISPWeight *roi_weight) + * + * Set roi weighting for AE SCENE judgement + * + * @param[out] roi_weight aexp weight. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_AE_GetROI(IMPISPWeight *roi_weight); + +/** + * @fn int IMP_ISP_Tuning_AE_SetROI(IMPISPWeight *roi_weight) + * + * Set roi weighting for AE SCENE judgement + * + * @param[in] roi_weight aexp weight. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int IMP_ISP_Tuning_AE_SetROI(IMPISPWeight *roi_weight); + +/** + * @fn int IMP_ISP_Tuning_SetAwbWeight(IMPISPWeight *awb_weight) + * + * Set zone weighting for AWB + * + * @param[in] awb_weight awb weight. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAwbWeight(IMPISPWeight *awb_weight); + +/** + * @fn int IMP_ISP_Tuning_GetAwbWeight(IMPISPWeight *awb_weight) + * + * Get zone weighting for AWB + * + * @param[out] awb_weight awb weight。 + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAwbWeight(IMPISPWeight *awb_weight); + +/** + * AWB statistics + */ +typedef struct { + unsigned char zone_r[225]; /**< 15*15 statistical average of each zone in R channel*/ + unsigned char zone_g[225]; /**< 15*15 statistical average of each zone in G channel*/ + unsigned char zone_b[225]; /**< 15*15 statistical average of each zone in B channel*/ +} IMPISPAWBZone; +/** + * @fn int IMP_ISP_Tuning_GetAwbZone(IMPISPAWBZONE *awb_zone) + * + * Get WB zone statistical average in R G B channel + * + * @param[out] awb_zone wb statistics。 + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAwbZone(IMPISPAWBZone *awb_zone); + +/** + * AWB algorithm + */ +typedef enum { + IMPISP_AWB_ALGO_NORMAL = 0, /*normal mode, use effective pixels for statistics*/ + IMPISP_AWB_ALGO_GRAYWORLD, /*grayworld mode, use all pixels for statistics*/ + IMPISP_AWB_ALGO_REWEIGHT, /*reweight for different color temperature*/ +} IMPISPAWBAlgo; + +/** + * @fn int IMP_ISP_Tuning_SetWB_ALGO(IMPISPAWBALGO wb_algo) + * + * Set AWB algorithm for different application situation + * + * @param[in] awb algorithm + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ + +int IMP_ISP_Tuning_SetWB_ALGO(IMPISPAWBAlgo wb_algo); + +/** + * AE statistics + */ +typedef struct { + unsigned char ae_histhresh[4]; /**< AE Histogram threshold for bin boundary.[0 ~ 255] */ + unsigned short ae_hist[5]; /**< Normalized histogram results for bin.[0 ~ 65535] */ + unsigned char ae_stat_nodeh; /**< Number of active zones horizontally for AE stats collection.[0 ~ 15]*/ + unsigned char ae_stat_nodev; /**< Number of active zones vertically for AE stats collection.[0 ~ 15]*/ +} IMPISPAEHist; + +/** + * AE statistics + */ +typedef struct { + unsigned int ae_hist[256]; /**< AE histogram results for 256 bin*/ +} IMPISPAEHistOrigin; + +/** + * @fn int IMP_ISP_Tuning_SetAeHist(IMPISPAEHist *ae_hist) + * + * Set AE statistics parameters + * + * @param[in] ae_hist AE statictics parameters. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAeHist(IMPISPAEHist *ae_hist); + +/** + * @fn int IMP_ISP_Tuning_GetAeHist(IMPISPAEHist *ae_hist) + * + * Get AE statistics information. + * + * @param[out] ae_hist AE statistics + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAeHist(IMPISPAEHist *ae_hist); + +/** + * @fn int IMP_ISP_Tuning_GetAeHist_Origin(IMPISPAEHistOrigin *ae_hist) + * + * Get AE 256 bin statistics information. + * + * @param[out] ae_hist AE statistics + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAeHist_Origin(IMPISPAEHistOrigin *ae_hist); + +/** + * AWB statistics + */ +struct isp_core_awb_sta_info{ + unsigned short r_gain; /**< AWB statistics R/G color ratio output [0 ~ 4095] 4.8bit fixed-point */ + unsigned short b_gain; /**< AWB statistics B/G color ratio output [0 ~ 4095] 4.8bit fixed-point */ + unsigned int awb_sum; /**< Number of pixels used for AWB statistics [0 ~ 4294967295] */ +}; +/** + * AWB statictis mode + */ +enum isp_core_awb_stats_mode{ + IMPISP_AWB_STATS_LEGACY_MODE = 0, /**< Legacy mode */ + IMPISP_AWB_STATS_CURRENT_MODE = 1, /**< Current mode */ + IMPISP_AWB_STATS_MODE_BUTT, +}; +/** + * AWB statictis parameters + */ +typedef struct { + struct isp_core_awb_sta_info awb_stat; /**< AWB statistics */ + enum isp_core_awb_stats_mode awb_stats_mode; /**< AWB statistic mode */ + unsigned short awb_whitelevel; /**< Upper limit of valid data for AWB [0 ~ 1023]*/ + unsigned short awb_blacklevel; /**< lower limit of valid data for AWB [0 ~ 1023]*/ + unsigned short cr_ref_max; /**< Maximum value of R/G for white region [0 ~ 4095] 4.8bit fixed-point*/ + unsigned short cr_ref_min; /**< Minimum value of R/G for white region [0 ~ 4095] 4.8bit fixed-point */ + unsigned short cb_ref_max; /**< Maximum value of B/G for white region [0 ~ 4095] 4.8bit fixed-point */ + unsigned short cb_ref_min; /**< Minimum value of B/G for white region [0 ~ 4095] 4.8bit fixed-point */ + unsigned char awb_stat_nodeh; /**< Number of active zones horizontally for AWB stats collection.[0 ~ 15] */ + unsigned char awb_stat_nodev; /**< Number of active zones vertically for AWB stats collection.[0 ~ 15] */ +} IMPISPAWBHist; + +/** + * @fn int IMP_ISP_Tuning_GetAwbHist(IMPISPAWBHist *awb_hist) + * + * Set AWB statistic parameters + * + * @param[out] awb_hist AWB statistic parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using this function, IMP_ISP_EnableTuning is called. + */ +int IMP_ISP_Tuning_GetAwbHist(IMPISPAWBHist *awb_hist); + +/** + * @fn int IMP_ISP_Tuning_SetAwbHist(IMPISPAWBHist *awb_hist) + * + * Get AWB Statistics + * + * @param[out] awb_hist AWB statistic + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAwbHist(IMPISPAWBHist *awb_hist); + +/** + * AF statistics + */ +struct isp_core_af_sta_info{ + unsigned int af_metrics; /**< The integrated and normalized measure of contrast*/ + unsigned int af_metrics_alt; /**< The integrated and normalized measure of contrast - with alternative threshold*/ +}; +/** + * AF statistics + */ +typedef struct { + struct isp_core_af_sta_info af_stat; /**< AF statistics*/ + unsigned char af_enable; /**< AF enable*/ + unsigned char af_metrics_shift; /**< Metrics scaling factor 0x0 is default */ + unsigned short af_delta; /**< AF statistics low pass fliter weight [0 ~ 64]*/ + unsigned short af_theta; /**< AF statistics high pass fliter weight [0 ~ 64]*/ + unsigned short af_hilight_th; /**< AF high light threshold [0 ~ 255]*/ + unsigned short af_alpha_alt; /**< AF statistics H and V direction weight [0 ~ 64]*/ + unsigned char af_hstart; /**< AF statistic pixel start by horizontal:[1 ~ width], must be odd number*/ + unsigned char af_vstart; /**< AF statistic pixel start by vertical:[3 ~ height], must be odd number*/ + unsigned char af_stat_nodeh; /**< Number of zones horizontally for AF stats [1 ~ 15] */ + unsigned char af_stat_nodev; /**< Number of zones vertically for AF stats [1 ~ 15] */ + unsigned char af_frame_num; +} IMPISPAFHist; + +/** + * @fn int int IMP_ISP_Tuning_GetAFMetrices(unsigned int *metric); + * + * Get AF statistic metric + * + * @param[in] metric AF statistic metric + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAFMetrices(unsigned int *metric); + +/** + * @fn int IMP_ISP_Tuning_GetAfHist(IMPISPAFHist *af_hist); + * + * Set AF statistic parameters + * + * @param[out] af_hist AF statistic parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAfHist(IMPISPAFHist *af_hist); + +/** + * @fn int IMP_ISP_Tuning_SetAfHist(IMPISPAFHist *af_hist) + * + * Get AF statistics + * + * @param[in] af_hist AF statistics parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAfHist(IMPISPAFHist *af_hist); + +/** + * @fn int IMP_ISP_Tuning_SetAfWeight(IMPISPWeight *af_weight) + * + * Set zone weighting for AF + * + * @param[in] af_weight af weight. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAfWeight(IMPISPWeight *af_weight); + +/** + * @fn int IMP_ISP_Tuning_GetAfWeight(IMPISPWeight *af_weight) + * + * Get zone weighting for AF + * + * @param[in] af_weight af weight. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAfWeight(IMPISPWeight *af_weight); + +/** + * @fn int IMP_ISP_Tuning_GetAfZone(IMPISPZone *af_zone) + * + * Get AF zone metric information. + * + * @param[out] af_zone AF metric info per zone + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAfZone(IMPISPZone *af_zone); + +/** + * ISP Wait Frame Params。 + */ +typedef struct { + uint32_t timeout; /**< timeout,unit ms */ + uint64_t cnt; /**< Frame num */ +}IMPISPWaitFrameAttr; +/** + * @fn int IMP_ISP_Tuning_WaitFrame(IMPISPWaitFrameAttr *attr) + * Wait frame done + * + * @param[out] attr frame done parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_WaitFrame(IMPISPWaitFrameAttr *attr); + +/** + * AE Min + */ +typedef struct { + unsigned int min_it; /**< AE min integration time */ + unsigned int min_again; /**< AE min analog gain */ + unsigned int min_it_short; /**< AE min integration time on short frame */ + unsigned int min_again_short; /**< AE min analog gain on short frame */ +} IMPISPAEMin; + +/** + * @fn int IMP_ISP_Tuning_SetAeMin(IMPISPAEMin *ae_min) + * + * Set AE Min parameters + * + * @param[in] ae_min AE min parameters. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAeMin(IMPISPAEMin *ae_min); + +/** + * @fn int IMP_ISP_Tuning_GetAeMin(IMPISPAEMin *ae_min) + * + * Get AE min information. + * + * @param[out] ae_min AE min parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAeMin(IMPISPAEMin *ae_min); + +/** + * @fn int IMP_ISP_Tuning_SetAe_IT_MAX(unsigned int it_max) + * + * Set AE Max parameters + * + * @param[in] it_max AE max it parameters. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAe_IT_MAX(unsigned int it_max); + +/** + * @fn int IMP_ISP_Tuning_GetAE_IT_MAX(unsigned int *it_max) + * + * Get AE max information. + * + * @param[out] ae_max AE max it parameters + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAE_IT_MAX(unsigned int *it_max); + +/** + * @fn int IMP_ISP_Tuning_GetAeZone(IMPISPZone *ae_zone) + * + * Get AE zone y information. + * + * @param[out] ae_zone AE y info per zone + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAeZone(IMPISPZone *ae_zone); + +/* + * ISP AE Target Parameters + */ +typedef struct { + unsigned int at_list[10]; /*ae target list*/ +} IMPISPAETargetList; + +/** + * @fn int IMP_ISP_Tuning_GetAeTargetList(IMPISPAETargetList *at_list) + * + * Set AE target List + * + * @param[in] at_list ae target list. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAeTargetList(IMPISPAETargetList *at_list); + +/** + * @fn int IMP_ISP_Tuning_GetAeTargetList(IMPISPAETargetList *at_list) + * + * Get AE target List + * + * @param[out] at_list ae target list. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAeTargetList(IMPISPAETargetList *at_list); + +/** + * ISP Module Control + */ +typedef union { + unsigned int key; + struct { + unsigned int bitBypassBLC : 1; /* [0] */ + unsigned int bitBypassGIB : 1; /* [1] */ + unsigned int bitBypassAG : 1; /* [2] */ + unsigned int bitBypassWDR : 1; /* [3] */ + unsigned int bitBypassDPC : 1; /* [4] */ + unsigned int bitBypassRDNS : 1; /* [5] */ + unsigned int bitBypassLSC : 1; /* [6] */ + unsigned int bitBypassADR : 1; /* [7] */ + unsigned int bitBypassDMSC : 1; /* [8] */ + unsigned int bitBypassCCM : 1; /* [9] */ + unsigned int bitBypassGAMMA : 1; /* [10] */ + unsigned int bitBypassDEFOG : 1; /* [11] */ + unsigned int bitBypassCSC : 1; /* [12] */ + unsigned int bitBypassCLM : 1; /* [13] */ + unsigned int bitBypassSP : 1; /* [14] */ + unsigned int bitBypassYDNS : 1; /* [15] */ + unsigned int bitBypassBCSH : 1; /* [16] */ + unsigned int bitBypassSDNS : 1; /* [17] */ + unsigned int bitBypassHLDC : 1; /* [18] */ + unsigned int bitRsv : 12; /* [19 ~ 30] */ + unsigned int bitBypassMDNS : 1; /* [31] */ + }; +} IMPISPModuleCtl; + +/** + * @fn int IMP_ISP_Tuning_SetModuleControl(IMPISPModuleCtl *ispmodule) + * + * Set ISP Module control + * + * @param[in] ispmodule ISP Module control. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetModuleControl(IMPISPModuleCtl *ispmodule); + +/** + * @fn int IMP_ISP_Tuning_GetModuleControl(IMPISPModuleCtl *ispmodule) + * + * Get ISP Module control. + * + * @param[out] ispmodule ISP Module control + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetModuleControl(IMPISPModuleCtl *ispmodule); + +/** + * ISP Front Crop Attribution + */ +typedef struct { + bool fcrop_enable; + unsigned int fcrop_top; + unsigned int fcrop_left; + unsigned int fcrop_width; + unsigned int fcrop_height; +} IMPISPFrontCrop; + +/** + * @fn int IMP_ISP_Tuning_SetFrontCrop(IMPISPFrontCrop *ispfrontcrop) + * + * Set Front Crop attribution + * + * @param[in] ispfrontcrop IFront Crop attribution. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetFrontCrop(IMPISPFrontCrop *ispfrontcrop); + +/** + * @fn int IMP_ISP_Tuning_GetFrontCrop(IMPISPFrontCrop *ispfrontcrop) + * + * Get Front Crop Attribution. + * + * @param[out] ispfrontcrop IFront Crop attribution. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetFrontCrop(IMPISPFrontCrop *ispfrontcrop); + +/** + * @fn int IMP_ISP_WDR_ENABLE(IMPISPTuningOpsMode mode) + * + * Enable ISP WDR. + * + * @paramin[in] mode ISP WDR mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_WDR_ENABLE(IMPISPTuningOpsMode mode); + +/** + * @fn IMP_ISP_WDR_ENABLE_Get(IMPISPTuningOpsMode* mode) + * + * Get ISP WDR Mode. + * + * @param[in] mode ISP WDR mode + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_WDR_ENABLE_Get(IMPISPTuningOpsMode* mode); + +/** + * @fn int IMP_ISP_Tuning_SetDPC_Strength(unsigned int ratio) + * + * Set DPC Strength. + * + * @param[in] ratio Intensity modulation ratio. Default value is 128.If it is greater than 128, that means increaseing the dpc value. If it is less than 128, that means decreaing the dpc value. The value range is [0-255]. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetDPC_Strength(unsigned int ratio); + +/** + * @fn int IMP_ISP_Tuning_GetDPC_Strength(unsigned int *strength) + * + * Get DPC Strength. + * + * @param[out] ratio Intensity modulation ratio. Default value is 128.If it is greater than 128, that means increaseing the dpc value. If it is less than 128, that means decreaing the dpc value. The value range is [0-255]. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetDPC_Strength(unsigned int *ratio); + +/** + * @fn int IMP_ISP_Tuning_SetDRC_Strength(unsigned int ratio) + * + * Set DRC Strength. + * + * @param[in] ratio Intensity modulation ratio. Default value is 128.If it is greater than 128, that means increaseing the drc value. If it is less than 128, that means decreaing the drc value. The value range is [0-255]. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetDRC_Strength(unsigned int ratio); + +/** + * @fn int IMP_ISP_Tuning_GetDRC_Strength(unsigned int *ratio) + * + * Get DRC Strength. + * + * @param[out] ratio Intensity modulation ratio. Default value is 128.If it is greater than 128, that means increaseing the drc value. If it is less than 128, that means decreaing the drc value. The value range is [0-255]. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetDRC_Strength(unsigned int *ratio); + +/** + * HFlip and VFlip parameters + */ +typedef enum { + IMPISP_FLIP_NORMAL_MODE = 0, /**< normal mode */ + IMPISP_FLIP_H_MODE = 1, /**< only mirror mode */ + IMPISP_FLIP_V_MODE = 2, /**< only flip mode */ + IMPISP_FLIP_HV_MODE = 3, /**< mirror & flip mode */ + IMPISP_FLIP_MODE_BUTT, +} IMPISPHVFLIP; + +/** + * @fn int IMP_ISP_Tuning_SetHVFLIP(IMPISPHVFLIP hvflip) + * + * Set HV Flip mode. + * + * @param[in] hvflip HV Flip mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetHVFLIP(IMPISPHVFLIP hvflip); + +/** + * @fn int IMP_ISP_Tuning_GetHVFlip(IMPISPHVFLIP *hvflip) + * + * Get HV Flip mode. + * + * @param[out] hvflip hvflip mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetHVFlip(IMPISPHVFLIP *hvflip); + +/** + * fill data type of Mask parameters + */ +typedef enum { + IMPISP_MASK_TYPE_RGB = 0, /**< RGB type */ + IMPISP_MASK_TYPE_YUV = 1, /**< YUV type */ +} IMPISP_MASK_TYPE; + +/** + * fill data value of Mask parameters + */ +typedef union mask_value { + struct { + unsigned char Red; /**< R offset of RGB type */ + unsigned char Green; /**< G offset of RGB type */ + unsigned char Blue; /**< B offset of RGB type */ + } mask_rgb; /**< RGB type */ + struct { + unsigned char y_value; /**< Y offset of YUV type */ + unsigned char u_value; /**< U offset of YUV type */ + unsigned char v_value; /**< V offset of YUV type */ + } mask_ayuv; /**< YUV type */ +} IMP_ISP_MASK_VALUE; + +/** + * Mask parameters of each channel + */ +typedef struct isp_mask_block_par { + unsigned char mask_en;/**< mask enable */ + unsigned short mask_pos_top;/**< y of mask position */ + unsigned short mask_pos_left;/**< x of mask position */ + unsigned short mask_width;/**< mask block width */ + unsigned short mask_height;/**< mask block height */ + IMP_ISP_MASK_VALUE mask_value;/**< mask value */ +} IMPISP_MASK_BLOCK_PAR; + +/** + * Mask parameters + */ +typedef struct { + IMPISP_MASK_BLOCK_PAR chn0[4];/**< chan0 mask attr */ + IMPISP_MASK_BLOCK_PAR chn1[4];/**< chan1 mask attr */ + IMPISP_MASK_BLOCK_PAR chn2[4];/**< chan2 mask attr */ + IMPISP_MASK_TYPE mask_type;/**< mask type */ +} IMPISPMASKAttr; + +/** + * @fn int IMP_ISP_Tuning_SetMask(IMPISPMASKAttr *mask) + * + * Set Mask Attr. + * + * @param[in] mask Mask attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetMask(IMPISPMASKAttr *mask); + +/** + * @fn int IMP_ISP_Tuning_GetMask(IMPISPMASKAttr *mask) + * + * Get Mask Attr. + * + * @param[out] mask Mask attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetMask(IMPISPMASKAttr *mask); + +/** + * Sensor attr parameters + */ +typedef struct { + unsigned int hts;/**< sensor hts */ + unsigned int vts;/**< sensor vts */ + unsigned int fps;/**< sensor fps: */ + unsigned int width;/**< sensor width*/ + unsigned int height;/**< sensor height*/ +} IMPISPSENSORAttr; +/** + * @fn int IMP_ISP_Tuning_GetSensorAttr(IMPISPSENSORAttr *attr) + * + * Get Sensor Attr. + * + * @param[out] attr Sensor attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetSensorAttr(IMPISPSENSORAttr *attr); + +/** + * @fn int IMP_ISP_Tuning_EnableDRC(IMPISPTuningOpsMode mode) + * + * Enable DRC. + * + * @param[out] mode DRC ENABLE mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_EnableDRC(IMPISPTuningOpsMode mode); + +/** + * @fn int IMP_ISP_Tuning_EnableDefog(IMPISPTuningOpsMode mode) + * + * Enable Defog. + * + * @param[out] mode Defog ENABLE mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_EnableDefog(IMPISPTuningOpsMode mode); + +/** + * @fn int IMP_ISP_Tuning_SetAwbCt(unsigned int *ct) + * + * set awb color temp. + * + * @param[out] ct AWB color temp value. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetAwbCt(unsigned int *ct); + +/** + * @fn int IMP_ISP_Tuning_GetAWBCt(unsigned int *ct) + * + * Get AWB color temp. + * + * @param[out] ct AWB color temp value. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAWBCt(unsigned int *ct); + +/** + * ISP CCM Attr + */ +typedef struct { + IMPISPTuningOpsMode ManualEn; /* CCM Manual enable ctrl */ + IMPISPTuningOpsMode SatEn; /* CCM Saturation enable ctrl */ + float ColorMatrix[9]; /* color matrix on manual mode */ +} IMPISPCCMAttr; +/** + * @fn int IMP_ISP_Tuning_SetCCMAttr(IMPISPCCMAttr *ccm) + * + * set ccm attr + * + * @param[out] ccm ccm attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetCCMAttr(IMPISPCCMAttr *ccm); + +/** + * @fn int IMP_ISP_Tuning_GetCCMAttr(IMPISPCCMAttr *ccm) + * + * Get CCM Attr. + * + * @param[out] ccm ccm attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetCCMAttr(IMPISPCCMAttr *ccm); + +/** + * ISP AE Attr + */ +typedef struct { + /* Ae Manual Attr On Linear Mode and Long Frame Which on WDR MODE */ + IMPISPTuningOpsMode AeFreezenEn; /* Ae Freezen Manual enable ctrl */ + IMPISPTuningOpsMode AeItManualEn; /* Ae Integration time Manual enable ctrl */ + unsigned int AeIt; /* Ae Integration time value */ + IMPISPTuningOpsMode AeAGainManualEn; /* Ae Sensor Analog Gain Manual enable ctrl */ + unsigned int AeAGain; /* Ae Sensor Analog Gain value */ + IMPISPTuningOpsMode AeDGainManualEn; /* Ae Sensor Digital Gain Manual enable ctrl */ + unsigned int AeDGain; /* Ae Sensor Digital Gain value */ + IMPISPTuningOpsMode AeIspDGainManualEn; /* Ae Isp Digital Gain Manual enable ctrl */ + unsigned int AeIspDGain; /* Ae Isp Digital Gain value */ + + /* Ae Mnaual Attr on Short Frame Which on WDR Mode*/ + IMPISPTuningOpsMode AeWdrShortFreezenEn; /* AeWdrShort Freezen Manual enable ctrl */ + IMPISPTuningOpsMode AeWdrShortItManualEn; /* AeWdrShort Integration time Manual enable ctrl */ + unsigned int AeWdrShortIt; /* AeWdrShort Integration time value */ + IMPISPTuningOpsMode AeWdrShortAGainManualEn; /* AeWdrShort Sensor Analog Gain Manual enable ctrl */ + unsigned int AeWdrShortAGain; /* AeWdrShort Sensor Analog Gain value */ + IMPISPTuningOpsMode AeWdrShortDGainManualEn; /* AeWdrShort Sensor Digital Gain Manual enable ctrl */ + unsigned int AeWdrShortDGain; /* AeWdrShort Sensor Digital Gain value */ + IMPISPTuningOpsMode AeWdrShortIspDGainManualEn; /* AeWdrShort Isp Digital Gain Manual enable ctrl */ + unsigned int AeWdrShortIspDGain; /* AeWdrShort Isp Digital Gain value */ +} IMPISPAEAttr; +/** + * @fn int IMP_ISP_Tuning_SetAeAttr(IMPISPAEAttr *ae) + * + * set Ae attr + * + * @param[out] ae ae manual attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + * @attention Before set the attr, you must memset the IMPISPAEAttr structure to 0, and then set the corresponding attr. + */ +int IMP_ISP_Tuning_SetAeAttr(IMPISPAEAttr *ae); + +/** + * @fn int IMP_ISP_Tuning_GetAeAttr(IMPISPAEAttr *ae) + * + * Get Ae Attr. + * + * @param[out] ae ae manual attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAeAttr(IMPISPAEAttr *ae); + +/** + * AE state info + */ +typedef struct { + bool stable; /*ae stable info, 1:stable 0:converging*/ + unsigned int target; /*current ae target*/ + unsigned int ae_mean; /*current ae statistical weighted average value*/ +}IMPISPAEState; + +/** + * @fn int IMP_ISP_Tuning_GetAeState(IMPISPAEState *ae_state) + * + * Get Ae State info. + * + * @param[out] ae ae state info. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_GetAeState(IMPISPAEState *ae_state); + +/** + * Scaler method + */ +typedef enum { + IMP_ISP_SCALER_METHOD_FITTING_CURVE, + IMP_ISP_SCALER_METHOD_FIXED_WEIGHT, + IMP_ISP_SCALER_METHOD_BUTT, +} IMPISPScalerMethod; + +/** + * Scaler effect params + */ +typedef struct { + unsigned char channel; /*channel 0~2*/ + IMPISPScalerMethod method; /*scaler method*/ + unsigned char level; /*scaler level range 0~128*/ +} IMPISPScalerLv; + +/** + * @fn int IMP_ISP_Tuning_SetScalerLv(IMPISPScalerLv *scaler_level) + * + * Set Scaler method and level. + * + * @param[in] mscaler opt. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + */ +int IMP_ISP_Tuning_SetScalerLv(IMPISPScalerLv *scaler_level); + +/** + * 3th custom AE library init Attribution + */ +typedef struct { + enum isp_core_expr_unit AeIntegrationTimeUnit; /**< AE integration time unit */ + uint32_t AeIntegrationTime; /**< AE integration time value */ + uint32_t AeAGain; /**< AE sensor analog gain value */ + uint32_t AeDGain; /**< AE sensor analog gain value */ + uint32_t AeIspDGain; /**< AE ISP digital gain value */ + + uint32_t AeMinIntegrationTime; /**< AE min integration time */ + uint32_t AeMinAGain; /**< AE min sensor analog gain */ + uint32_t AeMinDgain; /**< AE min sensor digital gain */ + uint32_t AeMinIspDGain; /**< AE min isp digital gain */ + uint32_t AeMaxIntegrationTime; /**< AE max integration time */ + uint32_t AeMaxAGain; /**< AE max sensor analog gain */ + uint32_t AeMaxDgain; /**< AE max sensor digital gain */ + uint32_t AeMaxIspDGain; /**< AE max isp digital gain */ + + /* AE Manual mode attr for short frame on WDR mode*/ + uint32_t AeShortIntegrationTime; /**< AE integration time value */ + uint32_t AeShortAGain; /**< AE sensor analog gain value */ + uint32_t AeShortDGain; /**< AE sensor digital gain value */ + uint32_t AeShortIspDGain; /**< AE ISP digital gain value */ + + uint32_t AeShortMinIntegrationTime; /**< AE min integration time */ + uint32_t AeShortMinAGain; /**< AE min sensor analog gain */ + uint32_t AeShortMinDgain; /**< AE min sensor digital gain */ + uint32_t AeShortMinIspDGain; /**< AE min isp digital gain */ + uint32_t AeShortMaxIntegrationTime; /**< AE max integration time */ + uint32_t AeShortMaxAGain; /**< AE max sensor analog gain */ + uint32_t AeShortMaxDgain; /**< AE max sensor digital gain */ + uint32_t AeShortMaxIspDGain; /**< AE max isp digital gain */ + + uint32_t fps; /**< sensor fps 16/16 */ + IMPISPAEHist AeStatis; /**< Ae statis attrbution */ +} IMPISPAeInitAttr; + +/** + * 3th custom AE library AE information + */ +typedef struct { + IMPISPZone ae_zone; /**< AE statis each zone */ + IMPISPAEHistOrigin ae_hist_256bin; /**< AE 256 bin hist */ + IMPISPAEHist ae_hist; /**< AE 5 bin hist and attribution */ + enum isp_core_expr_unit AeIntegrationTimeUnit; /**< AE integration time unit */ + uint32_t AeIntegrationTime; /**< AE integration time value */ + uint32_t AeAGain; /**< AE sensor analog gain value */ + uint32_t AeDGain; /**< AE sensor digital gain value */ + uint32_t AeIspDGain; /**< AE ISP digital gain value */ + uint32_t AeShortIntegrationTime; /**< AE integration time value */ + uint32_t AeShortAGain; /**< AE sensor analog gain value */ + uint32_t AeShortDGain; /**< AE sensor digital gain value */ + uint32_t AeShortIspDGain; /**< AE ISP digital gain value */ + + uint32_t Wdr_mode; /**< WDR mode or not */ + IMPISPSENSORAttr sensor_attr; /**< sensor attribution */ +} __attribute__((packed, aligned(1))) IMPISPAeInfo; + +/** + * 3th custom AE library AE attribution + */ +typedef struct { + uint32_t change; /**< change AE attr or not */ + enum isp_core_expr_unit AeIntegrationTimeUnit; /**< AE integration time unit */ + + uint32_t AeIntegrationTime; /**< AE integration time value */ + uint32_t AeAGain; /**< AE sensor analog gain value */ + uint32_t AeDGain; /**< AE sensor digital gain value */ + uint32_t AeIspDGain; /**< AE ISP digital gain value */ + + /* AE Manual mode attr for short frame on WDR mode*/ + uint32_t AeShortIntegrationTime; /**< AE integration time value */ + uint32_t AeShortAGain; /**< AE sensor analog gain value */ + uint32_t AeShortDGain; /**< AE sensor digital gain value */ + uint32_t AeShortIspDGain; /**< AE ISP digital gain value */ + + uint32_t luma; /**< AE Luma value */ + uint32_t luma_scence; /**< AE scence Luma value */ +} IMPISPAeAttr; + +/** + * 3th custom AE library AE notify attribution + */ +typedef enum { + IMPISP_AE_NOTIFY_FPS_CHANGE, /* AE notify the fps change*/ +} IMPISPAeNotify; + +typedef struct { + void *priv_data; /* private data addr*/ + int (*open)(void *priv_data, IMPISPAeInitAttr *AeInitAttr); /* AE open function for 3th custom library*/ + void (*close)(void *priv_data); /* AE close function for 3th custom library*/ + void (*handle)(void *priv_data, const IMPISPAeInfo *AeInfo, IMPISPAeAttr *AeAttr); /* AE handle function for 3th custom library*/ + int (*notify)(void *priv_data, IMPISPAeNotify notify, void* data); /* AE notify function for 3th custom library*/ +} IMPISPAeAlgoFunc; + +/** + * @fn int32_t IMP_ISP_SetAeAlgoFunc(IMPISPAeAlgoFunc *ae_func) + * + * the callback functions interface for 3th custom AE library. + * + * @param[in] ae_func the callback functions. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that IMP_ISP_AddSensor have be called. + */ +int32_t IMP_ISP_SetAeAlgoFunc(IMPISPAeAlgoFunc *ae_func); + + +/** + * 3th custom AWB library AWB init information + */ +typedef struct { + uint32_t cur_r_gain; /* current awb r-gain*/ + uint32_t cur_b_gain; /* current awb b-gain*/ + uint32_t r_gain_statis; /* current awb r-gain of global statis info*/ + uint32_t b_gain_statis; /* current awb b-gain of global statis info*/ + uint32_t r_gain_wei_statis; /* current awb r-gain of global weighted statis info*/ + uint32_t b_gain_wei_statis; /* current awb b-gain of global weighted statis info*/ + IMPISPAWBZone awb_statis; /* current awb statis info for each zone*/ +}__attribute__((packed, aligned(1))) IMPISPAwbInfo; + +/** + * 3th custom AWB library AWB attribution + */ +typedef struct { + uint32_t change; /* change awb attribution or not*/ + uint32_t r_gain; /* awb attribution of r-gain*/ + uint32_t b_gain; /* awb attribution of b-gain*/ + uint32_t ct; /* awb color temp*/ +} IMPISPAwbAttr; + +/** + * 3th custom AWB library AWB notify attribution + */ +typedef enum { + IMPISP_AWB_NOTIFY_MODE_CHANGE, +} IMPISPAwbNotify; + +/** + * 3th custom AWB library callback functions + */ +typedef struct { + void *priv_data; /* private data addr*/ + int (*open)(void *priv_data); /* AWB open function for 3th custom library*/ + void (*close)(void *priv_data); /* AWB close function for 3th custom library*/ + void (*handle)(void *priv_data, const IMPISPAwbInfo *AwbInfo, IMPISPAwbAttr *AwbAttr); /* AWB handle function for 3th custom library*/ + int (*notify)(void *priv_data, IMPISPAwbNotify notify, void *data); /* AWB notify function for 3th custom library*/ +} IMPISPAwbAlgoFunc; + +int32_t IMP_ISP_SetAwbAlgoFunc(IMPISPAwbAlgoFunc *awb_func); +/** + * @fn int32_t IMP_ISP_SetAwbAlgoFunc(IMPISPAwbAlgoFunc *awb_func) + * + * the callback functions interface for 3th custom AWB library. + * + * @param[in] awb_func the callback functions. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that IMP_ISP_AddSensor have be called. + */ + +/** + * black level attr + */ +typedef struct { + unsigned int black_level_r; /**< R channel */ + unsigned int black_level_gr; /**< GR channel */ + unsigned int black_level_gb; /**< GB channel */ + unsigned int black_level_b; /**< B channel */ + unsigned int black_level_ir; /**< IR channel */ +} IMPISPBlcAttr; + +/** + * @fn int IMP_ISP_Tuning_GetBlcAttr(IMPISPBlcAttr *blc) + * + * Gets the associated properties of the BLC. + * + * @param[out] blc blc attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using that function, make sure that ISP is working properly. + * @attention Before set the attr, you must memset the IMPISPAEAttr structure to 0. + */ +int IMP_ISP_Tuning_GetBlcAttr(IMPISPBlcAttr *blc); + +/** + * @fn int32_t IMP_ISP_Tuning_SetDefog_Strength(uint8_t *ratio) + * + * set isp defog module ratio. + * + * @param[in] ratio defog module ratio. + * + * @retval 0 means success. + * @retval Other value means failure, its value is an error code. + * + * @attention Before using it, make sure that ISP is working properly. + */ +int32_t IMP_ISP_Tuning_SetDefog_Strength(uint8_t *ratio); + +/** + * @fn int32_t IMP_ISP_Tuning_GetDefog_Strength(uint8_t *ratio) + * + * @param[in] ratio defog module ratio. + * + * @retval 0 means success. + * @retval Other value means failure, its value is an error code. + * + * @attention Before using it, make sure that ISP is working properly. + */ +int32_t IMP_ISP_Tuning_GetDefog_Strength(uint8_t *ratio); + +typedef enum { + ISP_CSC_CG_BT601_FULL, /**< BT601 full range */ + ISP_CSC_CG_BT601_CLIP, /**< BT601 not full range */ + ISP_CSC_CG_BT709_FULL, /**< BT709 full range */ + ISP_CSC_CG_BT709_CLIP, /**< BT709 not full range */ + ISP_CSC_CG_USER, /**< CUSTOM mode. Only use this mode, the IMPISPCscMatrix parameters is valid. */ + IMP_CSC_CG_BUTT, /**< effect paramater, parameters have to be less than this value */ +} IMPISPCscCgMode; + +typedef struct { + int csc_coef[9]; /**< 3x3 matrix */ + int csc_offset[2]; /**< [0]:UV offset [1]:Y offset */ + int csc_y_clip[2]; /**< Y max, Y min */ + int csc_c_clip[2]; /**< UV max, UV min */ +} IMPISPCscParam; + +typedef struct { + IMPISPCscCgMode mode; /**< mode */ + IMPISPCscParam csc_par; /**< Custom Matrix */ +} IMPISPCscAttr; + +/** + * @fn int32_t IMP_ISP_Tuning_SetCsc_Attr(IMPISPCscAttr *attr) + * + * Set the properties of CSC module. + * + * @param[in] attr CSC module attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int32_t IMP_ISP_Tuning_SetCsc_Attr(IMPISPCscAttr *attr); + +/** + * @fn int32_t IMP_ISP_Tuning_GetCsc_Attr(IMPISPCscAttr *attr) + * + * Get the properties of CSC module. + * + * @param[out] attr CSC module attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int32_t IMP_ISP_Tuning_GetCsc_Attr(IMPISPCscAttr *attr); + +/** + * WDR output mode. + */ +typedef enum { + IMPISP_WDR_OUTPUT_MODE_FUS_FRAME, /**< Mixture mode */ + IMPISP_WDR_OUTPUT_MODE_LONG_FRAME, /**< Long frame mode */ + IMPISP_WDR_OUTPUT_MODE_SHORT_FRAME, /**< Short frame mode */ + IMPISP_WDR_OUTPUT_MODE_BUTT, /**< effect paramater, parameters have to be less than this value */ +} IMPISPWdrOutputMode; + +/** + * @fn int32_t IMP_ISP_Tuning_SetWdr_OutputMode(IMPISPWdrOutputMode *mode) + * + * Set the WDR image output mode. + * + * @param[in] mode output mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int32_t IMP_ISP_Tuning_SetWdr_OutputMode(IMPISPWdrOutputMode *mode); + +/** + * @fn int32_t IMP_ISP_Tuning_GetWdr_OutputMode(IMPISPWdrOutputMode *mode) + * + * Get the WDR image output mode. + * + * @param[out] mode output mode. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int32_t IMP_ISP_Tuning_GetWdr_OutputMode(IMPISPWdrOutputMode *mode); + +/** + * frame drop parameter. + */ +typedef struct { + IMPISPTuningOpsMode enable; /**< enbale mark */ + uint8_t lsize; /**< sum (range:0~31) */ + uint32_t fmark; /**< bit mark(1 output,0 drop) */ +} IMPISPFrameDrop; + +/** + * frame drop attr. + */ +typedef struct { + IMPISPFrameDrop fdrop[3]; /**< frame drop parameters for each channel */ +} IMPISPFrameDropAttr; + +/** + * @fn int32_t IMP_ISP_SetFrameDrop(IMPISPFrameDropAttr *attr) + * + * Set frame drop attr. + * + * @param[in] attr Frame drop attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark Every time (lsize+1) is accepted, (fmark invalid figure) is lost. + * @remark Example:lsize=3,fmark=0x5(Frames 2 and 4 are lost every 4). + * + * @attention Before using it, make sure that 'IMP_ISP_Open' is working properly. + */ +int32_t IMP_ISP_SetFrameDrop(IMPISPFrameDropAttr *attr); + +/** + * @fn int32_t IMP_ISP_GetFrameDrop(IMPISPFrameDropAttr *attr) + * + * Get frame drop attr. + * + * @param[out] attr Frame drop attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @remark Every time (lsize+1) is accepted, (fmark invalid figure) is lost. + * @remark Example:lsize=3,fmark=0x5(Frames 2 and 4 are lost every 4). + * + * @attention Before using it, make sure that 'IMP_ISP_Open' is working properly. + */ +int32_t IMP_ISP_GetFrameDrop(IMPISPFrameDropAttr *attr); + +/** + * mjpeg fixed contrast. + */ +typedef struct { + IMPISPTuningOpsMode mode; + uint8_t range_low; + uint8_t range_high; +} IMPISPFixedContrastAttr; + +/** + * @fn int32_t IMP_ISP_SetFixedContraster(IMPISPFixedContrastAttr *attr) + * + * set mjpeg fixed contrast. + * + * @param[out] attr attr. + * + * @retval 0 means success. + * @retval Other values mean failure, its value is an error code. + * + * @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. + */ +int32_t IMP_ISP_SetFixedContraster(IMPISPFixedContrastAttr *attr); + +/* + * set gpio level in vic done + */ +typedef struct { + uint16_t gpio_num[10]; /** gpio num */ + uint16_t gpio_sta[10]; /** gpio state */ + uint16_t free; +} IMPISPGPIO; + +/** +* @fn int32_t IMP_ISP_SET_GPIO_INIT_OR_FREE(IMPISPGPIO *gpio) +* +* application and release GPIO +* @param[in] gpio_num application and release GPIO num,end mark 0xFF +* @param[in] gpio_sta GPIO state,0:low 1:high +* @param[in] free 0:application 1:release +* +* @retval 0 means success +* @retval Other values mean failure, its value is an error code. +* +* @remark gpio_num[10]={20,21,0xff},gpio_sta[10]= {1,0} means init PA20 high PA21 low +* +* @attention Before using it, make sure that 'IMP_ISP_EnableTuning' is working properly. +*/ +int32_t IMP_ISP_SET_GPIO_INIT_OR_FREE(IMPISPGPIO *attr); + +/** +* @fn int32_t IMP_ISP_SET_GPIO_STA(IMPISPGPIO *attr); +* +* set GPIO state in vic done. +* +* @param[in] gpio_num set GPIO num,end mark 0xFF +* @param[in] gpio_sta GPIO state,0:low 1:high +* +* @remark gpio_num[10]={20,21,0xff},gpio_sta[10]= {1,0} means PA20 high PA21 low +* +* @retval 0 means success +* @retval Other values mean failure, its value is an error code. +* +* @attention Before using it, make sure that 'IMP_ISP_SET_GPIO_INIT_OR_FREE' is working properly. +*/ +int32_t IMP_ISP_SET_GPIO_STA(IMPISPGPIO *attr); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +/** + * @} + */ + +#endif /* __IMP_ISP_H__ */ diff --git a/sdk/ingenic/include/imp_ivs.h b/sdk/ingenic/include/imp_ivs.h new file mode 100644 index 0000000..22c846b --- /dev/null +++ b/sdk/ingenic/include/imp_ivs.h @@ -0,0 +1,349 @@ +/* + * IMP IVS header file. + * + * Copyright (C) 2015 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __IMP_IVS_H__ +#define __IMP_IVS_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +#include + +/** + * @file + * IMP IVS module + */ + +#define IMP_IVS_DEFAULT_TIMEOUTMS (-1) +/** + * @defgroup IMP_IVS + * @ingroup imp + * @brief IVS intelligent analysis common API + * + * @section concept 1 Related concepts + * IMP IVS's main goal is to provide users with a number of embedded intelligent analysis algorithm to SDK interface. + * + * @subsection IMPIVSInterface 1.1 IMPIVSInterface + * IMPIVSInterface is the common algorithm interface, the Specific algorithm through the implementation of this interface and pass it to the IVS IMP to achieve the purpose of running the specific algorithm in SDK. + * + * For a channel to be an algorithm that can run the carrier, the Channel has to be into the SDK. To do so, we need to transmit the specific implementation of the general algorithm to the specific interface of this Channel. + * + * IMPIVSInterface member parameter is the init member parameter, it is a must to include int (*free_data)(void *data) member, and assigned to IMP_IVS_ReleaseDa in order to avoid a lock (out). + * + * + * @section ivs_usage 2 Using method + * Motion detection, as an example, reference: sample-move_c.c document. + + * Step.1 Init system, + call sample_system_init() realized in examples. \n + * All applications should be initialized only one time. + + * step.2 Init framesource, + if it is already created, you can just use it( continue with the process) + if it is not created, call sample_framesource_init(IVS_FS_CHN, &fs_chn_attr) + + * step.3 Create IVS group \n + * Multiple algorithm can be used to share a channel group, also can partly use the channel group reference: sample_ivs_move_init() function. + * @code + * int sample_ivs_move_init(int grp_num) + * { + * int ret = 0; + * + * ret = IMP_IVS_CreateGroup(grp_num); + * if (ret < 0) { + * IMP_LOG_ERR(TAG, "IMP_IVS_CreateGroup(%d) failed\n", grp_num); + * return -1; + * } + * return 0; + * } + * @endcode + + * step.4 Bind IVS group to Framesource group + * @code + * IMPCell framesource_cell = {DEV_ID_FS, IVS_FS_CHN, 0}; + * IMPCell ivs_cell = {DEV_ID_IVS, 0, 0}; + * ret = IMP_System_Bind(&framesource_cell, &ivs_cell); + * if (ret < 0) { + * IMP_LOG_ERR(TAG, "Bind FrameSource channel%d and ivs0 failed\n", IVS_FS_CHN); + * return -1; + * } + * @endcode + + * step.5 Enable Framesource and channel algorithm. + Advice : ivs index is equal to ivs channel num in order to make it more convenient to use them. + * @code + * IMP_FrameSource_SetFrameDepth(0, 0); + * ret = sample_framesource_streamon(IVS_FS_CHN); + * if (ret < 0) { + * IMP_LOG_ERR(TAG, "ImpStreamOn failed\n"); + * return -1; + * } + * ret = sample_ivs_move_start(0, 0, &inteface); + * if (ret < 0) { + * IMP_LOG_ERR(TAG, "sample_ivs_move_start(0, 0) failed\n"); + * return -1; + * } + * @endcode + * + * step.6 Get algorithm result\n + * Obtain the results and release the results must be strictly corresponding, can not be interrupted in the middle. + * @code + * for (i = 0; i < NR_FRAMES_TO_IVS; i++) { + * ret = IMP_IVS_PollingResult(0, IMP_IVS_DEFAULT_TIMEOUTMS); + * if (ret < 0) { + * IMP_LOG_ERR(TAG, "IMP_IVS_PollingResult(%d, %d) failed\n", 0, IMP_IVS_DEFAULT_TIMEOUTMS); + * return -1; + * } + * ret = IMP_IVS_GetResult(0, (void **)&result); + * if (ret < 0) { + * IMP_LOG_ERR(TAG, "IMP_IVS_GetResult(%d) failed\n", 0); + * return -1; + * } + * IMP_LOG_INFO(TAG, "frame[%d], result->ret=%d\n", i, result->ret); + * + * ret = IMP_IVS_ReleaseResult(0, (void *)result); + * if (ret < 0) { + * IMP_LOG_ERR(TAG, "IMP_IVS_ReleaseResult(%d) failed\n", 0); + * return -1; + * } + * } + * @endcode + * + * step.7 Release resources. + * @code + * sample_ivs_move_stop(0, inteface); + * sample_framesource_streamoff(1); + * IMP_System_UnBind(&framesource_cell, &ivs_cell); + * sample_ivs_move_exit(0); + * sample_framesource_exit(IVS_FS_CHN); + * sample_system_exit(); + * @endcode + * @{ + */ + +/** + * IVS common interface + */ + +typedef struct IMPIVSInterface IMPIVSInterface; + +struct IMPIVSInterface { + void *param; /**< algorithm input parameter */ + int paramSize; /**< parameter size */ + IMPPixelFormat pixfmt; /**< input pixel format */ + int (*init)(IMPIVSInterface *inf); /**< init algorithm func */ + void (*exit)(IMPIVSInterface *inf); /**< exit algorithm func */ + int (*preProcessSync)(IMPIVSInterface *inf, IMPFrameInfo *frame);/**< algorithm preprocess func, it's parameter frame hasn't been special locked by SDK IVS module, so no need to unlock by using free date, return >=0-> ok,-1->error */ + int (*processAsync)(IMPIVSInterface *inf, IMPFrameInfo *frame);/**< algorithm process func, should be sure unused frames must be unlocked by using free data asap, must be realized for it's a key func to generate algorithm result, return 0->nomal,1->skip check,-1->error */ + int (*getResult)(IMPIVSInterface *inf, void **result); /**< get algorithm result */ + int (*releaseResult)(IMPIVSInterface *inf, void *result); /**< release algorithm result */ + int (*getParam)(IMPIVSInterface *inf, void *param); /**< get algorithm parameter */ + int (*setParam)(IMPIVSInterface *inf, void *param); /**< set algorithm parameter */ + int (*flushFrame)(IMPIVSInterface *inf); /**< Released all frame which got and cached by processAsync */ + void *priv; /**< private info */ +}; + +/** + * Create IVS group + * + * @fn int IMP_IVS_CreateGroup(int GrpNum); + * + * @param[in] GrpNum IVS group number + * + * @retval 0 success + * @retval 1 failed + */ +int IMP_IVS_CreateGroup(int GrpNum); + +/** + * Destroy IVS group + * + * @fn int IMP_IVS_DestroyGroup(int GrpNum); + * + * @param[in] GrpNum IVS group number + * + * @retval 0 success + * @retval 1 failed + */ +int IMP_IVS_DestroyGroup(int GrpNum); +/** + * Create IVS channel to one algorithm entity. + * + * @fn int IMP_IVS_CreateChn(int ChnNum, IMPIVSInterface *handler); + * + * @param[in] ChnNum IVS channel number, advice being equal to algorithm index + * + * @param[in] handler IVS algorithm handler, an entity of one algorithm interface. + * + * @retval 0 success + * @retval 1 failed + */ +int IMP_IVS_CreateChn(int ChnNum, IMPIVSInterface *handler); + +/** + * Destroy IVS channel. + * + * @fn int IMP_IVS_DestroyChn(int ChnNum); + * + * @param[in] ChnNum ivs channel number + * + * @retval 0 success + * @retval 1 failed + */ +int IMP_IVS_DestroyChn(int ChnNum); + +/** + * Register one ivs channel to an ivs group + * + * @fn int IMP_IVS_RegisterChn(int GrpNum, int ChnNum); + * + * @param[in] GrpNum IVS group number + * + * @param[in] ChnNum IVS channel number + * + * @retval 0 success + * @retval 1 failed + * @remarks ChnNum is the registered Channel to the Group(GrpNum) + */ +int IMP_IVS_RegisterChn(int GrpNum, int ChnNum); + +/** + * Unregister one ivs channel from its registered ivs group + * + * @fn int IMP_IVS_UnRegisterChn(int ChnNum); + * + * @param[in] ChnNum IVS channel number + * + * @retval 0 success + * @retval 1 failed + */ +int IMP_IVS_UnRegisterChn(int ChnNum); + +/** + * Channel starts receiving picture(s) + * + * @fn int IMP_IVS_StartRecvPic(int ChnNum); + * + * @param[in] ChnNum ivs channel number + * + * @retval 0 success + * @retval 1 failed + * @remarks ChnNum is the Channel which starts receiving pictures + */ +int IMP_IVS_StartRecvPic(int ChnNum); + +/** + * Channel stops receiving picture(s) + * + * @fn int IMP_IVS_StopRecvPic(int ChnNum); + * + * @param[in] ChnNum ivs channel number + * + * @retval 0 success + * @retval 1 failed + * @remarks ChnNum is the Channel which stops receiving pictures + */ +int IMP_IVS_StopRecvPic(int ChnNum); + +/** + * Whether the blocking judge can or can not get the result of IVS function + * + * @fn int IMP_IVS_PollingResult(int ChnNum, int timeoutMs); + * + * @param[in] ChnNum ivs channel number + * @param[in] timeout max wait time,unit:ms;IMP_IVS_DEFAULT_TIMEOUTMS:internel wait time,0:no wait, >0: customer set wait time + * + * @retval 0 success + * @retval 1 failed + * + * @remark Only when the channel is created then the parameter IMPIVSInterface structure (in the ProcessAsync member) returns 0, that can help to say that the return function is working properly, so the PollingResult return function can be a success. + */ +int IMP_IVS_PollingResult(int ChnNum, int timeoutMs); + +/** + * Get IVS algorithm check result + * + * @fn int IMP_IVS_GetResult(int ChnNum, void **result); + * + * @param[in] ChnNum IVS channel number + * @param[in] result the result to one check process of the algorithm registerd to the ivs channel(ChnNum) + * + * @retval 0 success + * @retval 1 failed + * @remarks According to different functions of IVS binding channel, the output might be different (corresponding results). + */ +int IMP_IVS_GetResult(int ChnNum, void **result); + +/** + * Release IVS algorithm check result + * + * @fn int IMP_IVS_ReleaseResult(int ChnNum, void *result); + * + * @param[in] GrpNum IVS group number + * @param[in] ChnNum IVS channel number + * + * @param[in] result the result to one check process of the algorithm registerd to the ivs channel which num is ChnNum + * + * @retval 0 success + * @retval 1 failed + * @remarks According to different functions of IVS binding channel, it might Release different result resource for its output. + */ +int IMP_IVS_ReleaseResult(int ChnNum, void *result); + +/** + * Release IVS function to calculate the resources result + * + * @fn int IMP_IVS_ReleaseData(void *vaddr); + * + * @param[in] vaddr the released frame's virtual address + * + * @retval 0 success + * @retval 1 failed + * @remarks if libimp is used, it is a must to use the free_data of IVS function. + */ +int IMP_IVS_ReleaseData(void *vaddr); + +/** + * Get the algorithm parameter held by the channel indexed by ChnNum + * + * @fn int IMP_IVS_GetParam(int chnNum, void *param); + * + * @param[in] ChnNum IVS channel number + * @param[in] param algorithm parameter (virtual address pointer). + * + * @retval 0 success + * @retval 1 failed + */ +int IMP_IVS_GetParam(int chnNum, void *param); + +/** + * Set the algorithm parameter held by the channel indexed by ChnNum + * + * @fn int IMP_IVS_SetParam(int chnNum, void *param); + * + * @param[in] ChnNum IVS channel number + * @param[in] param algorithm parameter pointer. + * + * @retval 0 success + * @retval 1 failed + */ +int IMP_IVS_SetParam(int chnNum, void *param); + +/** + * @} + */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* __IMP_IVS_H__ */ diff --git a/sdk/ingenic/include/imp_ivs_base_move.h b/sdk/ingenic/include/imp_ivs_base_move.h new file mode 100644 index 0000000..7a629b4 --- /dev/null +++ b/sdk/ingenic/include/imp_ivs_base_move.h @@ -0,0 +1,85 @@ +/* + * IMP IVS Move func header file. + * + * Copyright (C) 2016 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __IMP_IVS_BASE_MOVE_H__ +#define __IMP_IVS_BASE_MOVE_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +#define IMP_IVS_MOVE_MAX_ROI_CNT 52 + +#include + +/** + * @file + * IMP IVS Motion detection module + */ +/** + * @defgroup MoveDetection + * @ingroup IMP_IVS + * @brief motion detection interface + * @{ +*/ + + +/** + *Base Motion detection algorithm input parameter structure +*/ +typedef struct { + int skipFrameCnt; /*< motion detected interval frame numbers */ + int referenceNum; /*specified the referenceNum frame relative to current frame as reference frame*/ + int sadMode; /* + +/** + * @file + * IMP IVS Motion detection module + */ + +/** + * @defgroup MoveDetection + * @ingroup IMP_IVS + * @brief motion detection interface + * @{ + */ + +/** + * Motion detection algorithm input parameter structure + */ +typedef struct { + int sense[IMP_IVS_MOVE_MAX_ROI_CNT]; /**< Sensitivity of motion detection: the range to normal camera is 0-4, while to Panoramic camera is 0-8 */ + int skipFrameCnt; /*< motion detected interval frame numbers */ + IMPFrameInfo frameInfo; /**< frame information, only need to assign width and height */ + IMPRect roiRect[IMP_IVS_MOVE_MAX_ROI_CNT]; /*< detect region of information */ + int roiRectCnt; /*< detect region information counts */ +} IMP_IVS_MoveParam; + +/* + * Motion detection algorithm output parameter structure + */ +typedef struct { + int retRoi[IMP_IVS_MOVE_MAX_ROI_CNT]; /*< region checkout result, 0:no motion, 1:move, region count equals to roiRectCnt */ +} IMP_IVS_MoveOutput; + +/** + * Create motion detection interface + * + * @fn IMPIVSInterface *IMP_IVS_CreateMoveInterface(IMP_IVS_MoveParam *param); + * + * @param[in] param motion detection algorithm input parameter structure + * + * @retval not NULL success, returns the motion detection interface handler pointer + * @retval NULL failed + * + * @attention null + */ +IMPIVSInterface *IMP_IVS_CreateMoveInterface(IMP_IVS_MoveParam *param); + +/** + * Destroy move detection interface + * + * @fn void IMP_IVS_DestroyMoveInterface(IMPIVSInterface *moveInterface); + * + * @param[in] moveInterface motion detection interface handler pointer + * + * @retval no return + */ +void IMP_IVS_DestroyMoveInterface(IMPIVSInterface *moveInterface); + +/** + * @} + */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ +#endif /* __IMP_IVS_MOVE_H__ */ diff --git a/sdk/ingenic/include/imp_log.h b/sdk/ingenic/include/imp_log.h new file mode 100644 index 0000000..c3320e3 --- /dev/null +++ b/sdk/ingenic/include/imp_log.h @@ -0,0 +1,161 @@ +/* + * IMP log func header file. + * + * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __IMP_LOG_H__ +#define __IMP_LOG_H__ + +/** + * @file + * Log interface header file + */ + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * define log level + */ +enum { + IMP_LOG_LEVEL_UNKNOWN, + IMP_LOG_LEVEL_RESERVED, + IMP_LOG_LEVEL_VERBOSE, + IMP_LOG_LEVEL_DEBUG, + IMP_LOG_LEVEL_INFO, + IMP_LOG_LEVEL_WARN, + IMP_LOG_LEVEL_ERROR, + IMP_LOG_LEVEL_FATAL, + IMP_LOG_LEVEL_SILENT +}; + +#define IMP_LOG_LEVEL_DEFAULT IMP_LOG_LEVEL_DEBUG + +/** + * define log out + */ +#define IMP_LOG_OUT_STDOUT 0 +#define IMP_LOG_OUT_LOCAL_FILE 1 +#define IMP_LOG_OUT_SERVER 2 +//#define IMP_LOG_OUT_DEFAULT IMP_LOG_OUT_SERVER +#define IMP_LOG_OUT_DEFAULT IMP_LOG_OUT_STDOUT + +/** + * define log option + */ +#define IMP_LOG_OP_PID_SHIFT 0 +#define IMP_LOG_OP_USTIME_SHIFT 1 +#define IMP_LOG_OP_MODULE_SHIFT 2 +#define IMP_LOG_OP_FILE_SHIFT 3 +#define IMP_LOG_OP_FUNC_SHIFT 4 +#define IMP_LOG_OP_LINE_SHIFT 5 + + +#define IMP_LOG_OP_PID (1<MEMBER) +#endif + +/** + * container_of - cast a member of a structure out to the containing structure + * Copy from kernel.h + * @ptr: the pointer to the member. + * @type: the type of the container struct this is embedded in. + * @member: the name of the member within the struct. + * + */ +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +char *IMPPixfmtToString(IMPPixelFormat pixfmt); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* __IMP_UTILS_H__ */ diff --git a/sdk/ingenic/include/su_adc.h b/sdk/ingenic/include/su_adc.h new file mode 100644 index 0000000..d77e086 --- /dev/null +++ b/sdk/ingenic/include/su_adc.h @@ -0,0 +1,119 @@ +/* + * SU ADC header file. + * + * Copyright (C) 2015 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __SU_ADC_H__ +#define __SU_ADC_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * ADC module include header + */ + +/** + * @defgroup Sysutils_ADC + * @ingroup sysutils + * @brief Analog to digital conversion module + * + * Please refer to the use of Samples + * @{ + */ + +/** + * @fn int SU_ADC_Init(void); + * + * ADC module init + * + * @retval 0 Success + * @retval Non-0 Failure,return error code + * + * @remark Before using the ADC, be sure to call this function. + * + * @attention None + */ +int SU_ADC_Init(void); + +/** + * @fn int SU_ADC_Exit(void); + * + * ADC module deinit + * + * @retval 0 Success + * @retval Non-0 Failure,return error code + * + * @remark After not using ADC,be sure to call this function. + * + * @attention None + */ +int SU_ADC_Exit(void); + +/** + * @fn int SU_ADC_EnableChn(uint32_t chn_num); + * + * Enable an ADC channel + * + * @param[in] chn_num The channel number you want to use. + * + * @retval 0 Success + * @retval Non-0 Failure,retrun error code + * + * @remark None + * + * @attention None + */ +int SU_ADC_EnableChn(uint32_t chn_num); + +/** + * @fn int SU_ADC_DisableChn(uint32_t chn_num); + * + * Disable an ADC channel + * + * @param[in] chn_num The channel num you want do stop. + * + * @retval 0 Success + * @retval Non-0 Failure,return error code. + * + * @remark None + * + * @attention None + */ +int SU_ADC_DisableChn(uint32_t chn_num); + +/** + * @fn int SU_ADC_GetChnValue(uint32_t chn_num, int *value); + * + * Get the ADC value of the channel chn_num + * + * @param[in] chn_num The channel number + * + * @param[out] value ADC value obtained + * + * @retval 0 Success + * @retval Non-0 Failure,return error code + * + * @remark None + * + * @attention None + */ +int SU_ADC_GetChnValue(uint32_t chn_num, int *value); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +/** + * @} + */ + +#endif /* __SU_ADC_H__ */ diff --git a/sdk/ingenic/include/su_base.h b/sdk/ingenic/include/su_base.h new file mode 100644 index 0000000..448bab0 --- /dev/null +++ b/sdk/ingenic/include/su_base.h @@ -0,0 +1,341 @@ +/* + * System utils header file. + * + * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __SU_BASE_H__ +#define __SU_BASE_H__ + +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * Sysutils Basic Functions header files + */ + +/** + * @defgroup sysutils System Utils + */ + +/** + * @defgroup Sysutils_Base + * @ingroup sysutils + * @brief System Basic Functions. + * @{ + */ + +/** + * Magic device ID + */ +#define DEVICE_ID_MAGIC "53ef" + +/** + * Length of magic device ID + */ +#define DEVICE_ID_MAGIC_LEN 4 + +/** + * Length of device ID + */ +#define DEVICE_ID_LEN 32 + +/** + * Maxnum length of Device model,Device ID and Firmware version + */ +#define MAX_INFO_LEN 64 + +/** + * Device Model + */ +typedef struct { + char chr[MAX_INFO_LEN]; /**< Device Model strings */ +} SUModelNum; + +/** + * Device software version + */ +typedef struct { + char chr[MAX_INFO_LEN]; /**< Device software version strings*/ +} SUVersion; + +/** + * Device ID. Device ID is a unique value, different values between the CPU chip differences + */ +typedef union { + char chr[MAX_INFO_LEN]; /**< Device ID in string */ + uint8_t hex[MAX_INFO_LEN]; /**< Device ID in binary */ +} SUDevID; + +/** + * System time structure + */ +typedef struct { + int sec; /**< Second,Range:0~59 */ + int min; /**< Minute,Range:0~59 */ + int hour; /**< Hour,Range:0~23 */ + int mday; /**< Day,Range:1~31 */ + int mon; /**< Month,Range:1~12 */ + int year; /**< Year,Range:>1900 */ +} SUTime; + +/** + * @fn int SU_Base_GetModelNumber(SUModelNum *modelNum) + * + * Get device model. + * + * @param[out] modelNum Device model structure pointer. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + */ +int SU_Base_GetModelNumber(SUModelNum *modelNum); + +/** + * @fn int SU_Base_GetVersion(SUVersion *version) + * + * Get device version. + * + * @param[out] version Device version structure pointer. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + */ +int SU_Base_GetVersion(SUVersion *version); + +/** + * @fn int SU_Base_GetDevID(SUDevID *devID) + * + * Get device ID. + * + * @param[out] devID Device ID structure pointer. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks The device ID of each CPU is unique. + * + * @attention None. + */ +int SU_Base_GetDevID(SUDevID *devID); + +/** + * @fn int SU_Base_GetTime(SUTime *time) + * + * Get system time. + * + * @param[in] time System time structure pointer. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + */ +int SU_Base_GetTime(SUTime *time); + +/** + * @fn int SU_Base_SetTime(SUTime *time) + * + * Set system time. + * + * @param[out] time System time structure pointer. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention System time parameters should be in a reasonable range, otherwise the function will call failure. + */ +int SU_Base_SetTime(SUTime *time); + +/** + * @fn int SU_Base_SUTime2Raw(SUTime *suTime, uint32_t *rawTime) + * + * Converts the time of the SUTime type to Raw time in seconds.. + * + * @param[in] suTime System time structure pointer. + * @param[out] rawTime Raw time(Count from the date 1970-01-01 00:00:00). + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks This function can be used to set the relative number of seconds alarm. + * + * @attention None. + */ +int SU_Base_SUTime2Raw(SUTime *suTime, uint32_t *rawTime); + +/** + * @fn int SU_Base_Raw2SUTime(uint32_t *rawTime, SUTime *suTime) + * + * Converts the time of the Raw time in seconds to SUTime type. + * + * @param[in] rawTime Raw time(Count from time 1970-01-01 00:00:00). + * @param[out] suTime System time structure pointer. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks This function can be used to set the relative number of seconds alarm. + * + * @attention None. + */ +int SU_Base_Raw2SUTime(uint32_t *rawTime, SUTime *suTime); + +/** + * @fn int SU_Base_SetAlarm(SUTime *time) + * + * Set Alarm time. + * + * @param[in] time System time structure pointer. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks Temporarily support alarm time setting within 24 hours. + * + * @attention System time structure parameters should be in a reasonable time Range, otherwise the function call Failure. + */ +int SU_Base_SetAlarm(SUTime *time); + +/** + * @fn int SU_Base_GetAlarm(SUTime *time) + * + * Get the current Alarm time. + * + * @param[out] time . + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + */ +int SU_Base_GetAlarm(SUTime *time); + +/** + * @fn int SU_Base_EnableAlarm() + * + * Enable Alarm. + * + * @param None. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks Before calling this function, please call SU_Base_GetAlarm (SUTime * time) to set the alarm time. + * + * @attention If alarm time before the current system time ,this function will return failure. + */ +int SU_Base_EnableAlarm(void); + +/** + * @fn int SU_Base_DisableAlarm() + * + * Disable Alarm. + * + * @param None. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + */ +int SU_Base_DisableAlarm(void); + +/** + * @fn int SU_Base_PollingAlarm(uint32_t timeoutMsec) + * + * Wait Alarm. + * + * @param[in] timeout,unit:ms. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks After calling this function, the program will enter the blocked state until the alarm response or timeout Exit. + * + * @attention None. + */ +int SU_Base_PollingAlarm(uint32_t timeoutMsec); + +/** + * @fn int SU_Base_Shutdown(void) + * + * Shutdown device. + * + * @param None. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks After calling this function the device will shut down immediately and turn off the main power. + * + * @attention Before calling this function make sure that all files have been saved. + */ +int SU_Base_Shutdown(void); + +/** + * @fn int SU_Base_Reboot(void) + * + * Reboot device. + * + * @param None. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks The device will immediately reboot after calling this function. + * + * @attention Before calling this function make sure that all files have been saved. + */ +int SU_Base_Reboot(void); + +/** + * @fn int SU_Base_Suspend(void) + * + * Suspend device. + * + * @param None. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks After calling this function the device will immediately enter suspend ,when the function exits normally indicates that the system wake. + * + * @attention None. + */ +int SU_Base_Suspend(); + +/** + * @} + */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* __SU_BASE_H__ */ diff --git a/sdk/ingenic/include/su_cipher.h b/sdk/ingenic/include/su_cipher.h new file mode 100644 index 0000000..d975697 --- /dev/null +++ b/sdk/ingenic/include/su_cipher.h @@ -0,0 +1,279 @@ +/* + * Cipher utils header file. + * + * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __SU_CIPHER_H__ +#define __SU_CIPHER_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * Sysutils The Encryption and Decryption management header file + */ + +/** + * @defgroup Sysutils_Cipher + * @ingroup sysutils + * @brief Encryption and Decryption manage + * @{ + */ + +/** + * Select an encryption algorithm. + * @remarks It supports two encryption algorithms AES and DES. + */ +typedef enum IN_UNF_CIPHER_ALG_E +{ + IN_UNF_CIPHER_ALG_AES = 0x0, + IN_UNF_CIPHER_ALG_DES = 0x1 +} IN_UNF_CIPHER_ALG; + +/** + * Select the encryption mode. + * @remarks It supports two encryption modes AES and DES. + */ +typedef enum IN_UNF_CIPHER_WORK_MODE_E +{ + IN_UNF_CIPHER_WORK_MODE_ECB = 0x0, + IN_UNF_CIPHER_WORK_MODE_CBC = 0x1, + IN_UNF_CIPHER_WORK_MODE_OTHER = 0x2 +} IN_UNF_CIPHER_WORK_MODE; + +/** + * Select the encryption key length used. + * @remarks By hardware limitations, at this stage only supports 128 bit KEY length. + */ +typedef enum IN_UNF_CIPHER_KEY_LENGTH_E +{ + IN_UNF_CIPHER_KEY_AES_128BIT = 0x0, +} IN_UNF_CIPHER_KEY_LENGTH; + +/** + * Select the data length of encryption algorithm at a process. + * @remarks By hardware limitations, at this stage only supports 128 bit KEY length. + */ +typedef enum IN_UNF_CIPHER_BIT_WIDTH_E +{ + IN_UNF_CIPHER_BIT_WIDTH_128BIT = 0x0, +} IN_UNF_CIPHER_BIT_WIDTH; + +/** + * Select the encryption process control structure. + */ +typedef struct IN_UNF_CIPHER_CTRL_S +{ + unsigned int key[4]; /**< KEY used in a encryption*/ + unsigned int IV[4]; /**< IV Vector used in a encryption*/ + unsigned int enDataLen; /**< Total length of data to be processed*/ + IN_UNF_CIPHER_ALG enAlg; /**< Encryption algorithm used in processing data */ + IN_UNF_CIPHER_BIT_WIDTH enBitWidth; /**< Data length of Encryption algorithm in once process */ + IN_UNF_CIPHER_WORK_MODE enWorkMode; /**< Encryption algorithm mode used to process data*/ + IN_UNF_CIPHER_KEY_LENGTH enKeyLen; /**< KEY length of the encryption algorithm */ +} IN_UNF_CIPHER_CTRL; + +/** + * @fn int SU_CIPHER_Init(void) + * + * Open encryption module. + * + * @param None. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + */ +int SU_CIPHER_Init(void); + +/** + * @fn int SU_CIPHER_DES_Init(void) + * + * Open des module. + * + * @param none. + * + * @retval 0 success. + * @retval non-0 failed. + * + * @remarks none. + * + * @attention none. + */ +int SU_CIPHER_DES_Init(void); + +/** + * @fn int SU_CIPHER_Exit(void) + * + * Close encryption module. + * + * @param None. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + */ +int SU_CIPHER_Exit(void); + +/** + * @fn int SU_CIPHER_DES_Exit(void) + * + * Close des module. + * + * @param None. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + */ +int SU_CIPHER_DES_Exit(void); + +/** + * @fn int SU_CIPHER_DES_Test(void) + * + * Invoke the des module interface test. + * + * @param None. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + */ +int SU_CIPHER_DES_Test(void); + +/** + * @fn int SU_CIPHER_CreateHandle(void) + * + * Get a encryption module handle. + * + * @param None. + * + * @retval success: Return the handle. + * @retval Failure: retval < 0. + * + * @remarks None. + * + * @attention This function can be called multiple times, once for each call will return a handle. + * If this function called N times,then N times SU_CIPHER_DestroyHandle() called should be to do + * to destroy all handles we have got. + * + */ +int SU_CIPHER_CreateHandle(void); + +/** + * @fn int SU_CIPHER_DestroyHandle(int fd) + * + * Destroy a encryption module handle. + * + * @param[in] fd Handle need to be destroy + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention This function can be called multiple times, each call will destroy one handle. + * + */ +int SU_CIPHER_DestroyHandle(int fd); + +/** + * @fn int SU_CIPHER_ConfigHandle(int hCipher, IN_UNF_CIPHER_CTRL* Ctrl) + * + * Config encryption module. + * + * @param[in] hCipher The handle need to be configed. + * @param[in] Ctrl Configuration information structure. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention None. + * + */ +int SU_CIPHER_ConfigHandle(int hCipher, IN_UNF_CIPHER_CTRL* Ctrl); + +/** + * @fn int SU_CIPHER_Encrypt(int hCipher, unsigned int * srcAddr, unsigned int * dstAddr, unsigned int dataLen) + * + * Start encrypt data. + * + * @param[in] hCipher Handle to be operated.. + * @param[in] srcAddr Source address of required encrypted data. + * @param[in] dstAddr Target address to store encrypted data. + * @param[in] dataLen Data length needed to be processed.. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention Encrypted data length dataLen maximum not more than 1Mbyte (1024*1024). + * + */ +int SU_CIPHER_Encrypt(int hCipher, unsigned int * srcAddr, unsigned int * dstAddr, unsigned int dataLen); + +/** + * @fn int SU_CIPHER_Decrypt(int hCipher, unsigned int * srcAddr, unsigned int * dstAddr, unsigned int dataLen); + * + * Start decrypt data. + * + * @param[in] hCipher Handle to be operated.. + * @param[in] srcAddr Source address of required decrypted data. + * @param[in] dstAddr Target address to store decrypted data. + * @param[in] dataLen Data length needed to be processed.. + * + * @retval 0 Success. + * @retval Non-0 Failure. + * + * @remarks None. + * + * @attention Decrypted data length dataLen maximum not more than 1Mbyte (1024*1024). + * + */ +int SU_CIPHER_Decrypt(int hCipher, unsigned int * srcAddr, unsigned int * dstAddr, unsigned int dataLen); + +/** + * Error Code. + */ +#define REINIT -10 /**< Repeat initialization */ +#define INIT_FAILED -11 /**< Initializatie failed*/ +#define FAILED_GETHANDLE -12 /**< Get handle failed*/ +#define INVALID_PARA -13 /**< Invalid parameter*/ +#define SET_PARA_FAILED -14 /**< Set parameters fail*/ +#define FAILURE -15 /**< Operate failure*/ +#define SET_DATALEN_ERR -16 /**< Set data length error*/ +#define EXIT_ERR -17 /**< Module exit error*/ +#define UNINIT -18 /**< Module not initialization*/ +#define FAILED_DESHANDLE -19 /**< Destroy handle failed*/ + +/** + * @} + */ +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* __SU_CIPHER_H__ */ diff --git a/sdk/ingenic/include/su_misc.h b/sdk/ingenic/include/su_misc.h new file mode 100644 index 0000000..63e8763 --- /dev/null +++ b/sdk/ingenic/include/su_misc.h @@ -0,0 +1,244 @@ +/* + * Misc utils header file. + * + * Copyright (C) 2014 Ingenic Semiconductor Co.,Ltd + */ + +#ifndef __SU_MISC_H__ +#define __SU_MISC_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif /* __cplusplus */ + +/** + * @file + * Sysutils header file of other functions + */ + +/** + * @defgroup Sysutils_Misc + * @ingroup sysutils + * @brief other functions. + * @{ + */ + +/** + * 按键事件. + */ +typedef enum { + KEY_RELEASED, /**< key release */ + KEY_PRESSED, /**< key press */ +} SUKeyEvent; + +/** + * LED行为命令. + */ +typedef enum { + LED_OFF, /**< Turn on LED */ + LED_ON, /**< Turn off LED */ +} SULedCmd; + +/** + * @fn int SU_Key_OpenEvent(void) + * + * Obtain the key event handle. + * + * @param none + * + * @retval >0 key event handle. + * @retval <=0 failed. + * + * @remarks After successfully obtaining a key event handle, it begins to "log" the key event until the key event is closed + * @remarks If more than one handle is opened, a copy of each keystroke event is recorded. + * @remarks For example, if two threads each open a key press event, each holding a handle, both threads will read the same sequence of events. + * But if two threads share the same handle, each keystroke event can be read only once. + * + * @attention none + */ +int SU_Key_OpenEvent(void); + +/** + * @fn int SU_Key_CloseEvent(int evfd) + * + * Turn off key event. + * + * @param[in] evfd key event handle + * + * @retval 0 success. + * @retval non-0 failed. + * + * @remarks none + * + * @attention none + */ +int SU_Key_CloseEvent(int evfd); + +/** + * @fn int SU_Key_ReadEvent(int evfd, int *keyCode, SUKeyEvent *event) + * + * Read key event. + * + * @param[in] evfd key event handle + * @param[in] keyCode keycode + * @param[out] event ket event pointer. + * + * @retval 0 success. + * @retval non-0 failed. + * + * @remarks The function blocks until a keystroke event returns. + * @remarks Keycodes are defined in linux/input.h, and mappings to GPIOs are defined in kernel board files. + * @remarks such as several commonly used keys: + * @code + #define KEY_HOME 102 //HOME key + #define KEY_POWER 116 //Power key, It can also be used as a wake-up key + #define KEY_WAKEUP 143 //Wake-up key, Keys used to wake up the system other than POWER key + #define KEY_F13 183 //When PIR is used as a key, it is defined as the F13 key + * @endcode + * + * @remarks The definition of key code and GPIO number, whether it is used as a wake-up source, and the effective power level information are defined in the core board-level file, as follows: + * + * @code + struct gpio_keys_button __attribute__((weak)) board_buttons[] = { + #ifdef GPIO_HOME + { + .gpio = GPIO_HOME, //Define GPIO num + .code = KEY_HOME, //Define key code + .desc = "home key", + .active_low = ACTIVE_LOW_HOME, //Define active level + #ifdef WAKEUP_HOME + .wakeup = WAKEUP_HOME, //Define whether can be used as wake-up source, 1 means be able to wake-up suspend + #endif + #ifdef CAN_DISABLE_HOME + .can_disable = CAN_DISABLE_HOME, //Define whether be able to Disabled + #endif + }, + #endif + #ifdef GPIO_POWER + { + .gpio = GPIO_POWER, + .code = KEY_POWER, + .desc = "power key", + .active_low = ACTIVE_LOW_POWER, + #ifdef WAKEUP_POWER + .wakeup = WAKEUP_POWER, + #endif + #ifdef CAN_DISABLE_POWER + .can_disable = CAN_DISABLE_POWER, + #endif + }, + #endif + } + * @endcode + * @remarks For digital PIR, one way to use PIR is to define PIR as a key, and PIR triggers the equivalent of a key press event (@ref KEY_PRESSED), + * PIR recovery is equivalent to a key lift event (@ref KEY_RELEASED). If the PIR wake-up function is required, the button corresponding to the PIR can be defined as the wake-up source. + * @remarks For details on how to use the API, please refer to sample-keyevent.c. + * + * @attention none + */ +int SU_Key_ReadEvent(int evfd, int *keyCode, SUKeyEvent *event); + +/** + * @fn int SU_Key_DisableEvent(int keyCode) + * + * Disable key event. + * + * @param[in] keyCode + * + * @retval 0 success. + * @retval non-0 failed. + * + * @remarks If a key key is configured as a wake-up source, pressing the key (whether the key is open or not) wakes the system when the system suspends. +* After the Disable key event, the system turns off the interruption of the key press event, and the key cannot wake the system + * @remarks This API can be used to disable PIR "keystrokes" to wake up the system. + * + * @attention none + */ +int SU_Key_DisableEvent(int keyCode); + +/** + * @fn int SU_Key_EnableEvent(int keyCode) + * + * Enable key event. + * + * @param[in] keyCode + * + * @retval 0 success. + * @retval non-0 failed. + * + * @remarks The reverse process as a disable keystroke event, please refer to@ref SU_Key_DisableEvent(int keyCode) + * + * @attention none + */ +int SU_Key_EnableEvent(int keyCode); + +/** + * @fn int SU_LED_Command(int ledNum, SULedCmd cmd) + * + * Send LED command. + * + * @param[in] ledNum LED number. + * @param[in] cmd LED behavior command. + * + * @retval 0 success. + * @retval non-0 failed. + * + * @remarksThe LED number varies depending on the development board. The LED number is defined in the kernel board-level file and registered as a Linux standard + * Quasi-Fixed Regulator equipment. In the board-level file, the GPIO number, active level, power recursion relationship, etc. of the LED need to be defined +*Information. Here is an example of defining two LED fixed regulators: + * @code + FIXED_REGULATOR_DEF( //define fixed regulator + led0, + "LED0", 3300000, GPIO_PA(14), + HIGH_ENABLE, UN_AT_BOOT, 0, + "ldo7", "vled0", NULL); + + FIXED_REGULATOR_DEF( + led1, + "LED1", 3300000, GPIO_PA(15), + HIGH_ENABLE, UN_AT_BOOT, 0, + "ldo7", "vled1", NULL); + + static struct platform_device *fixed_regulator_devices[] __initdata = { + &gsensor_regulator_device, + &led0_regulator_device, + &led1_regulator_device, + }; + + static int __init fix_regulator_init(void) //register regulator in subsys_initcall_sync + { + int i; + + for (i = 0; i < ARRAY_SIZE(fixed_regulator_devices); i++) + fixed_regulator_devices[i]->id = i; + + return platform_add_devices(fixed_regulator_devices, + ARRAY_SIZE(fixed_regulator_devices)); + } + subsys_initcall_sync(fix_regulator_init); + * @endcode + * @remarks Examples of the use of this API + * @code + if (SU_LED_Command(0, LED_ON) < 0) //enable LED0 + printf("LED0 turn on error\n"); + if (SU_LED_Command(1, LED_ON) < 0) //enable LED1 + printf("LED0 turn on error\n"); + if (SU_LED_Command(0, LED_OFF) < 0) //disable LED0 + printf("LED1 turn off error\n"); + if (SU_LED_Command(1, LED_OFF) < 0) //disable LED1 + printf("LED1 turn off error\n"); + * @endcode + * @attention none + */ +int SU_LED_Command(int ledNum, SULedCmd cmd); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* __SU_MISC_H__ */