This commit is contained in:
lixiaopeng
2021-02-23 12:03:08 +08:00
parent 6d4bfc6264
commit e98afe9b6d
6 changed files with 346 additions and 221 deletions

View File

@@ -3,13 +3,19 @@ package com.zhidao.roadcondition.service
import android.text.TextUtils
import android.util.Log
import com.hw.videoprocessor.VideoProcessor
import com.mogo.cloud.network.BaseData
import com.mogo.cloud.tanlu.api.ITanluUploadCallback
import com.mogo.cloud.tanlu.api.MogoUploadManager
import com.mogo.cloud.tanlu.bean.UploadInfo
import com.mogo.cloud.tanlu.bean.UploadResult
import com.mogo.commons.AbsMogoApplication
import com.mogo.commons.debug.DebugConfig
import com.mogo.commons.network.Utils
import com.mogo.utils.NetworkUtils
import com.zhidao.auto.carcorder.callback.TakePhotoCallback
import com.zhidao.auto.carcorder.callback.TakeVideoCallback
import com.zhidao.auto.carcorder.controller.ZdCarCoderController
import com.zhidao.roadcondition.constant.*
import com.zhidao.roadcondition.constant.STRATEGY_UPLOAD_TYPE_ARRAY
import com.zhidao.roadcondition.event.GetImageSuccessEvent
import com.zhidao.roadcondition.event.LatLngStickyEventBus
import com.zhidao.roadcondition.model.proxy.INFO_TYPE_IMG
@@ -127,17 +133,19 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
videoAndThumbMap["video"] = ""
videoAndThumbMap["thumb"] = ""
CosStatusController().sendInformationDirectly(
INFO_TYPE_VIDEO,
videoAndThumbMap,
mType,
entity,
mainInfoId,
mLongitude,
mLatitude,
mSpeed,
mFromType
)
// CosStatusController().sendInformationDirectly(
// INFO_TYPE_VIDEO,
// videoAndThumbMap,
// mType,
// entity,
// mainInfoId,
// mLongitude,
// mLatitude,
// mSpeed,
// mFromType
// )
getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) }
//地图上打点
taskAsync(3_000) {
@@ -168,17 +176,20 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
Log.e(TAG, "onTakePhotoFail -----mType = $mType --- isCustom = $isCustom")
//获取图片失败也上报,图片不打点
if (isCustom) {
CosStatusController().sendInformationDirectly(
INFO_TYPE_IMG,
mutableMapOf("pic" to ""),
mType,
entity,
mainInfoId,
mLongitude,
mLatitude,
mSpeed,
mFromType
)
// CosStatusController().sendInformationDirectly(
// INFO_TYPE_IMG,
// mutableMapOf("pic" to ""),
// mType,
// entity,
// mainInfoId,
// mLongitude,
// mLatitude,
// mSpeed,
// mFromType
// )
getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
}
@@ -219,8 +230,13 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
if (!TextUtils.isEmpty(mType)) {
Log.d(TAG, "onTakePhotoSuccess mType != null")
CosStatusController().uploadFile(mutableListOf(photoPath as String), entity, mType, mainInfoId, mFromType, mLongitude,
mLatitude, mSpeed)
// CosStatusController().uploadFile(mutableListOf(photoPath as String), entity, mType, mainInfoId, mFromType, mLongitude,
// mLatitude, mSpeed)
if (photoPath != null) {
getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
} else {
Log.d(TAG, "onTakePhotoSuccess mType == null")
Log.d(
@@ -230,32 +246,41 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
if (maxSpeedPic == -1) {
if (speed >= (abs(minSpeedPic) / 3.6f)) {
Log.d(TAG, "onTakePhotoSuccess abs =" + (abs(minSpeedPic) / 3.6f))
CosStatusController().uploadFile(
mutableListOf(photoPath as String),
entity,
mType,
mainInfoId,
mFromType,
mLongitude,
mLatitude,
mSpeed
)
// CosStatusController().uploadFile(
// mutableListOf(photoPath as String),
// entity,
// mType,
// mainInfoId,
// mFromType,
// mLongitude,
// mLatitude,
// mSpeed
// )
if (photoPath != null) {
getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
}
}
if (minSpeedPic > 0 && maxSpeedPic > 0) {
Log.d(TAG, "onTakePhotoSuccess minSpeedPic > 0 -- speed = $speed")
if ((speed >= (minSpeedPic / 3.6f)) && speed <= (maxSpeedPic / 3.6f)) {
CosStatusController().uploadFile(
mutableListOf(photoPath as String),
entity,
mType,
mainInfoId,
mFromType,
mLongitude,
mLatitude,
mSpeed
)
// CosStatusController().uploadFile(
// mutableListOf(photoPath as String),
// entity,
// mType,
// mainInfoId,
// mFromType,
// mLongitude,
// mLatitude,
// mSpeed
// )
if (photoPath != null) {
getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
}
}
}
@@ -293,10 +318,14 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
entity?.let {
if (it.isCustom) {
compressVideo(videoPath, thumbnailPath, it)
// compressVideo(videoPath, thumbnailPath, it)
getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
} else if (entity.fromType in STRATEGY_UPLOAD_TYPE_ARRAY) {
// 属于策略上报
compressVideo(videoPath, thumbnailPath, it)
// compressVideo(videoPath, thumbnailPath, it)
getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
} else {
Log.d(
TAG,
@@ -306,15 +335,19 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f))
if (speed >= (abs(minSpeedVideo) / 3.6f)) {
//获取视频以及缩略图成功,开始上报
compressVideo(videoPath, thumbnailPath, it)
// compressVideo(videoPath, thumbnailPath, it)
getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
}
if (minSpeedVideo > 0 && maxSpeedVideo > 0) {
Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed")
if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) {
compressVideo(videoPath, thumbnailPath, it)
// compressVideo(videoPath, thumbnailPath, it)
getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
} else {
}
} else {
}
}
}
@@ -327,34 +360,36 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
//获取视频失败
override fun onTakeVideoFail(camera: Int) {
trackGetVideo(3)
Log.e(TAG, "getVideo onTakeVideoFail")
getVideoFailed?.invoke()
val entity = CustomStatusHandler.pollVideoStatus()
entity?.let {
InformationUploadController.release(it.id)
Log.e(TAG, "getVideo onTakeVideoFail entity?.isCustom =" + it.isCustom)
// if (it.isCustom) {
// sendGetInfoFailedReceiver(mType)
// }
}
// trackGetVideo(3)
// Log.e(TAG, "getVideo onTakeVideoFail")
// getVideoFailed?.invoke()
// val entity = CustomStatusHandler.pollVideoStatus()
//
// entity?.let {
// InformationUploadController.release(it.id)
// Log.e(TAG, "getVideo onTakeVideoFail entity?.isCustom =" + it.isCustom)
//// if (it.isCustom) {
//// sendGetInfoFailedReceiver(mType)
//// }
// }
//失败了,传空地址,发起请求
videoAndThumbMap["video"] = ""
videoAndThumbMap["thumb"] = ""
// videoAndThumbMap["video"] = ""
// videoAndThumbMap["thumb"] = ""
CosStatusController().sendInformationDirectly(
INFO_TYPE_VIDEO,
videoAndThumbMap,
mType,
entity,
mainInfoId,
mLongitude,
mLatitude,
mSpeed,
mFromType
)
// CosStatusController().sendInformationDirectly(
// INFO_TYPE_VIDEO,
// videoAndThumbMap,
// mType,
// entity,
// mainInfoId,
// mLongitude,
// mLatitude,
// mSpeed,
// mFromType
// )
getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
//地图上打点
taskAsync(3_000) {
@@ -369,43 +404,83 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
/**
* 压缩视频并且上传
*/
private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) {
Log.d(
TAG,
"outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}"
)
val startTime = System.currentTimeMillis()
Thread(Runnable {
try {
VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext)
.input(videoPath)
.output(outputVideoPath)
.removeAudio(true)
.outWidth(1920)
.outHeight(1080)
.bitrate(2000 * 1024)
.frameRate(25)
.process()
Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime))
CosStatusController().uploadFile(
mutableListOf(outputVideoPath, thumbnailPath),
entity,
mType,
mainInfoId,
mFromType,
mLongitude,
mLatitude,
mSpeed
)
//删除压缩前的视频
deletePicFile(videoPath)
} catch (e: Exception) {
Log.e(TAG, "compressVideo e = $e")
//删除压缩前的视频
deletePicFile(videoPath)
e.printStackTrace()
// private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) {
// Log.d(
// TAG,
// "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}"
// )
// val startTime = System.currentTimeMillis()
// Thread(Runnable {
// try {
// VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext)
// .input(videoPath)
// .output(outputVideoPath)
// .removeAudio(true)
// .outWidth(1920)
// .outHeight(1080)
// .bitrate(2000 * 1024)
// .frameRate(25)
// .process()
// Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime))
// CosStatusController().uploadFile(
// mutableListOf(outputVideoPath, thumbnailPath),
// entity,
// mType,
// mainInfoId,
// mFromType,
// mLongitude,
// mLatitude,
// mSpeed
// )
//
// //删除压缩前的视频
// deletePicFile(videoPath)
// } catch (e: Exception) {
// Log.e(TAG, "compressVideo e = $e")
// //删除压缩前的视频
// deletePicFile(videoPath)
// e.printStackTrace()
// }
// }).start()
// }
/**
* 上报路况的视频和图片
*/
fun uploadRoadInfo(info: UploadInfo) {
MogoUploadManager.getInstance(AbsMogoApplication.getApp().applicationContext).uploadInfo(info, object : ITanluUploadCallback {
override fun onSuccess(result: BaseData<UploadResult>) {
}
}).start()
override fun onFailure(code: Int) {
}
override fun onError(e: Throwable) {
}
})
}
private fun getInfo(filePath: String, addr: String, lon: Double, lat: Double, poiType: String,
direction: Float, areaCode: String, cityCode: String, type: Int, fromType: String
, mainInfoId: Long): UploadInfo? {
val info = UploadInfo()
info.filePath = filePath
info.addr = addr
info.longitude = lon
info.latitude = lat
info.poiType = poiType
info.direction = direction
info.areaCode = areaCode
info.cityCode = cityCode
info.sn = Utils.getSn()
info.type = type //0为图片 1为视频
info.fromType = fromType
info.mainInfoId = mainInfoId
return info
}
override fun onTakePhotoCancel(photoType: Int, camera: Int) {
@@ -419,17 +494,20 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback {
videoAndThumbMap["video"] = ""
videoAndThumbMap["thumb"] = ""
CosStatusController().sendInformationDirectly(
INFO_TYPE_VIDEO,
videoAndThumbMap,
mType,
entity,
mainInfoId,
mLongitude,
mLatitude,
mSpeed,
mFromType
)
// CosStatusController().sendInformationDirectly(
// INFO_TYPE_VIDEO,
// videoAndThumbMap,
// mType,
// entity,
// mainInfoId,
// mLongitude,
// mLatitude,
// mSpeed,
// mFromType
// )
getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) }
}
//获取图片