volume: Implement GstStreamVolume interface
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 11 Sep 2009 13:04:42 +0000 (15:04 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 11 Sep 2009 14:37:35 +0000 (16:37 +0200)
gst/volume/gstvolume.c
gst/volume/gstvolume.h
tests/check/Makefile.am
tests/check/elements/volume.c

index 308ebf35b175f667fec1d9ba63edb51ba8513aa8..8646eaedb063e0c9024f0ff2d8243ea70d7134cc 100644 (file)
@@ -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
index 3d74a99d8690c1176db9124275b1343c6a81e47b..41999e1940d761fe5c5403a6b5f4cb54ee70e7f2 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <gst/gst.h>
 #include <gst/base/gstbasetransform.h>
+#include <gst/interfaces/streamvolume.h>
 #include <gst/audio/audio.h>
 #include <gst/audio/gstaudiofilter.h>
 
index 992b85a971ae071028bcd7955fbf81e40808974d..f68fb658ad5c9bb1c0e567b35a4b680db01bdf35 100644 (file)
@@ -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)
index 8cc9b9c947ff8569ebdb4785f354f0215fbc23ea..d59a96f3d8a363a6efd9b58d735af32b686d2685 100644 (file)
@@ -25,6 +25,7 @@
 #include <gst/base/gstbasetransform.h>
 #include <gst/check/gstcheck.h>
 #include <gst/controller/gstcontroller.h>
+#include <gst/interfaces/streamvolume.h>
 
 /* 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);