msdkdec: free unlocked msdk surface before output buffer allocation
authorHaihao Xiang <haihao.xiang@intel.com>
Mon, 23 Dec 2019 06:09:25 +0000 (14:09 +0800)
committerHaihao Xiang <haihao.xiang@intel.com>
Thu, 2 Jan 2020 00:43:36 +0000 (00:43 +0000)
commita819f05851a71a43514809d5081a49d7ab7e6cd4
tree4d66c121fead325464b632a0ce5eee08b4482e2f
parent66775f3e7289a852d54661a93cef29842fac0787
msdkdec: free unlocked msdk surface before output buffer allocation

https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/merge_requests/924
is trying to use video memory for decoding on Linux, which reveals a
hidden bug in msdkdec.

For video memory, it is possible that a locked mfx surface is not used
indeed and it will be un-locked later in MSDK, so we have to check the
associated MSDK surface to find out and free un-used surfaces, otherwise
it is easy to exhaust all pre-allocated mfx surfaces and get errors below:

0:00:00.777324879 27290 0x564b65a510a0 ERROR                default
gstmsdkvideomemory.c:77:gst_msdk_video_allocator_get_surface: failed to
get surface available
0:00:00.777429079 27290 0x564b65a510a0 ERROR         msdkbufferpool
gstmsdkbufferpool.c:260:gst_msdk_buffer_pool_alloc_buffer:<msdkbufferpool0>
failed to create new MSDK memory

Note the sample code in MSDK does similar thing in
CBuffering::SyncFrameSurfaces()
sys/msdk/gstmsdkdec.c