all
This commit is contained in:
277
app/src/main/java/com/tianrun/sipcall/call/InCallActivity.java
Normal file
277
app/src/main/java/com/tianrun/sipcall/call/InCallActivity.java
Normal file
@@ -0,0 +1,277 @@
|
||||
package com.tianrun.sipcall.call;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.tianrun.sipcall.R;
|
||||
import com.tianrun.sipcall.SipEngine;
|
||||
import com.tianrun.sipcall.ui.TrBaseActivity;
|
||||
import com.tianrun.sipcall.utils.CONS;
|
||||
import com.tianrun.sipcall.utils.logmy;
|
||||
|
||||
import blue.view.EngineServer;
|
||||
import blue.view.SMPercentFrameLayout;
|
||||
import blue.view.SMSurfaceViewRenderer;
|
||||
|
||||
|
||||
public class InCallActivity extends TrBaseActivity implements OnClickListener {
|
||||
public static Handler handler_CallActivity;
|
||||
public static String TAG = "CallActivity";
|
||||
private Handler handler = new Handler(this);
|
||||
private PowerManager powerManager = null;
|
||||
private WakeLock wakeLock = null;
|
||||
private SMSurfaceViewRenderer localRender;
|
||||
private SMSurfaceViewRenderer remoteRender;
|
||||
private SMPercentFrameLayout localRenderLayout;
|
||||
private SMPercentFrameLayout remoteRenderLayout;
|
||||
private ImageButton incall_answer, incall_hangup;
|
||||
private TextView show;
|
||||
// private Button meetingbutton;
|
||||
|
||||
private EngineServer engineServer;
|
||||
|
||||
private int callid = -1;//当前通话的id
|
||||
private String callnumber = "未知";
|
||||
private String callstate = "未知";
|
||||
private int calltype = 0; //0音频1视频
|
||||
private boolean VIDEOSTATE = false;
|
||||
public static Intent incallIntent;
|
||||
|
||||
@SuppressLint("InvalidWakeLockTag")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// fullScreen();
|
||||
setContentView(R.layout.incallactivity);
|
||||
handler_CallActivity = handler;
|
||||
powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是调试用的Tag
|
||||
wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
|
||||
//点亮屏幕
|
||||
wakeLock.acquire();
|
||||
|
||||
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
|
||||
KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");
|
||||
kl.disableKeyguard();
|
||||
initview();
|
||||
incallIntent = getIntent();
|
||||
setDate(this.getIntent());
|
||||
}
|
||||
|
||||
private void initview() {
|
||||
show = (TextView) findViewById(R.id.show);
|
||||
incall_answer = (ImageButton) findViewById(R.id.incall_answer);
|
||||
incall_hangup = (ImageButton) findViewById(R.id.incall_hangup);
|
||||
incall_hangup.setOnClickListener(this);
|
||||
incall_answer.setOnClickListener(this);
|
||||
//下面为视频部分
|
||||
localRender = (SMSurfaceViewRenderer) findViewById(R.id.local_video_view);
|
||||
remoteRender = (SMSurfaceViewRenderer) findViewById(R.id.remote_video_view);
|
||||
localRenderLayout = (SMPercentFrameLayout) findViewById(R.id.local_video_layout);
|
||||
remoteRenderLayout = (SMPercentFrameLayout) findViewById(R.id.remote_video_layout);
|
||||
engineServer = new EngineServer(localRender, remoteRender, localRenderLayout, remoteRenderLayout, true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
fullScreen();
|
||||
incallIntent = getIntent();
|
||||
setDate(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (callstate.equals("来电")) {
|
||||
incall_answer.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
incall_answer.setVisibility(View.GONE);
|
||||
}
|
||||
show.setText(callnumber + callstate);
|
||||
if (incall_answer.getVisibility() == View.VISIBLE) {
|
||||
incall_answer.setVisibility(View.GONE);
|
||||
SipEngine.getInstance().answer(callid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
// onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
stopVideoStream(true);
|
||||
super.onDestroy();
|
||||
SipEngine.getInstance().hangup(callid);
|
||||
handler_CallActivity = null;
|
||||
if (wakeLock != null) {
|
||||
wakeLock.release();
|
||||
wakeLock = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 变更通话数据
|
||||
*/
|
||||
public void setDate(Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
callid = bundle.getInt("callid");
|
||||
callnumber = bundle.getString("callnumber");
|
||||
callstate = bundle.getString("callstate");
|
||||
calltype = bundle.getInt("calltype");
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止视频
|
||||
*
|
||||
* @param isExit 是否完全退出视频
|
||||
*/
|
||||
public synchronized void stopVideoStream(boolean isExit) {
|
||||
if (VIDEOSTATE && engineServer != null) {
|
||||
engineServer.stopVideoStream(isExit);
|
||||
VIDEOSTATE = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message m) {
|
||||
switch (m.what) {
|
||||
case CONS.CALLSTATE:
|
||||
callstate = (String) m.obj;
|
||||
show.setText(callnumber + callstate);
|
||||
if (callstate.equals("挂断")) {
|
||||
stopVideoStream(true);
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
case CONS.MEDIASTATE:
|
||||
CallMediaUtils utils = (CallMediaUtils) m.obj;
|
||||
int r = utils.getR();
|
||||
int l = utils.getL();
|
||||
int payload = utils.getPayload();
|
||||
if (r != 0 || l != 0) {
|
||||
//开始视频
|
||||
ShowVideoView(true);
|
||||
startVideoStream(SipEngine.getInstance().getip(), r, l, payload);
|
||||
} else {
|
||||
//开始音频
|
||||
stopVideoStream(false);
|
||||
ShowVideoView(false);
|
||||
}
|
||||
break;
|
||||
case CONS.CALLDOWN:
|
||||
stopVideoStream(true);
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private synchronized void startVideoStream(String server, int rport, int lport, final int payload) {
|
||||
int BitRate = 768;
|
||||
int FrameRate = 10;
|
||||
int w = 480;
|
||||
int h = 270;
|
||||
String camerafb = "Front";
|
||||
int c = 1;
|
||||
switch (camerafb) {
|
||||
case "Front":
|
||||
c = 1;
|
||||
break;
|
||||
case "Post":
|
||||
c = 0;
|
||||
break;
|
||||
case "Usb":
|
||||
c = 2;
|
||||
break;
|
||||
}
|
||||
c = 0;
|
||||
logmy.e(callnumber + "--" + server + "--" + rport + "--" + lport);
|
||||
if (engineServer != null) {
|
||||
ShowVideoView(true);
|
||||
/*
|
||||
* 开始视频
|
||||
* @param context
|
||||
* @param server 服务器地址
|
||||
* @param rport 远程端口
|
||||
* @param lport 本地端口
|
||||
* @param payload payload
|
||||
* @param BitRate 带宽
|
||||
* @param FrameRate 帧率
|
||||
* @param w 宽
|
||||
* @param h 高
|
||||
* @param camtype 摄像头前后外置
|
||||
* @param videoHwAcceleration 是否启用硬编
|
||||
* @param recordTx 是否录制远程画面
|
||||
* @param recordRx 是否录制本地画面
|
||||
* @param saveVideoDir 录制画面存放的文件
|
||||
*/
|
||||
engineServer.startVideoStream(this, server, rport, lport, payload, BitRate, FrameRate, w, h, c, true);
|
||||
VIDEOSTATE = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.incall_hangup:
|
||||
SipEngine.getInstance().hangup(callid);
|
||||
if (SipEngine.callPagesConfig.size() == 0) {
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
case R.id.incall_answer:
|
||||
incall_answer.setVisibility(View.GONE);
|
||||
SipEngine.getInstance().answer(callid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ShowVideoView(boolean show) {
|
||||
if (show) {
|
||||
localRenderLayout.setVisibility(View.VISIBLE);
|
||||
remoteRenderLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
localRenderLayout.setVisibility(View.GONE);
|
||||
remoteRenderLayout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
void fullScreen() {
|
||||
int flag = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||
getWindow().getDecorView().setSystemUiVisibility(flag);
|
||||
}
|
||||
|
||||
public void switchCamera() {
|
||||
if (engineServer != null) {
|
||||
engineServer.switchCamera(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user