media/gpu/v4l2: use WeakPtr to reference V4L2Queue from buffer references

We have made V4L2ReadableBufferRef's destruction thread-safe, but they
still hold a scoped_refptr to their V4L2Queue. This means that the
V4L2Queue can be destroyed from V4L2ReadableBufferRef's destructor, i.e.
in the incorrect thread.

Fix this by changing the scoped_refptr to a WeakPtr. This design also
fixes another issue: it lets us invalidate the WeakPtrs if buffers get
reallocated, making it impossible to access the wrong buffer after such
an event.

Methods of V4L2ReadableBufferRef that make use of the queue accordingly
check that the WeakPtr is valid and return an error value if it is not.

Bug: 792790
Bug: b:119794200
Test: VDA unittest passed in regular and import mode on Hana.

Change-Id: I82722033d9b902fd44f5c090be47ffb4469222a3
Reviewed-on: https://chromium-review.googlesource.com/c/1481186
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634606}
2 files changed