Android 11.0 根据Camera的YUYV和MJPG两种格式做特殊处理
Posted 王睿丶
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 11.0 根据Camera的YUYV和MJPG两种格式做特殊处理相关的知识,希望对你有一定的参考价值。
Camera的格式,只能在Native层先获取,然后使用__system_property_set(key,value)
设置属性值。来到Java层后通过SystemProperties.get(key)
获取属性值就可以了。
hardware/interfaces/camera/device/3.4/default/ExternalCameraDevice.cpp
struct v4l2_fmtdesc fmtdesc;
fmtdesc.index = 0;
if (capability.device_caps & V4L2_CAP_VIDEO_CAPTURE_MPLANE)
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
else
fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
int ret = 0;
while (ret == 0)
++ char m = (char)fmtdesc.pixelformat & 0xFF;
++ if(m == 'M')
++ ALOGV("Recognize MJPG - %c = ",fmtdesc.pixelformat & 0xFF);
++ __system_property_set("media.audio.xxx.format_type", "MJPG");
++
ret = TEMP_FAILURE_RETRY(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc));
ALOGV("index:%d,ret:%d, format:%c%c%c%c", fmtdesc.index, ret,
fmtdesc.pixelformat & 0xFF,
(fmtdesc.pixelformat >> 8) & 0xFF,
(fmtdesc.pixelformat >> 16) & 0xFF,
(fmtdesc.pixelformat >> 24) & 0xFF);
if (ret == 0 && !(fmtdesc.flags & V4L2_FMT_FLAG_EMULATED))
auto it = std::find (
packages/apps/Camera2/src/com/android/camera/settings/SettingsUtil.java
public static Size sizeFromSettingString(String sizeSettingString)
if (sizeSettingString == null)
return null;
String[] parts = sizeSettingString.split(SIZE_SETTING_STRING_DIMENSION_DELIMITER);
if (parts.length != 2)
return null;
++ // wangrui Read Camera resolution format value, non-empty value is MJPG, empty value is YUYVav
++ String s = SystemProperties.get("media.audio.xxx.format_type");
try
int width = Integer.parseInt(parts[0]);
int height = Integer.parseInt(parts[1]);
++ if ("MJPG".equals(s))
++ android.util.Log.d("SettingsUtil","MJPG 摄像头");
++ else
++ if (width == 1600 && height == 1200)
++ width = 1280;
++ height = 720;
++
++ android.util.Log.d("SettingsUtil","YUYV 摄像头");
++
return new Size(width, height);
catch (NumberFormatException ex)
return null;
我是王睿丶,加入我的Q群:901440630,欢迎一起讨论安卓技术!
以上是关于Android 11.0 根据Camera的YUYV和MJPG两种格式做特殊处理的主要内容,如果未能解决你的问题,请参考以下文章
Android 11.0 Camera 默认分辨率90W像素
Android 11.0 修复Camera 启用后置摄像头在拍照界面下,白平衡按钮无法点击
Android 11.0 修复Camera 录像后,视频出现加速