Skip to content

Commit

Permalink
sipdroid: redo codec infrastructure to support arbitrary codecs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jejbgo committed Feb 15, 2010
1 parent 8906ce4 commit db3e892
Show file tree
Hide file tree
Showing 20 changed files with 839 additions and 201 deletions.
6 changes: 5 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
<activity android:name=".ui.Settings" android:label="@string/app_name"
android:excludeFromRecents="true" android:taskAffinity="">
</activity>
<activity
android:name="org.sipdroid.codecs.Codecs$CodecSettings"
android:label="@string/app_name" >
</activity>
<activity android:name=".ui.VideoCamera" android:label="@string/menu_video"
android:excludeFromRecents="true" android:taskAffinity=""
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
Expand Down Expand Up @@ -118,4 +122,4 @@
<uses-permission android:name="android.permission.VIBRATE" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" ></uses-permission>
</manifest>
</manifest>
9 changes: 9 additions & 0 deletions res/layout/incall.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/codec"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorSecondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

</RelativeLayout> <!-- End of inCallPanel -->
Expand Down
7 changes: 7 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
<string name="card_title_in_progress">Call in progress</string>
<string name="card_title_incoming_call">Incoming call</string>
<string name="card_title_call_ended">Call ended</string>
<string name="card_title_ended_no_codec">ERROR: Codecs Incompatible</string>
<string name="card_title_on_hold">On hold</string>

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

<string name="ongoing">Current Call</string>
<string name="onHold">On hold</string>
<string name="codecs">Audio Codecs</string>
<string name="codecs_summary">Select Audio Codecs to be available for voice calls</string>
<string name="codecs_move">Move this codec</string>
<string name="codecs_move_up">Move up one place</string>
<string name="codecs_move_down">Move down one place</string>
<string name="cancel">Cancel</string>
</resources>
5 changes: 5 additions & 0 deletions res/xml/codec_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="codecs"
android:title="@string/codecs">
</PreferenceScreen>
18 changes: 10 additions & 8 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">


<PreferenceScreen android:title="@string/settings_account">
<EditTextPreference
android:key="username"
Expand Down Expand Up @@ -58,13 +58,6 @@
android:entryValues="@array/pref_values"
android:summary="@string/settings_pref2"
android:dialogTitle="@string/settings_pref" />
<ListPreference
android:key="compression"
android:title="@string/settings_compression"
android:entries="@array/compression_display_values"
android:entryValues="@array/compression_values"
android:defaultValue="edge"
android:dialogTitle="@string/settings_compression" />
<CheckBoxPreference
android:key="auto_on"
android:title="@string/settings_auto_on"
Expand Down Expand Up @@ -184,4 +177,13 @@
android:hint="Accessno.,PIN#"
android:singleLine="true" />
</PreferenceScreen>
<PreferenceScreen
android:key="codecs"
android:title="@string/codecs" >
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="org.sipdroid.sipua"
android:targetClass="org.sipdroid.codecs.Codecs$CodecSettings" />

</PreferenceScreen>
</PreferenceScreen>
120 changes: 120 additions & 0 deletions src/org/sipdroid/codecs/Codec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package org.sipdroid.codecs;

import android.preference.ListPreference;

/**
* Represents the basic interface to the Codec classes All codecs need
* to implement basic encode and decode capability Codecs which
* inherit from {@link CodecBase} only need to implement encode,
* decode and init
*/
public interface Codec {
/**
* Decode a linear pcm audio stream
*
* @param encoded The encoded audio stream
*
* @param lin The linear pcm audio frame buffer in which to place the decoded stream
*
* @param size The size of the encoded frame
*
* @returns The size of the decoded frame
*/
int decode(byte encoded[], short lin[], int size);

/**
* Encode a linear pcm audio stream
*
* @param lin The linear stream to encode
*
* @param offset The offset into the linear stream to begin
*
* @param encoded The buffer to place the encoded stream
*
* @param size the size of the linear pcm stream (in words)
*
* @returns the length (in bytes) of the encoded stream
*/
int encode(short lin[], int offset, byte alaw[], int frames);

/**
* Optionally used to initiallize the codec before any
* encoding or decoding
*/
void init();

/**
* Optionally used to free any resources allocated in init
* after encoding or decoding is complete
*/
void close();

/**
* (implemented by {@link CodecBase}
* <p>
* checks to see if the user has enabled the codec.
*
* @returns true if the codec can be used
*/
boolean isEnabled();

/**
* (implemented by {@link CodecBase}
* <p>
* Checks to see if the binary library associated with the
* codec (if any) loaded OK.
*
* @returns true if the codec loaded properly
*/
boolean isLoaded();

/**
* (implemented by {@link CodecBase}
* <p>
* checks to see if the user has enabled the codec for use on
* edge only.
*
* @returns true if the codec can only be used on Edge Networks
*/
boolean edgeOnly();

/**
* (implemented by {@link CodecBase}
*
* @returns The user friendly string for the codec (should
* include both the name and the bandwidth
*/
String getTitle();


/**
* (implemented by {@link CodecBase}
*
* @returns The RTP assigned name string for the codec
*/
String name();

/**
* (implemented by {@link CodecBase}
*
* @returns The commonly used name for the codec.
*/
String userName();

/**
* (implemented by {@link CodecBase}
*
* @returns The RTP assigned number for the codec
*/
int number();

/**
* (implemented by {@link CodecBase}
*
* @param l The list preference controlling this Codec
*
* Used to add listeners for preference changes and update
* the codec parameters accordingly.
*/
void setListPreference(ListPreference l);
}
113 changes: 113 additions & 0 deletions src/org/sipdroid/codecs/CodecBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright (C) 2009 The Sipdroid Open Source Project
*
* This file is part of Sipdroid (http://www.sipdroid.org)
*
* Sipdroid is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.sipdroid.codecs;

import org.sipdroid.sipua.ui.Receiver;

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

class CodecBase implements Preference.OnPreferenceChangeListener {
protected String CODEC_NAME;
protected String CODEC_USER_NAME;
protected int CODEC_NUMBER;
protected String CODEC_DESCRIPTION;
protected String CODEC_DEFAULT_SETTING = "never";

private boolean loaded = false;
private boolean enabled = false;
private boolean edgeOnly = false;
private String value;

void load() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
value = sp.getString(CODEC_NAME, CODEC_DEFAULT_SETTING);
updateFlags(value);
loaded = true;
}

public boolean isLoaded() {
return loaded;
}

public void enable(boolean e) {
enabled = e && loaded;
}

public boolean isEnabled() {
return loaded && enabled;
}

public boolean edgeOnly() {
return loaded && enabled && edgeOnly;
}

public String name() {
return CODEC_NAME;
}

public String userName() {
return CODEC_USER_NAME;
}

public String getTitle() {
return CODEC_USER_NAME + " (" + CODEC_DESCRIPTION + ")";
}

public int number() {
return CODEC_NUMBER;
}

public void setListPreference(ListPreference l) {
l.setOnPreferenceChangeListener(this);
l.setValue(value);
}

public boolean onPreferenceChange(Preference p, Object newValue) {
ListPreference l = (ListPreference)p;
value = (String)newValue;

updateFlags(value);

l.setValue(value);
l.setSummary(l.getEntry());

return true;
}

private void updateFlags(String v) {

if (v.equals("never")) {
enabled = false;
} else {
enabled = true;
if (v.equals("edge"))
edgeOnly = true;
else
edgeOnly = false;
}
}

public String toString() {
return "CODEC{ " + CODEC_NUMBER + ": " + getTitle() + "}";
}
}
Loading

0 comments on commit db3e892

Please sign in to comment.