summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoney Alex <doney.alex@ittiam.com>2015-06-30 17:56:42 +0530
committerMarco Nelissen <marcone@google.com>2015-07-31 18:50:37 +0000
commit0574be65f4b2376e32bdf979650d8e5f168b68b7 (patch)
tree89925b8bed61b5f8d08385861c80f0510952b698
parenteddf6a33fe731e0dbba56092d5020cc8edc14ca5 (diff)
downloadandroid_external_libavc-0574be65f4b2376e32bdf979650d8e5f168b68b7.tar.gz
android_external_libavc-0574be65f4b2376e32bdf979650d8e5f168b68b7.tar.bz2
android_external_libavc-0574be65f4b2376e32bdf979650d8e5f168b68b7.zip
Cabac optimizations
Optimized cabac functions for writing bypass bins. Removed unused return from cabac flush function. Removed the macro REV_NBITS. Bug: 22860270 Change-Id: Iece82797f2f45a35281817a2b77a7c7fe4e02bd1
-rw-r--r--encoder/ih264e_cabac.c74
-rw-r--r--encoder/ih264e_cabac.h22
-rw-r--r--encoder/ih264e_cabac_encode.c11
3 files changed, 32 insertions, 75 deletions
diff --git a/encoder/ih264e_cabac.c b/encoder/ih264e_cabac.c
index 64ff7cd..26ded4d 100644
--- a/encoder/ih264e_cabac.c
+++ b/encoder/ih264e_cabac.c
@@ -111,29 +111,28 @@
*
*******************************************************************************
*/
+
UWORD32 ih264e_cabac_UEGk0_binarization(WORD16 i2_sufs, WORD8 *pi1_bins_len)
{
- UWORD32 u4_bins;
- WORD32 i4_len;
- WORD16 x, y;
-
- x = i2_sufs + 1;
- i4_len = CLZ(x);
- i4_len = 31 - i4_len;
- y = 1 << i4_len;
- y = y - 1;
- i2_sufs = i2_sufs - y;
- u4_bins = y << 1;
- u4_bins = u4_bins << i4_len;
- u4_bins = u4_bins + i2_sufs;
-
- REV(u4_bins, u4_bins);
- u4_bins = u4_bins >> (31 - 2 * i4_len);
- (*pi1_bins_len) = 2 * i4_len + 1;
-
- return (u4_bins);
-}
+ WORD32 unary_length;
+ UWORD32 u4_sufs_shiftk_plus1, u4_egk, u4_unary_bins;
+
+ u4_sufs_shiftk_plus1 = i2_sufs + 1;
+
+ unary_length = (32 - CLZ(u4_sufs_shiftk_plus1) + (0 == u4_sufs_shiftk_plus1));
+
+ /* unary code with (unary_length-1) '1's and terminating '0' bin */
+ u4_unary_bins = (1 << unary_length) - 2;
+
+ /* insert the symbol prefix of (unary length - 1) bins */
+ u4_egk = (u4_unary_bins << (unary_length - 1))
+ | (u4_sufs_shiftk_plus1 & ((1 << (unary_length - 1)) - 1));
+ /* length of the code = 2 *(unary_length - 1) + 1 + k */
+ *pi1_bins_len = (2 * unary_length) - 1;
+
+ return (u4_egk);
+}
/**
*******************************************************************************
@@ -236,14 +235,14 @@ void ih264e_get_cabac_context(entropy_ctxt_t *ps_ent_ctxt, WORD32 u4_mb_type)
* @param[in] ps_cabac_ctxt
* pointer to cabac context (handle)
*
- * @returns success or failure error code
+ * @returns none
*
* @remarks
* None
*
*******************************************************************************
*/
-WORD32 ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt)
+void ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt)
{
/* bit stream ptr */
@@ -267,17 +266,6 @@ WORD32 ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt)
WORD32 bits_left;
WORD32 rem_bits;
- /*********************************************************************/
- /* Bitstream overflow check */
- /* NOTE: corner case of epb bytes (max 2 for 32bit word) not handled */
- /*********************************************************************/
- if ((u4_strm_buf_offset + u4_out_standing_bytes + 1)
- >= ps_stream->u4_max_strm_size)
- {
- /* return without corrupting the buffer beyond its size */
- return (IH264E_BITSTREAM_BUFFER_OVERFLOW);
- }
-
if (carry)
{
/* CORNER CASE: if the previous data is 0x000003, then EPB will be inserted
@@ -336,7 +324,6 @@ WORD32 ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt)
ps_stream->u4_cur_word = 0;
ps_stream->i4_bits_left_in_cw = WORD_SIZE;
- return (IH264E_SUCCESS);
}
}
@@ -763,7 +750,6 @@ void ih264e_cabac_encode_bypass_bins(cabac_ctxt_t *ps_cabac, UWORD32 u4_bins,
UWORD32 u4_range = ps_cab_enc_env->u4_code_int_range;
WORD32 next_byte;
- UWORD32 rev_next_byte;
/* Sanity checks */
ASSERT((num_bins < 33) && (num_bins > 0));
@@ -777,14 +763,11 @@ void ih264e_cabac_encode_bypass_bins(cabac_ctxt_t *ps_cabac, UWORD32 u4_bins,
{
num_bins -= 8;
- /* extract the leading 8 bins */
- next_byte = (u4_bins) & 0xff;
- u4_bins >>= 8;
- REV_NBITS(next_byte, 8, rev_next_byte);
+ next_byte = (u4_bins >> (num_bins)) & 0xff;
/* L = (L << 8) + (R * next_byte) */
ps_cab_enc_env->u4_code_int_low <<= 8;
- ps_cab_enc_env->u4_code_int_low += (rev_next_byte * u4_range);
+ ps_cab_enc_env->u4_code_int_low += (next_byte * u4_range);
ps_cab_enc_env->u4_bits_gen += 8;
if (ps_cab_enc_env->u4_bits_gen > CABAC_BITS)
@@ -797,10 +780,8 @@ void ih264e_cabac_encode_bypass_bins(cabac_ctxt_t *ps_cabac, UWORD32 u4_bins,
/* Update low with remaining bins and return */
next_byte = (u4_bins & ((1 << num_bins) - 1));
- REV_NBITS(next_byte, num_bins, rev_next_byte);
-
ps_cab_enc_env->u4_code_int_low <<= num_bins;
- ps_cab_enc_env->u4_code_int_low += (rev_next_byte * u4_range);
+ ps_cab_enc_env->u4_code_int_low += (next_byte * u4_range);
ps_cab_enc_env->u4_bits_gen += num_bins;
if (ps_cab_enc_env->u4_bits_gen > CABAC_BITS)
@@ -810,10 +791,3 @@ void ih264e_cabac_encode_bypass_bins(cabac_ctxt_t *ps_cabac, UWORD32 u4_bins,
}
}
-
-
-
-
-
-
-
diff --git a/encoder/ih264e_cabac.h b/encoder/ih264e_cabac.h
index e781783..e4722fa 100644
--- a/encoder/ih264e_cabac.h
+++ b/encoder/ih264e_cabac.h
@@ -47,24 +47,6 @@
#define CABAC_BITS 9
-
-
-/**
-******************************************************************************
- * @macro Count number of bits set
-******************************************************************************
-*/
-#define REV_NBITS(word, size, rev_word) \
-{ \
- WORD32 i; \
- rev_word = 0; \
- for (i = 0; i < (size); i++) \
- { \
- UWORD32 bit = ((word) >> i) & 1; \
- rev_word += (1 << ((size) - i - 1)) * bit; \
- } \
-} \
-
/**
******************************************************************************
* @macro Reverse bits in an unsigned integer
@@ -201,14 +183,14 @@ void ih264e_get_cabac_context(entropy_ctxt_t *ps_ent_ctxt, WORD32 u4_mb_type);
* @param[in] ps_cabac_ctxt
* pointer to cabac context (handle)
*
- * @returns success or failure error code
+ * @returns none
*
* @remarks
* None
*
*******************************************************************************
*/
-WORD32 ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt);
+void ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt);
/**
diff --git a/encoder/ih264e_cabac_encode.c b/encoder/ih264e_cabac_encode.c
index bf3e88e..ecc30f5 100644
--- a/encoder/ih264e_cabac_encode.c
+++ b/encoder/ih264e_cabac_encode.c
@@ -856,7 +856,7 @@ static void ih264e_cabac_write_coeff4x4(WORD16 *pi2_res_block, UWORD8 u1_nnz,
}
/* encode coeff_sign_flag[i] */
u1_sign = ((*pi16_coeffs) < 0) ? 1 : 0;
- ih264e_cabac_encode_bypass_bins(ps_cabac_ctxt, u1_sign, 1);
+ ih264e_cabac_encode_bypass_bin(ps_cabac_ctxt, u1_sign);
i = CLZ(u4_sig_coeff);
i = 31 - i;
pi16_coeffs--;
@@ -1375,7 +1375,7 @@ static void ih264e_cabac_enc_ctx_mvd(WORD16 u1_mvd, UWORD32 u4_ctx_idx_offset,
{
if (i2_sufs >= (1 << k))
{
- u4_bins = (u4_bins | (1 << i1_bins_len));
+ u4_bins = (u4_bins | (1 << (31 - i1_bins_len)));
i1_bins_len++;
i2_sufs = i2_sufs - (1 << k);
k++;
@@ -1386,12 +1386,13 @@ static void ih264e_cabac_enc_ctx_mvd(WORD16 u1_mvd, UWORD32 u4_ctx_idx_offset,
while (k--)
{
u1_bin = ((i2_sufs >> k) & 0x01);
- u4_bins = (u4_bins | (u1_bin << i1_bins_len));
+ u4_bins = (u4_bins | (u1_bin << (31 - i1_bins_len)));
i1_bins_len++;
}
break;
}
}
+ u4_bins >>= (32 - i1_bins_len);
ih264e_cabac_encode_bypass_bins(ps_cabac_ctxt, u4_bins,
i1_bins_len);
}
@@ -1428,9 +1429,9 @@ static void ih264e_cabac_enc_ctx_mvd(WORD16 u1_mvd, UWORD32 u4_ctx_idx_offset,
}
/* sign bit, uses EncodeBypass */
if (u1_mvd > 0)
- ih264e_cabac_encode_bypass_bins(ps_cabac_ctxt, 0, 1);
+ ih264e_cabac_encode_bypass_bin(ps_cabac_ctxt, 0);
else
- ih264e_cabac_encode_bypass_bins(ps_cabac_ctxt, 1, 1);
+ ih264e_cabac_encode_bypass_bin(ps_cabac_ctxt, 1);
}
}