Skip to content

Commit e222df7

Browse files
TianhaolXinfengZhang
authored andcommitted
[Encode] Support lowpower for HEVC Encoding
Add one option "--lowpower" to support lowpower for hevc encoding, lowpower is disabled by default. Change option "--bitrate" to kbps.
1 parent dd2b961 commit e222df7

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

encode/hevcencode.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ enum {
7878
#define PROFILE_IDC_MAIN10 2
7979

8080
#define BITSTREAM_ALLOCATE_STEPPING 4096
81-
#define LCU_SIZE 32
81+
static int LCU_SIZE = 32;
8282

8383
#define SURFACE_NUM 16 /* 16 surfaces for source YUV */
8484
#define SURFACE_NUM 16 /* 16 surfaces for reference */
@@ -374,7 +374,9 @@ static struct SliceHeader ssh;
374374
static VADisplay va_dpy;
375375
static VAProfile hevc_profile = ~0;
376376
static int real_hevc_profile = 0;
377+
static VAEntrypoint entryPoint = VAEntrypointEncSlice;
377378
static int p2b = 1;
379+
static int lowpower = 0;
378380
static VAConfigAttrib attrib[VAConfigAttribTypeMax];
379381
static VAConfigAttrib config_attrib[VAConfigAttribTypeMax];
380382
static int config_attrib_num = 0, enc_packed_header_idx;
@@ -1746,7 +1748,7 @@ static int print_help(void)
17461748
printf(" --intra_period <number>\n");
17471749
printf(" --idr_period <number>\n");
17481750
printf(" --ip_period <number>\n");
1749-
printf(" --bitrate <bitrate>\n");
1751+
printf(" --bitrate <bitrate> Kbits per second\n");
17501752
printf(" --initialqp <number>\n");
17511753
printf(" --minqp <number>\n");
17521754
printf(" --rcmode <NONE|CBR|VBR|VCM|CQP|VBR_CONTRAINED>\n");
@@ -1757,6 +1759,7 @@ static int print_help(void)
17571759
printf(" --enablePSNR calculate PSNR of recyuv vs. srcyuv\n");
17581760
printf(" --profile 1: main 2 : main10\n");
17591761
printf(" --p2b 1: enable 0 : disalbe(defalut)\n");
1762+
printf(" --lowpower 1: enable 0 : disalbe(defalut)\n");
17601763
return 0;
17611764
}
17621765

@@ -1782,6 +1785,7 @@ static int process_cmdline(int argc, char *argv[])
17821785
{"framecount", required_argument, NULL, 16 },
17831786
{"profile", required_argument, NULL, 17 },
17841787
{"p2b", required_argument, NULL, 18 },
1788+
{"lowpower", required_argument, NULL, 19 },
17851789
{NULL, no_argument, NULL, 0 }
17861790
};
17871791
int long_index;
@@ -1808,7 +1812,7 @@ static int process_cmdline(int argc, char *argv[])
18081812
print_help();
18091813
exit(0);
18101814
case 1:
1811-
frame_bitrate = atoi(optarg);
1815+
frame_bitrate = atoi(optarg)*1000;
18121816
break;
18131817
case 2:
18141818
minimal_qp = atoi(optarg);
@@ -1870,6 +1874,9 @@ static int process_cmdline(int argc, char *argv[])
18701874
case 18:
18711875
p2b = atoi(optarg);
18721876
break;
1877+
case 19:
1878+
lowpower = atoi(optarg);
1879+
break;
18731880

18741881
case ':':
18751882
case '?':
@@ -1987,7 +1994,8 @@ static int init_va(void)
19871994
hevc_profile = profile_list[i];
19881995
vaQueryConfigEntrypoints(va_dpy, hevc_profile, entrypoints, &num_entrypoints);
19891996
for (slice_entrypoint = 0; slice_entrypoint < num_entrypoints; slice_entrypoint++) {
1990-
if (entrypoints[slice_entrypoint] == VAEntrypointEncSlice) {
1997+
if (entrypoints[slice_entrypoint] == VAEntrypointEncSlice ||
1998+
entrypoints[slice_entrypoint] == VAEntrypointEncSliceLP ) {
19911999
support_encode = 1;
19922000
break;
19932001
}
@@ -2023,7 +2031,7 @@ static int init_va(void)
20232031
for (i = 0; i < VAConfigAttribTypeMax; i++)
20242032
attrib[i].type = i;
20252033

2026-
va_status = vaGetConfigAttributes(va_dpy, hevc_profile, VAEntrypointEncSlice,
2034+
va_status = vaGetConfigAttributes(va_dpy, hevc_profile, entryPoint,
20272035
&attrib[0], VAConfigAttribTypeMax);
20282036
CHECK_VASTATUS(va_status, "vaGetConfigAttributes");
20292037
/* check the interested configattrib */
@@ -2165,7 +2173,12 @@ static int setup_encode()
21652173
VASurfaceID *tmp_surfaceid;
21662174
int codedbuf_size, i;
21672175

2168-
va_status = vaCreateConfig(va_dpy, hevc_profile, VAEntrypointEncSlice,
2176+
if (lowpower)
2177+
{
2178+
entryPoint = VAEntrypointEncSliceLP;
2179+
LCU_SIZE = 64;
2180+
}
2181+
va_status = vaCreateConfig(va_dpy, hevc_profile, entryPoint,
21692182
&config_attrib[0], config_attrib_num, &config_id);
21702183
CHECK_VASTATUS(va_status, "vaCreateConfig");
21712184

@@ -2325,7 +2338,7 @@ static int render_sequence(struct SeqParamSet *sps)
23252338
seq_param.intra_idr_period = intra_idr_period;
23262339
seq_param.ip_period = ip_period;
23272340

2328-
seq_param.bits_per_second = 400000;
2341+
seq_param.bits_per_second = frame_bitrate;
23292342
seq_param.pic_width_in_luma_samples = sps->pic_width_in_luma_samples;
23302343
seq_param.pic_height_in_luma_samples = sps->pic_height_in_luma_samples;
23312344

@@ -3171,6 +3184,7 @@ static int print_input()
31713184
printf("INPUT: Initial QP : %d\n", initial_qp);
31723185
printf("INPUT: Min QP : %d\n", minimal_qp);
31733186
printf("INPUT: P As B : %d\n", p2b);
3187+
printf("INPUT: lowpower : %d\n", lowpower);
31743188
printf("INPUT: Source YUV : %s", srcyuv_fp ? "FILE" : "AUTO generated");
31753189
if (srcyuv_fp)
31763190
printf(":%s (fourcc %s)\n", srcyuv_fn, fourcc_to_string(srcyuv_fourcc));

0 commit comments

Comments
 (0)