修改速度取值,更新行车记录仪代码。
DEMO必须依附于预览获取YUV数据,不符合需求,这里先接入直播,后续需要按照源码抽离直接通过USB获取YUV的服务

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2022-02-24 17:47:33 +08:00
parent 9df5dd5203
commit 353e8492b9
56 changed files with 2268 additions and 438 deletions

View File

@@ -52,6 +52,8 @@ dependencies {
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
implementation rootProject.ext.dependencies.mogoserviceapi
implementation rootProject.ext.dependencies.modulecommon
implementation project(':libraries:map-usbcamera')
implementation rootProject.ext.dependencies.mogo_core_utils
implementation rootProject.ext.dependencies.mogo_core_function_api
@@ -61,6 +63,8 @@ dependencies {
implementation project(':services:mogo-service-api')
implementation project(':modules:mogo-module-common')
implementation project(':libraries:map-usbcamera')
implementation project(':core:mogo-core-utils')
implementation project(':core:mogo-core-function-api')
implementation project(':core:mogo-core-function-call')

View File

@@ -1,3 +1,3 @@
GROUP=com.mogo.eagle.core.function.impl
POM_ARTIFACT_ID=devatools
POM_ARTIFACT_ID=carcorder
VERSION_CODE=1

View File

@@ -1,4 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.eagle.core.function.carcorder">
<application>
<service
android:name=".service.CarcorderService"
android:enabled="true"
android:exported="true"
android:process=":uvcservice">
<intent-filter>
<action android:name="com.mogo.launcher.action.CARCORDER_SERVICE" />
</intent-filter>
</service>
</application>
</manifest>

View File

@@ -0,0 +1,162 @@
package com.mogo.eagle.core.function.carcorder.service
import android.content.Intent
import android.hardware.usb.UsbDevice
import android.os.IBinder
import android.util.Log
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
import com.mogo.usbcamera.UVCCameraHelper
import com.serenegiant.usb.IFrameCallback
import com.serenegiant.usb.USBMonitor
import com.serenegiant.usb.USBMonitor.OnDeviceConnectListener
import com.serenegiant.usb.USBMonitor.UsbControlBlock
import com.serenegiant.usb.UVCCamera
import com.serenegiant.usb.common.BaseService
import com.serenegiant.usb.encoder.MediaVideoBufferEncoder
/**
* 行车记录仪服务
* @author donghongyu
*/
class CarcorderService : BaseService() {
private val DEBUG = true
val TAG = CarcorderService::class.java.name
// 挂载的USB设备集合
private var mDeviceList: List<UsbDevice>? = null
// USB 设备连接工具
private var mUSBMonitor: USBMonitor? = null
// 用于接入UVC摄像机
private var mUVCCamera: UVCCamera? = null
// 相机控制
private var mCtrlBlock: UsbControlBlock? = null
/**
* 配置相机基本按书
*/
private val previewWidth = 640
private val previewHeight = 480
// Default using MJPEG
// if your device is connected,but have no images
// please try to change it to FRAME_FORMAT_YUYV
val FRAME_FORMAT_MJPEG: Int = UVCCamera.FRAME_FORMAT_MJPEG
val MODE_BRIGHTNESS = UVCCamera.PU_BRIGHTNESS
val MODE_CONTRAST = UVCCamera.PU_CONTRAST
private val mFrameFormat = UVCCameraHelper.FRAME_FORMAT_MJPEG
override fun onCreate() {
super.onCreate()
if (DEBUG) {
Logger.d(TAG, "onCreate……")
}
if (mUSBMonitor == null) {
mUSBMonitor = USBMonitor(applicationContext, mOnDeviceConnectListener)
mUSBMonitor!!.register()
mDeviceList = mUSBMonitor!!.deviceList
}
}
override fun onDestroy() {
super.onDestroy()
if (DEBUG) Log.d(TAG, "onDestroy:")
if (mUSBMonitor != null) {
mUSBMonitor!!.unregister()
mUSBMonitor = null
}
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return super.onStartCommand(intent, flags, startId)
}
override fun onBind(intent: Intent): IBinder? {
return null
}
override fun onRebind(intent: Intent) {
if (DEBUG) Log.d(TAG, "onRebind:$intent")
}
override fun onUnbind(intent: Intent): Boolean {
if (DEBUG) Log.d(TAG, "onUnbind:$intent")
if (DEBUG) Log.d(TAG, "onUnbind:finished")
return true
}
//**********************************************************************************************************************************
private val mSync: Any = Any()
private val mVideoEncoder: MediaVideoBufferEncoder? = null
/**
* USB 设备连接监听
*/
private val mOnDeviceConnectListener: OnDeviceConnectListener = object : OnDeviceConnectListener {
override fun onAttach(device: UsbDevice) {
if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onAttach:${device.deviceName}---mDeviceList:${mDeviceList?.size}")
mUSBMonitor!!.requestPermission(device)
}
override fun onConnect(device: UsbDevice, ctrlBlock: UsbControlBlock, createNew: Boolean) {
if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onConnect:${device.deviceName}")
openCamera(device, ctrlBlock, createNew)
}
override fun onDisconnect(device: UsbDevice, ctrlBlock: UsbControlBlock) {
if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onDisconnect:${device.deviceName}")
}
override fun onDettach(device: UsbDevice) {
if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onDettach:${device.deviceName}")
}
override fun onCancel(device: UsbDevice) {
if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onCancel:${device.deviceName}")
}
}
/**
* 连接相机
*/
private fun openCamera(device: UsbDevice, ctrlBlock: UsbControlBlock, createNew: Boolean) {
if (mUVCCamera == null) {
mUVCCamera = UVCCamera()
mUVCCamera!!.open(ctrlBlock)
mUVCCamera!!.setStatusCallback { statusClass, event, selector, statusAttribute, data ->
if (DEBUG) Log.d(TAG, "IStatusCallback#onStatus(statusClass=${statusClass},event=${event},selector=${selector},statusAttribute=${statusAttribute},data=${data})")
}
try {
mUVCCamera!!.setPreviewSize(UVCCamera.DEFAULT_PREVIEW_WIDTH, UVCCamera.DEFAULT_PREVIEW_HEIGHT, UVCCamera.FRAME_FORMAT_MJPEG)
} catch (e: Exception) {
e.printStackTrace()
try {
mUVCCamera!!.setPreviewSize(UVCCamera.DEFAULT_PREVIEW_WIDTH, UVCCamera.DEFAULT_PREVIEW_HEIGHT, UVCCamera.DEFAULT_PREVIEW_MODE)
} catch (e: Exception) {
e.printStackTrace()
mUVCCamera!!.destroy()
}
}
mUVCCamera!!.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_YUV420SP)
mUVCCamera!!.startPreview()
}
}
/**
* 视频帧回掉
*/
private val mIFrameCallback = IFrameCallback { frame ->
if (DEBUG) Log.d(TAG, "IFrameCallback#onFrame:${frame}")
}
}