2020-09-10 22:38:32 +08:00
|
|
|
|
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;
|
2020-09-11 22:59:19 +08:00
|
|
|
|
import android.view.ViewGroup;
|
2020-09-10 22:38:32 +08:00
|
|
|
|
import android.widget.Button;
|
|
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
2020-09-11 22:59:19 +08:00
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
import androidx.viewpager.widget.PagerAdapter;
|
|
|
|
|
|
import androidx.viewpager.widget.ViewPager;
|
|
|
|
|
|
|
|
|
|
|
|
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
|
|
|
|
|
|
import com.qmuiteam.qmui.widget.tab.QMUITabBuilder;
|
|
|
|
|
|
import com.qmuiteam.qmui.widget.tab.QMUITabIndicator;
|
|
|
|
|
|
import com.qmuiteam.qmui.widget.tab.QMUITabSegment;
|
2020-09-10 22:38:32 +08:00
|
|
|
|
import com.tianrun.sipcall.R;
|
|
|
|
|
|
import com.tianrun.sipcall.SipEngine;
|
2020-09-11 22:59:19 +08:00
|
|
|
|
import com.tianrun.sipcall.db.DBGroup;
|
|
|
|
|
|
import com.tianrun.sipcall.db.DBUser;
|
|
|
|
|
|
import com.tianrun.sipcall.net.Net;
|
2020-09-10 22:38:32 +08:00
|
|
|
|
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 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;
|
2020-09-11 22:59:19 +08:00
|
|
|
|
QMUITabSegment mTabSegment;
|
|
|
|
|
|
ViewPager mContentViewPager;
|
2020-09-10 22:38:32 +08:00
|
|
|
|
|
|
|
|
|
|
private EngineServer engineServer;
|
|
|
|
|
|
|
|
|
|
|
|
private int callid = -1;//当前通话的id
|
|
|
|
|
|
private String callnumber = "未知";
|
|
|
|
|
|
private String callstate = "未知";
|
|
|
|
|
|
private int calltype = 0; //0音频1视频
|
2021-04-20 22:05:07 +08:00
|
|
|
|
private boolean selfCall = false;
|
2020-09-10 22:38:32 +08:00
|
|
|
|
private boolean VIDEOSTATE = false;
|
|
|
|
|
|
public static Intent incallIntent;
|
|
|
|
|
|
|
2020-09-11 22:59:19 +08:00
|
|
|
|
public String[] screenTyps = {"经典模式", "均分模式", "远程全屏", "本地全屏"};
|
|
|
|
|
|
|
|
|
|
|
|
private PagerAdapter mPagerAdapter = new PagerAdapter() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean isViewFromObject(View view, Object object) {
|
|
|
|
|
|
return view == object;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public int getCount() {
|
|
|
|
|
|
return screenTyps.length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Object instantiateItem(final ViewGroup container, int position) {
|
|
|
|
|
|
// ContentPage page = ContentPage.getPage(position);
|
|
|
|
|
|
View view = remoteRender;
|
|
|
|
|
|
// view.setTag(page);
|
|
|
|
|
|
// ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
|
|
|
|
|
|
// ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
|
|
|
// container.addView(view, params);
|
|
|
|
|
|
return view;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void destroyItem(ViewGroup container, int position, Object object) {
|
|
|
|
|
|
container.removeView((View) object);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public int getItemPosition(@NonNull Object object) {
|
|
|
|
|
|
View view = (View) object;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-09-10 22:38:32 +08:00
|
|
|
|
@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());
|
2020-09-11 22:59:19 +08:00
|
|
|
|
initTabAndPager();
|
2020-09-10 22:38:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2020-09-11 22:59:19 +08:00
|
|
|
|
mTabSegment = findViewById(R.id.ScreenType);
|
|
|
|
|
|
mContentViewPager = findViewById(R.id.contentViewPager);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initTabAndPager() {
|
|
|
|
|
|
mContentViewPager.setAdapter(mPagerAdapter);
|
|
|
|
|
|
mContentViewPager.setCurrentItem(0, false);
|
|
|
|
|
|
QMUITabBuilder tabBuilder = mTabSegment.tabBuilder();
|
|
|
|
|
|
for (int i = 0; i < screenTyps.length; i++) {
|
|
|
|
|
|
mTabSegment.addTab(tabBuilder.setText(screenTyps[i]).build(this));
|
|
|
|
|
|
}
|
|
|
|
|
|
int space = QMUIDisplayHelper.dp2px(this, 16);
|
|
|
|
|
|
mTabSegment.setIndicator(new QMUITabIndicator(
|
|
|
|
|
|
QMUIDisplayHelper.dp2px(this, 2), false, true));
|
|
|
|
|
|
mTabSegment.setMode(QMUITabSegment.MODE_SCROLLABLE);
|
|
|
|
|
|
mTabSegment.setItemSpaceInScrollMode(space);
|
|
|
|
|
|
mTabSegment.setupWithViewPager(mContentViewPager, false);
|
|
|
|
|
|
mTabSegment.setPadding(space, 0, space, 0);
|
|
|
|
|
|
mTabSegment.addOnTabSelectedListener(new QMUITabSegment.OnTabSelectedListener() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onTabSelected(int index) {
|
|
|
|
|
|
engineServer.adjustVideoView(index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onTabUnselected(int index) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onTabReselected(int index) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onDoubleTap(int index) {
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2020-09-10 22:38:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@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);
|
2021-04-20 22:05:07 +08:00
|
|
|
|
if (incall_answer.getVisibility() == View.VISIBLE && selfCall) {
|
2020-09-10 22:38:32 +08:00
|
|
|
|
incall_answer.setVisibility(View.GONE);
|
|
|
|
|
|
SipEngine.getInstance().answer(callid);
|
2021-04-29 09:19:35 +08:00
|
|
|
|
SipEngine.getInstance().StopdefaultCallMediaPlayer(this);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SipEngine.getInstance().PlaydefaultCallMediaPlayer(this);
|
2020-09-10 22:38:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@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");
|
2021-04-20 22:05:07 +08:00
|
|
|
|
selfCall = bundle.getBoolean("selfCall");
|
2020-09-10 22:38:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 停止视频
|
|
|
|
|
|
*
|
|
|
|
|
|
* @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) {
|
2020-09-28 17:07:11 +08:00
|
|
|
|
case CONS.ONGETCALLID:
|
|
|
|
|
|
callid = (int)m.obj;
|
|
|
|
|
|
break;
|
2020-09-10 22:38:32 +08:00
|
|
|
|
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);
|
2021-04-29 09:19:35 +08:00
|
|
|
|
SipEngine.getInstance().StopdefaultCallMediaPlayer(this);
|
2020-09-10 22:38:32 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|