mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 19:24:06 +00:00
Merge branch 'crypto'
This commit is contained in:
commit
ffb4f78e64
|
@ -125,6 +125,7 @@
|
|||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\extras\crypto.cpp" />
|
||||
<ClCompile Include="..\..\src\extras\libmd5.c" />
|
||||
<ClCompile Include="..\..\src\input_frame_buffer.c" />
|
||||
<ClCompile Include="..\..\src\kvazaar.c" />
|
||||
|
@ -177,6 +178,7 @@
|
|||
<ClCompile Include="..\..\src\strategies\strategies-quant.c" />
|
||||
<ClInclude Include="..\..\src\checkpoint.h" />
|
||||
<ClInclude Include="..\..\src\cu.h" />
|
||||
<ClInclude Include="..\..\src\extras\crypto.h" />
|
||||
<ClInclude Include="..\..\src\extras\libmd5.h" />
|
||||
<ClInclude Include="..\..\src\image.h" />
|
||||
<ClInclude Include="..\..\src\imagelist.h" />
|
||||
|
|
|
@ -217,6 +217,7 @@
|
|||
<Filter>Optimization\strategies\avx2</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\extras\libmd5.c" />
|
||||
<ClCompile Include="..\..\src\extras\crypto.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\bitstream.h">
|
||||
|
@ -403,6 +404,7 @@
|
|||
<Filter>Optimization\strategies\avx2</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\extras\libmd5.h" />
|
||||
<ClInclude Include="..\..\src\extras\crypto.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<YASM Include="..\..\src\extras\x86inc.asm">
|
||||
|
|
29
configure.ac
29
configure.ac
|
@ -23,7 +23,7 @@ AC_CONFIG_SRCDIR([src/encmain.c])
|
|||
#
|
||||
# Here is a somewhat sane guide to lib versioning: http://apr.apache.org/versioning.html
|
||||
ver_major=3
|
||||
ver_minor=6
|
||||
ver_minor=7
|
||||
ver_release=0
|
||||
|
||||
# Prevents configure from adding a lot of defines to the CFLAGS
|
||||
|
@ -38,6 +38,7 @@ AM_SILENT_RULES([yes])
|
|||
AC_PROG_CC
|
||||
AC_PROG_CC_C99
|
||||
AM_PROG_AR
|
||||
AC_PROG_CXX
|
||||
|
||||
# Get fread that can read more than 2GB on 32 bit systems.
|
||||
AC_SYS_LARGEFILE
|
||||
|
@ -52,14 +53,32 @@ AM_CONDITIONAL([HAVE_AVX2], [test x"$flag_avx2" = x"true"])
|
|||
AM_CONDITIONAL([HAVE_SSE4_1], [test x"$flag_sse4_1" = x"true"])
|
||||
AM_CONDITIONAL([HAVE_SSE2], [test x"$flag_sse2" = x"true"])
|
||||
|
||||
KVZ_CFLAGS="-Wall -Wtype-limits -Wvla -I$srcdir/src -ftree-vectorize -fvisibility=hidden"
|
||||
KVZ_CFLAGS="-Wall -Wtype-limits -Wvla -I$srcdir/src -I$srcdir/src/extras -ftree-vectorize -fvisibility=hidden"
|
||||
CFLAGS="$KVZ_CFLAGS $CFLAGS"
|
||||
|
||||
AC_ARG_WITH([cryptopp],
|
||||
AS_HELP_STRING([--with-cryptopp],
|
||||
[Build with cryptopp Enables selective encryption.]))
|
||||
AS_IF([test "x$with_cryptopp" = "xyes"], [
|
||||
PKG_CHECK_MODULES([cryptopp], [cryptopp],
|
||||
AC_DEFINE([KVZ_SEL_ENCRYPTION], [1], [With cryptopp]),
|
||||
AC_MSG_ERROR([cryptopp not found with pkg-config])
|
||||
)
|
||||
])
|
||||
|
||||
AM_CONDITIONAL([USE_CRYPTOPP], [test "x$with_cryptopp" = "xyes"])
|
||||
CPPFLAGS="$CPPFLAGS $cryptopp_CFLAGS"
|
||||
LIBS="$LIBS $cryptopp_LIBS"
|
||||
|
||||
|
||||
CPPFLAGS="-DKVZ_DLL_EXPORTS $CPPFLAGS"
|
||||
|
||||
AC_SEARCH_LIBS([log], [m c], [], [exit 1])
|
||||
AC_SEARCH_LIBS([pow], [m c], [], [exit 1])
|
||||
AC_SEARCH_LIBS([sqrt], [m c], [], [exit 1])
|
||||
|
||||
|
||||
|
||||
# This does workarounds for pthreads on various compilers.
|
||||
AX_PTHREAD
|
||||
CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
|
||||
|
@ -72,10 +91,6 @@ AC_ARG_ENABLE([werror], [AS_HELP_STRING([--disable-werror], [don't treat warning
|
|||
)
|
||||
|
||||
|
||||
# check for getopt
|
||||
AC_CHECK_HEADER([getopt.h], [], [CFLAGS="$CFLAGS -I$srcdir/src/extras"])
|
||||
|
||||
|
||||
# host and cpu specific settings
|
||||
AS_CASE([$host_cpu],
|
||||
[i?86], [BITS="32" ASFLAGS="$ASFLAGS -DARCH_X86_64=0" X86="true"],
|
||||
|
@ -133,10 +148,8 @@ AC_SUBST([ASFLAGS])
|
|||
KVZ_API_VERSION="$ver_major:$ver_minor:$ver_release"
|
||||
AC_SUBST([KVZ_API_VERSION])
|
||||
|
||||
|
||||
AC_CONFIG_FILES([Makefile
|
||||
src/Makefile
|
||||
src/kvazaar.pc
|
||||
tests/Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
|
|
|
@ -131,7 +131,8 @@ libkvazaar_la_SOURCES = \
|
|||
strategyselector.c \
|
||||
strategyselector.h \
|
||||
extras/libmd5.c \
|
||||
extras/libmd5.h
|
||||
extras/libmd5.h \
|
||||
extras/crypto.h
|
||||
|
||||
libkvazaar_la_CFLAGS =
|
||||
|
||||
|
@ -141,6 +142,12 @@ libkvazaar_la_LIBADD = \
|
|||
libsse2.la \
|
||||
libsse41.la
|
||||
|
||||
if USE_CRYPTOPP
|
||||
libkvazaar_la_SOURCES += \
|
||||
extras/crypto.h \
|
||||
extras/crypto.cpp
|
||||
endif
|
||||
|
||||
libkvazaar_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined -version-number $(KVZ_API_VERSION)
|
||||
|
||||
|
||||
|
|
208
src/cabac.c
208
src/cabac.c
|
@ -19,7 +19,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "cabac.h"
|
||||
|
||||
#include "encoderstate.h"
|
||||
|
||||
const uint8_t kvz_g_auc_next_state_mps[128] =
|
||||
{
|
||||
|
@ -271,6 +271,7 @@ void kvz_cabac_write_coeff_remain(cabac_data_t * const cabac, const uint32_t sym
|
|||
{
|
||||
int32_t code_number = symbol;
|
||||
uint32_t length;
|
||||
|
||||
if (code_number < (3 << r_param)) {
|
||||
length = code_number >> r_param;
|
||||
CABAC_BINS_EP(cabac, (1 << (length + 1)) - 2 , length + 1, "coeff_abs_level_remaining");
|
||||
|
@ -287,6 +288,198 @@ void kvz_cabac_write_coeff_remain(cabac_data_t * const cabac, const uint32_t sym
|
|||
}
|
||||
}
|
||||
|
||||
void kvz_cabac_write_coeff_remain_encry(struct encoder_state_t * const state, cabac_data_t * const cabac,const uint32_t symbol, const uint32_t r_param, int32_t base_level)
|
||||
{
|
||||
int32_t codeNumber = (int32_t)symbol;
|
||||
uint32_t length;
|
||||
|
||||
if (codeNumber < (3 << r_param)) {
|
||||
length = codeNumber>>r_param;
|
||||
CABAC_BINS_EP(cabac, (1 << (length + 1)) - 2 , length + 1, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP( (1<<(length+1))-2 , length+1);
|
||||
uint32_t Suffix = (codeNumber%(1<<r_param));
|
||||
|
||||
if(!r_param)
|
||||
CABAC_BINS_EP(cabac, Suffix, r_param, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(Suffix, r_param);
|
||||
if(r_param==1) {
|
||||
if(!(( base_level ==2 )&& (codeNumber==4 || codeNumber==5) ) ) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 1;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 1, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 1);
|
||||
} else {
|
||||
CABAC_BINS_EP(cabac, Suffix, 1, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(Suffix, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
if(r_param==2) {
|
||||
if( base_level ==1) {
|
||||
uint32_t key =ff_get_key(&state->tile->dbs_g, 2);
|
||||
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 3;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||
} else
|
||||
if( base_level ==2) {
|
||||
if(codeNumber<=7 || codeNumber>=12) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 3;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||
}
|
||||
else
|
||||
if(codeNumber<10) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||
state->tile->m_prev_pos = (( (Suffix&1) + ( state->tile->m_prev_pos^key )) & 1);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||
} else
|
||||
CABAC_BINS_EP(cabac, Suffix, 2, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(Suffix, 2);
|
||||
} else { //base_level=3
|
||||
if(codeNumber<=7 || codeNumber>11) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||
state->tile->m_prev_pos = (Suffix + ( state->tile->m_prev_pos^key ) ) & 3;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||
} else {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||
state->tile->m_prev_pos = ((Suffix&2))+(( (Suffix&1) + ( state->tile->m_prev_pos^key)) & 1);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 2, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 2);
|
||||
}
|
||||
}
|
||||
} else
|
||||
if(r_param==3) {
|
||||
if( base_level ==1) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 7;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||
}
|
||||
else if( base_level ==2) {
|
||||
if(codeNumber<=15 || codeNumber>23) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 7;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||
} else
|
||||
if(codeNumber<=19){
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||
state->tile->m_prev_pos = ((Suffix&4))+(( (Suffix&3) + (state->tile->m_prev_pos^key )) & 3);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||
} else
|
||||
if(codeNumber<=21){
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||
state->tile->m_prev_pos = 4+(( (Suffix&1) + ( state->tile->m_prev_pos^key )) & 1);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||
} else
|
||||
CABAC_BINS_EP(cabac, Suffix, 3, "coeff_abs_level_remaining");
|
||||
// m_pcBinIf->encodeBinsEP(Suffix, 3);
|
||||
} else {//base_level=3
|
||||
CABAC_BINS_EP(cabac, Suffix, 3, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(Suffix, 3);
|
||||
if(codeNumber<=15 || codeNumber>23) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||
state->tile->m_prev_pos = (Suffix + ( state->tile->m_prev_pos^key ) ) & 7;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||
} else
|
||||
if(codeNumber<=19) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||
state->tile->m_prev_pos = (( (Suffix&3) + ( state->tile->m_prev_pos^key )) &3);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||
} else
|
||||
if(codeNumber<=23) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||
state->tile->m_prev_pos = (Suffix&6)+(( (Suffix&1) + (state->tile->m_prev_pos^key )) & 1);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 3, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 3);
|
||||
}
|
||||
}
|
||||
} else
|
||||
if(r_param==4) {
|
||||
if( base_level ==1) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 4);
|
||||
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 15;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||
} else
|
||||
if( base_level ==2) {
|
||||
if(codeNumber<=31 || codeNumber>47) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 4);
|
||||
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & 15;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, r_param, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, r_param);
|
||||
} else
|
||||
if(codeNumber<=39) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||
state->tile->m_prev_pos = (( (Suffix&7) + ( state->tile->m_prev_pos^key )) & 7);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||
} else
|
||||
if(codeNumber<=43) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||
state->tile->m_prev_pos = 8+(( (Suffix&3) + ( state->tile->m_prev_pos^key )) & 3);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||
} else
|
||||
if(codeNumber<=45){
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||
state->tile->m_prev_pos = 12+(( (Suffix&1) + ( state->tile->m_prev_pos^key )) & 1);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||
} else
|
||||
CABAC_BINS_EP(cabac, Suffix, 4, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(Suffix, 4);
|
||||
} else {//base_level=3
|
||||
if(codeNumber<=31 || codeNumber>47) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 4);
|
||||
state->tile->m_prev_pos = (Suffix + ( state->tile->m_prev_pos^key ) ) & 15;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, r_param, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, r_param);
|
||||
} else
|
||||
if(codeNumber<=39) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 3);
|
||||
state->tile->m_prev_pos = (( (Suffix&7) + ( state->tile->m_prev_pos^key )) & 7);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||
} else
|
||||
if(codeNumber<=43) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 2);
|
||||
state->tile->m_prev_pos = 8+(( (Suffix&3) + ( state->tile->m_prev_pos^key )) & 3);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||
} else
|
||||
if(codeNumber<=47) {
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, 1);
|
||||
state->tile->m_prev_pos = (Suffix&14)+(( (Suffix&1) + (state->tile->m_prev_pos^key )) & 1);
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, 4, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
length = r_param;
|
||||
codeNumber = codeNumber - ( 3 << r_param);
|
||||
while (codeNumber >= (1<<length)) {
|
||||
codeNumber -= (1<<(length));
|
||||
++length;
|
||||
}
|
||||
CABAC_BINS_EP(cabac, (1 << (3 + length + 1 - r_param)) - 2, 3 + length + 1 - r_param, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP((1<<(COEF_REMAIN_BIN_REDUCTION+length+1-r_param))-2,COEF_REMAIN_BIN_REDUCTION+length+1-r_param);
|
||||
uint32_t Suffix = codeNumber;
|
||||
uint32_t key = ff_get_key(&state->tile->dbs_g, length);
|
||||
uint32_t mask = ( (1<<length ) -1 );
|
||||
state->tile->m_prev_pos = ( Suffix + ( state->tile->m_prev_pos^key ) ) & mask;
|
||||
CABAC_BINS_EP(cabac, state->tile->m_prev_pos, length, "coeff_abs_level_remaining");
|
||||
//m_pcBinIf->encodeBinsEP(m_prev_pos,length);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* \brief
|
||||
*/
|
||||
|
@ -346,7 +539,7 @@ void kvz_cabac_write_unary_max_symbol_ep(cabac_data_t * const data, unsigned int
|
|||
/**
|
||||
* \brief
|
||||
*/
|
||||
void kvz_cabac_write_ep_ex_golomb(cabac_data_t * const data, uint32_t symbol, uint32_t count)
|
||||
void kvz_cabac_write_ep_ex_golomb(struct encoder_state_t * const state, cabac_data_t * const data, uint32_t symbol, uint32_t count)
|
||||
{
|
||||
uint32_t bins = 0;
|
||||
int32_t num_bins = 0;
|
||||
|
@ -360,8 +553,15 @@ void kvz_cabac_write_ep_ex_golomb(cabac_data_t * const data, uint32_t symbol, ui
|
|||
bins = 2 * bins;
|
||||
++num_bins;
|
||||
|
||||
bins = (bins << count) | symbol;
|
||||
bins = (bins << count) | symbol;
|
||||
num_bins += count;
|
||||
|
||||
if(!state->cabac.only_count)
|
||||
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_MVs) {
|
||||
uint32_t key, mask;
|
||||
key = ff_get_key(&state->tile->dbs_g, num_bins>>1);
|
||||
mask = ( (1<<(num_bins >>1) ) -1 );
|
||||
state->tile->m_prev_pos = ( bins + ( state->tile->m_prev_pos^key ) ) & mask;
|
||||
bins = ( (bins >> (num_bins >>1) ) << (num_bins >>1) ) | state->tile->m_prev_pos;
|
||||
}
|
||||
kvz_cabac_encode_bins_ep(data, bins, num_bins);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "bitstream.h"
|
||||
|
||||
struct encoder_state_t;
|
||||
|
||||
// Types
|
||||
typedef struct
|
||||
|
@ -103,8 +104,10 @@ void kvz_cabac_finish(cabac_data_t *data);
|
|||
void kvz_cabac_flush(cabac_data_t *data);
|
||||
void kvz_cabac_write_coeff_remain(cabac_data_t *cabac, uint32_t symbol,
|
||||
uint32_t r_param);
|
||||
void kvz_cabac_write_ep_ex_golomb(cabac_data_t *data, uint32_t symbol,
|
||||
uint32_t count);
|
||||
void kvz_cabac_write_coeff_remain_encry(struct encoder_state_t * const state, cabac_data_t * const cabac, const uint32_t symbol,
|
||||
const uint32_t r_param, int32_t base_level);
|
||||
void kvz_cabac_write_ep_ex_golomb(struct encoder_state_t * const state, cabac_data_t *data,
|
||||
uint32_t symbol, uint32_t count);
|
||||
void kvz_cabac_write_unary_max_symbol(cabac_data_t *data, cabac_ctx_t *ctx,
|
||||
uint32_t symbol, int32_t offset,
|
||||
uint32_t max_symbol);
|
||||
|
|
63
src/cfg.c
63
src/cfg.c
|
@ -107,6 +107,7 @@ int kvz_config_init(kvz_config *cfg)
|
|||
cfg->calc_psnr = true;
|
||||
|
||||
cfg->mv_constraint = KVZ_MV_CONSTRAIN_NONE;
|
||||
cfg->crypto_features = KVZ_CRYPTO_OFF;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -137,11 +138,11 @@ static int atobool(const char *str)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int parse_enum(const char *arg, const char * const *names, int8_t *dst)
|
||||
static int parse_enum_n(const char *arg, unsigned num_chars, const char * const *names, int8_t *dst)
|
||||
{
|
||||
int8_t i;
|
||||
for (i = 0; names[i]; i++) {
|
||||
if (!strcmp(arg, names[i])) {
|
||||
if (!strncmp(arg, names[i], num_chars)) {
|
||||
*dst = i;
|
||||
return 1;
|
||||
}
|
||||
|
@ -150,6 +151,11 @@ static int parse_enum(const char *arg, const char * const *names, int8_t *dst)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int parse_enum(const char *arg, const char * const *names, int8_t *dst)
|
||||
{
|
||||
return parse_enum_n(arg, 255, names, dst);
|
||||
}
|
||||
|
||||
static int parse_tiles_specification(const char* const arg, int32_t * const ntiles, int32_t** const array) {
|
||||
const char* current_arg = NULL;
|
||||
int32_t current_value;
|
||||
|
@ -289,6 +295,8 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
|
|||
static const char * const hash_names[] = { "none", "checksum", "md5", NULL };
|
||||
|
||||
static const char * const cu_split_termination_names[] = { "zero", "off", NULL };
|
||||
static const char * const crypto_toggle_names[] = { "off", "on", NULL };
|
||||
static const char * const crypto_feature_names[] = { "mvs", "mv_signs", "trans_coeffs", "trans_coeff_signs", NULL };
|
||||
|
||||
static const char * const preset_values[11][32] = {
|
||||
{
|
||||
|
@ -838,6 +846,57 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
|
|||
cfg->cu_split_termination = mode;
|
||||
return result;
|
||||
}
|
||||
else if OPT("crypto")
|
||||
{
|
||||
// on, off, feature1+feature2
|
||||
|
||||
const char *token_begin = value;
|
||||
const char *cur = token_begin;
|
||||
|
||||
cfg->crypto_features = KVZ_CRYPTO_OFF;
|
||||
|
||||
// If value is on or off, set all features to on or off.
|
||||
int8_t toggle = 0;
|
||||
if (parse_enum(token_begin, crypto_toggle_names, &toggle)) {
|
||||
if (toggle == 1) {
|
||||
cfg->crypto_features = KVZ_CRYPTO_ON;
|
||||
}
|
||||
} else {
|
||||
// Try and parse "feature1+feature2" type list.
|
||||
for (;;) {
|
||||
if (*cur == '+' || *cur == '\0') {
|
||||
int8_t feature = 0;
|
||||
int num_chars = cur - token_begin;
|
||||
if (parse_enum_n(token_begin, num_chars, crypto_feature_names, &feature)) {
|
||||
cfg->crypto_features |= (1 << feature);
|
||||
} else {
|
||||
cfg->crypto_features = KVZ_CRYPTO_OFF;
|
||||
return 0;
|
||||
}
|
||||
token_begin = cur + 1;
|
||||
}
|
||||
|
||||
if (*cur == '\0') {
|
||||
break;
|
||||
} else {
|
||||
++cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Disallow turning on the encryption when it's not compiled in.
|
||||
bool encryption_compiled_in = false;
|
||||
#ifdef KVZ_SEL_ENCRYPTION
|
||||
encryption_compiled_in = true;
|
||||
#endif
|
||||
if (!encryption_compiled_in && cfg->crypto_features) {
|
||||
fprintf(stderr, "--crypto cannot be enabled because it's not compiled in.\n");
|
||||
cfg->crypto_features = KVZ_CRYPTO_OFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
#undef OPT
|
||||
|
|
|
@ -106,6 +106,7 @@ static const struct option long_options[] = {
|
|||
{ "mv-constraint", required_argument, NULL, 0 },
|
||||
{ "hash", required_argument, NULL, 0 },
|
||||
{"cu-split-termination",required_argument, NULL, 0 },
|
||||
{ "crypto", required_argument, NULL, 0 },
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
|
|
@ -104,8 +104,14 @@ static int encoder_state_config_tile_init(encoder_state_t * const state,
|
|||
} else {
|
||||
state->tile->wf_jobs = NULL;
|
||||
}
|
||||
|
||||
state->tile->id = encoder->tiles_tile_id[state->tile->lcu_offset_in_ts];
|
||||
|
||||
state->tile->dbs_g = NULL;
|
||||
if (state->encoder_control->cfg->crypto_features) {
|
||||
state->tile->dbs_g = InitC();
|
||||
}
|
||||
state->tile->m_prev_pos = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -117,7 +123,9 @@ static void encoder_state_config_tile_finalize(encoder_state_t * const state) {
|
|||
|
||||
kvz_videoframe_free(state->tile->frame);
|
||||
state->tile->frame = NULL;
|
||||
|
||||
if (state->encoder_control->cfg->crypto_features) {
|
||||
DeleteCryptoC(state->tile->dbs_g);
|
||||
}
|
||||
FREE_POINTER(state->tile->wf_jobs);
|
||||
}
|
||||
|
||||
|
|
|
@ -1186,6 +1186,7 @@ static void encode_inter_prediction_unit(encoder_state_t * const state,
|
|||
const uint32_t mvd_hor_abs = abs(mvd_hor);
|
||||
const uint32_t mvd_ver_abs = abs(mvd_ver);
|
||||
|
||||
|
||||
cabac->cur_ctx = &(cabac->ctx.cu_mvd_model[0]);
|
||||
CABAC_BIN(cabac, (mvd_hor != 0), "abs_mvd_greater0_flag_hor");
|
||||
CABAC_BIN(cabac, (mvd_ver != 0), "abs_mvd_greater0_flag_ver");
|
||||
|
@ -1202,18 +1203,23 @@ static void encode_inter_prediction_unit(encoder_state_t * const state,
|
|||
|
||||
if (hor_abs_gr0) {
|
||||
if (mvd_hor_abs > 1) {
|
||||
kvz_cabac_write_ep_ex_golomb(cabac,mvd_hor_abs-2, 1);
|
||||
kvz_cabac_write_ep_ex_golomb(state, cabac, mvd_hor_abs-2, 1);
|
||||
}
|
||||
|
||||
CABAC_BIN_EP(cabac, (mvd_hor>0)?0:1, "mvd_sign_flag_hor");
|
||||
uint32_t mvd_hor_sign = (mvd_hor>0)?0:1;
|
||||
if(!state->cabac.only_count)
|
||||
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_MV_SIGNS)
|
||||
mvd_hor_sign = mvd_hor_sign^ff_get_key(&state->tile->dbs_g, 1);
|
||||
CABAC_BIN_EP(cabac, mvd_hor_sign, "mvd_sign_flag_hor");
|
||||
}
|
||||
|
||||
if (ver_abs_gr0) {
|
||||
if (mvd_ver_abs > 1) {
|
||||
kvz_cabac_write_ep_ex_golomb(cabac,mvd_ver_abs-2, 1);
|
||||
kvz_cabac_write_ep_ex_golomb(state, cabac, mvd_ver_abs-2, 1);
|
||||
}
|
||||
|
||||
CABAC_BIN_EP(cabac, (mvd_ver>0)?0:1, "mvd_sign_flag_ver");
|
||||
uint32_t mvd_ver_sign = (mvd_ver>0)?0:1;
|
||||
if(!state->cabac.only_count)
|
||||
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_MV_SIGNS)
|
||||
mvd_ver_sign = mvd_ver_sign^ff_get_key(&state->tile->dbs_g, 1);
|
||||
CABAC_BIN_EP(cabac, mvd_ver_sign, "mvd_sign_flag_ver");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1758,6 +1764,7 @@ void kvz_encode_coeff_nxn(encoder_state_t * const state, coeff_t *coeff, uint8_t
|
|||
|
||||
// Scan all coeff groups to find out which of them have coeffs.
|
||||
// Populate sig_coeffgroup_flag with that info.
|
||||
|
||||
unsigned sig_cg_cnt = 0;
|
||||
for (int cg_y = 0; cg_y < width / 4; ++cg_y) {
|
||||
for (int cg_x = 0; cg_x < width / 4; ++cg_x) {
|
||||
|
@ -1919,10 +1926,17 @@ void kvz_encode_coeff_nxn(encoder_state_t * const state, coeff_t *coeff, uint8_t
|
|||
CABAC_BIN(cabac, symbol, "coeff_abs_level_greater2_flag");
|
||||
}
|
||||
}
|
||||
|
||||
if (be_valid && sign_hidden) {
|
||||
CABAC_BINS_EP(cabac, (coeff_signs >> 1), (num_non_zero - 1), "coeff_sign_flag");
|
||||
coeff_signs = coeff_signs >> 1;
|
||||
if(!state->cabac.only_count)
|
||||
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_TRANSF_COEFF_SIGNS) {
|
||||
coeff_signs = coeff_signs ^ ff_get_key(&state->tile->dbs_g, num_non_zero-1);
|
||||
}
|
||||
CABAC_BINS_EP(cabac, coeff_signs , (num_non_zero - 1), "coeff_sign_flag");
|
||||
} else {
|
||||
if(!state->cabac.only_count)
|
||||
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_TRANSF_COEFF_SIGNS)
|
||||
coeff_signs = coeff_signs ^ ff_get_key(&state->tile->dbs_g, num_non_zero);
|
||||
CABAC_BINS_EP(cabac, coeff_signs, num_non_zero, "coeff_sign_flag");
|
||||
}
|
||||
|
||||
|
@ -1933,7 +1947,13 @@ void kvz_encode_coeff_nxn(encoder_state_t * const state, coeff_t *coeff, uint8_t
|
|||
int32_t base_level = (idx < C1FLAG_NUMBER) ? (2 + first_coeff2) : 1;
|
||||
|
||||
if (abs_coeff[idx] >= base_level) {
|
||||
kvz_cabac_write_coeff_remain(cabac, abs_coeff[idx] - base_level, go_rice_param);
|
||||
if(!state->cabac.only_count) {
|
||||
if (state->encoder_control->cfg->crypto_features & KVZ_CRYPTO_TRANSF_COEFFS)
|
||||
kvz_cabac_write_coeff_remain_encry(state, cabac, abs_coeff[idx] - base_level, go_rice_param, base_level);
|
||||
else
|
||||
kvz_cabac_write_coeff_remain(cabac, abs_coeff[idx] - base_level, go_rice_param);
|
||||
} else
|
||||
kvz_cabac_write_coeff_remain(cabac, abs_coeff[idx] - base_level, go_rice_param);
|
||||
|
||||
if (abs_coeff[idx] > 3 * (1 << go_rice_param)) {
|
||||
go_rice_param = MIN(go_rice_param + 1, 4);
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "tables.h"
|
||||
#include "threadqueue.h"
|
||||
#include "videoframe.h"
|
||||
#include "extras/crypto.h"
|
||||
|
||||
|
||||
typedef enum {
|
||||
|
@ -113,6 +114,11 @@ typedef struct {
|
|||
|
||||
//Jobs for each individual LCU of a wavefront row.
|
||||
threadqueue_job_t **wf_jobs;
|
||||
|
||||
// Instance of encryption generator by tile
|
||||
Crypto_Handle dbs_g;
|
||||
uint32_t m_prev_pos;
|
||||
|
||||
} encoder_state_config_tile_t;
|
||||
|
||||
typedef struct {
|
||||
|
|
126
src/extras/crypto.cpp
Normal file
126
src/extras/crypto.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
#include <extras/crypto.h>
|
||||
|
||||
#ifndef KVZ_SEL_ENCRYPTION
|
||||
extern int kvz_make_vs_ignore_crypto_not_having_symbols;
|
||||
int kvz_make_vs_ignore_crypto_not_having_symbols = 0;
|
||||
#else
|
||||
#include <cryptopp/aes.h>
|
||||
#include <cryptopp/modes.h>
|
||||
#include <cryptopp/osrng.h>
|
||||
typedef struct AESDecoder {
|
||||
#if AESEncryptionStreamMode
|
||||
CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption *CFBdec;
|
||||
#else
|
||||
CryptoPP::CFB_Mode<CryptoPP::AES>::Decryption *CFBdec;
|
||||
#endif
|
||||
|
||||
byte key[CryptoPP::AES::DEFAULT_KEYLENGTH], iv[CryptoPP::AES::BLOCKSIZE], out_stream_counter[CryptoPP::AES::BLOCKSIZE], counter[CryptoPP::AES::BLOCKSIZE];
|
||||
int couter_avail, counter_index, counter_index_pos;
|
||||
} AESDecoder;
|
||||
|
||||
|
||||
AESDecoder* Init() {
|
||||
int init_val[32] = {201, 75, 219, 152, 6, 245, 237, 107, 179, 194, 81, 29, 66, 98, 198, 0, 16, 213, 27, 56, 255, 127, 242, 112, 97, 126, 197, 204, 25, 59, 38, 30};
|
||||
AESDecoder * AESdecoder = (AESDecoder *)malloc(sizeof(AESDecoder));
|
||||
for(int i=0;i<16; i++) {
|
||||
AESdecoder->iv [i] = init_val[i];
|
||||
AESdecoder->counter[i] = init_val[5+i];
|
||||
AESdecoder->key[i] = init_val[i+16];
|
||||
}
|
||||
#if AESEncryptionStreamMode
|
||||
AESdecoder->CFBdec = new CryptoPP::CFB_Mode<CryptoPP::AES >::Encryption(AESdecoder->key, CryptoPP::AES::DEFAULT_KEYLENGTH, AESdecoder->iv);
|
||||
#else
|
||||
AESdecoder->CFBdec = new CryptoPP::CFB_Mode<CryptoPP::AES >::Decryption(AESdecoder->key, CryptoPP::AES::DEFAULT_KEYLENGTH, AESdecoder->iv);
|
||||
#endif
|
||||
AESdecoder->couter_avail = 0;
|
||||
AESdecoder->counter_index = 0;
|
||||
AESdecoder->counter_index_pos = 0;
|
||||
return AESdecoder;
|
||||
}
|
||||
|
||||
void DeleteCrypto(AESDecoder * AESdecoder) {
|
||||
if(AESdecoder)
|
||||
free(AESdecoder);
|
||||
}
|
||||
|
||||
void Decrypt(AESDecoder *AESdecoder, const unsigned char *in_stream, int size_bits, unsigned char *out_stream) {
|
||||
int nb_bytes = ceil((double)size_bits/8);
|
||||
AESdecoder->CFBdec->ProcessData(out_stream, in_stream, nb_bytes);
|
||||
if(size_bits&7)
|
||||
AESdecoder->CFBdec->SetKeyWithIV(AESdecoder->key, CryptoPP::AES::DEFAULT_KEYLENGTH, AESdecoder->iv);
|
||||
|
||||
}
|
||||
void Incr_counter (unsigned char *counter) {
|
||||
counter[0]++;
|
||||
}
|
||||
|
||||
#if AESEncryptionStreamMode
|
||||
void Decrypt_counter(AESDecoder * AESdecoder) {
|
||||
AESdecoder->CFBdec->ProcessData(AESdecoder->out_stream_counter, AESdecoder->counter, 16);
|
||||
AESdecoder->couter_avail = 128;
|
||||
AESdecoder->counter_index = 15;
|
||||
AESdecoder->counter_index_pos = 8;
|
||||
Incr_counter(AESdecoder->counter);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if AESEncryptionStreamMode
|
||||
unsigned int get_key (AESDecoder * AESdecoder, int nb_bits) {
|
||||
unsigned int key_ = 0;
|
||||
if(nb_bits > 32) {
|
||||
printf("The Generator can not generate more than 32 bit %d \n", nb_bits);
|
||||
return 0;
|
||||
}
|
||||
if( !nb_bits )
|
||||
return 0;
|
||||
if(!AESdecoder->couter_avail)
|
||||
Decrypt_counter(AESdecoder);
|
||||
|
||||
if(AESdecoder->couter_avail >= nb_bits)
|
||||
AESdecoder->couter_avail -= nb_bits;
|
||||
else
|
||||
AESdecoder->couter_avail = 0;
|
||||
int nb = 0;
|
||||
while( nb_bits ) {
|
||||
if( nb_bits >= AESdecoder->counter_index_pos )
|
||||
nb = AESdecoder->counter_index_pos;
|
||||
else
|
||||
nb = nb_bits;
|
||||
key_ <<= nb;
|
||||
key_ += (AESdecoder->out_stream_counter[AESdecoder->counter_index] & ((1<<nb)-1));
|
||||
AESdecoder->out_stream_counter[AESdecoder->counter_index] >>= nb;
|
||||
nb_bits -= nb;
|
||||
|
||||
if(AESdecoder->counter_index && nb == AESdecoder->counter_index_pos ) {
|
||||
AESdecoder->counter_index--;
|
||||
AESdecoder->counter_index_pos = 8;
|
||||
} else {
|
||||
AESdecoder->counter_index_pos -= nb;
|
||||
if(nb_bits) {
|
||||
Decrypt_counter(AESdecoder);
|
||||
AESdecoder->couter_avail -= nb_bits;
|
||||
}
|
||||
}
|
||||
}
|
||||
return key_;
|
||||
}
|
||||
#endif
|
||||
|
||||
Crypto_Handle InitC(){
|
||||
AESDecoder* AESdecoder = Init();
|
||||
return AESdecoder;
|
||||
}
|
||||
#if AESEncryptionStreamMode
|
||||
unsigned int ff_get_key (Crypto_Handle *hdl, int nb_bits) {
|
||||
return get_key ((AESDecoder*)*hdl, nb_bits);
|
||||
}
|
||||
#endif
|
||||
void DecryptC(Crypto_Handle hdl, const unsigned char *in_stream, int size_bits, unsigned char *out_stream) {
|
||||
Decrypt((AESDecoder*)hdl, in_stream, size_bits, out_stream);
|
||||
}
|
||||
|
||||
void DeleteCryptoC(Crypto_Handle hdl) {
|
||||
DeleteCrypto((AESDecoder *)hdl);
|
||||
}
|
||||
|
||||
#endif // KVZ_SEL_ENCRYPTION
|
72
src/extras/crypto.h
Normal file
72
src/extras/crypto.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
#ifndef CRYPTO_H_
|
||||
#define CRYPTO_H_
|
||||
|
||||
#include "global.h"
|
||||
|
||||
#ifdef KVZ_SEL_ENCRYPTION
|
||||
#define STUBBED extern
|
||||
#else
|
||||
#define STUBBED static
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#define AESEncryptionStreamMode 1
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef void* Crypto_Handle;
|
||||
|
||||
STUBBED Crypto_Handle InitC();
|
||||
STUBBED void DecryptC(Crypto_Handle hdl, const unsigned char *in_stream, int size_bits, unsigned char *out_stream);
|
||||
#if AESEncryptionStreamMode
|
||||
STUBBED unsigned int ff_get_key(Crypto_Handle *hdl, int nb_bits);
|
||||
#endif
|
||||
STUBBED void DeleteCryptoC(Crypto_Handle hdl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef KVZ_SEL_ENCRYPTION
|
||||
// Provide static stubs to allow linking without libcryptopp and allows us to
|
||||
// avoid sprinkling ifdefs everywhere and having a bunch of code that's not
|
||||
// compiled during normal development.
|
||||
// Provide them in the header so we can avoid compiling the cpp file, which
|
||||
// means we don't need a C++ compiler when crypto is not enabled.
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static INLINE Crypto_Handle InitC()
|
||||
{
|
||||
// Stub.
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static INLINE void DecryptC(Crypto_Handle hdl, const unsigned char *in_stream,
|
||||
int size_bits, unsigned char *out_stream)
|
||||
{
|
||||
// Stub.
|
||||
assert(0);
|
||||
}
|
||||
|
||||
#if AESEncryptionStreamMode
|
||||
static INLINE unsigned int ff_get_key(Crypto_Handle *hdl, int nb_bits)
|
||||
{
|
||||
// Stub.
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static INLINE void DeleteCryptoC(Crypto_Handle hdl)
|
||||
{
|
||||
// Stub.
|
||||
assert(0);
|
||||
}
|
||||
|
||||
#endif // KVZ_SEL_ENCRYPTION
|
||||
|
||||
#endif // CRYPTO_H_
|
|
@ -138,6 +138,19 @@ enum kvz_cu_split_termination
|
|||
KVZ_CU_SPLIT_TERMINATION_OFF = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Enable and disable crypto features.
|
||||
* \since 3.7.0
|
||||
*/
|
||||
enum kvz_crypto_features {
|
||||
KVZ_CRYPTO_OFF = 0,
|
||||
KVZ_CRYPTO_MVs = (1 << 0),
|
||||
KVZ_CRYPTO_MV_SIGNS = (1 << 1),
|
||||
KVZ_CRYPTO_TRANSF_COEFFS = (1 << 2),
|
||||
KVZ_CRYPTO_TRANSF_COEFF_SIGNS = (1 << 3),
|
||||
KVZ_CRYPTO_ON = (1 << 4) - 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief GoP picture configuration.
|
||||
*/
|
||||
|
@ -247,6 +260,7 @@ typedef struct kvz_config
|
|||
|
||||
enum kvz_cu_split_termination cu_split_termination; /*!< \brief Mode of cu split termination. */
|
||||
|
||||
enum kvz_crypto_features crypto_features; /*!< \since 3.7.0 */
|
||||
} kvz_config;
|
||||
|
||||
/**
|
||||
|
|
16
src/rdo.c
16
src/rdo.c
|
@ -895,7 +895,7 @@ void kvz_rdoq(encoder_state_t * const state, coeff_t *coef, coeff_t *dest_coeff
|
|||
* \returns int
|
||||
* Calculates cost of actual motion vectors using CABAC coding
|
||||
*/
|
||||
uint32_t kvz_get_mvd_coding_cost_cabac(vector2d_t *mvd, cabac_data_t* cabac) {
|
||||
uint32_t kvz_get_mvd_coding_cost_cabac(encoder_state_t * const state, vector2d_t *mvd, cabac_data_t* cabac) {
|
||||
uint32_t bitcost = 0;
|
||||
const int32_t mvd_hor = mvd->x;
|
||||
const int32_t mvd_ver = mvd->y;
|
||||
|
@ -920,13 +920,13 @@ uint32_t kvz_get_mvd_coding_cost_cabac(vector2d_t *mvd, cabac_data_t* cabac) {
|
|||
}
|
||||
if (hor_abs_gr0) {
|
||||
if (mvd_hor_abs > 1) {
|
||||
kvz_cabac_write_ep_ex_golomb(cabac, mvd_hor_abs - 2, 1);
|
||||
kvz_cabac_write_ep_ex_golomb(state, cabac, mvd_hor_abs - 2, 1);
|
||||
}
|
||||
CABAC_BIN_EP(cabac, (mvd_hor > 0) ? 0 : 1, "mvd_sign_flag_hor");
|
||||
}
|
||||
if (ver_abs_gr0) {
|
||||
if (mvd_ver_abs > 1) {
|
||||
kvz_cabac_write_ep_ex_golomb(cabac, mvd_ver_abs - 2, 1);
|
||||
kvz_cabac_write_ep_ex_golomb(state, cabac, mvd_ver_abs - 2, 1);
|
||||
}
|
||||
CABAC_BIN_EP(cabac, (mvd_ver > 0) ? 0 : 1, "mvd_sign_flag_ver");
|
||||
}
|
||||
|
@ -941,7 +941,7 @@ uint32_t kvz_get_mvd_coding_cost_cabac(vector2d_t *mvd, cabac_data_t* cabac) {
|
|||
* \returns int
|
||||
* Calculates Motion Vector cost and related costs using CABAC coding
|
||||
*/
|
||||
int kvz_calc_mvd_cost_cabac(const encoder_state_t * const state, int x, int y, int mv_shift,
|
||||
int kvz_calc_mvd_cost_cabac(encoder_state_t * const state, int x, int y, int mv_shift,
|
||||
int16_t mv_cand[2][2], inter_merge_cand_t merge_cand[MRG_MAX_NUM_CANDS],
|
||||
int16_t num_cand, int32_t ref_idx, uint32_t *bitcost) {
|
||||
|
||||
|
@ -980,11 +980,11 @@ int kvz_calc_mvd_cost_cabac(const encoder_state_t * const state, int x, int y, i
|
|||
if (!merged) {
|
||||
mvd_temp1.x = x - mv_cand[0][0];
|
||||
mvd_temp1.y = y - mv_cand[0][1];
|
||||
cand1_cost = kvz_get_mvd_coding_cost_cabac(&mvd_temp1, cabac);
|
||||
cand1_cost = kvz_get_mvd_coding_cost_cabac(state, &mvd_temp1, cabac);
|
||||
|
||||
mvd_temp2.x = x - mv_cand[1][0];
|
||||
mvd_temp2.y = y - mv_cand[1][1];
|
||||
cand2_cost = kvz_get_mvd_coding_cost_cabac(&mvd_temp2, cabac);
|
||||
cand2_cost = kvz_get_mvd_coding_cost_cabac(state, &mvd_temp2, cabac);
|
||||
|
||||
// Select candidate 1 if it has lower cost
|
||||
if (cand2_cost < cand1_cost) {
|
||||
|
@ -1080,7 +1080,7 @@ int kvz_calc_mvd_cost_cabac(const encoder_state_t * const state, int x, int y, i
|
|||
|
||||
if (hor_abs_gr0) {
|
||||
if (mvd_hor_abs > 1) {
|
||||
kvz_cabac_write_ep_ex_golomb(cabac, mvd_hor_abs - 2, 1);
|
||||
kvz_cabac_write_ep_ex_golomb(state, cabac, mvd_hor_abs - 2, 1);
|
||||
}
|
||||
|
||||
CABAC_BIN_EP(cabac, (mvd_hor > 0) ? 0 : 1, "mvd_sign_flag_hor");
|
||||
|
@ -1088,7 +1088,7 @@ int kvz_calc_mvd_cost_cabac(const encoder_state_t * const state, int x, int y, i
|
|||
|
||||
if (ver_abs_gr0) {
|
||||
if (mvd_ver_abs > 1) {
|
||||
kvz_cabac_write_ep_ex_golomb(cabac, mvd_ver_abs - 2, 1);
|
||||
kvz_cabac_write_ep_ex_golomb(state, cabac, mvd_ver_abs - 2, 1);
|
||||
}
|
||||
|
||||
CABAC_BIN_EP(cabac, (mvd_ver > 0) ? 0 : 1, "mvd_sign_flag_ver");
|
||||
|
|
|
@ -55,10 +55,10 @@ uint32_t kvz_get_coded_level(encoder_state_t * state, double* coded_cost, double
|
|||
uint32_t c1_idx, uint32_t c2_idx,
|
||||
int32_t q_bits,double temp, int8_t last, int8_t type);
|
||||
|
||||
int kvz_calc_mvd_cost_cabac(const encoder_state_t * const state, int x, int y, int mv_shift,
|
||||
int kvz_calc_mvd_cost_cabac(encoder_state_t * const state, int x, int y, int mv_shift,
|
||||
int16_t mv_cand[2][2], inter_merge_cand_t merge_cand[MRG_MAX_NUM_CANDS],
|
||||
int16_t num_cand, int32_t ref_idx, uint32_t *bitcost);
|
||||
uint32_t kvz_get_mvd_coding_cost_cabac(vector2d_t *mvd, cabac_data_t* cabac);
|
||||
uint32_t kvz_get_mvd_coding_cost_cabac(encoder_state_t * const state, vector2d_t *mvd, cabac_data_t* cabac);
|
||||
|
||||
extern const float kvz_f_entropy_bits[128];
|
||||
#define CTX_ENTROPY_FBITS(ctx,val) kvz_f_entropy_bits[(ctx)->uc_state ^ (val)]
|
||||
|
|
|
@ -134,10 +134,10 @@ static bool mv_in_merge(const inter_merge_cand_t* merge_cand, int16_t num_cand,
|
|||
}
|
||||
|
||||
|
||||
static unsigned select_starting_point(int16_t num_cand, inter_merge_cand_t *merge_cand, vector2d_t *mv_in_out, vector2d_t *mv, const encoder_state_t *const state,
|
||||
static unsigned select_starting_point(int16_t num_cand, inter_merge_cand_t *merge_cand, vector2d_t *mv_in_out, vector2d_t *mv, encoder_state_t *const state,
|
||||
const vector2d_t *orig, unsigned width, unsigned height, int wpp_limit, const kvz_picture *pic, const kvz_picture *ref,
|
||||
int16_t mv_cand[2][2], int32_t ref_idx, unsigned best_cost, unsigned *best_index, uint32_t *best_bitcost,
|
||||
int(*calc_mvd)(const encoder_state_t * const, int, int, int, int16_t[2][2], inter_merge_cand_t[MRG_MAX_NUM_CANDS],
|
||||
int(*calc_mvd)(encoder_state_t * const, int, int, int, int16_t[2][2], inter_merge_cand_t[MRG_MAX_NUM_CANDS],
|
||||
int16_t, int32_t, uint32_t *)){
|
||||
// Go through candidates
|
||||
for (unsigned i = 0; i < num_cand; ++i) {
|
||||
|
@ -177,7 +177,7 @@ static unsigned select_starting_point(int16_t num_cand, inter_merge_cand_t *merg
|
|||
}
|
||||
|
||||
|
||||
static uint32_t get_mvd_coding_cost(vector2d_t *mvd, cabac_data_t* cabac)
|
||||
static uint32_t get_mvd_coding_cost(encoder_state_t * const state, vector2d_t *mvd, cabac_data_t* cabac)
|
||||
{
|
||||
uint32_t bitcost = 0;
|
||||
const int32_t mvd_hor = mvd->x;
|
||||
|
@ -210,7 +210,7 @@ static uint32_t get_mvd_coding_cost(vector2d_t *mvd, cabac_data_t* cabac)
|
|||
}
|
||||
|
||||
|
||||
static int calc_mvd_cost(const encoder_state_t * const state, int x, int y, int mv_shift,
|
||||
static int calc_mvd_cost(encoder_state_t * const state, int x, int y, int mv_shift,
|
||||
int16_t mv_cand[2][2], inter_merge_cand_t merge_cand[MRG_MAX_NUM_CANDS],
|
||||
int16_t num_cand,int32_t ref_idx, uint32_t *bitcost)
|
||||
{
|
||||
|
@ -240,11 +240,11 @@ static int calc_mvd_cost(const encoder_state_t * const state, int x, int y, int
|
|||
if(!merged) {
|
||||
mvd_temp1.x = x - mv_cand[0][0];
|
||||
mvd_temp1.y = y - mv_cand[0][1];
|
||||
cand1_cost = get_mvd_coding_cost(&mvd_temp1, NULL);
|
||||
cand1_cost = get_mvd_coding_cost(state, &mvd_temp1, NULL);
|
||||
|
||||
mvd_temp2.x = x - mv_cand[1][0];
|
||||
mvd_temp2.y = y - mv_cand[1][1];
|
||||
cand2_cost = get_mvd_coding_cost(&mvd_temp2, NULL);
|
||||
cand2_cost = get_mvd_coding_cost(state, &mvd_temp2, NULL);
|
||||
|
||||
// Select candidate 1 if it has lower cost
|
||||
if (cand2_cost < cand1_cost) {
|
||||
|
@ -257,7 +257,7 @@ static int calc_mvd_cost(const encoder_state_t * const state, int x, int y, int
|
|||
}
|
||||
|
||||
|
||||
unsigned kvz_tz_pattern_search(const encoder_state_t * const state, const kvz_picture *pic, const kvz_picture *ref, unsigned pattern_type,
|
||||
unsigned kvz_tz_pattern_search(encoder_state_t * const state, const kvz_picture *pic, const kvz_picture *ref, unsigned pattern_type,
|
||||
const vector2d_t *orig, const int iDist, vector2d_t *mv, unsigned best_cost, int *best_dist,
|
||||
int16_t mv_cand[2][2], inter_merge_cand_t merge_cand[MRG_MAX_NUM_CANDS], int16_t num_cand, int32_t ref_idx, uint32_t *best_bitcost,
|
||||
int width, int height, int wpp_limit)
|
||||
|
@ -269,7 +269,7 @@ unsigned kvz_tz_pattern_search(const encoder_state_t * const state, const kvz_pi
|
|||
vector2d_t mv_best = { 0, 0 };
|
||||
|
||||
|
||||
int(*calc_mvd)(const encoder_state_t * const, int, int, int,
|
||||
int(*calc_mvd)(encoder_state_t * const, int, int, int,
|
||||
int16_t[2][2], inter_merge_cand_t[MRG_MAX_NUM_CANDS],
|
||||
int16_t, int32_t, uint32_t *) = calc_mvd_cost;
|
||||
if (state->encoder_control->cfg->mv_rdo) {
|
||||
|
@ -416,7 +416,7 @@ unsigned kvz_tz_pattern_search(const encoder_state_t * const state, const kvz_pi
|
|||
}
|
||||
|
||||
|
||||
unsigned kvz_tz_raster_search(const encoder_state_t * const state, const kvz_picture *pic, const kvz_picture *ref,
|
||||
unsigned kvz_tz_raster_search(encoder_state_t * const state, const kvz_picture *pic, const kvz_picture *ref,
|
||||
const vector2d_t *orig, vector2d_t *mv, unsigned best_cost,
|
||||
int16_t mv_cand[2][2], inter_merge_cand_t merge_cand[MRG_MAX_NUM_CANDS], int16_t num_cand, int32_t ref_idx, uint32_t *best_bitcost,
|
||||
int width, int height, int iSearchRange, int iRaster, int wpp_limit)
|
||||
|
@ -426,7 +426,7 @@ unsigned kvz_tz_raster_search(const encoder_state_t * const state, const kvz_pic
|
|||
|
||||
vector2d_t mv_best = { 0, 0 };
|
||||
|
||||
int(*calc_mvd)(const encoder_state_t * const, int, int, int,
|
||||
int(*calc_mvd)(encoder_state_t * const, int, int, int,
|
||||
int16_t[2][2], inter_merge_cand_t[MRG_MAX_NUM_CANDS],
|
||||
int16_t, int32_t, uint32_t *) = calc_mvd_cost;
|
||||
if (state->encoder_control->cfg->mv_rdo) {
|
||||
|
@ -472,7 +472,7 @@ unsigned kvz_tz_raster_search(const encoder_state_t * const state, const kvz_pic
|
|||
}
|
||||
|
||||
|
||||
static unsigned tz_search(const encoder_state_t * const state,
|
||||
static unsigned tz_search(encoder_state_t * const state,
|
||||
unsigned width, unsigned height,
|
||||
const kvz_picture *pic, const kvz_picture *ref,
|
||||
const vector2d_t *orig, vector2d_t *mv_in_out,
|
||||
|
@ -497,7 +497,7 @@ static unsigned tz_search(const encoder_state_t * const state,
|
|||
unsigned best_index = num_cand + 1;
|
||||
int wpp_limit = get_wpp_limit(state, orig);
|
||||
|
||||
int(*calc_mvd)(const encoder_state_t * const, int, int, int,
|
||||
int(*calc_mvd)(encoder_state_t * const, int, int, int,
|
||||
int16_t[2][2], inter_merge_cand_t[MRG_MAX_NUM_CANDS],
|
||||
int16_t, int32_t, uint32_t *) = calc_mvd_cost;
|
||||
if (state->encoder_control->cfg->mv_rdo) {
|
||||
|
@ -608,7 +608,7 @@ static unsigned tz_search(const encoder_state_t * const state,
|
|||
* the predicted motion vector is way off. In the future even more additional
|
||||
* points like 0,0 might be used, such as vectors from top or left.
|
||||
*/
|
||||
static unsigned hexagon_search(const encoder_state_t * const state,
|
||||
static unsigned hexagon_search(encoder_state_t * const state,
|
||||
unsigned width, unsigned height,
|
||||
const kvz_picture *pic, const kvz_picture *ref,
|
||||
const vector2d_t *orig, vector2d_t *mv_in_out,
|
||||
|
@ -645,7 +645,7 @@ static unsigned hexagon_search(const encoder_state_t * const state,
|
|||
unsigned best_index = num_cand + 1;
|
||||
int wpp_limit = get_wpp_limit(state, orig);
|
||||
|
||||
int (*calc_mvd)(const encoder_state_t * const, int, int, int,
|
||||
int (*calc_mvd)(encoder_state_t * const, int, int, int,
|
||||
int16_t[2][2], inter_merge_cand_t[MRG_MAX_NUM_CANDS],
|
||||
int16_t, int32_t, uint32_t *) = calc_mvd_cost;
|
||||
if (state->encoder_control->cfg->mv_rdo) {
|
||||
|
@ -783,7 +783,7 @@ static unsigned hexagon_search(const encoder_state_t * const state,
|
|||
}
|
||||
|
||||
|
||||
static unsigned search_mv_full(const encoder_state_t * const state,
|
||||
static unsigned search_mv_full(encoder_state_t * const state,
|
||||
unsigned width, unsigned height,
|
||||
const kvz_picture *pic, const kvz_picture *ref,
|
||||
const vector2d_t *orig, vector2d_t *mv_in_out,
|
||||
|
@ -796,7 +796,7 @@ static unsigned search_mv_full(const encoder_state_t * const state,
|
|||
uint32_t best_bitcost = 0, bitcost;
|
||||
int wpp_limit = get_wpp_limit(state, orig);
|
||||
|
||||
int (*calc_mvd)(const encoder_state_t * const, int, int, int,
|
||||
int (*calc_mvd)(encoder_state_t * const, int, int, int,
|
||||
int16_t[2][2], inter_merge_cand_t[MRG_MAX_NUM_CANDS],
|
||||
int16_t, int32_t, uint32_t *) = calc_mvd_cost;
|
||||
if (state->encoder_control->cfg->mv_rdo) {
|
||||
|
@ -933,7 +933,7 @@ static unsigned search_mv_full(const encoder_state_t * const state,
|
|||
* Algoritm first searches 1/2-pel positions around integer mv and after best match is found,
|
||||
* refines the search by searching best 1/4-pel postion around best 1/2-pel position.
|
||||
*/
|
||||
static unsigned search_frac(const encoder_state_t * const state,
|
||||
static unsigned search_frac(encoder_state_t * const state,
|
||||
unsigned width, unsigned height,
|
||||
const kvz_picture *pic, const kvz_picture *ref,
|
||||
const vector2d_t *orig, vector2d_t *mv_in_out,
|
||||
|
@ -973,7 +973,7 @@ static unsigned search_frac(const encoder_state_t * const state,
|
|||
kvz_pixel dst[(LCU_WIDTH+1) * (LCU_WIDTH+1) * 16];
|
||||
kvz_pixel* dst_off = &dst[dst_stride*4+4];
|
||||
|
||||
int(*calc_mvd)(const encoder_state_t * const, int, int, int,
|
||||
int(*calc_mvd)(encoder_state_t * const, int, int, int,
|
||||
int16_t[2][2], inter_merge_cand_t[MRG_MAX_NUM_CANDS],
|
||||
int16_t, int32_t, uint32_t *) = calc_mvd_cost;
|
||||
if (state->encoder_control->cfg->mv_rdo) {
|
||||
|
@ -1083,7 +1083,7 @@ static unsigned search_frac(const encoder_state_t * const state,
|
|||
/**
|
||||
* \brief Perform inter search for a single reference frame.
|
||||
*/
|
||||
static void search_pu_inter_ref(const encoder_state_t * const state,
|
||||
static void search_pu_inter_ref(encoder_state_t * const state,
|
||||
int x, int y,
|
||||
int width, int height,
|
||||
int depth,
|
||||
|
@ -1092,7 +1092,7 @@ static void search_pu_inter_ref(const encoder_state_t * const state,
|
|||
inter_merge_cand_t merge_cand[MRG_MAX_NUM_CANDS],
|
||||
int16_t num_cand,
|
||||
unsigned ref_idx,
|
||||
uint32_t(*get_mvd_cost)(vector2d_t *, cabac_data_t*))
|
||||
uint32_t(*get_mvd_cost)(encoder_state_t * const, vector2d_t *, cabac_data_t*))
|
||||
{
|
||||
const int x_cu = x >> 3;
|
||||
const int y_cu = y >> 3;
|
||||
|
@ -1234,11 +1234,11 @@ static void search_pu_inter_ref(const encoder_state_t * const state,
|
|||
|
||||
mvd_temp1.x = mv.x - mv_cand[0][0];
|
||||
mvd_temp1.y = mv.y - mv_cand[0][1];
|
||||
cand1_cost = get_mvd_cost(&mvd_temp1, (cabac_data_t*)&state->cabac);
|
||||
cand1_cost = get_mvd_cost(state, &mvd_temp1, (cabac_data_t*)&state->cabac);
|
||||
|
||||
mvd_temp2.x = mv.x - mv_cand[1][0];
|
||||
mvd_temp2.y = mv.y - mv_cand[1][1];
|
||||
cand2_cost = get_mvd_cost(&mvd_temp2, (cabac_data_t*)&state->cabac);
|
||||
cand2_cost = get_mvd_cost(state, &mvd_temp2, (cabac_data_t*)&state->cabac);
|
||||
|
||||
// Select candidate 1 if it has lower cost
|
||||
if (cand2_cost < cand1_cost) {
|
||||
|
@ -1281,7 +1281,7 @@ static void search_pu_inter_ref(const encoder_state_t * const state,
|
|||
*
|
||||
* \return cost of the best mode
|
||||
*/
|
||||
static int search_pu_inter(const encoder_state_t * const state,
|
||||
static int search_pu_inter(encoder_state_t * const state,
|
||||
int x_cu, int y_cu,
|
||||
int depth,
|
||||
part_mode_t part_mode,
|
||||
|
@ -1317,7 +1317,7 @@ static int search_pu_inter(const encoder_state_t * const state,
|
|||
merge_cand,
|
||||
lcu);
|
||||
|
||||
uint32_t(*get_mvd_cost)(vector2d_t *, cabac_data_t*) = get_mvd_coding_cost;
|
||||
uint32_t(*get_mvd_cost)(encoder_state_t * const state, vector2d_t *, cabac_data_t*) = get_mvd_coding_cost;
|
||||
if (state->encoder_control->cfg->mv_rdo) {
|
||||
get_mvd_cost = kvz_get_mvd_coding_cost_cabac;
|
||||
}
|
||||
|
@ -1363,7 +1363,7 @@ static int search_pu_inter(const encoder_state_t * const state,
|
|||
uint8_t cutoff = num_cand;
|
||||
|
||||
|
||||
int(*calc_mvd)(const encoder_state_t * const, int, int, int,
|
||||
int(*calc_mvd)(encoder_state_t * const, int, int, int,
|
||||
int16_t[2][2], inter_merge_cand_t[MRG_MAX_NUM_CANDS],
|
||||
int16_t, int32_t, uint32_t *) = calc_mvd_cost;
|
||||
if (state->encoder_control->cfg->mv_rdo) {
|
||||
|
@ -1469,11 +1469,11 @@ static int search_pu_inter(const encoder_state_t * const state,
|
|||
|
||||
mvd_temp1.x = cur_cu->inter.mv[reflist][0] - mv_cand[0][0];
|
||||
mvd_temp1.y = cur_cu->inter.mv[reflist][1] - mv_cand[0][1];
|
||||
cand1_cost = get_mvd_cost(&mvd_temp1, (cabac_data_t*)&state->cabac);
|
||||
cand1_cost = get_mvd_cost(state, &mvd_temp1, (cabac_data_t*)&state->cabac);
|
||||
|
||||
mvd_temp2.x = cur_cu->inter.mv[reflist][0] - mv_cand[1][0];
|
||||
mvd_temp2.y = cur_cu->inter.mv[reflist][1] - mv_cand[1][1];
|
||||
cand2_cost = get_mvd_cost(&mvd_temp2, (cabac_data_t*)&state->cabac);
|
||||
cand2_cost = get_mvd_cost(state, &mvd_temp2, (cabac_data_t*)&state->cabac);
|
||||
|
||||
// Select candidate 1 if it has lower cost
|
||||
if (cand2_cost < cand1_cost) {
|
||||
|
@ -1517,7 +1517,7 @@ static int search_pu_inter(const encoder_state_t * const state,
|
|||
*
|
||||
* \return cost of the best mode
|
||||
*/
|
||||
int kvz_search_cu_inter(const encoder_state_t * const state, int x, int y, int depth, lcu_t *lcu)
|
||||
int kvz_search_cu_inter(encoder_state_t * const state, int x, int y, int depth, lcu_t *lcu)
|
||||
{
|
||||
return search_pu_inter(state, x, y, depth, SIZE_2Nx2N, 0, lcu);
|
||||
}
|
||||
|
@ -1537,7 +1537,7 @@ int kvz_search_cu_inter(const encoder_state_t * const state, int x, int y, int d
|
|||
*
|
||||
* \return cost of the best mode
|
||||
*/
|
||||
int kvz_search_cu_smp(const encoder_state_t * const state,
|
||||
int kvz_search_cu_smp(encoder_state_t * const state,
|
||||
int x, int y,
|
||||
int depth,
|
||||
part_mode_t part_mode,
|
||||
|
|
|
@ -31,9 +31,9 @@
|
|||
#include "global.h" // IWYU pragma: keep
|
||||
|
||||
|
||||
int kvz_search_cu_inter(const encoder_state_t * const state, int x, int y, int depth, lcu_t *lcu);
|
||||
int kvz_search_cu_inter(encoder_state_t * const state, int x, int y, int depth, lcu_t *lcu);
|
||||
|
||||
int kvz_search_cu_smp(const encoder_state_t * const state,
|
||||
int kvz_search_cu_smp(encoder_state_t * const state,
|
||||
int x, int y,
|
||||
int depth,
|
||||
part_mode_t part_mode,
|
||||
|
|
Loading…
Reference in a new issue