Commit graph

29 commits

Author SHA1 Message Date
Haihao Xiang c7be05cc38 msdk: make sure child context is destroyed first
The parent context shares some resources with child context, so the
child context should be destroyed first, otherwise the command below
will trigger a segmentation fault

$> gst-launch-1.0 videotestsrc num-buffers=100 ! msdkh264enc ! \
msdkh264dec ! fakesink videotestsrc num-buffers=50 ! \
msdkh264enc ! msdkh264dec ! fakesink

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2435>
2021-08-04 04:50:08 +00:00
Víctor Manuel Jáquez Leal 78f4777a82 msdk: Demote error log message to warning.
It is not an error that the available hardware doesn't support VA-API/MSDK. Just
none plugin features will be registered.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2336>
2021-06-21 06:30:07 +00:00
Haihao Xiang bda11a3e73 msdk: use MFXJoinSession() to join the parent and child sessions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1503>
2021-05-17 01:58:24 +00:00
Haihao Xiang cd3a3534c4 msdk: use a new method to create mfx session when using oneVPL dispatcher
In oneVPL, MFXLoad() and MFXCreateSession() are required to create a
workable mfx session[1]

[1] https://spec.oneapi.com/versions/latest/elements/oneVPL/source/programming_guide/VPL_prg_session.html#onevpl-dispatcher

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1503>
2021-05-17 01:58:24 +00:00
Haihao Xiang 39538adfd6 msdk: don't fall back to the default device
Ohterwise when user set a wrong device, the warning message doesn't get
printed if user doesn't set a right debug level in the environment, this
behavior might mislead user that the wrong device is being used.

This fixed https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1567

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2138>
2021-04-13 01:23:43 +00:00
Haihao Xiang 54091d0290 msdk: allow user specify a drm device via an env variable
User may specify the required device via GST_MSDK_DRM_DEVICE

Example:
GST_MSDK_DRM_DEVICE=/dev/dri/card0 gst-launch-1.0 videotestsrc ! msdkh264enc
! fakesink

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1953>
2021-02-24 04:40:14 +00:00
Haihao Xiang bdff6f5e42 msdk: needn't close mfx session when failed
Otherwise we will get double free issue because mfx session is closed in
finalize. See
https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1867#note_739346
for the double free issue.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1916>
2020-12-30 05:08:52 +00:00
Haihao Xiang 86fdd39147 msdk: check GstMsdkContext instead of mfxSession instance
When creating a GstMsdkContext instance, it also creates a mfxSession
instance, so we may check GstMsdkContext instead of mfxSession instance
to make sure MSDK is available. In addition, according to MSDK doc [1],
MFXVideoCORE_SetHandle function should be executed before any actual
usage of library including queries, otherwise the behavior is
unexpected, so we should call MFXVideoCORE_QueryPlatform after
MFXVideoCORE_SetHandle on Linux

[1] https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#working-with-va-api-applications

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1867>
2020-12-24 02:53:13 +00:00
rubenrua 6c3f092afc asfmux: Fix typo in property description
s/milisecs/milliseconds/g
2020-03-12 18:38:11 +01:00
Haihao Xiang ac9c9d8efc msdk: use cached response for DMABuf when the frame size is same
User is seeing corrupted display when running `videotestsrc !
video/x-raw,format=NV12,width=xxx,height=xxx ! msdkh265enc ! msdkh265dec
! glimagesink` with changed frame size, e.g. from 1920x1080 to 1920x240

The root cause is a same dmabuf fd is used for frames with
different size, which causes some unexpected result. This patch requires
cached response is used for frames with same size only for DMABuf, so a
dmabuf fd can't be used for frames with different size any more.
2020-01-28 03:46:04 +00:00
Haihao Xiang d6fbec5a44 msdk: make sure the found response meets the request
Otherwise the re-used msdk response doesn't have enough frames so it is
possible the pipeline will be broken
2020-01-06 02:16:53 +00:00
Haihao Xiang e50011c064 msdk: don't cache mfxFrameAllocResponse pointer
Otherwise it is possible that different wrappers share the same
mfxFrameAllocResponse pointer, so instead of caching the pointer, we may
cache the content of mfxFrameAllocResponse
2019-09-21 19:51:38 +00:00
Haihao Xiang 4841c2759d msdk: avoid reading data from freed memory
Both g_list_delete_link and g_list_remove remove an element and free it,
so l->next is invalid (catched by valgrind) after calling g_list_delete_link
or g_list_remove
2019-08-28 14:51:54 +00:00
Peter Seiderer 9b19968a66 msdk: fix error handling in case of unsupported hardware
Fix double gst_object_unref for GstMsdkContext.

https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/945
2019-04-10 15:54:31 +00:00
Haihao Xiang 5f2f289b7e msdk: verify the driver name
We need to make sure the Intel graphics card is used in a dual GPU
system.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/895
2019-02-12 12:13:31 +08:00
Haihao Xiang d7ad665d1c msdk: needn't call MFXJoinSession after MFXCloneSession
According to the MSDK documation[1], MFXCloneSession is a light-weight
equivalent of MFXJoinSession after MFXInit, so MFXJoinSession call isn't
needed in the msdk plugin, otherwise the cloned session is joined to the
parent session twice, and we will get a MFX error when closing the
parent session

example pipeline:

gst-launch-1.0 videotestsrc num-buffers=100 ! \
video/x-raw,format=NV12,width=352,height=288 ! msdkh264enc ! msdkh264dec ! \
msdkh264enc ! fakesink

Error message:

0:00:00.211948518 21733 0x5586ee741c60 ERROR                   msdk
msdk.c:148:msdk_close_session: Close failed (undefined behavior)

[1]: https://software.intel.com/en-us/node/628429#MFXCloneSession
2019-01-09 15:52:27 +08:00
Haihao Xiang 6c887f982e msdk: check whether mfx function call fails
And log the failures for debugging
2019-01-09 12:43:56 +08:00
Haihao Xiang 3110f3791f msdk: don't reset the external frame allocator
In gst-msdk, a mfx session may be shared between different gst
elements, each element tries to set the frame allocator. However, per
the MSDK documation[1], the behavior is undefined if reset the frame
allocator while the previous allocator is in use. Fortunately all
elements use the same frame allocator, so we can avoid to call
MFXVideoCORE_SetFrameAllocator again.

[1]: https://software.intel.com/en-us/node/628430#MFXVideoCORE3
2019-01-08 09:11:47 +00:00
Haihao Xiang 801189c02f msdk: decrease the reference count of object
Otherwise there are reference leaks if failed to clone or join a
mfx session
2018-12-12 17:24:00 +00:00
Tim-Philipp Müller 65c5b9a4f6 msdk: Update for g_type_class_add_private() deprecation in recent GLib
Untested.
2018-06-24 12:22:27 +02:00
U. Artie Eoff 275d754156 msdk: fix plugin load on implementations with only HW support
We can't assume that MSDK always supports SW implementation
on all platforms.  Thus, msdk_is_available should check for
ANY implementation.

https://bugzilla.gnome.org/show_bug.cgi?id=794991
2018-04-04 17:31:14 -08:00
Hyunjun Ko 762eb97092 msdk: specify the way to find a proper cached response by request
The current way to find proper response by just comparing request's
value is wrong.  We need to compare the size of a frame and the
number of suggested frames.

Refer to the sample in https://github.com/Intel-Media-SDK/samples.

https://bugzilla.gnome.org/show_bug.cgi?id=793707
2018-03-30 11:02:26 -08:00
Hyunjun Ko c9faf0d612 msdk: manage child sessions on parent GstMsdkContext
Sometimes parent context is released before its children get released.
In this case MFXClose of parent session fails.

To make sure that child sessions are closed before closing a parent
session,
Parent context needs to manage child sessions and close them first when
it's released.

https://bugzilla.gnome.org/show_bug.cgi?id=793412
2018-03-08 11:38:30 -09:00
Hyunjun Ko b08b8ddae3 msdk: manage MSDK surfaces seperately
Currently a gst buffer has one mfxFrameSurface when it's allocated and
can't be changed.
This is based on that the life of gst buffer and mfxFrameSurface would
be same.
But it's not true. Sometimes even if a gst buffer of a frame is finished
on downstream,
mfxFramesurface coupled with the gst buffer is still locked, which means
it's still being used in the driver.

So this patch does this.
Every time a gst buffer is acquired from the pool, it confirms if the
surface coupled with the buffer is unlocked.
If not, replace it with new unlocked one.
In this way, user(decoder or encoder) doesn't need to manage gst buffers
including locked surface.

To do that, this patch includes the following:
1. GstMsdkContext
- Manages MSDK surfaces available, used, locked respectively as the
following:
  1\ surfaces_avail : surfaces which are free and unused anywhere
  2\ surfaces_used : surfaces coupled with a gst buffer and being used
now.
  3\ surfaces_locked : surfaces still locked even after the gst buffer
is released.

- Provide an api to get MSDK surface available.
- Provide an api to release MSDK surface.

2. GstMsdkVideoMemory
- Gets a surface available when it's allocated.
- Provide an api to get an available surface with new unlocked one.
- Provide an api to release surface in the msdk video memory.

3. GstMsdkBufferPool
- In acquire_buffer, every time a gst buffer is acquired, get new
available surface from the list.
- In release_buffer, it confirms if the buffer's surface is unlocked or
not.
  - If unlocked, it is put to the available list.
  - If still locked, it is put to the locked list.

This also fixes bug #793525.

https://bugzilla.gnome.org/show_bug.cgi?id=793413
https://bugzilla.gnome.org/show_bug.cgi?id=793525
2018-03-08 11:37:12 -09:00
Sreerenj Balachandran b622d21d6a msdk : Add RenderNode support
Use drm render node as the first choice of device node file.
Fall backs to use drm primary (/dev/dri/card[0-9])
if there is no render node available

Basic logic is inherited from gstreamer-vaapi, but using
gudev API rather than libudev directly.

Added gudev library as dependency for msdk.

https://bugzilla.gnome.org/show_bug.cgi?id=791599
2018-02-13 14:40:22 -09:00
Hyunjun Ko 375a50a876 msdk: add async depth from each msdk element to GstMsdkContext to be shared
In case that pipeline is like ".. ! decoder ! encoder ! ..." with using
video memory,
decoder needs to know the async depth of the following msdk element so
that it could
allocate the correct number of video memory.

Otherwise, decoder's memory is exhausted while processing.

https://bugzilla.gnome.org/show_bug.cgi?id=790752
2018-02-13 13:52:14 -09:00
Hyunjun Ko dc82ccb9a2 msdk: context: add job type to figure out if joining session is necessary
According to the driver's instruction, if there are two or more encoders
or decoders in a process, the session should be joined by
MFXJoinSession.

To achieve this successfully by GstContext, this patch adds job type
specified if it's encoder, decoder or vpp.

If a msdk element gets to know if joining session is needed by the
shared context,
it should create another instance of GstContext with joined session,
which
is not shared.

https://bugzilla.gnome.org/show_bug.cgi?id=790752
2018-02-13 13:50:48 -09:00
Hyunjun Ko 4d860ec82b msdk: adds frame allocator using libva
Implements msdk frame allocator which is required from the driver.
Also makes these functions global so that GstMsdkAllocator could use
the allocated video memory later and couple with GstMsdkMemory.

GstMsdkContext keeps allocation information such as mfxFrameAllocRequest
and mfxFrameAllocResponse after allocation.

https://bugzilla.gnome.org/show_bug.cgi?id=790752
2018-02-13 12:43:42 -09:00
Hyunjun Ko 6ce9a66b80 msdk: implements GstMsdkContext.
Makes GstMsdkContext to be a descendant of GstObject so that
we could track the life-cycle of the session of the driver.

Also replaces MsdkContext with this one.
Keeps msdk_d3d.c alive for the future.

https://bugzilla.gnome.org/show_bug.cgi?id=790752
2018-02-13 12:41:28 -09:00