Update libwebrtc third-party opus to M78
https://bugs.webkit.org/show_bug.cgi?id=202728

Reviewed by Alex Christensen.

* Source/third_party/opus: Updated.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@250961 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/ThirdParty/libwebrtc/ChangeLog b/Source/ThirdParty/libwebrtc/ChangeLog
index 329cd09..cb4eb66 100644
--- a/Source/ThirdParty/libwebrtc/ChangeLog
+++ b/Source/ThirdParty/libwebrtc/ChangeLog
@@ -1,5 +1,14 @@
 2019-10-10  Youenn Fablet  <youenn@apple.com>
 
+        Update libwebrtc third-party opus to M78
+        https://bugs.webkit.org/show_bug.cgi?id=202728
+
+        Reviewed by Alex Christensen.
+
+        * Source/third_party/opus: Updated.
+
+2019-10-10  Youenn Fablet  <youenn@apple.com>
+
         Update libwebrtc third-arty libyuv to M78
         https://bugs.webkit.org/show_bug.cgi?id=202727
 
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/OWNERS b/Source/ThirdParty/libwebrtc/Source/third_party/opus/OWNERS
index 4cc08f0..bcecd2a 100644
--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/OWNERS
+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/OWNERS
@@ -1,2 +1,3 @@
+flim@chromium.org
 henrika@chromium.org
-sergeyu@chromium.org
+# COMPONENT: Internals>Media>Codecs
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/README.chromium b/Source/ThirdParty/libwebrtc/Source/third_party/opus/README.chromium
index 8bd3197..ec97cd2 100644
--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/README.chromium
+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/README.chromium
@@ -20,3 +20,6 @@
 * Make sure HB_gain is not NaN in an attempt to fix chromium:826914
 * Saturate add to avoid int overflow to fix chromium:842528. This should be
   reverted when updating to v1.3
+* Apply https://github.com/xiph/opus/commit/4f4b11c2398e96134dc62ee794bfe33ecd6e9bd2
+* Apply https://git.xiph.org/?p=opus.git;a=commit;h=812ae3fb5c589aaafe761b8ebf86bcbbb8f0ed76
+* Apply https://git.xiph.org/?p=opus.git;a=commit;h=cd529ed
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/autogen.sh b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/autogen.sh
old mode 100644
new mode 100755
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_draft.sh b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_draft.sh
old mode 100644
new mode 100755
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_isobmff.sh b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_isobmff.sh
old mode 100644
new mode 100755
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_oggdraft.sh b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/doc/build_oggdraft.sh
old mode 100644
new mode 100755
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_defines.h b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_defines.h
index 33c5acd..653d916 100644
--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_defines.h
+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/include/opus_defines.h
@@ -168,6 +168,7 @@
 /* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */
 #define OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST 4046
 #define OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST 4047
+#define OPUS_GET_IN_DTX_REQUEST              4049
 
 /* Macros to trigger compilation errors when the wrong types are provided to a CTL */
 #define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
@@ -712,6 +713,16 @@
   * </dl>
   * @hideinitializer */
 #define OPUS_GET_PHASE_INVERSION_DISABLED(x) OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int_ptr(x)
+/** Gets the DTX state of the encoder.
+  * Returns whether the last encoded frame was either a comfort noise update
+  * during DTX or not encoded because of DTX.
+  * @param[out] x <tt>opus_int32 *</tt>: Returns one of the following values:
+  * <dl>
+  * <dt>0</dt><dd>The encoder is not in DTX.</dd>
+  * <dt>1</dt><dd>The encoder is in DTX.</dd>
+  * </dl>
+  * @hideinitializer */
+#define OPUS_GET_IN_DTX(x) OPUS_GET_IN_DTX_REQUEST, __opus_check_int_ptr(x)
 
 /**@}*/
 
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_neon_intr.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_neon_intr.c
index 27142f3..726e666 100644
--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_neon_intr.c
+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/arm/LPC_inv_pred_gain_neon_intr.c
@@ -210,28 +210,32 @@
         /* Increase Q domain of the AR coefficients */
         t0_s16x8 = vld1q_s16( A_Q12 +  0 );
         t1_s16x8 = vld1q_s16( A_Q12 +  8 );
-        t2_s16x8 = vld1q_s16( A_Q12 + 16 );
+        if ( order > 16 ) {
+          t2_s16x8 = vld1q_s16( A_Q12 + 16 );
+        }
         t0_s32x4 = vpaddlq_s16( t0_s16x8 );
 
         switch( order - leftover )
         {
         case 24:
             t0_s32x4 = vpadalq_s16( t0_s32x4, t2_s16x8 );
-            /* Intend to fall through */
+            vst1q_s32( Atmp_QA + 16, vshll_n_s16( vget_low_s16 ( t2_s16x8 ), QA - 12 ) );
+            vst1q_s32( Atmp_QA + 20, vshll_n_s16( vget_high_s16( t2_s16x8 ), QA - 12 ) );
+            /* FALLTHROUGH */
 
         case 16:
             t0_s32x4 = vpadalq_s16( t0_s32x4, t1_s16x8 );
-            vst1q_s32( Atmp_QA + 16, vshll_n_s16( vget_low_s16 ( t2_s16x8 ), QA - 12 ) );
-            vst1q_s32( Atmp_QA + 20, vshll_n_s16( vget_high_s16( t2_s16x8 ), QA - 12 ) );
-            /* Intend to fall through */
+            vst1q_s32( Atmp_QA +  8, vshll_n_s16( vget_low_s16 ( t1_s16x8 ), QA - 12 ) );
+            vst1q_s32( Atmp_QA + 12, vshll_n_s16( vget_high_s16( t1_s16x8 ), QA - 12 ) );
+            /* FALLTHROUGH */
 
         case 8:
         {
             const int32x2_t t_s32x2 = vpadd_s32( vget_low_s32( t0_s32x4 ), vget_high_s32( t0_s32x4 ) );
             const int64x1_t t_s64x1 = vpaddl_s32( t_s32x2 );
             DC_resp = vget_lane_s32( vreinterpret_s32_s64( t_s64x1 ), 0 );
-            vst1q_s32( Atmp_QA +  8, vshll_n_s16( vget_low_s16 ( t1_s16x8 ), QA - 12 ) );
-            vst1q_s32( Atmp_QA + 12, vshll_n_s16( vget_high_s16( t1_s16x8 ), QA - 12 ) );
+            vst1q_s32( Atmp_QA + 0, vshll_n_s16( vget_low_s16 ( t0_s16x8 ), QA - 12 ) );
+            vst1q_s32( Atmp_QA + 4, vshll_n_s16( vget_high_s16( t0_s16x8 ), QA - 12 ) );
         }
         break;
 
@@ -246,17 +250,23 @@
         case 6:
             DC_resp += (opus_int32)A_Q12[ 5 ];
             DC_resp += (opus_int32)A_Q12[ 4 ];
-            /* Intend to fall through */
+            Atmp_QA[ order - leftover + 5 ] = silk_LSHIFT32( (opus_int32)A_Q12[ 5 ], QA - 12 );
+            Atmp_QA[ order - leftover + 4 ] = silk_LSHIFT32( (opus_int32)A_Q12[ 4 ], QA - 12 );
+            /* FALLTHROUGH */
 
         case 4:
             DC_resp += (opus_int32)A_Q12[ 3 ];
             DC_resp += (opus_int32)A_Q12[ 2 ];
-            /* Intend to fall through */
+            Atmp_QA[ order - leftover + 3 ] = silk_LSHIFT32( (opus_int32)A_Q12[ 3 ], QA - 12 );
+            Atmp_QA[ order - leftover + 2 ] = silk_LSHIFT32( (opus_int32)A_Q12[ 2 ], QA - 12 );
+            /* FALLTHROUGH */
 
         case 2:
             DC_resp += (opus_int32)A_Q12[ 1 ];
             DC_resp += (opus_int32)A_Q12[ 0 ];
-            /* Intend to fall through */
+            Atmp_QA[ order - leftover + 1 ] = silk_LSHIFT32( (opus_int32)A_Q12[ 1 ], QA - 12 );
+            Atmp_QA[ order - leftover + 0 ] = silk_LSHIFT32( (opus_int32)A_Q12[ 0 ], QA - 12 );
+            /* FALLTHROUGH */
 
         default:
             break;
@@ -266,8 +276,6 @@
         if( DC_resp >= 4096 ) {
             invGain_Q30 = 0;
         } else {
-            vst1q_s32( Atmp_QA + 0, vshll_n_s16( vget_low_s16 ( t0_s16x8 ), QA - 12 ) );
-            vst1q_s32( Atmp_QA + 4, vshll_n_s16( vget_high_s16( t0_s16x8 ), QA - 12 ) );
             invGain_Q30 = LPC_inverse_pred_gain_QA_neon( Atmp_QA, order );
         }
     }
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_neon_intr.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_neon_intr.c
index 00a70cb..6f3be02 100644
--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_neon_intr.c
+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/silk/fixed/arm/warped_autocorrelation_FIX_neon_intr.c
@@ -84,7 +84,9 @@
         silk_assert( ( order & 1 ) == 0 );
         silk_assert( 2 * QS - QC >= 0 );
 
-        ALLOC( input_QST, length + 2 * MAX_SHAPE_LPC_ORDER, opus_int32 );
+        /* The additional +4 is to ensure a later vld1q_s32 call does not overflow.               */
+        /* Strictly, only +3 is needed but +4 simplifies initialization using the 4x32 neon load. */
+        ALLOC( input_QST, length + 2 * MAX_SHAPE_LPC_ORDER + 4, opus_int32 );
 
         input_QS = input_QST;
         /* input_QS has zero paddings in the beginning and end. */
@@ -121,6 +123,8 @@
         vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
         input_QS += 4;
         vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
+        input_QS += 4;
+        vst1q_s32( input_QS, vdupq_n_s32( 0 ) );
         input_QS = input_QST + MAX_SHAPE_LPC_ORDER - orderT;
 
         /* The following loop runs ( length + order ) times, with ( order ) extra epilogues.                  */
@@ -153,7 +157,8 @@
             opus_int o = orderT;
             int32x4_t state_QS_s32x4[ 3 ][ 2 ];
 
-            ALLOC( state, length + orderT, opus_int32 );
+            /* The additional +4 is to ensure a later vld1q_s32 call does not overflow. */
+            ALLOC( state, length + order + 4, opus_int32 );
             state_QS_s32x4[ 2 ][ 1 ] = vdupq_n_s32( 0 );
 
             /* Calculate 8 taps of all inputs in each loop. */
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_encoder.c b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_encoder.c
index 2149c20b..7fa6be0 100644
--- a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_encoder.c
+++ b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/src/opus_encoder.c
@@ -2716,6 +2716,33 @@
             ret = celt_encoder_ctl(celt_enc, OPUS_SET_ENERGY_MASK(value));
         }
         break;
+        case OPUS_GET_IN_DTX_REQUEST:
+        {
+            opus_int32 *value = va_arg(ap, opus_int32*);
+            if (!value)
+            {
+                goto bad_arg;
+            }
+            if (st->silk_mode.useDTX && (st->prev_mode == MODE_SILK_ONLY || st->prev_mode == MODE_HYBRID)) {
+                /* DTX determined by Silk. */
+                int n;
+                void *silk_enc = (char*)st+st->silk_enc_offset;
+                *value = 1;
+                for (n=0;n<st->silk_mode.nChannelsInternal;n++) {
+                    *value = *value && ((silk_encoder*)silk_enc)->state_Fxx[n].sCmn.noSpeechCounter >= NB_SPEECH_FRAMES_BEFORE_DTX;
+                }
+            }
+#ifndef DISABLE_FLOAT_API
+            else if (st->use_dtx) {
+                /* DTX determined by Opus. */
+                *value = st->nb_no_activity_frames >= NB_SPEECH_FRAMES_BEFORE_DTX;
+            }
+#endif
+            else {
+                *value = 0;
+            }
+        }
+        break;
 
         case CELT_GET_MODE_REQUEST:
         {
diff --git a/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/update_version b/Source/ThirdParty/libwebrtc/Source/third_party/opus/src/update_version
old mode 100644
new mode 100755