Revert 7266 "WebRtcIsac_Encode and WebRtcIsacfix_Encode: Type en..."

This was causing apparently legitimate failures on the following bots:
http://chromegw/i/client.webrtc/builders/Linux64%20Release%20%5Blarge%20tests%5D/builds/2599
http://chromegw/i/client.webrtc/builders/Android%20Tests%20%28KK%20Nexus5%29%28dbg%29/builds/2023
http://chromegw/i/client.webrtc/builders/Android%20Tests%20%28JB%20Nexus7.2%29%28dbg%29/builds/1825
http://chromegw/i/client.webrtc/builders/Android%20Tests%20%28KK%20Nexus5%29/builds/2013
http://chromegw/i/client.webrtc/builders/Android%20Tests%20%28JB%20Nexus7.2%29/builds/1795

> WebRtcIsac_Encode and WebRtcIsacfix_Encode: Type encoded stream as uint8_t
> 
> We have to fix both at once, since there's a macro that calls one of
> them or the other.
> 
> BUG=909
> R=andrew@webrtc.org, bjornv@webrtc.org, henrik.lundin@webrtc.org, minyue@webrtc.org
> 
> Review URL: https://webrtc-codereview.appspot.com/19229004

TBR=kwiberg@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/30519004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7267 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h b/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h
index 942727a..7cd2954 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h
@@ -130,7 +130,7 @@
 
   int16_t WebRtcIsacfix_Encode(ISACFIX_MainStruct *ISAC_main_inst,
                                const int16_t *speechIn,
-                               uint8_t* encoded);
+                               int16_t *encoded);
 
 
 
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c b/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c
index 48631b5..e855dae 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/source/isacfix.c
@@ -17,7 +17,6 @@
 
 #include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h"
 
-#include <assert.h>
 #include <stdlib.h>
 
 #include "webrtc/modules/audio_coding/codecs/isac/fix/source/bandwidth_estimator.h"
@@ -356,7 +355,7 @@
 
 int16_t WebRtcIsacfix_Encode(ISACFIX_MainStruct *ISAC_main_inst,
                              const int16_t    *speechIn,
-                             uint8_t* encoded)
+                             int16_t          *encoded)
 {
   ISACFIX_SubStruct *ISAC_inst;
   int16_t stream_len;
@@ -383,20 +382,16 @@
     return -1;
   }
 
-  assert(stream_len % 2 == 0);
+
+  /* convert from bytes to int16_t */
 #ifndef WEBRTC_ARCH_BIG_ENDIAN
-  /* The encoded data vector is supposesd to be big-endian, but our internal
-     representation is little-endian. So byteswap. */
-  for (k = 0; k < stream_len / 2; ++k) {
-    uint16_t s = ISAC_inst->ISACenc_obj.bitstr_obj.stream[k];
-    /* In big-endian, we have... */
-    encoded[2 * k] = s >> 8;  /* ...most significant byte at low address... */
-    encoded[2 * k + 1] = s;  /* ...least significant byte at high address. */
+  for (k=0;k<(stream_len+1)>>1;k++) {
+    encoded[k] = (int16_t)( ( (uint16_t)(ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] >> 8 )
+                                  | (((ISAC_inst->ISACenc_obj.bitstr_obj).stream[k] & 0x00FF) << 8));
   }
+
 #else
-  /* The encoded data vector and our internal representation are both
-     big-endian. */
-  memcpy(encoded, ISAC_inst->ISACenc_obj.bitstr_obj.stream, stream_len);
+  WEBRTC_SPL_MEMCPY_W16(encoded, (ISAC_inst->ISACenc_obj.bitstr_obj).stream, (stream_len + 1)>>1);
 #endif
 
 
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/test/isac_speed_test.cc b/webrtc/modules/audio_coding/codecs/isac/fix/test/isac_speed_test.cc
index 207ee8c..3582751 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/test/isac_speed_test.cc
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/test/isac_speed_test.cc
@@ -71,7 +71,7 @@
   size_t pointer = 0;
   for (int idx = 0; idx < subblocks; idx++, pointer += subblock_length) {
     value = WebRtcIsacfix_Encode(ISACFIX_main_inst_, &in_data[pointer],
-                                 bit_stream);
+                                 reinterpret_cast<int16_t*>(bit_stream));
   }
   clocks = clock() - clocks;
   EXPECT_GT(value, 0);
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc b/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc
index 91c4d76..c3c6f13 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/test/kenny.cc
@@ -565,7 +565,7 @@
           /* Encode */
           stream_len = WebRtcIsacfix_Encode(ISAC_main_inst,
                                             shortdata,
-                                            (uint8_t*)streamdata);
+                                            (int16_t*)streamdata);
 
           /* If packet is ready, and CE testing, call the different API
              functions from the internal API. */
diff --git a/webrtc/modules/audio_coding/codecs/isac/fix/test/test_iSACfixfloat.c b/webrtc/modules/audio_coding/codecs/isac/fix/test/test_iSACfixfloat.c
index 965f2bc..d5682b2 100644
--- a/webrtc/modules/audio_coding/codecs/isac/fix/test/test_iSACfixfloat.c
+++ b/webrtc/modules/audio_coding/codecs/isac/fix/test/test_iSACfixfloat.c
@@ -439,9 +439,7 @@
 			/* iSAC encoding */
 
 			if (mode==0 || mode ==1) {
-                          stream_len = WebRtcIsac_Encode(ISAC_main_inst,
-                                                         shortdata,
-                                                         (uint8_t*)streamdata);
+				stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata,	streamdata);
 				if (stream_len < 0) {
 					/* exit if returned with error */
 					errtype=WebRtcIsac_GetErrorCode(ISAC_main_inst);
@@ -451,10 +449,7 @@
 			} else if (mode==2 || mode==3) {
 				/* iSAC encoding */
 				if (nbTest != 1)
-                                  stream_len = WebRtcIsacfix_Encode(
-                                      ISACFIX_main_inst,
-                                      shortdata,
-                                      (uint8_t*)streamdata);
+					stream_len = WebRtcIsacfix_Encode(ISACFIX_main_inst, shortdata,	streamdata);
 				else
 					stream_len = WebRtcIsacfix_EncodeNb(ISACFIX_main_inst, shortdata, streamdata);
 		
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h b/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h
index 4067058..76a61e6 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h
+++ b/webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h
@@ -147,7 +147,7 @@
   int16_t WebRtcIsac_Encode(
       ISACStruct*        ISAC_main_inst,
       const int16_t* speechIn,
-      uint8_t* encoded);
+      int16_t*       encoded);
 
 
   /******************************************************************************
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c b/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c
index 13170a0..d47eb80 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c
+++ b/webrtc/modules/audio_coding/codecs/isac/main/source/isac.c
@@ -496,7 +496,7 @@
  */
 int16_t WebRtcIsac_Encode(ISACStruct* ISAC_main_inst,
                           const int16_t* speechIn,
-                          uint8_t* encoded) {
+                          int16_t* encoded) {
   float inFrame[FRAMESAMPLES_10ms];
   int16_t speechInLB[FRAMESAMPLES_10ms];
   int16_t speechInUB[FRAMESAMPLES_10ms];
@@ -504,6 +504,7 @@
   int16_t streamLenUB = 0;
   int16_t streamLen = 0;
   int16_t k = 0;
+  uint8_t* ptrEncodedUW8 = (uint8_t*)encoded;
   int garbageLen = 0;
   int32_t bottleneck = 0;
   int16_t bottleneckIdx = 0;
@@ -642,22 +643,23 @@
       streamLenUB = 0;
     }
 
-    memcpy(encoded, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB);
+    memcpy(ptrEncodedUW8, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB);
     streamLen = streamLenLB;
     if (streamLenUB > 0) {
-      encoded[streamLenLB] = streamLenUB + 1 + LEN_CHECK_SUM_WORD8;
-      memcpy(&encoded[streamLenLB + 1],
-             instUB->ISACencUB_obj.bitstr_obj.stream,
-             streamLenUB);
-      streamLen += encoded[streamLenLB];
+      ptrEncodedUW8[streamLenLB] = (uint8_t)(streamLenUB + 1 +
+                                                   LEN_CHECK_SUM_WORD8);
+      memcpy(&ptrEncodedUW8[streamLenLB + 1],
+             instUB->ISACencUB_obj.bitstr_obj.stream, streamLenUB);
+      streamLen += ptrEncodedUW8[streamLenLB];
     } else {
-      encoded[streamLenLB] = 0;
+      ptrEncodedUW8[streamLenLB] = 0;
     }
   } else {
     if (streamLenLB == 0) {
       return 0;
     }
-    memcpy(encoded, instLB->ISACencLB_obj.bitstr_obj.stream, streamLenLB);
+    memcpy(ptrEncodedUW8, instLB->ISACencLB_obj.bitstr_obj.stream,
+           streamLenLB);
     streamLenUB = 0;
     streamLen = streamLenLB;
   }
@@ -695,11 +697,11 @@
      * 255 is the max garbage length we can signal using 8 bits. */
     if ((instISAC->bandwidthKHz == isac8kHz) ||
         (streamLenUB == 0)) {
-      ptrGarbage = &encoded[streamLenLB];
+      ptrGarbage = &ptrEncodedUW8[streamLenLB];
       limit = streamLen + 255;
     } else {
-      ptrGarbage = &encoded[streamLenLB + 1 + streamLenUB];
-      limit = streamLen + (255 - encoded[streamLenLB]);
+      ptrGarbage = &ptrEncodedUW8[streamLenLB + 1 + streamLenUB];
+      limit = streamLen + (255 - ptrEncodedUW8[streamLenLB]);
     }
     minBytes = (minBytes > limit) ? limit : minBytes;
 
@@ -716,12 +718,13 @@
        * That is the only way to preserve backward compatibility. */
       if ((instISAC->bandwidthKHz == isac8kHz) ||
           (streamLenUB == 0)) {
-        encoded[streamLenLB] = garbageLen;
+        ptrEncodedUW8[streamLenLB] = (uint8_t)garbageLen;
       } else {
-        encoded[streamLenLB] += garbageLen;
+        ptrEncodedUW8[streamLenLB] += (uint8_t)garbageLen;
         /* Write the length of the garbage at the end of the upper-band
          *  bit-stream, if exists. This helps for sanity check. */
-        encoded[streamLenLB + 1 + streamLenUB] = garbageLen;
+        ptrEncodedUW8[streamLenLB + 1 + streamLenUB] =
+            (uint8_t)garbageLen;
 
       }
       streamLen += garbageLen;
@@ -738,14 +741,16 @@
   if ((instISAC->bandwidthKHz != isac8kHz) && (streamLenUB > 0)) {
     uint32_t crc;
 
-    WebRtcIsac_GetCrc((int16_t*)(&(encoded[streamLenLB + 1])),
+    WebRtcIsac_GetCrc((int16_t*)(&(ptrEncodedUW8[streamLenLB + 1])),
                       streamLenUB + garbageLen, &crc);
 #ifndef WEBRTC_ARCH_BIG_ENDIAN
     for (k = 0; k < LEN_CHECK_SUM_WORD8; k++) {
-      encoded[streamLen - LEN_CHECK_SUM_WORD8 + k] = crc >> (24 - k * 8);
+      ptrEncodedUW8[streamLen - LEN_CHECK_SUM_WORD8 + k] =
+        (uint8_t)((crc >> (24 - k * 8)) & 0xFF);
     }
 #else
-    memcpy(&encoded[streamLenLB + streamLenUB + 1], &crc, LEN_CHECK_SUM_WORD8);
+    memcpy(&ptrEncodedUW8[streamLenLB + streamLenUB + 1], &crc,
+           LEN_CHECK_SUM_WORD8);
 #endif
   }
   return streamLen;
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/source/isac_unittest.cc b/webrtc/modules/audio_coding/codecs/isac/main/source/isac_unittest.cc
index 1d65373..3c55bd3 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/source/isac_unittest.cc
+++ b/webrtc/modules/audio_coding/codecs/isac/main/source/isac_unittest.cc
@@ -31,7 +31,7 @@
 
   int16_t speech_data_[kIsacNumberOfSamples];
   int16_t output_data_[kIsacNumberOfSamples];
-  uint8_t bitstream_[kMaxBytes];
+  int16_t bitstream_[kMaxBytes / 2];
   uint8_t bitstream_small_[7];  // Simulate sync packets.
 };
 
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc b/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc
index 8af4e6f..c5f9561 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc
+++ b/webrtc/modules/audio_coding/codecs/isac/main/test/ReleaseTest-API/ReleaseTest-API.cc
@@ -662,8 +662,8 @@
             if(!(testNum == 3 && framecnt == 0))
             {
                 stream_len = WebRtcIsac_Encode(ISAC_main_inst,
-                                               shortdata,
-                                               (uint8_t*)streamdata);
+                    shortdata,
+                    (int16_t*)streamdata);
                 if((payloadSize != 0) && (stream_len > payloadSize))
                 {
                     if(testNum == 0)
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc b/webrtc/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc
index 72d3fe8..fd70eca 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc
+++ b/webrtc/modules/audio_coding/codecs/isac/main/test/SwitchingSampRate/SwitchingSampRate.cc
@@ -283,8 +283,7 @@
 
 
       streamLen = WebRtcIsac_Encode(codecInstance[senderIdx],
-                                    audioBuff10ms,
-                                    (uint8_t*)bitStream);
+                                    audioBuff10ms, (short*)bitStream);
       int16_t ggg;
       if (streamLen > 0) {
         if((  WebRtcIsac_ReadFrameLen(codecInstance[receiverIdx],
diff --git a/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c b/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c
index 2df5a84..980465d 100644
--- a/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c
+++ b/webrtc/modules/audio_coding/codecs/isac/main/test/simpleKenny.c
@@ -373,10 +373,8 @@
 				cur_framesmpls += samplesIn10Ms;
 
 				//-------- iSAC encoding ---------
-                                stream_len = WebRtcIsac_Encode(
-                                        ISAC_main_inst,
-                                        shortdata,
-                                        (uint8_t*)payload);
+				stream_len = WebRtcIsac_Encode(ISAC_main_inst, shortdata,
+					(int16_t*)payload);
 
 				if(stream_len < 0)
 				{
diff --git a/webrtc/modules/audio_coding/main/acm2/acm_isac.cc b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc
index f3682f1..850204f 100644
--- a/webrtc/modules/audio_coding/main/acm2/acm_isac.cc
+++ b/webrtc/modules/audio_coding/main/acm2/acm_isac.cc
@@ -347,9 +347,8 @@
       return -1;
     }
     *bitstream_len_byte = ACM_ISAC_ENCODE(
-        codec_inst_ptr_->inst,
-        &in_audio_[in_audio_ix_read_],
-        bitstream);
+        codec_inst_ptr_->inst, &in_audio_[in_audio_ix_read_],
+        reinterpret_cast<int16_t*>(bitstream));
     // increment the read index this tell the caller that how far
     // we have gone forward in reading the audio buffer
     in_audio_ix_read_ += samples_in_10ms_audio_;
diff --git a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc
index 624e6a4..d33c8f2 100644
--- a/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq/audio_decoder_unittest.cc
@@ -348,11 +348,14 @@
   virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
                           uint8_t* output) {
     // Insert 3 * 10 ms. Expect non-zero output on third call.
-    EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input, output));
+    EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input,
+                                   reinterpret_cast<int16_t*>(output)));
     input += input_size_;
-    EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input, output));
+    EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input,
+                                   reinterpret_cast<int16_t*>(output)));
     input += input_size_;
-    int enc_len_bytes = WebRtcIsac_Encode(encoder_, input, output);
+    int enc_len_bytes =
+        WebRtcIsac_Encode(encoder_, input, reinterpret_cast<int16_t*>(output));
     EXPECT_GT(enc_len_bytes, 0);
     return enc_len_bytes;
   }
@@ -385,11 +388,14 @@
   virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
                           uint8_t* output) {
     // Insert 3 * 10 ms. Expect non-zero output on third call.
-    EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input, output));
+    EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input,
+                                   reinterpret_cast<int16_t*>(output)));
     input += input_size_;
-    EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input, output));
+    EXPECT_EQ(0, WebRtcIsac_Encode(encoder_, input,
+                                   reinterpret_cast<int16_t*>(output)));
     input += input_size_;
-    int enc_len_bytes = WebRtcIsac_Encode(encoder_, input, output);
+    int enc_len_bytes =
+        WebRtcIsac_Encode(encoder_, input, reinterpret_cast<int16_t*>(output));
     EXPECT_GT(enc_len_bytes, 0);
     return enc_len_bytes;
   }
@@ -435,11 +441,14 @@
   virtual int EncodeFrame(const int16_t* input, size_t input_len_samples,
                           uint8_t* output) {
     // Insert 3 * 10 ms. Expect non-zero output on third call.
-    EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input, output));
+    EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input,
+                                      reinterpret_cast<int16_t*>(output)));
     input += input_size_;
-    EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input, output));
+    EXPECT_EQ(0, WebRtcIsacfix_Encode(encoder_, input,
+                                      reinterpret_cast<int16_t*>(output)));
     input += input_size_;
-    int enc_len_bytes = WebRtcIsacfix_Encode(encoder_, input, output);
+    int enc_len_bytes = WebRtcIsacfix_Encode(
+        encoder_, input, reinterpret_cast<int16_t*>(output));
     EXPECT_GT(enc_len_bytes, 0);
     return enc_len_bytes;
   }
diff --git a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc
index 92bccee..93b366b 100644
--- a/webrtc/modules/audio_coding/neteq/test/RTPencode.cc
+++ b/webrtc/modules/audio_coding/neteq/test/RTPencode.cc
@@ -1632,13 +1632,9 @@
             cdlen=0;
             while (cdlen<=0) {
 #ifdef CODEC_ISAC /* floating point */
-                cdlen = WebRtcIsac_Encode(ISAC_inst[k],
-                                          &indata[noOfCalls * 160],
-                                          encoded);
+                cdlen=WebRtcIsac_Encode(ISAC_inst[k],&indata[noOfCalls*160],(int16_t*)encoded);
 #else /* fixed point */
-                cdlen = WebRtcIsacfix_Encode(ISAC_inst[k],
-                                             &indata[noOfCalls * 160],
-                                             encoded);
+                cdlen=WebRtcIsacfix_Encode(ISAC_inst[k],&indata[noOfCalls*160],(int16_t*)encoded);
 #endif
                 noOfCalls++;
             }
@@ -1649,9 +1645,7 @@
             int noOfCalls=0;
             cdlen=0;
             while (cdlen<=0) {
-                cdlen = WebRtcIsac_Encode(ISACSWB_inst[k],
-                                          &indata[noOfCalls * 320],
-                                          encoded);
+                cdlen=WebRtcIsac_Encode(ISACSWB_inst[k],&indata[noOfCalls*320],(int16_t*)encoded);
                 noOfCalls++;
             }
         }
diff --git a/webrtc/modules/audio_coding/neteq/test/neteq_isac_quality_test.cc b/webrtc/modules/audio_coding/neteq/test/neteq_isac_quality_test.cc
index b672a0c..6b0f482 100644
--- a/webrtc/modules/audio_coding/neteq/test/neteq_isac_quality_test.cc
+++ b/webrtc/modules/audio_coding/neteq/test/neteq_isac_quality_test.cc
@@ -138,7 +138,8 @@
     // The Isac encoder does not perform encoding (and returns 0) until it
     // receives a sequence of sub-blocks that amount to the frame duration.
     EXPECT_EQ(0, value);
-    value = WebRtcIsacfix_Encode(isac_encoder_, &in_data[pointer], payload);
+    value = WebRtcIsacfix_Encode(isac_encoder_, &in_data[pointer],
+                                 reinterpret_cast<int16_t*>(payload));
   }
   EXPECT_GT(value, 0);
   return value;