-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
jejbgo
committed
Feb 15, 2010
1 parent
8906ce4
commit db3e892
Showing
20 changed files
with
839 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() + "}"; | ||
} | ||
} |
Oops, something went wrong.