Commit graph

3681 commits

Author SHA1 Message Date
Seungha Yang 4d02858f66 d3d11videosink: Fix fallback buffer copy
Since we don't use dynamic texture now, cpu access to the fallback
texture should not happen.
2020-02-05 00:52:48 +00:00
Seungha Yang 2aa9f0bd6c d3d11window: Don't create swapchain again per caps change
Creating swapchain is relatively heavy operation. If output dxgi format
is not being chagned, we don't need to destroy and create swachain again.
2020-02-05 00:52:48 +00:00
Seungha Yang c1d2d9171d d3d11window: Invoke initial resize method from baseclass
... instead of calling from subclass in order for baseclass to handle
more things between swapchain creation and resource creation.
2020-02-05 00:52:48 +00:00
Seungha Yang 7aad9187e4 d3d11videosink: Use ID3D11VideoProcessor interface
...for color space conversion if available

ID3D11VideoProcessor is equivalent to DXVA-HD video processor
which might use specialized blocks for video processing
instead of general GPU resource. In addition to that feature,
we need to use this API for color space conversion of DXVA2 decoder
output memory, because any d3d11 texture arrays that were
created with D3D11_BIND_DECODER cannot be used for shader resource.

This is prework for d3d11decoder zero-copy rendering and also
for conditional HDR tone-map support.
Note that some Intel platform is known to support tone-mapping
at the driver level using this API on Windows 10.
2020-02-05 00:52:48 +00:00
Seungha Yang 122a9b93eb d3d11: Add video processor object
ID3D11VideoProcessor interface provides various image conversion
methods. Note that it's analogous to VAAPI VPP.
2020-02-05 00:52:48 +00:00
Seungha Yang a967db3b20 d3d11format: Add util methods for mapping DXGI color space with ours
Move color space mapping and hdr10 metadata conversion methods to
d3d11format in order to reuse the code.
2020-02-05 00:52:48 +00:00
Seungha Yang 3f4a84bd32 nvenc: Query maximum supported API version
We've been using NvEncodeAPICreateInstance method to find the supported API
version, but that seems to be insufficient since there is a case
where plugin failed in opening encoding session even if NvEncodeAPICreateInstance
succeeded. Asking driver about the version would be the most certain way.
2020-02-03 14:15:28 +00:00
Nicolas Dufresne 115b65d1ab kmssink: Fix crash with force-modesetting=1
This is a master regression, we would allocate a bo without having
created the allocator yet. As of now, we lazily create the allocator.
2020-01-31 10:01:51 -05:00
Seungha Yang 5d160a8968 msdkdec: Fix GstMsdkContext leak 2020-01-29 15:35:21 +09:00
Seungha Yang a8fff639c8 msdk: Clear reference counted object in dispose() method
Follow GObject's memory management model
2020-01-29 15:35:21 +09: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
Seungha Yang e97ef8a562 d3d11window_win32: Let DXGI choose client area
Don't specify the resolution of backbuffer. Then dxgi will let us know the
actual client area. When upstream resolution is chagned, updating the size
of backbuffer without the consideration for client size would cause mismatch
between them.
2020-01-26 12:13:24 +00:00
Nicolas Dufresne d393232bc2 nvdec: Do not map GStreamer discont to CUVid discont
Setting the CUVID_PKT_DISCONTINUITY implies clearing any past information
about the stream in the decoder. The GStreamer discont flag is used for
discontinuity caused by a seek, for first buffer and if a buffer was
dropped. In the first two cases, the parsers and demuxers should ensure we
start from a synchronization point, so it's unlikely that delta will be
matched against the wrong state.

For packet lost, the discontinuity flag will prevent the decoder from doing
any concealment, with a result that ca be much worst visually, or freeze the
playback until an IDR is met. It's better to let the decoder handle that for
us.

Removing this flag, also workaround a but in NVidia parser that makes it
ignore our ENDOFFRAME flag and increase the latency by one frame.
2020-01-25 13:39:03 +00:00
Nicolas Dufresne a28ce16b3f nvdec: Tell the parser we have complete pictures
This sets the CUVID_PKT_ENDOFPICTURE flag in order to inform the decoder that
we have a complete picture. This should remove one frame latency otherwise
introduce by NVidia parser.
2020-01-25 13:39:03 +00:00
Seungha Yang 20d85c95d0 d3d11window_corewindow: Always call methods of CoreWindow interface from UI thread
Like swapchain panel implementation, most methods of CoreWindow
should be called from UI thread.
2020-01-23 03:49:19 +00:00
Haihao Xiang e3ebebc20b msdk: Fix compiler warning
This patch fixed compiler warning below:

[1/4] Compiling C object 'sys/msdk/dc44ea0@@gstmsdk@sha/gstmsdkvpp.c.o'.
../../gst-plugins-bad/sys/msdk/gstmsdkvpp.c: In function
‘gst_msdkvpp_context_prepare’:
../../gst-plugins-bad/sys/msdk/gstmsdkvpp.c:214:7: warning: suggest
parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’
[-Wparentheses]
2020-01-21 18:37:10 +00:00
Seungha Yang a10f26aa3a nvenc: Do not access to broken encode session
If an encode session failed in initializing, the encode
session would be broken and the next nvenc API will cause crash.

Fixes: https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/1179
2020-01-21 16:34:41 +09:00
Nirbheek Chauhan 1bcf44bb1f msdk: Fix increasing memory usage in dynamic pipelines
Our context is non-persistent, and we propagate it throughout the
pipeline. This means that if we try to reuse any gstmsdk element by
removing it from the pipeline and then re-adding it, we'll clone the
mfxSession and create a new gstmsdk context as a child of the old one
inside `gst_msdk_context_new_with_parent()`.

Normally this only allocates a few KB inside the driver, but on
Windows it seems to allocate tens of MBs which leads to linearly
increasing memory usage for each PLAYING->NULL->PLAYING state cycle
for the process. The contexts will only be freed when the pipeline
itself goes to `NULL`, which would defeat the purpose of dynamic
pipelines.

Essentially, we need to optimize the case in which the element is
removed from the pipeline and re-added and the same context is re-set
on it. To detect that case, we set the context on `old_context`, and
compare it to the new one when preparing the context. If they're the
same, we don't need to do anything.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/946
2020-01-21 00:38:41 +00:00
Nirbheek Chauhan 6834a12112 msdk: Reorganize context preparation code
Split it out into a separate function with early exits to make the
flow clearer, and document what the function is doing clearly.
No functional changes.
2020-01-21 00:38:41 +00:00
Nirbheek Chauhan e83d5fd8d6 msdk: Fix warning about unused variable on Windows 2020-01-21 00:38:41 +00:00
Nirbheek Chauhan c0d778c2c7 msdk: Use gst_clear_object()
`gst_object_replace()` is not supposed to be used for unreffing and
NULLing objects.
2020-01-21 00:38:41 +00:00
Nirbheek Chauhan bda687344b nvcodec: Print debug info when initializing nvenc
We weren't printing the return value.
2020-01-20 17:15:55 +05:30
Nirbheek Chauhan 1a7ea45ffd nvcodec: Fix crash on 32-bit Windows
We weren't using the correct calling convention when calling CUDA and
CUVID APIs. `CUDAAPI` is `__stdcall` on Windows. This was working fine
on x64 because `__stdcall` is ignored and there's no special calling
convention. However, on x86, we need to use `__stdcall`.
2020-01-20 17:15:55 +05:30
Nirbheek Chauhan 7e93ae0638 nvcodec: cuda.h only needs glib.h, not gst.h
Just a nitpick. Also, force the compiler to use our stub header
instead of searching for it in the include paths.
2020-01-20 15:10:51 +05:30
Josep Torra ef37446460 msdkdec: align frame list using decoded timestamp
Before this change decoder used the oldest frame in the list to pair it
with the decoded surface. This only works when there's a perfect stream
like HEADERS,SYNCPOINT,DELTA...

When playing RTSP streams we can get imperfect streams like HEADERS,
DELTA,SYNCPOINT,DELTA... In this case decoder drops the frames
between HEADERS and SYNCPOINT which leads into using wrong PTS on
the output frames.

With this change we inject the input PTS into the bitstream and use it
to align the internal frame list with the actually decoded position.

Fixes playback with:
```
gst-launch-1.0 rtspsrc location=... latency=0 drop-on-latency=1 ! ...
```
2020-01-19 04:26:15 +00:00
Seungha Yang e8d527df93 nvenc: Query supported minimum resolution
Hard-coded 16x16 resolution is likely to differ from the device's support
in most cases. If we can use NV_ENC_CAPS_WIDTH_MIN and NV_ENC_CAPS_HEIGHT_MIN,
update pad template with returned value.
2020-01-16 15:24:03 +00:00
Seungha Yang 58a663c1e5 nvcodec: Bump SDK header to version 9.1
Update header to query minimum resolution of encoder and to control
the number of reference frame if it's supported
2020-01-16 15:24:03 +00:00
Haihao Xiang 52abbeeefb msdkdec: support transform_meta virtual method
Allow the base class to copy GstVideoRegionOfInterestMeta data to the
output buffer when calling gst_video_decoder_finish_frame
2020-01-15 00:47:12 +00:00
Haihao Xiang 8512624a41 msdkenc: set ROI region for msdk{h264, h265}enc
A reconfig is needed when ROI is changed, otherwise the ROI parameters won't
take effect
2020-01-15 00:47:12 +00:00
Haihao Xiang 84e234a8c7 msdkenc: add set_extra_params virtual method
set_extra_params is added to allow sub class to add extra mfx parameters
for changed input frame or meta data
2020-01-15 00:47:12 +00:00
Haihao Xiang 0e2fc39f24 msdkenc: add need_reconfig virtual method
need_reconfig is added to allow sub class requires a reconfig when
the input frame or the MetaData (e.g. GstVideoRegionOfInterestMeta)
attached to the input frame is changed.
2020-01-15 00:47:12 +00:00
Seungha Yang 6e73e762c5 d3d11h265dec: Fix wrong NoRaslOutputFlag setting
... and handle EOS and EOB nals.

Only the first CRA picture should be associated with NoRaslOutputFlag
as the comment in code.
2020-01-14 08:47:30 +00:00
Nirbheek Chauhan b7d91711f7 ipcpipeline: Minimal fixes that allow building with MSVC 2020-01-14 09:23:02 +05:30
Nirbheek Chauhan c8db7a9127 ipcpipeline: Rework compiler checks
`pipe()` isn't used since 15927b6511,
and `socketpair()` from `#include <sys/socket.h>` is used only in the
examples. In practice, you can use probably also use anything that
allows you to create fd pairs, such as named pipes or anonymous pipes.

We use the cross-platform GstPollFD API in the plugin.
2020-01-14 09:23:02 +05:30
Seungha Yang 96f0f4b613 d3d11memory: Always use native DXGI format if device support it
Use consistent memory layout between dxva and other shader use case.
For example, use DXGI_FORMAT_NV12 texture format instead of
two textures with DXGI_FORMAT_R8_UNORM and DXGI_FORMAT_R8G8_UNORM.
2020-01-13 01:58:08 +00:00
Seungha Yang 9ee40679b5 Revert "d3d11: Add support for D3D11_USAGE_DYNAMIC"
This reverts commit ddd13fc7c0

Dynamic usage can reduce the number of copy per frame but make
things complicated and the benefit seems to not significant.
Also since we don't provide _map() method for the dynamic usage,
application cannot read buffers which make "last-sample" property
unusable in case of d3d11videosink.
2020-01-13 01:58:08 +00:00
Seungha Yang e188893963 d3d11: Don't register decoders if unavailable
DXVA requires a hardware interface but may not be available,
such as in the case of VMs or when the GPU vendor does not provide a decoder interface.
2020-01-11 17:42:04 +09:00
Seungha Yang 616082d14a d3d11decoder: Don't return not initialized object from _new() method
... and change some debug levels since initialization failure might not be fatal.
2020-01-11 17:42:04 +09:00
Nicolas Dufresne 6d6e897762 decklink: Silence no driver / no SO messages
This g_once() is called everywhere, even in provider. This cause
spurious error when device monitor is used. Just silence or remove
the spurious logs.
2020-01-10 08:00:05 +00:00
Haihao Xiang bdf9a76226 Revert "msdkdec: make sure to use video memory on Linux"
Commit a1584b6 caused big performance drop if the downstream element
is not a msdk element because it is very slow to read data from video
memory directly.

This reverts commit a1584b6f99.
2020-01-10 01:36:40 +00:00
Seungha Yang 49a1f022fd d3d11colorconverter: Handle P016_LE format
P016 format is no different than P010. Not much things to add code.
2020-01-09 16:29:47 +00:00
Seungha Yang bbab229905 d3d11colorconverter: Add support for YUV to YUV conversion 2020-01-09 16:29:47 +00:00
Seungha Yang a122f305f9 d3d11colorconverter: Add support for RGB to YUV conversion
... and remove code for RGBx since it's not supported format
by our d3d11 implementation for now.
2020-01-09 16:29:47 +00:00
Seungha Yang da50cc4d92 d3d11format: Remove invalid format from supported format list 2020-01-09 16:29:47 +00:00
Sebastian Dröge e4389146d9 decklinkvideosink: Always configure 10 bit YUV for VANC frames
If 8 bit are required by the device/mode then it will be converted internally
by the SDK, but the SDK won't automatically convert from 8 to 10 bit. As
such, always use 10 bit VANC.

Some devices require configuring also a 10 bit video format when using
10 bit VANC is required but those would fail regardless and the
application would have to configure the correct video format.

With newer versions of the SDK this information can be retrieved via the
BMDDeckLinkVANCRequires10BitYUVVideoFrames flag but we don't use a new
enough SDK version yet to extract this information.
2020-01-09 12:54:04 +02:00
Seungha Yang e4daa2ef43 d3d11: Add support for Universal Windows Platform
Initial UWP support via new window (CoreWindow and SwapChainPanel) implementation.
2020-01-06 20:14:51 +09:00
Seungha Yang 43a8eb9e92 d3d11decoder: Fix build on non-desktop target
Although the target platform of D3D11 decoding API are both desktop and UWP app,
DXVA header is blocked by "WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
which is meaning that that's only for desktop app.
To workaround this inconsistent annoyingness, we need to define WINAPI_PARTITION_DESKTOP
regardless of target WinAPI partition.
2020-01-06 18:45:56 +09:00
Haihao Xiang 9064de27f9 msdkvp9enc: fix 10bit encoding
The codec profile should be consistent with the frame fourcc code, this
fixes pipeline below:

gst-launch-1.0 videotestsrc ! \
video/x-raw,width=320,height=240,format=P010_10LE ! msdkvp9enc ! \
fakesink
2020-01-06 03:54:57 +00:00
Haihao Xiang da22ff3846 msdkvp9enc: fix width and height
The frame width and height is rounded up to 128 and 32 since commit
8daac1c, so the width, height for initialization should be rounded up to
128 and 32 too because the MSDK VP9 encoder will do some check on width
and height.

Sample pipeline:
gst-launch-1.0 videotestsrc ! \
video/x-raw,width=320,height=240,format=NV12 ! msdkvp9enc ! fakesink
2020-01-06 03:54:57 +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