Skip to content

Commit 44a0896

Browse files
committed
Added 1DLUT filter sample code and template.
Signed-off-by: Zhang, Furong <furong.zhang@intel.com>
1 parent c464d3f commit 44a0896

File tree

3 files changed

+240
-8
lines changed

3 files changed

+240
-8
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Configuration information for video process test case.
2+
# This application will firstly load yuv frames to one type of surface(P010)
3+
# you require. After video processing, the processed content (NV12 surface)
4+
# will be stored to frames(nv12 format in file).
5+
# Supported features include scaling and implicit format conversion(P010<->RGB<->NV12).
6+
# you can modify this configuration file to set the corresponding parameters.
7+
8+
#1.Source YUV file information
9+
SRC_FILE_NAME: ./Flower.p010
10+
SRC_FRAME_WIDTH: 1920
11+
SRC_FRAME_HEIGHT: 1080
12+
SRC_FRAME_FORMAT: P010
13+
SRC_FILE_FORMAT: P010
14+
15+
#2.Destination YUV(RGB) file information
16+
DST_FILE_NAME: ./out_1920x1080.p010
17+
DST_FRAME_WIDTH: 1920
18+
DST_FRAME_HEIGHT: 1080
19+
DST_FRAME_FORMAT: P010
20+
DST_FILE_FORMAT: P010
21+
22+
#3.How many frames to be processed
23+
FRAME_SUM: 1
24+
25+
#4.3DLUT configuration file
26+
3DLUT_FILE_NAME: ./3dlut_65cubic.dat
27+
3DLUT_SEG_SIZE: 65
28+
3DLUT_MUL_SIZE: 128
29+
3DLUT_CHANNEL_MAPPING: 1
30+
31+
#5.1DLUT configuration file
32+
1DLUT_FILE_NAME: ./1dlut_256.dat
33+
1DLUT_SEG_SIZE: 256
34+
35+
#5. pipeline(3DLUT->Scaling: 1, Scaling->3DLUT: 0, Scaling only: 2, 1DLUT_3DLUT: 3)
36+
PIPELINE: 3
37+

videoprocess/process_3dlut.cfg.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ FRAME_SUM: 1
2828
3DLUT_MUL_SIZE: 128
2929
3DLUT_CHANNEL_MAPPING: 1
3030

31-
#5. 3DLUT Scaling pipeline(3DLUT->Scaling: 1, Scaling->3DLUT: 0, Scaling only: 2)
32-
3DLUT_SCALING: 1
31+
#5. Pipeline Configuration(3DLUT->Scaling: 1, Scaling->3DLUT: 0, Scaling only: 2)
32+
PIPELINE: 1
3333

videoprocess/vpp3dlut.cpp

Lines changed: 201 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
/* indicate the pipleine is 3dlut -> scaling, by default in one call */
5353
#define VA_3DLUT_SCALING 1
5454
#define VA_SCALING_ONLY 2
55+
#define VA_1DLUT_3DLUT 3
5556

5657
static VADisplay va_dpy = NULL;
5758
static VAContextID context_id = 0;
@@ -90,6 +91,13 @@ static uint16_t g_3dlut_seg_size = 65;
9091
static uint16_t g_3dlut_mul_size = 128;
9192
static uint32_t g_3dlut_channel_mapping = 1;
9293

94+
static char g_1dlut_file_name[MAX_LEN];
95+
static uint16_t g_1dlut_seg_size = 256;
96+
static uint8_t* g_1dlut_buffer = NULL;
97+
static uint8_t g_1dlut_bit_depth = 16;
98+
static uint8_t g_1dlut_channel_num = 4;
99+
static uint32_t g_1dlut_buffer_size = g_1dlut_seg_size * (g_1dlut_bit_depth / 8) * g_1dlut_channel_num;
100+
93101
#if VA_CHECK_VERSION(1, 12, 0)
94102

95103
static int8_t
@@ -989,6 +997,45 @@ store_yuv_surface_to_file(FILE *fp,
989997
}
990998
}
991999

1000+
static VAStatus
1001+
upload_data_to_1dlut(FILE *fp)
1002+
{
1003+
VAStatus va_status;
1004+
uint32_t real_size = 0;
1005+
uint16_t *p1dlut_buffer = NULL;
1006+
1007+
if (g_1dlut_buffer == NULL) {
1008+
g_1dlut_buffer = (unsigned char*)malloc(g_1dlut_seg_size * g_1dlut_bit_depth / 8 * g_1dlut_channel_num);
1009+
assert(g_1dlut_buffer);
1010+
}
1011+
1012+
p1dlut_buffer = (uint16_t*)g_1dlut_buffer;
1013+
1014+
if (fp) {
1015+
fseek(fp, 0L, SEEK_END);
1016+
real_size = ftell(fp);
1017+
rewind(fp);
1018+
1019+
if (real_size != g_1dlut_buffer_size) {
1020+
printf("1DLUT file size error!\n");
1021+
}
1022+
1023+
if (fread(g_1dlut_buffer, real_size, 1, fp) != 0) {
1024+
printf("upload_data_to_1dlut %d\n");
1025+
va_status = VA_STATUS_SUCCESS;
1026+
}
1027+
} else { // default test 1dlut
1028+
for (uint32_t index = 0; index < g_1dlut_seg_size; index++) {
1029+
p1dlut_buffer[index *4 + 0] = index * 257;
1030+
p1dlut_buffer[index *4 + 1] = index * 257;
1031+
p1dlut_buffer[index *4 + 2] = index * 257;
1032+
p1dlut_buffer[index *4 + 3] = index * 257;
1033+
}
1034+
}
1035+
1036+
return va_status;
1037+
}
1038+
9921039
static VAStatus
9931040
upload_data_to_3dlut(FILE *fp,
9941041
VASurfaceID &surface_id)
@@ -1007,12 +1054,12 @@ upload_data_to_3dlut(FILE *fp,
10071054
va_status = vaMapBuffer(va_dpy, surface_image.buf, &surface_p);
10081055
CHECK_VASTATUS(va_status, "vaMapBuffer");
10091056

1010-
if (surface_image.format.fourcc == VA_FOURCC_RGBA && fp) {
1011-
/* 3DLUT surface is allocated to 32 bit RGB */
1012-
frame_size = surface_image.width * surface_image.height * 4;
1013-
newImageBuffer = (unsigned char*)malloc(frame_size);
1014-
assert(newImageBuffer);
1057+
/* 3DLUT surface is allocated to 32 bit RGB */
1058+
frame_size = surface_image.width * surface_image.height * 4;
1059+
newImageBuffer = (unsigned char*)malloc(frame_size);
1060+
assert(newImageBuffer);
10151061

1062+
if (surface_image.format.fourcc == VA_FOURCC_RGBA && fp) {
10161063
fseek(fp, 0L, SEEK_END);
10171064
lut3d_size = ftell(fp);
10181065
rewind(fp);
@@ -1024,6 +1071,10 @@ upload_data_to_3dlut(FILE *fp,
10241071
printf("upload_data_to_3dlut: 3DLUT surface width %d, height %d, pitch %d, frame size %d, 3dlut file size: %d\n", surface_image.width, surface_image.height, surface_image.pitches[0], frame_size, lut3d_size);
10251072
}
10261073
}
1074+
else { // default 3dlut
1075+
memset(newImageBuffer, 0xff, frame_size);
1076+
memcpy(surface_p, newImageBuffer, frame_size);
1077+
}
10271078

10281079
if (newImageBuffer) {
10291080
free(newImageBuffer);
@@ -1059,6 +1110,50 @@ create_surface(VASurfaceID * p_surface_id,
10591110
return va_status;
10601111
}
10611112

1113+
static VAStatus
1114+
lut1D_filter_init(VABufferID &filter_param_buf_id)
1115+
{
1116+
VAStatus va_status;
1117+
VAProcFilterParameterBuffer1DLUT lut1d_param;
1118+
VABufferID lut1d_param_buf_id;
1119+
uint32_t num_caps = 10;
1120+
bool bSupported = false;
1121+
1122+
VAProcFilterCap1DLUT caps[num_caps];
1123+
memset(&caps, 0, sizeof(VAProcFilterCap1DLUT)*num_caps);
1124+
va_status = vaQueryVideoProcFilterCaps(va_dpy, context_id,
1125+
VAProcFilter1DLUT,
1126+
(void *)caps, &num_caps);
1127+
CHECK_VASTATUS(va_status, "vaQueryVideoProcFilterCaps");
1128+
printf("vaQueryVideoProcFilterCaps num_caps %d\n", num_caps);
1129+
1130+
/* check if the input parameters are supported */
1131+
for (uint32_t index = 0; index < num_caps; index++) {
1132+
// check lut_size and lut_stride
1133+
if (caps[index].lut_size = g_1dlut_seg_size) {
1134+
bSupported = true;
1135+
}
1136+
}
1137+
1138+
if (bSupported) {
1139+
lut1d_param.type = VAProcFilter1DLUT;
1140+
lut1d_param.buffer_size = g_1dlut_buffer_size;
1141+
lut1d_param.lut_buffer = g_1dlut_buffer;
1142+
lut1d_param.lut_size = g_1dlut_seg_size;
1143+
lut1d_param.bit_depth = g_1dlut_bit_depth;
1144+
lut1d_param.num_channel = g_1dlut_channel_num;
1145+
1146+
/* create 3dlut fitler buffer */
1147+
va_status = vaCreateBuffer(va_dpy, context_id,
1148+
VAProcFilterParameterBufferType, sizeof(lut1d_param), 1,
1149+
&lut1d_param, &lut1d_param_buf_id);
1150+
1151+
filter_param_buf_id = lut1d_param_buf_id;
1152+
}
1153+
1154+
return va_status;
1155+
}
1156+
10621157
static VAStatus
10631158
lut3D_filter_init(VABufferID &filter_param_buf_id)
10641159
{
@@ -1109,6 +1204,83 @@ lut3D_filter_init(VABufferID &filter_param_buf_id)
11091204
return va_status;
11101205
}
11111206

1207+
static VAStatus
1208+
video_frame_process_1dlut_3dlut(
1209+
VASurfaceID in_surface_id,
1210+
VASurfaceID out_surface_id)
1211+
1212+
{
1213+
VAStatus va_status;
1214+
VAProcPipelineParameterBuffer pipeline_param;
1215+
VARectangle surface_region, output_region;
1216+
VABufferID pipeline_param_buf_id = VA_INVALID_ID;
1217+
VABufferID filter_param_buf_id[2];
1218+
1219+
/*Create 1DLUT Filter*/
1220+
lut1D_filter_init(filter_param_buf_id[0]);
1221+
1222+
/*Create 3DLUT Filter*/
1223+
lut3D_filter_init(filter_param_buf_id[1]);
1224+
1225+
/* Fill pipeline buffer */
1226+
surface_region.x = 0;
1227+
surface_region.y = 0;
1228+
surface_region.width = g_in_pic_width;
1229+
surface_region.height = g_in_pic_height;
1230+
output_region.x = 0;
1231+
output_region.y = 0;
1232+
output_region.width = g_out_pic_width;
1233+
output_region.height = g_out_pic_height;
1234+
1235+
memset(&pipeline_param, 0, sizeof(pipeline_param));
1236+
pipeline_param.surface = in_surface_id;
1237+
pipeline_param.surface_region = &surface_region;
1238+
pipeline_param.output_region = &output_region;
1239+
pipeline_param.filter_flags = 0;
1240+
pipeline_param.filters = filter_param_buf_id;
1241+
pipeline_param.num_filters = 2;
1242+
/* input is bt2020 */
1243+
pipeline_param.surface_color_standard = VAProcColorStandardBT2020;
1244+
pipeline_param.output_color_standard = VAProcColorStandardBT2020;
1245+
1246+
va_status = vaCreateBuffer(va_dpy,
1247+
context_id,
1248+
VAProcPipelineParameterBufferType,
1249+
sizeof(pipeline_param),
1250+
1,
1251+
&pipeline_param,
1252+
&pipeline_param_buf_id);
1253+
CHECK_VASTATUS(va_status, "vaCreateBuffer");
1254+
1255+
va_status = vaBeginPicture(va_dpy,
1256+
context_id,
1257+
out_surface_id);
1258+
CHECK_VASTATUS(va_status, "vaBeginPicture");
1259+
1260+
va_status = vaRenderPicture(va_dpy,
1261+
context_id,
1262+
&pipeline_param_buf_id,
1263+
1);
1264+
CHECK_VASTATUS(va_status, "vaRenderPicture");
1265+
1266+
va_status = vaEndPicture(va_dpy, context_id);
1267+
CHECK_VASTATUS(va_status, "vaEndPicture");
1268+
1269+
if (pipeline_param_buf_id != VA_INVALID_ID) {
1270+
vaDestroyBuffer(va_dpy, pipeline_param_buf_id);
1271+
}
1272+
1273+
if (filter_param_buf_id[0] != VA_INVALID_ID) {
1274+
vaDestroyBuffer(va_dpy, filter_param_buf_id[0]);
1275+
}
1276+
1277+
if (filter_param_buf_id[1] != VA_INVALID_ID) {
1278+
vaDestroyBuffer(va_dpy, filter_param_buf_id[1]);
1279+
}
1280+
1281+
return va_status;
1282+
}
1283+
11121284
static VAStatus
11131285
video_frame_process_3dlut(VASurfaceID in_surface_id,
11141286
VASurfaceID out_surface_id)
@@ -1322,6 +1494,12 @@ vpp_context_create()
13221494
}
13231495
}
13241496

1497+
if (g_pipeline_sequence == VA_1DLUT_3DLUT) {
1498+
FILE *lut1d_file = NULL;
1499+
lut1d_file = fopen(g_1dlut_file_name, "rb");
1500+
upload_data_to_1dlut(lut1d_file);
1501+
}
1502+
13251503
va_status = vaCreateConfig(va_dpy,
13261504
VAProfileNone,
13271505
VAEntrypointVideoProc,
@@ -1438,7 +1616,9 @@ parse_basic_parameters()
14381616

14391617
read_value_uint32(g_config_file_fd, "FRAME_SUM", &g_frame_count);
14401618

1441-
read_value_uint32(g_config_file_fd, "3DLUT_SCALING", &g_pipeline_sequence);
1619+
if (read_value_uint32(g_config_file_fd, "PIPELINE", &g_pipeline_sequence)) {
1620+
printf("Read Pipeline Oonfiguration failed, exit.");
1621+
}
14421622

14431623
if (read_value_string(g_config_file_fd, "3DLUT_FILE_NAME", g_3dlut_file_name)) {
14441624
printf("Read 3DLUT file failed, exit.");
@@ -1456,6 +1636,14 @@ parse_basic_parameters()
14561636
printf("Read channel_mapping failed, exit.");
14571637
}
14581638

1639+
if (read_value_string(g_config_file_fd, "1DLUT_FILE_NAME", g_1dlut_file_name)) {
1640+
printf("Read 1DLUT file failed, exit.");
1641+
}
1642+
1643+
if (read_value_uint16(g_config_file_fd, "1DLUT_SEG_SIZE", &g_1dlut_seg_size)) {
1644+
printf("Read segment_size failed, exit.");
1645+
}
1646+
14591647
if (g_in_pic_width != g_out_pic_width ||
14601648
g_in_pic_height != g_out_pic_height)
14611649
printf("Scaling will be done : from %4d x %4d to %4d x %4d \n",
@@ -1534,6 +1722,8 @@ int32_t main(int32_t argc, char *argv[])
15341722
} else if (g_pipeline_sequence == VA_SCALING_ONLY) {
15351723
printf("process frame #%d in VA_SCALING_ONLY\n", i);
15361724
video_frame_process_scaling(g_in_surface_id, g_out_surface_id);
1725+
} else if (g_pipeline_sequence == VA_1DLUT_3DLUT) {
1726+
video_frame_process_1dlut_3dlut(g_in_surface_id, g_out_surface_id);
15371727
} else {
15381728
printf("Unknown pipeline sequence, default is 3DLUT->scaling!\n");
15391729
}
@@ -1549,6 +1739,11 @@ int32_t main(int32_t argc, char *argv[])
15491739
if (g_config_file_fd)
15501740
fclose(g_config_file_fd);
15511741

1742+
if (g_1dlut_buffer) {
1743+
free(g_1dlut_buffer);
1744+
g_1dlut_buffer = NULL;
1745+
}
1746+
15521747
vpp_context_destroy();
15531748

15541749
return 0;

0 commit comments

Comments
 (0)