Skip to content

Commit 81ac706

Browse files
committed
Merge remote-tracking branch 'origin/new_mian' into new_mian
2 parents 4beacdd + f7ce197 commit 81ac706

16 files changed

+4511
-36
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ dependencies {
7979
implementation libs.androidx.core.ktx
8080
implementation libs.kotlinx.coroutines.android
8181
implementation libs.gson
82-
implementation 'com.tencent.iot.video:video-device-android:1.0.8'
82+
implementation 'com.tencent.iot.video:video-device-android:1.0.9.01-SNAPSHOT'
8383
}

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

Lines changed: 40 additions & 13 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
}
@@ -195,7 +222,7 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
195222
this.visitor = visitor
196223
this.channel = channel
197224
this.videoResType = videoResType
198-
Log.w(TAG, "onNotify()")
225+
Log.w(TAG, "onNotify() called with event = $event, visitor = $visitor, channel = $channel, videoResType = $videoResType")
199226
var msg = ""
200227
when (event) {
201228
P2pEventType.IV_AVT_EVENT_P2P_PEER_CONNECT_FAIL, P2pEventType.IV_AVT_EVENT_P2P_PEER_ERROR -> {

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ import com.example.ivdemo.adapter.UserListAdapter
1313
import com.tencent.iot.twcall.R
1414
import com.tencent.iot.twcall.databinding.ActivityTweCallBinding
1515
import com.tencent.iot.video.device.VideoNativeInterface
16+
import com.tencent.iot.video.device.annotations.AudioEncType
1617
import com.tencent.iot.video.device.annotations.CallType
1718
import com.tencent.iot.video.device.annotations.PixelType
1819
import com.tencent.iot.video.device.annotations.StreamType
20+
import com.tencent.iot.video.device.annotations.VideoEncType
1921
import com.tencent.iot.video.device.annotations.VoipActivateType
22+
import com.tencent.iot.video.device.annotations.VoipRecvVFpsType
23+
import com.tencent.iot.video.device.annotations.VoipRecvVRotateType
2024
import com.tencent.iot.video.device.callback.IvVoipCallback
2125
import com.tencent.iot.video.device.model.AvDataInfo
26+
import com.tencent.iot.video.device.model.VoipVideoInfo
2227
import com.tencent.iotvideo.link.CameraRecorder
2328
import com.tencent.iotvideo.link.SimplePlayer
2429
import com.tencent.iotvideo.link.entity.UserEntity
@@ -33,6 +38,7 @@ private const val DATA_PATH = "/storage/emulated/0/"
3338

3439
class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallback {
3540

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

3844
private var condition1 = false
@@ -120,7 +126,6 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
120126

121127
override fun initView() {
122128
cameraRecorder.init(this)
123-
cameraRecorder.isSaveRecord(true)
124129
with(binding) {
125130
titleLayout.tvTitle.text = getString(R.string.title_tweCall)
126131
titleLayout.ivRightBtn.isVisible = true
@@ -199,7 +204,7 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
199204
} else {
200205
showToast("twecall初始化成功")
201206
val activeDeviceInfo = VideoNativeInterface.getInstance().voipActiveDeviceInfoV2
202-
if (activeDeviceInfo == null || activeDeviceInfo.expireTime < System.currentTimeMillis()/1000) {
207+
if (activeDeviceInfo == null || activeDeviceInfo.expireTime < System.currentTimeMillis() / 1000) {
203208
val activateRes = VideoNativeInterface.getInstance()
204209
.activateVoipLicenseV2(VoipActivateType.VOIP_ACT_IPC)
205210
if (activateRes == 0) {
@@ -280,9 +285,17 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
280285
if (isVideo) QualitySetting.getInstance(this@TweCallActivity).isWxCameraOn else true
281286
val callType =
282287
if (isVideo) CallType.IV_CM_STREAM_TYPE_VIDEO else CallType.IV_CM_STREAM_TYPE_AUDIO
288+
val videoInfo = VoipVideoInfo(
289+
VideoEncType.IV_CM_VENC_TYPE_H264,
290+
VideoEncType.IV_CM_VENC_TYPE_H264,
291+
recvPixel,
292+
AudioEncType.IV_CM_AENC_TYPE_AAC,
293+
VoipRecvVFpsType.VOIP_RECV_V_FPS_MAX,
294+
VoipRecvVRotateType.VOIP_RECV_V_ROTATE_NONE
295+
)
283296
val res = VideoNativeInterface.getInstance().doWxCloudVoipCall(
284297
modelId, wxaAppId, openId, deviceId,
285-
callType, recvPixel, true, calleeCameraSwitch
298+
callType, videoInfo, true, calleeCameraSwitch
286299
)
287300
val result = when (res) {
288301
-2 -> "通话中"
@@ -310,8 +323,16 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
310323
if (isVideo) QualitySetting.getInstance(this@TweCallActivity).isWxCameraOn else true
311324
val callType =
312325
if (isVideo) CallType.IV_CM_STREAM_TYPE_VIDEO else CallType.IV_CM_STREAM_TYPE_AUDIO
326+
val videoInfo = VoipVideoInfo(
327+
VideoEncType.IV_CM_VENC_TYPE_H264,
328+
VideoEncType.IV_CM_VENC_TYPE_H264,
329+
recvPixel,
330+
AudioEncType.IV_CM_AENC_TYPE_AAC,
331+
VoipRecvVFpsType.VOIP_RECV_V_FPS_MAX,
332+
VoipRecvVRotateType.VOIP_RECV_V_ROTATE_NONE
333+
)
313334
val res = VideoNativeInterface.getInstance()
314-
.doWxCloudVoipCallV2(openId, callType, recvPixel, true, calleeCameraSwitch)
335+
.doWxCloudVoipCallV2(openId, callType, videoInfo, true, calleeCameraSwitch)
315336
val result = when (res) {
316337
-2 -> "通话中"
317338
0 -> "呼叫成功"
@@ -372,8 +393,10 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
372393
Log.d(TAG, "destory")
373394
checkDefaultThreadActiveAndExecuteTask {
374395
// VideoNativeInterface.getInstance().exitWxCloudVoip()
375-
VideoNativeInterface.getInstance().exitWxCloudVoipV2()
376-
Log.d(TAG, "exit twecall v2")
396+
if (initStatus == 0) {
397+
VideoNativeInterface.getInstance().exitWxCloudVoipV2()
398+
Log.d(TAG, "exit twecall v2")
399+
}
377400
}
378401
super.onDestroy()
379402
}

app/src/main/java/com/example/ivdemo/popup/CustomCommandDialog.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.ivdemo.popup
22

33
import android.content.Context
4+
import android.util.Log
45
import android.widget.Toast
56
import androidx.fragment.app.FragmentManager
67
import androidx.lifecycle.lifecycleScope
@@ -43,7 +44,11 @@ class CustomCommandDialog(context: Context, private val visitor: Int) :
4344
}
4445

4546
fun receiveCommand(msg: String): JSONObject {
46-
binding.tvResult.append("接受信令 ==> $msg\n\n")
47+
Log.d("IPCActivity","receiveCommand msg:$msg")
48+
49+
lifecycleScope.launch {
50+
binding.tvResult.append("接受信令 ==> $msg\n\n")
51+
}
4752
var replyMsg = binding.tvCommand.text.toString()
4853
if (replyMsg.isEmpty()) {
4954
showToast("回复信令内容不能为空,已取默认值success")
@@ -57,7 +62,10 @@ class CustomCommandDialog(context: Context, private val visitor: Int) :
5762
} catch (e: JSONException) {
5863
e.printStackTrace()
5964
}
60-
binding.tvResult.append("回复信令 ==> $resJson\n\n")
65+
lifecycleScope.launch {
66+
binding.tvResult.append("回复信令 ==> $resJson\n\n")
67+
}
68+
Log.d("IPCActivity","receiveCommand returnJson:$resJson")
6169
return resJson
6270
}
6371

app/src/main/java/com/example/ivdemo/popup/DeviceSettingDialog.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.example.ivdemo.popup
22

3+
import android.content.ClipboardManager
34
import android.content.Context
45
import android.text.Editable
56
import android.text.TextWatcher
67
import android.view.View
78
import android.widget.RadioButton
89
import android.widget.Toast
10+
import androidx.core.content.ContextCompat
911
import androidx.fragment.app.FragmentManager
1012
import com.tencent.iot.twcall.databinding.PopupDeviceSettingLayoutBinding
13+
import com.tencent.iotvideo.link.entity.UserEntity
1114
import com.tencent.iotvideo.link.util.DeviceSetting
1215
import com.tencent.iotvideo.link.util.updateOperate
1316

@@ -16,6 +19,9 @@ class DeviceSettingDialog(private val context: Context) :
1619

1720
private val deviceSetting by lazy { DeviceSetting.getInstance(context) }
1821
private var ipcType: Int = 2
22+
private var wxAppId: String? = null
23+
private var modelId: String? = null
24+
private var openId: String? = null
1925
private val textWatcher = object : TextWatcher {
2026
override fun beforeTextChanged(
2127
s: CharSequence?,
@@ -57,6 +63,23 @@ class DeviceSettingDialog(private val context: Context) :
5763
rgSelectWay.setOnCheckedChangeListener { group, checkedId ->
5864
ipcType = group.findViewById<RadioButton>(checkedId).tag.toString().toInt()
5965
}
66+
btnPaste.setOnClickListener {
67+
val clipboard =
68+
ContextCompat.getSystemService(context, ClipboardManager::class.java);
69+
if (clipboard != null && clipboard.hasPrimaryClip()) {
70+
clipboard.primaryClip?.getItemAt(0)?.text.toString().split("\n")
71+
.forEachIndexed { index, s ->
72+
when (index) {
73+
0 -> binding.etLoginProductId.setText(s)
74+
1 -> binding.etLoginDeviceName.setText(s)
75+
2 -> binding.etLoginDeviceKey.setText(s)
76+
3 -> wxAppId = s
77+
4 -> modelId = s
78+
5 -> openId = s
79+
}
80+
}
81+
}
82+
}
6083

6184
btnConfirm.setOnClickListener(View.OnClickListener {
6285
if (!checkDeviceInfo()) {
@@ -83,6 +106,15 @@ class DeviceSettingDialog(private val context: Context) :
83106
deviceSetting.productId = etLoginProductId.text.toString()
84107
deviceSetting.deviceName = etLoginDeviceName.text.toString()
85108
deviceSetting.deviceKey = etLoginDeviceKey.text.toString()
109+
wxAppId?.let {
110+
deviceSetting.appId = it
111+
}
112+
modelId?.let {
113+
deviceSetting.modelId = it
114+
}
115+
openId?.let {
116+
deviceSetting.addOnlyEntity(UserEntity(openId, false))
117+
}
86118
}
87119
}
88120

0 commit comments

Comments
 (0)