# HG changeset patch # User nikita@nikita-laptop # Date 1264305139 -3600 # Node ID 2f2f5e24ac6adb9d2dccb6788c8b4572df5f7772 # Parent 4e40f3481f238e16e47c7f73990328c36935653f Voip MAJ diff -r 4e40f3481f23 -r 2f2f5e24ac6a AndroidManifest.xml --- a/AndroidManifest.xml Sun Jan 24 00:42:29 2010 +0100 +++ b/AndroidManifest.xml Sun Jan 24 04:52:19 2010 +0100 @@ -97,6 +97,8 @@ + + diff -r 4e40f3481f23 -r 2f2f5e24ac6a assets/alerting Binary file assets/alerting has changed diff -r 4e40f3481f23 -r 2f2f5e24ac6a res/menu/call.xml --- a/res/menu/call.xml Sun Jan 24 00:42:29 2010 +0100 +++ b/res/menu/call.xml Sun Jan 24 04:52:19 2010 +0100 @@ -5,6 +5,6 @@ android:title="~ speaker off ~" android:icon="@android:drawable/ic_lock_silent_mode" /> - + diff -r 4e40f3481f23 -r 2f2f5e24ac6a res/raw/ringback.ogg Binary file res/raw/ringback.ogg has changed diff -r 4e40f3481f23 -r 2f2f5e24ac6a src/com/beem/project/beem/jingle/JingleService.java --- a/src/com/beem/project/beem/jingle/JingleService.java Sun Jan 24 00:42:29 2010 +0100 +++ b/src/com/beem/project/beem/jingle/JingleService.java Sun Jan 24 04:52:19 2010 +0100 @@ -66,6 +66,7 @@ import android.content.Intent; import com.beem.project.beem.ui.Call; +import com.beem.project.beem.jingle.RTPAudioSession; import com.beem.project.beem.service.aidl.IBeemJingleListener; import com.beem.project.beem.service.aidl.IJingle; @@ -84,6 +85,7 @@ private JingleSessionRequest mRequest; private Context mContext; private boolean isCaller; + private RTPAudioSession mAudioSession; /** * JingleService constructor. @@ -150,12 +152,18 @@ } isCaller = false; } + + @Override + public void setSpeakerMode(int mode) throws RemoteException { + mAudioSession.setSpeakerMode(mode); + } /** * close a jingle call. */ @Override public void closeCall() throws RemoteException { + mAudioSession = null; if (isCaller) { try { mOut.terminate("Cancelled"); @@ -242,10 +250,8 @@ public void sessionEstablished(PayloadType pt, TransportCandidate remoteCandidate, TransportCandidate localCandidate, JingleSession jingleSession) { Log.d(TAG, "Session " + jingleSession.getResponder() + "established"); - - jingleSession.getSession().getMediaSession(pt.getName()); + mAudioSession = (RTPAudioSession) jingleSession.getSession().getMediaSession(MicrophoneRTPManager.MEDIA_NAME); final int n = mRemoteJingleListeners.beginBroadcast(); - for (int i = 0; i < n; i++) { IBeemJingleListener listener = mRemoteJingleListeners.getBroadcastItem(i); try { diff -r 4e40f3481f23 -r 2f2f5e24ac6a src/com/beem/project/beem/jingle/RTPAudioSession.java --- a/src/com/beem/project/beem/jingle/RTPAudioSession.java Sun Jan 24 00:42:29 2010 +0100 +++ b/src/com/beem/project/beem/jingle/RTPAudioSession.java Sun Jan 24 04:52:19 2010 +0100 @@ -32,19 +32,24 @@ 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); + SipdroidSocket rtpSocket = null; + try { + rtpSocket = new SipdroidSocket(local.getPort()); + } catch (Exception e) { + e.printStackTrace(); + } + mSender = new RtpStreamSender(true, 8, 8000, 160, rtpSocket, remote.getIp(), remote.getPort()); + mReceiver = new RtpStreamReceiver(rtpSocket, 8); } @Override public void initialize() { - // TODO Auto-generated method stub - + } + + public void setSpeakerMode(final int mode) { + mReceiver.speaker(mode); } @Override @@ -81,16 +86,4 @@ mSender = null; } } - - 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(); - } - } } diff -r 4e40f3481f23 -r 2f2f5e24ac6a src/com/beem/project/beem/service/aidl/IJingle.aidl --- a/src/com/beem/project/beem/service/aidl/IJingle.aidl Sun Jan 24 00:42:29 2010 +0100 +++ b/src/com/beem/project/beem/service/aidl/IJingle.aidl Sun Jan 24 04:52:19 2010 +0100 @@ -66,5 +66,10 @@ * close a jingle audio call */ void closeCall(); + + /** + * Set speaker mode + */ + void setSpeakerMode(in int mode); } diff -r 4e40f3481f23 -r 2f2f5e24ac6a src/com/beem/project/beem/ui/Call.java --- a/src/com/beem/project/beem/ui/Call.java Sun Jan 24 00:42:29 2010 +0100 +++ b/src/com/beem/project/beem/ui/Call.java Sun Jan 24 04:52:19 2010 +0100 @@ -48,6 +48,7 @@ import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.media.AudioManager; import android.media.Ringtone; import android.media.RingtoneManager; import android.net.Uri; @@ -57,6 +58,7 @@ import android.os.Vibrator; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; @@ -93,6 +95,8 @@ private Button mAcceptCall; private IJingle mJingle; + final static long[] vibratePattern = {0,1000,1000}; + 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; @@ -115,6 +119,8 @@ } public static void startRingtone() { + android.os.Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); + v.vibrate(vibratePattern,1); oRingtone = RingtoneManager.getRingtone(mContext, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)); oRingtone.play(); } @@ -139,9 +145,12 @@ if (callingIntent.getBooleanExtra("isCaller", false)) { mAcceptCall = (Button) findViewById(R.id.call_accept_button); mAcceptCall.setVisibility(View.GONE); + call_state = UA_STATE_OUTGOING_CALL; } else { mAcceptCall = (Button) findViewById(R.id.call_accept_button); mAcceptCall.setOnClickListener(new ClickListener()); + call_state = UA_STATE_INCOMING_CALL; + Call.startRingtone(); } mCallInfo = (TextView) findViewById(R.id.call_info); } @@ -182,6 +191,39 @@ } /** + * Callback for menu item selected. + * @param item the item selected + * @return true on success, false otherwise + */ + @Override + public final boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.call_speaker_on: + try { + mJingle.setSpeakerMode(AudioManager.MODE_NORMAL); + } catch (RemoteException e) { + e.printStackTrace(); + } + return true; + case R.id.call_speaker_off: + try { + mJingle.setSpeakerMode(AudioManager.MODE_IN_CALL); + } catch (RemoteException e) { + e.printStackTrace(); + } + return true; + case R.id.call_hold_on: + Call.call_state = UA_STATE_HOLD; + return true; + case R.id.call_hold_off: + Call.call_state = UA_STATE_INCALL; + return true; + default: + return false; + } + } + + /** * Click event listener on cancel button. */ private class ClickListener implements OnClickListener { @@ -195,10 +237,15 @@ @Override public void onClick(View v) { try { - if (v == mCloseCall) + if (v == mCloseCall) { mJingle.closeCall(); - else if (v == mAcceptCall) + stopRingtone(); + Call.call_state = UA_STATE_IDLE; + } else if (v == mAcceptCall) { mJingle.acceptCall(); + stopRingtone(); + Call.call_state = UA_STATE_INCALL; + } } catch (RemoteException e) { e.printStackTrace(); } @@ -227,7 +274,6 @@ @Override public void run() { mCallInfo.setText(mStr); - } } @@ -237,26 +283,33 @@ @Override public void sessionClosed(final String reason) { android.util.Log.d("TEST", "TEST " + reason); + Call.stopRingtone(); + call_state = UA_STATE_IDLE; mHandler.post(new RunnableChange(reason)); } @Override public void sessionDeclined(final String reason) { android.util.Log.d("TEST", "TEST4 " + reason); + Call.stopRingtone(); + call_state = UA_STATE_IDLE; mHandler.post(new RunnableChange(reason)); } @Override public void sessionClosedOnError(final String error) { android.util.Log.d("TEST", "TEST5 " + error); + Call.stopRingtone(); + call_state = UA_STATE_IDLE; mHandler.post(new RunnableChange(error)); } @Override public void sessionEstablished() { android.util.Log.d("TEST", "TEST2 "); - //mCallInfo.setText("established"); - mHandler.post(new RunnableChange("ok")); + call_state = UA_STATE_INCALL; + Call.stopRingtone(); + mHandler.post(new RunnableChange("established")); } @Override diff -r 4e40f3481f23 -r 2f2f5e24ac6a src/com/beem/project/beem/utils/Random.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/utils/Random.java Sun Jan 24 04:52:19 2010 +0100 @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2005 Luca Veltri - University of Parma - Italy + * + * This file is part of MjSip (http://www.mjsip.org) + * + * MjSip 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 2 of the License, or + * (at your option) any later version. + * + * MjSip 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 MjSip; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author(s): + * Luca Veltri (luca.veltri@unipr.it) + */ + +package com.beem.project.beem.utils; + +/** + * Class Random collects some static methods for generating random numbers and + * other stuff. + */ +public class Random { + /** The random seed */ + static final long seed = System.currentTimeMillis(); + // static final long seed=0; + + static java.util.Random rand = new java.util.Random(seed); + + // static java.util.Random rand=new java.util.Random(); + + /** Returns a random integer between 0 and n-1 */ + /* + * static public int nextInt(int n) { seed=(seed*37)%987654321; return + * (int)(seed%n); } + */ + + /** Returns true or false respectively with probability p/100 and (1-p/100) */ + /* + * static boolean percent(int p) { return integer(100)