Skip to content

Commit b2cd710

Browse files
committed
修复退出崩溃逻辑问题
1 parent 8e0f48e commit b2cd710

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

app/src/main/java/com/example/ivdemo/BaseIPCActivity.kt

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
4040
private val region = "china"
4141
private val isUserCongestionCtrl = true
4242

43+
@Volatile
44+
protected var sysInitResCode = -1
45+
46+
@Volatile
47+
protected var dmInitResCode = -1
48+
49+
@Volatile
50+
protected var avtInitResCode = -1
51+
4352
override fun onCreate(savedInstanceState: Bundle?) {
4453
super.onCreate(savedInstanceState)
4554
if (!checkPerformCreate()) return
@@ -63,10 +72,18 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
6372
// start run JNI iot_video_demo
6473
checkDefaultThreadActiveAndExecuteTask {
6574
val sysInitInfo = SysInitInfo(productId, deviceName, deviceKey, region)
66-
val sysInit = VideoNativeInterface.getInstance().initIvSystem(sysInitInfo, this)
67-
Log.d(TAG, "initIvSystem,resCode:$sysInit")
68-
val dmInit = VideoNativeInterface.getInstance().initIvDm()
69-
Log.d(TAG, "initIvDm,resCode:$dmInit")
75+
sysInitResCode = VideoNativeInterface.getInstance().initIvSystem(sysInitInfo, this)
76+
Log.d(TAG, "initIvSystem,resCode:$sysInitResCode")
77+
if (sysInitResCode != 0) {
78+
showToast("initIvSystem fail,resCode:$sysInitResCode")
79+
return@checkDefaultThreadActiveAndExecuteTask
80+
}
81+
dmInitResCode = VideoNativeInterface.getInstance().initIvDm()
82+
Log.d(TAG, "initIvDm,resCode:$dmInitResCode")
83+
if (dmInitResCode != 0) {
84+
showToast("initIvDm fail,resCode:$dmInitResCode")
85+
return@checkDefaultThreadActiveAndExecuteTask
86+
}
7087
val congestion = CongestionCtrlInfo()
7188
if (isUserCongestionCtrl) { //启用水位告警以及告警的有高中低三挡水位值,当 p2p 内部缓存的水位到达这个值的时候会收到 onNotify回调
7289
congestion.lowMark = 200 * 1024
@@ -79,8 +96,12 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
7996
}
8097
val avtInitInfo = AvtInitInfo()
8198
avtInitInfo.congestion = congestion
82-
val avtInit = VideoNativeInterface.getInstance().initIvAvt(avtInitInfo, this)
83-
Log.d(TAG, "initIvAvt,resCode:$avtInit")
99+
avtInitResCode = VideoNativeInterface.getInstance().initIvAvt(avtInitInfo, this)
100+
Log.d(TAG, "initIvAvt,resCode:$avtInitResCode")
101+
if (avtInitResCode != 0) {
102+
showToast("initIvDm fail,resCode:$avtInitResCode")
103+
return@checkDefaultThreadActiveAndExecuteTask
104+
}
84105
}
85106
}
86107

@@ -91,12 +112,18 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
91112
override fun onDestroy() {
92113
super.onDestroy()
93114
checkDefaultThreadActiveAndExecuteTask {
94-
val exitIvAvt = VideoNativeInterface.getInstance().exitIvAvt()
95-
Log.d(TAG, "exit avt resCode:$exitIvAvt")
96-
val exitIvDm = VideoNativeInterface.getInstance().exitIvDm()
97-
Log.d(TAG, "exit dm resCode:$exitIvDm")
98-
val exitIvSys = VideoNativeInterface.getInstance().exitIvSys()
99-
Log.d(TAG, "exit sys resCode:$exitIvSys")
115+
if (avtInitResCode == 0) {
116+
val exitIvAvt = VideoNativeInterface.getInstance().exitIvAvt()
117+
Log.d(TAG, "exit avt resCode:$exitIvAvt")
118+
}
119+
if (dmInitResCode == 0) {
120+
val exitIvDm = VideoNativeInterface.getInstance().exitIvDm()
121+
Log.d(TAG, "exit dm resCode:$exitIvDm")
122+
}
123+
if (sysInitResCode == 0) {
124+
val exitIvSys = VideoNativeInterface.getInstance().exitIvSys()
125+
Log.d(TAG, "exit sys resCode:$exitIvSys")
126+
}
100127
defaultThread.shutdown()
101128
}
102129
}

app/src/main/java/com/example/ivdemo/TweCallActivity.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private const val DATA_PATH = "/storage/emulated/0/"
3838

3939
class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallback {
4040

41+
@Volatile
4142
private var initStatus = -1 // 未初始化 -1, 初始化成功 0, 其他
4243

4344
private var condition1 = false
@@ -204,7 +205,7 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
204205
} else {
205206
showToast("twecall初始化成功")
206207
val activeDeviceInfo = VideoNativeInterface.getInstance().voipActiveDeviceInfoV2
207-
if (activeDeviceInfo == null || activeDeviceInfo.expireTime < System.currentTimeMillis()/1000) {
208+
if (activeDeviceInfo == null || activeDeviceInfo.expireTime < System.currentTimeMillis() / 1000) {
208209
val activateRes = VideoNativeInterface.getInstance()
209210
.activateVoipLicenseV2(VoipActivateType.VOIP_ACT_IPC)
210211
if (activateRes == 0) {
@@ -393,8 +394,10 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
393394
Log.d(TAG, "destory")
394395
checkDefaultThreadActiveAndExecuteTask {
395396
// VideoNativeInterface.getInstance().exitWxCloudVoip()
396-
VideoNativeInterface.getInstance().exitWxCloudVoipV2()
397-
Log.d(TAG, "exit twecall v2")
397+
if (initStatus == 0) {
398+
VideoNativeInterface.getInstance().exitWxCloudVoipV2()
399+
Log.d(TAG, "exit twecall v2")
400+
}
398401
}
399402
super.onDestroy()
400403
}

0 commit comments

Comments
 (0)