Commit Graph

68 Commits

Author SHA1 Message Date
Matthias Clasen
b9a7e5fa85 gstreamer: Defer the sync
Don't sync right when we receive the buffer,
pass it along with the texture to be executed
later in the renderer.
2023-04-28 06:23:45 +02:00
Benjamin Otte
fa44d258d0 media-gstreamer: Port to GdkGLTextureBuilder
This is a rudimentary port that does not take advantage of all the cool
new formats that we could support now.
2023-04-27 06:40:47 +02:00
Chun-wei Fan
b5ebe270c3 gtkgstsink.c: Drop workarounds needed for Windows
Since we are making GdkGLContext call the core wgl*() functions directly
instead of via libepoxy, drop the workarounds that we needed for notifying
libepoxy that wglMakeCurrent() outside of GDK/GTK was called.

This way, we clean up the code, and as a result, we can use the GstGL
APIs like the other platforms to query what GL api that is to be used.

For ensuring that things work between different threads, we now call
gdk_gl_context_clear_current() in place of calling wglMakeCurrent(xxx,
NULL), so that we make sure that there is no current GL context on a
thread outside of GstGL's thread, which Windows does not like.
2023-03-24 18:50:49 +08:00
Matthias Clasen
bcb0882208 modules: Stop using g_slice 2023-03-14 14:56:42 -04:00
Chun-wei Fan
432e8664e1 modules/media: Fix Visual Studio builds with older GLib
The current definitions of the g_io_module_*() symbols do not build on
Visual Studio when building against GLib earlier than 2.75.0 due to the
way how these symbols are decorated in the GLib headers, as Visual Studio
does not allow symbols that were previously marked with 'extern' (or so)
to be marked with anything that is symantically different later.

As a result, if we are using Visual Studio and glib-2.74.x or earlier,
override _GLIB_EXTERN as appropriate in the modules/media sources before
including the GIO headers.  This sadly, means that we need a
configure-time check as it would have been too late if we checked the
GLib version using G_VERSION_CHECK macro, as the GIO headers would have
been included already.

There are similar items in the print backends, but we will not attempt
to update these files as they are not meant to be built for Windows.
2023-03-07 15:36:42 +08:00
Matthias Clasen
7430bd7780 gstreamer: Fix gl context use
We were not activating the context in which
we want to wait for the fence. This caused
a stream of critical warnings.

Fixes: #5586
2023-02-12 19:29:04 -05:00
Matthias Clasen
69eed999bb gst: Rename a field for clarity
gst_gdk_context is clearer than gst_app_context. Maybe
2023-01-30 15:01:31 -05:00
Matthias Clasen
55f7f7d0ee gst: Fix synchronization
It does not make sense to sync and wait in the
same context, that is just a no-op. The intention
of this code clearly was to sync in the gst
context, and wait in the gdk one.

That also matches what the gtk sink implementation
in gstreamer does.
2023-01-30 12:04:49 -05:00
Matthias Clasen
0a6f3944a0 Revert "modules: Fix build on Visual Studio"
This reverts commit acd9c12667.

This commit breaks the build with GLib main on all platforms,
and defining _GLIB_EXTERN arguably invades the GLib namespace.

A different fix for msvc will have to be found.
2022-10-31 20:20:32 -04:00
Matthias Clasen
e499a09759 Drop gtkintl.h
Include gtkprivate.h for I_() and glib-i18n.h for
gettext macros.
2022-09-24 10:03:37 -04:00
Stephan Vedder
83ff85d227 ffmpeg: add audio playback through avdevice 2022-08-04 10:49:44 +00:00
Stephan Vedder
1c8bddf3ca ffmpeg: Fix crash on some media files
Return code EAGAIN expects the user to feed more packets into the decoder
2022-07-04 13:29:09 +02:00
Sophie Herold
a546ae32d7 Remove all nicks and blurbs from param specs
Those property features don't seem to be in use anywhere.
They are redundant since the docs cover the same information
and more. They also created unnecessary translation work.

Closes #4904
2022-05-11 18:16:29 +02:00
Benjamin Otte
25520964af ffmpeg: Hey, this variable is const now! 2022-04-26 19:39:20 +02:00
Matthias Clasen
ddba7f8601 Apply 1 suggestion(s) to 1 file(s) 2022-03-24 17:16:11 +00:00
Caolán McNamara
82f57c6a93 GtkMediaStream with gstreamer backend isn't 'prepared' until media is played
This seems to be a problem since:
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3565

To demo the problem, the video demo in gtk4-demo is currently set to
autoplay, but it doesn't autoplay on load as expected because the
"prepared" notification doesn't fire until the user explicitly presses
play.

Similarly if the demo is tweaked to disable autoplay then on loading a
video (or an audio-only ogg) the duration is not known or shown until
the user presses play.

In LibreOffice we want to know what the size of the video is to position
it before the user can interact with it to set it to play. We can
workaround this to some degree by listening to "invalidate-size" on the
GtkMediaStream object which updates for videos, but that doesn't wor
for audio-only streams.

So restore listening to media-info-updated but ignore -1 (which I see
for audio-only where I get -1 and then a useful value) and 0 of the
original report.

see also:
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3550

GNOME/gtk!4513
2022-03-09 16:29:11 +00:00
Christian Hergert
7ec9c5181d media: support OpenGL-based video playback on macOS
If we have GStreamer on macOS we likely have support for CGL to get an
OpenGL context we can use. This provides the missing pieces to get
accelerated video playback in gtk4-widget-factory working.
2022-02-16 21:31:20 -08:00
Timm Bäder
b74d3c2221 gtkgstpaintable: Handle a NULL value
gst_element_factory_make can return NULL.
2022-02-16 10:02:24 +01:00
Luca Bacci
ef1905a665
post install: query media modules 2022-01-14 18:57:03 +01:00
Ivan Molodetskikh
604541863c gstmediafile: Correctly report unknown duration
When loading .mp3 files the duration is initially unknown. Before this
change it was reported as a large integer (since GST_CLOCK_TIME_NONE is
-1). Now it's correctly reported as 0.
2021-12-04 11:48:30 +03:00
Matthias Clasen
96e837ae9f Improve a msgid
Instead of gl-context, say "GL Context".

Fixes: #4248
2021-10-18 08:35:54 -04:00
Xavier Claessens
2c060663cf media: Check for gstreamer verion instead of using cc.links()
This fix error when gstgl_dep comes from a subproject because in that
case it cannot be used in compiler checks.
2021-09-01 12:04:05 -04:00
Matthias Clasen
00763e5af3 media: Don't include gsk/gl/gskglrenderer.h 2021-08-22 12:29:40 -04:00
Matthias Clasen
3227aa2c45 mediastream: Rename apis one more time
Before we end up with names that we are unhappy with,
rename things one more time, and update all callers.
2021-07-03 09:05:33 -04:00
Timm Bäder
106417ada7 gtkffmediafile: Fix deprecated API usage 2021-07-02 18:41:55 +02:00
Matthias Clasen
96fc5dc3a7 mediastream: Some more api renaming
Also rename gtk_media_stream_ended to
gtk_media_stream_set_ended, to avoid naming
collision with GtkMediaStream:ended.

The existing entry points still exist, deprecated
and marked as non-introspectable.

Update all internal uses.

Fixes: #4023
2021-06-15 18:33:23 -04:00
Matthias Clasen
86b5dba43b mediastream: Rename an api to avoid name collisions
Some bindings can't handle the coexistence of
GtkMediaStream:prepared and gtk_media_stream_prepared.
Help them out by renaming the function to
gtk_media_stream_set_prepared, and rename
gtk_media_stream_unprepared as well, to match.

The existing entry points still exist, deprecated.

Update all internal uses.

Fixes: #4023
2021-06-14 07:50:12 -04:00
Chun-wei Fan
16f307b305 media-gstreamer: Provide fallback mode for playback
Make the "gl-context" property of the GstGLSink readable as well so that
we can query whether the GstGLContext sharing really succeeded.  If it
did, then we proceed to playback our video using the glimagesink as we
did before.  If it didn't, throw out the GtkGstSink we were creating, and
re-create the GtkGstSink without the "gl-context" property, meaning that
we won't be using the glimagesink in this case.
2021-05-24 19:04:37 +08:00
Chun-wei Fan
ccdec5da77 gtkgstsink.c: Support EGL on Windows as well
Add support to look for and use the EGL context in Windows if it was activated
instead of desktop OpenGL.

GstGL may have been built with or without EGL/libANGLE support, so if it were,
check in GstGL whether we have gst_gl_display_new_with_type() to create a
GstGLDisplay that is of the GST_GL_WINDOW_WIN32 type when we are using
Desktop OpenGL (WGL), otherwise we show messages indicating that envvars
need to be set to initialize GstGL properly.

Due to a bug in GstGL, the GstGLContext can only be set up successfully
if one of the following is true:

*  An OpenGL 3.x or later emulator, such as Mesa is used (for WGL)
*  The latest GstGL master is being used, at the time of writing (for
   WGL)
*  GTK, libepoxy and GstGL are all built only with WGL support (for WGL)
*  EGL is being used in GTK at runtime

Special thanks to Matthew Waters for the help during the process.
2021-05-24 19:04:14 +08:00
Chun-wei Fan
52d1c0c271 media/gstreamer: Support using GL for video for Windows
Add support to share the WGL context in GDK with the WGL context in GStreamer,
so that we can also use OpenGL in the gstreamer media backend to playback
videos.  For now OpenGL/ES is not supported for this under Windows.

The process of setting this up in Windows is a little bit more involved, as:

*  The OpenGL support in GstGL requires a GL 4.1 Core context, but we may just
   get the GL version from wglCreateContextAttribsARB() that we pass into the
   attributes, which is 3.2 by default.  So, try to ask for a 4.1 Core context
   first if we are asking for anything less.

*  There is only one GstDisplay available for Windows, so we just use
   gst_gl_display_new().

*  We must explicitly tell libepoxy that we are using wglMakeCurrent() outside
   of libepoxy that is being used in GdkGL, otherwise we would end up crashing
   as the GL/WGL function pointers would become invalid.

*  We must also deactivate temporarily the underlying WGL context that was made
   current by gdk_gl_context_make_current() so that when
   gst_gl_display_create_context() calls wglShareLists(), we won't get bitten
   by error 0xaa (resource busy), as some drivers don't handle this well when
   the GL context is current in another thread.

For the last two points we make use of macros defined by the platforms that the
build is done for to help us carry out the necessary tasks as needed.

Thanks to Matthew Waters for the info on integrating GstGL and windowing
toolkits on Windows.
2021-05-24 16:36:40 +08:00
Ivan Molodetskikh
12a9a0faf7 gtkgstmediafile: Remove media-info-updated callback
Instead, rely on position-updated which is also called always, and also
a little later than media-info-updated, giving GstPlayer time to figure
out more of the video info. Tested on local and remote mount videos,
images, sound files.

Works around / fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/3913,
https://gitlab.gnome.org/GNOME/gtk/-/issues/3914.
2021-05-19 18:55:37 +03:00
Rafał Dzięgiel
bbd4ee2986
meson: Do not enforce GStreamer EGL lib
GStreamer EGL headers are handled by GstGL lib.
No need to additionally import them.
2021-05-15 14:03:23 +02:00
Rafał Dzięgiel
c51eb7665e
gtkgstsink: Support EGL under x11
Add support for EGL under x11 windowing system to GStreamer sink
2021-05-14 19:29:00 +02:00
Ivan Molodetskikh
03ca7081df gtkgstmediafile: Fix callback argument type 2021-05-01 18:17:40 +03:00
Matthias Clasen
187072c3fa media: Fix a memory leak
This was introduced in e7dc82fa32.
2021-04-10 09:02:59 -04:00
Benjamin Otte
e7dc82fa32 gstmedia: Properly detect stream metadata when preparing
We can look at the GstPlayerMediaInfo to get all the info we care about.
2021-03-30 22:26:26 +02:00
Benjamin Otte
6569a877d8 Merge branch 'wip/otte/for-master' into 'master'
Wip/otte/for master

Closes #3810

See merge request GNOME/gtk!3366
2021-03-29 15:41:55 +00:00
Benjamin Otte
06be1f8b52 gstmedia: Ensure we prepare files without duration
In particular this fixes playback of images.

Fixes #3810
2021-03-29 17:08:34 +02:00
Matthias Clasen
60ccae000b media: Always use GL with gstreamer
As long as we can create a GL context, pass one to
gstreamer. This at least gets us GL textures with
the ngl renderer, the previous code was arbitrarily
refusing that.
2021-03-17 16:28:12 -04:00
David Lechner
b509809f34 meson: use correct module file extension on macOS
GModule requires the .so file extension on macOS for historic reasons.
However Meson defaults to .dylib for modules, so we need to override
it to get the correct extension.

Fixes #3645.
2021-02-05 16:54:28 -06:00
Jan Alexander Steffens (heftig)
4644dab081
gtkgstsink: Sync texture before handing it to GDK
We need to synchronize when moving the texture between contexts, or we
get glitches with VA-API decoding.
2021-01-29 18:58:17 +01:00
Jan Alexander Steffens (heftig)
00fd60aaa8
gtkgstsink: Use video_frame_free also for the GL path
The video frame needs to stay mapped while the texture is in use.

Avoid using g_memdup because the structure is not supposed to be moved.
2021-01-26 20:30:47 +01:00
Jan Alexander Steffens (heftig)
c7a7d0582a
gtkgstsink: Report allocation size even if no pool requested
We can do that so we should.
2021-01-26 20:30:47 +01:00
Chun-wei Fan
2b8ad6c4b5 gtkffmediafile.c: Use g_snprintf()
Visual Studio 2013 is just shy of being sufficiently C99-compliant to
build GTK master, as it did not support snprintf() in its CRT
implementation.

Use g_snprintf() to cover for this.
2021-01-08 22:24:42 -05:00
Matthias Clasen
0eab4deab0 Merge branch 'media-caps' into 'master'
media: Be more specific in our caps

See merge request GNOME/gtk!3037
2021-01-05 21:34:27 +00:00
Matthias Clasen
532b8c71a8 media: Be more specific in our caps
We can only handle 2D textures, so tell gstreamer
about that.
2021-01-05 09:28:04 -05:00
Chun-wei Fan
397a71ca8b gstreamer media backend: Disable OpenGL on Windows
...for at least WGL, since we are not allowed to use wglMakeCurrent(),
which is eventually called by gdk_gl_context_make_current() to share WGL
contexts across different threads, which will cause a crash.

This means, we cannot enable WGL in the gstreamer media backend on
Windows.
2021-01-05 14:34:06 +08:00
Matthias Clasen
536a67ec96 media: Only force GL if we're using a GL renderer
When we are not using a GL renderer, getting GL textures
is no advantage to us, so don't make gstreamer send its
frames as GL memory in this case.
2021-01-04 15:01:19 -05:00
Matthias Clasen
53fe751371 media: Convince gstreamer to deliver GL memory
Use a glsinkbin to make gstreamer deliver GL memory.
2021-01-04 15:00:36 -05:00
Benjamin Otte
7901ab857b media: Add support for OpenGL to GtkGstMediaFile 2021-01-04 15:00:36 -05:00