【发布时间】:2019-05-09 11:33:41
【问题描述】:
我已经开始与 sample app 一起探索 CameraX 库,我注意到在管理生命周期方面有些不一致。
在这个帖子中,我将只讨论预览用例,因为它主要与生命周期相关。
在示例应用程序中,在CameraFragment 中,用例在onViewCreated 中绑定到CameraX,在onDestroyView 中未绑定。第一个问题是,如果我们将LifecycleOwner 传递给bind 方法,我们是否必须使用unbind 用例?我们可以将它们绑定到onCreate 并将生命周期管理留给CameraX 吗?
我也尝试过遵循getting started 教程,其中TextureView 的SurfaceTexture 刚刚被替换。在示例应用程序中,TextureView 首先从父级中删除,然后添加,然后SurfaceTexture 被替换。我们必须这样做吗?是什么原因?
另一件事是,在示例应用程序中,用例是从view.post { } 方法绑定的。我在使用这种方法时遇到了很多问题,因为在将片段放入后台堆栈后,用另一个片段替换而不是重新创建,CameraX 记录了许多消息:
E/CamX: [ERROR][STATS_AEC] aec_led_calibration.cpp:560: aec_led_cal_apply_calibration Invalid pointer 0x7921174000 0x0
E/CamX: [ERROR][STATS_AEC] aec_set.cpp:1346: aec_set_fps_range Aec_Error invalid input 414 E/CamX: [ERROR][STATS_AEC] camxcaecstatsprocessor.cpp:1671 SetAlgoBayerHistValue() Unsupported bayer hist channel!
E/CamX: [ERROR][STATS ] camxcaecstatsprocessor.cpp:3194 ProcessRequestFastAE() [FastAE] Failed to apply gain to the stats! E/CamX: [ERROR][STATS_AEC] aec_process.cpp:1229: aec_process_stats_parsing aec is null or invalid
E/CamX: [ERROR][STATS_AEC] aec_process.cpp:7983: aec_process_preview_and_video Error: invalid stats
只设置OnPreviewOutputUpdateListener而不是绑定所有用例可以吗?
编辑
为了显示确切的问题,我创建了简单的项目Camera Playground。
这里是CameraFragment 完整的逻辑。
class CameraFragment : Fragment() {
private val preview by lazy {
val configuration = PreviewConfig.Builder().build()
Preview(configuration)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
CameraX.bindToLifecycle(this, preview)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_camera, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
button_gallery.setOnClickListener {
requireActivity().supportFragmentManager
.beginTransaction()
.replace(R.id.container, GalleryFragment())
.addToBackStack("GalleryFragment")
.commit()
}
preview.setOnPreviewOutputUpdateListener { texture_view.surfaceTexture = it.surfaceTexture }
}
}
现在单击图库按钮后,CameraFragment 将替换为 GalleryFragment。按下返回按钮并返回CameraFragment 后,CameraX 会记录此类消息:
2019-05-09 14:12:20.969 778-1363/? E/CamX: [ERROR][STATS ] gcamfastaeutil.cpp:1170 SetTuningData() [FastAE] ERROR! Failed to get the tuning data
2019-05-09 14:12:20.969 778-1363/? E/CamX: [ERROR][HAL ] camxmetadatapool.cpp:1447 GetMetadataByTag() Invalid Slot to get a metadata from
2019-05-09 14:12:20.969 778-1363/? E/CamX: [ERROR][HAL ] camxmetadatapool.cpp:1447 GetMetadataByTag() Invalid Slot to get a metadata from
2019-05-09 14:12:20.969 778-1363/? E/CamX: [ERROR][STATS_AEC] aec_led_calibration.cpp:560: aec_led_cal_apply_calibration Invalid pointer 0x7920f1d000 0x0
2019-05-09 14:12:20.969 778-1363/? E/CamX: [ERROR][STATS_AEC] aec_set.cpp:1346: aec_set_fps_range Aec_Error invalid input 0
2019-05-09 14:12:20.969 778-1363/? E/CamX: [ERROR][STATS ] camxae.cpp:2203 AECSetSensorInfo() Wrong initial sequence from HAL!
2019-05-09 14:12:20.969 778-1363/? E/CamX: [ERROR][STATS_AEC] aec_get.cpp:777: aec_get_param GET_EXP_PARAMS ERROR, Uninitialized exposure settings requested
2019-05-09 14:12:20.969 778-1363/? E/CamX: [ERROR][HAL ] camxmetadatapool.cpp:1447 GetMetadataByTag() Invalid Slot to get a metadata from
【问题讨论】:
-
CameraX 还是很新的。由于代码在过去一年中发生了很大变化,因此这些问题中的许多似乎已被弃用。我很想看到关于“新”代码的后续行动。 (我很好奇它会持续多久!)