From af63ed56e6713760316942535720c4f262e5957e Mon Sep 17 00:00:00 2001 From: zhaoshuaiadada Date: Wed, 8 Jun 2022 19:34:35 +0800 Subject: [PATCH 1/3] ds2 add pitch --- package/ai/code/video_object_detect_320.conf | 6 +- .../ai/code/video_object_detect_320x320.conf | 6 +- .../ai/code/video_object_detect_432x368.conf | 6 +- package/ai/code/video_object_detect_512.conf | 6 +- package/ai/code/video_object_detect_640.conf | 6 +- .../ai/code/video_object_detect_640x480.conf | 6 +- package/encode_app/src/video_sample.conf | 6 +- .../encode_app/src/video_sample_720p60.conf | 6 +- .../src/video_sample_vga480p75.conf | 6 +- .../ffmpeg_canaan/0024-buildroot-ffmpeg.patch | 24 ++++++++ .../src/config/video_drm_1080x1920.conf | 6 +- .../src/config/video_drm_1080x1920_r2k.conf | 6 +- .../src/config/video_drm_1920x1080.conf | 6 +- package/mediactl_lib/src/isp/isp_cfg.c | 6 +- package/mediactl_lib/src/isp/isp_com.h | 1 + package/mediactl_lib/src/isp/json_parse.c | 22 +++++++ package/mediactl_lib/src/media_ctl.c | 1 + .../patches/linux/0009-ds2-add-pitch.patch | 58 +++++++++++++++++++ 18 files changed, 158 insertions(+), 26 deletions(-) create mode 100644 package/ffmpeg_canaan/0024-buildroot-ffmpeg.patch create mode 100644 package/patches/linux/0009-ds2-add-pitch.patch diff --git a/package/ai/code/video_object_detect_320.conf b/package/ai/code/video_object_detect_320.conf index 0c917df..0044e87 100644 --- a/package/ai/code/video_object_detect_320.conf +++ b/package/ai/code/video_object_detect_320.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":320, "video5_height_r":240, - "video5_out_format":0 + "video5_out_format":0, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/ai/code/video_object_detect_320x320.conf b/package/ai/code/video_object_detect_320x320.conf index 37b34f5..4cce780 100644 --- a/package/ai/code/video_object_detect_320x320.conf +++ b/package/ai/code/video_object_detect_320x320.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":320, "video5_height_r":320, - "video5_out_format":0 + "video5_out_format":0, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/ai/code/video_object_detect_432x368.conf b/package/ai/code/video_object_detect_432x368.conf index faff30c..cbc0bc0 100644 --- a/package/ai/code/video_object_detect_432x368.conf +++ b/package/ai/code/video_object_detect_432x368.conf @@ -33,7 +33,8 @@ "video5_width":432, "video5_height":368, "video5_height_r":368, - "video5_out_format":0 + "video5_out_format":0, + "video5_pitch":432 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/ai/code/video_object_detect_512.conf b/package/ai/code/video_object_detect_512.conf index db998cc..3b4ee0a 100644 --- a/package/ai/code/video_object_detect_512.conf +++ b/package/ai/code/video_object_detect_512.conf @@ -33,7 +33,8 @@ "video5_width":512, "video5_height":512, "video5_height_r":400, - "video5_out_format":0 + "video5_out_format":0, + "video5_pitch":512 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/ai/code/video_object_detect_640.conf b/package/ai/code/video_object_detect_640.conf index 061448d..c3e3a07 100644 --- a/package/ai/code/video_object_detect_640.conf +++ b/package/ai/code/video_object_detect_640.conf @@ -33,7 +33,8 @@ "video5_width":640, "video5_height":640, "video5_height_r":480, - "video5_out_format":0 + "video5_out_format":0, + "video5_pitch":640 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/ai/code/video_object_detect_640x480.conf b/package/ai/code/video_object_detect_640x480.conf index 61139c0..d61a2e8 100644 --- a/package/ai/code/video_object_detect_640x480.conf +++ b/package/ai/code/video_object_detect_640x480.conf @@ -33,7 +33,8 @@ "video5_width":640, "video5_height":480, "video5_height_r":480, - "video5_out_format":0 + "video5_out_format":0, + "video5_pitch":640 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/encode_app/src/video_sample.conf b/package/encode_app/src/video_sample.conf index be5d69c..c51b4e7 100644 --- a/package/encode_app/src/video_sample.conf +++ b/package/encode_app/src/video_sample.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":320, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/encode_app/src/video_sample_720p60.conf b/package/encode_app/src/video_sample_720p60.conf index 78dca5c..719710f 100644 --- a/package/encode_app/src/video_sample_720p60.conf +++ b/package/encode_app/src/video_sample_720p60.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":320, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/encode_app/src/video_sample_vga480p75.conf b/package/encode_app/src/video_sample_vga480p75.conf index 4c2392b..3efca95 100644 --- a/package/encode_app/src/video_sample_vga480p75.conf +++ b/package/encode_app/src/video_sample_vga480p75.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":320, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/ffmpeg_canaan/0024-buildroot-ffmpeg.patch b/package/ffmpeg_canaan/0024-buildroot-ffmpeg.patch new file mode 100644 index 0000000..8c06262 --- /dev/null +++ b/package/ffmpeg_canaan/0024-buildroot-ffmpeg.patch @@ -0,0 +1,24 @@ +Index: b/libavdevice/video_sample.conf +=================================================================== +--- a/libavdevice/video_sample.conf ++++ b/libavdevice/video_sample.conf +@@ -33,7 +33,8 @@ + "video5_width":320, + "video5_height":320, + "video5_height_r":240, +- "video5_out_format":1 ++ "video5_out_format":1, ++ "video5_pitch":320 + } + }, + "sensor1":{ +@@ -70,7 +71,8 @@ + "video9_width":320, + "video9_height":240, + "video9_height_r":240, +- "video9_out_format":1 ++ "video9_out_format":1, ++ "video9_pitch":320 + } + }, + "mipi_csi2":{ diff --git a/package/mediactl_lib/src/config/video_drm_1080x1920.conf b/package/mediactl_lib/src/config/video_drm_1080x1920.conf index d9115dc..f3b86d4 100644 --- a/package/mediactl_lib/src/config/video_drm_1080x1920.conf +++ b/package/mediactl_lib/src/config/video_drm_1080x1920.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":320, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/mediactl_lib/src/config/video_drm_1080x1920_r2k.conf b/package/mediactl_lib/src/config/video_drm_1080x1920_r2k.conf index ae148e7..7066146 100644 --- a/package/mediactl_lib/src/config/video_drm_1080x1920_r2k.conf +++ b/package/mediactl_lib/src/config/video_drm_1080x1920_r2k.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":320, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/mediactl_lib/src/config/video_drm_1920x1080.conf b/package/mediactl_lib/src/config/video_drm_1920x1080.conf index 8fff62b..e399540 100644 --- a/package/mediactl_lib/src/config/video_drm_1920x1080.conf +++ b/package/mediactl_lib/src/config/video_drm_1920x1080.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":320, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/mediactl_lib/src/isp/isp_cfg.c b/package/mediactl_lib/src/isp/isp_cfg.c index fd25abc..9a9d02b 100644 --- a/package/mediactl_lib/src/isp/isp_cfg.c +++ b/package/mediactl_lib/src/isp/isp_cfg.c @@ -266,7 +266,8 @@ int isp_f2k_cfg(struct media_entity *entity,struct isp_cfg_info *isp_cfg,uint32_ isp_wrap_info->ds1Info.ds1_uv_buf1_base = phyAddr+line_stride*height; // - width = isp_wrap_info->ds2Info.ds2_size.width; + //width = isp_wrap_info->ds2Info.ds2_size.width; + width = isp_wrap_info->ds2Info.ds2_size.pitch; // add pitch line_stride = calc_stride(width); if( OUT_ARGB == isp_wrap_info->ds2Info.ds2_out_img_out_format) { @@ -421,7 +422,8 @@ int isp_r2k_cfg(struct media_entity *entity,struct isp_cfg_info *isp_cfg,uint32_ isp_wrap_info->ds1Info.ds1_uv_buf1_base = phyAddr+line_stride*height; // - width = isp_wrap_info->ds2Info.ds2_size.width; + //width = isp_wrap_info->ds2Info.ds2_size.width; + width = isp_wrap_info->ds2Info.ds2_size.pitch; line_stride = calc_stride(width); if( OUT_ARGB == isp_wrap_info->ds2Info.ds2_out_img_out_format) { diff --git a/package/mediactl_lib/src/isp/isp_com.h b/package/mediactl_lib/src/isp/isp_com.h index 930123b..62efea5 100644 --- a/package/mediactl_lib/src/isp/isp_com.h +++ b/package/mediactl_lib/src/isp/isp_com.h @@ -35,6 +35,7 @@ struct image_size_s { unsigned int width; unsigned int height; + unsigned int pitch; }; typedef enum _VI_PIPE_ID diff --git a/package/mediactl_lib/src/isp/json_parse.c b/package/mediactl_lib/src/isp/json_parse.c index 1cc1a13..756905a 100644 --- a/package/mediactl_lib/src/isp/json_parse.c +++ b/package/mediactl_lib/src/isp/json_parse.c @@ -322,6 +322,16 @@ void doit_video_cfg(char *text,struct vi_cfg_info *vi_cfg,struct sensor_info *se //printf("cJSON_GetObjectItem: type=%d, string is %s, valueint is %d\n",item->type,item->string,item->valueint); } + item=cJSON_GetObjectItem(object,"video5_pitch"); + printf("%s:video5_pitch %p\n",__func__,item); + if(item != NULL) + { + wds2Info->ds2_size.pitch = item->valueint; + ds2Info->ds_out_size.pitch = wds2Info->ds2_size.pitch; + printf("cJSON_GetObjectItem: type=%d, string is %s, valueint is %d pitch is %d \n",item->type,item->string,item->valueint,ds2Info->ds_out_size.pitch); + } + + dev_info[0].video_used = 0; if((dev_info[0].enable[0] == 1)||(dev_info[0].enable[1] == 1)||(dev_info[0].enable[2] == 1)||(dev_info[0].enable[3] == 1)) { @@ -580,6 +590,18 @@ void doit_video_cfg(char *text,struct vi_cfg_info *vi_cfg,struct sensor_info *se dev_info[1].video_out_format[3] = item->valueint; //printf("cJSON_GetObjectItem: type=%d, string is %s, valueint is %d\n",item->type,item->string,item->valueint); } + + item=cJSON_GetObjectItem(object,"video9_pitch"); + //printf("%s:active_height %p\n",__func__,item); + if(item != NULL) + { + //dev_info[1].video_height[3] = item->valueint; + wds2Info->ds2_size.pitch = item->valueint; + ds2Info->ds_out_size.pitch = wds2Info->ds2_size.pitch; + //printf("cJSON_GetObjectItem: type=%d, string is %s, valueint is %d\n",item->type,item->string,item->valueint); + } + + dev_info[1].video_used = 0; if((dev_info[1].enable[0] == 1)||(dev_info[1].enable[1] == 1)||(dev_info[1].enable[2] == 1)||(dev_info[1].enable[3] == 1)) { diff --git a/package/mediactl_lib/src/media_ctl.c b/package/mediactl_lib/src/media_ctl.c index 17756c5..ee75f04 100644 --- a/package/mediactl_lib/src/media_ctl.c +++ b/package/mediactl_lib/src/media_ctl.c @@ -764,6 +764,7 @@ void pipline_cfg(struct isp_pipeline_s *isp_pipeline,struct sensor_info *sensor) isp_pipeline->video_entity_info[3].used = isp_wrap_cfg->ds2Info.ds2_out_en; isp_pipeline->video_entity_info[3].video_size.width = isp_wrap_cfg->ds2Info.ds2_size.width; isp_pipeline->video_entity_info[3].video_size.height = isp_wrap_cfg->ds2Info.ds2_video_height;//isp_wrap_cfg->ds2Info.ds2_size.height; + isp_pipeline->video_entity_info[3].video_size.pitch = isp_wrap_cfg->ds2Info.ds2_size.pitch;//isp_wrap_cfg->ds2Info.ds2_size.height; isp_pipeline->video_entity_info[3].video_out_format = isp_wrap_cfg->ds2Info.ds2_out_img_out_format; // isp_pipeline->pipeline_en = 0; diff --git a/package/patches/linux/0009-ds2-add-pitch.patch b/package/patches/linux/0009-ds2-add-pitch.patch new file mode 100644 index 0000000..f174f3a --- /dev/null +++ b/package/patches/linux/0009-ds2-add-pitch.patch @@ -0,0 +1,58 @@ +From 26d6a4251d6f56b83103d231db531a2a11fa157a Mon Sep 17 00:00:00 2001 +From: zhaoshuaiadada +Date: Wed, 8 Jun 2022 19:20:41 +0800 +Subject: [PATCH] ds2 add pitch + +--- + drivers/media/platform/canaan-isp/isp_2k/isp_f2k.c | 1 + + drivers/media/platform/canaan-isp/k510isp_com.h | 3 ++- + drivers/media/platform/canaan-isp/vi/vi_com.h | 2 ++ + 3 files changed, 5 insertions(+), 1 deletion(-) + +diff --git a/drivers/media/platform/canaan-isp/isp_2k/isp_f2k.c b/drivers/media/platform/canaan-isp/isp_2k/isp_f2k.c +index 906443b2..6085ed61 100755 +--- a/drivers/media/platform/canaan-isp/isp_2k/isp_f2k.c ++++ b/drivers/media/platform/canaan-isp/isp_2k/isp_f2k.c +@@ -3040,6 +3040,7 @@ static long f2k_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) + mutex_lock(&f2k->ioctl_lock); + //ret = isp_f2k_ds_config(f2k, arg); + memcpy((void*)isp_ds_cfg,arg,sizeof(struct isp_ds_cfg_info)); ++ + mutex_unlock(&f2k->ioctl_lock); + break; + case VIDIOC_K510ISP_F2K_REMAP_MAIN_CFG: +diff --git a/drivers/media/platform/canaan-isp/k510isp_com.h b/drivers/media/platform/canaan-isp/k510isp_com.h +index 6ecec4c6..8927b06f 100755 +--- a/drivers/media/platform/canaan-isp/k510isp_com.h ++++ b/drivers/media/platform/canaan-isp/k510isp_com.h +@@ -33,7 +33,8 @@ + + typedef struct _IMAGE_SIZE{ + unsigned int Width; +- unsigned int Height; ++ unsigned int Height; ++ unsigned int pitch; + }IMAGE_SIZE; + + typedef enum _VI_PIPE_ID +diff --git a/drivers/media/platform/canaan-isp/vi/vi_com.h b/drivers/media/platform/canaan-isp/vi/vi_com.h +index 01ad1caf..5faf8895 100755 +--- a/drivers/media/platform/canaan-isp/vi/vi_com.h ++++ b/drivers/media/platform/canaan-isp/vi/vi_com.h +@@ -127,11 +127,13 @@ typedef enum _MIPI_CSI_DMOE_E + typedef struct _IMAGE_SIZE_INFO{ + unsigned int Width; + unsigned int Height; ++ unsigned int pitch; + }IMAGE_SIZE_INFO; + // + typedef struct _IMAGE_SIZE_ST{ + unsigned int Width_st; + unsigned int Height_st; ++ unsigned int pitch; + }IMAGE_SIZE_ST; + + typedef enum _VI_PIPE_WDR_MODE_E +-- +2.36.1 + From c82650d6e143791b1355b29b720c72f4f5a3f4da Mon Sep 17 00:00:00 2001 From: zhaoshuaiadada Date: Thu, 9 Jun 2022 10:59:18 +0800 Subject: [PATCH 2/3] ds2 add pitch --- package/ai/code/object_detect_opencv/data/video.conf | 6 ++++-- package/ai/code/object_detect_v4l2/data/video.conf | 6 ++++-- package/ai/code/retinaface_mb_320_opencv/data/video.conf | 6 ++++-- package/ai/code/retinaface_mb_320_v4l2/data/video.conf | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/package/ai/code/object_detect_opencv/data/video.conf b/package/ai/code/object_detect_opencv/data/video.conf index 35f1e5b..da09bb1 100644 --- a/package/ai/code/object_detect_opencv/data/video.conf +++ b/package/ai/code/object_detect_opencv/data/video.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":240, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/ai/code/object_detect_v4l2/data/video.conf b/package/ai/code/object_detect_v4l2/data/video.conf index 35f1e5b..da09bb1 100644 --- a/package/ai/code/object_detect_v4l2/data/video.conf +++ b/package/ai/code/object_detect_v4l2/data/video.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":240, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/ai/code/retinaface_mb_320_opencv/data/video.conf b/package/ai/code/retinaface_mb_320_opencv/data/video.conf index 35f1e5b..da09bb1 100644 --- a/package/ai/code/retinaface_mb_320_opencv/data/video.conf +++ b/package/ai/code/retinaface_mb_320_opencv/data/video.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":240, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ diff --git a/package/ai/code/retinaface_mb_320_v4l2/data/video.conf b/package/ai/code/retinaface_mb_320_v4l2/data/video.conf index 35f1e5b..da09bb1 100644 --- a/package/ai/code/retinaface_mb_320_v4l2/data/video.conf +++ b/package/ai/code/retinaface_mb_320_v4l2/data/video.conf @@ -33,7 +33,8 @@ "video5_width":320, "video5_height":240, "video5_height_r":240, - "video5_out_format":1 + "video5_out_format":1, + "video5_pitch":320 } }, "sensor1":{ @@ -70,7 +71,8 @@ "video9_width":320, "video9_height":240, "video9_height_r":240, - "video9_out_format":1 + "video9_out_format":1, + "video9_pitch":320 } }, "mipi_csi2":{ From 1e73c195d525be303adae461c254d12cfac40058 Mon Sep 17 00:00:00 2001 From: zhaoshuaiadada Date: Thu, 9 Jun 2022 14:22:38 +0800 Subject: [PATCH 3/3] fix mx2-781 --- board/canaan/k510/k510_rootfs_skeleton/etc/init.d/rc.sysinit | 2 ++ 1 file changed, 2 insertions(+) diff --git a/board/canaan/k510/k510_rootfs_skeleton/etc/init.d/rc.sysinit b/board/canaan/k510/k510_rootfs_skeleton/etc/init.d/rc.sysinit index 3de42ee..c643ea8 100755 --- a/board/canaan/k510/k510_rootfs_skeleton/etc/init.d/rc.sysinit +++ b/board/canaan/k510/k510_rootfs_skeleton/etc/init.d/rc.sysinit @@ -101,6 +101,8 @@ cd / ntpdate ntp.aliyun.com >/dev/null 2>&1 & /app/dsp_log/dsp_log & +i2ctransfer -f -y 0 w3@0x10 0x01 0x00 0x00 + cd /app/mediactl_lib/ ./v4l2_drm.out -f video_drm_1080x1920.conf -e 1 & cd /