new sipdroid
authornikita@nikita-laptop
Sun, 24 Jan 2010 00:42:29 +0100
changeset 835 4e40f3481f23
parent 834 e8d6255306f8
child 836 2f2f5e24ac6a
new sipdroid
src/com/beem/project/beem/jingle/JingleService.java
src/com/beem/project/beem/jingle/RTPAudioSession.java
src/com/beem/project/beem/ui/Call.java
src/org/sipdroid/media/G711.java
src/org/sipdroid/media/RtpStreamReceiver.java
src/org/sipdroid/media/RtpStreamSender.java
src/org/sipdroid/net/RtpPacket.java
src/org/sipdroid/net/RtpSocket.java
src/org/sipdroid/net/SipdroidSocket.java
src/org/sipdroid/net/impl/OSNetworkSystem.java
src/org/sipdroid/net/impl/PlainDatagramSocketImpl.java
--- a/src/com/beem/project/beem/jingle/JingleService.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/com/beem/project/beem/jingle/JingleService.java	Sun Jan 24 00:42:29 2010 +0100
@@ -93,7 +93,6 @@
 	BasicTransportManager bt = new BasicTransportManager();
 	mMediaManagers = new ArrayList<JingleMediaManager>();
 	mMediaManagers.add(new MicrophoneRTPManager(bt, ctx));
-	CodecManager.load();
 	mContext = ctx;
     }
 
--- a/src/com/beem/project/beem/jingle/RTPAudioSession.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/com/beem/project/beem/jingle/RTPAudioSession.java	Sun Jan 24 00:42:29 2010 +0100
@@ -16,84 +16,81 @@
  * @author nikita
  */
 public class RTPAudioSession extends JingleMediaSession {
-	
-	private RtpStreamSender mSender=null;
-	private RtpStreamReceiver mReceiver=null;
+
+    private RtpStreamSender mSender=null;
+    private RtpStreamReceiver mReceiver=null;
 
-	private RTPSession rtpSession;
+    /**
+     * constructor.
+     * @param payloadType the payload typ used
+     * @param remote the remote transport info
+     * @param local the local tranport info
+     * @param mediaLocator don't know
+     * @param jingleSession the current jingle session
+     * @param ctx 
+     */
+    public RTPAudioSession(final PayloadType pt, final TransportCandidate remote,
+	final TransportCandidate local, final String mediaLocator, final JingleSession jingleSession, Context ctx) {
+	super(pt, remote, local, mediaLocator, jingleSession);
+
+	prepareRtpSession(local.getPort(), remote.getIp(), remote.getPort());
+	Log.d("AUDIO", String.format("payload type : %s ipdest %s port dest %d port src %d",pt.getName(), remote.getIp(), remote.getPort(), local.getPort()));
+
+	//mSender = new RtpStreamSender(CodecManager.getCodecByRtpName(pt.getName()), rtpSession);
+
+	//mReceiver = new RtpStreamReceiver(CodecManager.getCodecByRtpName(pt.getName()), rtpSession, ctx);
+    }
 
-	/**
-	 * constructor.
-	 * @param payloadType the payload typ used
-	 * @param remote the remote transport info
-	 * @param local the local tranport info
-	 * @param mediaLocator don't know
-	 * @param jingleSession the current jingle session
-	 * @param ctx 
-	 */
-	public RTPAudioSession(final PayloadType pt, final TransportCandidate remote,
-			final TransportCandidate local, final String mediaLocator, final JingleSession jingleSession, Context ctx) {
-		super(pt, remote, local, mediaLocator, jingleSession);
-		
-		prepareRtpSession(local.getPort(), remote.getIp(), remote.getPort());
-		Log.d("AUDIO", String.format("payload type : %s ipdest %s port dest %d port src %d",pt.getName(), remote.getIp(), remote.getPort(), local.getPort()));
-		
-		mSender = new RtpStreamSender(CodecManager.getCodecByRtpName(pt.getName()), rtpSession);
+    @Override
+    public void initialize() {
+	// TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void setTrasmit(boolean active) {
+    }
 
-		mReceiver = new RtpStreamReceiver(CodecManager.getCodecByRtpName(pt.getName()), rtpSession, ctx);
+    @Override
+    public void startReceive() {
+	if (mReceiver != null) {
+	    mReceiver.start();
 	}
+    }
 
-	@Override
-	public void initialize() {
-		// TODO Auto-generated method stub
+    @Override
+    public void startTrasmit() {
+	if (mSender != null) {
+	    mSender.start();
+	}
+    }
 
-	}
-
-	@Override
-	public void setTrasmit(boolean active) {
+    @Override
+    public void stopReceive() {
+	if (mReceiver != null) {
+	    mReceiver.halt();
+	    mReceiver = null;
 	}
 
-	@Override
-	public void startReceive() {
-		if (mReceiver != null) {
-			mReceiver.start();
-		}
-	}
+    }
 
-	@Override
-	public void startTrasmit() {
-		if (mSender != null) {
-			mSender.start();
-		}
-		rtpSession.RTPSessionRegister(mReceiver, null, null);
+    @Override
+    public void stopTrasmit() {
+	if (mSender != null) {
+	    mSender.halt();
+	    mSender = null;
 	}
+    }
 
-	@Override
-	public void stopReceive() {
-		if (mReceiver != null) {
-			mReceiver.halt();
-			mReceiver = null;
-		}
-		rtpSession.endSession();
-	}
+    private void prepareRtpSession(int src_port, String dest_addr, int dest_port) {
+	SipdroidSocket rtpSocket = null;
+	SipdroidSocket rtcpSocket = null;
 
-	@Override
-	public void stopTrasmit() {
-		if (mSender != null) {
-			mSender.halt();
-			mSender = null;
-		}
+	try {
+	    rtpSocket = new SipdroidSocket(src_port);
+	    rtcpSocket = new SipdroidSocket(src_port + 1);
+	} catch (Exception e) {
+	    e.printStackTrace();
 	}
-	
-	private void prepareRtpSession(int src_port, String dest_addr, int dest_port) {
-		SipdroidSocket rtpSocket = null;
-		SipdroidSocket rtcpSocket = null;
-
-		try {
-			rtpSocket = new SipdroidSocket(src_port);
-			rtcpSocket = new SipdroidSocket(src_port + 1);
-		} catch (Exception e) {
-		    e.printStackTrace();
-		}
-	}
+    }
 }
--- a/src/com/beem/project/beem/ui/Call.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/com/beem/project/beem/ui/Call.java	Sun Jan 24 00:42:29 2010 +0100
@@ -45,11 +45,16 @@
 
 import android.app.Activity;
 import android.content.ComponentName;
+import android.content.Context;
 import android.content.Intent;
 import android.content.ServiceConnection;
+import android.media.Ringtone;
+import android.media.RingtoneManager;
+import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
+import android.os.Vibrator;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.View;
@@ -88,6 +93,32 @@
     private Button mAcceptCall;
     private IJingle mJingle;
 
+    public static final int UA_STATE_IDLE = 0;
+    public static final int UA_STATE_INCOMING_CALL = 1;
+    public static final int UA_STATE_OUTGOING_CALL = 2;
+    public static final int UA_STATE_INCALL = 3;
+    public static final int UA_STATE_HOLD = 4;
+
+    public static int call_state = UA_STATE_IDLE;
+    public static int docked = -1,headset = -1;
+    public static Ringtone oRingtone;
+    public static Context mContext;
+
+    public static void stopRingtone() {
+	android.os.Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
+	v.cancel();
+	if (oRingtone != null) {
+	    Ringtone ringtone = oRingtone;
+	    oRingtone = null;
+	    ringtone.stop();
+	}
+    }
+
+    public static void startRingtone() {
+	oRingtone = RingtoneManager.getRingtone(mContext, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE));
+	oRingtone.play();
+    }
+
     /**
      * Constructor.
      */
@@ -97,6 +128,7 @@
     @Override
     protected void onCreate(Bundle savedInstanceState) {
 	super.onCreate(savedInstanceState);
+	Call.mContext = this;
 	setContentView(R.layout.call);
 	Intent callingIntent = this.getIntent();
 
@@ -175,12 +207,12 @@
     }
 
     private class BeemJingleSessionListener extends IBeemJingleListener.Stub {
-	
+
 	/**
 	 * Refresh the call activity.
 	 */
 	private class RunnableChange implements Runnable {
-	    
+
 	    private String mStr;
 	    /**
 	     * Constructor.
@@ -195,7 +227,7 @@
 	    @Override
 	    public void run() {
 		mCallInfo.setText(mStr);
-		
+
 	    }
 	}
 
--- a/src/org/sipdroid/media/G711.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/org/sipdroid/media/G711.java	Sun Jan 24 00:42:29 2010 +0100
@@ -1,4 +1,4 @@
-package src.org.sipdroid.media;
+package org.sipdroid.media;
 
 /**
  * G.711 codec. This class provides methods for u-law, A-law and linear PCM
--- a/src/org/sipdroid/media/RtpStreamReceiver.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/org/sipdroid/media/RtpStreamReceiver.java	Sun Jan 24 00:42:29 2010 +0100
@@ -19,20 +19,18 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-package src.org.sipdroid.media;
+package org.sipdroid.media;
 
 import java.io.IOException;
 import java.net.SocketException;
 
-import org.sipdroid.sipua.UserAgent;
-import org.sipdroid.sipua.ui.Receiver;
-import org.sipdroid.sipua.ui.Sipdroid;
+import com.beem.project.beem.jingle.JingleService;
+import com.beem.project.beem.ui.Call;
+import org.sipdroid.net.RtpPacket;
+import org.sipdroid.net.RtpSocket;
+import org.sipdroid.net.SipdroidSocket;
 import org.sipdroid.pjlib.Codec;
 
-import src.org.sipdroid.net.RtpPacket;
-import src.org.sipdroid.net.RtpSocket;
-import src.org.sipdroid.net.SipdroidSocket;
-
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.SharedPreferences.Editor;
@@ -41,6 +39,7 @@
 import android.media.AudioTrack;
 import android.media.ToneGenerator;
 import android.os.PowerManager;
+import android.os.RemoteException;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
 
@@ -50,442 +49,426 @@
  */
 public class RtpStreamReceiver extends Thread {
 
-	/** Whether working in debug mode. */
-	public static boolean DEBUG = true;
+    /** Whether working in debug mode. */
+    public static boolean DEBUG = true;
 
-	/** Payload type */
-	int p_type;
+    /** Payload type */
+    int p_type;
 
-	/** Size of the read buffer */
-	public static final int BUFFER_SIZE = 1024;
+    /** Size of the read buffer */
+    public static final int BUFFER_SIZE = 1024;
 
-	/** Maximum blocking time, spent waiting for reading new bytes [milliseconds] */
-	public static final int SO_TIMEOUT = 200;
+    /** Maximum blocking time, spent waiting for reading new bytes [milliseconds] */
+    public static final int SO_TIMEOUT = 200;
 
-	/** The RtpSocket */
-	RtpSocket rtp_socket = null;
+    /** The RtpSocket */
+    private RtpSocket rtp_socket = null;
 
-	/** Whether it is running */
-	boolean running;
-	AudioManager am;
-	ContentResolver cr;
-	public static int speakermode;
-	
-	/**
-	 * Constructs a RtpStreamReceiver.
-	 * 
-	 * @param output_stream
-	 *            the stream sink
-	 * @param socket
-	 *            the local receiver SipdroidSocket
-	 */
-	public RtpStreamReceiver(SipdroidSocket socket, int payload_type) {
-		init(socket);
-		p_type = payload_type;
-	}
+    /** Whether it is running */
+    private boolean running;
+    private AudioManager am;
+    private ContentResolver cr;
+    public static int speakermode;
+    private JingleService mJingle;
 
-	/** Inits the RtpStreamReceiver */
-	private void init(SipdroidSocket socket) {
-		if (socket != null)
-			rtp_socket = new RtpSocket(socket);
-	}
+    /**
+     * Constructs a RtpStreamReceiver.
+     * 
+     * @param output_stream
+     *            the stream sink
+     * @param socket
+     *            the local receiver SipdroidSocket
+     */
+    public RtpStreamReceiver(SipdroidSocket socket, int payload_type) {
+	init(socket);
+	p_type = payload_type;
+    }
+
+    /** Inits the RtpStreamReceiver */
+    private void init(SipdroidSocket socket) {
+	if (socket != null)
+	    rtp_socket = new RtpSocket(socket);
+    }
 
-	/** Whether is running */
-	public boolean isRunning() {
-		return running;
-	}
+    /** Whether is running */
+    public boolean isRunning() {
+	return running;
+    }
+
+    /** Stops running */
+    public void halt() {
+	running = false;
+    }
 
-	/** Stops running */
-	public void halt() {
-		running = false;
-	}
-	
-	public int speaker(int mode) {
-		int old = speakermode;
-		
-		if (Receiver.headset > 0 && mode == AudioManager.MODE_NORMAL)
-			return old;
-		saveVolume();
-		setMode(speakermode = mode);
-		restoreVolume();
-		return old;
-	}
+    public int speaker(int mode) {
+	int old = speakermode;
+
+	if (Call.headset > 0 && mode == AudioManager.MODE_NORMAL)
+	    return old;
+	saveVolume();
+	setMode(speakermode = mode);
+	restoreVolume();
+	return old;
+    }
 
-	double smin = 200,s;
-	public static int nearend;
-	
-	void calc(short[] lin,int off,int len) {
-		int i,j;
-		double sm = 30000,r;
-		
-		for (i = 0; i < len; i += 5) {
-			j = lin[i+off];
-			s = 0.03*Math.abs(j) + 0.97*s;
-			if (s < sm) sm = s;
-			if (s > smin) nearend = 3000/5;
-			else if (nearend > 0) nearend--;
-		}
-		for (i = 0; i < len; i++) {
-			j = lin[i+off];
-			if (j > 6550)
-				lin[i+off] = 6550*5;
-			else if (j < -6550)
-				lin[i+off] = -6550*5;
-			else
-				lin[i+off] = (short)(j*5);
-		}
-		r = (double)len/100000;
-		smin = sm*r + smin*(1-r);
+    double smin = 200,s;
+    public static int nearend;
+
+    void calc(short[] lin,int off,int len) {
+	int i,j;
+	double sm = 30000,r;
+
+	for (i = 0; i < len; i += 5) {
+	    j = lin[i+off];
+	    s = 0.03*Math.abs(j) + 0.97*s;
+	    if (s < sm) sm = s;
+	    if (s > smin) nearend = 3000/5;
+	    else if (nearend > 0) nearend--;
+	}
+	for (i = 0; i < len; i++) {
+	    j = lin[i+off];
+	    if (j > 6550)
+		lin[i+off] = 6550*5;
+	    else if (j < -6550)
+		lin[i+off] = -6550*5;
+	    else
+		lin[i+off] = (short)(j*5);
 	}
-	
-	static void setStreamVolume(final int stream,final int vol,final int flags) {
-        (new Thread() {
-			public void run() {
-				AudioManager am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE);
-				am.setStreamVolume(stream, vol, flags);
-				if (stream == AudioManager.STREAM_MUSIC) restored = true;
-			}
-        }).start();
+	r = (double)len/100000;
+	smin = sm*r + smin*(1-r);
+    }
+
+    static void setStreamVolume(final int stream,final int vol,final int flags) {
+	(new Thread() {
+	    public void run() {
+		AudioManager am = (AudioManager) Call.mContext.getSystemService(Context.AUDIO_SERVICE);
+		am.setStreamVolume(stream, vol, flags);
+		if (stream == AudioManager.STREAM_MUSIC) restored = true;
+	    }
+	}).start();
+    }
+
+    static boolean restored;
+
+    public static float getEarGain() {
+	try {
+	    return Float.valueOf(PreferenceManager.getDefaultSharedPreferences(Call.mContext).getString(Call.headset > 0?"heargain":"eargain", "0.25"));
+	} catch (NumberFormatException i) {
+	    return (float)0.25;
+	}			
+    }
+
+    void restoreVolume() {
+	switch (am.getMode()) {
+	    case AudioManager.MODE_IN_CALL:
+		setStreamVolume(AudioManager.STREAM_RING,(int)(
+		    am.getStreamMaxVolume(AudioManager.STREAM_RING)*
+		    getEarGain()), 0);
+		track.setStereoVolume(AudioTrack.getMaxVolume()*
+		    getEarGain()
+		    ,AudioTrack.getMaxVolume()*
+		    getEarGain());
+		break;
+	    case AudioManager.MODE_NORMAL:
+		track.setStereoVolume(AudioTrack.getMaxVolume(),AudioTrack.getMaxVolume());
+		break;
 	}
-	
-	static boolean restored;
-	
-	void restoreVolume() {
-		switch (am.getMode()) {
-		case AudioManager.MODE_IN_CALL:
-				setStreamVolume(AudioManager.STREAM_RING,(int)(
-						am.getStreamMaxVolume(AudioManager.STREAM_RING)*
-						org.sipdroid.sipua.ui.Settings.getEarGain()), 0);
-				track.setStereoVolume(AudioTrack.getMaxVolume()*
-						org.sipdroid.sipua.ui.Settings.getEarGain()
-						,AudioTrack.getMaxVolume()*
-						org.sipdroid.sipua.ui.Settings.getEarGain());
-				break;
-		case AudioManager.MODE_NORMAL:
-				track.setStereoVolume(AudioTrack.getMaxVolume(),AudioTrack.getMaxVolume());
-				break;
-		}
-		setStreamVolume(AudioManager.STREAM_MUSIC,
-				PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getInt("volume"+speakermode, 
-				am.getStreamMaxVolume(AudioManager.STREAM_MUSIC)*
-				(speakermode == AudioManager.MODE_NORMAL?4:3)/4
-				),0);
-	}
-	
-	void saveVolume() {
-		if (restored) {
-			Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
-			edit.putInt("volume"+speakermode,am.getStreamVolume(AudioManager.STREAM_MUSIC));
-			edit.commit();
-		}
+	setStreamVolume(AudioManager.STREAM_MUSIC,
+	    PreferenceManager.getDefaultSharedPreferences(Call.mContext).getInt("volume"+speakermode, 
+		am.getStreamMaxVolume(AudioManager.STREAM_MUSIC)*
+		(speakermode == AudioManager.MODE_NORMAL?4:3)/4
+	    ),0);
+    }
+
+    void saveVolume() {
+	if (restored) {
+	    Editor edit = PreferenceManager.getDefaultSharedPreferences(Call.mContext).edit();
+	    edit.putInt("volume"+speakermode,am.getStreamVolume(AudioManager.STREAM_MUSIC));
+	    edit.commit();
 	}
-	
-	void saveSettings() {
-		if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getBoolean("oldvalid",false)) {
-			int oldvibrate = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
-			int oldvibrate2 = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION);
-			if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).contains("oldvibrate2"))
-				oldvibrate2 = AudioManager.VIBRATE_SETTING_ON;
-			int oldpolicy = android.provider.Settings.System.getInt(cr, android.provider.Settings.System.WIFI_SLEEP_POLICY, 
-					Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
-			Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
-			edit.putInt("oldvibrate", oldvibrate);
-			edit.putInt("oldvibrate2", oldvibrate2);
-			edit.putInt("oldpolicy", oldpolicy);
-			edit.putInt("oldring",am.getStreamVolume(AudioManager.STREAM_RING));
-			edit.putBoolean("oldvalid", true);
-			edit.commit();
-		}
+    }
+
+    void saveSettings() {
+	if (!PreferenceManager.getDefaultSharedPreferences(Call.mContext).getBoolean("oldvalid",false)) {
+	    int oldvibrate = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
+	    int oldvibrate2 = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION);
+	    if (!PreferenceManager.getDefaultSharedPreferences(Call.mContext).contains("oldvibrate2"))
+		oldvibrate2 = AudioManager.VIBRATE_SETTING_ON;
+	    int oldpolicy = android.provider.Settings.System.getInt(cr, android.provider.Settings.System.WIFI_SLEEP_POLICY, 
+		Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
+	    Editor edit = PreferenceManager.getDefaultSharedPreferences(Call.mContext).edit();
+	    edit.putInt("oldvibrate", oldvibrate);
+	    edit.putInt("oldvibrate2", oldvibrate2);
+	    edit.putInt("oldpolicy", oldpolicy);
+	    edit.putInt("oldring",am.getStreamVolume(AudioManager.STREAM_RING));
+	    edit.putBoolean("oldvalid", true);
+	    edit.commit();
 	}
-	
-	public static void setMode(int mode) {
-		Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
-		edit.putBoolean("setmode", mode != AudioManager.MODE_NORMAL);
-		edit.commit();
-		AudioManager am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE);
-		am.setMode(mode);
+    }
+
+    public static void setMode(int mode) {
+	Editor edit = PreferenceManager.getDefaultSharedPreferences(Call.mContext).edit();
+	edit.putBoolean("setmode", mode != AudioManager.MODE_NORMAL);
+	edit.commit();
+	AudioManager am = (AudioManager) Call.mContext.getSystemService(Context.AUDIO_SERVICE);
+	am.setMode(mode);
+    }
+
+    public static void restoreMode() {
+	if (PreferenceManager.getDefaultSharedPreferences(Call.mContext).getBoolean("setmode",true)) {
+	    setMode(AudioManager.MODE_NORMAL);
 	}
-	
-	public static void restoreMode() {
-		if (PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getBoolean("setmode",true)) {
-			if (Receiver.pstn_state == null || Receiver.pstn_state.equals("IDLE"))
-				setMode(AudioManager.MODE_NORMAL);
-			else {
-				Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
-				edit.putBoolean("setmode", false);
-				edit.commit();
-			}
-		}
+    }
+
+    public static void restoreSettings() {
+	if (PreferenceManager.getDefaultSharedPreferences(Call.mContext).getBoolean("oldvalid",true)) {
+	    AudioManager am = (AudioManager) Call.mContext.getSystemService(Context.AUDIO_SERVICE);
+	    ContentResolver cr = Call.mContext.getContentResolver();
+	    int oldvibrate = PreferenceManager.getDefaultSharedPreferences(Call.mContext).getInt("oldvibrate",0);
+	    int oldvibrate2 = PreferenceManager.getDefaultSharedPreferences(Call.mContext).getInt("oldvibrate2",0);
+	    int oldpolicy = PreferenceManager.getDefaultSharedPreferences(Call.mContext).getInt("oldpolicy",0);
+	    am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,oldvibrate);
+	    am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,oldvibrate2);
+	    Settings.System.putInt(cr, Settings.System.WIFI_SLEEP_POLICY, oldpolicy);
+	    setStreamVolume(AudioManager.STREAM_RING, PreferenceManager.getDefaultSharedPreferences(Call.mContext).getInt("oldring",0), 0);
+	    Editor edit = PreferenceManager.getDefaultSharedPreferences(Call.mContext).edit();
+	    edit.putBoolean("oldvalid", false);
+	    edit.commit();
+	    PowerManager pm = (PowerManager) Call.mContext.getSystemService(Context.POWER_SERVICE);
+	    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
+		PowerManager.ACQUIRE_CAUSES_WAKEUP, "Sipdroid.RtpStreamReceiver");
+	    wl.acquire(1000);
 	}
+	restoreMode();
+    }
+
+    public static float good, late, lost, loss;
+    public static int timeout;
 
-	public static void restoreSettings() {
-		if (PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getBoolean("oldvalid",true)) {
-			AudioManager am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE);
-	        ContentResolver cr = Receiver.mContext.getContentResolver();
-			int oldvibrate = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getInt("oldvibrate",0);
-			int oldvibrate2 = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getInt("oldvibrate2",0);
-			int oldpolicy = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getInt("oldpolicy",0);
-			am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,oldvibrate);
-			am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,oldvibrate2);
-			Settings.System.putInt(cr, Settings.System.WIFI_SLEEP_POLICY, oldpolicy);
-			setStreamVolume(AudioManager.STREAM_RING, PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getInt("oldring",0), 0);
-			Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
-			edit.putBoolean("oldvalid", false);
-			edit.commit();
-			PowerManager pm = (PowerManager) Receiver.mContext.getSystemService(Context.POWER_SERVICE);
-			PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
-					PowerManager.ACQUIRE_CAUSES_WAKEUP, "Sipdroid.RtpStreamReceiver");
-			wl.acquire(1000);
-		}
-		restoreMode();
+    void empty() {
+	try {
+	    rtp_socket.getDatagramSocket().setSoTimeout(1);
+	    for (;;)
+		rtp_socket.receive(rtp_packet);
+	} catch (SocketException e2) {
+	    e2.printStackTrace();
+	} catch (IOException e) {
+	}
+	try {
+	    rtp_socket.getDatagramSocket().setSoTimeout(1000);
+	} catch (SocketException e2) {
+	    e2.printStackTrace();
+	}
+    }
+
+    RtpPacket rtp_packet;
+    AudioTrack track;
+
+    /** Runs it in a new Thread. */
+    public void run() {
+	boolean nodata = PreferenceManager.getDefaultSharedPreferences(Call.mContext).getBoolean("nodata",false);
+
+	if (rtp_socket == null) {
+	    if (DEBUG)
+		println("ERROR: RTP socket is null");
+	    return;
 	}
 
-	public static float good, late, lost, loss;
-	public static int timeout;
-	
-	void empty() {
-		try {
-			rtp_socket.getDatagramSocket().setSoTimeout(1);
-			for (;;)
-				rtp_socket.receive(rtp_packet);
-		} catch (SocketException e2) {
-			if (!Sipdroid.release) e2.printStackTrace();
-		} catch (IOException e) {
+	byte[] buffer = new byte[BUFFER_SIZE+12];
+	byte[] buffer_gsm = new byte[33+12];
+	int i;
+	rtp_packet = new RtpPacket(buffer, 0);
+
+	if (DEBUG)
+	    println("Reading blocks of max " + buffer.length + " bytes");
+
+	running = true;
+	speakermode = Call.docked > 0?AudioManager.MODE_NORMAL:AudioManager.MODE_IN_CALL;
+	restored = false;
+
+	android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO);
+	am = (AudioManager) Call.mContext.getSystemService(Context.AUDIO_SERVICE);
+	cr = Call.mContext.getContentResolver();
+	saveSettings();
+	Settings.System.putInt(cr, Settings.System.WIFI_SLEEP_POLICY,Settings.System.WIFI_SLEEP_POLICY_NEVER);
+	am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,AudioManager.VIBRATE_SETTING_OFF);
+	am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,AudioManager.VIBRATE_SETTING_OFF);
+	int oldvol = am.getStreamVolume(AudioManager.STREAM_MUSIC);
+	track = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,
+	    BUFFER_SIZE*2*2, AudioTrack.MODE_STREAM);
+	short lin[] = new short[BUFFER_SIZE];
+	short lin2[] = new short[BUFFER_SIZE];
+	int user, server, lserver, luser, cnt, todo, headroom, len = 0, seq = 0, cnt2 = 0, m = 1,
+	expseq, getseq, vm = 1, gap, gseq;
+	timeout = 1;
+	boolean islate;
+	user = 0;
+	lserver = 0;
+	luser = -8000;
+	cnt = 0;
+	switch (p_type) {
+	    case 3:
+		Codec.init();
+		break;
+	    case 0:
+	    case 8:
+		G711.init();
+		break;
+	}
+	ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_MUSIC,(int)(ToneGenerator.MAX_VOLUME*2*0.95));
+	track.play();
+	if (Call.headset > 0 && Call.oRingtone != null) {
+	    ToneGenerator tg2 = new ToneGenerator(AudioManager.STREAM_RING,(int)(ToneGenerator.MAX_VOLUME*2*0.95));
+	    tg2.startTone(ToneGenerator.TONE_SUP_RINGTONE);
+	    System.gc();
+	    tg2.stopTone();
+	} else
+	    System.gc();
+	while (running) {
+	    if (Call.call_state == Call.UA_STATE_HOLD) {
+		tg.stopTone();
+		track.pause();
+		while (running && Call.call_state == Call.UA_STATE_HOLD) {
+		    try {
+			sleep(1000);
+		    } catch (InterruptedException e1) {
+			e1.printStackTrace();
+		    }
 		}
-		try {
-			rtp_socket.getDatagramSocket().setSoTimeout(1000);
-		} catch (SocketException e2) {
-			if (!Sipdroid.release) e2.printStackTrace();
+		track.play();
+		System.gc();
+		timeout = 1;
+		seq = 0;
+	    }
+	    try {
+		rtp_socket.receive(rtp_packet);
+		if (timeout != 0) {
+		    tg.stopTone();
+		    track.pause();
+		    user += track.write(lin2,0,BUFFER_SIZE);
+		    user += track.write(lin2,0,BUFFER_SIZE);
+		    track.play();
+		    cnt += 2*BUFFER_SIZE;
+		    empty();
 		}
-	}
-	
-	RtpPacket rtp_packet;
-	AudioTrack track;
-	
-	/** Runs it in a new Thread. */
-	public void run() {
-		boolean nodata = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getBoolean("nodata",false);
-		
-		if (rtp_socket == null) {
-			if (DEBUG)
-				println("ERROR: RTP socket is null");
-			return;
+		timeout = 0;
+	    } catch (IOException e) {
+		if (timeout == 0 && nodata) {
+		    tg.startTone(ToneGenerator.TONE_SUP_RINGTONE);
+		}
+		rtp_socket.getDatagramSocket().disconnect();
+		if (++timeout > 22) {
+		    try {
+			mJingle.closeCall();
+		    } catch (RemoteException e1) {
+			e1.printStackTrace();
+		    }
+		    break;
+		}
+	    }
+	    if (running && timeout == 0) {		
+		gseq = rtp_packet.getSequenceNumber();
+		if (seq == gseq) {
+		    m++;
+		    continue;
 		}
 
-		byte[] buffer = new byte[BUFFER_SIZE+12];
-		byte[] buffer_gsm = new byte[33+12];
-		int i;
-		rtp_packet = new RtpPacket(buffer, 0);
+		server = track.getPlaybackHeadPosition();
+		headroom = user-server;
 
-		if (DEBUG)
-			println("Reading blocks of max " + buffer.length + " bytes");
+		if (headroom > 1500)
+		    cnt += len;
+		else
+		    cnt = 0;
 
-		running = true;
-		speakermode = Receiver.docked > 0?AudioManager.MODE_NORMAL:AudioManager.MODE_IN_CALL;
-		restored = false;
+		if (lserver == server)
+		    cnt2++;
+		else
+		    cnt2 = 0;
 
-		android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO);
-		am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE);
-        cr = Receiver.mContext.getContentResolver();
-		saveSettings();
-		Settings.System.putInt(cr, Settings.System.WIFI_SLEEP_POLICY,Settings.System.WIFI_SLEEP_POLICY_NEVER);
-		am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,AudioManager.VIBRATE_SETTING_OFF);
-		am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,AudioManager.VIBRATE_SETTING_OFF);
-		int oldvol = am.getStreamVolume(AudioManager.STREAM_MUSIC);
-		track = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT,
-				BUFFER_SIZE*2*2, AudioTrack.MODE_STREAM);
-		short lin[] = new short[BUFFER_SIZE];
-		short lin2[] = new short[BUFFER_SIZE];
-		int user, server, lserver, luser, cnt, todo, headroom, len = 0, seq = 0, cnt2 = 0, m = 1,
-			expseq, getseq, vm = 1, gap, gseq;
-		timeout = 1;
-		boolean islate;
-		user = 0;
-		lserver = 0;
-		luser = -8000;
-		cnt = 0;
-		switch (p_type) {
-		case 3:
-			Codec.init();
-			break;
-		case 0:
-		case 8:
-			G711.init();
-			break;
+		if (cnt <= 500 || cnt2 >= 2 || headroom - 875 < len) {
+		    switch (rtp_packet.getPayloadType()) {
+			case 0:
+			    len = rtp_packet.getPayloadLength();
+			    G711.ulaw2linear(buffer, lin, len);
+			    break;
+			case 8:
+			    len = rtp_packet.getPayloadLength();
+			    G711.alaw2linear(buffer, lin, len);
+			    break;
+			case 3:
+			    for (i = 12; i < 45; i++)
+				buffer_gsm[i] = buffer[i];
+			    len = Codec.decode(buffer_gsm, lin, 0);
+			    break;
+		    }
+
+		    if (speakermode == AudioManager.MODE_NORMAL)
+			calc(lin,0,len);
 		}
-		ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_MUSIC,(int)(ToneGenerator.MAX_VOLUME*2*org.sipdroid.sipua.ui.Settings.getEarGain()));
-		track.play();
-		if (Receiver.headset > 0 && Receiver.oRingtone != null) {
-			ToneGenerator tg2 = new ToneGenerator(AudioManager.STREAM_RING,(int)(ToneGenerator.MAX_VOLUME*2*org.sipdroid.sipua.ui.Settings.getEarGain()));
-			tg2.startTone(ToneGenerator.TONE_SUP_RINGTONE);
-			System.gc();
-			tg2.stopTone();
+
+		if (headroom < 250) { 
+		    todo = 875 - headroom;
+		    println("insert "+todo);
+		    islate = true;
+		    user += track.write(lin2,0,todo);
 		} else
-			System.gc();
-		while (running) {
-			if (Receiver.call_state == UserAgent.UA_STATE_HOLD) {
-				tg.stopTone();
-				track.pause();
-				while (running && Receiver.call_state == UserAgent.UA_STATE_HOLD) {
-					try {
-						sleep(1000);
-					} catch (InterruptedException e1) {
-					}
-				}
-				track.play();
-				System.gc();
-				timeout = 1;
-				seq = 0;
-			}
-			try {
-				rtp_socket.receive(rtp_packet);
-				if (timeout != 0) {
-					tg.stopTone();
-					track.pause();
-					user += track.write(lin2,0,BUFFER_SIZE);
-					user += track.write(lin2,0,BUFFER_SIZE);
-					track.play();
-					cnt += 2*BUFFER_SIZE;
-					empty();
-				}
-				timeout = 0;
-			} catch (IOException e) {
-				if (timeout == 0 && nodata) {
-					tg.startTone(ToneGenerator.TONE_SUP_RINGTONE);
-				}
-				rtp_socket.getDatagramSocket().disconnect();
-				if (++timeout > 22) {
-					Receiver.engine(Receiver.mContext).rejectcall();
-					break;
-				}
-			}
-			if (running && timeout == 0) {		
-				 gseq = rtp_packet.getSequenceNumber();
-				 if (seq == gseq) {
-					 m++;
-					 continue;
-				 }
-				 
-				 server = track.getPlaybackHeadPosition();
-				 headroom = user-server;
-				 
-				 if (headroom > 1500)
-					 cnt += len;
-				 else
-					 cnt = 0;
-				 
-				 if (lserver == server)
-					 cnt2++;
-				 else
-					 cnt2 = 0;
+		    islate = false;
+
+		if (cnt > 500 && cnt2 < 2) {
+		    todo = headroom - 875;
+		    println("cut "+todo);
+		    if (todo < len)
+			user += track.write(lin,todo,len-todo);
+		} else
+		    user += track.write(lin,0,len);
 
-				 if (cnt <= 500 || cnt2 >= 2 || headroom - 875 < len) {
-					 switch (rtp_packet.getPayloadType()) {
-					 case 0:
-						 len = rtp_packet.getPayloadLength();
-						 G711.ulaw2linear(buffer, lin, len);
-						 break;
-					 case 8:
-						 len = rtp_packet.getPayloadLength();
-						 G711.alaw2linear(buffer, lin, len);
-						 break;
-					 case 3:
-						 for (i = 12; i < 45; i++)
-							 buffer_gsm[i] = buffer[i];
-						 len = Codec.decode(buffer_gsm, lin, 0);
-						 break;
-					 }
-					 
-		 			 if (speakermode == AudioManager.MODE_NORMAL)
-		 				 calc(lin,0,len);
-				 }
-				 
-	 			 if (headroom < 250) { 
-					todo = 875 - headroom;
-					println("insert "+todo);
-					islate = true;
-					user += track.write(lin2,0,todo);
-				 } else
-					islate = false;
+		seq = gseq;
 
-				 if (cnt > 500 && cnt2 < 2) {
-					 todo = headroom - 875;
-					 println("cut "+todo);
-					 if (todo < len)
-						 user += track.write(lin,todo,len-todo);
-				 } else
-					 user += track.write(lin,0,len);
-				 
-				 if (seq != 0) {
-					 getseq = gseq&0xff;
-					 expseq = ++seq&0xff;
-					 if (m == RtpStreamSender.m) vm = m;
-					 gap = (getseq - expseq) & 0xff;
-					 if (gap > 0) {
-						 if (gap > 100) gap = 1;
-						 loss += gap;
-						 lost += gap;
-						 good += gap - 1;
-					 } else {
-						 if (m < vm)
-							 loss++;
-						 if (islate)
-							 late++;
-					 }
-					 good++;
-					 if (good > 100) {
-						 good *= 0.99;
-						 lost *= 0.99;
-						 loss *= 0.99;
-						 late *= 0.99;
-					 }
-				 }
-				 m = 1;
-				 seq = gseq;
-				 
-				 if (user >= luser + 8000 && Receiver.call_state == UserAgent.UA_STATE_INCALL) {
-					 if (luser == -8000 || am.getMode() != speakermode) {
-						 saveVolume();
-						 setMode(speakermode);
-						 restoreVolume();
-					 }
-					 luser = user;
-				 }
-				 lserver = server;
-			}
+		if (user >= luser + 8000 && Call.call_state == Call.UA_STATE_INCALL) {
+		    if (luser == -8000 || am.getMode() != speakermode) {
+			saveVolume();
+			setMode(speakermode);
+			restoreVolume();
+		    }
+		    luser = user;
 		}
-		track.stop();
-		saveVolume();
-		setStreamVolume(AudioManager.STREAM_MUSIC,oldvol,0);
-		restoreSettings();
-		setStreamVolume(AudioManager.STREAM_MUSIC,oldvol,0);
-		tg.stopTone();
-		tg = new ToneGenerator(AudioManager.STREAM_RING,ToneGenerator.MAX_VOLUME/4*3);
-		tg.startTone(ToneGenerator.TONE_PROP_PROMPT);
-		try {
-			sleep(500);
-		} catch (InterruptedException e) {
-		}
-		tg.stopTone();
-		
-		rtp_socket.close();
-		rtp_socket = null;
+		lserver = server;
+	    }
+	}
+	track.stop();
+	saveVolume();
+	setStreamVolume(AudioManager.STREAM_MUSIC,oldvol,0);
+	restoreSettings();
+	setStreamVolume(AudioManager.STREAM_MUSIC,oldvol,0);
+	tg.stopTone();
+	tg = new ToneGenerator(AudioManager.STREAM_RING,ToneGenerator.MAX_VOLUME/4*3);
+	tg.startTone(ToneGenerator.TONE_PROP_PROMPT);
+	try {
+	    sleep(500);
+	} catch (InterruptedException e) {
+	    e.printStackTrace();
+	}
+	tg.stopTone();
 
-		if (DEBUG)
-			println("rtp receiver terminated");
-	}
+	rtp_socket.close();
+	rtp_socket = null;
 
-	/** Debug output */
-	private static void println(String str) {
-		if (!Sipdroid.release) System.out.println("RtpStreamReceiver: " + str);
-	}
+	if (DEBUG)
+	    println("rtp receiver terminated");
+    }
 
-	public static int byte2int(byte b) { // return (b>=0)? b : -((b^0xFF)+1);
-		// return (b>=0)? b : b+0x100;
-		return (b + 0x100) % 0x100;
-	}
+    /** Debug output */
+    private static void println(String str) {
+	System.out.println("RtpStreamReceiver: " + str);
+    }
 
-	public static int byte2int(byte b1, byte b2) {
-		return (((b1 + 0x100) % 0x100) << 8) + (b2 + 0x100) % 0x100;
-	}
+    public static int byte2int(byte b) { // return (b>=0)? b : -((b^0xFF)+1);
+	// return (b>=0)? b : b+0x100;
+	return (b + 0x100) % 0x100;
+    }
+
+    public static int byte2int(byte b1, byte b2) {
+	return (((b1 + 0x100) % 0x100) << 8) + (b2 + 0x100) % 0x100;
+    }
 }
--- a/src/org/sipdroid/media/RtpStreamSender.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/org/sipdroid/media/RtpStreamSender.java	Sun Jan 24 00:42:29 2010 +0100
@@ -19,22 +19,23 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-package src.org.sipdroid.media;
+package org.sipdroid.media;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetAddress;
 import java.util.Random;
 
-import org.sipdroid.sipua.UserAgent;
-import org.sipdroid.sipua.ui.Receiver;
-import org.sipdroid.sipua.ui.Settings;
-import org.sipdroid.sipua.ui.Sipdroid;
+
 import org.sipdroid.pjlib.Codec;
 
-import src.org.sipdroid.net.RtpPacket;
-import src.org.sipdroid.net.RtpSocket;
-import src.org.sipdroid.net.SipdroidSocket;
+import org.sipdroid.media.RtpStreamReceiver;
+import org.sipdroid.net.RtpPacket;
+import org.sipdroid.net.RtpSocket;
+import org.sipdroid.net.SipdroidSocket;
+
+import com.beem.project.beem.ui.Call;
+import com.beem.project.beem.utils.BeemConnectivity;
 
 import android.content.Context;
 import android.media.AudioFormat;
@@ -42,6 +43,7 @@
 import android.media.AudioRecord;
 import android.media.MediaRecorder;
 import android.preference.PreferenceManager;
+import android.provider.Settings;
 import android.telephony.TelephonyManager;
 
 /**
@@ -49,331 +51,326 @@
  * it through RTP.
  */
 public class RtpStreamSender extends Thread {
-	/** Whether working in debug mode. */
-	public static boolean DEBUG = true;
+    /** Whether working in debug mode. */
+    public static boolean DEBUG = true;
+
+    /** The RtpSocket */
+    RtpSocket rtp_socket = null;
 
-	/** The RtpSocket */
-	RtpSocket rtp_socket = null;
+    /** Payload type */
+    int p_type;
+
+    /** Number of frame per second */
+    long frame_rate;
 
-	/** Payload type */
-	int p_type;
+    /** Number of bytes per frame */
+    int frame_size;
 
-	/** Number of frame per second */
-	long frame_rate;
+    /**
+     * Whether it works synchronously with a local clock, or it it acts as slave
+     * of the InputStream
+     */
+    boolean do_sync = true;
 
-	/** Number of bytes per frame */
-	int frame_size;
+    /**
+     * Synchronization correction value, in milliseconds. It accellarates the
+     * sending rate respect to the nominal value, in order to compensate program
+     * latencies.
+     */
+    int sync_adj = 0;
 
-	/**
-	 * Whether it works synchronously with a local clock, or it it acts as slave
-	 * of the InputStream
-	 */
-	boolean do_sync = true;
+    /** Whether it is running */
+    boolean running = false;
+    boolean muted = false;
 
-	/**
-	 * Synchronization correction value, in milliseconds. It accellarates the
-	 * sending rate respect to the nominal value, in order to compensate program
-	 * latencies.
-	 */
-	int sync_adj = 0;
-
-	/** Whether it is running */
-	boolean running = false;
-	boolean muted = false;
+    /**
+     * Constructs a RtpStreamSender.
+     * 
+     * @param input_stream
+     *            the stream to be sent
+     * @param do_sync
+     *            whether time synchronization must be performed by the
+     *            RtpStreamSender, or it is performed by the InputStream (e.g.
+     *            the system audio input)
+     * @param payload_type
+     *            the payload type
+     * @param frame_rate
+     *            the frame rate, i.e. the number of frames that should be sent
+     *            per second; it is used to calculate the nominal packet time
+     *            and,in case of do_sync==true, the next departure time
+     * @param frame_size
+     *            the size of the payload
+     * @param src_socket
+     *            the socket used to send the RTP packet
+     * @param dest_addr
+     *            the destination address
+     * @param dest_port
+     *            the destination port
+     */
+    public RtpStreamSender(boolean do_sync,
+	int payload_type, long frame_rate, int frame_size,
+	SipdroidSocket src_socket, String dest_addr, int dest_port) {
+	init(do_sync, payload_type, frame_rate, frame_size,
+	    src_socket, dest_addr, dest_port);
+    }
 
-	/**
-	 * Constructs a RtpStreamSender.
-	 * 
-	 * @param input_stream
-	 *            the stream to be sent
-	 * @param do_sync
-	 *            whether time synchronization must be performed by the
-	 *            RtpStreamSender, or it is performed by the InputStream (e.g.
-	 *            the system audio input)
-	 * @param payload_type
-	 *            the payload type
-	 * @param frame_rate
-	 *            the frame rate, i.e. the number of frames that should be sent
-	 *            per second; it is used to calculate the nominal packet time
-	 *            and,in case of do_sync==true, the next departure time
-	 * @param frame_size
-	 *            the size of the payload
-	 * @param src_socket
-	 *            the socket used to send the RTP packet
-	 * @param dest_addr
-	 *            the destination address
-	 * @param dest_port
-	 *            the destination port
-	 */
-	public RtpStreamSender(boolean do_sync,
-			int payload_type, long frame_rate, int frame_size,
-			SipdroidSocket src_socket, String dest_addr, int dest_port) {
-		init(do_sync, payload_type, frame_rate, frame_size,
-				src_socket, dest_addr, dest_port);
+    /** Inits the RtpStreamSender */
+    private void init(boolean do_sync,
+	int payload_type, long frame_rate, int frame_size,
+	SipdroidSocket src_socket, String dest_addr,
+	int dest_port) {
+	this.p_type = payload_type;
+	this.frame_rate = frame_rate;
+	this.frame_size = frame_size;
+	this.do_sync = do_sync;
+	try {
+	    rtp_socket = new RtpSocket(src_socket, InetAddress
+		.getByName(dest_addr), dest_port);
+	} catch (Exception e) {
+	    e.printStackTrace();
 	}
+    }
+
+    /** Sets the synchronization adjustment time (in milliseconds). */
+    public void setSyncAdj(int millisecs) {
+	sync_adj = millisecs;
+    }
+
+    /** Whether is running */
+    public boolean isRunning() {
+	return running;
+    }
+
+    public boolean mute() {
+	return muted = !muted;
+    }
+
+    public static int delay = 0;
 
-	/** Inits the RtpStreamSender */
-	private void init(boolean do_sync,
-			int payload_type, long frame_rate, int frame_size,
-			SipdroidSocket src_socket, String dest_addr,
-			int dest_port) {
-		this.p_type = payload_type;
-		this.frame_rate = frame_rate;
-		this.frame_size = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getString("server","").equals("pbxes.org")?
-				(payload_type == 3?960:1024):frame_size; //15
-		this.do_sync = do_sync;
-		try {
-			rtp_socket = new RtpSocket(src_socket, InetAddress
-					.getByName(dest_addr), dest_port);
-		} catch (Exception e) {
-			if (!Sipdroid.release) e.printStackTrace();
-		}
-	}
+    /** Stops running */
+    public void halt() {
+	running = false;
+    }
+
+    Random random;
+    double smin = 200,s;
+    int nearend;
+
+    void calc(short[] lin,int off,int len) {
+	int i,j;
+	double sm = 30000,r;
 
-	/** Sets the synchronization adjustment time (in milliseconds). */
-	public void setSyncAdj(int millisecs) {
-		sync_adj = millisecs;
-	}
-
-	/** Whether is running */
-	public boolean isRunning() {
-		return running;
+	for (i = 0; i < len; i += 5) {
+	    j = lin[i+off];
+	    s = 0.03*Math.abs(j) + 0.97*s;
+	    if (s < sm) sm = s;
+	    if (s > smin) nearend = 3000/5;
+	    else if (nearend > 0) nearend--;
 	}
-	
-	public boolean mute() {
-		return muted = !muted;
+	for (i = 0; i < len; i++) {
+	    j = lin[i+off];
+	    if (j > 6550)
+		lin[i+off] = 6550*5;
+	    else if (j < -6550)
+		lin[i+off] = -6550*5;
+	    else
+		lin[i+off] = (short)(j*5);
 	}
+	r = (double)len/100000;
+	smin = sm*r + smin*(1-r);
+    }
 
-	public static int delay = 0;
-	
-	/** Stops running */
-	public void halt() {
-		running = false;
+    void calc1(short[] lin,int off,int len) {
+	int i,j;
+
+	for (i = 0; i < len; i++) {
+	    j = lin[i+off];
+	    lin[i+off] = (short)(j>>1);
 	}
+    }
 
-	Random random;
-	double smin = 200,s;
-	int nearend;
-	
-	void calc(short[] lin,int off,int len) {
-		int i,j;
-		double sm = 30000,r;
-		
-		for (i = 0; i < len; i += 5) {
-			j = lin[i+off];
-			s = 0.03*Math.abs(j) + 0.97*s;
-			if (s < sm) sm = s;
-			if (s > smin) nearend = 3000/5;
-			else if (nearend > 0) nearend--;
-		}
-		for (i = 0; i < len; i++) {
-			j = lin[i+off];
-			if (j > 6550)
-				lin[i+off] = 6550*5;
-			else if (j < -6550)
-				lin[i+off] = -6550*5;
-			else
-				lin[i+off] = (short)(j*5);
-		}
-		r = (double)len/100000;
-		smin = sm*r + smin*(1-r);
+    void calc5(short[] lin,int off,int len) {
+	int i,j;
+
+	for (i = 0; i < len; i++) {
+	    j = lin[i+off];
+	    if (j > 16350)
+		lin[i+off] = 16350<<1;
+	    else if (j < -16350)
+		lin[i+off] = -16350<<1;
+	    else
+		lin[i+off] = (short)(j<<1);
+	}
+    }
+
+    void calc10(short[] lin,int off,int len) {
+	int i,j;
+
+	for (i = 0; i < len; i++) {
+	    j = lin[i+off];
+	    if (j > 8150)
+		lin[i+off] = 8150<<2;
+	    else if (j < -8150)
+		lin[i+off] = -8150<<2;
+	    else
+		lin[i+off] = (short)(j<<2);
 	}
+    }
 
-	void calc1(short[] lin,int off,int len) {
-		int i,j;
-		
-		for (i = 0; i < len; i++) {
-			j = lin[i+off];
-			lin[i+off] = (short)(j>>1);
-		}
-	}
+    void noise(short[] lin,int off,int len,double power) {
+	int i,r = (int)(power*2);
+	short ran;
 
-	void calc5(short[] lin,int off,int len) {
-		int i,j;
-		
-		for (i = 0; i < len; i++) {
-			j = lin[i+off];
-			if (j > 16350)
-				lin[i+off] = 16350<<1;
-			else if (j < -16350)
-				lin[i+off] = -16350<<1;
-			else
-				lin[i+off] = (short)(j<<1);
-		}
+	if (r == 0) r = 1;
+	for (i = 0; i < len; i += 4) {
+	    ran = (short)(random.nextInt(r*2)-r);
+	    lin[i+off] = ran;
+	    lin[i+off+1] = ran;
+	    lin[i+off+2] = ran;
+	    lin[i+off+3] = ran;
 	}
+    }
+    public static float getMicGain() {
+	if (Call.headset > 0)
+	    return Float.valueOf(PreferenceManager.getDefaultSharedPreferences(Call.mContext).getString("hmicgain", "1.0"));
+	return Float.valueOf(PreferenceManager.getDefaultSharedPreferences(Call.mContext).getString("micgain", "0.25"));
+    }
+
+    /** Runs it in a new Thread. */
+    public void run() {
+	if (rtp_socket == null)
+	    return;
+	byte[] buffer = new byte[frame_size + 12];
+	RtpPacket rtp_packet = new RtpPacket(buffer, 0);
+	rtp_packet.setPayloadType(p_type);
+	int seqn = 0;
+	long time = 0;
+	double p = 0;
+	TelephonyManager tm = (TelephonyManager) Call.mContext.getSystemService(Context.TELEPHONY_SERVICE);
+	boolean improve = PreferenceManager.getDefaultSharedPreferences(Call.mContext).getBoolean("improve",false);
+	boolean useGSM = !PreferenceManager.getDefaultSharedPreferences(Call.mContext).getString("compression","edge").equals("never");
+	int micgain = (int)(getMicGain()*10);
+	running = true;
+
+	if (DEBUG)
+	    println("Reading blocks of " + buffer.length + " bytes");
 
-	void calc10(short[] lin,int off,int len) {
-		int i,j;
-		
-		for (i = 0; i < len; i++) {
-			j = lin[i+off];
-			if (j > 8150)
-				lin[i+off] = 8150<<2;
-			else if (j < -8150)
-				lin[i+off] = -8150<<2;
-			else
-				lin[i+off] = (short)(j<<2);
-		}
+	android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
+	AudioRecord record = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, 
+	    AudioRecord.getMinBufferSize(8000, 
+		AudioFormat.CHANNEL_CONFIGURATION_MONO, 
+		AudioFormat.ENCODING_PCM_16BIT)*3/2);
+	short[] lin = new short[frame_size*11];
+	int num,ring = 0;
+	random = new Random();
+	InputStream alerting = null;
+	try {
+	    alerting = Call.mContext.getAssets().open("alerting");
+	} catch (IOException e2) {
+	    e2.printStackTrace();
 	}
-
-	void noise(short[] lin,int off,int len,double power) {
-		int i,r = (int)(power*2);
-		short ran;
-
-		if (r == 0) r = 1;
-		for (i = 0; i < len; i += 4) {
-			ran = (short)(random.nextInt(r*2)-r);
-			lin[i+off] = ran;
-			lin[i+off+1] = ran;
-			lin[i+off+2] = ran;
-			lin[i+off+3] = ran;
-		}
+	switch (p_type) {
+	    case 3:
+		Codec.init();
+		break;
+	    case 0:
+	    case 8:
+		G711.init();
+		break;
 	}
-	
-	public static int m;
-	
-	/** Runs it in a new Thread. */
-	public void run() {
-		if (rtp_socket == null)
-			return;
-		byte[] buffer = new byte[frame_size + 12];
-		RtpPacket rtp_packet = new RtpPacket(buffer, 0);
-		rtp_packet.setPayloadType(p_type);
-		int seqn = 0;
-		long time = 0;
-		double p = 0;
-		TelephonyManager tm = (TelephonyManager) Receiver.mContext.getSystemService(Context.TELEPHONY_SERVICE);
-		boolean improve = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getBoolean("improve",false);
-		boolean useGSM = !PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getString("compression","edge").equals("never");
-		int micgain = (int)(Settings.getMicGain()*10);
-		running = true;
-		m = 1;
+	record.startRecording();
+	while (running) {
+	    if (muted || Call.call_state == Call.UA_STATE_HOLD) {
+		record.stop();
+		while (running && (muted || Call.call_state == Call.UA_STATE_HOLD)) {
+		    try {
+			sleep(1000);
+		    } catch (InterruptedException e1) {
+			e1.printStackTrace();
+		    }
+		}
+		record.startRecording();
+	    }
+	    num = record.read(lin,(ring+delay)%(frame_size*11),frame_size);
 
-		if (DEBUG)
-			println("Reading blocks of " + buffer.length + " bytes");
-
-		android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
-		AudioRecord record = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, 
-				AudioRecord.getMinBufferSize(8000, 
-						AudioFormat.CHANNEL_CONFIGURATION_MONO, 
-						AudioFormat.ENCODING_PCM_16BIT)*3/2);
-		short[] lin = new short[frame_size*11];
-		int num,ring = 0;
-		random = new Random();
-		InputStream alerting = null;
+	    if (RtpStreamReceiver.speakermode == AudioManager.MODE_NORMAL) {
+		calc(lin,(ring+delay)%(frame_size*11),num);
+		if (RtpStreamReceiver.nearend != 0)
+		    noise(lin,(ring+delay)%(frame_size*11),num,p);
+		else if (RtpStreamReceiver.nearend == 0)
+		    p = 0.9*p + 0.1*s;
+	    } else switch (micgain) {
+		case 1:
+		    calc1(lin,(ring+delay)%(frame_size*11),num);
+		    break;
+		case 5:
+		    calc5(lin,(ring+delay)%(frame_size*11),num);
+		    break;
+		case 10:
+		    calc10(lin,(ring+delay)%(frame_size*11),num);
+		    break;
+	    }
+	    if (Call.call_state != Call.UA_STATE_INCALL && alerting != null) {
 		try {
-			alerting = Receiver.mContext.getAssets().open("alerting");
-		} catch (IOException e2) {
-			if (!Sipdroid.release) e2.printStackTrace();
+		    if (alerting.available() < num)
+			alerting.reset();
+		    alerting.read(buffer,12,num);
+		} catch (IOException e) {
+		    e.printStackTrace();
 		}
-		switch (p_type) {
-		case 3:
-			Codec.init();
+		switch (p_type) {// have to add ulaw case?
+		    case 3:
+			G711.alaw2linear(buffer, lin, num);
+			num = Codec.encode(lin, 0, buffer, num);
 			break;
-		case 0:
-		case 8:
-			G711.init();
+		    case 0:
+			G711.alaw2linear(buffer, lin, num);
+			G711.linear2ulaw(lin, 0, buffer, num);
 			break;
 		}
-		record.startRecording();
-		while (running) {
-			 if (muted || Receiver.call_state == UserAgent.UA_STATE_HOLD) {
-				record.stop();
-				while (running && (muted || Receiver.call_state == UserAgent.UA_STATE_HOLD)) {
-					try {
-						sleep(1000);
-					} catch (InterruptedException e1) {
-					}
-				}
-				record.startRecording();
-			 }
-			 num = record.read(lin,(ring+delay)%(frame_size*11),frame_size);
+	    } else {
+		switch (p_type) {
+		    case 3:
+			num = Codec.encode(lin, ring%(frame_size*11), buffer, num);
+			break;
+		    case 0:
+			G711.linear2ulaw(lin, ring%(frame_size*11), buffer, num);
+			break;
+		    case 8:
+			G711.linear2alaw(lin, ring%(frame_size*11), buffer, num);
+			break;
+		}
+	    }
+	    ring += frame_size;
+	    rtp_packet.setSequenceNumber(seqn++);
+	    rtp_packet.setTimestamp(time);
+	    rtp_packet.setPayloadLength(num);
+	    try {
+		rtp_socket.send(rtp_packet);
+	    } catch (IOException e) {
+		e.printStackTrace();
+	    }
+	    time += frame_size;
+	    if (useGSM && p_type == 8 && !BeemConnectivity.isWifi(Call.mContext) && tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE) {
+		rtp_packet.setPayloadType(p_type = 3);
+		if (frame_size == 1024) {
+		    frame_size = 960;
+		    ring = 0;
+		}
+	    }
+	}
+	record.stop();
 
-			 if (RtpStreamReceiver.speakermode == AudioManager.MODE_NORMAL) {
- 				 calc(lin,(ring+delay)%(frame_size*11),num);
- 	 			 if (RtpStreamReceiver.nearend != 0)
-	 				 noise(lin,(ring+delay)%(frame_size*11),num,p);
-	 			 else if (nearend == 0)
-	 				 p = 0.9*p + 0.1*s;
- 			 } else switch (micgain) {
- 			 case 1:
- 				 calc1(lin,(ring+delay)%(frame_size*11),num);
- 				 break;
- 			 case 5:
- 				 calc5(lin,(ring+delay)%(frame_size*11),num);
- 				 break;
- 			 case 10:
- 				 calc10(lin,(ring+delay)%(frame_size*11),num);
- 				 break;
- 			 }
-			 if (Receiver.call_state != UserAgent.UA_STATE_INCALL && alerting != null) {
-				 try {
-					if (alerting.available() < num)
-						alerting.reset();
-					alerting.read(buffer,12,num);
-				 } catch (IOException e) {
-					if (!Sipdroid.release) e.printStackTrace();
-				 }
-				 switch (p_type) {// have to add ulaw case?
-				 case 3:
-					 G711.alaw2linear(buffer, lin, num);
-					 num = Codec.encode(lin, 0, buffer, num);
-					 break;
-				 case 0:
-					 G711.alaw2linear(buffer, lin, num);
-					 G711.linear2ulaw(lin, 0, buffer, num);
-					 break;
-				 }
-			 } else {
-				 switch (p_type) {
-				 case 3:
-					 num = Codec.encode(lin, ring%(frame_size*11), buffer, num);
-					 break;
-				 case 0:
-					 G711.linear2ulaw(lin, ring%(frame_size*11), buffer, num);
-					 break;
-				 case 8:
-					 G711.linear2alaw(lin, ring%(frame_size*11), buffer, num);
-					 break;
-				 }
-			 }
- 			 ring += frame_size;
- 			 rtp_packet.setSequenceNumber(seqn++);
- 			 rtp_packet.setTimestamp(time);
- 			 rtp_packet.setPayloadLength(num);
- 			 try {
- 				 rtp_socket.send(rtp_packet);
- 				 if (m == 2)
- 					 rtp_socket.send(rtp_packet);
- 			 } catch (IOException e) {
- 			 }
-			 time += frame_size;
- 			 if (improve && RtpStreamReceiver.good != 0 &&
- 					 RtpStreamReceiver.loss/RtpStreamReceiver.good > 0.01 &&
- 					 (Receiver.on_wlan || tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_EDGE))        	
- 				 m = 2;
- 			 else
- 				 m = 1;
- 			 if (useGSM && p_type == 8 && !Receiver.on_wlan && tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE) {
- 				 rtp_packet.setPayloadType(p_type = 3);
- 				 if (frame_size == 1024) {
- 					 frame_size = 960;
- 					 ring = 0;
- 				 }
- 			 }
-		}
-		record.stop();
-		
-		rtp_socket.close();
-		rtp_socket = null;
+	rtp_socket.close();
+	rtp_socket = null;
 
-		if (DEBUG)
-			println("rtp sender terminated");
-	}
+	if (DEBUG)
+	    println("rtp sender terminated");
+    }
 
-	/** Debug output */
-	private static void println(String str) {
-		if (!Sipdroid.release) System.out.println("RtpStreamSender: " + str);
-	}
+    /** Debug output */
+    private static void println(String str) {
+	System.out.println("RtpStreamSender: " + str);
+    }
 
 }
\ No newline at end of file
--- a/src/org/sipdroid/net/RtpPacket.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/org/sipdroid/net/RtpPacket.java	Sun Jan 24 00:42:29 2010 +0100
@@ -19,300 +19,300 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-package src.org.sipdroid.net;
+package org.sipdroid.net;
 
-import org.zoolu.tools.Random;
+import com.beem.project.beem.utils.Random;
 
 /**
  * RtpPacket implements a RTP packet.
  */
 public class RtpPacket {
-	/* RTP packet buffer containing both the RTP header and payload */
-	byte[] packet;
+    /* RTP packet buffer containing both the RTP header and payload */
+    byte[] packet;
 
-	/* RTP packet length */
-	int packet_len;
+    /* RTP packet length */
+    int packet_len;
 
-	/* RTP header length */
-	// int header_len;
-	/** Gets the RTP packet */
-	public byte[] getPacket() {
-		return packet;
-	}
+    /* RTP header length */
+    // int header_len;
+    /** Gets the RTP packet */
+    public byte[] getPacket() {
+	return packet;
+    }
 
-	/** Gets the RTP packet length */
-	public int getLength() {
-		return packet_len;
-	}
+    /** Gets the RTP packet length */
+    public int getLength() {
+	return packet_len;
+    }
 
-	/** Gets the RTP header length */
-	public int getHeaderLength() {
-		if (packet_len >= 12)
-			return 12 + 4 * getCscrCount();
-		else
-			return packet_len; // broken packet
-	}
+    /** Gets the RTP header length */
+    public int getHeaderLength() {
+	if (packet_len >= 12)
+	    return 12 + 4 * getCscrCount();
+	else
+	    return packet_len; // broken packet
+    }
 
-	/** Gets the RTP header length */
-	public int getPayloadLength() {
-		if (packet_len >= 12)
-			return packet_len - getHeaderLength();
-		else
-			return 0; // broken packet
-	}
+    /** Gets the RTP header length */
+    public int getPayloadLength() {
+	if (packet_len >= 12)
+	    return packet_len - getHeaderLength();
+	else
+	    return 0; // broken packet
+    }
 
-	/** Sets the RTP payload length */
-	public void setPayloadLength(int len) {
-		packet_len = getHeaderLength() + len;
-	}
+    /** Sets the RTP payload length */
+    public void setPayloadLength(int len) {
+	packet_len = getHeaderLength() + len;
+    }
 
-	// version (V): 2 bits
-	// padding (P): 1 bit
-	// extension (X): 1 bit
-	// CSRC count (CC): 4 bits
-	// marker (M): 1 bit
-	// payload type (PT): 7 bits
-	// sequence number: 16 bits
-	// timestamp: 32 bits
-	// SSRC: 32 bits
-	// CSRC list: 0 to 15 items, 32 bits each
+    // version (V): 2 bits
+    // padding (P): 1 bit
+    // extension (X): 1 bit
+    // CSRC count (CC): 4 bits
+    // marker (M): 1 bit
+    // payload type (PT): 7 bits
+    // sequence number: 16 bits
+    // timestamp: 32 bits
+    // SSRC: 32 bits
+    // CSRC list: 0 to 15 items, 32 bits each
 
-	/** Gets the version (V) */
-	public int getVersion() {
-		if (packet_len >= 12)
-			return (packet[0] >> 6 & 0x03);
-		else
-			return 0; // broken packet
-	}
+    /** Gets the version (V) */
+    public int getVersion() {
+	if (packet_len >= 12)
+	    return (packet[0] >> 6 & 0x03);
+	else
+	    return 0; // broken packet
+    }
 
-	/** Sets the version (V) */
-	public void setVersion(int v) {
-		if (packet_len >= 12)
-			packet[0] = (byte) ((packet[0] & 0x3F) | ((v & 0x03) << 6));
-	}
+    /** Sets the version (V) */
+    public void setVersion(int v) {
+	if (packet_len >= 12)
+	    packet[0] = (byte) ((packet[0] & 0x3F) | ((v & 0x03) << 6));
+    }
 
-	/** Whether has padding (P) */
-	public boolean hasPadding() {
-		if (packet_len >= 12)
-			return getBit(packet[0], 5);
-		else
-			return false; // broken packet
-	}
+    /** Whether has padding (P) */
+    public boolean hasPadding() {
+	if (packet_len >= 12)
+	    return getBit(packet[0], 5);
+	else
+	    return false; // broken packet
+    }
 
-	/** Set padding (P) */
-	public void setPadding(boolean p) {
-		if (packet_len >= 12)
-			packet[0] = setBit(p, packet[0], 5);
-	}
+    /** Set padding (P) */
+    public void setPadding(boolean p) {
+	if (packet_len >= 12)
+	    packet[0] = setBit(p, packet[0], 5);
+    }
 
-	/** Whether has extension (X) */
-	public boolean hasExtension() {
-		if (packet_len >= 12)
-			return getBit(packet[0], 4);
-		else
-			return false; // broken packet
-	}
+    /** Whether has extension (X) */
+    public boolean hasExtension() {
+	if (packet_len >= 12)
+	    return getBit(packet[0], 4);
+	else
+	    return false; // broken packet
+    }
 
-	/** Set extension (X) */
-	public void setExtension(boolean x) {
-		if (packet_len >= 12)
-			packet[0] = setBit(x, packet[0], 4);
-	}
+    /** Set extension (X) */
+    public void setExtension(boolean x) {
+	if (packet_len >= 12)
+	    packet[0] = setBit(x, packet[0], 4);
+    }
 
-	/** Gets the CSCR count (CC) */
-	public int getCscrCount() {
-		if (packet_len >= 12)
-			return (packet[0] & 0x0F);
-		else
-			return 0; // broken packet
-	}
+    /** Gets the CSCR count (CC) */
+    public int getCscrCount() {
+	if (packet_len >= 12)
+	    return (packet[0] & 0x0F);
+	else
+	    return 0; // broken packet
+    }
 
-	/** Whether has marker (M) */
-	public boolean hasMarker() {
-		if (packet_len >= 12)
-			return getBit(packet[1], 7);
-		else
-			return false; // broken packet
-	}
+    /** Whether has marker (M) */
+    public boolean hasMarker() {
+	if (packet_len >= 12)
+	    return getBit(packet[1], 7);
+	else
+	    return false; // broken packet
+    }
 
-	/** Set marker (M) */
-	public void setMarker(boolean m) {
-		if (packet_len >= 12)
-			packet[1] = setBit(m, packet[1], 7);
-	}
+    /** Set marker (M) */
+    public void setMarker(boolean m) {
+	if (packet_len >= 12)
+	    packet[1] = setBit(m, packet[1], 7);
+    }
 
-	/** Gets the payload type (PT) */
-	public int getPayloadType() {
-		if (packet_len >= 12)
-			return (packet[1] & 0x7F);
-		else
-			return -1; // broken packet
-	}
+    /** Gets the payload type (PT) */
+    public int getPayloadType() {
+	if (packet_len >= 12)
+	    return (packet[1] & 0x7F);
+	else
+	    return -1; // broken packet
+    }
 
-	/** Sets the payload type (PT) */
-	public void setPayloadType(int pt) {
-		if (packet_len >= 12)
-			packet[1] = (byte) ((packet[1] & 0x80) | (pt & 0x7F));
-	}
+    /** Sets the payload type (PT) */
+    public void setPayloadType(int pt) {
+	if (packet_len >= 12)
+	    packet[1] = (byte) ((packet[1] & 0x80) | (pt & 0x7F));
+    }
 
-	/** Gets the sequence number */
-	public int getSequenceNumber() {
-		if (packet_len >= 12)
-			return getInt(packet, 2, 4);
-		else
-			return 0; // broken packet
-	}
+    /** Gets the sequence number */
+    public int getSequenceNumber() {
+	if (packet_len >= 12)
+	    return getInt(packet, 2, 4);
+	else
+	    return 0; // broken packet
+    }
 
-	/** Sets the sequence number */
-	public void setSequenceNumber(int sn) {
-		if (packet_len >= 12)
-			setInt(sn, packet, 2, 4);
-	}
+    /** Sets the sequence number */
+    public void setSequenceNumber(int sn) {
+	if (packet_len >= 12)
+	    setInt(sn, packet, 2, 4);
+    }
 
-	/** Gets the timestamp */
-	public long getTimestamp() {
-		if (packet_len >= 12)
-			return getLong(packet, 4, 8);
-		else
-			return 0; // broken packet
-	}
+    /** Gets the timestamp */
+    public long getTimestamp() {
+	if (packet_len >= 12)
+	    return getLong(packet, 4, 8);
+	else
+	    return 0; // broken packet
+    }
 
-	/** Sets the timestamp */
-	public void setTimestamp(long timestamp) {
-		if (packet_len >= 12)
-			setLong(timestamp, packet, 4, 8);
-	}
+    /** Sets the timestamp */
+    public void setTimestamp(long timestamp) {
+	if (packet_len >= 12)
+	    setLong(timestamp, packet, 4, 8);
+    }
 
-	/** Gets the SSCR */
-	public long getSscr() {
-		if (packet_len >= 12)
-			return getLong(packet, 8, 12);
-		else
-			return 0; // broken packet
-	}
+    /** Gets the SSCR */
+    public long getSscr() {
+	if (packet_len >= 12)
+	    return getLong(packet, 8, 12);
+	else
+	    return 0; // broken packet
+    }
 
-	/** Sets the SSCR */
-	public void setSscr(long ssrc) {
-		if (packet_len >= 12)
-			setLong(ssrc, packet, 8, 12);
-	}
+    /** Sets the SSCR */
+    public void setSscr(long ssrc) {
+	if (packet_len >= 12)
+	    setLong(ssrc, packet, 8, 12);
+    }
 
-	/** Gets the CSCR list */
-	public long[] getCscrList() {
-		int cc = getCscrCount();
-		long[] cscr = new long[cc];
-		for (int i = 0; i < cc; i++)
-			cscr[i] = getLong(packet, 12 + 4 * i, 16 + 4 * i);
-		return cscr;
-	}
+    /** Gets the CSCR list */
+    public long[] getCscrList() {
+	int cc = getCscrCount();
+	long[] cscr = new long[cc];
+	for (int i = 0; i < cc; i++)
+	    cscr[i] = getLong(packet, 12 + 4 * i, 16 + 4 * i);
+	return cscr;
+    }
 
-	/** Sets the CSCR list */
-	public void setCscrList(long[] cscr) {
-		if (packet_len >= 12) {
-			int cc = cscr.length;
-			if (cc > 15)
-				cc = 15;
-			packet[0] = (byte) (((packet[0] >> 4) << 4) + cc);
-			cscr = new long[cc];
-			for (int i = 0; i < cc; i++)
-				setLong(cscr[i], packet, 12 + 4 * i, 16 + 4 * i);
-			// header_len=12+4*cc;
-		}
+    /** Sets the CSCR list */
+    public void setCscrList(long[] cscr) {
+	if (packet_len >= 12) {
+	    int cc = cscr.length;
+	    if (cc > 15)
+		cc = 15;
+	    packet[0] = (byte) (((packet[0] >> 4) << 4) + cc);
+	    cscr = new long[cc];
+	    for (int i = 0; i < cc; i++)
+		setLong(cscr[i], packet, 12 + 4 * i, 16 + 4 * i);
+	    // header_len=12+4*cc;
 	}
+    }
 
-	/** Sets the payload */
-	public void setPayload(byte[] payload, int len) {
-		if (packet_len >= 12) {
-			int header_len = getHeaderLength();
-			for (int i = 0; i < len; i++)
-				packet[header_len + i] = payload[i];
-			packet_len = header_len + len;
-		}
+    /** Sets the payload */
+    public void setPayload(byte[] payload, int len) {
+	if (packet_len >= 12) {
+	    int header_len = getHeaderLength();
+	    for (int i = 0; i < len; i++)
+		packet[header_len + i] = payload[i];
+	    packet_len = header_len + len;
 	}
+    }
 
-	/** Gets the payload */
-	public byte[] getPayload() {
-		int header_len = getHeaderLength();
-		int len = packet_len - header_len;
-		byte[] payload = new byte[len];
-		for (int i = 0; i < len; i++)
-			payload[i] = packet[header_len + i];
-		return payload;
-	}
+    /** Gets the payload */
+    public byte[] getPayload() {
+	int header_len = getHeaderLength();
+	int len = packet_len - header_len;
+	byte[] payload = new byte[len];
+	for (int i = 0; i < len; i++)
+	    payload[i] = packet[header_len + i];
+	return payload;
+    }
 
-	/** Creates a new RTP packet */
-	public RtpPacket(byte[] buffer, int packet_length) {
-		packet = buffer;
-		packet_len = packet_length;
-		if (packet_len < 12)
-			packet_len = 12;
-		init(0x0F);
-	}
+    /** Creates a new RTP packet */
+    public RtpPacket(byte[] buffer, int packet_length) {
+	packet = buffer;
+	packet_len = packet_length;
+	if (packet_len < 12)
+	    packet_len = 12;
+	init(0x0F);
+    }
 
-	/** init the RTP packet header (only PT) */
-	public void init(int ptype) {
-		init(ptype, Random.nextLong());
-	}
+    /** init the RTP packet header (only PT) */
+    public void init(int ptype) {
+	init(ptype, Random.nextLong());
+    }
 
-	/** init the RTP packet header (PT and SSCR) */
-	public void init(int ptype, long sscr) {
-		init(ptype, Random.nextInt(), Random.nextLong(), sscr);
-	}
+    /** init the RTP packet header (PT and SSCR) */
+    public void init(int ptype, long sscr) {
+	init(ptype, Random.nextInt(), Random.nextLong(), sscr);
+    }
 
-	/** init the RTP packet header (PT, SQN, TimeStamp, SSCR) */
-	public void init(int ptype, int seqn, long timestamp, long sscr) {
-		setVersion(2);
-		setPayloadType(ptype);
-		setSequenceNumber(seqn);
-		setTimestamp(timestamp);
-		setSscr(sscr);
-	}
+    /** init the RTP packet header (PT, SQN, TimeStamp, SSCR) */
+    public void init(int ptype, int seqn, long timestamp, long sscr) {
+	setVersion(2);
+	setPayloadType(ptype);
+	setSequenceNumber(seqn);
+	setTimestamp(timestamp);
+	setSscr(sscr);
+    }
 
-	// *********************** Private and Static ***********************
+    // *********************** Private and Static ***********************
 
-	/** Gets int value */
-	private static int getInt(byte b) {
-		return ((int) b + 256) % 256;
-	}
+    /** Gets int value */
+    private static int getInt(byte b) {
+	return ((int) b + 256) % 256;
+    }
 
-	/** Gets long value */
-	private static long getLong(byte[] data, int begin, int end) {
-		long n = 0;
-		for (; begin < end; begin++) {
-			n <<= 8;
-			n += data[begin];
-		}
-		return n;
+    /** Gets long value */
+    private static long getLong(byte[] data, int begin, int end) {
+	long n = 0;
+	for (; begin < end; begin++) {
+	    n <<= 8;
+	    n += data[begin];
 	}
+	return n;
+    }
 
-	/** Sets long value */
-	private static void setLong(long n, byte[] data, int begin, int end) {
-		for (end--; end >= begin; end--) {
-			data[end] = (byte) (n % 256);
-			n >>= 8;
-		}
+    /** Sets long value */
+    private static void setLong(long n, byte[] data, int begin, int end) {
+	for (end--; end >= begin; end--) {
+	    data[end] = (byte) (n % 256);
+	    n >>= 8;
 	}
+    }
 
-	/** Gets Int value */
-	private static int getInt(byte[] data, int begin, int end) {
-		return (int) getLong(data, begin, end);
-	}
+    /** Gets Int value */
+    private static int getInt(byte[] data, int begin, int end) {
+	return (int) getLong(data, begin, end);
+    }
 
-	/** Sets Int value */
-	private static void setInt(int n, byte[] data, int begin, int end) {
-		setLong(n, data, begin, end);
-	}
+    /** Sets Int value */
+    private static void setInt(int n, byte[] data, int begin, int end) {
+	setLong(n, data, begin, end);
+    }
 
-	/** Gets bit value */
-	private static boolean getBit(byte b, int bit) {
-		return (b >> bit) == 1;
-	}
+    /** Gets bit value */
+    private static boolean getBit(byte b, int bit) {
+	return (b >> bit) == 1;
+    }
 
-	/** Sets bit value */
-	private static byte setBit(boolean value, byte b, int bit) {
-		if (value)
-			return (byte) (b | (1 << bit));
-		else
-			return (byte) ((b | (1 << bit)) ^ (1 << bit));
-	}
+    /** Sets bit value */
+    private static byte setBit(boolean value, byte b, int bit) {
+	if (value)
+	    return (byte) (b | (1 << bit));
+	else
+	    return (byte) ((b | (1 << bit)) ^ (1 << bit));
+    }
 }
--- a/src/org/sipdroid/net/RtpSocket.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/org/sipdroid/net/RtpSocket.java	Sun Jan 24 00:42:29 2010 +0100
@@ -19,7 +19,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-package src.org.sipdroid.net;
+package org.sipdroid.net;
 
 import java.net.InetAddress;
 import java.net.DatagramPacket;
@@ -34,59 +34,59 @@
  * receive RtpPackets.
  */
 public class RtpSocket {
-	/** UDP socket */
-	SipdroidSocket socket;
-	DatagramPacket datagram;
-	
-	/** Remote address */
-	InetAddress r_addr;
+    /** UDP socket */
+    SipdroidSocket socket;
+    DatagramPacket datagram;
 
-	/** Remote port */
-	int r_port;
+    /** Remote address */
+    InetAddress r_addr;
+
+    /** Remote port */
+    int r_port;
 
-	/** Creates a new RTP socket (only receiver) */
-	public RtpSocket(SipdroidSocket datagram_socket) {
-		socket = datagram_socket;
-		r_addr = null;
-		r_port = 0;
-		datagram = new DatagramPacket(new byte[1],1);
-	}
+    /** Creates a new RTP socket (only receiver) */
+    public RtpSocket(SipdroidSocket datagram_socket) {
+	socket = datagram_socket;
+	r_addr = null;
+	r_port = 0;
+	datagram = new DatagramPacket(new byte[1],1);
+    }
 
-	/** Creates a new RTP socket (sender and receiver) */
-	public RtpSocket(SipdroidSocket datagram_socket,
-			InetAddress remote_address, int remote_port) {
-		socket = datagram_socket;
-		r_addr = remote_address;
-		r_port = remote_port;
-		datagram = new DatagramPacket(new byte[1],1);
-	}
+    /** Creates a new RTP socket (sender and receiver) */
+    public RtpSocket(SipdroidSocket datagram_socket,
+	InetAddress remote_address, int remote_port) {
+	socket = datagram_socket;
+	r_addr = remote_address;
+	r_port = remote_port;
+	datagram = new DatagramPacket(new byte[1],1);
+    }
 
-	/** Returns the RTP SipdroidSocket */
-	public SipdroidSocket getDatagramSocket() {
-		return socket;
-	}
+    /** Returns the RTP SipdroidSocket */
+    public SipdroidSocket getDatagramSocket() {
+	return socket;
+    }
 
-	/** Receives a RTP packet from this socket */
-	public void receive(RtpPacket rtpp) throws IOException {
-		datagram.setData(rtpp.packet);
-		datagram.setLength(rtpp.packet.length);
-		socket.receive(datagram);
-		if (!socket.isConnected())
-			socket.connect(datagram.getAddress(),datagram.getPort());
-		rtpp.packet_len = datagram.getLength();
-	}
+    /** Receives a RTP packet from this socket */
+    public void receive(RtpPacket rtpp) throws IOException {
+	datagram.setData(rtpp.packet);
+	datagram.setLength(rtpp.packet.length);
+	socket.receive(datagram);
+	if (!socket.isConnected())
+	    socket.connect(datagram.getAddress(),datagram.getPort());
+	rtpp.packet_len = datagram.getLength();
+    }
 
-	/** Sends a RTP packet from this socket */
-	public void send(RtpPacket rtpp) throws IOException {
-		datagram.setData(rtpp.packet);
-		datagram.setLength(rtpp.packet_len);
-		datagram.setAddress(r_addr);
-		datagram.setPort(r_port);
-		socket.send(datagram);
-	}
+    /** Sends a RTP packet from this socket */
+    public void send(RtpPacket rtpp) throws IOException {
+	datagram.setData(rtpp.packet);
+	datagram.setLength(rtpp.packet_len);
+	datagram.setAddress(r_addr);
+	datagram.setPort(r_port);
+	socket.send(datagram);
+    }
 
-	/** Closes this socket */
-	public void close() { // socket.close();
-	}
+    /** Closes this socket */
+    public void close() { // socket.close();
+    }
 
 }
--- a/src/org/sipdroid/net/SipdroidSocket.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/org/sipdroid/net/SipdroidSocket.java	Sun Jan 24 00:42:29 2010 +0100
@@ -18,7 +18,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-package src.org.sipdroid.net;
+package org.sipdroid.net;
 
 import java.io.IOException;
 import java.net.DatagramPacket;
@@ -33,57 +33,58 @@
 
 public class SipdroidSocket extends DatagramSocket {
 
-	PlainDatagramSocketImpl impl;
-	public static boolean loaded = false;
-	
-	public SipdroidSocket(int port) throws SocketException, UnknownHostException {
-		super(!loaded?port:0);
-		if (loaded) {
-			impl = new PlainDatagramSocketImpl();
-			impl.create();
-			impl.bind(port,InetAddress.getByName("0"));
-		}
-	}
-	
-	public void close() {
-		super.close();
-		if (loaded) impl.close();
-	}
-	
-	public void setSoTimeout(int val) throws SocketException {
-		if (loaded) impl.setOption(SocketOptions.SO_TIMEOUT, val);
-		else super.setSoTimeout(val);
-	}
-	
-	public void receive(DatagramPacket pack) throws IOException {
-		if (loaded) impl.receive(pack);
-		else super.receive(pack);
+    PlainDatagramSocketImpl impl;
+    public static boolean loaded = false;
+
+    public SipdroidSocket(int port) throws SocketException, UnknownHostException {
+	super(!loaded?port:0);
+	if (loaded) {
+	    impl = new PlainDatagramSocketImpl();
+	    impl.create();
+	    impl.bind(port,InetAddress.getByName("0"));
 	}
-	
-	public void send(DatagramPacket pack) throws IOException {
-		if (loaded) impl.send(pack);
-		else super.send(pack);
-	}
-	
-	public boolean isConnected() {
-		if (loaded) return true;
-		else return super.isConnected();
-	}
-	
-	public void disconnect() {
-		if (!loaded) super.disconnect();
+    }
+
+    public void close() {
+	super.close();
+	if (loaded) impl.close();
+    }
+
+    public void setSoTimeout(int val) throws SocketException {
+	if (loaded) impl.setOption(SocketOptions.SO_TIMEOUT, val);
+	else super.setSoTimeout(val);
+    }
+
+    public void receive(DatagramPacket pack) throws IOException {
+	if (loaded) impl.receive(pack);
+	else super.receive(pack);
+    }
+
+    public void send(DatagramPacket pack) throws IOException {
+	if (loaded) impl.send(pack);
+	else super.send(pack);
+    }
+
+    public boolean isConnected() {
+	if (loaded) return true;
+	else return super.isConnected();
+    }
+
+    public void disconnect() {
+	if (!loaded) super.disconnect();
+    }
+
+    public void connect(InetAddress addr,int port) {
+	if (!loaded) super.connect(addr,port);
+    }
+
+    static {
+	try {
+	    System.loadLibrary("OSNetworkSystem");
+	    OSNetworkSystem.getOSNetworkSystem().oneTimeInitialization(true);
+	    SipdroidSocket.loaded = true;
+	} catch (Throwable e) {
+	    e.printStackTrace();
 	}
-	
-	public void connect(InetAddress addr,int port) {
-		if (!loaded) super.connect(addr,port);
-	}
-
-	static {
-			try {
-		        System.loadLibrary("OSNetworkSystem");
-		        OSNetworkSystem.getOSNetworkSystem().oneTimeInitialization(true);
-		        SipdroidSocket.loaded = true;
-			} catch (Throwable e) {
-			}
-	}
+    }
 }
--- a/src/org/sipdroid/net/impl/OSNetworkSystem.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/org/sipdroid/net/impl/OSNetworkSystem.java	Sun Jan 24 00:42:29 2010 +0100
@@ -22,7 +22,7 @@
 // address length was changed from long to int for performance reasons.
 // END android-note
 
-package src.org.sipdroid.net.impl;
+package org.sipdroid.net.impl;
 
 import java.io.FileDescriptor;
 import java.io.IOException;
--- a/src/org/sipdroid/net/impl/PlainDatagramSocketImpl.java	Sat Jan 23 22:19:43 2010 +0100
+++ b/src/org/sipdroid/net/impl/PlainDatagramSocketImpl.java	Sun Jan 24 00:42:29 2010 +0100
@@ -18,7 +18,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-package src.org.sipdroid.net.impl;
+package org.sipdroid.net.impl;
 
 import java.io.FileDescriptor;
 import java.io.IOException;