2011-03-25 07:26:00 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2011> Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-03-25 07:26:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstplaysinkaudioconvert.h"
|
|
|
|
|
|
|
|
#include <gst/pbutils/pbutils.h>
|
2022-03-25 13:59:23 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2011-03-25 07:26:00 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_play_sink_audio_convert_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_play_sink_audio_convert_debug
|
|
|
|
|
|
|
|
#define parent_class gst_play_sink_audio_convert_parent_class
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstPlaySinkAudioConvert, gst_play_sink_audio_convert,
|
2011-10-17 16:55:30 +00:00
|
|
|
GST_TYPE_PLAY_SINK_CONVERT_BIN);
|
2011-03-25 07:26:00 +00:00
|
|
|
|
2011-10-17 21:05:30 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_USE_CONVERTERS,
|
|
|
|
PROP_USE_VOLUME,
|
2022-09-30 16:33:49 +00:00
|
|
|
PROP_VOLUME_ELEMENT,
|
2011-10-17 21:05:30 +00:00
|
|
|
};
|
|
|
|
|
2011-03-25 07:26:00 +00:00
|
|
|
static gboolean
|
2011-10-17 21:05:30 +00:00
|
|
|
gst_play_sink_audio_convert_add_conversion_elements (GstPlaySinkAudioConvert *
|
|
|
|
self)
|
2011-03-25 07:26:00 +00:00
|
|
|
{
|
2011-10-17 21:05:30 +00:00
|
|
|
GstPlaySinkConvertBin *cbin = GST_PLAY_SINK_CONVERT_BIN (self);
|
2011-10-17 16:55:30 +00:00
|
|
|
GstElement *el, *prev = NULL;
|
2011-03-25 07:26:00 +00:00
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
g_assert (cbin->conversion_elements == NULL);
|
2011-03-25 07:26:00 +00:00
|
|
|
|
2011-10-17 21:05:30 +00:00
|
|
|
GST_DEBUG_OBJECT (self,
|
|
|
|
"Building audio conversion with use-converters %d, use-volume %d",
|
|
|
|
self->use_converters, self->use_volume);
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
if (self->use_converters) {
|
|
|
|
el = gst_play_sink_convert_bin_add_conversion_element_factory (cbin,
|
|
|
|
"audioconvert", "conv");
|
|
|
|
if (el) {
|
|
|
|
prev = el;
|
2011-03-25 07:26:00 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
el = gst_play_sink_convert_bin_add_conversion_element_factory (cbin,
|
|
|
|
"audioresample", "resample");
|
|
|
|
if (el) {
|
2011-03-25 07:26:00 +00:00
|
|
|
if (prev) {
|
2011-10-17 16:55:30 +00:00
|
|
|
if (!gst_element_link_pads_full (prev, "src", el, "sink",
|
2011-03-25 07:26:00 +00:00
|
|
|
GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
|
|
|
|
goto link_failed;
|
|
|
|
}
|
2011-10-17 16:55:30 +00:00
|
|
|
prev = el;
|
2011-03-25 07:26:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
if (self->use_volume && self->volume) {
|
|
|
|
el = self->volume;
|
|
|
|
gst_play_sink_convert_bin_add_conversion_element (cbin, el);
|
|
|
|
if (prev) {
|
|
|
|
if (!gst_element_link_pads_full (prev, "src", el, "sink",
|
|
|
|
GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
|
|
|
|
goto link_failed;
|
2011-03-25 07:26:00 +00:00
|
|
|
}
|
2011-10-17 16:55:30 +00:00
|
|
|
prev = el;
|
2011-03-25 07:26:00 +00:00
|
|
|
}
|
2011-10-17 21:05:30 +00:00
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
return TRUE;
|
2011-03-25 07:26:00 +00:00
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
link_failed:
|
|
|
|
return FALSE;
|
2011-03-25 07:26:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_sink_audio_convert_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstPlaySinkAudioConvert *self = GST_PLAY_SINK_AUDIO_CONVERT_CAST (object);
|
|
|
|
|
|
|
|
if (self->volume)
|
|
|
|
gst_object_unref (self->volume);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2011-10-17 21:05:30 +00:00
|
|
|
static void
|
|
|
|
gst_play_sink_audio_convert_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPlaySinkAudioConvert *self = GST_PLAY_SINK_AUDIO_CONVERT_CAST (object);
|
|
|
|
gboolean v, changed = FALSE;
|
|
|
|
|
2011-10-19 13:12:01 +00:00
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
2011-10-17 21:05:30 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_USE_CONVERTERS:
|
|
|
|
v = g_value_get_boolean (value);
|
|
|
|
if (v != self->use_converters) {
|
|
|
|
self->use_converters = v;
|
|
|
|
changed = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_USE_VOLUME:
|
|
|
|
v = g_value_get_boolean (value);
|
|
|
|
if (v != self->use_volume) {
|
|
|
|
self->use_volume = v;
|
|
|
|
changed = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
GstPlaySinkConvertBin *cbin = GST_PLAY_SINK_CONVERT_BIN (self);
|
|
|
|
GST_DEBUG_OBJECT (self, "Rebuilding converter bin");
|
|
|
|
gst_play_sink_convert_bin_remove_elements (cbin);
|
|
|
|
gst_play_sink_audio_convert_add_conversion_elements (self);
|
2011-10-19 13:13:30 +00:00
|
|
|
gst_play_sink_convert_bin_add_identity (cbin);
|
2011-10-17 21:05:30 +00:00
|
|
|
gst_play_sink_convert_bin_cache_converter_caps (cbin);
|
|
|
|
}
|
2011-10-19 13:12:01 +00:00
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
2011-10-17 21:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_sink_audio_convert_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPlaySinkAudioConvert *self = GST_PLAY_SINK_AUDIO_CONVERT_CAST (object);
|
|
|
|
|
2011-10-19 13:12:01 +00:00
|
|
|
GST_PLAY_SINK_CONVERT_BIN_LOCK (self);
|
2011-10-17 21:05:30 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_USE_CONVERTERS:
|
|
|
|
g_value_set_boolean (value, self->use_converters);
|
|
|
|
break;
|
|
|
|
case PROP_USE_VOLUME:
|
|
|
|
g_value_set_boolean (value, self->use_volume);
|
|
|
|
break;
|
2022-09-30 16:33:49 +00:00
|
|
|
case PROP_VOLUME_ELEMENT:
|
|
|
|
g_value_set_object (value, self->volume);
|
|
|
|
break;
|
2011-10-17 21:05:30 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-19 13:12:01 +00:00
|
|
|
GST_PLAY_SINK_CONVERT_BIN_UNLOCK (self);
|
2011-10-17 21:05:30 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 07:26:00 +00:00
|
|
|
static void
|
|
|
|
gst_play_sink_audio_convert_class_init (GstPlaySinkAudioConvertClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_play_sink_audio_convert_debug,
|
|
|
|
"playsinkaudioconvert", 0, "play bin");
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_play_sink_audio_convert_finalize;
|
2011-10-17 21:05:30 +00:00
|
|
|
gobject_class->set_property = gst_play_sink_audio_convert_set_property;
|
|
|
|
gobject_class->get_property = gst_play_sink_audio_convert_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_USE_CONVERTERS,
|
|
|
|
g_param_spec_boolean ("use-converters", "Use converters",
|
|
|
|
"Whether to use conversion elements", FALSE,
|
2011-11-24 10:34:12 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-10-17 21:05:30 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_USE_VOLUME,
|
|
|
|
g_param_spec_boolean ("use-volume", "Use volume",
|
|
|
|
"Whether to use a volume element", FALSE,
|
2011-11-24 10:34:12 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-03-25 07:26:00 +00:00
|
|
|
|
2022-09-30 16:33:49 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_VOLUME_ELEMENT,
|
|
|
|
g_param_spec_object ("volume-element", "Volume element",
|
|
|
|
"Retrieve the soft-volume element used when use-volume=TRUE",
|
|
|
|
GST_TYPE_ELEMENT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-04-09 23:45:16 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2011-03-25 07:26:00 +00:00
|
|
|
"Player Sink Audio Converter", "Audio/Bin/Converter",
|
|
|
|
"Convenience bin for audio conversion",
|
|
|
|
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_play_sink_audio_convert_init (GstPlaySinkAudioConvert * self)
|
|
|
|
{
|
2011-10-17 16:55:30 +00:00
|
|
|
GstPlaySinkConvertBin *cbin = GST_PLAY_SINK_CONVERT_BIN (self);
|
2011-03-25 07:26:00 +00:00
|
|
|
|
2011-10-17 16:55:30 +00:00
|
|
|
cbin->audio = TRUE;
|
2011-03-25 07:26:00 +00:00
|
|
|
|
|
|
|
/* FIXME: Only create this on demand but for now we need
|
|
|
|
* it to always exist because of playsink's volume proxying
|
|
|
|
* logic.
|
|
|
|
*/
|
|
|
|
self->volume = gst_element_factory_make ("volume", "volume");
|
|
|
|
if (self->volume)
|
|
|
|
gst_object_ref_sink (self->volume);
|
2011-10-17 21:05:30 +00:00
|
|
|
|
|
|
|
gst_play_sink_audio_convert_add_conversion_elements (self);
|
|
|
|
gst_play_sink_convert_bin_cache_converter_caps (cbin);
|
2011-03-25 07:26:00 +00:00
|
|
|
}
|