52
52
/* indicate the pipleine is 3dlut -> scaling, by default in one call */
53
53
#define VA_3DLUT_SCALING 1
54
54
#define VA_SCALING_ONLY 2
55
+ #define VA_1DLUT_3DLUT 3
55
56
56
57
static VADisplay va_dpy = NULL ;
57
58
static VAContextID context_id = 0 ;
@@ -90,6 +91,13 @@ static uint16_t g_3dlut_seg_size = 65;
90
91
static uint16_t g_3dlut_mul_size = 128 ;
91
92
static uint32_t g_3dlut_channel_mapping = 1 ;
92
93
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
+
93
101
#if VA_CHECK_VERSION(1, 12, 0)
94
102
95
103
static int8_t
@@ -989,6 +997,45 @@ store_yuv_surface_to_file(FILE *fp,
989
997
}
990
998
}
991
999
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
+
992
1039
static VAStatus
993
1040
upload_data_to_3dlut (FILE *fp,
994
1041
VASurfaceID &surface_id)
@@ -1007,12 +1054,12 @@ upload_data_to_3dlut(FILE *fp,
1007
1054
va_status = vaMapBuffer (va_dpy, surface_image.buf , &surface_p);
1008
1055
CHECK_VASTATUS (va_status, " vaMapBuffer" );
1009
1056
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);
1015
1061
1062
+ if (surface_image.format .fourcc == VA_FOURCC_RGBA && fp) {
1016
1063
fseek (fp, 0L , SEEK_END);
1017
1064
lut3d_size = ftell (fp);
1018
1065
rewind (fp);
@@ -1024,6 +1071,10 @@ upload_data_to_3dlut(FILE *fp,
1024
1071
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);
1025
1072
}
1026
1073
}
1074
+ else { // default 3dlut
1075
+ memset (newImageBuffer, 0xff , frame_size);
1076
+ memcpy (surface_p, newImageBuffer, frame_size);
1077
+ }
1027
1078
1028
1079
if (newImageBuffer) {
1029
1080
free (newImageBuffer);
@@ -1059,6 +1110,50 @@ create_surface(VASurfaceID * p_surface_id,
1059
1110
return va_status;
1060
1111
}
1061
1112
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
+
1062
1157
static VAStatus
1063
1158
lut3D_filter_init (VABufferID &filter_param_buf_id)
1064
1159
{
@@ -1109,6 +1204,83 @@ lut3D_filter_init(VABufferID &filter_param_buf_id)
1109
1204
return va_status;
1110
1205
}
1111
1206
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
+
1112
1284
static VAStatus
1113
1285
video_frame_process_3dlut (VASurfaceID in_surface_id,
1114
1286
VASurfaceID out_surface_id)
@@ -1322,6 +1494,12 @@ vpp_context_create()
1322
1494
}
1323
1495
}
1324
1496
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
+
1325
1503
va_status = vaCreateConfig (va_dpy,
1326
1504
VAProfileNone,
1327
1505
VAEntrypointVideoProc,
@@ -1438,7 +1616,9 @@ parse_basic_parameters()
1438
1616
1439
1617
read_value_uint32 (g_config_file_fd, " FRAME_SUM" , &g_frame_count);
1440
1618
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
+ }
1442
1622
1443
1623
if (read_value_string (g_config_file_fd, " 3DLUT_FILE_NAME" , g_3dlut_file_name)) {
1444
1624
printf (" Read 3DLUT file failed, exit." );
@@ -1456,6 +1636,14 @@ parse_basic_parameters()
1456
1636
printf (" Read channel_mapping failed, exit." );
1457
1637
}
1458
1638
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
+
1459
1647
if (g_in_pic_width != g_out_pic_width ||
1460
1648
g_in_pic_height != g_out_pic_height)
1461
1649
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[])
1534
1722
} else if (g_pipeline_sequence == VA_SCALING_ONLY) {
1535
1723
printf (" process frame #%d in VA_SCALING_ONLY\n " , i);
1536
1724
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);
1537
1727
} else {
1538
1728
printf (" Unknown pipeline sequence, default is 3DLUT->scaling!\n " );
1539
1729
}
@@ -1549,6 +1739,11 @@ int32_t main(int32_t argc, char *argv[])
1549
1739
if (g_config_file_fd)
1550
1740
fclose (g_config_file_fd);
1551
1741
1742
+ if (g_1dlut_buffer) {
1743
+ free (g_1dlut_buffer);
1744
+ g_1dlut_buffer = NULL ;
1745
+ }
1746
+
1552
1747
vpp_context_destroy ();
1553
1748
1554
1749
return 0 ;
0 commit comments