Implement AudioEncoderPcmU/A classes and convert AudioDecoder tests

BUG=3926
R=kjellander@webrtc.org, kwiberg@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7481 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder.h b/webrtc/modules/audio_coding/codecs/audio_encoder.h
index 1569caf..f8142e2 100644
--- a/webrtc/modules/audio_coding/codecs/audio_encoder.h
+++ b/webrtc/modules/audio_coding/codecs/audio_encoder.h
@@ -12,7 +12,6 @@
 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_
 
 #include <algorithm>
-#include <limits>
 
 #include "webrtc/base/checks.h"
 #include "webrtc/typedefs.h"
@@ -28,24 +27,27 @@
   // Accepts one 10 ms block of input audio (i.e., sample_rate_hz() / 100 *
   // num_channels() samples). Multi-channel audio must be sample-interleaved.
   // If successful, the encoder produces zero or more bytes of output in
-  // |encoded|, and returns the number of bytes. In case of error, -1 is
-  // returned. It is an error for the encoder to attempt to produce more than
-  // |max_encoded_bytes| bytes of output.
-  ssize_t Encode(uint32_t timestamp,
-                 const int16_t* audio,
-                 size_t num_samples,
-                 size_t max_encoded_bytes,
-                 uint8_t* encoded,
-                 uint32_t* encoded_timestamp) {
+  // |encoded|, and provides the number of encoded bytes in |encoded_bytes|.
+  // In case of error, false is returned, otherwise true. It is an error for the
+  // encoder to attempt to produce more than |max_encoded_bytes| bytes of
+  // output.
+  bool Encode(uint32_t timestamp,
+              const int16_t* audio,
+              size_t num_samples,
+              size_t max_encoded_bytes,
+              uint8_t* encoded,
+              size_t* encoded_bytes,
+              uint32_t* encoded_timestamp) {
     CHECK_EQ(num_samples,
              static_cast<size_t>(sample_rate_hz() / 100 * num_channels()));
-    ssize_t num_bytes =
-        Encode(timestamp, audio, max_encoded_bytes, encoded, encoded_timestamp);
-    CHECK_LE(num_bytes,
-             static_cast<ssize_t>(std::min(
-                 max_encoded_bytes,
-                 static_cast<size_t>(std::numeric_limits<ssize_t>::max()))));
-    return num_bytes;
+    bool ret = Encode(timestamp,
+                      audio,
+                      max_encoded_bytes,
+                      encoded,
+                      encoded_bytes,
+                      encoded_timestamp);
+    CHECK_LE(*encoded_bytes, max_encoded_bytes);
+    return ret;
   }
 
   // Returns the input sample rate in Hz, the number of input channels, and the
@@ -56,11 +58,12 @@
   virtual int num_10ms_frames_per_packet() const = 0;
 
  protected:
-  virtual ssize_t Encode(uint32_t timestamp,
-                         const int16_t* audio,
-                         size_t max_encoded_bytes,
-                         uint8_t* encoded,
-                         uint32_t* encoded_timestamp) = 0;
+  virtual bool Encode(uint32_t timestamp,
+                      const int16_t* audio,
+                      size_t max_encoded_bytes,
+                      uint8_t* encoded,
+                      size_t* encoded_bytes,
+                      uint32_t* encoded_timestamp) = 0;
 };
 
 }  // namespace webrtc