2012-06-26 08:50:08 +00:00
|
|
|
#include <gst/gst.h>
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2022-12-13 17:42:11 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <TargetConditionals.h>
|
|
|
|
#endif
|
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* playbin2 flags */
|
2019-02-07 19:32:58 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GST_PLAY_FLAG_VIS = (1 << 3) /* Enable rendering of visualizations when there is no video stream. */
|
2012-06-26 08:50:08 +00:00
|
|
|
} GstPlayFlags;
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Return TRUE if this is a Visualization element */
|
2019-02-07 19:32:58 +00:00
|
|
|
static gboolean
|
|
|
|
filter_vis_features (GstPluginFeature * feature, gpointer data)
|
|
|
|
{
|
2012-06-26 08:50:08 +00:00
|
|
|
GstElementFactory *factory;
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
if (!GST_IS_ELEMENT_FACTORY (feature))
|
|
|
|
return FALSE;
|
|
|
|
factory = GST_ELEMENT_FACTORY (feature);
|
|
|
|
if (!g_strrstr (gst_element_factory_get_klass (factory), "Visualization"))
|
|
|
|
return FALSE;
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2019-02-07 19:32:58 +00:00
|
|
|
int
|
2022-12-13 17:42:11 +00:00
|
|
|
tutorial_main (int argc, char *argv[])
|
2019-02-07 19:32:58 +00:00
|
|
|
{
|
2012-06-26 08:50:08 +00:00
|
|
|
GstElement *pipeline, *vis_plugin;
|
|
|
|
GstBus *bus;
|
|
|
|
GstMessage *msg;
|
|
|
|
GList *list, *walk;
|
2012-06-26 11:25:16 +00:00
|
|
|
GstElementFactory *selected_factory = NULL;
|
2012-06-26 08:50:08 +00:00
|
|
|
guint flags;
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Initialize GStreamer */
|
|
|
|
gst_init (&argc, &argv);
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Get a list of all visualization plugins */
|
2019-02-07 19:32:58 +00:00
|
|
|
list =
|
|
|
|
gst_registry_feature_filter (gst_registry_get (), filter_vis_features,
|
|
|
|
FALSE, NULL);
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Print their names */
|
2019-02-07 19:32:58 +00:00
|
|
|
g_print ("Available visualization plugins:\n");
|
2012-06-26 08:50:08 +00:00
|
|
|
for (walk = list; walk != NULL; walk = g_list_next (walk)) {
|
|
|
|
const gchar *name;
|
2012-06-26 11:25:16 +00:00
|
|
|
GstElementFactory *factory;
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
factory = GST_ELEMENT_FACTORY (walk->data);
|
|
|
|
name = gst_element_factory_get_longname (factory);
|
2019-02-07 19:32:58 +00:00
|
|
|
g_print (" %s\n", name);
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 11:25:16 +00:00
|
|
|
if (selected_factory == NULL || g_str_has_prefix (name, "GOOM")) {
|
|
|
|
selected_factory = factory;
|
|
|
|
}
|
2012-06-26 08:50:08 +00:00
|
|
|
}
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Don't use the factory if it's still empty */
|
|
|
|
/* e.g. no visualization plugins found */
|
2012-06-26 11:25:16 +00:00
|
|
|
if (!selected_factory) {
|
2012-06-26 08:50:08 +00:00
|
|
|
g_print ("No visualization plugins found!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 11:25:16 +00:00
|
|
|
/* We have now selected a factory for the visualization element */
|
2019-02-07 19:32:58 +00:00
|
|
|
g_print ("Selected '%s'\n",
|
|
|
|
gst_element_factory_get_longname (selected_factory));
|
2012-06-26 11:25:16 +00:00
|
|
|
vis_plugin = gst_element_factory_create (selected_factory, NULL);
|
2012-06-26 08:50:08 +00:00
|
|
|
if (!vis_plugin)
|
|
|
|
return -1;
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Build the pipeline */
|
2019-02-07 19:32:58 +00:00
|
|
|
pipeline =
|
|
|
|
gst_parse_launch ("playbin uri=http://radio.hbr1.com:19800/ambient.ogg",
|
|
|
|
NULL);
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Set the visualization flag */
|
|
|
|
g_object_get (pipeline, "flags", &flags, NULL);
|
|
|
|
flags |= GST_PLAY_FLAG_VIS;
|
|
|
|
g_object_set (pipeline, "flags", flags, NULL);
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* set vis plugin for playbin2 */
|
|
|
|
g_object_set (pipeline, "vis-plugin", vis_plugin, NULL);
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Start playing */
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Wait until error or EOS */
|
|
|
|
bus = gst_element_get_bus (pipeline);
|
2019-02-07 19:32:58 +00:00
|
|
|
msg =
|
|
|
|
gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
|
|
|
|
GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
|
2016-11-05 08:18:49 +00:00
|
|
|
|
2012-06-26 08:50:08 +00:00
|
|
|
/* Free resources */
|
|
|
|
if (msg != NULL)
|
|
|
|
gst_message_unref (msg);
|
|
|
|
gst_plugin_feature_list_free (list);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
return 0;
|
|
|
|
}
|
2022-12-13 17:42:11 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
#if defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE
|
2024-02-02 11:54:32 +00:00
|
|
|
return gst_macos_main ((GstMainFunc) tutorial_main, argc, argv, NULL);
|
2022-12-13 17:42:11 +00:00
|
|
|
#else
|
|
|
|
return tutorial_main (argc, argv);
|
|
|
|
#endif
|
|
|
|
}
|