summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChia-chi Yeh <chiachi@android.com>2010-09-29 10:36:52 +0800
committerChia-chi Yeh <chiachi@android.com>2010-09-29 10:36:52 +0800
commita6f950c9682ffffc00ca976aafeeedf391718b1d (patch)
tree214050021aa67943f35439c2a6a50497f7e58f1a
parent78c11b3cf170fdd35ff6984bc2a64c01e2457503 (diff)
downloadframeworks_base-a6f950c9682ffffc00ca976aafeeedf391718b1d.zip
frameworks_base-a6f950c9682ffffc00ca976aafeeedf391718b1d.tar.gz
frameworks_base-a6f950c9682ffffc00ca976aafeeedf391718b1d.tar.bz2
RTP: Enable GSM codec.
Change-Id: Iae1913fb0643f1c66b5d16f24d51924d363e5ef5
-rw-r--r--voip/java/android/net/rtp/AudioCodec.java2
-rw-r--r--voip/jni/rtp/Android.mk10
-rw-r--r--voip/jni/rtp/AudioCodec.cpp2
-rw-r--r--voip/jni/rtp/GsmCodec.cpp74
4 files changed, 84 insertions, 4 deletions
diff --git a/voip/java/android/net/rtp/AudioCodec.java b/voip/java/android/net/rtp/AudioCodec.java
index 4851a46..dfa6841 100644
--- a/voip/java/android/net/rtp/AudioCodec.java
+++ b/voip/java/android/net/rtp/AudioCodec.java
@@ -81,7 +81,7 @@ public class AudioCodec {
public static final AudioCodec AMR = new AudioCodec(97, "AMR/8000", null);
// TODO: add rest of the codecs when the native part is done.
- private static final AudioCodec[] sCodecs = {PCMU, PCMA};
+ private static final AudioCodec[] sCodecs = {GSM, PCMU, PCMA};
private AudioCodec(int type, String rtpmap, String fmtp) {
this.type = type;
diff --git a/voip/jni/rtp/Android.mk b/voip/jni/rtp/Android.mk
index 69afd49..29683bd 100644
--- a/voip/jni/rtp/Android.mk
+++ b/voip/jni/rtp/Android.mk
@@ -22,21 +22,25 @@ LOCAL_MODULE := librtp_jni
LOCAL_SRC_FILES := \
AudioCodec.cpp \
AudioGroup.cpp \
- G711Codec.cpp \
RtpStream.cpp \
util.cpp \
rtp_jni.cpp
+LOCAL_SRC_FILES += \
+ G711Codec.cpp \
+ GsmCodec.cpp
+
LOCAL_SHARED_LIBRARIES := \
libnativehelper \
libcutils \
libutils \
libmedia
-LOCAL_STATIC_LIBRARIES :=
+LOCAL_STATIC_LIBRARIES := libgsm
LOCAL_C_INCLUDES += \
- $(JNI_H_INCLUDE)
+ $(JNI_H_INCLUDE) \
+ external/libgsm/inc
LOCAL_CFLAGS += -fvisibility=hidden
diff --git a/voip/jni/rtp/AudioCodec.cpp b/voip/jni/rtp/AudioCodec.cpp
index 8912d82..fc33ef2 100644
--- a/voip/jni/rtp/AudioCodec.cpp
+++ b/voip/jni/rtp/AudioCodec.cpp
@@ -20,6 +20,7 @@
extern AudioCodec *newAlawCodec();
extern AudioCodec *newUlawCodec();
+extern AudioCodec *newGsmCodec();
struct AudioCodecType {
const char *name;
@@ -27,6 +28,7 @@ struct AudioCodecType {
} gAudioCodecTypes[] = {
{"PCMA", newAlawCodec},
{"PCMU", newUlawCodec},
+ {"GSM", newGsmCodec},
{NULL, NULL},
};
diff --git a/voip/jni/rtp/GsmCodec.cpp b/voip/jni/rtp/GsmCodec.cpp
new file mode 100644
index 0000000..8d2286e
--- /dev/null
+++ b/voip/jni/rtp/GsmCodec.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyrightm (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "AudioCodec.h"
+
+extern "C" {
+#include "gsm.h"
+}
+
+namespace {
+
+class GsmCodec : public AudioCodec
+{
+public:
+ GsmCodec() {
+ mEncode = gsm_create();
+ mDecode = gsm_create();
+ }
+
+ ~GsmCodec() {
+ if (mEncode) {
+ gsm_destroy(mEncode);
+ }
+ if (mDecode) {
+ gsm_destroy(mDecode);
+ }
+ }
+
+ int set(int sampleRate, const char *fmtp) {
+ return (sampleRate == 8000 && mEncode && mDecode) ? 160 : -1;
+ }
+
+ int encode(void *payload, int16_t *samples);
+ int decode(int16_t *samples, void *payload, int length);
+
+private:
+ gsm mEncode;
+ gsm mDecode;
+};
+
+int GsmCodec::encode(void *payload, int16_t *samples)
+{
+ gsm_encode(mEncode, samples, (unsigned char *)payload);
+ return 33;
+}
+
+int GsmCodec::decode(int16_t *samples, void *payload, int length)
+{
+ if (length == 33 &&
+ gsm_decode(mDecode, (unsigned char *)payload, samples) == 0) {
+ return 160;
+ }
+ return -1;
+}
+
+} // namespace
+
+AudioCodec *newGsmCodec()
+{
+ return new GsmCodec;
+}