Opus wrapper: Use const for inputs and uint8[] for byte streams

About half of the functions already followed the desired pattern; this
patch fixes the other half.

BUG=909
R=aluebs@webrtc.org, bjornv@webrtc.org, henrik.lundin@webrtc.org, minyue@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7409 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h b/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h
index 11c4ac2..c134856 100644
--- a/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h
+++ b/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h
@@ -42,8 +42,11 @@
  * Return value                 : >0 - Length (in bytes) of coded data
  *                                -1 - Error
  */
-int16_t WebRtcOpus_Encode(OpusEncInst* inst, int16_t* audio_in, int16_t samples,
-                          int16_t length_encoded_buffer, uint8_t* encoded);
+int16_t WebRtcOpus_Encode(OpusEncInst* inst,
+                          const int16_t* audio_in,
+                          int16_t samples,
+                          int16_t length_encoded_buffer,
+                          uint8_t* encoded);
 
 /****************************************************************************
  * WebRtcOpus_SetBitRate(...)
@@ -190,10 +193,10 @@
 int16_t WebRtcOpus_DecodeNew(OpusDecInst* inst, const uint8_t* encoded,
                              int16_t encoded_bytes, int16_t* decoded,
                              int16_t* audio_type);
-int16_t WebRtcOpus_Decode(OpusDecInst* inst, const int16_t* encoded,
+int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded,
                           int16_t encoded_bytes, int16_t* decoded,
                           int16_t* audio_type);
-int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, const int16_t* encoded,
+int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, const uint8_t* encoded,
                                int16_t encoded_bytes, int16_t* decoded,
                                int16_t* audio_type);
 
diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c
index af581aa..0c2644b 100644
--- a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c
+++ b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c
@@ -63,17 +63,21 @@
   }
 }
 
-int16_t WebRtcOpus_Encode(OpusEncInst* inst, int16_t* audio_in, int16_t samples,
-                          int16_t length_encoded_buffer, uint8_t* encoded) {
-  opus_int16* audio = (opus_int16*) audio_in;
-  unsigned char* coded = encoded;
+int16_t WebRtcOpus_Encode(OpusEncInst* inst,
+                          const int16_t* audio_in,
+                          int16_t samples,
+                          int16_t length_encoded_buffer,
+                          uint8_t* encoded) {
   int res;
 
   if (samples > 48 * kWebRtcOpusMaxEncodeFrameSizeMs) {
     return -1;
   }
 
-  res = opus_encode(inst->encoder, audio, samples, coded,
+  res = opus_encode(inst->encoder,
+                    (const opus_int16*)audio_in,
+                    samples,
+                    encoded,
                     length_encoded_buffer);
 
   if (res > 0) {
@@ -222,13 +226,11 @@
 /* |frame_size| is set to maximum Opus frame size in the normal case, and
  * is set to the number of samples needed for PLC in case of losses.
  * It is up to the caller to make sure the value is correct. */
-static int DecodeNative(OpusDecoder* inst, const int16_t* encoded,
+static int DecodeNative(OpusDecoder* inst, const uint8_t* encoded,
                         int16_t encoded_bytes, int frame_size,
                         int16_t* decoded, int16_t* audio_type) {
-  unsigned char* coded = (unsigned char*) encoded;
-  opus_int16* audio = (opus_int16*) decoded;
-
-  int res = opus_decode(inst, coded, encoded_bytes, audio, frame_size, 0);
+  int res = opus_decode(
+      inst, encoded, encoded_bytes, (opus_int16*)decoded, frame_size, 0);
 
   /* TODO(tlegrand): set to DTX for zero-length packets? */
   *audio_type = 0;
@@ -239,13 +241,11 @@
   return -1;
 }
 
-static int DecodeFec(OpusDecoder* inst, const int16_t* encoded,
+static int DecodeFec(OpusDecoder* inst, const uint8_t* encoded,
                      int16_t encoded_bytes, int frame_size,
                      int16_t* decoded, int16_t* audio_type) {
-  unsigned char* coded = (unsigned char*) encoded;
-  opus_int16* audio = (opus_int16*) decoded;
-
-  int res = opus_decode(inst, coded, encoded_bytes, audio, frame_size, 1);
+  int res = opus_decode(
+      inst, encoded, encoded_bytes, (opus_int16*)decoded, frame_size, 1);
 
   /* TODO(tlegrand): set to DTX for zero-length packets? */
   *audio_type = 0;
@@ -259,12 +259,12 @@
 int16_t WebRtcOpus_DecodeNew(OpusDecInst* inst, const uint8_t* encoded,
                              int16_t encoded_bytes, int16_t* decoded,
                              int16_t* audio_type) {
-  int16_t* coded = (int16_t*)encoded;
-  int decoded_samples;
-
-  decoded_samples = DecodeNative(inst->decoder_left, coded, encoded_bytes,
-                                 kWebRtcOpusMaxFrameSizePerChannel,
-                                 decoded, audio_type);
+  int decoded_samples = DecodeNative(inst->decoder_left,
+                                     encoded,
+                                     encoded_bytes,
+                                     kWebRtcOpusMaxFrameSizePerChannel,
+                                     decoded,
+                                     audio_type);
   if (decoded_samples < 0) {
     return -1;
   }
@@ -275,7 +275,7 @@
   return decoded_samples;
 }
 
-int16_t WebRtcOpus_Decode(OpusDecInst* inst, const int16_t* encoded,
+int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded,
                           int16_t encoded_bytes, int16_t* decoded,
                           int16_t* audio_type) {
   int decoded_samples;
@@ -310,7 +310,7 @@
   return decoded_samples;
 }
 
-int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, const int16_t* encoded,
+int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, const uint8_t* encoded,
                                int16_t encoded_bytes, int16_t* decoded,
                                int16_t* audio_type) {
   int decoded_samples;
@@ -439,7 +439,6 @@
 int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded,
                              int16_t encoded_bytes, int16_t* decoded,
                              int16_t* audio_type) {
-  int16_t* coded = (int16_t*)encoded;
   int decoded_samples;
   int fec_samples;
 
@@ -449,7 +448,7 @@
 
   fec_samples = opus_packet_get_samples_per_frame(encoded, 48000);
 
-  decoded_samples = DecodeFec(inst->decoder_left, coded, encoded_bytes,
+  decoded_samples = DecodeFec(inst->decoder_left, encoded, encoded_bytes,
                               fec_samples, decoded, audio_type);
   if (decoded_samples < 0) {
     return -1;
diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc b/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc
index 4a0d49f..e76dcdc 100644
--- a/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc
+++ b/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc
@@ -131,7 +131,6 @@
   int16_t audio_type;
   int16_t output_data_decode_new[kOpusMaxFrameSamples];
   int16_t output_data_decode[kOpusMaxFrameSamples];
-  int16_t* coded = reinterpret_cast<int16_t*>(bitstream_);
   encoded_bytes = WebRtcOpus_Encode(opus_mono_encoder_, speech_data_,
                                     kOpus20msFrameSamples, kMaxBytes,
                                     bitstream_);
@@ -140,7 +139,7 @@
                                  encoded_bytes, output_data_decode_new,
                                  &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_Decode(opus_mono_decoder_, coded,
+            WebRtcOpus_Decode(opus_mono_decoder_, bitstream_,
                               encoded_bytes, output_data_decode,
                               &audio_type));
 
@@ -175,7 +174,6 @@
   int16_t output_data_decode_new[kOpusMaxFrameSamples];
   int16_t output_data_decode[kOpusMaxFrameSamples];
   int16_t output_data_decode_slave[kOpusMaxFrameSamples];
-  int16_t* coded = reinterpret_cast<int16_t*>(bitstream_);
   encoded_bytes = WebRtcOpus_Encode(opus_stereo_encoder_, speech_data_,
                                     kOpus20msFrameSamples, kMaxBytes,
                                     bitstream_);
@@ -184,11 +182,11 @@
                                  encoded_bytes, output_data_decode_new,
                                  &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_Decode(opus_stereo_decoder_, coded,
+            WebRtcOpus_Decode(opus_stereo_decoder_, bitstream_,
                               encoded_bytes, output_data_decode,
                               &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_DecodeSlave(opus_stereo_decoder_, coded,
+            WebRtcOpus_DecodeSlave(opus_stereo_decoder_, bitstream_,
                                    encoded_bytes, output_data_decode_slave,
                                    &audio_type));
 
@@ -259,7 +257,6 @@
   int16_t output_data_decode_new[kOpusMaxFrameSamples];
   int16_t output_data_decode[kOpusMaxFrameSamples];
   int16_t output_data_decode_slave[kOpusMaxFrameSamples];
-  int16_t* coded = reinterpret_cast<int16_t*>(bitstream_);
   encoded_bytes = WebRtcOpus_Encode(opus_stereo_encoder_, speech_data_,
                                     kOpus20msFrameSamples, kMaxBytes,
                                     bitstream_);
@@ -268,11 +265,11 @@
                                  encoded_bytes, output_data_decode_new,
                                  &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_Decode(opus_stereo_decoder_, coded,
+            WebRtcOpus_Decode(opus_stereo_decoder_, bitstream_,
                               encoded_bytes, output_data_decode,
                               &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_DecodeSlave(opus_stereo_decoder_, coded,
+            WebRtcOpus_DecodeSlave(opus_stereo_decoder_, bitstream_,
                                    encoded_bytes, output_data_decode_slave,
                                    &audio_type));
 
@@ -293,11 +290,11 @@
                                  encoded_bytes, output_data_decode_new,
                                  &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_Decode(opus_stereo_decoder_, coded,
+            WebRtcOpus_Decode(opus_stereo_decoder_, bitstream_,
                               encoded_bytes, output_data_decode,
                               &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_DecodeSlave(opus_stereo_decoder_, coded,
+            WebRtcOpus_DecodeSlave(opus_stereo_decoder_, bitstream_,
                                    encoded_bytes, output_data_decode_slave,
                                    &audio_type));
 
@@ -399,7 +396,6 @@
   int16_t audio_type;
   int16_t output_data_decode_new[kOpusMaxFrameSamples];
   int16_t output_data_decode[kOpusMaxFrameSamples];
-  int16_t* coded = reinterpret_cast<int16_t*>(bitstream_);
   encoded_bytes = WebRtcOpus_Encode(opus_mono_encoder_, speech_data_,
                                     kOpus20msFrameSamples, kMaxBytes,
                                     bitstream_);
@@ -408,7 +404,7 @@
                                  encoded_bytes, output_data_decode_new,
                                  &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_Decode(opus_mono_decoder_, coded,
+            WebRtcOpus_Decode(opus_mono_decoder_, bitstream_,
                               encoded_bytes, output_data_decode,
                               &audio_type));
 
@@ -451,7 +447,6 @@
   int16_t output_data_decode_new[kOpusMaxFrameSamples];
   int16_t output_data_decode[kOpusMaxFrameSamples];
   int16_t output_data_decode_slave[kOpusMaxFrameSamples];
-  int16_t* coded = reinterpret_cast<int16_t*>(bitstream_);
   encoded_bytes = WebRtcOpus_Encode(opus_stereo_encoder_, speech_data_,
                                     kOpus20msFrameSamples, kMaxBytes,
                                     bitstream_);
@@ -460,11 +455,11 @@
                                  encoded_bytes, output_data_decode_new,
                                  &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_Decode(opus_stereo_decoder_, coded,
+            WebRtcOpus_Decode(opus_stereo_decoder_, bitstream_,
                               encoded_bytes, output_data_decode,
                               &audio_type));
   EXPECT_EQ(kOpus20msFrameSamples,
-            WebRtcOpus_DecodeSlave(opus_stereo_decoder_, coded,
+            WebRtcOpus_DecodeSlave(opus_stereo_decoder_, bitstream_,
                                    encoded_bytes,
                                    output_data_decode_slave,
                                    &audio_type));