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

Integrate Libmeo with AOM AV1 SW-BRC #375

Open
wants to merge 4 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
28 changes: 28 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ if ENABLE_TESTS
SUBDIRS += test
endif

#libmebo and libaom_av1_rc support
if ENABLE_MEBO
MEBO_SUPPORT = yes
endif

if ENABLE_AOM_AV1_RC
AOM_AV1_RC_SUPPORT = yes
endif

if ENABLE_BRC
BRC_SUPPORT = yes
endif

if ENABLE_BRC_CONTROLLER
BRC_CONTROLLER_SUPPORT = yes
endif

export DL_LIBS

MEBO_LOCAL_PATH = $(abs_top_srcdir)/encode/libmebo/libs
AOM_AV1_RC_LOCAL_PATH = $(abs_top_srcdir)/encode/aom_libs/
SYSTEM_LIBS_DIR = /usr/local/lib/x86_64-linux-gnu/

export MEBO_LOCAL_PATH
export AOM_AV1_RC_LOCAL_PATH
export SYSTEM_LIBS_DIR


# Extra clean files so that maintainer-clean removes *everything*
MAINTAINERCLEANFILES = \
aclocal.m4 compile config.guess config.sub \
Expand Down
150 changes: 150 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,156 @@ AC_ARG_ENABLE([tests],
[build unit tests @<:@default=no@:>@])],
[], [enable_tests="no"])

AC_ARG_ENABLE(mebo,
[AC_HELP_STRING([--enable-mebo],
[Enable LibMebo Support @<:@default=yes@:>@])],
[], [enable_mebo="yes"])

AC_ARG_ENABLE(aom_av1_rc,
[AC_HELP_STRING([--enable-aom_av1_rc],
[Enable AOM AV1 RC Support @<:@default=yes@:>@])],
[], [enable_aom_av1_rc="yes"])

AC_ARG_ENABLE(brc,
[AC_HELP_STRING([--enable-brc],
[Enable Bitrate RC for VP9,VP8 Support
@<:@default=yes@:>@])],
[], [enable_brc="yes"])

AC_ARG_ENABLE(brc_controller,
[AC_HELP_STRING([--enable-brc_controller],
[Enable Bitrate RC_controller
to support libmebo @<:@default=yes@:>@])],
[], [enable_brc_controller="yes"])

#check for LibMebo library
MEBO_LIBDIR=""
abs_srcdir="$(cd "$srcdir" && pwd)"
if test "x$enable_mebo" != "xno" ; then
#local path
if test -f "$srcdir/encode/libmebo/libs/libmebo.so"; then
MEBO_LIBDIR="${abs_srcdir}/encode/libmebo/libs"
AC_DEFINE([HAVE_MEBO], [1], [Define if MEBO is available])
AC_MSG_NOTICE([MEBO LIB INSTALLED in local path])
else
AC_MSG_NOTICE([Mebo LIB NOT INSTALLED in local path])
#system path
if test -f "/usr/local/lib/x86_64-linux-gnu/libmebo.so" ; then
MEBO_LIBDIR="/usr/local/lib/x86_64-linux-gnu"
AC_DEFINE([HAVE_MEBO], [1], [Define if MEBO is available])
AC_MSG_NOTICE([MEBO LIB INSTALLED in SYSTEM path])
else
AC_MSG_NOTICE([Mebo LIB NOT INSTALLED in system path])
if test "x$enable_mebo"="xyes"; then
AC_MSG_ERROR(
[LibMebo NOT installed in local path nor in system paths])
fi
fi
fi
fi
AC_SUBST([MEBO_LIBDIR])

#CHECK FOR AOM AV1 RC library
AOM_AV1_RC_LIBDIR=""
if test "x$enable_aom_av1_rc" != "xno" ; then
#local path
if test -f "$srcdir/encode/libmebo/libs/aom_libs/libaom_av1_rc.so"; then
AOM_AV1_RC_LIBDIR="${abs_srcdir}/encode/libmebo/libs/aom_libs/"
AC_DEFINE([HAVE_AOM_AV1_RC], [1], [Define if AOM AV1 RC is available])
AC_MSG_NOTICE([AOM AV1 RC LIB INSTALLED in local path])
else
AC_MSG_NOTICE([AOM AV1 RC LIB NOT INSTALLED in local path])
#system path
if test -f "/usr/local/lib/x86_64-linux-gnu/libaom_av1_rc.so" ; then
AOM_AV1_RC_LIBDIR="/usr/local/lib/x86_64-linux-gnu"
AC_DEFINE([HAVE_AOM_AV1_RC], [1], [Define if AOM AV1 RC
is available])
AC_MSG_NOTICE([AOM AV1 RC LIB INSTALLED in SYSTEM path])
else
AC_MSG_NOTICE([AOM AV1 RC LIB NOT INSTALLED in system path])
if test "x$enable_aom_av1_rc"="xyes"; then
AC_MSG_ERROR(
[AOM AV1 RC NOT installed in local path nor in system paths])
fi
fi
fi
fi
AC_SUBST([AOM_AV1_RC_LIBDIR])


#Check for brc library
BRC_LIBDIR=""
if test "x$enable_brc" != "xno" ; then
#local path
if test -f "$srcdir/encode/libmebo/libs/libbrc.so"; then
BRC_LIBDIR="${abs_srcdir}/encode/libmebo/libs"
AC_DEFINE([HAVE_BRC], [1], [Define if BRC is available])
AC_MSG_NOTICE([BRC LIB INSTALLED in local path])
else
AC_MSG_NOTICE([BRC LIB NOT INSTALLED in local path])
#system path
if test -f "/usr/local/lib/x86_64-linux-gnu/libbrc.so" ; then
BRC_LIBDIR="/usr/local/lib/x86_64-linux-gnu"
AC_DEFINE([HAVE_BRC], [1], [Define if BRC is available])
AC_MSG_NOTICE([BRC LIB INSTALLED in SYSTEM path])
else
AC_MSG_NOTICE([BRC LIB NOT INSTALLED in system path])
if test "x$enable_brc"="xyes"; then
AC_MSG_ERROR(
[BRC NOT installed in local path nor in system paths])
fi
fi
fi
fi
AC_SUBST([BRC_LIBDIR])

#Check for brc_controller library
BRC_CONTROLLER_LIBDIR=""
if test "x$enable_brc_controller" != "xno" ; then
#local path
if test -f "$srcdir/encode/libmebo/libs/libbrc_controller.so"; then
BRC_CONTROLLER_LIBDIR="${abs_srcdir}/encode/libmebo/libs"
AC_DEFINE([HAVE_BRC_CONTROLLER], [1], [Define if BRC_CONTROLLER
is available])
AC_MSG_NOTICE([BRC_CONTROLLER LIB INSTALLED in local path])
else
AC_MSG_NOTICE([BRC_CONTROLLER LIB NOT INSTALLED in local path])
#system path
if test -f "/usr/local/lib/x86_64-linux-gnu/libbrc_controller.so" ; then
BRC_CONTROLLER_LIBDIR="/usr/local/lib/x86_64-linux-gnu"
AC_DEFINE([HAVE_BRC_CONTROLLER], [1], [Define if BRC_CONTROLLER
is available])
AC_MSG_NOTICE([BRC_CONTROLLER LIB INSTALLED in SYSTEM path])
else
AC_MSG_NOTICE([BRC LIB NOT INSTALLED in system path])
if test "x$enable_brc_controller"="xyes"; then
AC_MSG_ERROR(
[BRC_CONTROLLER NOT installed in local path nor
in system paths])
fi
fi
fi
fi
AC_SUBST([BRC_CONTROLLER_LIBDIR])

# configure for ldl lib
AC_CHECK_LIB([dl], [dlopen],
[DL_LIBS= "-ldl",
AC_DEFINE([HAVE_DLOPEN], [1], [Define if dlopen is available])],
[AC_MSG_ERROR([Unable to find library support dlopen, dlsym])])
AC_SUBST([DL_LIBS])

#libs path
AC_MSG_NOTICE([LIBRARY PATHS ARE set to])
AC_MSG_NOTICE([MEBO_LIBDIR is set to :${MEBO_LIBDIR}])
AC_MSG_NOTICE([AOM_AV1_RC_LIBDIR is set to :${AOM_AV1_RC_LIBDIR}])
AC_MSG_NOTICE([BRC_LIBDIR is set to :${BRC_LIBDIR}])
AC_MSG_NOTICE([BRC_CONTROLLER is set to :${BRC_CONTROLLER_LIBDIR}])

AM_CONDITIONAL([ENABLE_MEBO], [test "x$MEBO_LIBDIR"!="x"])
AM_CONDITIONAL([ENABLE_AOM_AV1_RC], [test "x$AOM_AV1_RC_LIBDIR"!="x"])
AM_CONDITIONAL([ENABLE_BRC], [test "x$BRC_LIBDIR"!="x"])
AM_CONDITIONAL([ENABLE_BRC_CONTROLLER], [test "x$BRC_CONTROLLER_LIBDIR"!="x"])

LT_INIT
AC_DISABLE_STATIC
Expand Down
12 changes: 11 additions & 1 deletion encode/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,22 @@ vp8enc_LDADD = \
$(top_builddir)/common/libva-display.la \
-lpthread -lm

AUTOMAKE_OPTIONS =subdir-objects

av1encode_SOURCES = av1encode.c
av1encode_SOURCES += libmebo/libmebo_interface.cc
av1encode_CFLAGS = -I$(top_srcdir)/common -g
av1encode_LDADD = \
$(LIBVA_LIBS) \
$(top_builddir)/common/libva-display.la \
-lpthread -lm
-lpthread -lm \
-L$(MEBO_LIBDIR)-lmebo \
-L$(BRC_LIBDIR)-lbrc \
-L$(BRC_CONTROLLER_LIBDIR)-lbrc_controller \
-L$(AOM_AV1_RC_LIBDIR)-laom_av1_rc \
-ldl



valgrind: $(bin_PROGRAMS) $(noinst_PROGRAMS)
for a in $(bin_PROGRAMS) $(noinst_PROGRAMS); do \
Expand Down
89 changes: 43 additions & 46 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 "av1encode.h"
#include "libmebo/libmebo_interface.h"

#define ALIGN16(x) ((x+15)&~15)
#define CHECK_VASTATUS(va_status,func) \
Expand Down Expand Up @@ -441,43 +443,7 @@ 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 vbr_max_bitrate;
int buffer_size;
int initial_buffer_fullness;
};



static VADisplay va_dpy;
Expand All @@ -498,7 +464,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 @@ -629,11 +595,12 @@ 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(" --enswbrc 1 or 0 , 1 enable software brc, 0 use hw brc\n");

printf(" sample usage:\n");
printf("./av1encode -n 8 -f 30 --intra_period 4 --ip_period 1 --rcmode CQP --srcyuv ./input.yuv --recyuv ./rec.yuv --fourcc IYUV --level 8 --width 1920 --height 1080 --base_q_idx 128 -o ./out.av1 --LDB --low_power_mode\n"
"./av1encode -n 8 -f 30 --intra_period 4 --ip_period 1 --rcmode CBR --srcyuv ./input.yuv --recyuv ./rec.yuv --fourcc IYUV --level 8 --width 1920 --height 1080 --target_bitrate 3360000 -o ./out.av1 --LDB --low_power_mode\n"
"./av1encode -n 8 -f 30 --intra_period 4 --ip_period 1 --rcmode VBR --srcyuv ./input.yuv --recyuv ./rec.yuv --fourcc IYUV --level 8 --width 1920 --height 1080 --vbr_max_bitrate 3360000 -o ./out.av1 --LDB --low_power_mode\n");
printf("./av1encode -n 8 -f 30 --intra_period 4 --ip_period 1 --rcmode CQP --srcyuv ./input.yuv --recyuv ./rec.yuv --fourcc IYUV --level 8 --width 1920 --height 1080 --base_q_idx 128 -o ./out.av1 --LDB --low_power_mode --enswbrc 1\n"
"./av1encode -n 8 -f 30 --intra_period 4 --ip_period 1 --rcmode CBR --srcyuv ./input.yuv --recyuv ./rec.yuv --fourcc IYUV --level 8 --width 1920 --height 1080 --target_bitrate 3360000 -o ./out.av1 --LDB --low_power_mode --enswbrc 0\n"
"./av1encode -n 8 -f 30 --intra_period 4 --ip_period 1 --rcmode VBR --srcyuv ./input.yuv --recyuv ./rec.yuv --fourcc IYUV --level 8 --width 1920 --height 1080 --vbr_max_bitrate 3360000 -o ./out.av1 --LDB --low_power_mode --enswbrc 0\n");

}

Expand All @@ -659,6 +626,7 @@ static void process_cmdline(int argc, char *argv[])
{"low_power_mode", no_argument, NULL, 15},
{"target_bitrate", required_argument, NULL, 16},
{"vbr_max_bitrate", required_argument, NULL, 17},
{"enswbrc", required_argument, NULL, 18},
{NULL, no_argument, NULL, 0 }
};

Expand Down Expand Up @@ -732,6 +700,10 @@ static void process_cmdline(int argc, char *argv[])
case 17:
ips.vbr_max_bitrate = atoi(optarg);
break;
case 18:
ips.enable_swbrc = atoi(optarg);
printf("ips.enable_swbrc = %d\n", ips.enable_swbrc);
break;
case 'u':
ips.buffer_size = atoi(optarg) * 8000;
break;
Expand Down Expand Up @@ -2311,10 +2283,19 @@ build_pps_buffer(VAEncPictureParameterBufferAV1* pps)

// //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(ips.enable_swbrc) {
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 @@ -2573,6 +2554,9 @@ 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(ips.enable_swbrc) {
post_encode_update(coded_size);
}

fflush(coded_fp);

Expand Down Expand Up @@ -2772,7 +2756,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;
if (ips.encode_syncmode == 0)
pthread_create(&encode_thread, NULL, storage_task_thread, NULL);

Expand All @@ -2787,6 +2771,11 @@ static int encode_frames(void)
}

tmp = GetTickCount();
if(ips.enable_swbrc) {
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 Expand Up @@ -2963,6 +2952,14 @@ int main(int argc, char **argv)

init_va();
setup_encode();
if(ips.enable_swbrc) {
int result = CreateInitLibmebo(ips);

if(result == 0)
printf("libs are opened correctly\n");
else
printf("there is some problem in opening libs\n");
}

encode_frames();

Expand Down
Loading
Loading