I've been working for 2 months with different Camera2 API projects. As you may know, Camera2 API is little difficult to understand and maintain, it requires some knowledge of multiprocessing, states and callabacks. Simple example of "just" taking photo on google examples has 1000 lines (https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java). In the internet, there is also very promissing implementation, called Camera3 https://github.com/QuinnFreedman/Camera3 - which simplifies usage of Camera2.
In a few articles, and examples I saw, that core part of Camera2 applications is machine automaton(FSA). FSA is ok, but as it becomes large, it is difficult to understand, maintain and extend. Imho, sollution is to use "State" design pattern(https://en.wikipedia.org/wiki/State_pattern). There is Context object which hold state, and State interface and concrete states (open, close, preview, take photo).
Simple sketch:
CamerContext:
- fields: contains device, session, charactericst, surfaces, handler, lock, request builders, callbacks(capture, session, device)
- methods: onOpenCamera, onCloseCamera, onCaptureCompleted
CameraState:
- concrete: OpenState, CloseState, PreviewState, TakingPhotoState
Questions:
- Have anyone do PoC "State" design pattern with camera2 api? Is this doable?
- Have anyone do state design pattern with parallel computing (locks, threads)? Any thoughts, tutorial, have you internesting articles?
Aucun commentaire:
Enregistrer un commentaire