1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.sipdroid.codecs;

import org.sipdroid.sipua.ui.Receiver;
import org.sipdroid.sipua.ui.Settings;
import org.sipdroid.sipua.ui.Sipdroid;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

class G729 extends CodecBase implements Codec {

  G729() {
    CODEC_NAME = "G729";
    CODEC_USER_NAME = "G729";
    CODEC_DESCRIPTION = "8kbit";
    CODEC_NUMBER = 18;
    CODEC_DEFAULT_SETTING = "always";
    /* up convert original compression parameter for this codec */
    SharedPreferences sp = PreferenceManager
        .getDefaultSharedPreferences(Receiver.mContext);
    String pref = sp.getString(Settings.PREF_COMPRESSION,
        Settings.DEFAULT_COMPRESSION);
    if (pref != null) {
      SharedPreferences.Editor e = sp.edit();
      e.remove("compression");
      e.putString(CODEC_NAME, pref);
      e.commit();
    }
    super.update();
  }

  void load() {
    try {
      System.loadLibrary("g729_jni");
      super.load();
    } catch (Throwable e) {
      if (!Sipdroid.release)
        e.printStackTrace();
    }

  }

  public native int open();

  public native int decode(byte encoded[], short lin[], int size);

  public native int encode(short lin[], int offset, byte encoded[], int size);

  public native void close();

  public void init() {
    load();
    if (isLoaded())
      open();
  }

}