mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 19:20:35 +00:00
gst-libs/gst/audio/: Add gst_audio_default_registry_mixer_filter() utility function.
Original commit message from CVS: * gst-libs/gst/audio/Makefile.am: * gst-libs/gst/audio/mixerutils.c: (gst_audio_mixer_filter_do_filter), (gst_audio_mixer_filter_check_element), (gst_audio_mixer_filter_probe_feature), (element_factory_rank_compare_func), (gst_audio_default_registry_mixer_filter): * gst-libs/gst/audio/mixerutils.h: Add gst_audio_default_registry_mixer_filter() utility function.
This commit is contained in:
parent
f6e5a1a9f2
commit
e737f441d3
5 changed files with 257 additions and 2 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2006-01-09 Tim-Philipp Müller <tim at centricular dot net>
|
||||
|
||||
* gst-libs/gst/audio/Makefile.am:
|
||||
* gst-libs/gst/audio/mixerutils.c:
|
||||
(gst_audio_mixer_filter_do_filter),
|
||||
(gst_audio_mixer_filter_check_element),
|
||||
(gst_audio_mixer_filter_probe_feature),
|
||||
(element_factory_rank_compare_func),
|
||||
(gst_audio_default_registry_mixer_filter):
|
||||
* gst-libs/gst/audio/mixerutils.h:
|
||||
Add gst_audio_default_registry_mixer_filter() utility
|
||||
function.
|
||||
|
||||
2006-01-03 Michael Smith <msmith@fluendo.com>
|
||||
|
||||
* gst/audioresample/resample.h:
|
||||
|
|
2
common
2
common
|
@ -1 +1 @@
|
|||
Subproject commit d1911d4b3d6267f9cd9dfb68fcef2afe4d098092
|
||||
Subproject commit e0b121388ece524c0b7035a72bddd191d122d8bf
|
|
@ -15,7 +15,10 @@ EXTRA_DIST = gstaudiofiltertemplate.c make_filter
|
|||
CLEANFILES = gstaudiofilterexample.c \
|
||||
$(BUILT_SOURCES)
|
||||
|
||||
libgstaudio_@GST_MAJORMINOR@_la_SOURCES = audio.c gstaudioclock.c \
|
||||
libgstaudio_@GST_MAJORMINOR@_la_SOURCES = \
|
||||
audio.c \
|
||||
gstaudioclock.c \
|
||||
mixerutils.c \
|
||||
multichannel.c \
|
||||
gstaudiofilter.c \
|
||||
gstaudiosink.c \
|
||||
|
@ -35,6 +38,7 @@ libgstaudio_@GST_MAJORMINOR@include_HEADERS = \
|
|||
gstbaseaudiosink.h \
|
||||
gstbaseaudiosrc.h \
|
||||
gstringbuffer.h \
|
||||
mixerutils.h \
|
||||
multichannel.h
|
||||
|
||||
nodist_libgstaudio_@GST_MAJORMINOR@include_HEADERS = \
|
||||
|
|
206
gst-libs/gst/audio/mixerutils.c
Normal file
206
gst-libs/gst/audio/mixerutils.c
Normal file
|
@ -0,0 +1,206 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2003-2004 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
||||
* Copyright (C) 2005-2006 Tim-Philipp Müller <tim centricular net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "mixerutils.h"
|
||||
|
||||
#include <gst/interfaces/propertyprobe.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
gst_audio_mixer_filter_do_filter (GstAudioMixerFilterFunc filter_func,
|
||||
GstElementFactory * factory,
|
||||
GstElement ** p_element, GList ** p_collection, gpointer user_data)
|
||||
{
|
||||
/* so, the element is a mixer, let's see if the caller wants it */
|
||||
if (filter_func != NULL) {
|
||||
if (filter_func (GST_MIXER (*p_element), user_data) == TRUE) {
|
||||
*p_collection = g_list_prepend (*p_collection, *p_element);
|
||||
/* do not set state back to NULL here on purpose, caller
|
||||
* might want to keep the mixer open */
|
||||
*p_element = NULL;
|
||||
}
|
||||
} else {
|
||||
gst_element_set_state (*p_element, GST_STATE_NULL);
|
||||
*p_collection = g_list_prepend (*p_collection, *p_element);
|
||||
*p_element = NULL;
|
||||
}
|
||||
|
||||
/* create new element for further probing if the old one */
|
||||
if (*p_element == NULL) {
|
||||
gst_element_factory_create (factory, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_audio_mixer_filter_check_element (GstElement * element)
|
||||
{
|
||||
GstStateChangeReturn ret;
|
||||
|
||||
/* open device (only then we can know for sure whether it is a mixer) */
|
||||
gst_element_set_state (element, GST_STATE_READY);
|
||||
ret = gst_element_get_state (element, NULL, NULL, 1 * GST_SECOND);
|
||||
if (ret != GST_STATE_CHANGE_SUCCESS) {
|
||||
GST_DEBUG ("could not open device / set element to READY");
|
||||
gst_element_set_state (element, GST_STATE_NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* is this device a mixer? */
|
||||
if (!GST_IS_MIXER (element)) {
|
||||
GST_DEBUG ("element is not a mixer");
|
||||
gst_element_set_state (element, GST_STATE_NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* any tracks? */
|
||||
if (!gst_mixer_list_tracks (GST_MIXER (element))) {
|
||||
GST_DEBUG ("element is a mixer, but has no tracks");
|
||||
gst_element_set_state (element, GST_STATE_NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GST_DEBUG ("element is a mixer with mixer tracks");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_audio_mixer_filter_probe_feature (GstAudioMixerFilterFunc filter_func,
|
||||
GstElementFactory * factory,
|
||||
GList ** p_collection, gboolean first, gpointer user_data)
|
||||
{
|
||||
GstElement *element;
|
||||
|
||||
GST_DEBUG ("probing %s ...", gst_element_factory_get_longname (factory));
|
||||
|
||||
/* create element */
|
||||
element = gst_element_factory_create (factory, NULL);
|
||||
|
||||
if (element == NULL) {
|
||||
GST_DEBUG ("could not create element from factory");
|
||||
return;
|
||||
}
|
||||
|
||||
GST_DEBUG ("created element %s (%p)", GST_ELEMENT_NAME (element), element);
|
||||
|
||||
if (GST_IS_PROPERTY_PROBE (element)) {
|
||||
GstPropertyProbe *probe;
|
||||
const GParamSpec *devspec;
|
||||
|
||||
probe = GST_PROPERTY_PROBE (element);
|
||||
|
||||
GST_DEBUG ("probing available devices ...");
|
||||
if ((devspec = gst_property_probe_get_property (probe, "device"))) {
|
||||
GValueArray *array;
|
||||
|
||||
if ((array = gst_property_probe_probe_and_get_values (probe, devspec))) {
|
||||
guint n;
|
||||
|
||||
GST_DEBUG ("there are %d available devices", array->n_values);
|
||||
|
||||
/* set all devices and test for mixer */
|
||||
for (n = 0; n < array->n_values; n++) {
|
||||
GValue *device;
|
||||
|
||||
/* set this device */
|
||||
device = g_value_array_get_nth (array, n);
|
||||
g_object_set_property (G_OBJECT (element), "device", device);
|
||||
|
||||
GST_DEBUG ("trying device %s ..", g_value_get_string (device));
|
||||
|
||||
if (gst_audio_mixer_filter_check_element (element)) {
|
||||
gst_audio_mixer_filter_do_filter (filter_func, factory, &element,
|
||||
p_collection, user_data);
|
||||
|
||||
if (first && *p_collection != NULL) {
|
||||
GST_DEBUG ("Stopping after first found mixer, as requested");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_value_array_free (array);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GST_DEBUG ("element does not support the property probe interface");
|
||||
|
||||
if (gst_audio_mixer_filter_check_element (element)) {
|
||||
gst_audio_mixer_filter_do_filter (filter_func, factory, &element,
|
||||
p_collection, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
if (element) {
|
||||
gst_element_set_state (element, GST_STATE_NULL);
|
||||
gst_object_unref (element);
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
element_factory_rank_compare_func (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
gint rank_a = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (a));
|
||||
gint rank_b = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (b));
|
||||
|
||||
return rank_b - rank_a;
|
||||
}
|
||||
|
||||
GList *
|
||||
gst_audio_default_registry_mixer_filter (GstAudioMixerFilterFunc filter_func,
|
||||
gboolean first, gpointer data)
|
||||
{
|
||||
GList *mixer_list = NULL;
|
||||
GList *feature_list;
|
||||
GList *walk;
|
||||
|
||||
/* go through all elements of a certain class and check whether
|
||||
* they implement a mixer. If so, add it to the list. */
|
||||
feature_list = gst_registry_get_feature_list (gst_registry_get_default (),
|
||||
GST_TYPE_ELEMENT_FACTORY);
|
||||
|
||||
feature_list = g_list_sort (feature_list, element_factory_rank_compare_func);
|
||||
|
||||
for (walk = feature_list; walk != NULL; walk = walk->next) {
|
||||
GstElementFactory *factory;
|
||||
const gchar *klass;
|
||||
|
||||
factory = GST_ELEMENT_FACTORY (walk->data);
|
||||
|
||||
/* check category */
|
||||
klass = gst_element_factory_get_klass (factory);
|
||||
if (strcmp (klass, "Generic/Audio") == 0) {
|
||||
gst_audio_mixer_filter_probe_feature (filter_func, factory,
|
||||
&mixer_list, first, data);
|
||||
}
|
||||
|
||||
if (first && mixer_list != NULL) {
|
||||
GST_DEBUG ("Stopping after first found mixer, as requested");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gst_plugin_feature_list_free (feature_list);
|
||||
|
||||
return g_list_reverse (mixer_list);
|
||||
}
|
32
gst-libs/gst/audio/mixerutils.h
Normal file
32
gst-libs/gst/audio/mixerutils.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2005-2006 Tim-Philipp Müller <tim centricular net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GST_AUDIO_MIXERUTILS_H__
|
||||
#define __GST_AUDIO_MIXERUTILS_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/interfaces/mixer.h>
|
||||
|
||||
typedef gboolean (*GstAudioMixerFilterFunc) (GstMixer * mixer, gpointer user_data);
|
||||
|
||||
GList * gst_audio_default_registry_mixer_filter (GstAudioMixerFilterFunc filter_func,
|
||||
gboolean first,
|
||||
gpointer user_data);
|
||||
|
||||
#endif /* __GST_AUDIO_MIXERUTILS_H__ */
|
Loading…
Reference in a new issue