Camera API : Camera.getNumberOfCameras()分析
文章目录
- 高通 Camera API: Camera.getNumberOfCameras()分析
- 背景
- 接口实现分析
- 为什么?
- 如何处理?
- 拓展
高通 Camera API: Camera.getNumberOfCameras()分析
背景
最近调试的高通设备 有前摄 后摄 扫描头 三个camera设备
但是app 使用接口 Camera.getNumberOfCameras()的返回值为2. 出于好奇 看了一下接口源码实现
接口实现分析
/*** Returns the number of physical cameras available on this device.* The return value of this method might change dynamically if the device* supports external cameras and an external camera is connected or* disconnected.** If there is a* {@link android.hardware.camera2.CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA* logical multi-camera} in the system, to maintain app backward compatibility, this method will* only expose one camera per facing for all logical camera and physical camera groups.* Use camera2 API to see all cameras.** @return total number of accessible camera devices, or 0 if there are no* cameras or an error was encountered enumerating them.*/public static int getNumberOfCameras() {boolean exposeAuxCamera = false;String packageName = ActivityThread.currentOpPackageName();/* Force to expose only two cameras* if the package name does not falls in this bucket*/String packageList = SystemProperties.get("vendor.camera.aux.packagelist");if (packageList.length() > 0) {TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');splitter.setString(packageList);for (String str : splitter) {if (packageName.equals(str)) {exposeAuxCamera = true;break;}}}int numberOfCameras = _getNumberOfCameras();if (exposeAuxCamera == false && (numberOfCameras > 2)) {numberOfCameras = 2;}return numberOfCameras;}/*** Returns the number of physical cameras available on this device.*//** @hide */public native static int _getNumberOfCameras();
作为对比 AOSP的代码如下:
/*** Returns the number of physical cameras available on this device.* The return value of this method might change dynamically if the device* supports external cameras and an external camera is connected or* disconnected.** If there is a* {@link android.hardware.camera2.CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA* logical multi-camera} in the system, to maintain app backward compatibility, this method will* only expose one camera per facing for all logical camera and physical camera groups.* Use camera2 API to see all cameras.** @return total number of accessible camera devices, or 0 if there are no* cameras or an error was encountered enumerating them.*/public native static int getNumberOfCameras();
我们可以看到 高通的实现做了一层简单的封装
AOSP中获取物理设备的接口加入了_前缀变为隐藏起开
对app开放的是高通封装后的实现
在这个封装中 加入了一个属性 “vendor.camera.aux.packagelist”
只有在这个属性中定义的应用才能获得超过2个的摄像头
默认这个属性只有高通的骁龙相机
#Expose aux camera for below packages
vendor.camera.aux.packagelist=org.codeaurora.snapcam
其他app,当设备camera设备超过3个的时候,只能获得2个的结果
为什么?
拙以为 这个接口是针对手机的物理形态适配的 一个前摄 一个后摄。 多余三个的情况多余的情况大概率是后摄的多镜头 可以看做一个设备
如何处理?
如果想单独使用扫描头作为物理设备:
可以如下尝试操作来打开
try {Method openMethod = Class.forName("android.hardware.Camera").getMethod("openLegacy", int.class, int.class);mCamera = (android.hardware.Camera) openMethod.invoke(null, 2, CAMERA_HAL_API_VERSION_1_0);mCamera.setDisplayOrientation(oritationAdjust);} catch (Exception e) {/* Retry with open if openLegacy doesn't exist/fails */Log.v(TAG, "openLegacy failed due to " + e.getMessage()+ ", using open instead");mCamera = android.hardware.Camera.open(2);}
拓展
类似的接口还有
CameraManager.getCameraIdList()
/*** Get a list of all camera IDs that are at least PRESENT; ignore devices that are* NOT_PRESENT or ENUMERATING, since they cannot be used by anyone.*/public String[] getCameraIdList() {String[] cameraIds = null;synchronized(mLock) {// Try to make sure we have an up-to-date list of camera devices.connectCameraServiceLocked();boolean exposeAuxCamera = false;String packageName = ActivityThread.currentOpPackageName();String packageList = SystemProperties.get("vendor.camera.aux.packagelist");if (packageList.length() > 0) {TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');splitter.setString(packageList);for (String str : splitter) {if (packageName.equals(str)) {exposeAuxCamera = true;break;}}}int idCount = 0;for (int i = 0; i < mDeviceStatus.size(); i++) {if(!exposeAuxCamera && (i == 2)) break;int status = mDeviceStatus.valueAt(i);if (status == ICameraServiceListener.STATUS_NOT_PRESENT ||status == ICameraServiceListener.STATUS_ENUMERATING) continue;idCount++;}cameraIds = new String[idCount];idCount = 0;for (int i = 0; i < mDeviceStatus.size(); i++) {if(!exposeAuxCamera && (i == 2)) break;int status = mDeviceStatus.valueAt(i);if (status == ICameraServiceListener.STATUS_NOT_PRESENT ||status == ICameraServiceListener.STATUS_ENUMERATING) continue;cameraIds[idCount] = mDeviceStatus.keyAt(i);idCount++;}}// The sort logic must match the logic in// libcameraservice/common/CameraProviderManager.cpp::getAPI1CompatibleCameraDeviceIdsArrays.sort(cameraIds, new Comparator<String>() {@Overridepublic int compare(String s1, String s2) {int s1Int = 0, s2Int = 0;try {s1Int = Integer.parseInt(s1);} catch (NumberFormatException e) {s1Int = -1;}try {s2Int = Integer.parseInt(s2);} catch (NumberFormatException e) {s2Int = -1;}// Uint device IDs firstif (s1Int >= 0 && s2Int >= 0) {return s1Int - s2Int;} else if (s1Int >= 0) {return -1;} else if (s2Int >= 0) {return 1;} else {// Simple string compare if both id are not uintreturn s1.compareTo(s2);}}});return cameraIds;}
Camera API : Camera.getNumberOfCameras()分析相关推荐
- Android Camera API 2使用OpenGL ES 2.0和GLSurfaceView对预览进行实时二次处理(黑白滤镜)
这段时间有点忙,一直没时间写第三篇教程,其实代码很早之前就写好了.本系列教程会有三篇文章讲解Android平台滤镜的实现方式,希望在阅读本文之前先阅读前面两篇文档. 第一篇 Android Camer ...
- 调用Camera API实现自己的拍照和摄像程序
参考博客: http://www.cnblogs.com/franksunny/archive/2011/11/17/2252926.html 根据Camera API实现自己的拍照和摄像程序 通过上 ...
- Android 新老两代 Camera API 大起底
https://blog.csdn.net/Byeweiyang/article/details/80515192 0.背景简介 最近有一部分相机相关的需求,专注于对拍摄的照片.视频的噪点.色温.明暗 ...
- 基于Android5.0的Camera Framework源码分析 (三)
上一次讲解了一下startPreview过程,主要是为了画出一条大致的从上到下的线条,今天我们看一下Camera在Framework的sendCommand和dataCallback,这部分属于衔接过 ...
- android 音视频流采集,Android 音视频开发(四):使用 Camera API 采集视频数据(示例代码)...
本文主要将的是:使用 Camera API 采集视频数据并保存到文件,分别使用 SurfaceView.TextureView 来预览 Camera 数据,取到 NV21 的数据回调. 注: 需要权限 ...
- Using the Cordova Camera API
使用ionic开发一款android或ios应用,估计少不了使用到Camera API,这里记录下使用过程. 创建空的ionic应用 ionic start myTabs tabs 通过cd demo ...
- Android开发:调用camera API 创建MediaRecorder
本文出自 "whithin's" 博客,请务必保留此出处http://whithin.blog.51cto.com/690417/1063573 1. add below thr ...
- Android Camera TakePicture過程分析
Android Camera TakePicture過程分析 接著上一篇文章,繼續講解camera拍照等具體功能實行流程 Camera子系统采用C/S架构,客户端和服务端在两个不同的进程当中,它们使用 ...
- Android Camera 四 Camera HAL 分析
Android Camera 一 源码路径 Android Camera 二 JNI JAVA和C/CPP图像数据传输流程分析 Android Camera 三 CameraService 和 Cli ...
最新文章
- SMA携手LG推出住宅光伏储能逆变器
- Speex for Android
- valgrind 看内存泄漏
- 【攻防世界015】notsequence
- 在IAR 中出现the stack plug-in failed to set a breakpoint on main
- Centos7安装Docker教程
- 24 CO配置-控制-产品成本控制-成本对象控制-定义订单交货的货物接收评估
- spring组键扫描
- java中workFlowEvent_防止线程在java中重复处理
- 【报告分享】2020年母婴未来消费新趋势报告.pdf(附下载链接)
- 一支python教学_第一只python爬虫
- 19-备忘录模式Quarkus实现
- SwitchyOmega_Chromium插件的下载安装以及使用
- easyui获取图片路径_Easyui filebox(文件框)_EasyUI 插件
- python打开文件方式
- 腾讯云折(tian)腾(keng)记
- 手机配指环条码阅读器的爱恨纠缠
- 了解阿克曼转向原理的作用
- 5个超好用的自媒体网站,免费用
- STM32官方的一些参考手册资料