2 * winegstreamer Unix library interface
4 * Copyright 2020-2021 Zebediah Figura for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include <gst/video/video.h>
33 #include <gst/audio/audio.h>
34 #include <gst/tag/tag.h>
37 #define WIN32_NO_STATUS
41 #include "unix_private.h"
43 /* GStreamer callbacks may be called on threads not created by Wine, and
44 * therefore cannot access the Wine TEB. This means that we must use GStreamer
45 * debug logging instead of Wine debug logging. In order to be safe we forbid
46 * any use of Wine debug logging in this entire file. */
48 GST_DEBUG_CATEGORY(wine
);
50 GstElement
*create_element(const char *name
, const char *plugin_set
)
54 if (!(element
= gst_element_factory_make(name
, NULL
)))
55 fprintf(stderr
, "winegstreamer: failed to create %s, are %u-bit GStreamer \"%s\" plugins installed?\n",
56 name
, 8 * (unsigned int)sizeof(void *), plugin_set
);
60 GstElement
*find_element(GstElementFactoryListType type
, GstCaps
*src_caps
, GstCaps
*sink_caps
)
62 GstElement
*element
= NULL
;
63 GList
*tmp
, *transforms
;
66 if (!(transforms
= gst_element_factory_list_get_elements(type
, GST_RANK_MARGINAL
)))
69 tmp
= gst_element_factory_list_filter(transforms
, src_caps
, GST_PAD_SINK
, FALSE
);
70 gst_plugin_feature_list_free(transforms
);
71 if (!(transforms
= tmp
))
74 tmp
= gst_element_factory_list_filter(transforms
, sink_caps
, GST_PAD_SRC
, FALSE
);
75 gst_plugin_feature_list_free(transforms
);
76 if (!(transforms
= tmp
))
79 transforms
= g_list_sort(transforms
, gst_plugin_feature_rank_compare_func
);
80 for (tmp
= transforms
; tmp
!= NULL
&& element
== NULL
; tmp
= tmp
->next
)
82 name
= gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(tmp
->data
));
83 if (!(element
= gst_element_factory_create(GST_ELEMENT_FACTORY(tmp
->data
), NULL
)))
84 GST_WARNING("Failed to create %s element.", name
);
86 gst_plugin_feature_list_free(transforms
);
91 GST_DEBUG("Created %s element %p.", name
, element
);
95 gchar
*src_str
= gst_caps_to_string(src_caps
), *sink_str
= gst_caps_to_string(sink_caps
);
96 GST_WARNING("Failed to create element matching caps %s / %s.", src_str
, sink_str
);
104 bool append_element(GstElement
*container
, GstElement
*element
, GstElement
**first
, GstElement
**last
)
106 gchar
*name
= gst_element_get_name(element
);
107 bool success
= false;
109 if (!gst_bin_add(GST_BIN(container
), element
) ||
110 !gst_element_sync_state_with_parent(element
) ||
111 (*last
&& !gst_element_link(*last
, element
)))
113 GST_ERROR("Failed to link %s element.", name
);
117 GST_DEBUG("Linked %s element %p.", name
, element
);
128 bool link_src_to_element(GstPad
*src_pad
, GstElement
*element
)
130 GstPadLinkReturn ret
;
133 if (!(sink_pad
= gst_element_get_static_pad(element
, "sink")))
135 gchar
*name
= gst_element_get_name(element
);
136 GST_ERROR("Failed to find sink pad on %s", name
);
140 if ((ret
= gst_pad_link(src_pad
, sink_pad
)))
142 gchar
*src_name
= gst_pad_get_name(src_pad
), *sink_name
= gst_pad_get_name(sink_pad
);
143 GST_ERROR("Failed to link element pad %s with pad %s", src_name
, sink_name
);
147 gst_object_unref(sink_pad
);
151 bool link_element_to_sink(GstElement
*element
, GstPad
*sink_pad
)
153 GstPadLinkReturn ret
;
156 if (!(src_pad
= gst_element_get_static_pad(element
, "src")))
158 gchar
*name
= gst_element_get_name(element
);
159 GST_ERROR("Failed to find src pad on %s", name
);
163 if ((ret
= gst_pad_link(src_pad
, sink_pad
)))
165 gchar
*src_name
= gst_pad_get_name(src_pad
), *sink_name
= gst_pad_get_name(sink_pad
);
166 GST_ERROR("Failed to link pad %s with element pad %s", src_name
, sink_name
);
170 gst_object_unref(src_pad
);
174 NTSTATUS
wg_init_gstreamer(void *arg
)
176 char arg0
[] = "wine";
177 char arg1
[] = "--gst-disable-registry-fork";
178 char *args
[] = {arg0
, arg1
, NULL
};
179 int argc
= ARRAY_SIZE(args
) - 1;
183 if (!gst_init_check(&argc
, &argv
, &err
))
185 fprintf(stderr
, "winegstreamer: failed to initialize GStreamer: %s\n", err
->message
);
187 return STATUS_UNSUCCESSFUL
;
190 GST_DEBUG_CATEGORY_INIT(wine
, "WINE", GST_DEBUG_FG_RED
, "Wine GStreamer support");
192 GST_INFO("GStreamer library version %s; wine built with %d.%d.%d.",
193 gst_version_string(), GST_VERSION_MAJOR
, GST_VERSION_MINOR
, GST_VERSION_MICRO
);
194 return STATUS_SUCCESS
;