Commit graph

4295 commits

Author SHA1 Message Date
Víctor Manuel Jáquez Leal
4c7218d7ae va: vpp: handle context query
Previously vapostproc didn't communicate its context through query mechanism,
which is required for context sharing. This patch completes this missing bits.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2007>
2021-02-05 18:52:56 +01:00
Víctor Manuel Jáquez Leal
da363a20fe va: vpp: don't copy color, size or orientation video metas
If they are processed by the element.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2007>
2021-02-05 18:52:56 +01:00
Víctor Manuel Jáquez Leal
a29b56008a va: vpp: don't break passthrough if no color balance required
The function `_add_filter_cb_buffer()` returned TRUE if no color balance filter
are required, but that's is wrong, since it will break the passthrough. This
patch return FALSE which is the correct value for the situation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2007>
2021-02-05 18:52:56 +01:00
Víctor Manuel Jáquez Leal
b6e8741c29 va: vpp: use gst_clear_caps()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2007>
2021-02-05 18:52:23 +01:00
Víctor Manuel Jáquez Leal
6ae2494887 va: filter: don't destroy pipeline buffer
This was only required by i915 driver before libva-2.0 because it didn't
conform.

Also changes the way _destroy_filters() is called, now inside a locked block, so
it must not lock in it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2006>
2021-02-05 16:54:07 +01:00
Víctor Manuel Jáquez Leal
599e16fde8 va: filter: lock member variables access
While gst_va_filter_open() and gst_va_filter_close() remain non-thread-safe, the
other API calls that modify member variables are locked.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2005>
2021-02-04 11:12:37 +01:00
Seungha Yang
6bdf09d252 d3d11decoder: Fix deadlock when DPB texture pool is full
Unlike other stateless decoder implementations (e.g., VA),
our DPB pool cannot be grown since we are using
texture array (pre-allocated, fixed-size d3d11 texture pool).
So, if there's no more available texture to use,
there's no way other than copying it to downstream's
d3d11 buffer pool. Otherwise deadlock will happen.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2003>
2021-02-03 20:46:22 +00:00
Haihao Xiang
956d6e8ff7 va: sort the device queue
If so, the elements will be registered per drm node in order of
renderD128, renderD129, ... etc, an element with constant name will be
registered on renderD128 on a hardware with multiple drm nodes.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1988>
2021-02-02 10:28:04 +08:00
Seungha Yang
95e1ce7e7a v4l2decoder: Small documentation fix
Fixing documentation even though those methods are v4l2codecs plugin internals

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2000>
2021-02-02 04:33:33 +09:00
Nicolas Dufresne
99ebbf72ef v4l2codecs: h264: Enable 1 frame delay on non-live
When doing non-live decoding, enable 1 frame of delay. This will ensure
that we queue the next decoding job before we actually wait for the previous
to complete. This improves throughput notably on RK3399.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
241a490084 v4l2codecs: Add support for render delay
This add support for render delay in the decoder helper.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
88b93416fe v4l2codecs: Coding style fix
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
13a40b1da9 v4l2codecs: Poll inside set_done()
This removes the need for the gst_v4l2_decoder_is_done() helper and
simplify slightly the subclass code.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
1c2f391b57 v4l2codecs: Make request structure ref-counted
This adds a non-thread safe refcount to the GstV4l2Request. This will
allow holding on more then one request in order to implement render
delay. This is made non-thread safe for speed as we know this will all
happen on the same streaming thread.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
3db6f45ca9 v4l2codecs: Rework handling of queues and pending requests
Starting from this patch, all queue and dequeue operation happening
on V4L2 is now abstracted with the request. Buffers are dequeued
automatically when pending requests are marked done and only 1 in-flight
request is now used.

Along with fixing issues with request not being reused with slice
decoders, this change reduces the memory footprint by allocating only
two bitstream buffers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Staz M
180ab8377f decklink: Fixed decklinkvideosink auto format detection
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1994>
2021-01-29 16:49:07 +00:00
Seungha Yang
fba807bead nvh264sldec: Add support for output-delay to improve throughput performance
NVDEC API support delaying getting decoded output, and recommended
delay by API document is 4 frames. In case that throughput is
more critical factor than latency, we can prefer delayed output
as recommended by NVIDIA.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1925>
2021-01-29 16:22:28 +00:00
Seungha Yang
66eed8a61d d3d11videosink: Don't limit max buffers of buffer pool
In some case, especially reverse playback, we would need more than
two buffers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1989>
2021-01-27 20:08:51 +00:00
Seungha Yang
0b0bf1b0bf d3d11: Suppress some warning debug messages
* Don't warn for live object, since ID3D11Debug itself seems to be
  holding refcount of ID3D11Device at the moment we called
  ID3D11Debug::ReportLiveDeviceObjects(). It would report live object
  always
* Device might not be able to support some formats (e.g., P010)
  especially in case of WARP device. We don't need to warn about that.
* gst_d3d11_device_new() can be used for device enumeration. Don't warn
  even if we cannot create D3D11 device with given adapter index therefore.
* Don't warn for HLSL compiler warning. It's just noise and
  should not be critical thing at all

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1986>
2021-01-27 04:46:42 +09:00
Seungha Yang
60e223f4fd d3d11videosink: Add support for drawing on application's own texture
Add a way to support drawing on application's texture instead of
usual window handle.
To make use of this new feature, application should follow below step.
1) Enable this feature by using "draw-on-shared-texture" property
2) Watch "begin-draw" signal
3) On "begin-draw" signal handler, application can request drawing
   by using "draw" signal action. Note that "draw" signal action
   should be happen before "begin-draw" signal handler is returned

NOTE 1) For texture sharing, creating a texture with
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX flag is strongly recommend
if possible because we cannot ensure sync a texture
which was created with D3D11_RESOURCE_MISC_SHARED
and it would cause glitch with ID3D11VideoProcessor use case.

NOTE 2) Direct9Ex doesn't support texture sharing which was
created with D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX. In other words,
D3D11_RESOURCE_MISC_SHARED is the only option for Direct3D11/Direct9Ex interop.

NOTE 3) Because of missing synchronization around ID3D11VideoProcessor,
If shared texture was created with D3D11_RESOURCE_MISC_SHARED,
d3d11videosink might use fallback texture to convert DXVA texture
to normal Direct3D texture. Then converted texture will be
copied to user-provided shared texture.

* Why not use generic appsink approach?
In order for application to be able to store video data
which was produced by GStreamer in application's own texture,
there would be two possible approaches,
one is copying our texture into application's own texture,
and the other is drawing on application's own texture directly.
The former (appsink way) cannot be a zero-copy by nature.
In order to support zero-copy processing, we need to draw on
application's own texture directly.

For example, assume that application wants RGBA texture.
Then we can imagine following case.

"d3d11h264dec ! d3d11convert ! video/x-raw(memory:D3D11Memory),format=RGBA ! appsink"
                             ^
                             |_ allocate new Direct3D texture for RGBA format

In above case, d3d11convert will allocate new texture(s) for RGBA format
and then application will copy again the our RGBA texutre into
application's own texture. One texture allocation plus per frame GPU copy will hanppen
in that case therefore.
Moreover, in order for application to be able to access
our texture, we need to allocate texture with additional flags for
application's Direct3D11 device to be able to read texture data.
That would be another implementation burden on our side

But with this MR, we can configure pipeline in this way
"d3d11h264dec ! d3d11videosink".

In that way, we can save at least one texture allocation and
per frame texutre copy since d3d11videosink will convert incoming texture
into application's texture format directly without copy.

* What if we expose texture without conversion and application does
  conversion by itself?
As mentioned above, for application to be able to access our texture
from application's Direct3D11 device, we need to allocate texture
in a special form. But in some case, that might not be possible.
Also, if a texture belongs to decoder DPB, exposing such texture
to application is unsafe and usual Direct3D11 shader cannot handle
such texture. To convert format, ID3D11VideoProcessor API needs to
be used but that would be a implementation burden for application.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1873>
2021-01-26 18:14:37 +00:00
Seungha Yang
6f6a82d0f5 d3d11: Add support for MPEG-2 video decoding
Add DXVA/Direct3D11 API based MPEG-2 decoder element

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1969>
2021-01-25 18:05:53 +00:00
Víctor Manuel Jáquez Leal
8a8688c639 va: filter: fix assignation to proper variable
Fix the result of a wrong copy&paste

Fixes: #1501
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1976>
2021-01-22 09:38:27 +01:00
Seungha Yang
1f7681c385 mfvideoenc: Add support for P010 d3d11 texture
Add P010 Direct3D11 texture format support

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1970>
2021-01-21 18:53:27 +09:00
Seungha Yang
7b9debedc8 d3d11: Don't use hardcoded maximum resolution value
Maximum supported texture dimension is pre-defined based on
feature level and it couldn't be INT_MAX in any case.
See also https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-devices-downlevel-intro

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1964>
2021-01-20 19:31:27 +09:00
Seungha Yang
fd76521c24 d3d11videosink: Fix ugly thread name for Win32 window impl.
Don't need to put Win32 twice

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1962>
2021-01-19 11:23:56 +00:00
Seungha Yang
96923c4fa2 d3d11videosink: Fix MSVC build warnings around UWP code
gstd3d11window_corewindow.cpp(408): warning C4189:
  'storage': local variable is initialized but not referenced
gstd3d11window_corewindow.cpp(490): warning C4189:
  'self': local variable is initialized but not referenced
gstd3d11window_swapchainpanel.cpp(481): warning C4189:
  'self': local variable is initialized but not referenced

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1962>
2021-01-19 11:23:56 +00:00
Seungha Yang
d16b5b7f7f d3d11: Allow building UWP features with Desktop features if possible
WINAPI_PARTITION_DESKTOP and WINAPI_PARTITION_APP can coexist.
Although UWP only binaries should be used for production stage,
this change will be useful for development stage

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1962>
2021-01-19 11:23:56 +00:00
Seungha Yang
46c577222d d3d11decoder: Do more retry for ID3D11VideoContext::DecoderBeginFrame failure
Some GPUs (especially NVIDIA) are complaining that GPU is still busy
even we did 50 times of retry with 1ms sleep per failure.
Because DXVA/D3D11 doesn't provide API for "GPU-IS-READY-TO-DECODE"
like signal, there seems to be still no better solution other than sleep.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1913>
2021-01-18 12:04:53 +00:00
Seungha Yang
3f43fef3ce d3d11videosink: Fix build error on UWP
gstd3d11videosink.c(662): error C2065: 'sink': undeclared identifier

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1961>
2021-01-18 19:48:12 +09:00
He Junyan
0158849145 va: Fix some gst_object_unref error because the pointer is NULL.
!1957 introduces some error of gst_object_unref for NULL pointer.
Fixes all of them.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1959>
2021-01-17 14:00:50 +08:00
He Junyan
82c0f90197 va: Make the caps pointer operation atomic in vadecoder.
The vadecoder's srcpad_caps and sinkpad_caps pointers are outside of the
mutex protection. Just make all operation for them atomic.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1957>
2021-01-15 20:40:21 +08:00
He Junyan
6b1e1924fd va: Fix a latent race condition in vabasedec.
The vabasedec's display and decoder are created/destroyed between
the gst_va_base_dec_open/close pair. All the data and event handling
functions are between this pair and so the accessing to these pointers
are safe. But the query function can be called anytime. So we need to:
1. Make these pointers operation in open/close and query atomic.
2. Hold an extra ref during query function to avoid it destroyed.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1957>
2021-01-15 20:40:10 +08:00
Sebastian Dröge
4d07974b10 decklinkaudiosrc: Allow disabling audio sample alignment code by setting the alignment-threshold to 0
And handle setting it to GST_CLOCK_TIME_NONE as always aligning without
ever detecting a discont.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1956>
2021-01-14 14:37:32 +02:00
Seungha Yang
84db4b68fe mfvideoenc: Add support for Direct3D11 texture
Initial support for d3d11 texture so that encoder can copy
upstream d3d11 texture into encoder's own texture pool without
downloading memory.

This implementation requires MFTEnum2() API for creating
MFT (Media Foundation Transform) object for specific GPU but
the API is Windows 10 desktop only. So UWP is not target
of this change.
See also https://docs.microsoft.com/en-us/windows/win32/api/mfapi/nf-mfapi-mftenum2

Note that, for MF plugin to be able to support old OS versions
without breakage, this commit will load MFTEnum2() symbol
by using g_module_open()

Summary of required system environment:
- Needs Windows 10 (probably at least RS 1 update)
- GPU should support ExtendedNV12SharedTextureSupported feature
- Desktop application only (UWP is not supported yet)

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1903>
2021-01-13 20:15:04 +00:00
Seungha Yang
0f7af4b143 d3d11: Move core methods to gst-libs
Move d3d11 device, memory, buffer pool and minimal method
to gst-libs so that other plugins can access d3d11 resource.
Since Direct3D is primary graphics API on Windows, we need
this infrastructure for various plugins can share GPU resource
without downloading GPU memory.
Note that this implementation is public only for -bad scope
for now.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/464>
2021-01-13 15:01:20 +00:00
Seungha Yang
98eebf3322 va: allocator: Fix deadlock caused by double lock
Trivial bug fix for deadlock

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1949>
2021-01-12 21:28:04 +09:00
Seungha Yang
ad3fb007e1 meson: va: Skip configuration on non-linux environment
VA plugin is linux-only plugin, so we can skip it earlier.
Note that this plugin is making use of libdrm meson fallback,
which is unusable on the other platforms such as Windows

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1946>
2021-01-07 23:47:35 +09:00
Haihao Xiang
3e2e07bb8a msdkenc: the unit for max-frame-size is kbyte
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1944>
2021-01-07 12:07:28 +00:00
Víctor Manuel Jáquez Leal
4625ac92b6 va: mpeg2dec: refactor the picture reference filling
Add the helper function _get_surface_id() which extracts the
VASurfaceID from the passed picture. This function gets the surface of
the next and previous reference picture.

Instead of if-statements, this refactor uses a switch-statement with a
fall-through, for P-type pictures, making the code a bit more readable.

Also it adds quirks for gallium driver, which cannot handle invalid
surfaces as forwarding nor backwarding references, so the function fails.
Also iHD cannot handle them, but to avoid failing, the current picture
is used as self-reference.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1939>
2021-01-06 17:27:10 +01:00
Víctor Manuel Jáquez Leal
aff338bb24 va: mpeg2dec: set first field either frame or has a first field
Add a helper function _is_frame_start() which check if picture has a
frame structure or if it has not an interlaced first field yet. This
function is used with filling is_first_field parameter.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1939>
2021-01-06 17:27:10 +01:00
Víctor Manuel Jáquez Leal
df6c4843a7 va: display: parse and set driver implementation
This enum can be used for quirk handling. It's not a property because
the driver enum list might change, it's not static, thus avoiding the
update of GType declaration.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1938>
2021-01-05 17:54:34 +00:00
Víctor Manuel Jáquez Leal
543d54d492 va: display: add function precondition check
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1938>
2021-01-05 17:54:34 +00:00
He Junyan
4c66a0265c va: mpeg2dec: Using the current picture's surface when missing reference.
When missing the reference frames, we should not just discard the current
frame. Some streams have group of picture header. It is an optional header
that can be used immediately before a coded I-frame to indicate to the decoder
if the first consecutive B-pictures immediately following the coded I-frame can
be reconstructed properly in the case of a random access.
In that case, the B frames may miss the previous reference and can still be
correctly decoded. We also notice that the second field of the I frame may
be set to P type, and it only ref its first field.
We should not skip all those frames, and even the frame really misses the
reference frame, some manner such as inserting grey picture should be used
to handle these cases.

The driver crashes when it needs to access the reference picture while we set
forward_reference_picture or backward_reference_picture to VA_INVALID_ID. We
now set it to current picture to avoid this. This is just a temp manner.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1929>
2021-01-04 13:09:01 +00:00
He Junyan
b2b0483d03 va: mpeg2dec: Apply buffer_flags to the output buffer.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1929>
2021-01-04 13:09:01 +00:00
Haihao Xiang
1f1a5b4ad1 msdkenc{h264,h265}: add min-qp and max-qp properties
The SDK allows user to set a QP range [1], so add min-qp and max-qp to
sepecify QP range. By default, there is no limitations on QP.

[1] https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#mfxextcodingoption2

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1908>
2020-12-30 06:40:36 +00:00
Haihao Xiang
7bc3d51b42 msdkenc{h264,h265}: add p-pyramid property
The SDK can support P-Pyramid reference structure [1], so add a new
property to enable this feature in msdkenc{h264,h265}.

[1] https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#preftype

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1908>
2020-12-30 06:40:36 +00:00
Haihao Xiang
af988e282a msdkh265enc: add b-pyramid property
Like as msdkh264enc, b-pyramid is added to enable B-Pyramid reference
structure for H265 encoding

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1908>
2020-12-30 06:40:36 +00:00
Haihao Xiang
ff206f6525 msdkh265enc: add transform-skip property
Since the SDK API 1.26, TransformSkip was added to control
transform_skip_enabled_flag setting in PPS [1]

[1] https://github.com/Intel-Media-SDK/MediaSDK/blob/master/doc/mediasdk-man.md#mfxextcodingoption3

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1908>
2020-12-30 06:40:36 +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
Seungha Yang
68a47eb316 d3d11compositor: Add support for resolution change
Not only for position update (e.g., xpos, ypos),
we need to configure shader again per resolution change of each
input stream.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1912>
2020-12-28 16:05:20 +00:00