@@ -15,18 +15,25 @@ import com.tencent.iot.video.device.consts.P2pEventType
1515import com.tencent.iot.video.device.model.AvDataInfo
1616import com.tencent.iot.video.device.model.AvtInitInfo
1717import com.tencent.iot.video.device.model.SysInitInfo
18+ import kotlinx.coroutines.CoroutineScope
1819import kotlinx.coroutines.Dispatchers
20+ import kotlinx.coroutines.cancel
1921import kotlinx.coroutines.launch
2022import org.json.JSONObject
2123
22- private val TAG = IPCActivity ::class .java.simpleName
24+ private val TAG = BaseIPCActivity ::class .java.simpleName
2325
2426abstract class BaseIPCActivity <VB : ViewBinding > : AppCompatActivity (), IvDeviceCallback,
2527 IvAvtCallback {
28+ protected val defaultScope = CoroutineScope (Dispatchers .Default )
2629 protected val productId: String? by lazy { intent.getStringExtra(" productId" ) }
2730 protected val deviceName: String? by lazy { intent.getStringExtra(" deviceName" ) }
2831 protected val deviceKey: String? by lazy { intent.getStringExtra(" deviceKey" ) }
2932 protected val binding by lazy { getViewBinding() }
33+ protected var visitor: Int = 0
34+ protected var channel: Int = 0
35+ protected var videoResType: Int = 0
36+ protected var isOnline = false
3037 private val region = " china"
3138
3239 override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -63,21 +70,27 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
6370 protected abstract fun initView ()
6471
6572 override fun onDestroy () {
66- lifecycleScope.launch(Dispatchers .Default ) {
67- VideoNativeInterface .getInstance().exitIvAvt()
68- VideoNativeInterface .getInstance().exitIvDm()
69- VideoNativeInterface .getInstance().exitIvSys()
70- }
7173 super .onDestroy()
74+ defaultScope.launch(Dispatchers .Default ) {
75+ val exitIvAvt = VideoNativeInterface .getInstance().exitIvAvt()
76+ Log .d(TAG , " exit avt res:$exitIvAvt " )
77+ val exitIvDm = VideoNativeInterface .getInstance().exitIvDm()
78+ Log .d(TAG , " exit dm res:$exitIvDm " )
79+ val exitIvSys = VideoNativeInterface .getInstance().exitIvSys()
80+ Log .d(TAG , " exit sys res:$exitIvSys " )
81+ cancel()
82+ }
7283 }
7384
7485 override fun onOnline (netDateTime : Long ) {
7586 Log .d(TAG , " onOnline netDateTime--->$netDateTime " )
87+ isOnline = true
7688 showToast(" 设备上线" )
7789 }
7890
7991 override fun onOffline (status : Int ) {
8092 Log .d(TAG , " onOffline status--->$status " )
93+ isOnline = false
8194 showToast(" 设备下线" )
8295 }
8396
@@ -86,14 +99,23 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
8699 }
87100
88101 override fun onGetAvEncInfo (visitor : Int , channel : Int , videoResType : Int ): AvDataInfo {
102+ this .visitor = visitor
103+ this .channel = channel
104+ this .videoResType = videoResType
89105 return AvDataInfo .createDefaultAvDataInfo(videoResType)
90106 }
91107
92108 override fun onStartRealPlay (visitor : Int , channel : Int , videoResType : Int ) {
109+ this .visitor = visitor
110+ this .channel = channel
111+ this .videoResType = videoResType
93112 Log .d(TAG , " onStartRealPlay visitor $visitor channel $channel res_type $videoResType " )
94113 }
95114
96115 override fun onStopRealPlay (visitor : Int , channel : Int , videoResType : Int ) {
116+ this .visitor = visitor
117+ this .channel = channel
118+ this .videoResType = videoResType
97119 Log .d(TAG , " onStopRealPlay visitor $visitor channel $channel res_type $videoResType " )
98120 }
99121
@@ -107,6 +129,8 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
107129 sample_rate : Int ,
108130 sample_num : Int
109131 ): Int {
132+ this .visitor = visitor
133+ this .channel = channel
110134 Log .d(TAG , " onStartRecvAudioStream visitor $visitor " )
111135 return 0
112136 }
@@ -119,11 +143,15 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
119143 width : Int ,
120144 frameRate : Int
121145 ): Int {
146+ this .visitor = visitor
147+ this .channel = channel
122148 Log .d(TAG , " onStartRecvVideoStream video stream is not supported in this activity" )
123149 return 0
124150 }
125151
126152 override fun onStopRecvStream (visitor : Int , channel : Int , streamType : Int ): Int {
153+ this .visitor = visitor
154+ this .channel = channel
127155 Log .d(TAG , " onStopRecvStream visitor $visitor stream_type $streamType stopped" )
128156 return 0
129157 }
@@ -136,6 +164,7 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
136164 pts : Long ,
137165 seq : Long
138166 ): Int {
167+ this .visitor = visitor
139168 Log .d(
140169 TAG ,
141170 " onRecvStream visitor $visitor stream_type $streamType data$data len$len pts$pts seq$seq "
@@ -144,6 +173,9 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
144173 }
145174
146175 override fun onNotify (event : Int , visitor : Int , channel : Int , videoResType : Int ) {
176+ this .visitor = visitor
177+ this .channel = channel
178+ this .videoResType = videoResType
147179 Log .w(TAG , " onNotify()" )
148180 var msg = " "
149181 when (event) {
@@ -175,6 +207,9 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
175207 videoResType : Int ,
176208 args : String?
177209 ): String {
210+ this .visitor = visitor
211+ this .channel = channel
212+ this .videoResType = videoResType
178213 Log .d(
179214 TAG ,
180215 " onRecvCommand command $command visitor $visitor channel$channel videoResType$videoResType args$args "
@@ -293,17 +328,22 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
293328 }
294329
295330 override fun onDownloadFile (status : Int , visitor : Int , channel : Int ): Int {
331+ this .visitor = visitor
332+ this .channel = channel
296333 Log .d(TAG , " onDownloadFile status $status visitor $visitor channel$channel " )
297334 return 0
298335 }
299336
300337 override fun onGetPeerOuterNet (visitor : Int , channel : Int , netInfo : String? ) {
338+ this .visitor = visitor
339+ this .channel = channel
301340 Log .d(TAG , " onGetPeerOuterNet visitor $visitor channel $channel netInfo$netInfo " )
302341 }
303342
304- private fun showToast (msg : String ) {
343+ fun showToast (msg : String ) {
344+ Log .d(TAG , " msg:$msg " )
305345 lifecycleScope.launch {
306- Toast .makeText(this @BaseIPCActivity, msg, Toast .LENGTH_SHORT ).show();
346+ Toast .makeText(this @BaseIPCActivity.applicationContext , msg, Toast .LENGTH_SHORT ).show();
307347 }
308348 }
309349}
0 commit comments