├── ic_launcher-web.png
├── README.md
├── src
├── jay
│ ├── media
│ │ ├── LanVedioPlay.java
│ │ ├── LanVedioRecord.java
│ │ ├── LanAudioPlay.java
│ │ ├── MediaService.java
│ │ ├── LanAudioRecord.java
│ │ └── MediaManager.java
│ ├── dencode
│ │ ├── Decoder.java
│ │ └── Encoder.java
│ ├── codec
│ │ ├── alaw.java
│ │ ├── ulaw.java
│ │ ├── Speex.java
│ │ ├── G722.java
│ │ ├── Codec.java
│ │ ├── EchoCancellation.java
│ │ └── G711.java
│ └── func
│ │ └── func.java
├── org
│ └── sipdroid
│ │ └── net
│ │ ├── RtpPacket.java
│ │ ├── .svn
│ │ ├── all-wcprops
│ │ ├── entries
│ │ └── text-base
│ │ │ ├── SipdroidSocket.java.svn-base
│ │ │ ├── KeepAliveSip.java.svn-base
│ │ │ ├── RtpSocket.java.svn-base
│ │ │ ├── KeepAliveUdp.java.svn-base
│ │ │ └── RtpPacket.java.svn-base
│ │ ├── Random.java
│ │ └── RtpSocket.java
└── com
│ └── shawn
│ └── demo
│ └── voip
│ ├── MainActivity.java
│ └── .svn
│ ├── text-base
│ ├── Static.java.svn-base
│ ├── AudioReader.java.svn-base
│ ├── AudioWriter.java.svn-base
│ └── MainActivity.java.svn-base
│ └── entries
├── libs
├── android-support-v4.jar
├── armeabi
│ ├── libg722_jni.so
│ └── libspeex_jni.so
└── armeabi-v7a
│ ├── libg722_jni.so
│ └── libspeex_jni.so
├── bin
├── classes
│ ├── jay
│ │ ├── func
│ │ │ └── func.class
│ │ ├── codec
│ │ │ ├── Codec.class
│ │ │ ├── G711.class
│ │ │ ├── G722.class
│ │ │ ├── Speex.class
│ │ │ ├── alaw.class
│ │ │ ├── ulaw.class
│ │ │ └── EchoCancellation.class
│ │ ├── dencode
│ │ │ ├── Decoder.class
│ │ │ └── Encoder.class
│ │ └── media
│ │ │ ├── LanAudioPlay.class
│ │ │ ├── LanVedioPlay.class
│ │ │ ├── MediaManager.class
│ │ │ ├── MediaService.class
│ │ │ ├── LanAudioRecord.class
│ │ │ ├── LanVedioRecord.class
│ │ │ ├── MediaManager$1.class
│ │ │ └── MediaService$JayBinder.class
│ ├── com
│ │ └── shawn
│ │ │ └── demo
│ │ │ └── voip
│ │ │ ├── R.class
│ │ │ ├── rtp.class
│ │ │ ├── R$attr.class
│ │ │ ├── R$id.class
│ │ │ ├── R$menu.class
│ │ │ ├── R$dimen.class
│ │ │ ├── R$layout.class
│ │ │ ├── R$string.class
│ │ │ ├── R$style.class
│ │ │ ├── BuildConfig.class
│ │ │ ├── R$drawable.class
│ │ │ ├── MainActivity.class
│ │ │ ├── MainActivity$1.class
│ │ │ ├── MainActivity$2.class
│ │ │ ├── MainActivity$3.class
│ │ │ └── .svn
│ │ │ ├── text-base
│ │ │ ├── Static.java.svn-base
│ │ │ ├── AudioReader.java.svn-base
│ │ │ ├── AudioWriter.java.svn-base
│ │ │ └── MainActivity.java.svn-base
│ │ │ └── entries
│ └── org
│ │ └── sipdroid
│ │ └── net
│ │ ├── Random.class
│ │ ├── RtpPacket.class
│ │ ├── RtpSocket.class
│ │ └── .svn
│ │ ├── all-wcprops
│ │ ├── entries
│ │ └── text-base
│ │ ├── SipdroidSocket.java.svn-base
│ │ ├── KeepAliveSip.java.svn-base
│ │ ├── RtpSocket.java.svn-base
│ │ ├── KeepAliveUdp.java.svn-base
│ │ └── RtpPacket.java.svn-base
└── AndroidManifest.xml
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── values-sw600dp
│ └── dimens.xml
├── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── menu
│ └── main.xml
├── values-sw720dp-land
│ └── dimens.xml
└── layout
│ └── main.xml
├── gen
└── com
│ └── shawn
│ └── demo
│ └── voip
│ ├── BuildConfig.java
│ └── R.java
├── .settings
└── org.eclipse.jdt.core.prefs
├── .classpath
├── project.properties
├── proguard-project.txt
├── .project
└── AndroidManifest.xml
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/ic_launcher-web.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | lan-voice-chat
2 | ==============
3 |
4 | an android lan voice chat,refer to sipdroid.
5 |
--------------------------------------------------------------------------------
/src/jay/media/LanVedioPlay.java:
--------------------------------------------------------------------------------
1 | package jay.media;
2 |
3 | public class LanVedioPlay
4 | {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/src/jay/media/LanVedioRecord.java:
--------------------------------------------------------------------------------
1 | package jay.media;
2 |
3 | public class LanVedioRecord
4 | {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/libs/armeabi/libg722_jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/libs/armeabi/libg722_jni.so
--------------------------------------------------------------------------------
/libs/armeabi/libspeex_jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/libs/armeabi/libspeex_jni.so
--------------------------------------------------------------------------------
/src/jay/dencode/Decoder.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/src/jay/dencode/Decoder.java
--------------------------------------------------------------------------------
/bin/classes/jay/func/func.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/func/func.class
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libg722_jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/libs/armeabi-v7a/libg722_jni.so
--------------------------------------------------------------------------------
/src/jay/media/LanAudioPlay.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/src/jay/media/LanAudioPlay.java
--------------------------------------------------------------------------------
/src/jay/media/MediaService.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/src/jay/media/MediaService.java
--------------------------------------------------------------------------------
/bin/classes/jay/codec/Codec.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/codec/Codec.class
--------------------------------------------------------------------------------
/bin/classes/jay/codec/G711.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/codec/G711.class
--------------------------------------------------------------------------------
/bin/classes/jay/codec/G722.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/codec/G722.class
--------------------------------------------------------------------------------
/bin/classes/jay/codec/Speex.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/codec/Speex.class
--------------------------------------------------------------------------------
/bin/classes/jay/codec/alaw.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/codec/alaw.class
--------------------------------------------------------------------------------
/bin/classes/jay/codec/ulaw.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/codec/ulaw.class
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libspeex_jni.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/libs/armeabi-v7a/libspeex_jni.so
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/jay/media/LanAudioRecord.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/src/jay/media/LanAudioRecord.java
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/org/sipdroid/net/RtpPacket.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/src/org/sipdroid/net/RtpPacket.java
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/R.class
--------------------------------------------------------------------------------
/bin/classes/jay/dencode/Decoder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/dencode/Decoder.class
--------------------------------------------------------------------------------
/bin/classes/jay/dencode/Encoder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/dencode/Encoder.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/rtp.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/rtp.class
--------------------------------------------------------------------------------
/bin/classes/jay/media/LanAudioPlay.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/media/LanAudioPlay.class
--------------------------------------------------------------------------------
/bin/classes/jay/media/LanVedioPlay.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/media/LanVedioPlay.class
--------------------------------------------------------------------------------
/bin/classes/jay/media/MediaManager.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/media/MediaManager.class
--------------------------------------------------------------------------------
/bin/classes/jay/media/MediaService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/media/MediaService.class
--------------------------------------------------------------------------------
/bin/classes/org/sipdroid/net/Random.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/org/sipdroid/net/Random.class
--------------------------------------------------------------------------------
/src/com/shawn/demo/voip/MainActivity.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/src/com/shawn/demo/voip/MainActivity.java
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/R$attr.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/R$id.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/R$menu.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/R$menu.class
--------------------------------------------------------------------------------
/bin/classes/jay/codec/EchoCancellation.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/codec/EchoCancellation.class
--------------------------------------------------------------------------------
/bin/classes/jay/media/LanAudioRecord.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/media/LanAudioRecord.class
--------------------------------------------------------------------------------
/bin/classes/jay/media/LanVedioRecord.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/media/LanVedioRecord.class
--------------------------------------------------------------------------------
/bin/classes/jay/media/MediaManager$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/media/MediaManager$1.class
--------------------------------------------------------------------------------
/bin/classes/org/sipdroid/net/RtpPacket.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/org/sipdroid/net/RtpPacket.class
--------------------------------------------------------------------------------
/bin/classes/org/sipdroid/net/RtpSocket.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/org/sipdroid/net/RtpSocket.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/R$dimen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/R$dimen.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/R$layout.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/R$string.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/R$style.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/R$style.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/BuildConfig.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/R$drawable.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/MainActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/MainActivity.class
--------------------------------------------------------------------------------
/bin/classes/jay/media/MediaService$JayBinder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/jay/media/MediaService$JayBinder.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/MainActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/MainActivity$1.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/MainActivity$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/MainActivity$2.class
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/MainActivity$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shawn7com/lan-voice-chat/HEAD/bin/classes/com/shawn/demo/voip/MainActivity$3.class
--------------------------------------------------------------------------------
/src/com/shawn/demo/voip/.svn/text-base/Static.java.svn-base:
--------------------------------------------------------------------------------
1 | package com.sea.chapter6_5;
2 |
3 | public class Static {
4 | public final static int SAMPLERATEINHZ = 8000;
5 | }
6 |
--------------------------------------------------------------------------------
/bin/classes/com/shawn/demo/voip/.svn/text-base/Static.java.svn-base:
--------------------------------------------------------------------------------
1 | package com.sea.chapter6_5;
2 |
3 | public class Static {
4 | public final static int SAMPLERATEINHZ = 8000;
5 | }
6 |
--------------------------------------------------------------------------------
/gen/com/shawn/demo/voip/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.shawn.demo.voip;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
33 | * RtpSocket is associated to a DatagramSocket that is used to send and/or 34 | * receive RtpPackets. 35 | */ 36 | public class RtpSocket { 37 | /** UDP socket */ 38 | SipdroidSocket socket; 39 | DatagramPacket datagram; 40 | 41 | /** Remote address */ 42 | InetAddress r_addr; 43 | 44 | /** Remote port */ 45 | int r_port; 46 | 47 | /** Creates a new RTP socket (only receiver) */ 48 | public RtpSocket(SipdroidSocket datagram_socket) { 49 | socket = datagram_socket; 50 | r_addr = null; 51 | r_port = 0; 52 | datagram = new DatagramPacket(new byte[1],1); 53 | } 54 | 55 | /** Creates a new RTP socket (sender and receiver) */ 56 | public RtpSocket(SipdroidSocket datagram_socket, 57 | InetAddress remote_address, int remote_port) { 58 | socket = datagram_socket; 59 | r_addr = remote_address; 60 | r_port = remote_port; 61 | datagram = new DatagramPacket(new byte[1],1); 62 | } 63 | 64 | /** Returns the RTP SipdroidSocket */ 65 | public SipdroidSocket getDatagramSocket() { 66 | return socket; 67 | } 68 | 69 | /** Receives a RTP packet from this socket */ 70 | public void receive(RtpPacket rtpp) throws IOException { 71 | datagram.setData(rtpp.packet); 72 | datagram.setLength(rtpp.packet.length); 73 | socket.receive(datagram); 74 | if (!socket.isConnected()) 75 | socket.connect(datagram.getAddress(),datagram.getPort()); 76 | rtpp.packet_len = datagram.getLength(); 77 | } 78 | 79 | /** Sends a RTP packet from this socket */ 80 | public void send(RtpPacket rtpp) throws IOException { 81 | datagram.setData(rtpp.packet); 82 | datagram.setLength(rtpp.packet_len); 83 | datagram.setAddress(r_addr); 84 | datagram.setPort(r_port); 85 | socket.send(datagram); 86 | } 87 | 88 | /** Closes this socket */ 89 | public void close() { // socket.close(); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /bin/classes/org/sipdroid/net/.svn/text-base/RtpSocket.java.svn-base: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Sipdroid Open Source Project 3 | * Copyright (C) 2005 Luca Veltri - University of Parma - Italy 4 | * 5 | * This file is part of Sipdroid (http://www.sipdroid.org) 6 | * 7 | * Sipdroid is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This source code is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this source code; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | package org.sipdroid.net; 23 | 24 | import java.net.InetAddress; 25 | import java.net.DatagramPacket; 26 | import java.io.IOException; 27 | 28 | 29 | 30 | /** 31 | * RtpSocket implements a RTP socket for receiving and sending RTP packets. 32 | *
33 | * RtpSocket is associated to a DatagramSocket that is used to send and/or 34 | * receive RtpPackets. 35 | */ 36 | public class RtpSocket { 37 | /** UDP socket */ 38 | SipdroidSocket socket; 39 | DatagramPacket datagram; 40 | 41 | /** Remote address */ 42 | InetAddress r_addr; 43 | 44 | /** Remote port */ 45 | int r_port; 46 | 47 | /** Creates a new RTP socket (only receiver) */ 48 | public RtpSocket(SipdroidSocket datagram_socket) { 49 | socket = datagram_socket; 50 | r_addr = null; 51 | r_port = 0; 52 | datagram = new DatagramPacket(new byte[1],1); 53 | } 54 | 55 | /** Creates a new RTP socket (sender and receiver) */ 56 | public RtpSocket(SipdroidSocket datagram_socket, 57 | InetAddress remote_address, int remote_port) { 58 | socket = datagram_socket; 59 | r_addr = remote_address; 60 | r_port = remote_port; 61 | datagram = new DatagramPacket(new byte[1],1); 62 | } 63 | 64 | /** Returns the RTP SipdroidSocket */ 65 | public SipdroidSocket getDatagramSocket() { 66 | return socket; 67 | } 68 | 69 | /** Receives a RTP packet from this socket */ 70 | public void receive(RtpPacket rtpp) throws IOException { 71 | datagram.setData(rtpp.packet); 72 | datagram.setLength(rtpp.packet.length); 73 | socket.receive(datagram); 74 | if (!socket.isConnected()) 75 | socket.connect(datagram.getAddress(),datagram.getPort()); 76 | rtpp.packet_len = datagram.getLength(); 77 | } 78 | 79 | /** Sends a RTP packet from this socket */ 80 | public void send(RtpPacket rtpp) throws IOException { 81 | datagram.setData(rtpp.packet); 82 | datagram.setLength(rtpp.packet_len); 83 | datagram.setAddress(r_addr); 84 | datagram.setPort(r_port); 85 | socket.send(datagram); 86 | } 87 | 88 | /** Closes this socket */ 89 | public void close() { // socket.close(); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/org/sipdroid/net/Random.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 Luca Veltri - University of Parma - Italy 3 | * 4 | * This file is part of MjSip (http://www.mjsip.org) 5 | * 6 | * MjSip is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MjSip is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with MjSip; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | * 20 | * Author(s): 21 | * Luca Veltri (luca.veltri@unipr.it) 22 | */ 23 | 24 | package org.sipdroid.net; 25 | 26 | /** 27 | * Class Random collects some static methods for generating random numbers and 28 | * other stuff. 29 | */ 30 | public class Random { 31 | /** The random seed */ 32 | static final long seed = System.currentTimeMillis(); 33 | // static final long seed=0; 34 | 35 | static java.util.Random rand = new java.util.Random(seed); 36 | 37 | // static java.util.Random rand=new java.util.Random(); 38 | 39 | /** Returns a random integer between 0 and n-1 */ 40 | /* 41 | * static public int nextInt(int n) { seed=(seed*37)%987654321; return 42 | * (int)(seed%n); } 43 | */ 44 | 45 | /** Returns true or false respectively with probability p/100 and (1-p/100) */ 46 | /* 47 | * static boolean percent(int p) { return integer(100)
35 | * RtpSocket is associated to a DatagramSocket that is used to send and/or
36 | * receive RtpPackets.
37 | */
38 | public class RtpSocket {
39 | // private final static String TAG = "RtpSocket";
40 |
41 | /** UDP socket */
42 | DatagramSocket socket;
43 | DatagramPacket datagram;
44 |
45 | /** Remote address */
46 | InetAddress r_addr;
47 |
48 | /** Remote port */
49 | int r_port;
50 |
51 | long ms=0;
52 |
53 | /** Creates a new RTP socket (only receiver) */
54 | public RtpSocket(DatagramSocket datagram_socket) {
55 | socket = datagram_socket;
56 | r_addr = null;
57 | r_port = 0;
58 | datagram = new DatagramPacket(new byte[1],1);
59 | }
60 |
61 | /** Creates a new RTP socket (sender and receiver) */
62 | public RtpSocket(DatagramSocket datagram_socket,
63 | InetAddress remote_address, int remote_port) {
64 | socket = datagram_socket;
65 | r_addr = remote_address;
66 | r_port = remote_port;
67 | datagram = new DatagramPacket(new byte[1],1);
68 | }
69 |
70 | /** Returns the RTP SipdroidSocket */
71 | public DatagramSocket getDatagramSocket() {
72 | return socket;
73 | }
74 |
75 | /** Receives a RTP packet from this socket */
76 | public void receive(RtpPacket rtpp) throws IOException {
77 |
78 | datagram.setData(rtpp.packet);
79 | datagram.setLength(rtpp.packet.length);
80 | socket.receive(datagram);
81 | if (!socket.isConnected())
82 | socket.connect(datagram.getAddress(),datagram.getPort());
83 | rtpp.packet_len = datagram.getLength();
84 |
85 | Log.d("RtpSocket", "Receive Perodic: "+(System.currentTimeMillis()-ms)+" ms");
86 | ms=System.currentTimeMillis();
87 |
88 | // Log.i(TAG,"RtpSocket receive : "+datagram.getLength());
89 | }
90 |
91 | /** Sends a RTP packet from this socket */
92 | public void send(RtpPacket rtpp) throws IOException {
93 | datagram.setData(rtpp.packet);
94 | datagram.setLength(rtpp.packet_len);
95 | datagram.setAddress(r_addr);
96 | datagram.setPort(r_port);
97 | socket.send(datagram);
98 | Log.d("RtpSocket", "Send Perodic: "+(System.currentTimeMillis()-ms)+" ms");
99 | ms=System.currentTimeMillis();
100 | // Log.i(TAG,"RtpSocket send : "+rtpp.packet_len);
101 | }
102 |
103 | /** Closes this socket */
104 | public void close() { // socket.close();
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/jay/codec/EchoCancellation.java:
--------------------------------------------------------------------------------
1 | package jay.codec;
2 |
3 | import java.util.LinkedList;
4 |
5 | import android.util.Log;
6 | import jay.func.func;
7 |
8 | public class EchoCancellation implements Runnable{
9 |
10 | private Speex speex_echo = new Speex();
11 | private volatile Thread runner;
12 | private final Object mutex = new Object();
13 | final static int framesize = 160;
14 | final static int filterlength = 1024;
15 | private volatile int CaptureSize = 0;
16 | private volatile int PlaySize = 0;
17 | private volatile boolean isCancelling;
18 | protected LinkedList
31 | * It can be used for both signaling (SIP) or data plane (RTP/UDP).
32 | */
33 | public class KeepAliveUdp extends Thread {
34 | /** Destination socket address (e.g. the registrar server) */
35 | protected SocketAddress target;
36 |
37 | /** Time between two keep-alive tokens [millisecs] */
38 | protected long delta_time;
39 |
40 | /** UdpSocket */
41 | UdpSocket udp_socket;
42 |
43 | /** Udp packet */
44 | UdpPacket udp_packet = null;
45 |
46 | /** Expiration date [millisecs] */
47 | long expire = 0;
48 |
49 | /** Whether it is running */
50 | boolean stop = false;
51 |
52 | /** Creates a new KeepAliveUdp daemon */
53 | protected KeepAliveUdp(SocketAddress target, long delta_time) {
54 | this.target = target;
55 | this.delta_time = delta_time;
56 | }
57 |
58 | /** Creates a new KeepAliveUdp daemon */
59 | public KeepAliveUdp(UdpSocket udp_socket, SocketAddress target,
60 | long delta_time) {
61 | this.target = target;
62 | this.delta_time = delta_time;
63 | init(udp_socket, null);
64 | start();
65 | }
66 |
67 | /** Creates a new KeepAliveUdp daemon */
68 | public KeepAliveUdp(UdpSocket udp_socket, SocketAddress target,
69 | UdpPacket udp_packet, long delta_time) {
70 | this.target = target;
71 | this.delta_time = delta_time;
72 | init(udp_socket, udp_packet);
73 | start();
74 | }
75 |
76 | /** Inits the KeepAliveUdp */
77 | private void init(UdpSocket udp_socket, UdpPacket udp_packet) {
78 | this.udp_socket = udp_socket;
79 | if (udp_packet == null) {
80 | byte[] buff = { (byte) '\r', (byte) '\n' };
81 | udp_packet = new UdpPacket(buff, 0, buff.length);
82 | }
83 | if (target != null) {
84 | udp_packet.setIpAddress(target.getAddress());
85 | udp_packet.setPort(target.getPort());
86 | }
87 | this.udp_packet = udp_packet;
88 | }
89 |
90 | /** Whether the UDP relay is running */
91 | public boolean isRunning() {
92 | return !stop;
93 | }
94 |
95 | /** Sets the time (in milliseconds) between two keep-alive tokens */
96 | public void setDeltaTime(long delta_time) {
97 | this.delta_time = delta_time;
98 | }
99 |
100 | /** Gets the time (in milliseconds) between two keep-alive tokens */
101 | public long getDeltaTime() {
102 | return delta_time;
103 | }
104 |
105 | /** Sets the destination SocketAddress */
106 | public void setDestSoAddress(SocketAddress soaddr) {
107 | target = soaddr;
108 | if (udp_packet != null && target != null) {
109 | udp_packet.setIpAddress(target.getAddress());
110 | udp_packet.setPort(target.getPort());
111 | }
112 |
113 | }
114 |
115 | /** Gets the destination SocketAddress */
116 | public SocketAddress getDestSoAddress() {
117 | return target;
118 | }
119 |
120 | /** Sets the expiration time (in milliseconds) */
121 | public void setExpirationTime(long time) {
122 | if (time == 0)
123 | expire = 0;
124 | else
125 | expire = System.currentTimeMillis() + time;
126 | }
127 |
128 | /** Stops sending keep-alive tokens */
129 | public void halt() {
130 | stop = true;
131 | }
132 |
133 | /** Sends the kepp-alive packet now. */
134 | public void sendToken() throws java.io.IOException { // do send?
135 | if (!stop && target != null && udp_socket != null) {
136 | udp_socket.send(udp_packet);
137 | }
138 | }
139 |
140 | /** Main thread. */
141 | public void run() {
142 | try {
143 | while (!stop) {
144 | // sendToken();
145 | // System.out.print(".");
146 | sleep(delta_time);
147 | if (expire > 0 && System.currentTimeMillis() > expire)
148 | halt();
149 | }
150 | } catch (Exception e) {
151 | e.printStackTrace();
152 | }
153 | // System.out.println("o");
154 | udp_socket = null;
155 | }
156 |
157 | /** Gets a String representation of the Object */
158 | public String toString() {
159 | String str = null;
160 | if (udp_socket != null) {
161 | str = "udp:" + udp_socket.getLocalAddress() + ":"
162 | + udp_socket.getLocalPort() + "-->" + target.toString();
163 | }
164 | return str + " (" + delta_time + "ms)";
165 | }
166 |
167 | }
--------------------------------------------------------------------------------
/bin/classes/org/sipdroid/net/.svn/text-base/KeepAliveUdp.java.svn-base:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Sipdroid Open Source Project
3 | * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
4 | *
5 | * This file is part of Sipdroid (http://www.sipdroid.org)
6 | *
7 | * Sipdroid is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This source code is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this source code; if not, write to the Free Software
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 | */
21 |
22 | package org.sipdroid.net;
23 |
24 | import org.zoolu.net.*;
25 |
26 | /**
27 | * KeepAliveUdp thread, for keeping the connection up toward a target node (e.g.
28 | * toward the serving proxy/gw or a remote UA). It periodically sends
29 | * keep-alive tokens in order to refresh NAT UDP session timeouts.
30 | *
31 | * It can be used for both signaling (SIP) or data plane (RTP/UDP).
32 | */
33 | public class KeepAliveUdp extends Thread {
34 | /** Destination socket address (e.g. the registrar server) */
35 | protected SocketAddress target;
36 |
37 | /** Time between two keep-alive tokens [millisecs] */
38 | protected long delta_time;
39 |
40 | /** UdpSocket */
41 | UdpSocket udp_socket;
42 |
43 | /** Udp packet */
44 | UdpPacket udp_packet = null;
45 |
46 | /** Expiration date [millisecs] */
47 | long expire = 0;
48 |
49 | /** Whether it is running */
50 | boolean stop = false;
51 |
52 | /** Creates a new KeepAliveUdp daemon */
53 | protected KeepAliveUdp(SocketAddress target, long delta_time) {
54 | this.target = target;
55 | this.delta_time = delta_time;
56 | }
57 |
58 | /** Creates a new KeepAliveUdp daemon */
59 | public KeepAliveUdp(UdpSocket udp_socket, SocketAddress target,
60 | long delta_time) {
61 | this.target = target;
62 | this.delta_time = delta_time;
63 | init(udp_socket, null);
64 | start();
65 | }
66 |
67 | /** Creates a new KeepAliveUdp daemon */
68 | public KeepAliveUdp(UdpSocket udp_socket, SocketAddress target,
69 | UdpPacket udp_packet, long delta_time) {
70 | this.target = target;
71 | this.delta_time = delta_time;
72 | init(udp_socket, udp_packet);
73 | start();
74 | }
75 |
76 | /** Inits the KeepAliveUdp */
77 | private void init(UdpSocket udp_socket, UdpPacket udp_packet) {
78 | this.udp_socket = udp_socket;
79 | if (udp_packet == null) {
80 | byte[] buff = { (byte) '\r', (byte) '\n' };
81 | udp_packet = new UdpPacket(buff, 0, buff.length);
82 | }
83 | if (target != null) {
84 | udp_packet.setIpAddress(target.getAddress());
85 | udp_packet.setPort(target.getPort());
86 | }
87 | this.udp_packet = udp_packet;
88 | }
89 |
90 | /** Whether the UDP relay is running */
91 | public boolean isRunning() {
92 | return !stop;
93 | }
94 |
95 | /** Sets the time (in milliseconds) between two keep-alive tokens */
96 | public void setDeltaTime(long delta_time) {
97 | this.delta_time = delta_time;
98 | }
99 |
100 | /** Gets the time (in milliseconds) between two keep-alive tokens */
101 | public long getDeltaTime() {
102 | return delta_time;
103 | }
104 |
105 | /** Sets the destination SocketAddress */
106 | public void setDestSoAddress(SocketAddress soaddr) {
107 | target = soaddr;
108 | if (udp_packet != null && target != null) {
109 | udp_packet.setIpAddress(target.getAddress());
110 | udp_packet.setPort(target.getPort());
111 | }
112 |
113 | }
114 |
115 | /** Gets the destination SocketAddress */
116 | public SocketAddress getDestSoAddress() {
117 | return target;
118 | }
119 |
120 | /** Sets the expiration time (in milliseconds) */
121 | public void setExpirationTime(long time) {
122 | if (time == 0)
123 | expire = 0;
124 | else
125 | expire = System.currentTimeMillis() + time;
126 | }
127 |
128 | /** Stops sending keep-alive tokens */
129 | public void halt() {
130 | stop = true;
131 | }
132 |
133 | /** Sends the kepp-alive packet now. */
134 | public void sendToken() throws java.io.IOException { // do send?
135 | if (!stop && target != null && udp_socket != null) {
136 | udp_socket.send(udp_packet);
137 | }
138 | }
139 |
140 | /** Main thread. */
141 | public void run() {
142 | try {
143 | while (!stop) {
144 | // sendToken();
145 | // System.out.print(".");
146 | sleep(delta_time);
147 | if (expire > 0 && System.currentTimeMillis() > expire)
148 | halt();
149 | }
150 | } catch (Exception e) {
151 | e.printStackTrace();
152 | }
153 | // System.out.println("o");
154 | udp_socket = null;
155 | }
156 |
157 | /** Gets a String representation of the Object */
158 | public String toString() {
159 | String str = null;
160 | if (udp_socket != null) {
161 | str = "udp:" + udp_socket.getLocalAddress() + ":"
162 | + udp_socket.getLocalPort() + "-->" + target.toString();
163 | }
164 | return str + " (" + delta_time + "ms)";
165 | }
166 |
167 | }
--------------------------------------------------------------------------------
/src/org/sipdroid/net/.svn/text-base/RtpPacket.java.svn-base:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Sipdroid Open Source Project
3 | * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
4 | *
5 | * This file is part of Sipdroid (http://www.sipdroid.org)
6 | *
7 | * Sipdroid is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This source code is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this source code; if not, write to the Free Software
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 | */
21 |
22 | package org.sipdroid.net;
23 |
24 | import org.zoolu.tools.Random;
25 |
26 | /**
27 | * RtpPacket implements a RTP packet.
28 | */
29 | public class RtpPacket {
30 | /* RTP packet buffer containing both the RTP header and payload */
31 | byte[] packet;
32 |
33 | /* RTP packet length */
34 | int packet_len;
35 |
36 | /* RTP header length */
37 | // int header_len;
38 | /** Gets the RTP packet */
39 | public byte[] getPacket() {
40 | return packet;
41 | }
42 |
43 | /** Gets the RTP packet length */
44 | public int getLength() {
45 | return packet_len;
46 | }
47 |
48 | /** Gets the RTP header length */
49 | public int getHeaderLength() {
50 | if (packet_len >= 12)
51 | return 12 + 4 * getCscrCount();
52 | else
53 | return packet_len; // broken packet
54 | }
55 |
56 | /** Gets the RTP header length */
57 | public int getPayloadLength() {
58 | if (packet_len >= 12)
59 | return packet_len - getHeaderLength();
60 | else
61 | return 0; // broken packet
62 | }
63 |
64 | /** Sets the RTP payload length */
65 | public void setPayloadLength(int len) {
66 | packet_len = getHeaderLength() + len;
67 | }
68 |
69 | // version (V): 2 bits
70 | // padding (P): 1 bit
71 | // extension (X): 1 bit
72 | // CSRC count (CC): 4 bits
73 | // marker (M): 1 bit
74 | // payload type (PT): 7 bits
75 | // sequence number: 16 bits
76 | // timestamp: 32 bits
77 | // SSRC: 32 bits
78 | // CSRC list: 0 to 15 items, 32 bits each
79 |
80 | /** Gets the version (V) */
81 | public int getVersion() {
82 | if (packet_len >= 12)
83 | return (packet[0] >> 6 & 0x03);
84 | else
85 | return 0; // broken packet
86 | }
87 |
88 | /** Sets the version (V) */
89 | public void setVersion(int v) {
90 | if (packet_len >= 12)
91 | packet[0] = (byte) ((packet[0] & 0x3F) | ((v & 0x03) << 6));
92 | }
93 |
94 | /** Whether has padding (P) */
95 | public boolean hasPadding() {
96 | if (packet_len >= 12)
97 | return getBit(packet[0], 5);
98 | else
99 | return false; // broken packet
100 | }
101 |
102 | /** Set padding (P) */
103 | public void setPadding(boolean p) {
104 | if (packet_len >= 12)
105 | packet[0] = setBit(p, packet[0], 5);
106 | }
107 |
108 | /** Whether has extension (X) */
109 | public boolean hasExtension() {
110 | if (packet_len >= 12)
111 | return getBit(packet[0], 4);
112 | else
113 | return false; // broken packet
114 | }
115 |
116 | /** Set extension (X) */
117 | public void setExtension(boolean x) {
118 | if (packet_len >= 12)
119 | packet[0] = setBit(x, packet[0], 4);
120 | }
121 |
122 | /** Gets the CSCR count (CC) */
123 | public int getCscrCount() {
124 | if (packet_len >= 12)
125 | return (packet[0] & 0x0F);
126 | else
127 | return 0; // broken packet
128 | }
129 |
130 | /** Whether has marker (M) */
131 | public boolean hasMarker() {
132 | if (packet_len >= 12)
133 | return getBit(packet[1], 7);
134 | else
135 | return false; // broken packet
136 | }
137 |
138 | /** Set marker (M) */
139 | public void setMarker(boolean m) {
140 | if (packet_len >= 12)
141 | packet[1] = setBit(m, packet[1], 7);
142 | }
143 |
144 | /** Gets the payload type (PT) */
145 | public int getPayloadType() {
146 | if (packet_len >= 12)
147 | return (packet[1] & 0x7F);
148 | else
149 | return -1; // broken packet
150 | }
151 |
152 | /** Sets the payload type (PT) */
153 | public void setPayloadType(int pt) {
154 | if (packet_len >= 12)
155 | packet[1] = (byte) ((packet[1] & 0x80) | (pt & 0x7F));
156 | }
157 |
158 | /** Gets the sequence number */
159 | public int getSequenceNumber() {
160 | if (packet_len >= 12)
161 | return getInt(packet, 2, 4);
162 | else
163 | return 0; // broken packet
164 | }
165 |
166 | /** Sets the sequence number */
167 | public void setSequenceNumber(int sn) {
168 | if (packet_len >= 12)
169 | setInt(sn, packet, 2, 4);
170 | }
171 |
172 | /** Gets the timestamp */
173 | public long getTimestamp() {
174 | if (packet_len >= 12)
175 | return getLong(packet, 4, 8);
176 | else
177 | return 0; // broken packet
178 | }
179 |
180 | /** Sets the timestamp */
181 | public void setTimestamp(long timestamp) {
182 | if (packet_len >= 12)
183 | setLong(timestamp, packet, 4, 8);
184 | }
185 |
186 | /** Gets the SSCR */
187 | public long getSscr() {
188 | if (packet_len >= 12)
189 | return getLong(packet, 8, 12);
190 | else
191 | return 0; // broken packet
192 | }
193 |
194 | /** Sets the SSCR */
195 | public void setSscr(long ssrc) {
196 | if (packet_len >= 12)
197 | setLong(ssrc, packet, 8, 12);
198 | }
199 |
200 | /** Gets the CSCR list */
201 | public long[] getCscrList() {
202 | int cc = getCscrCount();
203 | long[] cscr = new long[cc];
204 | for (int i = 0; i < cc; i++)
205 | cscr[i] = getLong(packet, 12 + 4 * i, 16 + 4 * i);
206 | return cscr;
207 | }
208 |
209 | /** Sets the CSCR list */
210 | public void setCscrList(long[] cscr) {
211 | if (packet_len >= 12) {
212 | int cc = cscr.length;
213 | if (cc > 15)
214 | cc = 15;
215 | packet[0] = (byte) (((packet[0] >> 4) << 4) + cc);
216 | cscr = new long[cc];
217 | for (int i = 0; i < cc; i++)
218 | setLong(cscr[i], packet, 12 + 4 * i, 16 + 4 * i);
219 | // header_len=12+4*cc;
220 | }
221 | }
222 |
223 | /** Sets the payload */
224 | public void setPayload(byte[] payload, int len) {
225 | if (packet_len >= 12) {
226 | int header_len = getHeaderLength();
227 | for (int i = 0; i < len; i++)
228 | packet[header_len + i] = payload[i];
229 | packet_len = header_len + len;
230 | }
231 | }
232 |
233 | /** Gets the payload */
234 | public byte[] getPayload() {
235 | int header_len = getHeaderLength();
236 | int len = packet_len - header_len;
237 | byte[] payload = new byte[len];
238 | for (int i = 0; i < len; i++)
239 | payload[i] = packet[header_len + i];
240 | return payload;
241 | }
242 |
243 | /** Creates a new RTP packet */
244 | public RtpPacket(byte[] buffer, int packet_length) {
245 | packet = buffer;
246 | packet_len = packet_length;
247 | if (packet_len < 12)
248 | packet_len = 12;
249 | init(0x0F);
250 | }
251 |
252 | /** init the RTP packet header (only PT) */
253 | public void init(int ptype) {
254 | init(ptype, Random.nextLong());
255 | }
256 |
257 | /** init the RTP packet header (PT and SSCR) */
258 | public void init(int ptype, long sscr) {
259 | init(ptype, Random.nextInt(), Random.nextLong(), sscr);
260 | }
261 |
262 | /** init the RTP packet header (PT, SQN, TimeStamp, SSCR) */
263 | public void init(int ptype, int seqn, long timestamp, long sscr) {
264 | setVersion(2);
265 | setPayloadType(ptype);
266 | setSequenceNumber(seqn);
267 | setTimestamp(timestamp);
268 | setSscr(sscr);
269 | }
270 |
271 | // *********************** Private and Static ***********************
272 |
273 | /** Gets int value */
274 | private static int getInt(byte b) {
275 | return ((int) b + 256) % 256;
276 | }
277 |
278 | /** Gets long value */
279 | private static long getLong(byte[] data, int begin, int end) {
280 | long n = 0;
281 | for (; begin < end; begin++) {
282 | n <<= 8;
283 | n += data[begin] & 0xFF;
284 | }
285 | return n;
286 | }
287 |
288 | /** Sets long value */
289 | private static void setLong(long n, byte[] data, int begin, int end) {
290 | for (end--; end >= begin; end--) {
291 | data[end] = (byte) (n % 256);
292 | n >>= 8;
293 | }
294 | }
295 |
296 | /** Gets Int value */
297 | private static int getInt(byte[] data, int begin, int end) {
298 | return (int) getLong(data, begin, end);
299 | }
300 |
301 | /** Sets Int value */
302 | private static void setInt(int n, byte[] data, int begin, int end) {
303 | setLong(n, data, begin, end);
304 | }
305 |
306 | /** Gets bit value */
307 | private static boolean getBit(byte b, int bit) {
308 | return (b >> bit) == 1;
309 | }
310 |
311 | /** Sets bit value */
312 | private static byte setBit(boolean value, byte b, int bit) {
313 | if (value)
314 | return (byte) (b | (1 << bit));
315 | else
316 | return (byte) ((b | (1 << bit)) ^ (1 << bit));
317 | }
318 | }
319 |
--------------------------------------------------------------------------------
/bin/classes/org/sipdroid/net/.svn/text-base/RtpPacket.java.svn-base:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Sipdroid Open Source Project
3 | * Copyright (C) 2005 Luca Veltri - University of Parma - Italy
4 | *
5 | * This file is part of Sipdroid (http://www.sipdroid.org)
6 | *
7 | * Sipdroid is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This source code is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this source code; if not, write to the Free Software
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 | */
21 |
22 | package org.sipdroid.net;
23 |
24 | import org.zoolu.tools.Random;
25 |
26 | /**
27 | * RtpPacket implements a RTP packet.
28 | */
29 | public class RtpPacket {
30 | /* RTP packet buffer containing both the RTP header and payload */
31 | byte[] packet;
32 |
33 | /* RTP packet length */
34 | int packet_len;
35 |
36 | /* RTP header length */
37 | // int header_len;
38 | /** Gets the RTP packet */
39 | public byte[] getPacket() {
40 | return packet;
41 | }
42 |
43 | /** Gets the RTP packet length */
44 | public int getLength() {
45 | return packet_len;
46 | }
47 |
48 | /** Gets the RTP header length */
49 | public int getHeaderLength() {
50 | if (packet_len >= 12)
51 | return 12 + 4 * getCscrCount();
52 | else
53 | return packet_len; // broken packet
54 | }
55 |
56 | /** Gets the RTP header length */
57 | public int getPayloadLength() {
58 | if (packet_len >= 12)
59 | return packet_len - getHeaderLength();
60 | else
61 | return 0; // broken packet
62 | }
63 |
64 | /** Sets the RTP payload length */
65 | public void setPayloadLength(int len) {
66 | packet_len = getHeaderLength() + len;
67 | }
68 |
69 | // version (V): 2 bits
70 | // padding (P): 1 bit
71 | // extension (X): 1 bit
72 | // CSRC count (CC): 4 bits
73 | // marker (M): 1 bit
74 | // payload type (PT): 7 bits
75 | // sequence number: 16 bits
76 | // timestamp: 32 bits
77 | // SSRC: 32 bits
78 | // CSRC list: 0 to 15 items, 32 bits each
79 |
80 | /** Gets the version (V) */
81 | public int getVersion() {
82 | if (packet_len >= 12)
83 | return (packet[0] >> 6 & 0x03);
84 | else
85 | return 0; // broken packet
86 | }
87 |
88 | /** Sets the version (V) */
89 | public void setVersion(int v) {
90 | if (packet_len >= 12)
91 | packet[0] = (byte) ((packet[0] & 0x3F) | ((v & 0x03) << 6));
92 | }
93 |
94 | /** Whether has padding (P) */
95 | public boolean hasPadding() {
96 | if (packet_len >= 12)
97 | return getBit(packet[0], 5);
98 | else
99 | return false; // broken packet
100 | }
101 |
102 | /** Set padding (P) */
103 | public void setPadding(boolean p) {
104 | if (packet_len >= 12)
105 | packet[0] = setBit(p, packet[0], 5);
106 | }
107 |
108 | /** Whether has extension (X) */
109 | public boolean hasExtension() {
110 | if (packet_len >= 12)
111 | return getBit(packet[0], 4);
112 | else
113 | return false; // broken packet
114 | }
115 |
116 | /** Set extension (X) */
117 | public void setExtension(boolean x) {
118 | if (packet_len >= 12)
119 | packet[0] = setBit(x, packet[0], 4);
120 | }
121 |
122 | /** Gets the CSCR count (CC) */
123 | public int getCscrCount() {
124 | if (packet_len >= 12)
125 | return (packet[0] & 0x0F);
126 | else
127 | return 0; // broken packet
128 | }
129 |
130 | /** Whether has marker (M) */
131 | public boolean hasMarker() {
132 | if (packet_len >= 12)
133 | return getBit(packet[1], 7);
134 | else
135 | return false; // broken packet
136 | }
137 |
138 | /** Set marker (M) */
139 | public void setMarker(boolean m) {
140 | if (packet_len >= 12)
141 | packet[1] = setBit(m, packet[1], 7);
142 | }
143 |
144 | /** Gets the payload type (PT) */
145 | public int getPayloadType() {
146 | if (packet_len >= 12)
147 | return (packet[1] & 0x7F);
148 | else
149 | return -1; // broken packet
150 | }
151 |
152 | /** Sets the payload type (PT) */
153 | public void setPayloadType(int pt) {
154 | if (packet_len >= 12)
155 | packet[1] = (byte) ((packet[1] & 0x80) | (pt & 0x7F));
156 | }
157 |
158 | /** Gets the sequence number */
159 | public int getSequenceNumber() {
160 | if (packet_len >= 12)
161 | return getInt(packet, 2, 4);
162 | else
163 | return 0; // broken packet
164 | }
165 |
166 | /** Sets the sequence number */
167 | public void setSequenceNumber(int sn) {
168 | if (packet_len >= 12)
169 | setInt(sn, packet, 2, 4);
170 | }
171 |
172 | /** Gets the timestamp */
173 | public long getTimestamp() {
174 | if (packet_len >= 12)
175 | return getLong(packet, 4, 8);
176 | else
177 | return 0; // broken packet
178 | }
179 |
180 | /** Sets the timestamp */
181 | public void setTimestamp(long timestamp) {
182 | if (packet_len >= 12)
183 | setLong(timestamp, packet, 4, 8);
184 | }
185 |
186 | /** Gets the SSCR */
187 | public long getSscr() {
188 | if (packet_len >= 12)
189 | return getLong(packet, 8, 12);
190 | else
191 | return 0; // broken packet
192 | }
193 |
194 | /** Sets the SSCR */
195 | public void setSscr(long ssrc) {
196 | if (packet_len >= 12)
197 | setLong(ssrc, packet, 8, 12);
198 | }
199 |
200 | /** Gets the CSCR list */
201 | public long[] getCscrList() {
202 | int cc = getCscrCount();
203 | long[] cscr = new long[cc];
204 | for (int i = 0; i < cc; i++)
205 | cscr[i] = getLong(packet, 12 + 4 * i, 16 + 4 * i);
206 | return cscr;
207 | }
208 |
209 | /** Sets the CSCR list */
210 | public void setCscrList(long[] cscr) {
211 | if (packet_len >= 12) {
212 | int cc = cscr.length;
213 | if (cc > 15)
214 | cc = 15;
215 | packet[0] = (byte) (((packet[0] >> 4) << 4) + cc);
216 | cscr = new long[cc];
217 | for (int i = 0; i < cc; i++)
218 | setLong(cscr[i], packet, 12 + 4 * i, 16 + 4 * i);
219 | // header_len=12+4*cc;
220 | }
221 | }
222 |
223 | /** Sets the payload */
224 | public void setPayload(byte[] payload, int len) {
225 | if (packet_len >= 12) {
226 | int header_len = getHeaderLength();
227 | for (int i = 0; i < len; i++)
228 | packet[header_len + i] = payload[i];
229 | packet_len = header_len + len;
230 | }
231 | }
232 |
233 | /** Gets the payload */
234 | public byte[] getPayload() {
235 | int header_len = getHeaderLength();
236 | int len = packet_len - header_len;
237 | byte[] payload = new byte[len];
238 | for (int i = 0; i < len; i++)
239 | payload[i] = packet[header_len + i];
240 | return payload;
241 | }
242 |
243 | /** Creates a new RTP packet */
244 | public RtpPacket(byte[] buffer, int packet_length) {
245 | packet = buffer;
246 | packet_len = packet_length;
247 | if (packet_len < 12)
248 | packet_len = 12;
249 | init(0x0F);
250 | }
251 |
252 | /** init the RTP packet header (only PT) */
253 | public void init(int ptype) {
254 | init(ptype, Random.nextLong());
255 | }
256 |
257 | /** init the RTP packet header (PT and SSCR) */
258 | public void init(int ptype, long sscr) {
259 | init(ptype, Random.nextInt(), Random.nextLong(), sscr);
260 | }
261 |
262 | /** init the RTP packet header (PT, SQN, TimeStamp, SSCR) */
263 | public void init(int ptype, int seqn, long timestamp, long sscr) {
264 | setVersion(2);
265 | setPayloadType(ptype);
266 | setSequenceNumber(seqn);
267 | setTimestamp(timestamp);
268 | setSscr(sscr);
269 | }
270 |
271 | // *********************** Private and Static ***********************
272 |
273 | /** Gets int value */
274 | private static int getInt(byte b) {
275 | return ((int) b + 256) % 256;
276 | }
277 |
278 | /** Gets long value */
279 | private static long getLong(byte[] data, int begin, int end) {
280 | long n = 0;
281 | for (; begin < end; begin++) {
282 | n <<= 8;
283 | n += data[begin] & 0xFF;
284 | }
285 | return n;
286 | }
287 |
288 | /** Sets long value */
289 | private static void setLong(long n, byte[] data, int begin, int end) {
290 | for (end--; end >= begin; end--) {
291 | data[end] = (byte) (n % 256);
292 | n >>= 8;
293 | }
294 | }
295 |
296 | /** Gets Int value */
297 | private static int getInt(byte[] data, int begin, int end) {
298 | return (int) getLong(data, begin, end);
299 | }
300 |
301 | /** Sets Int value */
302 | private static void setInt(int n, byte[] data, int begin, int end) {
303 | setLong(n, data, begin, end);
304 | }
305 |
306 | /** Gets bit value */
307 | private static boolean getBit(byte b, int bit) {
308 | return (b >> bit) == 1;
309 | }
310 |
311 | /** Sets bit value */
312 | private static byte setBit(boolean value, byte b, int bit) {
313 | if (value)
314 | return (byte) (b | (1 << bit));
315 | else
316 | return (byte) ((b | (1 << bit)) ^ (1 << bit));
317 | }
318 | }
319 |
--------------------------------------------------------------------------------
/src/jay/codec/G711.java:
--------------------------------------------------------------------------------
1 | package jay.codec;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * G.711 codec. This class provides methods for u-law, A-law and linear PCM
7 | * conversions.
8 | */
9 | public class G711 {
10 | /*
11 | * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
12 | * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
13 | * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
14 | */
15 |
16 | private final static String TAG = "G711";
17 | static final short[] a2s = new short[256];
18 | static final int[] _a2s = {
19 |
20 | 60032, 60288, 59520, 59776, 61056, 61312, 60544, 60800,
21 | 57984, 58240, 57472, 57728, 59008, 59264, 58496, 58752,
22 | 62784, 62912, 62528, 62656, 63296, 63424, 63040, 63168,
23 | 61760, 61888, 61504, 61632, 62272, 62400, 62016, 62144,
24 | 43520, 44544, 41472, 42496, 47616, 48640, 45568, 46592,
25 | 35328, 36352, 33280, 34304, 39424, 40448, 37376, 38400,
26 | 54528, 55040, 53504, 54016, 56576, 57088, 55552, 56064,
27 | 50432, 50944, 49408, 49920, 52480, 52992, 51456, 51968,
28 | 65192, 65208, 65160, 65176, 65256, 65272, 65224, 65240,
29 | 65064, 65080, 65032, 65048, 65128, 65144, 65096, 65112,
30 | 65448, 65464, 65416, 65432, 65512, 65528, 65480, 65496,
31 | 65320, 65336, 65288, 65304, 65384, 65400, 65352, 65368,
32 | 64160, 64224, 64032, 64096, 64416, 64480, 64288, 64352,
33 | 63648, 63712, 63520, 63584, 63904, 63968, 63776, 63840,
34 | 64848, 64880, 64784, 64816, 64976, 65008, 64912, 64944,
35 | 64592, 64624, 64528, 64560, 64720, 64752, 64656, 64688,
36 | 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
37 | 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
38 | 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
39 | 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
40 | 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
41 | 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
42 | 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
43 | 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
44 | 344, 328, 376, 360, 280, 264, 312, 296,
45 | 472, 456, 504, 488, 408, 392, 440, 424,
46 | 88, 72, 120, 104, 24, 8, 56, 40,
47 | 216, 200, 248, 232, 152, 136, 184, 168,
48 | 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
49 | 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
50 | 688, 656, 752, 720, 560, 528, 624, 592,
51 | 944, 912, 1008, 976, 816, 784, 880, 848
52 |
53 | };
54 |
55 | static final byte[] s2a = new byte[65536];
56 | static final int[] _s2a = {
57 |
58 | 213,212,215,214,209,208,211,210,221,220,223,222,217,216,219,218,
59 | 197,196,199,198,193,192,195,194,205,204,207,206,201,200,203,202,
60 | 245,245,244,244,247,247,246,246,241,241,240,240,243,243,242,242,
61 | 253,253,252,252,255,255,254,254,249,249,248,248,251,251,250,250,
62 | 229,229,229,229,228,228,228,228,231,231,231,231,230,230,230,230,
63 | 225,225,225,225,224,224,224,224,227,227,227,227,226,226,226,226,
64 | 237,237,237,237,236,236,236,236,239,239,239,239,238,238,238,238,
65 | 233,233,233,233,232,232,232,232,235,235,235,235,234,234,234,234,
66 | 149,149,149,149,149,149,149,149,148,148,148,148,148,148,148,148,
67 | 151,151,151,151,151,151,151,151,150,150,150,150,150,150,150,150,
68 | 145,145,145,145,145,145,145,145,144,144,144,144,144,144,144,144,
69 | 147,147,147,147,147,147,147,147,146,146,146,146,146,146,146,146,
70 | 157,157,157,157,157,157,157,157,156,156,156,156,156,156,156,156,
71 | 159,159,159,159,159,159,159,159,158,158,158,158,158,158,158,158,
72 | 153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
73 | 155,155,155,155,155,155,155,155,154,154,154,154,154,154,154,154,
74 | 133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,
75 | 132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,
76 | 135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,
77 | 134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,
78 | 129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,
79 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
80 | 131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,
81 | 130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,
82 | 141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,
83 | 140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,
84 | 143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,
85 | 142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,
86 | 137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,
87 | 136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,
88 | 139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,
89 | 138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,
90 | 181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,
91 | 181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,
92 | 180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,
93 | 180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,
94 | 183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,
95 | 183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,
96 | 182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,
97 | 182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,
98 | 177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,
99 | 177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,
100 | 176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,
101 | 176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,
102 | 179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,
103 | 179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,
104 | 178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,
105 | 178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,
106 | 189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,
107 | 189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,
108 | 188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,
109 | 188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,
110 | 191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,
111 | 191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,
112 | 190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,
113 | 190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,
114 | 185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,
115 | 185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,
116 | 184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,
117 | 184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,
118 | 187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,
119 | 187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,
120 | 186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,
121 | 186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,
122 | 165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,
123 | 165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,
124 | 165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,
125 | 165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,
126 | 164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,
127 | 164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,
128 | 164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,
129 | 164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,
130 | 167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
131 | 167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
132 | 167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
133 | 167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
134 | 166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,
135 | 166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,
136 | 166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,
137 | 166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,
138 | 161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
139 | 161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
140 | 161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
141 | 161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
142 | 160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
143 | 160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
144 | 160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
145 | 160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
146 | 163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,
147 | 163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,
148 | 163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,
149 | 163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,
150 | 162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,
151 | 162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,
152 | 162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,
153 | 162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,
154 | 173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
155 | 173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
156 | 173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
157 | 173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
158 | 172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
159 | 172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
160 | 172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
161 | 172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
162 | 175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
163 | 175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
164 | 175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
165 | 175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
166 | 174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,
167 | 174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,
168 | 174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,
169 | 174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,
170 | 169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
171 | 169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
172 | 169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
173 | 169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
174 | 168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
175 | 168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
176 | 168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
177 | 168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
178 | 171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
179 | 171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
180 | 171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
181 | 171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
182 | 170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
183 | 170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
184 | 170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
185 | 170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
186 | 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
187 | 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
188 | 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
189 | 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
190 | 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
191 | 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
192 | 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
193 | 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
194 | 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
195 | 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
196 | 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
197 | 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
198 | 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
199 | 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
200 | 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
201 | 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
202 | 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
203 | 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
204 | 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
205 | 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
206 | 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
207 | 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
208 | 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
209 | 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
210 | 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
211 | 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
212 | 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
213 | 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
214 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
215 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
216 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
217 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
218 | 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
219 | 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
220 | 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
221 | 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
222 | 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
223 | 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
224 | 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
225 | 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
226 | 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
227 | 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
228 | 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
229 | 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
230 | 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
231 | 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
232 | 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
233 | 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
234 | 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
235 | 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
236 | 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
237 | 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
238 | 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
239 | 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
240 | 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
241 | 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
242 | 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
243 | 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
244 | 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
245 | 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
246 | 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
247 | 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
248 | 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
249 | 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
250 | 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
251 | 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
252 | 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
253 | 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
254 | 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
255 | 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
256 | 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57,
257 | 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57,
258 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
259 | 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
260 | 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
261 | 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
262 | 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
263 | 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
264 | 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
265 | 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
266 | 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
267 | 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
268 | 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
269 | 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
270 | 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
271 | 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
272 | 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
273 | 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
274 | 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
275 | 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
276 | 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
277 | 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
278 | 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
279 | 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
280 | 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
281 | 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
282 | 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
283 | 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
284 | 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
285 | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
286 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
287 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
288 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
289 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
290 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
291 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
292 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
293 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
294 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
295 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
296 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
297 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
298 | 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
299 | 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25,
300 | 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31,
301 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29,
302 | 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19,
303 | 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17,
304 | 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
305 | 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21,
306 | 106,106,106,106,107,107,107,107,104,104,104,104,105,105,105,105,
307 | 110,110,110,110,111,111,111,111,108,108,108,108,109,109,109,109,
308 | 98, 98, 98, 98, 99, 99, 99, 99, 96, 96, 96, 96, 97, 97, 97, 97,
309 | 102,102,102,102,103,103,103,103,100,100,100,100,101,101,101,101,
310 | 122,122,123,123,120,120,121,121,126,126,127,127,124,124,125,125,
311 | 114,114,115,115,112,112,113,113,118,118,119,119,116,116,117,117,
312 | 74, 75, 72, 73, 78, 79, 76, 77, 66, 67, 64, 65, 70, 71, 68, 69,
313 | 90, 91, 88, 89, 94, 95, 92, 93, 82, 83, 80, 81, 86, 87, 84, 85
314 | };
315 |
316 | //change G711 ulaw start
317 | static final int _u2a[] = { /* u- to A-law conversions */
318 | 1, 1, 2, 2, 3, 3, 4, 4,
319 | 5, 5, 6, 6, 7, 7, 8, 8,
320 | 9, 10, 11, 12, 13, 14, 15, 16,
321 | 17, 18, 19, 20, 21, 22, 23, 24,
322 | 25, 27, 29, 31, 33, 34, 35, 36,
323 | 37, 38, 39, 40, 41, 42, 43, 44,
324 | 46, 48, 49, 50, 51, 52, 53, 54,
325 | 55, 56, 57, 58, 59, 60, 61, 62,
326 | 64, 65, 66, 67, 68, 69, 70, 71,
327 | 72, 73, 74, 75, 76, 77, 78, 79,
328 | 81, 82, 83, 84, 85, 86, 87, 88,
329 | 89, 90, 91, 92, 93, 94, 95, 96,
330 | 97, 98, 99, 100, 101, 102, 103, 104,
331 | 105, 106, 107, 108, 109, 110, 111, 112,
332 | 113, 114, 115, 116, 117, 118, 119, 120,
333 | 121, 122, 123, 124, 125, 126, 127, 128};
334 |
335 | static final int _a2u[] = { /* A- to u-law conversions */
336 | 1, 3, 5, 7, 9, 11, 13, 15,
337 | 16, 17, 18, 19, 20, 21, 22, 23,
338 | 24, 25, 26, 27, 28, 29, 30, 31,
339 | 32, 32, 33, 33, 34, 34, 35, 35,
340 | 36, 37, 38, 39, 40, 41, 42, 43,
341 | 44, 45, 46, 47, 48, 48, 49, 49,
342 | 50, 51, 52, 53, 54, 55, 56, 57,
343 | 58, 59, 60, 61, 62, 63, 64, 64,
344 | 65, 66, 67, 68, 69, 70, 71, 72,
345 | 73, 74, 75, 76, 77, 78, 79, 80,
346 | 80, 81, 82, 83, 84, 85, 86, 87,
347 | 88, 89, 90, 91, 92, 93, 94, 95,
348 | 96, 97, 98, 99, 100, 101, 102, 103,
349 | 104, 105, 106, 107, 108, 109, 110, 111,
350 | 112, 113, 114, 115, 116, 117, 118, 119,
351 | 120, 121, 122, 123, 124, 125, 126, 127};
352 |
353 | //change end
354 |
355 | public static void init() {
356 | Log.d(TAG, "G711 init()");
357 | }
358 |
359 | static {
360 | Log.d(TAG, "G711 static");
361 |
362 | int i;
363 | for (i = 0; i < 256; i++)
364 | a2s[i] = (short)_a2s[i];
365 | for (i = 0; i < 65536; i++)
366 | s2a[i] = (byte)_s2a[i >> 4];
367 | }
368 |
369 | public static void alaw2linear(byte alaw[],short lin[],int frames) {
370 | int i;
371 | for (i = 0; i < frames; i++)
372 | lin[i] = a2s[alaw[i+12] & 0xff];
373 | }
374 |
375 | public static void alaw2linear(byte alaw[],short lin[],int frames,int mu) {
376 | int i;
377 | for (i = 0; i < frames; i++)
378 | lin[i] = a2s[alaw[i/mu+12] & 0xff];
379 | }
380 |
381 | public static void linear2alaw(short lin[],int offset,byte alaw[],int frames) {
382 | int i;
383 | for (i = 0; i < frames; i++)
384 | alaw[i+12] = s2a[lin[i+offset] & 0xffff];
385 | }
386 |
387 | //change g711 ulaw start
388 | protected static int alaw2ulaw(int aval)
389 | { aval&=0xff;
390 | return ((aval & 0x80)!=0)? (0xFF^_a2u[aval^0xD5]) : (0x7F^_a2u[aval^0x55]);
391 | }
392 |
393 | protected static int ulaw2alaw(int uval)
394 | { uval&=0xff;
395 | return ((uval&0x80)!=0)? (0xD5^(_u2a[0xFF^uval]-1)) : (0x55^(_u2a[0x7F^uval]-1));
396 | }
397 |
398 | public static void ulaw2linear(byte ulaw[],short lin[],int frames) {
399 | int i;
400 | for (i = 0; i < frames; i++)
401 | lin[i] = a2s[ulaw2alaw(ulaw[i+12] & 0xff)];
402 | }
403 | public static void linear2ulaw(short lin[],int offset,byte ulaw[],int frames) {
404 | int i;
405 | for (i = 0; i < frames; i++)
406 | ulaw[i+12] = (byte)alaw2ulaw(s2a[lin[i+offset] & 0xffff]);
407 | }
408 | //change end
409 | }
410 |
--------------------------------------------------------------------------------