]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-audio-sink.c
Add audio/video sink and source abstractions
[empathy.git] / libempathy-gtk / empathy-audio-sink.c
1 /*
2  * empathy-gst-audio-sink.c - Source for EmpathyGstAudioSink
3  * Copyright (C) 2008 Collabora Ltd.
4  * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "empathy-audio-sink.h"
26
27 G_DEFINE_TYPE(EmpathyGstAudioSink, empathy_audio_sink, GST_TYPE_BIN)
28
29 /* signal enum */
30 #if 0
31 enum
32 {
33     LAST_SIGNAL
34 };
35
36 static guint signals[LAST_SIGNAL] = {0};
37 #endif
38
39 /* private structure */
40 typedef struct _EmpathyGstAudioSinkPrivate EmpathyGstAudioSinkPrivate;
41
42 struct _EmpathyGstAudioSinkPrivate
43 {
44   gboolean dispose_has_run;
45   GstElement *sink;
46 };
47
48 #define EMPATHY_GST_AUDIO_SINK_GET_PRIVATE(o) \
49   (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_GST_AUDIO_SINK, \
50   EmpathyGstAudioSinkPrivate))
51
52 static void
53 empathy_audio_sink_init (EmpathyGstAudioSink *obj)
54 {
55   EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (obj);
56   GstElement *resample;
57   GstPad *ghost, *sink;
58
59   /* allocate any data required by the object here */
60   resample = gst_element_factory_make ("audioresample", NULL);
61
62   priv->sink = gst_element_factory_make ("gconfaudiosink", NULL);
63
64   gst_bin_add_many (GST_BIN (obj), resample, priv->sink, NULL);
65   gst_element_link_many (resample, priv->sink, NULL);
66
67   sink = gst_element_get_static_pad (resample, "sink");
68
69   ghost = gst_ghost_pad_new ("sink", sink);
70   gst_element_add_pad (GST_ELEMENT (obj), ghost);
71
72   gst_object_unref (G_OBJECT (sink));
73 }
74
75 static void empathy_audio_sink_dispose (GObject *object);
76 static void empathy_audio_sink_finalize (GObject *object);
77
78 static void
79 empathy_audio_sink_class_init (EmpathyGstAudioSinkClass
80   *empathy_audio_sink_class)
81 {
82   GObjectClass *object_class = G_OBJECT_CLASS (empathy_audio_sink_class);
83
84   g_type_class_add_private (empathy_audio_sink_class,
85     sizeof (EmpathyGstAudioSinkPrivate));
86
87   object_class->dispose = empathy_audio_sink_dispose;
88   object_class->finalize = empathy_audio_sink_finalize;
89 }
90
91 void
92 empathy_audio_sink_dispose (GObject *object)
93 {
94   EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (object);
95   EmpathyGstAudioSinkPrivate *priv = EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
96
97   if (priv->dispose_has_run)
98     return;
99
100   priv->dispose_has_run = TRUE;
101
102   /* release any references held by the object here */
103
104   if (G_OBJECT_CLASS (empathy_audio_sink_parent_class)->dispose)
105     G_OBJECT_CLASS (empathy_audio_sink_parent_class)->dispose (object);
106 }
107
108 void
109 empathy_audio_sink_finalize (GObject *object)
110 {
111   //EmpathyGstAudioSink *self = EMPATHY_GST_AUDIO_SINK (object);
112   //EmpathyGstAudioSinkPrivate *priv =
113   //  EMPATHY_GST_AUDIO_SINK_GET_PRIVATE (self);
114
115   /* free any data held directly by the object here */
116
117   G_OBJECT_CLASS (empathy_audio_sink_parent_class)->finalize (object);
118 }
119
120 GstElement *
121 empathy_audio_sink_new (void)
122 {
123   return GST_ELEMENT (g_object_new (EMPATHY_TYPE_GST_AUDIO_SINK, NULL));
124 }