Merge cherrypicks of [4793640, 4793602, 4793603, 4793660, 4793604, 4793680, 4793681, 4793581, 4793582, 4793625, 4793626, 4793627, 4793628, 4793700, 4793701, 4793702, 4793703, 4793704, 4793705, 4793661, 4793720, 4793721, 4793722, 4793723, 4793724, 4793725, 4793726, 4793727, 4793728, 4793583, 4793740, 4793760, 4793662, 4793780, 4793729] into pi-release-2

Change-Id: Iec4eada4d802c96de534f7a5df10a70451dbc3a6
diff --git a/decoder/armv8/ixheaacd_qmf_dec_armv8.c b/decoder/armv8/ixheaacd_qmf_dec_armv8.c
index a4b89c5..8cfe002 100644
--- a/decoder/armv8/ixheaacd_qmf_dec_armv8.c
+++ b/decoder/armv8/ixheaacd_qmf_dec_armv8.c
@@ -501,8 +501,8 @@
                               WORD32 index) {
   int i;
   WORD32 l1, l2, h2, fft_jmp;
-  WORD32 xt0_0, yt0_0, xt1_0, yt1_0, xt2_0, yt2_0;
-  WORD32 xh0_0, xh1_0, xh20_0, xh21_0, xl0_0, xl1_0, xl20_0, xl21_0;
+  WORD64 xt0_0, yt0_0, xt1_0, yt1_0, xt2_0, yt2_0;
+  WORD64 xh0_0, xh1_0, xh20_0, xh21_0, xl0_0, xl1_0, xl20_0, xl21_0;
   WORD32 x_0, x_1, x_l1_0, x_l1_1, x_l2_0, x_l2_1;
   WORD32 x_h2_0, x_h2_1;
   WORD32 si10, si20, si30, co10, co20, co30;
@@ -539,34 +539,34 @@
       x_l1_0 = x[l1];
       x_l2_0 = x[l2];
 
-      xh0_0 = x_0 + x_l1_0;
-      xl0_0 = x_0 - x_l1_0;
+      xh0_0 = (WORD64)x_0 + (WORD64)x_l1_0;
+      xl0_0 = (WORD64)x_0 - (WORD64)x_l1_0;
 
-      xh20_0 = x_h2_0 + x_l2_0;
-      xl20_0 = x_h2_0 - x_l2_0;
+      xh20_0 = (WORD64)x_h2_0 + (WORD64)x_l2_0;
+      xl20_0 = (WORD64)x_h2_0 - (WORD64)x_l2_0;
 
-      x[0] = xh0_0 + xh20_0;
-      xt0_0 = xh0_0 - xh20_0;
+      x[0] = (WORD32)ixheaacd_add64_sat(xh0_0, xh20_0);
+      xt0_0 = (WORD64)xh0_0 - (WORD64)xh20_0;
 
       x_1 = x[1];
       x_h2_1 = x[h2 + 1];
       x_l1_1 = x[l1 + 1];
       x_l2_1 = x[l2 + 1];
 
-      xh1_0 = x_1 + x_l1_1;
-      xl1_0 = x_1 - x_l1_1;
+      xh1_0 = (WORD64)x_1 + (WORD64)x_l1_1;
+      xl1_0 = (WORD64)x_1 - (WORD64)x_l1_1;
 
-      xh21_0 = x_h2_1 + x_l2_1;
-      xl21_0 = x_h2_1 - x_l2_1;
+      xh21_0 = (WORD64)x_h2_1 + (WORD64)x_l2_1;
+      xl21_0 = (WORD64)x_h2_1 - (WORD64)x_l2_1;
 
-      x[1] = xh1_0 + xh21_0;
-      yt0_0 = xh1_0 - xh21_0;
+      x[1] = (WORD32)ixheaacd_add64_sat(xh1_0, xh21_0);
+      yt0_0 = (WORD64)xh1_0 - (WORD64)xh21_0;
 
-      xt1_0 = xl0_0 + xl21_0;
-      xt2_0 = xl0_0 - xl21_0;
+      xt1_0 = (WORD64)xl0_0 + (WORD64)xl21_0;
+      xt2_0 = (WORD64)xl0_0 - (WORD64)xl21_0;
 
-      yt2_0 = xl1_0 + xl20_0;
-      yt1_0 = xl1_0 - xl20_0;
+      yt2_0 = (WORD64)xl1_0 + (WORD64)xl20_0;
+      yt1_0 = (WORD64)xl1_0 - (WORD64)xl20_0;
 
       mul_11 = ixheaacd_mult64(xt2_0, co30);
       mul_3 = ixheaacd_mult64(yt2_0, si30);
@@ -607,8 +607,6 @@
   WORD32 x_0, x_1, x_2, x_3;
   WORD32 x_4, x_5, x_6, x_7;
   WORD32 x_8, x_9, x_a, x_b, x_c, x_d, x_e, x_f;
-  WORD32 n00, n10, n20, n30, n01, n11, n21, n31;
-  WORD32 n02, n12, n22, n32, n03, n13, n23, n33;
   WORD32 n0, j0;
   WORD32 *x2, *x0;
   WORD32 *y0, *y1, *y2, *y3;
@@ -636,23 +634,14 @@
       x_6 = *x0++;
       x_7 = *x0++;
 
-      n00 = x_0 + x_2;
-      n01 = x_1 + x_3;
-      n20 = x_0 - x_2;
-      n21 = x_1 - x_3;
-      n10 = x_4 + x_6;
-      n11 = x_5 + x_7;
-      n30 = x_4 - x_6;
-      n31 = x_5 - x_7;
-
-      y0[h2] = n00;
-      y0[h2 + 1] = n01;
-      y1[h2] = n10;
-      y1[h2 + 1] = n11;
-      y2[h2] = n20;
-      y2[h2 + 1] = n21;
-      y3[h2] = n30;
-      y3[h2 + 1] = n31;
+      y0[h2] = ixheaacd_add32_sat(x_0, x_2);
+      y0[h2 + 1] = ixheaacd_add32_sat(x_1, x_3);
+      y1[h2] = ixheaacd_add32_sat(x_4, x_6);
+      y1[h2 + 1] = ixheaacd_add32_sat(x_5, x_7);
+      y2[h2] = ixheaacd_sub32_sat(x_0, x_2);
+      y2[h2 + 1] = ixheaacd_sub32_sat(x_1, x_3);
+      y3[h2] = ixheaacd_sub32_sat(x_4, x_6);
+      y3[h2 + 1] = ixheaacd_sub32_sat(x_5, x_7);
 
       x_8 = *x2++;
       x_9 = *x2++;
@@ -663,23 +652,14 @@
       x_e = *x2++;
       x_f = *x2++;
 
-      n02 = x_8 + x_a;
-      n03 = x_9 + x_b;
-      n22 = x_8 - x_a;
-      n23 = x_9 - x_b;
-      n12 = x_c + x_e;
-      n13 = x_d + x_f;
-      n32 = x_c - x_e;
-      n33 = x_d - x_f;
-
-      y0[h2 + 2] = n02;
-      y0[h2 + 3] = n03;
-      y1[h2 + 2] = n12;
-      y1[h2 + 3] = n13;
-      y2[h2 + 2] = n22;
-      y2[h2 + 3] = n23;
-      y3[h2 + 2] = n32;
-      y3[h2 + 3] = n33;
+      y0[h2 + 2] = ixheaacd_add32_sat(x_8, x_a);
+      y0[h2 + 3] = ixheaacd_add32_sat(x_9, x_b);
+      y1[h2 + 2] = ixheaacd_add32_sat(x_c, x_e);
+      y1[h2 + 3] = ixheaacd_add32_sat(x_d, x_f);
+      y2[h2 + 2] = ixheaacd_sub32_sat(x_8, x_a);
+      y2[h2 + 3] = ixheaacd_sub32_sat(x_9, x_b);
+      y3[h2 + 2] = ixheaacd_sub32_sat(x_c, x_e);
+      y3[h2 + 3] = ixheaacd_sub32_sat(x_d, x_f);
     }
     x0 += (WORD32)npoints >> 1;
     x2 += (WORD32)npoints >> 1;
@@ -1224,19 +1204,19 @@
     r1 = *qmf_real++;
     i1 = *qmf_imag++;
 
-    timag = ixheaacd_add32(i1, r1);
+    timag = ixheaacd_add32_sat(i1, r1);
     timag = (ixheaacd_shl32_sat(timag, shift));
     filter_states_rev[j] = timag;
 
-    treal = ixheaacd_sub32(i2, r2);
+    treal = ixheaacd_sub32_sat(i2, r2);
     treal = (ixheaacd_shl32_sat(treal, shift));
     filter_states[j] = treal;
 
-    treal = ixheaacd_sub32(i1, r1);
+    treal = ixheaacd_sub32_sat(i1, r1);
     treal = (ixheaacd_shl32_sat(treal, shift));
     *filter_states++ = treal;
 
-    timag = ixheaacd_add32(i2, r2);
+    timag = ixheaacd_add32_sat(i2, r2);
     timag = (ixheaacd_shl32_sat(timag, shift));
     *filter_states_rev++ = timag;
   }
diff --git a/decoder/ixheaacd_esbr_polyphase.c b/decoder/ixheaacd_esbr_polyphase.c
index bcb4685..d51a14c 100644
--- a/decoder/ixheaacd_esbr_polyphase.c
+++ b/decoder/ixheaacd_esbr_polyphase.c
@@ -120,8 +120,9 @@
         *ptr_u++ = ((*analy_cos_sin_tab++) * u[k]);
         *ptr_u++ = ((*analy_cos_sin_tab++) * u[k]);
       }
-      if (ixheaacd_cmplx_anal_fft != NULL)
-        (*ixheaacd_cmplx_anal_fft)(u_in, u_out, anal_size * 2);
+      if (ptr_hbe_txposer->ixheaacd_cmplx_anal_fft != NULL)
+        (*(ptr_hbe_txposer->ixheaacd_cmplx_anal_fft))(u_in, u_out,
+                                                      anal_size * 2);
       else
         return -1;
 
@@ -209,8 +210,9 @@
       FLOAT32 *syn_buf = &buffer[kmax];
       kmax += synth_size;
 
-      if (ixheaacd_real_synth_fft != NULL)
-        (*ixheaacd_real_synth_fft)(synth_buf_r, synth_out, synth_size * 2);
+      if (ptr_hbe_txposer->ixheaacd_real_synth_fft != NULL)
+        (*(ptr_hbe_txposer->ixheaacd_real_synth_fft))(synth_buf_r, synth_out,
+                                                      synth_size * 2);
       else
         return -1;
 
diff --git a/decoder/ixheaacd_hbe_trans.c b/decoder/ixheaacd_hbe_trans.c
index e188572..0c6f191 100644
--- a/decoder/ixheaacd_hbe_trans.c
+++ b/decoder/ixheaacd_hbe_trans.c
@@ -132,32 +132,32 @@
             (FLOAT32 *)ixheaacd_synth_cos_table_kl_4;
         ptr_hbe_txposer->analy_cos_sin_tab =
             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_8;
-        ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
-        ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
+        ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
+        ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
         break;
       case 8:
         ptr_hbe_txposer->synth_cos_tab =
             (FLOAT32 *)ixheaacd_synth_cos_table_kl_8;
         ptr_hbe_txposer->analy_cos_sin_tab =
             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_16;
-        ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
-        ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
+        ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
+        ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
         break;
       case 12:
         ptr_hbe_txposer->synth_cos_tab =
             (FLOAT32 *)ixheaacd_synth_cos_table_kl_12;
         ptr_hbe_txposer->analy_cos_sin_tab =
             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_24;
-        ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p3;
-        ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p3;
+        ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p3;
+        ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p3;
         break;
       case 16:
         ptr_hbe_txposer->synth_cos_tab =
             (FLOAT32 *)ixheaacd_synth_cos_table_kl_16;
         ptr_hbe_txposer->analy_cos_sin_tab =
             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_32;
-        ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
-        ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
+        ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
+        ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
         break;
       case 20:
         ptr_hbe_txposer->synth_cos_tab =
@@ -170,8 +170,8 @@
             (FLOAT32 *)ixheaacd_synth_cos_table_kl_4;
         ptr_hbe_txposer->analy_cos_sin_tab =
             (FLOAT32 *)ixheaacd_analy_cos_sin_table_kl_8;
-        ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
-        ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
+        ptr_hbe_txposer->ixheaacd_real_synth_fft = &ixheaacd_real_synth_fft_p2;
+        ptr_hbe_txposer->ixheaacd_cmplx_anal_fft = &ixheaacd_cmplx_anal_fft_p2;
     }
 
     ptr_hbe_txposer->synth_wind_coeff = ixheaacd_map_prot_filter(synth_size);
@@ -213,9 +213,9 @@
         break;
       }
     }
-  }
-  if (ptr_hbe_txposer->k_start < 0) {
-    return -1;
+    if (ptr_hbe_txposer->k_start < 0) {
+      return -1;
+    }
   }
   return 0;
 }
diff --git a/decoder/ixheaacd_lpfuncs.c b/decoder/ixheaacd_lpfuncs.c
index 06fce57..c42896e 100644
--- a/decoder/ixheaacd_lpfuncs.c
+++ b/decoder/ixheaacd_lpfuncs.c
@@ -662,7 +662,7 @@
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
 
       win_ovadd_op =
-          ixheaacd_add32(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
+          ixheaacd_add32_sat(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
 
       *out_samples = ixheaacd_round16(ixheaacd_shl32_sat(win_ovadd_op, 1));
       out_samples += stride;
@@ -672,7 +672,7 @@
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
 
       win_ovadd_op =
-          ixheaacd_add32(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
+          ixheaacd_add32_sat(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
 
       *out_samples = ixheaacd_round16(ixheaacd_shl32_sat(win_ovadd_op, 1));
       out_samples += stride;
@@ -681,7 +681,7 @@
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
 
       win_ovadd_op =
-          ixheaacd_add32(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
+          ixheaacd_add32_sat(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
 
       *out_samples = ixheaacd_round16(ixheaacd_shl32_sat(win_ovadd_op, 1));
       out_samples += stride;
@@ -691,7 +691,7 @@
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
 
       win_ovadd_op =
-          ixheaacd_add32(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
+          ixheaacd_add32_sat(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
 
       *out_samples = ixheaacd_round16(ixheaacd_shl32_sat(win_ovadd_op, 1));
       out_samples += stride;
@@ -705,19 +705,23 @@
       WORD16 win_val;
       win_val = *p_win++;
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
-      *p_out2++ = ixheaacd_add32(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
+      *p_out2++ =
+          ixheaacd_add32_sat(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
 
       win_val = *p_win++;
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
-      *p_out2++ = ixheaacd_add32(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
+      *p_out2++ =
+          ixheaacd_add32_sat(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
 
       win_val = *p_win++;
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
-      *p_out2++ = ixheaacd_add32(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
+      *p_out2++ =
+          ixheaacd_add32_sat(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
 
       win_val = *p_win++;
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
-      *p_out2++ = ixheaacd_add32(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
+      *p_out2++ =
+          ixheaacd_add32_sat(ixheaacd_shl32(win_op, q_shift), *ptr_out++);
     }
 
     loop_size = ((((framesize << 2) - delay) - (framesize * 3)) >> 2) - 1;
@@ -753,7 +757,7 @@
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
 
       win_ovadd_op =
-          ixheaacd_add32(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
+          ixheaacd_add32_sat(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
 
       *out_samples = ixheaacd_round16(ixheaacd_shl32(win_ovadd_op, 1));
       out_samples += stride;
@@ -762,7 +766,7 @@
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
 
       win_ovadd_op =
-          ixheaacd_add32(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
+          ixheaacd_add32_sat(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
 
       *out_samples = ixheaacd_round16(ixheaacd_shl32(win_ovadd_op, 1));
       out_samples += stride;
@@ -771,7 +775,7 @@
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
 
       win_ovadd_op =
-          ixheaacd_add32(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
+          ixheaacd_add32_sat(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
 
       *out_samples = ixheaacd_round16(ixheaacd_shl32(win_ovadd_op, 1));
       out_samples += stride;
@@ -780,7 +784,7 @@
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
 
       win_ovadd_op =
-          ixheaacd_add32(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
+          ixheaacd_add32_sat(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
 
       *out_samples = ixheaacd_round16(ixheaacd_shl32(win_ovadd_op, 1));
       out_samples += stride;
@@ -794,19 +798,23 @@
       WORD16 win_val;
       win_val = *p_win++;
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
-      *p_out2++ = ixheaacd_add32(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
+      *p_out2++ =
+          ixheaacd_add32_sat(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
 
       win_val = *p_win++;
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
-      *p_out2++ = ixheaacd_add32(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
+      *p_out2++ =
+          ixheaacd_add32_sat(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
 
       win_val = *p_win++;
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
-      *p_out2++ = ixheaacd_add32(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
+      *p_out2++ =
+          ixheaacd_add32_sat(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
 
       win_val = *p_win++;
       win_op = ixheaacd_mult32x16in32(*ptr_z++, (win_val));
-      *p_out2++ = ixheaacd_add32(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
+      *p_out2++ =
+          ixheaacd_add32_sat(ixheaacd_shr32(win_op, q_shift), *ptr_out++);
     }
     loop_size = ((((framesize << 2) - delay) - (framesize * 3)) >> 2) - 1;
     for (i = loop_size; i >= 0; i--) {
diff --git a/decoder/ixheaacd_pns_js_thumb.c b/decoder/ixheaacd_pns_js_thumb.c
index d6dfae7..15db806 100644
--- a/decoder/ixheaacd_pns_js_thumb.c
+++ b/decoder/ixheaacd_pns_js_thumb.c
@@ -354,10 +354,11 @@
         scale_spec = (*ixheaacd_calc_max_spectral_line)(ptr_tmp, size);
       }
 
-      if (filter->direction == -1) {
-        position = stop - 1;
-      } else {
+      if (filter->direction != -1) {
         position = start;
+      } else {
+        position = stop - 1;
+        if (((win << 7) + position) < filter->order) continue;
       }
 
       if ((num_ch <= 2) &&
diff --git a/decoder/ixheaacd_qmf_poly.h b/decoder/ixheaacd_qmf_poly.h
index 8a67480..0cafcf1 100644
--- a/decoder/ixheaacd_qmf_poly.h
+++ b/decoder/ixheaacd_qmf_poly.h
@@ -37,8 +37,4 @@
 
 VOID ixheaacd_real_synth_fft_p3(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points);
 
-VOID (*ixheaacd_real_synth_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points);
-
-VOID (*ixheaacd_cmplx_anal_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points);
-
 #endif
diff --git a/decoder/ixheaacd_sbr_dec.h b/decoder/ixheaacd_sbr_dec.h
index ac92ef5..0beec6d 100644
--- a/decoder/ixheaacd_sbr_dec.h
+++ b/decoder/ixheaacd_sbr_dec.h
@@ -48,6 +48,9 @@
   FLOAT32 *analy_cos_sin_tab;
 
   FLOAT32 norm_qmf_in_buf[46][128];
+  VOID (*ixheaacd_real_synth_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points);
+
+  VOID (*ixheaacd_cmplx_anal_fft)(FLOAT32 *inp, FLOAT32 *out, WORD32 n_points);
 
 } ia_esbr_hbe_txposer_struct;
 
diff --git a/test/ixheaacd_main.c b/test/ixheaacd_main.c
index 4d77b58..feec6c5 100644
--- a/test/ixheaacd_main.c
+++ b/test/ixheaacd_main.c
@@ -1576,6 +1576,16 @@
     if (raw_testing) {
       ixheaacd_i_bytes_to_read =
           get_metadata_dec_exec(meta_info, frame_counter);
+
+      if (ixheaacd_i_bytes_to_read <= 0) {
+        err_code = (*p_ia_process_api)(pv_ia_process_api_obj,
+                                       IA_API_CMD_INPUT_OVER, 0, NULL);
+
+        _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code);
+
+        return IA_NO_ERROR;
+      }
+
       err_code =
           (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES,
                               0, &ixheaacd_i_bytes_to_read);