当前位置: 首页 > news >正文

制作一个网站怎么做的seo是什么姓

制作一个网站怎么做的,seo是什么姓,西安网站建设易网宣,东莞市广建建设工程有限公司Android在后台读取UVC摄像头的帧数据流并推送 添加UvcCamera依赖库 使用原版的 saki4510t/UVCCamera 在预览过程中断开可能会闪退,这里使用的是 jiangdongguo/AndroidUSBCamera 中修改的版本,下载到本地即可。 https://github.com/jiangdongguo/AndroidU…

Android在后台读取UVC摄像头的帧数据流并推送

  1. 添加UvcCamera依赖库
    使用原版的 saki4510t/UVCCamera 在预览过程中断开可能会闪退,这里使用的是
    jiangdongguo/AndroidUSBCamera 中修改的版本,下载到本地即可。
    https://github.com/jiangdongguo/AndroidUSBCamera

  2. 监听UVC连接回调

    mUSBMonitor = USBMonitor(context, mOnDeviceConnectListener)mUSBMonitor.register()public interface OnDeviceConnectListener {void onAttach(UsbDevice device);void onDetach(UsbDevice device);void onConnect(UsbDevice device, UsbControlBlock ctrlBlock, boolean createNew);void onDisconnect(UsbDevice device, UsbControlBlock ctrlBlock);void onCancel(UsbDevice device);}
  1. 检测到UVC后连接该设备

USB连接上会回调,onAttach, 本地判断连接上的USB设备是否UVC,如果是的话可以尝试调用连接该对象。调用mUSBMonitor.requestPermission(cam)就会请求权限并且连接该对象。连接成功后会回调 onConnect。

    var connectJob: Disposable? = nulloverride fun onAttach(device: UsbDevice?) {BLLog.i(TAG, "onAttach")BLLog.toast("USB_DEVICE_ATTACHED")connectJob?.dispose()connectJob = CommonUtils.runDelayed(1000) {autoConnectUvcDevice()}}private fun autoConnectUvcDevice() {val context = BLSession.getApplicationContext()val filter: List<DeviceFilter> =DeviceFilter.getDeviceFilters(context, R.xml.device_filter_uvc)val devs: List<UsbDevice> = mUSBMonitor?.getDeviceList(filter[0]) ?: listOf()val cam = findUsbCam(devs)BLLog.log2File(TAG, "autoConnect 共有USB数量:${devs.size}, Uvc: ${cam?.productName}")if (cam == null) {BLLog.i(TAG, "未连接USB摄像头")} else {mUSBMonitor.requestPermission(cam)}}

device_filter_uvc.xml

<usb><usb-device class="239" subclass="2" />	<!-- all device of UVC -->
</usb>

如何判断该连接对象是UVC对象,如果名字中包含USBCam或 interfaceClass = USB_CLASS_VIDEO

    private fun findUsbCam(devs: List<UsbDevice>): UsbDevice? {for (dev in devs) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {val name = "" + dev.productName + dev.manufacturerNameBLLog.i(TAG, "findUsbCam name:$name")if (name.contains("USBCam")) {return dev}for (i in 0 until dev.interfaceCount) {val inter = dev.getInterface(i)BLLog.i(TAG, "getInterface($i):$inter")if (inter.interfaceClass == UsbConstants.USB_CLASS_VIDEO) {return dev}}}}return null}
  1. 在onConnect中保存UvcCamera对象
            override fun onConnect(device: UsbDevice?,ctrlBlock: USBMonitor.UsbControlBlock?,createNew: Boolean) {BLLog.i(TAG, "onConnect  ${device?.productName}")synchronized(mSync) {try {// 保存最新的Uvc对象val camera = UVCCamera();camera.open(ctrlBlock)BLLog.log2File(TAG,"supportedSize:" + camera.supportedSize + "thread:" + Thread.currentThread().name)if (applyPreviewSize(camera)) {mUVCCamera?.destroy()mUVCCamera = camerapreviewStatus = PreViewStatus.None} else {BLLog.console(TAG, "UVC不支持此分辨率:$defPreviewSize")if (mUVCCamera == null) {mUVCCamera = camera}}uvcChangedSub.onNext(true)} catch (e:Exception){BLLog.log2File(TAG, "onConnect Recv exception: $e")}}}
  1. 预览并获取YUC视频帧
    如果需要预览到UI中显示,需要创建SurfaceView或者TextureView.
        mUVCCamera?.setPreviewDisplay(previewSurface)mUVCCamera?.startPreview()

如果不需要预览到UI中显示,可以new一个SurfaceTexture对象传进去即可;必须要调用预览才能获取到YUV数据。

        val surfaceTexture = SurfaceTexture(0)mUVCCamera?.setPreviewTexture(surfaceTexture)BLLog.i(TAG, "startPreviewWithAir")mUVCCamera?.startPreview()

预览后获取YUV帧流:

        val width = mUVCCamera?.previewSize?.width ?: defPreviewSize.widthval height = mUVCCamera?.previewSize?.height ?: defPreviewSize.heightyuvCallback = callbackmUVCCamera?.setFrameCallback({ buffer: ByteBuffer ->
//            BLLog.i(TAG, "onFrame ${width}*${height}")// yuv格式if (acceptFrame()) {val format = MediaFormat.createVideoFormat("", width, height)val data = ByteArray(buffer.remaining())buffer.get(data)val frame = YuvFrameData(format, data, width, height)yuvCallback?.onGetYuvData(frame)}}, UVCCamera.PIXEL_FORMAT_NV21)

获取到的YUV帧可以使用其他推流SDK进行推流即可,比如使用阿里云推流SDK推流。
这完成可以在后台进行推流,不需要UI上展示,节省设备的性能。

  1. 连接类参考:
// Uvc设备连接器
object UvcConnector : BaseBussModel(ModelType.Shared) {private val TAG = UvcConnector::class.java.simpleNameprivate val KEY_UVC_PREVIEW_SIZE = "KEY_UVC_PREVIEW_SIZE"// 默认支持:640*480, 1920*1080private var defPreviewSize = MySize.parseSize("1920*1080")!!enum class PreViewStatus {None,Visible,Air,}private lateinit var mUSBMonitor: USBMonitor@Volatileprivate var mUVCCamera: UVCCamera? = nullprivate val mSync = Object()private var previewStatus = PreViewStatus.None@Volatileprivate var yuvCallback: IMediaKit.OnYuvListener? = null// 状态变更消息private var uvcChangedSub = PublishSubject.create<Boolean>()override fun onStartUp() {super.onStartUp()BLLog.i(TAG, "onStartUp")val context = BLSession.getApplicationContext()mUSBMonitor = USBMonitor(context, mOnDeviceConnectListener)mUSBMonitor.register()CommonUtils.runAsync(::loadPreviewSize)}override fun onShutdown() {BLLog.i(TAG, "onShutdown")mUSBMonitor.unregister()mUSBMonitor.destroy()super.onShutdown()}fun hasUvcDevice(): Boolean {return mUVCCamera != null}fun previewStatus(): PreViewStatus {return previewStatus}fun getSubject() = uvcChangedSubfun getNowSize(): MySize? {return mUVCCamera?.previewSize?.let {MySize(it.width, it.height)}}fun getExpSize(): MySize {return defPreviewSize}fun startPreview(previewSurface: Surface): CallResult {BLLog.i(TAG, "startPreview")if (!hasUvcDevice()) {return CallResult(false, "未连接设备")}if (previewStatus == PreViewStatus.Air) {mUVCCamera?.stopPreview()}if (!applyPreviewSize(mUVCCamera)) {BLLog.console(TAG, "UVC不支持此分辨率:$defPreviewSize")return CallResult(false, "UVC不支持此分辨率:$defPreviewSize")}mUVCCamera?.setPreviewDisplay(previewSurface)mUVCCamera?.startPreview()previewStatus = PreViewStatus.Visibleif (yuvCallback != null) {setYuvCallback(yuvCallback!!)}uvcChangedSub.onNext(true)return CallResult(true, "成功")}fun stopPreview() {BLLog.i(TAG, "stopPreview")if (previewStatus != PreViewStatus.Visible) {return}mUVCCamera?.stopPreview()previewStatus = PreViewStatus.None// 需要接收数据if (yuvCallback != null) {startPreviewWithAir()setYuvCallback(yuvCallback!!)}uvcChangedSub.onNext(true)}fun clearYuvCallback() {yuvCallback = nullif (previewStatus == PreViewStatus.Air) {mUVCCamera?.stopPreview()previewStatus = PreViewStatus.NoneuvcChangedSub.onNext(true)}}fun setYuvCallback(callback: IMediaKit.OnYuvListener): Boolean {if (mUVCCamera == null) {return false}if (previewStatus == PreViewStatus.None) {startPreviewWithAir()}val width = mUVCCamera?.previewSize?.width ?: defPreviewSize.widthval height = mUVCCamera?.previewSize?.height ?: defPreviewSize.heightyuvCallback = callbackmUVCCamera?.setFrameCallback({ buffer: ByteBuffer ->
//            BLLog.i(TAG, "onFrame ${width}*${height}")// yuv格式if (acceptFrame()) {val format = MediaFormat.createVideoFormat("", width, height)val data = ByteArray(buffer.remaining())buffer.get(data)val frame = YuvFrameData(format, data, width, height)yuvCallback?.onGetYuvData(frame)}}, UVCCamera.PIXEL_FORMAT_NV21)return true}private fun acceptFrame(): Boolean {return Random.nextInt(30) <= 25}private fun startPreviewWithAir() {if (!applyPreviewSize(mUVCCamera)) {BLLog.console(TAG, "UVC不支持此分辨率:$defPreviewSize")return}val surfaceTexture = SurfaceTexture(0)mUVCCamera?.setPreviewTexture(surfaceTexture)BLLog.i(TAG, "startPreviewWithAir")mUVCCamera?.startPreview()previewStatus = PreViewStatus.AiruvcChangedSub.onNext(true)}private fun findUsbCam(devs: List<UsbDevice>): UsbDevice? {for (dev in devs) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {val name = "" + dev.productName + dev.manufacturerNameBLLog.i(TAG, "findUsbCam name:$name")if (name.contains("USBCam")) {return dev}for (i in 0 until dev.interfaceCount) {val inter = dev.getInterface(i)BLLog.i(TAG, "getInterface($i):$inter")if (inter.interfaceClass == UsbConstants.USB_CLASS_VIDEO) {return dev}}}}return null}private fun autoConnectUvcDevice() {val context = BLSession.getApplicationContext()val filter: List<DeviceFilter> =DeviceFilter.getDeviceFilters(context, R.xml.device_filter_uvc)val devs: List<UsbDevice> = mUSBMonitor?.getDeviceList(filter[0]) ?: listOf()val cam = findUsbCam(devs)BLLog.log2File(TAG, "autoConnect 共有USB数量:${devs.size}, Uvc: ${cam?.productName}")if (cam == null) {BLLog.i(TAG, "未连接USB摄像头")} else {mUSBMonitor.requestPermission(cam)}}private fun applyPreviewSize(camera: UVCCamera?):Boolean {if (camera == null){return false}try {camera.setPreviewSize(defPreviewSize.width,defPreviewSize.height,UVCCamera.FRAME_FORMAT_MJPEG)} catch (e: IllegalArgumentException) {BLLog.log2File(TAG, "setPreviewSize1 $defPreviewSize: $e")try {// fallback to YUV modecamera.setPreviewSize(defPreviewSize.width,defPreviewSize.height,UVCCamera.DEFAULT_PREVIEW_MODE)} catch (e1: IllegalArgumentException) {BLLog.log2File(TAG, "setPreviewSize2 $defPreviewSize: $e1")return false}}return true}private val mOnDeviceConnectListener: USBMonitor.OnDeviceConnectListener =object : USBMonitor.OnDeviceConnectListener {var connectJob: Disposable? = nulloverride fun onAttach(device: UsbDevice?) {BLLog.i(TAG, "onAttach")BLLog.toast("USB_DEVICE_ATTACHED")connectJob?.dispose()connectJob = CommonUtils.runDelayed(1000) {autoConnectUvcDevice()}}override fun onDetach(device: UsbDevice?) {BLLog.i(TAG, "onDetach")BLLog.toast("USB_DEVICE_DETACHED")synchronized(mSync) {if (mUVCCamera != null) {mUVCCamera?.destroy()mUVCCamera = nullpreviewStatus = PreViewStatus.NoneuvcChangedSub.onNext(true)}}}override fun onConnect(device: UsbDevice?,ctrlBlock: USBMonitor.UsbControlBlock?,createNew: Boolean) {BLLog.i(TAG, "onConnect  ${device?.productName}")synchronized(mSync) {try {// 保存最新的Uvc对象val camera = UVCCamera();camera.open(ctrlBlock)BLLog.log2File(TAG,"supportedSize:" + camera.supportedSize + "thread:" + Thread.currentThread().name)if (applyPreviewSize(camera)) {mUVCCamera?.destroy()mUVCCamera = camerapreviewStatus = PreViewStatus.None} else {BLLog.console(TAG, "UVC不支持此分辨率:$defPreviewSize")if (mUVCCamera == null) {mUVCCamera = camera}}uvcChangedSub.onNext(true)} catch (e:Exception){BLLog.log2File(TAG, "onConnect Recv exception: $e")}}}override fun onDisconnect(device: UsbDevice?, ctrlBlock: USBMonitor.UsbControlBlock?) {BLLog.i(TAG, "onDisconnect ${device?.productName}")synchronized(mSync) {mUVCCamera?.destroy()mUVCCamera = nullpreviewStatus = PreViewStatus.NoneuvcChangedSub.onNext(true)}}override fun onCancel(device: UsbDevice?) {BLLog.i(TAG, "onCancel")}}fun setPreviewSize(size: MySize) {defPreviewSize = sizeSharedPreferenceHelper.saveCustom(KEY_UVC_PREVIEW_SIZE, size.toString())}private fun loadPreviewSize() {val str = SharedPreferenceHelper.loadCustom(KEY_UVC_PREVIEW_SIZE, "")defPreviewSize = MySize.parseSize(str) ?: defPreviewSize}
}

文章转载自:
http://corybantic.c7629.cn
http://lop.c7629.cn
http://flannelled.c7629.cn
http://bronchiectasis.c7629.cn
http://dishonour.c7629.cn
http://molinete.c7629.cn
http://clianthus.c7629.cn
http://clary.c7629.cn
http://impermanency.c7629.cn
http://riffler.c7629.cn
http://possessory.c7629.cn
http://mcluhanesque.c7629.cn
http://zahle.c7629.cn
http://initiate.c7629.cn
http://adenitis.c7629.cn
http://superstrength.c7629.cn
http://dichasial.c7629.cn
http://borrower.c7629.cn
http://vagueness.c7629.cn
http://aurochs.c7629.cn
http://warrant.c7629.cn
http://tacmar.c7629.cn
http://enswathement.c7629.cn
http://mistful.c7629.cn
http://alemannic.c7629.cn
http://futile.c7629.cn
http://brilliance.c7629.cn
http://trisomic.c7629.cn
http://fife.c7629.cn
http://overcompensation.c7629.cn
http://documentary.c7629.cn
http://limpet.c7629.cn
http://makebate.c7629.cn
http://bluegill.c7629.cn
http://elb.c7629.cn
http://forcer.c7629.cn
http://hemagglutination.c7629.cn
http://unaccomplished.c7629.cn
http://corral.c7629.cn
http://aztec.c7629.cn
http://caffeol.c7629.cn
http://cryotron.c7629.cn
http://renovascular.c7629.cn
http://briticism.c7629.cn
http://disimpassioned.c7629.cn
http://withheld.c7629.cn
http://idiomorphism.c7629.cn
http://municipio.c7629.cn
http://relevantly.c7629.cn
http://satyagrahi.c7629.cn
http://catalepsis.c7629.cn
http://inertly.c7629.cn
http://hydroski.c7629.cn
http://tincture.c7629.cn
http://uxoricide.c7629.cn
http://unfilterable.c7629.cn
http://bentonitic.c7629.cn
http://lombardy.c7629.cn
http://plausible.c7629.cn
http://hoopoe.c7629.cn
http://dehydroisoandrosterone.c7629.cn
http://retsina.c7629.cn
http://syntactically.c7629.cn
http://unsteady.c7629.cn
http://folknik.c7629.cn
http://premillenarian.c7629.cn
http://internalise.c7629.cn
http://omnifocal.c7629.cn
http://elenctic.c7629.cn
http://sometimes.c7629.cn
http://pillowy.c7629.cn
http://holc.c7629.cn
http://anthropochory.c7629.cn
http://prosthesis.c7629.cn
http://torero.c7629.cn
http://hooverize.c7629.cn
http://estrin.c7629.cn
http://radiodetector.c7629.cn
http://skinbound.c7629.cn
http://etic.c7629.cn
http://ambitious.c7629.cn
http://sulfane.c7629.cn
http://seaport.c7629.cn
http://oyer.c7629.cn
http://dmn.c7629.cn
http://disjoin.c7629.cn
http://inchmeal.c7629.cn
http://erzgebirge.c7629.cn
http://filthily.c7629.cn
http://dolichosaurus.c7629.cn
http://stitchwork.c7629.cn
http://bandicoot.c7629.cn
http://hyalograph.c7629.cn
http://comstockery.c7629.cn
http://hemolysin.c7629.cn
http://resubject.c7629.cn
http://refrain.c7629.cn
http://regal.c7629.cn
http://aswarm.c7629.cn
http://witling.c7629.cn
http://www.zhongyajixie.com/news/80597.html

相关文章:

  • 做内衣的网站网站推广的基本方法
  • wordpress 页面 背景图优化网站建设seo
  • 凡科做的网站能被收录吗网站服务器速度对seo有什么影响
  • 网站生鲜建设市场分析广东省广州市佛山市
  • 佛山外贸网站建设渠道自助建站系统破解版
  • 做电商网站的设计思路有什么临沂做网站建设公司
  • 专业专业的网站开发网络培训心得
  • 优化方案2021版英语系统优化
  • 京东优惠券网站怎么做百度电脑版下载官网
  • 网站自动生成重庆seo公司
  • wordpress幻灯片主题深圳百度首页优化
  • 福安网站设计软文是指什么
  • 济南做网站建设的公司网络整合营销理论
  • 中国建设银行积分换购网站东莞网站建设方案外包
  • html如何做网站百度推广一般要多少钱
  • 手机端网站提交表单验证代码宁波seo网站推广软件
  • 小型企业网站设计与制作西安网站搭建公司
  • 太原市城乡建设局网站为什么不建议去外包公司上班
  • 木门行业网站该怎么做常用的网络推广方法有哪些
  • 下载网站的软件营销型网站优化
  • 网站建设vs网络推广合肥seo推广公司
  • 设计公司官方网站seo营销培训
  • 网站手机版怎么做百度广告管家
  • 网站建设单位是什么意思今日头条网站推广
  • 门户网站的优点小程序开发平台官网
  • 上海环球金融中心灰色行业seo大神
  • 个人能建设网站吗广州最近爆发什么病毒
  • 网页制作公司职员的日常劳动场景如何做seo
  • 学做网站要代码百度关键词排名怎么靠前
  • 沈阳网站建设兼职知名做网站的公司