RTP: Enable GSM codec.

Change-Id: Iae1913fb0643f1c66b5d16f24d51924d363e5ef5
This commit is contained in:
Chia-chi Yeh
2010-09-29 10:36:52 +08:00
parent 78c11b3cf1
commit a6f950c968
4 changed files with 84 additions and 4 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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},
};

74
voip/jni/rtp/GsmCodec.cpp Normal file
View File

@@ -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;
}