package org.webrtc.voiceengine.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.AudioTrack;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class AndroidTest extends Activity {
private byte[] _playBuffer = null;
private short[] _circBuffer = new short[8000]; // can hold 50 frames
private int _recIndex = 0;
private int _playIndex = 0;
// private int _streamVolume = 4;
private int _maxVolume = 0; // Android max level (commonly 5)
// VoE level (0-255), corresponds to level 4 out of 5
private int _volumeLevel = 204;
private Thread _playThread;
private Thread _recThread;
private Thread _autotestThread;
private static AudioTrack _at;
private static AudioRecord _ar;
private File _fr = null;
private FileInputStream _in = null;
private boolean _isRunningPlay = false;
private boolean _isRunningRec = false;
private boolean _settingSet = true;
private boolean _isCallActive = false;
private boolean _runAutotest = false; // ENABLE AUTOTEST HERE!
private int _channel = -1;
private int _codecIndex = 0;
private int _ecIndex = 0;
private int _nsIndex = 0;
private int _agcIndex = 0;
private int _vadIndex = 0;
private int _audioIndex = 3;
private int _settingMenu = 0;
private int _receivePort = 1234;
private int _destinationPort = 1234;
private String _destinationIP = "127.0.0.1";
// "Build" settings
private final boolean _playFromFile = false;
// Set to true to send data to native code and back
private final boolean _runThroughNativeLayer = true;
private final boolean enableSend = true;
private final boolean enableReceive = true;
private final boolean useNativeThread = false;
Context mContext = null;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContext = this;
TextView tv = (TextView) findViewById(R.id.TextView01);
tv.setText("Trail Version, Please contact dotphoenix@qq.com fro more informaions.");
final EditText ed = (EditText) findViewById(R.id.EditText01);
ed.setWidth(200);
ed.setText(_destinationIP);
final Button buttonStart = (Button) findViewById(R.id.Button01);
buttonStart.setWidth(200);
if (_runAutotest) {
buttonStart.setText("Run test");
} else {
buttonStart.setText("Start Call");
}
// button.layout(50, 50, 100, 40);
buttonStart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (_runAutotest) {
startAutoTest();
} else {
if (_isCallActive) {
if (stopCall() != -1) {
_isCallActive = false;
buttonStart.setText("Start Call");
}
} else {
if (!NativeInit()) {
Log.e("*Webrtc*", "Native init failed");
// showWarningToast();
} else {
Log.d("*Webrtc*", "Native init successful");
}
_destinationIP = ed.getText().toString();
int started = startCall();
if (started != -1) {
_isCallActive = true;
buttonStart.setText("Stop Call");
}
}
}
// displayTextFromFile();
// recordAudioToFile();
// if(!_playFromFile)
// {
// recAudioInThread();
// }
// playAudioInThread();
}
});
final Button buttonStop = (Button) findViewById(R.id.Button02);
buttonStop.setWidth(200);
buttonStop.setText("Close app");
buttonStop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!_runAutotest) {
ShutdownVoE();
}
// This call terminates and should close the activity
finish();
// playAudioFromFile();
// if(!_playFromFile)
// {
// stopRecAudio();
// }
// stopPlayAudio();
}
});
final Button buttonStartSound = (Button) findViewById(R.id.ButtonStartSound);
buttonStartSound.setWidth(200);
buttonStartSound.setText("Start Sound");
buttonStartSound.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String text = buttonStartSound.getText().toString();
if (text.compareToIgnoreCase("Start Sound") == 0) {
String codecname;
switch (_codecIndex) {
case 0:
codecname = "iSAC";
break;
case 1:
codecname = "PCMU";
break;
case 2:
codecname = "PCMA";
break;
case 3:
codecname = "iLBC";
break;
default:
codecname = "PCMU";
break;
}
Log.d("*Webrtc*", "Calling native init...");
if (!NativeInit()) {
// showWarningToast();
Log.d("*Webrtc*", "Native init failed");
} else {
Log.d("*Webrtc*", "Native init successful");
}
StartSound(_destinationIP, _destinationPort, _receivePort,
codecname);
buttonStartSound.setText("Stop Sound");
} else {
StopSound();
buttonStartSound.setText("Start Sound");
}
}
});
String ap1[] = { "EC off", "AECM" };
final ArrayAdapter<String> adapterAp1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, ap1);
String ap2[] = { "NS off", "NS low", "NS moderate", "NS high",
"NS very high" };
final ArrayAdapter<String> adapterAp2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, ap2);
String ap3[] = { "AGC off", "AGC adaptive", "AGC fixed" };
final ArrayAdapter<String> adapterAp3 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, ap3);
String ap4[] = { "VAD off", "VAD conventional", "VAD high rate",
"VAD mid rate", "VAD low rate" };
final ArrayAdapter<String> adapterAp4 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, ap4);
String codecs[] = { "iSAC", "PCMU", "PCMA", "iLBC" };
final ArrayAdapter<String> adapterCodecs = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_dropdown_item, codecs);
final Spinner spinnerSettings1 = (Spinner) findViewById(R.id.Spinner01);
final Spinner spinnerSettings2 = (Spinner) findViewById(R.id.Spinner02);
spinnerSettings1.setMinimumWidth(200);
String settings[] = { "Codec", "Echo Control", "Noise Suppression",
"Automatic Gain Control", "Voice Activity Detection" };
ArrayAdapter<String> adapterSettings1 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, settings);
spinnerSettings1.setAdapter(adapterSettings1);
spinnerSettings1
.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView adapterView,
View view, int position, long id) {
_settingMenu = position;
_settingSet = false;
if (position == 0) {
spinnerSettings2.setAdapter(adapterCodecs);
spinnerSettings2.setSelection(_codecIndex);
}
if (position == 1) {
spinnerSettings2.setAdapter(adapterAp1);
spinnerSettings2.setSelection(_ecIndex);
}
if (
- 1
- 2
- 3
- 4
前往页