我们想查看camera 相关的一些基本配置信息,可以dump media.camera来查看:
adb shell dump media.camera > camera.txt复制代码
一. 查看相机支持的preview size和picture size
在dump结果中,搜索android.scaler.availableStreamConfigurations,出来的结果列表形式如下:
android.scaler.availableStreamConfigurations (d000a): int32[516] [34 1920 1080 OUTPUT ]
其中,第1个参数为format,第2个参数为width,第3个参数为height,第4个参数为streamType(preview看OUTPUT类型)。
主要的format为:
HAL_PIXEL_FORMAT_RAW16 = 32;
HAL_PIXEL_FORMAT_BLOB = 33;
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 34;
HAL_PIXEL_FORMAT_YCbCr_420_888 = 35;
HAL_PIXEL_FORMAT_RAW_OPAQUE = 36;
HAL_PIXEL_FORMAT_RAW10 = 37;
HAL_PIXEL_FORMAT_RAW12 = 38;
HAL_PIXEL_FORMAT_BLOB表示是jpeg stream,对应的size即平时所说的picture size; HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED表示preview stream,对应的size即平时所说的preview size.
例如,[34 1920 1080 OUTPUT ]表示preview size支持1920x1080. [33 1280 720 OUTPUT ]表示picture size支持1280x720.
所以availableStreamConfigurations的输出结果中,所有format=34且streamType=OUTPUT的size即为相机支持的preview size.
同理,所有format=33且streamType=OUTPUT的size即为相机支持的picture size.
二、查看相机支持的FPS
在dump结果中,搜索android.control.aeAvailableTargetFpsRanges,出来的结果列表形式如下:
android.control.aeAvailableTargetFpsRanges (10014): int32[8] [15 15 15 30 ] [30 30 30 30 ]
数据中每2个一组构成一个FPSRange,其中第1个为FPSRange的下限,第2个为FPSRange的上限。
三.查看当前打开的相机及其设置
在dump结果,搜索CameraDeviceClient,出来的结果类似:
Number of camera devices: 7 Number of normal camera devices: 3 Device 0 maps to "0" Device 1 maps to "1" Device 2 maps to "2" Active Camera Clients: [ (Camera ID: 0, Cost: 100, PID: 13723, Score: 0, State: 2User Id: 0, Client Package Name: com.jingdong.app.mall, Conflicting Client Devices: {6, }) ] Allowed user IDs: 0复制代码
要查看相机当前的设置,只需在该client的“Dumping camera metadata array”中根据对应的key搜索即可。
例如:查看相机当前设置的FPS
在dump结果中,搜索android.control.aeTargetFpsRange,出来的结果即为当前的FPSRange.
android.control.aeTargetFpsRange (10005): int32[2] [15 30 ]复制代码
例如,[15 30 ]表示当前设定的FPSRange为[15 30 ].
四.查看相机当前设置的preview size和picture size
在dump结果中,搜索Stream configuration,Stream configuration的输出类似:
Stream[0]: Output Consumer name: SurfaceView - com.jingdong.app.mall/com.jd.lib.scan.lib.zxing.client.android.CaptureActivity#0 State: 4 Dims: 720 x 480, format 0x22, dataspace 0x0 Max size: 0 Combined usage: 133376, max HAL buffers: 8 Frames produced: 69, last timestamp: 850646358680 ns Total buffers: 9, currently dequeued: 5 DequeueBuffer latency histogram: (74) samples 5 10 15 20 25 30 35 40 45 inf (max ms) 100.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 (%) Stream[1]: Output Consumer name: Camera2-JpegConsumer State: 4 Dims: 720 x 480, format 0x21, dataspace 0x8c20000 Max size: 778507 Combined usage: 131075, max HAL buffers: 8 Frames produced: 0, last timestamp: 0 ns Total buffers: 9, currently dequeued: 0 Stream[2]: Output Consumer name: Camera2-CallbackConsumer State: 4 Dims: 720 x 480, format 0x23, dataspace 0x8c20000 Max size: 0 Combined usage: 131075, max HAL buffers: 8 Frames produced: 66, last timestamp: 850613073471 ns Total buffers: 14, currently dequeued: 6 DequeueBuffer latency histogram: (72) samples复制代码
其中stream 0的format为0x22=34,这个即为preview stream,其size为720 x 480. 其中stream 1的format为0x21=33,这个即为jpeg stream,其size为720 x 480.
附录:
------- CameraService.cpp status_t CameraService::dump(int fd, const Vector<String16>& args) { ATRACE_CALL(); if (checkCallingPermission(String16("android.permission.DUMP")) == false) { dprintf(fd, "Permission Denial: can't dump CameraService from pid=%d, uid=%d\n", getCallingPid(), getCallingUid()); return NO_ERROR; } bool locked = tryLock(mServiceLock); // failed to lock - CameraService is probably deadlocked if (!locked) { dprintf(fd, "!! CameraService may be deadlocked !!\n"); } if (!mInitialized) { dprintf(fd, "!! No camera HAL available !!\n"); // Dump event log for error information dumpEventLog(fd); if (locked) mServiceLock.unlock(); return NO_ERROR; } dprintf(fd, "\n== Service global info: ==\n\n"); dprintf(fd, "Number of camera devices: %d\n", mNumberOfCameras); dprintf(fd, "Number of normal camera devices: %zu\n", mNormalDeviceIds.size()); for (size_t i = 0; i < mNormalDeviceIds.size(); i++) { dprintf(fd, " Device %zu maps to \"%s\"\n", i, mNormalDeviceIds[i].c_str()); } String8 activeClientString = mActiveClientManager.toString(); dprintf(fd, "Active Camera Clients:\n%s", activeClientString.string()); dprintf(fd, "Allowed user IDs: %s\n", toString(mAllowedUsers).string()); dumpEventLog(fd); bool stateLocked = tryLock(mCameraStatesLock); if (!stateLocked) { dprintf(fd, "CameraStates in use, may be deadlocked\n"); } int argSize = args.size(); for (int i = 0; i < argSize; i++) { if (args[i] == TagMonitor::kMonitorOption) { if (i + 1 < argSize) { mMonitorTags = String8(args[i + 1]); } break; } } for (auto& state : mCameraStates) { String8 cameraId = state.first; dprintf(fd, "== Camera device %s dynamic info: ==\n", cameraId.string()); CameraParameters p = state.second->getShimParams(); if (!p.isEmpty()) { dprintf(fd, " Camera1 API shim is using parameters:\n "); p.dump(fd, args); } auto clientDescriptor = mActiveClientManager.get(cameraId); if (clientDescriptor != nullptr) { dprintf(fd, " Device %s is open. Client instance dump:\n", cameraId.string()); dprintf(fd, " Client priority score: %d state: %d\n", clientDescriptor->getPriority().getScore(), clientDescriptor->getPriority().getState()); dprintf(fd, " Client PID: %d\n", clientDescriptor->getOwnerId()); auto client = clientDescriptor->getValue(); dprintf(fd, " Client package: %s\n", String8(client->getPackageName()).string()); client->dumpClient(fd, args); } else { dprintf(fd, " Device %s is closed, no client instance\n", cameraId.string()); } }复制代码