Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

software rate control changes #348

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions encode/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,22 @@ vp8enc_LDADD = \
-lpthread -lm

av1encode_SOURCES = av1encode.c
av1encode_CFLAGS = -I$(top_srcdir)/common -g
av1encode_SOURCES += rate_control_interface.cc

#av1encode_LDADD = \
# $(LIBVA_LIBS) \
# $(top_builddir)/common/libva-display.la \
# -lpthread -lm \
# -L$(top_builddir)/encode/rate_control/libs/ -laom_av1_rc
# -L$(top_builddir)/encode/rate_control/libs/ -ljsoncpp

av1encode_LDADD = \
$(LIBVA_LIBS) \
$(top_builddir)/common/libva-display.la \
-lpthread -lm
$(top_builddir)/common/libva-display.la \
-lpthread -lm \
-laom_av1_rc

av1encode_CFLAGS = -I$(top_srcdir)/common -g

valgrind: $(bin_PROGRAMS) $(noinst_PROGRAMS)
for a in $(bin_PROGRAMS) $(noinst_PROGRAMS); do \
Expand Down
106 changes: 50 additions & 56 deletions encode/av1encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <math.h>
#include <va/va.h>
#include "va_display.h"
#include "rate_ctrl_interface.h"
#include "av1encode.h"

#define ALIGN16(x) ((x+15)&~15)
#define CHECK_VASTATUS(va_status,func) \
Expand Down Expand Up @@ -448,46 +450,6 @@ struct BitOffsets
uint32_t CDEFParamsSizeInBits;
};

struct Av1InputParameters
{
char* srcyuv;
char* recyuv;
char* output;
uint32_t profile;

uint32_t order_hint_bits;
uint32_t enable_cdef;
uint32_t width;
uint32_t height;
uint32_t LDB;
uint32_t frame_rate_extN;
uint32_t frame_rate_extD;
uint32_t level;

// for brc
uint32_t bit_rate;
uint8_t MinBaseQIndex;
uint8_t MaxBaseQIndex;

uint32_t intra_period;
uint32_t ip_period;
uint32_t RateControlMethod;
uint32_t BRefType;
int encode_syncmode;
int calc_psnr;
int frame_count;
int frame_width_aligned;
int frame_height_aligned;
uint32_t base_qindex;
int bit_depth;
int target_bitrate;
int max_bitrate;
int buffer_size;
int initial_buffer_fullness;

};


static VADisplay va_dpy;
static VAProfile av1_profile;
static VAEntrypoint entryPoint;
Expand All @@ -506,7 +468,7 @@ static VAEncPictureParameterBufferAV1 pic_param;
static VAEncTileGroupBufferAV1 tile_group_param;

// sh fh ips
static struct Av1InputParameters ips;
struct Av1InputParameters ips;
static FH fh;
static SH sh;
struct BitOffsets offsets;
Expand Down Expand Up @@ -657,10 +619,10 @@ static void print_help()
printf(" --base_q_idx <number> 1-255\n");
printf(" --normal_mode select VAEntrypointEncSlice as entrypoint\n");
printf(" --low_power_mode select VAEntrypointEncSliceLP as entrypoint\n");

printf(" --en_sw_brc <number> 0-1\n");

printf(" sample usage");
printf("./av1encode -n 8 -f 30 --intra_period 4 --ip_period 1 --rcmode CQP --srcyuv ./input.yuv --recyuv ./rec.yuv --fourcc IYUV --level 8 --height 1080 --width 1920 --base_q_idx 128 -o ./out.av1 -t 3360000 -u 210 -d 420 --LDB --low_power_mode");

printf("./av1encode -n 8 -f 30 --intra_period 4 --ip_period 1 --rcmode CQP --srcyuv ./input.yuv --recyuv ./rec.yuv --fourcc IYUV --level 8 --height 1080 --width 1920 --base_q_idx 128 -o ./out.av1 -t 3360000 -u 210 -d 420 --LDB --low_power_mode --en_sw_brc 0 or 1 \n");

}

Expand All @@ -685,6 +647,7 @@ static void process_cmdline(int argc, char *argv[])
{"LDB", no_argument, NULL, 13},
{"normal_mode", no_argument, NULL, 14},
{"low_power_mode", no_argument, NULL, 15},
{"en_sw_brc", required_argument, NULL, 16},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align?

{NULL, no_argument, NULL, 0 }

};
Expand Down Expand Up @@ -712,7 +675,7 @@ static void process_cmdline(int argc, char *argv[])
break;
case 3:
ips.RateControlMethod = string_to_rc(optarg); //16:cqp 2:CBR 4:VBR
break;
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align

case 4:
ips.srcyuv = strdup(optarg);
break;
Expand Down Expand Up @@ -749,8 +712,15 @@ static void process_cmdline(int argc, char *argv[])
requested_entrypoint = VAEntrypointEncSlice;
break;
case 15:
requested_entrypoint = VAEntrypointEncSliceLP;
requested_entrypoint = VAEntrypointEncSliceLP;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align

break;
case 16:
ips.en_sw_brc = atoi(optarg);
if(1 == ips.en_sw_brc)
{
ips.RateControlMethod = VA_RC_CQP;
}
break;
case 't':
ips.target_bitrate = atoi(optarg);
break;
Expand Down Expand Up @@ -2343,12 +2313,23 @@ build_pps_buffer(VAEncPictureParameterBufferAV1* pps)
fill_ref_params(pps);
pps->refresh_frame_flags = fh.refresh_frame_flags;

// //loop filter
// auto& lf = fh.loop_filter_params;
pps->filter_level[0] = (uint8_t)(fh.loop_filter_params.loop_filter_level[0]);
pps->filter_level[1] = (uint8_t)(fh.loop_filter_params.loop_filter_level[1]);
pps->filter_level_u = (uint8_t)(fh.loop_filter_params.loop_filter_level[2]);
pps->filter_level_v = (uint8_t)(fh.loop_filter_params.loop_filter_level[3]);

if(1 == ips.en_sw_brc)
{
int lfdata[4] ;
getLoopfilterfromRc(lfdata);
pps->filter_level[0] = lfdata[0] ;
pps->filter_level[1] = lfdata[1] ;
pps->filter_level_u = lfdata[2] ;
pps->filter_level_v = lfdata[3] ;
}
else
{
pps->filter_level[0] = (uint8_t)(fh.loop_filter_params.loop_filter_level[0]);
pps->filter_level[1] = (uint8_t)(fh.loop_filter_params.loop_filter_level[1]);
pps->filter_level_u = (uint8_t)(fh.loop_filter_params.loop_filter_level[2]);
pps->filter_level_v = (uint8_t)(fh.loop_filter_params.loop_filter_level[3]);
}
pps->loop_filter_flags.bits.sharpness_level = fh.loop_filter_params.loop_filter_sharpness;
pps->loop_filter_flags.bits.mode_ref_delta_enabled = fh.loop_filter_params.loop_filter_delta_enabled;
pps->loop_filter_flags.bits.mode_ref_delta_update = fh.loop_filter_params.loop_filter_delta_update;
Expand Down Expand Up @@ -2547,7 +2528,7 @@ static int load_surface(VASurfaceID surface_id, unsigned long long display_order

return 0;
}

unsigned int consumed_bytes = 0;
static int save_codeddata(unsigned long long display_order, unsigned long long encode_order)
{
VACodedBufferSegment *buf_list = NULL;
Expand Down Expand Up @@ -2606,7 +2587,11 @@ static int save_codeddata(unsigned long long display_order, unsigned long long e
}
printf("%08lld", encode_order);
printf("(%06d bytes coded)\n", coded_size);

if(1 == ips.en_sw_brc)
{
consumed_bytes = coded_size;
updateRatecontrolAfterEncode(consumed_bytes);
}
fflush(coded_fp);

return 0;
Expand Down Expand Up @@ -2790,7 +2775,10 @@ static int encode_frames(void)
unsigned int i, tmp;
VAStatus va_status;
//VASurfaceStatus surface_status;

if(1 == ips.en_sw_brc)
{
create_ratectrl(ips);
}
/* upload RAW YUV data into all surfaces */
tmp = GetTickCount();
if (srcyuv_fp != NULL) {
Expand All @@ -2806,7 +2794,7 @@ static int encode_frames(void)
memset(&seq_param, 0, sizeof(seq_param));
memset(&pic_param, 0, sizeof(pic_param));
memset(&tile_group_param, 0, sizeof(tile_group_param));

unsigned int baseqp =45;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a default value?

if (ips.encode_syncmode == 0)
pthread_create(&encode_thread, NULL, storage_task_thread, NULL);

Expand All @@ -2821,6 +2809,12 @@ static int encode_frames(void)
}

tmp = GetTickCount();
if(1 == ips.en_sw_brc)
{
baseqp = getQPfromRatectrl(current_frame_type);
ips.base_qindex = baseqp;
}

va_status = vaBeginPicture(va_dpy, context_id, src_surface[current_slot]);
CHECK_VASTATUS(va_status, "vaBeginPicture");
BeginPictureTicks += GetTickCount() - tmp;
Expand Down
59 changes: 59 additions & 0 deletions encode/av1encode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef AV1_ENCODE_H_
#define AV1_ENCODE_H_

#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif


struct Av1InputParameters
{
char* srcyuv;
char* recyuv;
char* output;
uint32_t profile;

uint32_t order_hint_bits;
uint32_t enable_cdef;
uint32_t width;
uint32_t height;
uint32_t LDB;
uint32_t frame_rate_extN;
uint32_t frame_rate_extD;
uint32_t level;

// for brc
uint32_t bit_rate;
uint8_t MinBaseQIndex;
uint8_t MaxBaseQIndex;

uint32_t intra_period;
uint32_t ip_period;
uint32_t RateControlMethod;
uint32_t BRefType;
int encode_syncmode;
int calc_psnr;
int frame_count;
int frame_width_aligned;
int frame_height_aligned;
uint32_t base_qindex;
int bit_depth;
int target_bitrate;
int max_bitrate;
int buffer_size;
int initial_buffer_fullness;
bool en_sw_brc;

};

#ifdef __cplusplus
}
#endif

#endif//AV1_ENCODE_H_
Loading
Loading