[6.8.0][驾驶位视频流] 优化代码逻辑
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.mogo.eagle.core.function.datacenter.autopilot.telematic
|
||||
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.protobuf.TextFormat
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.commons.utils.MogoAnalyticUtils
|
||||
import com.mogo.eagle.core.data.app.AppConfigInfo
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters
|
||||
import com.mogo.eagle.core.data.autopilot.AutopilotControlParameters.AutoPilotLine
|
||||
@@ -28,8 +31,11 @@ import com.mogo.eagle.core.function.call.och.CallerOchBizFunctionCall4EagleManag
|
||||
import com.mogo.eagle.core.function.call.telematic.CallerTelematicListenerManager
|
||||
import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager
|
||||
import com.mogo.eagle.core.function.call.v2x.CallerTrafficLightListenerManager
|
||||
import com.mogo.eagle.core.utilcode.kotlin.lifeCycleScope
|
||||
import com.mogo.eagle.core.utilcode.kotlin.scope
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.eagle.core.utilcode.util.AppStateManager
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
@@ -41,11 +47,14 @@ import com.zhidao.support.adas.high.AdasManager
|
||||
import com.zhjt.service.chain.ChainLog
|
||||
import io.netty.channel.Channel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import mogo.telematics.pad.MessagePad
|
||||
import mogo.telematics.pad.MessagePad.TrackedObject
|
||||
import java.nio.charset.Charset
|
||||
import java.util.Collections
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class TeleMsgHandler : IMsgHandler {
|
||||
|
||||
@@ -70,6 +79,8 @@ class TeleMsgHandler : IMsgHandler {
|
||||
|
||||
private var listener: EventListener? = null
|
||||
|
||||
private var lastTimeOnReceiveDriveVideo = 0L
|
||||
|
||||
override fun handleMsgFromServer(msg: MogoProtocolMsg?, channel: Channel?) {
|
||||
msg?.let { it ->
|
||||
if (it.protocolType == TelematicConstant.V2N_AI_ROAD_DATA_TO_PASSENGER) {
|
||||
@@ -163,35 +174,96 @@ class TeleMsgHandler : IMsgHandler {
|
||||
val content = String(it.body, Charset.defaultCharset())
|
||||
Log.d(TAG, "乘客屏收到司机屏转发的驾驶位视频流开关 --- 2 ---:$content")
|
||||
val data = GsonUtils.fromJson(content, Map::class.java)
|
||||
val open = data["open"].toString().toInt() == 1
|
||||
val playUrl = data["playUrl"]?.toString()
|
||||
//TODO yangyakun
|
||||
if (open) {
|
||||
if (playUrl != null) {
|
||||
// 1. 获取视频播放控件
|
||||
val target = CallerDevaToolsManager.driveSeatVideoProvider()?.getDriveVideoView(playUrl) { event ->
|
||||
if (data.containsKey("open")) {
|
||||
val open = data["open"].toString().toInt() == 1
|
||||
val playUrl = data["playUrl"]?.toString()
|
||||
MogoAnalyticUtils.track("DriveSeatVideoStream", HashMap<String, Any>().also {
|
||||
it["step"] = 0
|
||||
it["open"] = open
|
||||
it["playUrl"] = playUrl ?: ""
|
||||
})
|
||||
AppStateManager.currentActivity()?.lifeCycleScope?.launchWhenResumed {
|
||||
if (open) {
|
||||
if (playUrl != null) {
|
||||
// 1. 获取视频播放控件
|
||||
val target = CallerDevaToolsManager.driveSeatVideoProvider()?.getDriveVideoView(playUrl) { event ->
|
||||
Log.d(TAG, "event -> $event")
|
||||
MogoAnalyticUtils.track("DriveSeatVideoStream", HashMap<String, Any>().also {
|
||||
it["step"] = 3
|
||||
it["open"] = true
|
||||
it["playUrl"] = playUrl
|
||||
it["event"] = event
|
||||
})
|
||||
}
|
||||
if (target != null) {
|
||||
MogoAnalyticUtils.track("DriveSeatVideoStream", HashMap<String, Any>().also {
|
||||
it["step"] = 1
|
||||
it["open"] = true
|
||||
it["playUrl"] = playUrl
|
||||
})
|
||||
CallerTelematicManager.sendMsgToServer(TelematicConstant.DRIVE_SEAT_VIDEO_STREAM_RSP, "11".toByteArray())
|
||||
} else {
|
||||
MogoAnalyticUtils.track("DriveSeatVideoStream", HashMap<String, Any>().also {
|
||||
it["step"] = 2
|
||||
it["open"] = true
|
||||
it["playUrl"] = playUrl
|
||||
})
|
||||
}
|
||||
if (target != null && !ViewCompat.isAttachedToWindow(target) && (lastTimeOnReceiveDriveVideo == 0L || SystemClock.elapsedRealtime() - lastTimeOnReceiveDriveVideo > TimeUnit.SECONDS.toMillis(10))) {
|
||||
MogoAnalyticUtils.track("DriveSeatVideoStream", HashMap<String, Any>().also {
|
||||
it["step"] = 4
|
||||
it["open"] = true
|
||||
it["playUrl"] = playUrl
|
||||
})
|
||||
CallerDevaToolsManager.driveSeatVideoProvider()?.poller()?.onEach {
|
||||
Log.d(TAG, "--- poller -> $it")
|
||||
if (!it) {
|
||||
// 设备离线了,乘客屏的驾驶位视频控件要移除
|
||||
CallerOchBizFunctionCall4EagleManager.setVideoView(null)
|
||||
}
|
||||
CallerTelematicManager.sendMsgToServer(TelematicConstant.DRIVE_SEAT_VIDEO_STREAM_RSP, if (it) "1".toByteArray() else "0".toByteArray())
|
||||
}?.launchIn(target.scope)
|
||||
|
||||
CallerOchBizFunctionCall4EagleManager.setVideoView(target)
|
||||
lastTimeOnReceiveDriveVideo = SystemClock.elapsedRealtime()
|
||||
}
|
||||
} else {
|
||||
MogoAnalyticUtils.track("DriveSeatVideoStream", HashMap<String, Any>().also {
|
||||
it["step"] = 5
|
||||
it["open"] = true
|
||||
it["playUrl"] = ""
|
||||
})
|
||||
CallerTelematicManager.sendMsgToServer(TelematicConstant.DRIVE_SEAT_VIDEO_STREAM_RSP, "10".toByteArray())
|
||||
}
|
||||
} else {
|
||||
//第1个0代表运营面板开关关闭,第2个1代表关闭成功,告之司机端; 相应的还有状态:00表示关闭失败
|
||||
CallerTelematicManager.sendMsgToServer(TelematicConstant.DRIVE_SEAT_VIDEO_STREAM_RSP, "01".toByteArray())
|
||||
CallerOchBizFunctionCall4EagleManager.setVideoView(null)
|
||||
MogoAnalyticUtils.track("DriveSeatVideoStream", HashMap<String, Any>().also {
|
||||
it["step"] = 6
|
||||
it["open"] = false
|
||||
it["playUrl"] = ""
|
||||
})
|
||||
}
|
||||
|
||||
if (target != null) {
|
||||
// 2. 添加到一个ViewGroup上
|
||||
// 11: 第1个1代表运营面板开关打开,第2个1代表打开成功,告之司机端
|
||||
// 10: 第1个1代表运营面板开关打开,第2个0代表打开成功,告之司机端
|
||||
CallerTelematicManager.sendMsgToServer(TelematicConstant.DRIVE_SEAT_VIDEO_STREAM_RSP, "11".toByteArray())
|
||||
}
|
||||
CallerOchBizFunctionCall4EagleManager.setVideoView(target)
|
||||
|
||||
} else {
|
||||
CallerTelematicManager.sendMsgToServer(TelematicConstant.DRIVE_SEAT_VIDEO_STREAM_RSP, "10".toByteArray())
|
||||
}
|
||||
} else {
|
||||
//第1个0代表运营面板开关关闭,第2个1代表关闭成功,告之司机端; 相应的还有状态:00表示关闭失败
|
||||
CallerTelematicManager.sendMsgToServer(TelematicConstant.DRIVE_SEAT_VIDEO_STREAM_RSP, "01".toByteArray())
|
||||
CallerOchBizFunctionCall4EagleManager.setVideoView(null)
|
||||
} else if (data.containsKey("query")) {
|
||||
val isPlaying = CallerDevaToolsManager.driveSeatVideoProvider()?.isVideoPlaying()
|
||||
MogoAnalyticUtils.track("DriveSeatVideoStream", HashMap<String, Any>().also {
|
||||
it["step"] = 8
|
||||
it["isPlaying"] = isPlaying ?: false
|
||||
})
|
||||
Log.e(TAG, "乘客屏收到司机屏转发的驾驶位视频流开关--- 4 ---: isPlaying -> $isPlaying")
|
||||
CallerTelematicManager.sendMsgToServer(TelematicConstant.DRIVE_SEAT_VIDEO_STREAM_RSP, if (isPlaying == true) "111".toByteArray() else "000".toByteArray())
|
||||
}
|
||||
|
||||
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
Log.e(TAG, "乘客屏收到司机屏转发的驾驶位视频流开关--- 3 ---", t)
|
||||
MogoAnalyticUtils.track("DriveSeatVideoStream", HashMap<String, Any>().also {
|
||||
it["step"] = 7
|
||||
it["error"] = t.message ?: "未知异常"
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user