From 723b2baa5dd2812652b753c2cf01efa8b61a1f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 11 Sep 2009 15:04:42 +0200 Subject: [PATCH] volume: Implement GstStreamVolume interface --- gst/volume/gstvolume.c | 13 +++++++++---- gst/volume/gstvolume.h | 1 + tests/check/Makefile.am | 2 ++ tests/check/elements/volume.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/gst/volume/gstvolume.c b/gst/volume/gstvolume.c index 308ebf35b1..8646eaedb0 100644 --- a/gst/volume/gstvolume.c +++ b/gst/volume/gstvolume.c @@ -137,20 +137,26 @@ static void gst_volume_mixer_init (GstMixerClass * iface); #define _init_interfaces(type) \ { \ - static const GInterfaceInfo voliface_info = { \ + static const GInterfaceInfo voliface_info = { \ (GInterfaceInitFunc) gst_volume_interface_init, \ NULL, \ NULL \ }; \ - static const GInterfaceInfo volmixer_info = { \ + static const GInterfaceInfo volmixer_info = { \ (GInterfaceInitFunc) gst_volume_mixer_init, \ NULL, \ NULL \ + }; \ + static const GInterfaceInfo svol_info = { \ + NULL, \ + NULL, \ + NULL \ }; \ \ g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE, \ &voliface_info); \ g_type_add_interface_static (type, GST_TYPE_MIXER, &volmixer_info); \ + g_type_add_interface_static (type, GST_TYPE_STREAM_VOLUME, &svol_info); \ } GST_BOILERPLATE_FULL (GstVolume, gst_volume, GstAudioFilter, @@ -302,8 +308,7 @@ volume_update_volume (GstVolume * this, gfloat volume, gboolean mute) static gboolean gst_volume_interface_supported (GstImplementsInterface * iface, GType type) { - g_return_val_if_fail (type == GST_TYPE_MIXER, FALSE); - return TRUE; + return (type == GST_TYPE_MIXER || type == GST_TYPE_STREAM_VOLUME); } static void diff --git a/gst/volume/gstvolume.h b/gst/volume/gstvolume.h index 3d74a99d86..41999e1940 100644 --- a/gst/volume/gstvolume.h +++ b/gst/volume/gstvolume.h @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 992b85a971..f68fb658ad 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -280,6 +280,8 @@ elements_textoverlay_LDADD = $(GST_BASE_LIBS) $(LDADD) elements_textoverlay_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) elements_volume_LDADD = \ + $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ + $(GST_PLUGINS_BASE_LIBS) \ $(GST_CONTROLLER_LIBS) \ $(GST_BASE_LIBS) \ $(LDADD) diff --git a/tests/check/elements/volume.c b/tests/check/elements/volume.c index 8cc9b9c947..d59a96f3d8 100644 --- a/tests/check/elements/volume.c +++ b/tests/check/elements/volume.c @@ -25,6 +25,7 @@ #include #include #include +#include /* For ease of programming we use globals to keep refs for our floating * src and sink pads we create; otherwise we always have to do get_pad, @@ -148,6 +149,35 @@ cleanup_volume (GstElement * volume) gst_check_teardown_element (volume); } +GST_START_TEST (test_get_set) +{ + GstElement *volume = gst_element_factory_make ("volume", NULL); + gdouble val; + + fail_unless (volume != NULL); + g_object_get (G_OBJECT (volume), "volume", &val, NULL); + fail_unless (val == 1.0); + fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume), + GST_STREAM_VOLUME_FORMAT_LINEAR)); + + g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); + g_object_get (G_OBJECT (volume), "volume", &val, NULL); + fail_unless (val == 0.5); + fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume), + GST_STREAM_VOLUME_FORMAT_LINEAR)); + + gst_stream_volume_set_volume (GST_STREAM_VOLUME (volume), + GST_STREAM_VOLUME_FORMAT_LINEAR, 1.0); + g_object_get (G_OBJECT (volume), "volume", &val, NULL); + fail_unless (val == 1.0); + fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume), + GST_STREAM_VOLUME_FORMAT_LINEAR)); + + gst_object_unref (volume); +} + +GST_END_TEST; + GST_START_TEST (test_unity_s8) { GstElement *volume; @@ -1459,6 +1489,7 @@ volume_suite (void) TCase *tc_chain = tcase_create ("general"); suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_get_set); tcase_add_test (tc_chain, test_unity_s8); tcase_add_test (tc_chain, test_half_s8); tcase_add_test (tc_chain, test_double_s8);