summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhenrik.lundin@webrtc.org <henrik.lundin@webrtc.org>2014-10-16 11:26:24 +0000
committerhenrik.lundin@webrtc.org <henrik.lundin@webrtc.org>2014-10-16 11:26:24 +0000
commit3d4c452f885d5c075095c1df3dcbfb8aaf4e46af (patch)
tree98aba9018f6040b04d4e12b298d588736dca3aa0
parent787e3f1e9bb6cec351466876f79a612debd38fbb (diff)
downloadwebrtc-3d4c452f885d5c075095c1df3dcbfb8aaf4e46af.tar.gz
New interface class AudioEncoder
This class will be the base for new C++ wrapper classes for all encoders. BUG=3926 TBR=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/23999004 git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@7463 4adac7df-926f-26a2-2b94-8c16560cd09d
-rw-r--r--modules/audio_coding/codecs/audio_encoder.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/modules/audio_coding/codecs/audio_encoder.h b/modules/audio_coding/codecs/audio_encoder.h
new file mode 100644
index 00000000..0d446bcb
--- /dev/null
+++ b/modules/audio_coding/codecs/audio_encoder.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_
+#define WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_
+
+#include <algorithm>
+#include <limits>
+
+#include "webrtc/base/checks.h"
+#include "webrtc/typedefs.h"
+
+namespace webrtc {
+
+// This is the interface class for encoders in AudioCoding module. Each codec
+// codec type must have an implementation of this class.
+class AudioEncoder {
+ public:
+ virtual ~AudioEncoder() {}
+
+ // 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) {
+ 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);
+ 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;
+ }
+
+ // Returns the input sample rate in Hz, the number of input channels, and the
+ // number of 10 ms frames the encoder puts in one output packet. These are
+ // constants set at instantiation time.
+ virtual int sample_rate_hz() const = 0;
+ virtual int num_channels() const = 0;
+ 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) = 0;
+};
+
+} // namespace webrtc
+#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_