Adds a fuzzing mode that causes the encoder to make random decisions
This commit is contained in:
parent
c2d86f0639
commit
f334c82ec3
7 changed files with 70 additions and 0 deletions
|
@ -141,6 +141,13 @@ AC_ARG_ENABLE(assertions, [ --enable-assertions enable additional software
|
|||
AC_DEFINE([ENABLE_ASSERTIONS], , [Assertions])
|
||||
fi])
|
||||
|
||||
ac_enable_fuzzing="no"
|
||||
AC_ARG_ENABLE(fuzzing, [ --enable-fuzzing causes the encoder to make random decisions],
|
||||
[if test "$enableval" = yes; then
|
||||
ac_enable_fuzzing="yes"
|
||||
AC_DEFINE([FUZZING], , [Fuzzing])
|
||||
fi])
|
||||
|
||||
if test "$OPUS_BUILD" != "true" ; then
|
||||
saved_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -fvisibility=hidden"
|
||||
|
@ -219,6 +226,7 @@ AC_MSG_RESULT([
|
|||
Fixed point debugging: ......... ${ac_enable_fixed_debug}
|
||||
Custom modes: .................. ${ac_enable_custom_modes}
|
||||
Assertion checking: ............ ${ac_enable_assertions}
|
||||
Fuzzing: .. .......... ${ac_enable_fuzzing}
|
||||
------------------------------------------------------------------------
|
||||
])
|
||||
|
||||
|
|
|
@ -477,6 +477,10 @@ int spreading_decision(const CELTMode *m, celt_norm *X, int *average,
|
|||
} else {
|
||||
decision = SPREAD_NONE;
|
||||
}
|
||||
#ifdef FUZZING
|
||||
decision = rand()&0x3;
|
||||
*tapset_decision=rand()%3;
|
||||
#endif
|
||||
return decision;
|
||||
}
|
||||
|
||||
|
|
|
@ -387,6 +387,9 @@ static int transient_analysis(const opus_val32 * restrict in, int len, int C,
|
|||
is_transient=1;
|
||||
}
|
||||
RESTORE_STACK;
|
||||
#ifdef FUZZING
|
||||
is_transient = rand()&0x1;
|
||||
#endif
|
||||
return is_transient;
|
||||
}
|
||||
|
||||
|
@ -709,6 +712,12 @@ static int tf_analysis(const CELTMode *m, int len, int C, int isTransient,
|
|||
tf_res[i] = path0[i+1];
|
||||
}
|
||||
RESTORE_STACK;
|
||||
#ifdef FUZZING
|
||||
tf_select = rand()&0x1;
|
||||
tf_res[0] = rand()&0x1;
|
||||
for (i=1;i<len;i++)
|
||||
tf_res[i] = tf_res[i-1] ^ ((rand()&0xF) == 0);
|
||||
#endif
|
||||
return tf_select;
|
||||
}
|
||||
|
||||
|
@ -857,6 +866,9 @@ static int alloc_trim_analysis(const CELTMode *m, const celt_norm *X,
|
|||
trim_index = 0;
|
||||
if (trim_index>10)
|
||||
trim_index = 10;
|
||||
#ifdef FUZZING
|
||||
trim_index = rand()%11;
|
||||
#endif
|
||||
return trim_index;
|
||||
}
|
||||
|
||||
|
@ -1102,6 +1114,10 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
|
|||
CELT_COPY(pre[c]+COMBFILTER_MAXPERIOD, in+c*(N+st->overlap)+st->overlap, N);
|
||||
} while (++c<CC);
|
||||
|
||||
#ifdef FUZZING
|
||||
if ((rand()&0x3F)==0)
|
||||
silence = 1;
|
||||
#endif
|
||||
if (tell==1)
|
||||
ec_enc_bit_logp(enc, silence, 15);
|
||||
else
|
||||
|
@ -1332,10 +1348,19 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
|
|||
if (C==2)
|
||||
d2 = HALF32(d2 + 2*bandLogE[i+st->mode->nbEBands]-
|
||||
bandLogE[i-1+st->mode->nbEBands]-bandLogE[i+1+st->mode->nbEBands]);
|
||||
#ifdef FUZZING
|
||||
if((rand()&0xF)==0)
|
||||
{
|
||||
offsets[i] += 1;
|
||||
if((rand()&0x3)==0)
|
||||
offsets[i] += 1+(rand()&0x3);
|
||||
}
|
||||
#else
|
||||
if (d2 > SHL16(t1,DB_SHIFT))
|
||||
offsets[i] += 1;
|
||||
if (d2 > SHL16(t2,DB_SHIFT))
|
||||
offsets[i] += 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
dynalloc_logp = 6;
|
||||
|
@ -1527,6 +1552,9 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
|
|||
if (anti_collapse_rsv > 0)
|
||||
{
|
||||
anti_collapse_on = st->consec_transient<2;
|
||||
#ifdef FUZZING
|
||||
anti_collapse_on = rand()&0x1;
|
||||
#endif
|
||||
ec_enc_bits(enc, anti_collapse_on, 1);
|
||||
}
|
||||
quant_energy_finalise(st->mode, st->start, st->end, oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_tell(enc), enc, C);
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#include "mathops.h"
|
||||
#include "arch.h"
|
||||
|
||||
#ifdef CUSTOM_MODES
|
||||
|
||||
/*Guaranteed to return a conservatively large estimate of the binary logarithm
|
||||
with frac bits of fractional precision.
|
||||
Tested for all possible 32-bit inputs with frac=4, where the maximum
|
||||
|
@ -68,6 +70,7 @@ int log2_frac(opus_uint32 val, int frac)
|
|||
/*Exact powers of two require no rounding.*/
|
||||
else return l-1<<frac;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef SMALL_FOOTPRINT
|
||||
|
||||
|
|
|
@ -35,7 +35,9 @@
|
|||
#include "entenc.h"
|
||||
#include "entdec.h"
|
||||
|
||||
#ifdef CUSTOM_MODES
|
||||
int log2_frac(opus_uint32 val, int frac);
|
||||
#endif
|
||||
|
||||
void get_required_bits(opus_int16 *bits, int N, int K, int frac);
|
||||
|
||||
|
|
|
@ -351,7 +351,11 @@ static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int
|
|||
skip here must be explicitly signaled.*/
|
||||
/*Choose a threshold with some hysteresis to keep bands from
|
||||
fluctuating in and out.*/
|
||||
#ifdef FUZZING
|
||||
if ((rand()&0x1) == 0)
|
||||
#else
|
||||
if (band_bits > ((j<prev?7:9)*band_width<<LM<<BITRES)>>4)
|
||||
#endif
|
||||
{
|
||||
ec_enc_bit_logp(ec, 1, 1);
|
||||
break;
|
||||
|
|
|
@ -217,6 +217,12 @@ int opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size,
|
|||
} else {
|
||||
st->stream_channels = st->channels;
|
||||
}
|
||||
|
||||
#ifdef FUZZING
|
||||
if (st->channels == 2 && (rand()&0x1F)==0)
|
||||
st->stream_channels = 3-st->stream_channels;
|
||||
#endif
|
||||
|
||||
/* Equivalent bit-rate for mono */
|
||||
mono_rate = st->bitrate_bps;
|
||||
if (st->stream_channels==2)
|
||||
|
@ -225,6 +231,20 @@ int opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size,
|
|||
of 60 bits/frame */
|
||||
mono_rate -= 60*(st->Fs/frame_size - 50);
|
||||
|
||||
#ifdef FUZZING
|
||||
if ((rand()&0xF)==0)
|
||||
{
|
||||
if ((rand()&0x1)==0)
|
||||
st->mode = MODE_CELT_ONLY;
|
||||
else
|
||||
st->mode = MODE_SILK_ONLY;
|
||||
} else {
|
||||
if (st->prev_mode==MODE_CELT_ONLY)
|
||||
st->mode = MODE_CELT_ONLY;
|
||||
else
|
||||
st->mode = MODE_SILK_ONLY;
|
||||
}
|
||||
#else
|
||||
/* Mode selection depending on application and signal type */
|
||||
if (st->user_mode==OPUS_APPLICATION_VOIP)
|
||||
{
|
||||
|
@ -260,6 +280,7 @@ int opus_encode(OpusEncoder *st, const opus_int16 *pcm, int frame_size,
|
|||
else
|
||||
st->mode = MODE_SILK_ONLY;
|
||||
}
|
||||
#endif
|
||||
/* Automatic (rate-dependent) bandwidth selection */
|
||||
if (st->mode == MODE_CELT_ONLY || st->first || st->silk_mode.allowBandwidthSwitch)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue