Dynamically load codec list
Description: This cl adds a feature that can query video engine and voice engine and load code list in gui settings. Currently, codec lists are fixed in resource file, it caused confusion and problems. TBR=ronghua BUG= TEST=test on android Review URL: https://webrtc-codereview.appspot.com/583006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2301 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -114,6 +114,15 @@ JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_SetLocal
|
||||
JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_SetSendDestination
|
||||
(JNIEnv *, jobject, jint, jint, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: org_webrtc_videoengineapp_ViEAndroidJavaAPI
|
||||
* Method: GetCodecs(
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_GetCodecs(
|
||||
JNIEnv *env,
|
||||
jobject);
|
||||
|
||||
/*
|
||||
* Class: org_webrtc_videoengineapp_ViEAndroidJavaAPI
|
||||
* Method: SetReceiveCodec
|
||||
@@ -380,6 +389,14 @@ JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_VoE_1Sto
|
||||
JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_VoE_1NumOfCodecs
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: org_webrtc_videoengineapp_ViEAndroidJavaAPI
|
||||
* Method: VoE_NumOfCodecs
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_VoE_1GetCodecs
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: org_webrtc_videoengineapp_ViEAndroidJavaAPI
|
||||
* Method: VoE_SetSendCodec
|
||||
|
@@ -714,6 +714,49 @@ JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_SetSendC
|
||||
return vieData.codec->SetSendCodec(channel, codec);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_webrtc_videoengineapp_ViEAndroidJavaAPI
|
||||
* Method: SetSendCodec
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_GetCodecs(
|
||||
JNIEnv *env,
|
||||
jobject)
|
||||
{
|
||||
if (NULL == vieData.codec) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jobjectArray ret;
|
||||
int i;
|
||||
int num = vieData.codec->NumberOfCodecs();
|
||||
char info[32];
|
||||
|
||||
ret = (jobjectArray)env->NewObjectArray(
|
||||
num,
|
||||
env->FindClass("java/lang/String"),
|
||||
env->NewStringUTF(""));
|
||||
|
||||
for (int i = 0; i < num; ++i) {
|
||||
webrtc::VideoCodec codecToList;
|
||||
vieData.codec->GetCodec(i, codecToList);
|
||||
sprintf(info, "%s pltype:%d", codecToList.plName, codecToList.plType);
|
||||
env->SetObjectArrayElement(ret, i, env->NewStringUTF( info ));
|
||||
|
||||
__android_log_print(
|
||||
ANDROID_LOG_DEBUG,
|
||||
WEBRTC_LOG_TAG,
|
||||
"Codec[%d] %s, pltype=%d, bitRate=%d, maxBitRate=%d,"
|
||||
" width=%d, height=%d, frameRate=%d\n",
|
||||
i, codecToList.plName, codecToList.plType,
|
||||
codecToList.startBitrate, codecToList.maxBitrate,
|
||||
codecToList.width, codecToList.height,
|
||||
codecToList.maxFramerate);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_webrtc_videoengineapp_ViEAndroidJavaAPI
|
||||
* Method: AddRemoteRenderer
|
||||
@@ -1395,7 +1438,6 @@ JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_VoE_1Sto
|
||||
return voeData.file->StopPlayingFileAsMicrophone(channel);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: org_webrtc_videoengineapp_ViEAndroidJavaAPI
|
||||
* Method: VoE_NumOfCodecs
|
||||
@@ -1409,6 +1451,44 @@ JNIEXPORT jint JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_VoE_1Num
|
||||
return voeData.codec->NumOfCodecs();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_webrtc_videoengineapp_ViEAndroidJavaAPI
|
||||
* Method: VoE_NumOfCodecs
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_webrtc_videoengineapp_ViEAndroidJavaAPI_VoE_1GetCodecs(
|
||||
JNIEnv *env,
|
||||
jobject)
|
||||
{
|
||||
if (!voeData.codec) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, WEBRTC_LOG_TAG,
|
||||
"Codec pointer doesn't exist");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jobjectArray ret;
|
||||
int i;
|
||||
int num = voeData.codec->NumOfCodecs();
|
||||
char info[32];
|
||||
|
||||
ret = (jobjectArray)env->NewObjectArray(
|
||||
num,
|
||||
env->FindClass("java/lang/String"),
|
||||
env->NewStringUTF(""));
|
||||
|
||||
for(i = 0; i < num; i++) {
|
||||
webrtc::CodecInst codecToList;
|
||||
voeData.codec->GetCodec(i, codecToList);
|
||||
__android_log_print(ANDROID_LOG_DEBUG, WEBRTC_LOG_TAG,
|
||||
"VoiceEgnine Codec[%d] %s, pltype=%d\n",
|
||||
i, codecToList.plname, codecToList.pltype);
|
||||
sprintf(info, "%s pltype:%d", codecToList.plname, codecToList.pltype);
|
||||
env->SetObjectArrayElement(ret, i, env->NewStringUTF( info ));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_webrtc_videoengineapp_ViEAndroidJavaAPI
|
||||
* Method: VoE_SetSendCodec
|
||||
|
@@ -73,14 +73,14 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/opengl"
|
||||
android:checked="true"
|
||||
android:textColor="#0f0"/>
|
||||
android:textColor="#fff"/>
|
||||
<RadioButton
|
||||
android:id="@+id/radio_surface"
|
||||
android:onClick="onClick"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/surfaceview"
|
||||
android:textColor="#0f0" />
|
||||
android:textColor="#fff" />
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
||||
|
||||
|
18
src/video_engine/main/test/android_test/res/layout/row.xml
Normal file
18
src/video_engine/main/test/android_test/res/layout/row.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="3dip">
|
||||
<TextView
|
||||
android:layout_toRightOf="@+id/image"
|
||||
android:padding="3dip"
|
||||
android:layout_marginTop="2dip"
|
||||
android:textColor="#000"
|
||||
android:textStyle="bold"
|
||||
android:id="@+id/spinner_row"
|
||||
android:text="description"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</RelativeLayout>
|
@@ -1,22 +0,0 @@
|
||||
<resources>
|
||||
|
||||
<string-array name="codectype">
|
||||
<item>vp8</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="codecSize"><item>176x144</item><item>320x240</item>
|
||||
<item>352x288</item><item>640x480</item>
|
||||
|
||||
</string-array>
|
||||
|
||||
<string-array name="voiceCodecType">
|
||||
<item>iPCM-wb</item>
|
||||
<item>iSAC</item>
|
||||
<item>iSAC-LC</item>
|
||||
<item>EG711U</item>
|
||||
<item>EG711A</item>
|
||||
<item>PCMU</item>
|
||||
<item>PCMA</item>
|
||||
<item>iLBC</item>
|
||||
</string-array>
|
||||
</resources>
|
@@ -54,6 +54,7 @@ public class ViEAndroidJavaAPI {
|
||||
public native int SetLocalReceiver(int channel, int port);
|
||||
public native int SetSendDestination(int channel, int port, byte ipadr[]);
|
||||
// Codec
|
||||
public native String[] GetCodecs();
|
||||
public native int SetReceiveCodec(int channel, int codecNum,
|
||||
int intbitRate, int width,
|
||||
int height, int frameRate);
|
||||
@@ -126,6 +127,7 @@ public class ViEAndroidJavaAPI {
|
||||
|
||||
// Codec-setting functions
|
||||
public native int VoE_NumOfCodecs();
|
||||
public native String[] VoE_GetCodecs();
|
||||
public native int VoE_SetSendCodec(int channel, int index);
|
||||
|
||||
//VE funtions
|
||||
|
@@ -18,7 +18,10 @@ import java.util.Enumeration;
|
||||
import org.webrtc.videoengine.ViERenderer;
|
||||
|
||||
import android.app.TabActivity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Canvas;
|
||||
@@ -37,9 +40,11 @@ import android.os.PowerManager.WakeLock;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Display;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
@@ -137,7 +142,7 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
|
||||
// Audio settings
|
||||
private Spinner spVoiceCodecType;
|
||||
private int voiceCodecType = 5; // PCMU = 5
|
||||
private int voiceCodecType = 0;
|
||||
private TextView etARxPort;
|
||||
private int receivePortVoice = 11113;
|
||||
private TextView etATxPort;
|
||||
@@ -162,6 +167,11 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
|
||||
private boolean usingFrontCamera = false;
|
||||
|
||||
private String[] mVideoCodecsStrings = null;
|
||||
private String[] mVideoCodecsSizeStrings = { "176x144", "320x240",
|
||||
"352x288", "640x480" };
|
||||
private String[] mVoiceCodecsStrings = null;
|
||||
|
||||
private OrientationEventListener orientationListener;
|
||||
int currentOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
|
||||
int currentCameraOrientation = 0;
|
||||
@@ -348,6 +358,30 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
}
|
||||
}
|
||||
|
||||
public class SpinnerAdapter extends ArrayAdapter<String> {
|
||||
private String[] mCodecString = null;
|
||||
public SpinnerAdapter(Context context, int textViewResourceId, String[] objects) {
|
||||
super(context, textViewResourceId, objects);
|
||||
mCodecString = objects;
|
||||
}
|
||||
|
||||
@Override public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
@Override public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return getCustomView(position, convertView, parent);
|
||||
}
|
||||
|
||||
public View getCustomView(int position, View convertView, ViewGroup parent) {
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
View row = inflater.inflate(R.layout.row, parent, false);
|
||||
TextView label = (TextView)row.findViewById(R.id.spinner_row);
|
||||
label.setText(mCodecString[position]);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
private void StartMain() {
|
||||
mTabHost.setCurrentTab(0);
|
||||
|
||||
@@ -357,6 +391,19 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
if (null == ViEAndroidAPI)
|
||||
ViEAndroidAPI = new ViEAndroidJavaAPI(this);
|
||||
|
||||
if (0 > SetupVoE() || 0 > ViEAndroidAPI.GetVideoEngine() ||
|
||||
0 > ViEAndroidAPI.Init(enableTrace) ) {
|
||||
// Show dialog
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
|
||||
alertDialog.setTitle("WebRTC Error");
|
||||
alertDialog.setMessage("Can not init video engine.");
|
||||
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
return;
|
||||
} });
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
btSwitchCamera = (Button)findViewById(R.id.btSwitchCamera);
|
||||
btSwitchCamera.setOnClickListener(this);
|
||||
btStartStopCall = (Button)findViewById(R.id.btStartStopCall);
|
||||
@@ -367,21 +414,31 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
remoteSurfaceView = null;
|
||||
svLocal = null;
|
||||
|
||||
// init UI
|
||||
ArrayAdapter<?> adapter;
|
||||
|
||||
int resource = android.R.layout.simple_spinner_item;
|
||||
int dropdownRes = android.R.layout.simple_spinner_dropdown_item;
|
||||
|
||||
// video codec
|
||||
spCodecType = (Spinner) findViewById(R.id.spCodecType);
|
||||
adapter = ArrayAdapter.createFromResource(this,
|
||||
R.array.codectype,
|
||||
resource);
|
||||
adapter.setDropDownViewResource(dropdownRes);
|
||||
spCodecType.setAdapter(adapter);
|
||||
spCodecType.setSelection(codecType);
|
||||
// Video codec
|
||||
mVideoCodecsStrings = ViEAndroidAPI.GetCodecs();
|
||||
spCodecType = (Spinner)findViewById(R.id.spCodecType);
|
||||
spCodecType.setOnItemSelectedListener(this);
|
||||
spCodecType.setAdapter(new SpinnerAdapter(this,
|
||||
R.layout.row,
|
||||
mVideoCodecsStrings));
|
||||
spCodecType.setSelection(0);
|
||||
|
||||
// Video Codec size
|
||||
spCodecSize = (Spinner) findViewById(R.id.spCodecSize);
|
||||
spCodecSize.setOnItemSelectedListener(this);
|
||||
spCodecSize.setAdapter(new SpinnerAdapter(this,
|
||||
R.layout.row,
|
||||
mVideoCodecsSizeStrings));
|
||||
spCodecSize.setSelection(0);
|
||||
|
||||
// Voice codec
|
||||
mVoiceCodecsStrings = ViEAndroidAPI.VoE_GetCodecs();
|
||||
spVoiceCodecType = (Spinner)findViewById(R.id.spVoiceCodecType);
|
||||
spVoiceCodecType.setOnItemSelectedListener(this);
|
||||
spVoiceCodecType.setAdapter(new SpinnerAdapter(this,
|
||||
R.layout.row,
|
||||
mVoiceCodecsStrings));
|
||||
spVoiceCodecType.setSelection(0);
|
||||
|
||||
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radio_group1);
|
||||
radioGroup.clearCheck();
|
||||
@@ -392,22 +449,6 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
radioGroup.check(R.id.radio_surface);
|
||||
}
|
||||
|
||||
// voice codec
|
||||
spVoiceCodecType = (Spinner) findViewById(R.id.spVoiceCodecType);
|
||||
adapter = ArrayAdapter.createFromResource(this, R.array.voiceCodecType,
|
||||
resource);
|
||||
adapter.setDropDownViewResource(dropdownRes);
|
||||
spVoiceCodecType.setAdapter(adapter);
|
||||
spVoiceCodecType.setSelection(voiceCodecType);
|
||||
spVoiceCodecType.setOnItemSelectedListener(this);
|
||||
|
||||
spCodecSize = (Spinner) findViewById(R.id.spCodecSize);
|
||||
adapter = ArrayAdapter.createFromResource(this, R.array.codecSize,
|
||||
resource);
|
||||
adapter.setDropDownViewResource(dropdownRes);
|
||||
spCodecSize.setAdapter(adapter);
|
||||
spCodecSize.setOnItemSelectedListener(this);
|
||||
|
||||
etRemoteIp = (EditText) findViewById(R.id.etRemoteIp);
|
||||
etRemoteIp.setText(remoteIp);
|
||||
|
||||
@@ -462,7 +503,6 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
int ret = 0;
|
||||
|
||||
if (enableVoice) {
|
||||
SetupVoE();
|
||||
StartVoiceEngine();
|
||||
}
|
||||
|
||||
@@ -472,8 +512,6 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
svLocal = ViERenderer.CreateLocalRenderer(this);
|
||||
}
|
||||
|
||||
ret = ViEAndroidAPI.GetVideoEngine();
|
||||
ret = ViEAndroidAPI.Init(enableTrace);
|
||||
channel = ViEAndroidAPI.CreateChannel(voiceChannel);
|
||||
ret = ViEAndroidAPI.SetLocalReceiver(channel,
|
||||
receivePortVideo);
|
||||
@@ -573,7 +611,7 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupVoE() {
|
||||
private int SetupVoE() {
|
||||
// Create VoiceEngine
|
||||
// Error logging is done in native API wrapper
|
||||
ViEAndroidAPI.VoE_Create();
|
||||
@@ -581,16 +619,19 @@ public class WebRTCDemo extends TabActivity implements IViEAndroidCallback,
|
||||
// Initialize
|
||||
if (0 != ViEAndroidAPI.VoE_Init(enableTrace)) {
|
||||
Log.d(TAG, "VoE init failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create channel
|
||||
voiceChannel = ViEAndroidAPI.VoE_CreateChannel();
|
||||
if (0 != voiceChannel) {
|
||||
Log.d(TAG, "VoE create channel failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Suggest to use the voice call audio stream for hardware volume controls
|
||||
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int StartVoiceEngine() {
|
||||
|
Reference in New Issue
Block a user