Skip to content

Commit

Permalink
Grayscale/night mode specifics
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jun 6, 2024
1 parent 49c9206 commit a195a44
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 18 deletions.
17 changes: 17 additions & 0 deletions src/hal/hisi/v4_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ int v4_channel_create(char index, char mirror, char flip, char framerate)
return EXIT_SUCCESS;
}

int v4_channel_grayscale(char enable)
{
int ret;

for (char i = 0; i < V4_VENC_CHN_NUM; i++) {
v4_venc_para param;
if (!v4_state[i].enable) continue;
if (ret = v4_venc.fnGetChannelParam(i, &param))
return ret;
param.grayscaleOn = enable;
if (ret = v4_venc.fnSetChannelParam(i, &param))
return ret;
}

return EXIT_SUCCESS;
}

int v4_channel_unbind(char index)
{
int ret;
Expand Down
1 change: 1 addition & 0 deletions src/hal/hisi/v4_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ int v4_audio_init(void);

int v4_channel_bind(char index);
int v4_channel_create(char index, char mirror, char flip, char framerate);
int v4_channel_grayscale(char enable);
int v4_channel_unbind(char index);

void *v4_image_thread(void);
Expand Down
25 changes: 25 additions & 0 deletions src/hal/hisi/v4_venc.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ typedef struct {
v4_venc_packinfo packetInfo[8];
} v4_venc_pack;

typedef struct {
int grayscaleOn;
unsigned int prio;
unsigned int maxStrmCnt;
unsigned int wakeFrmCnt;
int cropOn;
v4_common_rect crop;
int srcFps;
int dstFps;
} v4_venc_para;

typedef struct {
unsigned int leftPics;
unsigned int leftBytes;
Expand Down Expand Up @@ -363,9 +374,11 @@ typedef struct {

int (*fnCreateChannel)(int channel, v4_venc_chn *config);
int (*fnGetChannelConfig)(int channel, v4_venc_chn *config);
int (*fnGetChannelParam)(int channel, v4_venc_para *config);
int (*fnDestroyChannel)(int channel);
int (*fnResetChannel)(int channel);
int (*fnSetChannelConfig)(int channel, v4_venc_chn *config);
int (*fnSetChannelParam)(int channel, v4_venc_para *config);
int (*fnSetColorToGray)(int channel, int *active);

int (*fnFreeDescriptor)(int channel);
Expand Down Expand Up @@ -410,6 +423,12 @@ static int v4_venc_load(v4_venc_impl *venc_lib) {
return EXIT_FAILURE;
}

if (!(venc_lib->fnGetChannelParam = (int(*)(int channel, v4_venc_para *config))
dlsym(venc_lib->handle, "HI_MPI_VENC_GetChnParam"))) {
fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_GetChnParam!\n");
return EXIT_FAILURE;
}

if (!(venc_lib->fnResetChannel = (int(*)(int channel))
dlsym(venc_lib->handle, "HI_MPI_VENC_ResetChn"))) {
fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_ResetChn!\n");
Expand All @@ -422,6 +441,12 @@ static int v4_venc_load(v4_venc_impl *venc_lib) {
return EXIT_FAILURE;
}

if (!(venc_lib->fnSetChannelParam = (int(*)(int channel, v4_venc_para *config))
dlsym(venc_lib->handle, "HI_MPI_VENC_SetChnParam"))) {
fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_SetChnParam!\n");
return EXIT_FAILURE;
}

if (!(venc_lib->fnFreeDescriptor = (int(*)(int channel))
dlsym(venc_lib->handle, "HI_MPI_VENC_CloseFd"))) {
fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_CloseFd!\n");
Expand Down
4 changes: 1 addition & 3 deletions src/hal/sstar/i6_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ int i6_video_destroy_all(void)
return EXIT_SUCCESS;
}

int i6_video_snapshot_grab(char index, char quality, char grayscale, hal_jpegdata *jpeg)
int i6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg)
{
int ret;

Expand All @@ -596,8 +596,6 @@ int i6_video_snapshot_grab(char index, char quality, char grayscale, hal_jpegdat
goto abort;
}

i6_channel_grayscale(grayscale);

unsigned int count = 1;
if (i6_venc.fnStartReceivingEx(index, &count)) {
fprintf(stderr, "[i6_venc] Requesting one frame "
Expand Down
2 changes: 1 addition & 1 deletion src/hal/sstar/i6_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int i6_region_setbitmap(int handle, hal_bitmap *bitmap);
int i6_video_create(char index, hal_vidconfig *config);
int i6_video_destroy(char index);
int i6_video_destroy_all(void);
int i6_video_snapshot_grab(char index, char quality, char grayscale, hal_jpegdata *jpeg);
int i6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg);
void *i6_video_thread(void);

void i6_system_deinit(void);
Expand Down
4 changes: 1 addition & 3 deletions src/hal/sstar/i6c_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ int i6c_video_destroy_all(void)
return EXIT_SUCCESS;
}

int i6c_video_snapshot_grab(char index, char quality, char grayscale, hal_jpegdata *jpeg)
int i6c_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg)
{
int ret;
char device =
Expand Down Expand Up @@ -705,8 +705,6 @@ int i6c_video_snapshot_grab(char index, char quality, char grayscale, hal_jpegda
goto abort;
}

i6c_channel_grayscale(grayscale);

unsigned int count = 1;
if (i6c_venc.fnStartReceivingEx(device, index, &count)) {
fprintf(stderr, "[i6c_venc] Requesting one frame "
Expand Down
2 changes: 1 addition & 1 deletion src/hal/sstar/i6c_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int i6c_region_setbitmap(int handle, hal_bitmap *bitmap);
int i6c_video_create(char index, hal_vidconfig *config);
int i6c_video_destroy(char index, char jpeg);
int i6c_video_destroy_all(void);
int i6c_video_snapshot_grab(char index, char quality, char grayscale, hal_jpegdata *jpeg);
int i6c_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg);
void *i6c_video_thread(void);

void i6c_system_deinit(void);
Expand Down
4 changes: 1 addition & 3 deletions src/hal/sstar/i6f_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ int i6f_video_destroy_all(void)
return EXIT_SUCCESS;
}

int i6f_video_snapshot_grab(char index, char quality, char grayscale, hal_jpegdata *jpeg)
int i6f_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg)
{
int ret;
char device =
Expand Down Expand Up @@ -664,8 +664,6 @@ int i6f_video_snapshot_grab(char index, char quality, char grayscale, hal_jpegda
goto abort;
}

i6f_channel_grayscale(grayscale);

unsigned int count = 1;
if (i6f_venc.fnStartReceivingEx(device, index, &count)) {
fprintf(stderr, "[i6f_venc] Requesting one frame "
Expand Down
2 changes: 1 addition & 1 deletion src/hal/sstar/i6f_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int i6f_region_setbitmap(int handle, hal_bitmap *bitmap);
int i6f_video_create(char index, hal_vidconfig *config);
int i6f_video_destroy(char index, char jpeg);
int i6f_video_destroy_all(void);
int i6f_video_snapshot_grab(char index, char quality, char grayscale, hal_jpegdata *jpeg);
int i6f_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg);
void *i6f_video_thread(void);

void i6f_system_deinit(void);
Expand Down
9 changes: 3 additions & 6 deletions src/jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,9 @@ int jpeg_get(short width, short height, char quality, char grayscale,
int ret;

switch (plat) {
case HAL_PLATFORM_I6: ret = i6_video_snapshot_grab(jpeg_index, quality,
grayscale, jpeg); break;
case HAL_PLATFORM_I6C: ret = i6c_video_snapshot_grab(jpeg_index, quality,
grayscale, jpeg); break;
case HAL_PLATFORM_I6F: ret = i6f_video_snapshot_grab(jpeg_index, quality,
grayscale, jpeg); break;
case HAL_PLATFORM_I6: ret = i6_video_snapshot_grab(jpeg_index, quality, jpeg); break;
case HAL_PLATFORM_I6C: ret = i6c_video_snapshot_grab(jpeg_index, quality, jpeg); break;
case HAL_PLATFORM_I6F: ret = i6f_video_snapshot_grab(jpeg_index, quality, jpeg); break;
case HAL_PLATFORM_V3: ret = v3_video_snapshot_grab(jpeg_index, jpeg); break;
case HAL_PLATFORM_V4: ret = v4_video_snapshot_grab(jpeg_index, jpeg); break;
case HAL_PLATFORM_T31: ret = t31_video_snapshot_grab(app_config.mjpeg_enable ?
Expand Down
1 change: 1 addition & 0 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void set_grayscale(bool active) {
case HAL_PLATFORM_I6C: i6c_channel_grayscale(active); break;
case HAL_PLATFORM_I6F: i6f_channel_grayscale(active); break;
case HAL_PLATFORM_V3: v3_channel_grayscale(active); break;
case HAL_PLATFORM_V4: v4_channel_grayscale(active); break;
case HAL_PLATFORM_T31: t31_channel_grayscale(active); break;
}
pthread_mutex_unlock(&mutex);
Expand Down

0 comments on commit a195a44

Please sign in to comment.