ndk/media/image_reader: Don't assume ownership of NativeWindow
#418
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When implementing proper ownership
acquire()
andrelease()
semantics forNativeWindow
in #207, I thought I had checked all existing calls toNativeWindow::from_ptr()
to make sure that they return a pointer that we get ownership over, and have to clean up ourselves. This turns out to not be the case forAImageReader_getWindow()
:And can be trivially reproduced by creating an
ImageReader
and calling.get_window()
. Dropping theNativeWindow
is fine but subsequently dropping theImageReader
results in a NULL-pointer SEGFAULT.For now calling
clone_from_ptr()
is enough to first acquire an extra reference on the pointer so that ownership remains balanced, but in the future we'd like to investigate a new non-ownedNativeWindow
type similar toHardwareBuffer
.As of writing the following calls to
from_ptr()
remain, that are all confirmed to transfer ownership and require cleanup via_release()
:ASurfaceTexture_acquireANativeWindow()
;AMediaCodec_createInputSurface()
;AMediaCodec_createPersistentInputSurface()
;ANativeWindow_fromSurface()
.