Commit graph

3689 commits

Author SHA1 Message Date
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
Julien Isorce
f578eab6fd msdkenc: renegotiate when video info changes
Renegotiation was implemented for bitrate change. We can re-use
the same sequence when video info changes except that this can be
executed right away when receiving the new input format. I.e. no
need to wait for the next call to handle_frame.
2020-01-06 01:13:28 +00:00
Philippe Normand
9f1fbd3649 decklink: Fix crash when probing without driver
If there is no decklink hardware/driver, the devices list is empty (NULL), so
this needs to be checked before iterating over the list.
2020-01-05 16:20:18 +00:00
Julien Isorce
4e6a1b9634 msdkdec: trigger renegotiation if video info changes
Useful when framerate changes. Previously it was only checking
for resolution change but renego should happen if any video
info changes.
2020-01-03 10:19:57 -08:00
Julien Isorce
a1584b6f99 msdkdec: make sure to use video memory on Linux
The block that sets use_video_memory flag is after the
the condition `if gst_msdk_context_prepare` but it
always returns false when there is no other msdk elements.
So the decoder ends up with use_video_memory as FALSE.
Note that msdkvpp always set use_video_memory as TRUE.

When use_video_memory is FALSE then the msdkdec allocates
the output frames with posix_memalign (see gstmsdksystemmemory.c).
The result is then copied back to the GstVideoPool's buffers
(or to the downstream pool's buffers if any).
When use_video_memory is TRUE then the msdkdec uses vaCreateSurfaces
to create vaapi surfaces for the hw decoder to decode into
(see gstmsdkvideomemory.c). The result is then copied to either
the internal GstVideoPool and to the downstream pool if any.
(vaDeriveImage/vaMapBuffer is used in order to read the surfaces)
2020-01-03 07:08:23 +00:00
Seungha Yang
b88af2e4fe msdkdec: Correct return value of GstVideoDecoder::flush()
Use boolean instead of GstFlowReturn as declared.
Note that since base class does not check return value of GstVideoDecoder::flush(),
this would not cause any change of behavior.
2020-01-02 12:22:07 +09:00
Haihao Xiang
a819f05851 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()
2020-01-02 00:43:36 +00:00
Seungha Yang
a139c8c7e8 d3d11: Add h265 decoder element
Some DPB management implementation is taken from gstreamer-vaapi
2019-12-31 02:13:48 +00:00
Seungha Yang
0e7b6526b8 d3d11: Add vp9 decoder element
Based on gstreamer-vaapi and Chromium implemetation.
2019-12-31 02:13:48 +00:00
Seungha Yang
586390b1ba d3d11: Add h264 decoder element
New decoder implementation based on dxva2 on d3d11 APIs. The DPB
management implementation is taken from Chromium.
2019-12-31 02:13:48 +00:00
Seungha Yang
7bfdeaf161 d3d11: Add support for Array typed texture memory
A ID3D11Texture2D memory can consist of multiple planes with array.
For array typed memory, GstD3D11Allocator will allocate new GstD3D11Memory
with increased reference count to the ID3D11Texture2D but different array index.
2019-12-31 02:13:48 +00:00
Stéphane Cerveau
add7878e14 bad: use of g_value_dup_string
Use helper method to get string from GValue.
2019-12-30 14:13:03 +00:00
Seungha Yang
81dde0f5b8 d3d11: Aggregate d3d11 memory usage query for dynamic-usage type decision
Even if one of downstream d3d11 elements can support dynamic-usage memory,
another one might not support it. Also, to support dynamic-usage,
both upstream and downstream d3d11device must be the same object.
2019-12-28 05:43:44 +00:00
Seungha Yang
d731bcb18a d3d11colorconvert: Remove device type dependent behavior
If d3d11colorconvert element is configured, do color space conversion
regardless of the device type whether it's S/W emulation or real H/W.
Since d3d11colorconvert is no more a child of d3d11videosinkbin,
we don't need this behavior. Note that previous code was added to
avoid color space conversion from d3d11videosink if no hardware
device is available (S/W emulation of d3d11 is too slow).
2019-12-28 05:43:44 +00:00
Seungha Yang
46186356ca d3d11colorconverter: Fix unmatched lock/unlock pair 2019-12-28 05:43:44 +00:00
Seungha Yang
ab80c771df d3d11upload: Don't hard overwrite caps features to support d3d11 memory passthrough
d3d11upload should be able to support upstream d3d11 memory, not only system memory.

Fix for following pipeline
d3d11upload ! "video/x-raw(memory:D3D11Memory)" ! d3d11videosink
2019-12-28 05:43:44 +00:00
Seungha Yang
5298d95195 d3d11window: Make use of partial presentation with IDXGISwapChain1::Present1
Since we might draw on partial area of backbuffer in case of force-aspect-ratio,
presenting only updated area is more efficient way.

See also https://docs.microsoft.com/ko-kr/windows/win32/direct3ddxgi/dxgi-1-2-presentation-improvements
2019-12-24 20:10:54 +09:00
Seungha Yang
487a41d312 d3d11videosink: Add support for overlay composition
Add d3d11overlaycompositor object to draw overlay image
on render target using Blend method.
2019-12-24 19:00:45 +09:00
Seungha Yang
a5295509af d3d11: Enable dxgi debug layer and always try to pop d3d11/dxgi debug message if possible
Note that dxgi and d3d11 sdk debug will be enabled on debug build
2019-12-24 19:00:40 +09:00
Seungha Yang
49bccf0433 nvcodec: Refactor plugin initialization
Create CUDA context per device, instead of per codec and encoder/decoder.
Allocating CUDA context is heavy operation so we should reuse it
as much as possible.

Fixes: https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/1130
2019-12-24 08:10:14 +00:00
Seungha Yang
0e013fe539 d3d11videosink: Use dynamic texture for fallback buffer
Upload CPU memory to texture directly by using dynamic usage texture.
This will reduce at least one step of staging copy per frame.
2019-12-20 19:21:02 +09:00
Seungha Yang
65cace22e2 d3d11colorconvert: Set TRANSFER_NEED_DOWNLOAD flag to output memory for later cpu access
Otherwise CPU cannot access texture via gst_memory_map()
2019-12-20 19:21:02 +09:00
Seungha Yang
18e13404a2 d3d11colorconvert: Use shader resource and render target bind flags together
The output of d3d11colorconvert would be used for rendering (i.e., shader resource)
2019-12-20 19:21:02 +09:00
Seungha Yang
62c8d19e01 d3d11window: Change aspect-ratio mode from window thread
Call DXGI API from window thread as much as possible
2019-12-20 19:21:02 +09:00
Seungha Yang
1b687d556a d3d11videosink: Add support for full screen mode
borderless top-most style full screen mode support.
Basically fullscreen toggle mode is disabled by default. To enable it
use "fullscreen-toggle-mode" property to allow fullscreen mode change
by user input and/or property.
2019-12-20 19:21:02 +09:00
Seungha Yang
0788492461 d3d11: Use GRecMutex to protect immediate context and dxgi API call
In some cases, rendering and dxgi (e.g., swapchain) APIs should be
called from window message pump thread, but current design (dedicated d3d11 thread)
make it impossible. To solve it, change concurrency model to locking based one
from single-thread model.
2019-12-20 19:21:03 +09:00
Seungha Yang
a0a85cd80c d3d11window: Prefer to use flip-sequential over discard
flip-sequential is more efficient than discard
2019-12-20 11:15:12 +09:00
Seungha Yang
1424de0a4a d3d11window: Don't hold backbuffer interface
We don't need to hold it
2019-12-20 11:15:12 +09:00
Seungha Yang
32d618c677 d3d11window: Use CreateSwapChainForHwnd if available
That's recommended way from MS and CreateSwapChainForHwnd supports
more options than CreateSwapChain
2019-12-20 11:15:12 +09:00
Seungha Yang
9fd0b62f2d d3d11: Use configuration file for dxgi header version check 2019-12-20 11:15:12 +09:00
Seungha Yang
23b47a7ec1 d3d11window: Use allow-tearing mode if device supports it
As the recommendation from MS.
2019-12-20 11:15:12 +09:00
Seungha Yang
72b6b3557d d3d11window: Disable fullscreen mode change by alt + enter
Disable full screen mode change until proper handling is implemented
2019-12-20 11:15:12 +09:00
Seungha Yang
9dada90108 d3d11videosink: Remove resizing window hack and unify resizing flow
In earlier implementation of d3d11videosink where no shader was implemented,
the aspect ratio and render size were adjusted by manipulating the backbuffer size
with unintuitive formula. Since now we do color conversion and resize using
shader, we can remove the hack.
2019-12-20 11:15:12 +09:00
Seungha Yang
61cb6b2bbe d3d11: Pass GstD3D11Memory object to ensure_{shader_resource,render_target}_view methods
The method name indicates it should be d3d11memory, so passing
GstD3D11Memory seems to make more sense than GstMemory.
2019-12-20 11:15:12 +09:00
Seungha Yang
7c041f1934 d3d11videosink: Don't specify crop meta to allocation query
d3d11videosink could not handle it for now
2019-12-20 11:15:12 +09:00
Aaron Boxer
c8193b1615 d3dvideosink: hold class lock for entire duration of class destruction
This avoids a race condition currently when temporarily releasing the
lock and then re-acquiring.
2019-12-18 13:15:06 -05:00
Aaron Boxer
7cb6dbefba d3dvideosink: improve concurrency on hidden window create/destroy 2019-12-18 13:15:06 -05:00
Aaron Boxer
eff0117b5a d3dvideosink: use thread pool to handle events from hidden window event queue
window event queue now does not lock on the class lock, so we can now shut
it down without releasing the class lock, thus avoiding a potential race when
stopping the sink.
2019-12-18 13:15:06 -05:00
Aaron Boxer
027eb5ef20 d3dvideosink: improve concurrency on internal window create/destroy
Remove timeout and rely on condition variable instead to indicate thread
start.
2019-12-18 13:15:06 -05:00
Aaron Boxer
adfbce336a d3dvideosink: only warn about HWND already set if new HWND is not NULL 2019-12-18 13:15:06 -05:00
Aaron Boxer
84403dbae3 d3dvideosink: add more null checks 2019-12-18 13:15:05 -05:00
Aaron Boxer
06862d7ff5 d3dvideosink: check ref count and device before resetting display 2019-12-18 13:15:05 -05:00
Aaron Boxer
85c1550b92 d3dvideosink: use class lock when checking d3d formats, and cache format list 2019-12-18 13:15:05 -05:00
Aaron Boxer
d7af30bab9 d3dvideosink: destroy device just before final d3d release call
and free overlays after swap chain is released
2019-12-18 13:15:05 -05:00
Aaron Boxer
5e3520a302 d3dvideosink: add two forward declarations 2019-12-18 13:15:05 -05:00
Aaron Boxer
49211bdf74 d3dvideosink: use class lock when setting pool config 2019-12-18 13:15:05 -05:00
Aaron Boxer
fb6c2e8533 d3dvideosink: use class lock when allocating pool buffer 2019-12-18 13:15:05 -05:00
Aaron Boxer
52254ad31c d3dvideosink: use class lock when creating overlay textures 2019-12-18 13:15:05 -05:00
Aaron Boxer
51f823c98a d3dvideosinnk: check d3d device exists before creating overlay vertex buffer 2019-12-18 13:15:05 -05:00
Aaron Boxer
8710eb0656 d3dvideosink: pass hidden window hwnd to GST_DEBUG, rather than NULL 2019-12-18 13:15:05 -05:00
Aaron Boxer
54ce3d5011 d3dvideosink: fix typo 2019-12-18 13:15:05 -05:00
Seungha Yang
64eb1d46b5 d3d11window: Always draw to internal window
... and use SetParent() WIN32 API when external window is used.
Depending on DXGI swap effect, the external window might not be
reusable by another backend. To preserve the external window's property
and setting, drawing to internal window seems to be safer way.
2019-12-16 22:24:29 +09:00
Seungha Yang
638c6d6931 d3d11window: Always set error reason to GError object 2019-12-16 18:21:02 +09:00
Julien Isorce
93bc74284f msdkdec: call finalize on the parent class
Otherwise GstVideoDecoder is not finalized and
resources are leaked.

Somehow GST_TRACERS="leaks" GST_DEBUG="GST_TRACER:7" did not catch it.

Valgrind output:

==31645== 22,480 (1,400 direct, 21,080 indirect) bytes in 5 blocks are definitely lost in loss record 5,042 of 5,049
==31645==    at 0x4C2FB0F: malloc
==31645==    by 0x51D9E88: g_malloc
==31645==    by 0x51FA7B5: g_slice_alloc
==31645==    by 0x51FAC68: g_slice_alloc0
==31645==    by 0x58D9984: g_type_create_instance
==31645==    by 0x58BA344: g_object_new_with_properties
==31645==    by 0x58BADA0: g_object_new
==31645==    by 0x8ECA966: gst_video_decoder_init
==31645==    by 0x58D99E7: g_type_create_instance
==31645==    by 0x58BA344: g_object_new_with_properties
2019-12-13 15:36:26 -08:00
Roman Shpuntov
5da2938244 avfvideosrc: element requests camera permissions even with capture-screen property is true
https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/1137

macOS has different dialogs for camera capture and screen capture.
No need to request screen capture permissions, the system detect
screen capture automatically and create request dialog.
2019-12-11 17:31:03 +00:00
Seungha Yang
a400126889 d3d11window: Initialize surface rect with given external window handle
Unlike internal window, resize event might not happen with external window.
2019-12-11 23:04:55 +09:00
Seungha Yang
a8ec409b84 d3d11device: Report alive d3d11 objects at the end
It would be useful for debugging d3d11 object leak.
2019-12-11 23:04:49 +09:00
Seungha Yang
59295b4271 d3d11: Fix ID3D11SamplerState leak 2019-12-11 12:57:46 +00:00
Stéphane Cerveau
6bc0e9527e remove various useless linefeed in logs 2019-12-11 10:51:29 +01:00
Haihao Xiang
b18be3562c msdk: ignore MFX_ERR_UNDEFINED_BEHAVIOR when loading a plugin
An issue can be seen when using msdkh265enc with bitrate change in
playing state. The root cause is the corresponding plugin is loaded
again.

Returning MFX_ERR_UNDEFINED_BEHAVIOR from MSDK just means the plugin has
been loaded, so we may ignore this error when doing configuation again
in the sub class, otherwise the pipeline will be interrupted
2019-12-10 17:23:53 +00:00
Seungha Yang
d963d442c5 d3d11videosink: Fix broken fallback rendering
Make fallback rendering work
2019-12-10 04:06:28 +00:00
Seungha Yang
abc1443cf0 d3d11videosink: Add debug message for fallback reason 2019-12-10 04:06:28 +00:00
Seungha Yang
9835289239 d3d11window: Do not check shader resource view if not doing conversion
If d3d11window does not convert format internally, shader resource view
is not required. Note that shader resource view is used for
color conversion using shader but when conversion is not required,
we just copy input input texture to backbuffer.
2019-12-10 04:06:28 +00:00
Julien Isorce
b681d6f62e msdkvpp: check mfx surface nullity for the input buffer
In theory it should not happen but it happened to me
in some cases where it failed to allocate some video
buffers so this was a consequence of a corner case.
Better to be safe than sorry.
2019-12-10 03:00:13 +00:00
Seungha Yang
8154b22a88 d3d11window: Clear old swapchain per prepare
_prepare() might be called multiple times for given window, so clear
old swapchain if any.

Fixes: https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/1138
2019-12-10 10:58:28 +09:00
Julien Isorce
3bae199863 msdkdec: fix assertion 'frame->ref_count > 0' failed
Can happen if the oldest frame is the current frame
and if gst_video_decoder_finish_frame failed in which
case the current is unref and then drop instead of
just drop.
This patch also removes some assumptions, it was strange
to call unref and finish_frame in gst_msdkdec_finish_task.
In principle when owning a frame, the code should either
unref, or drop or finish.
2019-12-09 16:10:51 +00:00
Seungha Yang
5bf10d8781 d3d11window: Always set dxgi colorspace if possible
Not only for the 10 bits RGB case with HDR metadata, set proper color space
to swapchain in order to make color representaion correct
2019-12-09 12:22:15 +00:00
Matthew Waters
526afac736 vtdec: add support for outputing vulkan images 2019-12-09 01:49:31 +00:00
Matthew Waters
acac78c1ce applemedia: rename IOSurfaceMemory -> IOSurfaceGLMemory 2019-12-09 01:49:30 +00:00
Matthew Waters
0560946c82 videotexturecache: implement GL specifics as a subclass 2019-12-09 01:49:30 +00:00
Matthew Waters
ff5ba2f126 applemedia/videocache: make a GObject subclass 2019-12-09 01:49:30 +00:00
Matthew Waters
27f4fb060d avfvideosrc: don't leak texture caches
If decide_allocation is called multiple times, then we would continually
overwrite the previous cache without freeing
2019-12-09 01:49:30 +00:00
Aaron Boxer
e9891dfe14 d3d11: translate windows error codes to human readable strings
This will help with debugging.
2019-12-07 16:09:03 -06:00
Xavier Claessens
da584995f6 mlaudiosink: Fix crash when stopping pipeline
This is a bug in LuminOS 0.97.0.
2019-12-06 15:29:29 +00:00
Xavier Claessens
380ab8123b Add mlaudiosink element 2019-12-06 15:29:29 +00:00
Sebastian Dröge
f776e2df96 decklink: Return new references to the devices from get_devices()
Otherwise the caller will free the devices we store internally.
2019-12-05 21:22:18 +02:00
Seungha Yang
4eac9d0ae6 d3dvideosink: Fix warning for unhandled enum in switch
d3dhelpers.c:135:3: warning: enumeration value 'D3DFMT_D32_LOCKABLE' not handled in switch [-Wswitch]
2019-12-05 04:31:54 +00:00
Seungha Yang
199caccc41 d3d11: Initialize debug categories of non-GstElement implementation in plugin init
That's the way to expose debug category to --gst-debug-help
2019-12-05 02:29:18 +00:00
Seungha Yang
71befc477f d3d11window: Invoke resize task with high priority
On resize event, swapchain should be configured with higher priority
than the other tasks since it's directly related to visual artifacts.
2019-12-05 02:29:18 +00:00
Seungha Yang
d2b85683de d3d11device: Add gst_d3d11_device_thread_add_full method
I would be used to invoke GPU task with specified priority.
2019-12-05 02:29:18 +00:00
Seungha Yang
7cab47ddda d3d11videosinkbin: Drop d3d11 color convert element
d3d11videosink can convert color space now, so the conversion element
seems to be redundant.
2019-12-05 02:29:18 +00:00
Seungha Yang
ca3ddf7848 d3d11videosink: Add color conversion support
Draw to back buffer texture directly. It would reduce the number of
copy at least once when color conversion is required.
2019-12-05 02:29:18 +00:00
Seungha Yang
622733ed0d d3d11converter: Skip setup converter if input and output formats are equal 2019-12-05 02:29:18 +00:00
Seungha Yang
c9cb08fcd4 d3d11colorconvert: Split color space converter to reuse code 2019-12-05 02:29:18 +00:00
Seungha Yang
42ca123f0f d3d11: Split shader to reuse code 2019-12-05 02:29:18 +00:00
Seungha Yang
59d9589722 d3d11videosink: Draw window with cached texture on resize
This would render nicer than presenting scene with broken aspect ratio,
especially in case of low framerate.
2019-12-05 02:29:18 +00:00
Seungha Yang
ddd13fc7c0 d3d11: Add support for D3D11_USAGE_DYNAMIC
D3D11 dynamic texture is a special memory type, which is mainly used for
frequent CPU write access to the texture. For now, this texture type
does not support gst_memory_{map,unmap}
2019-12-05 02:29:18 +00:00
Seungha Yang
5ce4748cc0 d3d11device: Add debug message for CreateTexture2D failure 2019-12-05 02:29:18 +00:00
Seungha Yang
914d2df79e d3d11device: Fix misreading debug message 2019-12-05 02:29:18 +00:00
Seungha Yang
71ae632b25 d3d11colorconvert: Disable color conversion with software rasterizer
It's much slower than our CPU based color-converter in most case.
2019-12-05 02:29:18 +00:00
Seungha Yang
79e88b76da d3d11videosink: Handle context query
Propagate d3d11device via context query.
2019-12-05 02:29:18 +00:00
Seungha Yang
5edf64d655 d3d11colorconvert: Avoid copy in/out texture if possible
When input and/or output d3d11memory has its own view, use them for
rendering to avoid texture copy
2019-12-05 02:29:18 +00:00
Seungha Yang
da3545e8c8 d3d11memory: Allocate texture with required views
Store required resource views with d3d11 texture when it requested.
2019-12-05 02:29:18 +00:00