Skip to content

Commit db3e892

Browse files
author
jejbgo
committed
sipdroid: redo codec infrastructure to support arbitrary codecs
Instead of having the GSM codec as special, this patch uses a plugin infrastructure to support the adding of arbitrary codecs to Siproid. It also changes the way users select codecs by adding a new 'Audio Codecs' preference screen and allowing them to select for each codec when it will be used (always, edge only or never) and also allowing them to change the order in which codecs are presented to the other end. This code also fixes a bug in the original implementation where on an incoming call, we could be presented with a codec we support that actually has a different media identifier number in the session descriptor. On incoming, it is the remote who chooses the media identifier numbers to use, so we have to do a string comparison to see if we support it and then globally use the remote's media identifier number. I also added the codec being used to the in call screen and a long delay call disconnect dialog if we find a codec mismatch on either incoming or outgoing. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
1 parent 8906ce4 commit db3e892

20 files changed

Lines changed: 839 additions & 201 deletions

AndroidManifest.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
<activity android:name=".ui.Settings" android:label="@string/app_name"
7676
android:excludeFromRecents="true" android:taskAffinity="">
7777
</activity>
78+
<activity
79+
android:name="org.sipdroid.codecs.Codecs$CodecSettings"
80+
android:label="@string/app_name" >
81+
</activity>
7882
<activity android:name=".ui.VideoCamera" android:label="@string/menu_video"
7983
android:excludeFromRecents="true" android:taskAffinity=""
8084
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
@@ -118,4 +122,4 @@
118122
<uses-permission android:name="android.permission.VIBRATE" ></uses-permission>
119123
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
120124
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" ></uses-permission>
121-
</manifest>
125+
</manifest>

res/layout/incall.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ xmlns:android="http://schemas.android.com/apk/res/android"
9898
android:layout_width="wrap_content"
9999
android:layout_height="wrap_content"
100100
/>
101+
<TextView
102+
android:id="@+id/codec"
103+
android:layout_gravity="center_horizontal"
104+
android:gravity="center_horizontal"
105+
android:textAppearance="?android:attr/textAppearanceMedium"
106+
android:textColor="?android:attr/textColorSecondary"
107+
android:layout_width="wrap_content"
108+
android:layout_height="wrap_content"
109+
/>
101110
</LinearLayout>
102111

103112
</RelativeLayout> <!-- End of inCallPanel -->

res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
<string name="card_title_in_progress">Call in progress</string>
237237
<string name="card_title_incoming_call">Incoming call</string>
238238
<string name="card_title_call_ended">Call ended</string>
239+
<string name="card_title_ended_no_codec">ERROR: Codecs Incompatible</string>
239240
<string name="card_title_on_hold">On hold</string>
240241

241242
<string name="unknown">Unknown</string>
@@ -245,4 +246,10 @@
245246

246247
<string name="ongoing">Current Call</string>
247248
<string name="onHold">On hold</string>
249+
<string name="codecs">Audio Codecs</string>
250+
<string name="codecs_summary">Select Audio Codecs to be available for voice calls</string>
251+
<string name="codecs_move">Move this codec</string>
252+
<string name="codecs_move_up">Move up one place</string>
253+
<string name="codecs_move_down">Move down one place</string>
254+
<string name="cancel">Cancel</string>
248255
</resources>

res/xml/codec_settings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<PreferenceScreen
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:key="codecs"
4+
android:title="@string/codecs">
5+
</PreferenceScreen>

res/xml/preferences.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<PreferenceScreen
22
xmlns:android="http://schemas.android.com/apk/res/android">
3-
3+
44
<PreferenceScreen android:title="@string/settings_account">
55
<EditTextPreference
66
android:key="username"
@@ -58,13 +58,6 @@
5858
android:entryValues="@array/pref_values"
5959
android:summary="@string/settings_pref2"
6060
android:dialogTitle="@string/settings_pref" />
61-
<ListPreference
62-
android:key="compression"
63-
android:title="@string/settings_compression"
64-
android:entries="@array/compression_display_values"
65-
android:entryValues="@array/compression_values"
66-
android:defaultValue="edge"
67-
android:dialogTitle="@string/settings_compression" />
6861
<CheckBoxPreference
6962
android:key="auto_on"
7063
android:title="@string/settings_auto_on"
@@ -184,4 +177,13 @@
184177
android:hint="Accessno.,PIN#"
185178
android:singleLine="true" />
186179
</PreferenceScreen>
180+
<PreferenceScreen
181+
android:key="codecs"
182+
android:title="@string/codecs" >
183+
<intent
184+
android:action="android.intent.action.MAIN"
185+
android:targetPackage="org.sipdroid.sipua"
186+
android:targetClass="org.sipdroid.codecs.Codecs$CodecSettings" />
187+
188+
</PreferenceScreen>
187189
</PreferenceScreen>

src/org/sipdroid/codecs/Codec.java

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package org.sipdroid.codecs;
2+
3+
import android.preference.ListPreference;
4+
5+
/**
6+
* Represents the basic interface to the Codec classes All codecs need
7+
* to implement basic encode and decode capability Codecs which
8+
* inherit from {@link CodecBase} only need to implement encode,
9+
* decode and init
10+
*/
11+
public interface Codec {
12+
/**
13+
* Decode a linear pcm audio stream
14+
*
15+
* @param encoded The encoded audio stream
16+
*
17+
* @param lin The linear pcm audio frame buffer in which to place the decoded stream
18+
*
19+
* @param size The size of the encoded frame
20+
*
21+
* @returns The size of the decoded frame
22+
*/
23+
int decode(byte encoded[], short lin[], int size);
24+
25+
/**
26+
* Encode a linear pcm audio stream
27+
*
28+
* @param lin The linear stream to encode
29+
*
30+
* @param offset The offset into the linear stream to begin
31+
*
32+
* @param encoded The buffer to place the encoded stream
33+
*
34+
* @param size the size of the linear pcm stream (in words)
35+
*
36+
* @returns the length (in bytes) of the encoded stream
37+
*/
38+
int encode(short lin[], int offset, byte alaw[], int frames);
39+
40+
/**
41+
* Optionally used to initiallize the codec before any
42+
* encoding or decoding
43+
*/
44+
void init();
45+
46+
/**
47+
* Optionally used to free any resources allocated in init
48+
* after encoding or decoding is complete
49+
*/
50+
void close();
51+
52+
/**
53+
* (implemented by {@link CodecBase}
54+
* <p>
55+
* checks to see if the user has enabled the codec.
56+
*
57+
* @returns true if the codec can be used
58+
*/
59+
boolean isEnabled();
60+
61+
/**
62+
* (implemented by {@link CodecBase}
63+
* <p>
64+
* Checks to see if the binary library associated with the
65+
* codec (if any) loaded OK.
66+
*
67+
* @returns true if the codec loaded properly
68+
*/
69+
boolean isLoaded();
70+
71+
/**
72+
* (implemented by {@link CodecBase}
73+
* <p>
74+
* checks to see if the user has enabled the codec for use on
75+
* edge only.
76+
*
77+
* @returns true if the codec can only be used on Edge Networks
78+
*/
79+
boolean edgeOnly();
80+
81+
/**
82+
* (implemented by {@link CodecBase}
83+
*
84+
* @returns The user friendly string for the codec (should
85+
* include both the name and the bandwidth
86+
*/
87+
String getTitle();
88+
89+
90+
/**
91+
* (implemented by {@link CodecBase}
92+
*
93+
* @returns The RTP assigned name string for the codec
94+
*/
95+
String name();
96+
97+
/**
98+
* (implemented by {@link CodecBase}
99+
*
100+
* @returns The commonly used name for the codec.
101+
*/
102+
String userName();
103+
104+
/**
105+
* (implemented by {@link CodecBase}
106+
*
107+
* @returns The RTP assigned number for the codec
108+
*/
109+
int number();
110+
111+
/**
112+
* (implemented by {@link CodecBase}
113+
*
114+
* @param l The list preference controlling this Codec
115+
*
116+
* Used to add listeners for preference changes and update
117+
* the codec parameters accordingly.
118+
*/
119+
void setListPreference(ListPreference l);
120+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (C) 2009 The Sipdroid Open Source Project
3+
*
4+
* This file is part of Sipdroid (http://www.sipdroid.org)
5+
*
6+
* Sipdroid is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This source code is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this source code; if not, write to the Free Software
18+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19+
*/
20+
package org.sipdroid.codecs;
21+
22+
import org.sipdroid.sipua.ui.Receiver;
23+
24+
import android.content.SharedPreferences;
25+
import android.preference.ListPreference;
26+
import android.preference.Preference;
27+
import android.preference.PreferenceManager;
28+
29+
class CodecBase implements Preference.OnPreferenceChangeListener {
30+
protected String CODEC_NAME;
31+
protected String CODEC_USER_NAME;
32+
protected int CODEC_NUMBER;
33+
protected String CODEC_DESCRIPTION;
34+
protected String CODEC_DEFAULT_SETTING = "never";
35+
36+
private boolean loaded = false;
37+
private boolean enabled = false;
38+
private boolean edgeOnly = false;
39+
private String value;
40+
41+
void load() {
42+
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
43+
value = sp.getString(CODEC_NAME, CODEC_DEFAULT_SETTING);
44+
updateFlags(value);
45+
loaded = true;
46+
}
47+
48+
public boolean isLoaded() {
49+
return loaded;
50+
}
51+
52+
public void enable(boolean e) {
53+
enabled = e && loaded;
54+
}
55+
56+
public boolean isEnabled() {
57+
return loaded && enabled;
58+
}
59+
60+
public boolean edgeOnly() {
61+
return loaded && enabled && edgeOnly;
62+
}
63+
64+
public String name() {
65+
return CODEC_NAME;
66+
}
67+
68+
public String userName() {
69+
return CODEC_USER_NAME;
70+
}
71+
72+
public String getTitle() {
73+
return CODEC_USER_NAME + " (" + CODEC_DESCRIPTION + ")";
74+
}
75+
76+
public int number() {
77+
return CODEC_NUMBER;
78+
}
79+
80+
public void setListPreference(ListPreference l) {
81+
l.setOnPreferenceChangeListener(this);
82+
l.setValue(value);
83+
}
84+
85+
public boolean onPreferenceChange(Preference p, Object newValue) {
86+
ListPreference l = (ListPreference)p;
87+
value = (String)newValue;
88+
89+
updateFlags(value);
90+
91+
l.setValue(value);
92+
l.setSummary(l.getEntry());
93+
94+
return true;
95+
}
96+
97+
private void updateFlags(String v) {
98+
99+
if (v.equals("never")) {
100+
enabled = false;
101+
} else {
102+
enabled = true;
103+
if (v.equals("edge"))
104+
edgeOnly = true;
105+
else
106+
edgeOnly = false;
107+
}
108+
}
109+
110+
public String toString() {
111+
return "CODEC{ " + CODEC_NUMBER + ": " + getTitle() + "}";
112+
}
113+
}

0 commit comments

Comments
 (0)