需求:
android 8.1 系统里,没有摄像头的情况下,需要模拟出一个摄像头给app 用。
当某个app打开摄像头的时候,就把一段普通的视频文件播放出去,让这个app 以为是真的摄像头在拍摄。
之前尝试过在linux 内核里添加 v4l2 驱动,但是这个驱动不行,原因如下:
“hardware/libhardware/modules/camera/3_4/v4l2_camera.cpp” 的源码里注释写了:
// TODO(b/29939583): V4L2 doesn’t actually support more than 1
// stream at a time. If not all streams are the same format
// and size, error. Note that this means the HAL is not spec-compliant.
// Technically, this error should be thrown during validation, but
// since it isn’t a spec-valid error validation isn’t set up to check it.
某些app 会指定打开第二个摄像头,而且有2个stream, 但是 v4l2 驱动只有一个 stream 。
所以用虚拟的v4l2 驱动这条路就走不通了。 需要其他方案 。
如果能在 v4l2 驱动集成之上搞定,也是可以的 。