Skip to content

Commit a4d9bfd

Browse files
committed
增加信令发送、事件上报和告警
1 parent 5d9a806 commit a4d9bfd

File tree

11 files changed

+295
-20
lines changed

11 files changed

+295
-20
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
minSdkVersion 23
1515
targetSdkVersion 29
1616
versionCode 1
17-
versionName "1.0"
17+
versionName "1.1.0"
1818

1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2020
}
@@ -59,5 +59,5 @@ dependencies {
5959
implementation libs.kotlinx.coroutines.android
6060
implementation libs.mmkv
6161
implementation libs.gson
62-
implementation 'com.tencent.iot.video:video-device-android:1.0.6.02-SNAPSHOT'
62+
implementation 'com.tencent.iot.video:video-device-android:1.0.6.03-SNAPSHOT'
6363
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
3030
protected val deviceName: String? by lazy { intent.getStringExtra("deviceName") }
3131
protected val deviceKey: String? by lazy { intent.getStringExtra("deviceKey") }
3232
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
3337
private val region = "china"
3438

3539
override fun onCreate(savedInstanceState: Bundle?) {
@@ -80,11 +84,13 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
8084

8185
override fun onOnline(netDateTime: Long) {
8286
Log.d(TAG, "onOnline netDateTime--->$netDateTime")
87+
isOnline = true
8388
showToast("设备上线")
8489
}
8590

8691
override fun onOffline(status: Int) {
8792
Log.d(TAG, "onOffline status--->$status")
93+
isOnline = false
8894
showToast("设备下线")
8995
}
9096

@@ -93,14 +99,23 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
9399
}
94100

95101
override fun onGetAvEncInfo(visitor: Int, channel: Int, videoResType: Int): AvDataInfo {
102+
this.visitor = visitor
103+
this.channel = channel
104+
this.videoResType = videoResType
96105
return AvDataInfo.createDefaultAvDataInfo(videoResType)
97106
}
98107

99108
override fun onStartRealPlay(visitor: Int, channel: Int, videoResType: Int) {
109+
this.visitor = visitor
110+
this.channel = channel
111+
this.videoResType = videoResType
100112
Log.d(TAG, "onStartRealPlay visitor $visitor channel $channel res_type $videoResType")
101113
}
102114

103115
override fun onStopRealPlay(visitor: Int, channel: Int, videoResType: Int) {
116+
this.visitor = visitor
117+
this.channel = channel
118+
this.videoResType = videoResType
104119
Log.d(TAG, "onStopRealPlay visitor $visitor channel $channel res_type $videoResType")
105120
}
106121

@@ -114,6 +129,8 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
114129
sample_rate: Int,
115130
sample_num: Int
116131
): Int {
132+
this.visitor = visitor
133+
this.channel = channel
117134
Log.d(TAG, "onStartRecvAudioStream visitor $visitor")
118135
return 0
119136
}
@@ -126,11 +143,15 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
126143
width: Int,
127144
frameRate: Int
128145
): Int {
146+
this.visitor = visitor
147+
this.channel = channel
129148
Log.d(TAG, "onStartRecvVideoStream video stream is not supported in this activity")
130149
return 0
131150
}
132151

133152
override fun onStopRecvStream(visitor: Int, channel: Int, streamType: Int): Int {
153+
this.visitor = visitor
154+
this.channel = channel
134155
Log.d(TAG, "onStopRecvStream visitor $visitor stream_type $streamType stopped")
135156
return 0
136157
}
@@ -143,6 +164,7 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
143164
pts: Long,
144165
seq: Long
145166
): Int {
167+
this.visitor = visitor
146168
Log.d(
147169
TAG,
148170
"onRecvStream visitor $visitor stream_type $streamType data$data len$len pts$pts seq$seq"
@@ -151,6 +173,9 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
151173
}
152174

153175
override fun onNotify(event: Int, visitor: Int, channel: Int, videoResType: Int) {
176+
this.visitor = visitor
177+
this.channel = channel
178+
this.videoResType = videoResType
154179
Log.w(TAG, "onNotify()")
155180
var msg = ""
156181
when (event) {
@@ -182,6 +207,9 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
182207
videoResType: Int,
183208
args: String?
184209
): String {
210+
this.visitor = visitor
211+
this.channel = channel
212+
this.videoResType = videoResType
185213
Log.d(
186214
TAG,
187215
"onRecvCommand command $command visitor $visitor channel$channel videoResType$videoResType args$args"
@@ -300,11 +328,15 @@ abstract class BaseIPCActivity<VB : ViewBinding> : AppCompatActivity(), IvDevice
300328
}
301329

302330
override fun onDownloadFile(status: Int, visitor: Int, channel: Int): Int {
331+
this.visitor = visitor
332+
this.channel = channel
303333
Log.d(TAG, "onDownloadFile status $status visitor $visitor channel$channel")
304334
return 0
305335
}
306336

307337
override fun onGetPeerOuterNet(visitor: Int, channel: Int, netInfo: String?) {
338+
this.visitor = visitor
339+
this.channel = channel
308340
Log.d(TAG, "onGetPeerOuterNet visitor $visitor channel $channel netInfo$netInfo")
309341
}
310342

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.example.ivdemo.popup.QualitySettingDialog
1515
import com.tencent.iot.twcall.R
1616
import com.tencent.iot.twcall.databinding.ActivityDuplexVideoBinding
1717
import com.tencent.iot.video.device.VideoNativeInterface
18+
import com.tencent.iot.video.device.annotations.CsChannelType
1819
import com.tencent.iot.video.device.annotations.StreamType
1920
import com.tencent.iot.video.device.model.AvDataInfo
2021
import com.tencent.iotvideo.link.CameraRecorder
@@ -107,7 +108,7 @@ class DuplexVideoActivity : BaseIPCActivity<ActivityDuplexVideoBinding>() {
107108
showToast("P2PInfo 已更新")
108109
}
109110
binding.tvP2pInfo.text = String.format(getString(R.string.text_p2p_info), p2pInfo)
110-
handler.postDelayed(taskRunnable, UPDATE_P2P_INFO_TOKEN, 60000)
111+
handler.postDelayed(taskRunnable, UPDATE_P2P_INFO_TOKEN, 10000)
111112
}
112113

113114
@RequiresApi(Build.VERSION_CODES.P)

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

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
package com.example.ivdemo
22

3+
import android.graphics.Bitmap
4+
import android.graphics.Canvas
35
import android.graphics.SurfaceTexture
6+
import android.graphics.drawable.BitmapDrawable
7+
import android.graphics.drawable.Drawable
48
import android.os.Build
59
import android.os.Handler
610
import android.os.Looper
711
import android.util.Log
812
import android.view.TextureView
9-
import android.widget.Toast
1013
import androidx.annotation.RequiresApi
14+
import androidx.core.content.ContextCompat
1115
import androidx.core.view.isVisible
1216
import androidx.lifecycle.lifecycleScope
17+
import com.example.ivdemo.popup.CustomCommandDialog
1318
import com.example.ivdemo.popup.QualitySettingDialog
1419
import com.tencent.iot.twcall.R
1520
import com.tencent.iot.twcall.databinding.ActivityIpcBinding
1621
import com.tencent.iot.video.device.VideoNativeInterface
1722
import com.tencent.iot.video.device.annotations.CsChannelType
1823
import com.tencent.iot.video.device.annotations.StreamType
1924
import com.tencent.iot.video.device.model.AvDataInfo
20-
import com.tencent.iot.video.device.model.CsBalanceInfo
2125
import com.tencent.iotvideo.link.CameraRecorder
2226
import com.tencent.iotvideo.link.SimplePlayer
2327
import com.tencent.iotvideo.link.util.copyTextToClipboard
2428
import kotlinx.coroutines.Dispatchers
2529
import kotlinx.coroutines.launch
30+
import java.io.ByteArrayOutputStream
2631

2732
class IPCActivity : BaseIPCActivity<ActivityIpcBinding>() {
2833

@@ -32,6 +37,7 @@ class IPCActivity : BaseIPCActivity<ActivityIpcBinding>() {
3237
private var localPreviewSurface: SurfaceTexture? = null
3338
private val handler = Handler(Looper.getMainLooper())
3439
private val UPDATE_P2P_INFO_TOKEN = "update_p2p_info_token"
40+
private var customCommandDialog: CustomCommandDialog? = null
3541

3642
private val listener = object : TextureView.SurfaceTextureListener {
3743
override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) {
@@ -85,6 +91,38 @@ class IPCActivity : BaseIPCActivity<ActivityIpcBinding>() {
8591
tvCopy.setOnClickListener {
8692
copyTextToClipboard(this@IPCActivity, tvP2pInfo.text.toString().substringAfter(":"))
8793
}
94+
btnCloudStorageReport.setOnClickListener {
95+
if (!isOnline) {
96+
showToast("设备未上线")
97+
return@setOnClickListener
98+
}
99+
VideoNativeInterface.getInstance()
100+
.startCsEvent(CsChannelType.CS_SINGLE_CH, 1, "report test cs info")
101+
}
102+
btnCloudWareReport.setOnClickListener {
103+
if (!isOnline) {
104+
showToast("设备未上线")
105+
return@setOnClickListener
106+
}
107+
val drawable = ContextCompat.getDrawable(this@IPCActivity, R.drawable.mom)
108+
drawable?.let {
109+
VideoNativeInterface.getInstance().reportCsEventDirectly(
110+
CsChannelType.CS_SINGLE_CH,
111+
1,
112+
"report test cs info",
113+
0,
114+
bitmapToByteArray(drawableToBitmap(it))
115+
)
116+
}
117+
}
118+
btnCustomCommand.setOnClickListener {
119+
if (!isOnline) {
120+
showToast("设备未上线")
121+
return@setOnClickListener
122+
}
123+
customCommandDialog = CustomCommandDialog(this@IPCActivity, visitor)
124+
customCommandDialog?.show(supportFragmentManager)
125+
}
88126
// btnIpcCall.setOnClickListener {
89127
// val time = System.currentTimeMillis()
90128
// val timeD = time - lastClickTime
@@ -107,12 +145,28 @@ class IPCActivity : BaseIPCActivity<ActivityIpcBinding>() {
107145
showToast("P2PInfo 已更新")
108146
}
109147
binding.tvP2pInfo.text = String.format(getString(R.string.text_p2p_info), p2pInfo)
110-
handler.postDelayed(taskRunnable, UPDATE_P2P_INFO_TOKEN, 60000)
148+
handler.postDelayed(taskRunnable, UPDATE_P2P_INFO_TOKEN, 10000)
149+
}
150+
151+
private var shouldGetCs = true
152+
private fun updateCsState() {
153+
if (shouldGetCs) {
154+
val info =
155+
VideoNativeInterface.getInstance().getCsBalanceInfo(CsChannelType.CS_SINGLE_CH, 10)
156+
if (info != null) {
157+
shouldGetCs = false
158+
binding.tvCloudStorageState.text = String.format(
159+
getString(R.string.text_cloud_storage_state),
160+
if (info.csSwitch) "已开通" else "未开通"
161+
)
162+
}
163+
}
111164
}
112165

113166
@RequiresApi(Build.VERSION_CODES.P)
114167
private val taskRunnable = Runnable {
115168
updateP2pInfo()
169+
updateCsState()
116170
}
117171

118172
override fun onDestroy() {
@@ -125,14 +179,7 @@ class IPCActivity : BaseIPCActivity<ActivityIpcBinding>() {
125179
super.onOnline(netDateTime)
126180
lifecycleScope.launch(Dispatchers.Main) {
127181
updateP2pInfo()
128-
val info = VideoNativeInterface.getInstance()
129-
.getCsBalanceInfo(CsChannelType.CS_MULTI_CH1, 1000)
130182
handler.postDelayed(taskRunnable, UPDATE_P2P_INFO_TOKEN, 60000)
131-
Log.d(
132-
"hhh",
133-
"info:${info.csDays} ${info.csType} ${info.csSwitch} ${info.freeTrialRemainingSec}"
134-
)
135-
// binding.tvCloudStorageState.text =info.
136183
}
137184
}
138185

@@ -196,4 +243,35 @@ class IPCActivity : BaseIPCActivity<ActivityIpcBinding>() {
196243
}
197244
return 0
198245
}
246+
247+
override fun onRecvCommand(
248+
command: Int,
249+
visitor: Int,
250+
channel: Int,
251+
videoResType: Int,
252+
args: String?
253+
): String {
254+
return customCommandDialog?.receiveCommand(args ?: "null").toString()
255+
}
256+
257+
private fun drawableToBitmap(drawable: Drawable): Bitmap {
258+
if (drawable is BitmapDrawable) {
259+
return drawable.bitmap
260+
}
261+
262+
val width = drawable.intrinsicWidth
263+
val height = drawable.intrinsicHeight
264+
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
265+
val canvas = Canvas(bitmap)
266+
drawable.setBounds(0, 0, canvas.width, canvas.height)
267+
drawable.draw(canvas)
268+
return bitmap
269+
}
270+
271+
// 将Bitmap转换为byte数组
272+
private fun bitmapToByteArray(bitmap: Bitmap): ByteArray {
273+
val stream = ByteArrayOutputStream()
274+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
275+
return stream.toByteArray()
276+
}
199277
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import java.io.IOException
2121

2222
class OTAUpgradeActivity : BaseIPCActivity<ActivityOtaUpgradeBinding>(), IvOTACallback {
2323

24-
private var isOnline = false
2524
private var newFirmwareSize: Int = 0
2625
private var isUpgrade = false
2726

@@ -89,13 +88,11 @@ class OTAUpgradeActivity : BaseIPCActivity<ActivityOtaUpgradeBinding>(), IvOTACa
8988
super.onOnline(netDateTime)
9089
updateState(getString(R.string.text_ota_check))
9190
checkForNewFirmware()
92-
isOnline = true
9391
binding.btnExitOta.updateOperate(true)
9492
}
9593

9694
override fun onOffline(status: Int) {
9795
super.onOffline(status)
98-
isOnline = false
9996
}
10097

10198
override fun onFirmwareUpdate(firmwareName: String, firmwareLen: Int) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
4141
private var condition2 = false
4242
private val lock = Any()
4343

44-
private var visitor = 0
4544
private var type = 0
4645
private var height = 0
4746
private var width = 0
@@ -413,7 +412,6 @@ class TweCallActivity : BaseIPCActivity<ActivityTweCallBinding>(), IvVoipCallbac
413412
): Int {
414413
Log.d(TAG, "start video visitor $visitor h: $height w: $width")
415414
lifecycleScope.launch { updateVideoUI(true) }
416-
this.visitor = visitor
417415
this.type = type
418416
this.height = height
419417
this.width = width

0 commit comments

Comments
 (0)