I am working on a video encoder based on the CameraView library, but I've run into issues with the overlay feature. Essentially, the library implements an OverlayLayout view that inherits from a FrameLayout (which inherits from ViewGroup). The library renders the overlay views on canvases. One canvas is for the preview and the other is for video encoding. The problem is that with hardware accelerated canvases, the preview rendering is managed by the Choreographer and circumvents the thread safety implemented in the CameraView library. When the canvases are rendered at the same time (or more to the point, when one of the overlay view is rendered on both canvases at the same time), I get an IllegalStateException from RenderNode.beginRecording/endRecording, crashing the video recording. I need the hardware accelerated canvas because I play a video on the overlay, so I need to somehow make this thread safe.
Based on this reference and what I see in the call stack when I encounter the issue, I thought that overriding ViewGroup.dispatchGetDisplayList in OverlayLayout like this could fix my problem:
@Override
protected void dispatchGetDisplayList() {
synchronized (hardwareLock) {
super.dispatchGetDisplayList();
}
}
Unfortunately, I get a warning that this doesn't override anything from the super class and super.dispatchGetDisplayList also yields a compiling error. I don't understand this. When I open ViewGroup.java in Android Studio, the method is there with the exact same signature and I see that it's overriding the same method from View. FrameLayout doesn't implement an override. Funny enough, ViewGroup.java opened in Android Studio gives the same warning about that method not being overridden, while it clearly is.
1- Am I missing something about method overriding in Java? (I'm more familiar with C++). 2- Is there another way I could make my app (Modifying the CameraView library) thread safe?
Edit: Turns out the method in View and ViewGroup has the "Hide" annotation. I thought this was part of a comment and had no effect on the code. I guess overriding this is not an option.