]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-video-src.c
Add audio/video sink and source abstractions
[empathy.git] / libempathy-gtk / empathy-video-src.c
1 /*
2  * empathy-gst-video-src.c - Source for EmpathyGstVideoSrc
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-video-src.h"
26
27 G_DEFINE_TYPE(EmpathyGstVideoSrc, empathy_video_src, 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 _EmpathyGstVideoSrcPrivate EmpathyGstVideoSrcPrivate;
41
42 struct _EmpathyGstVideoSrcPrivate
43 {
44   gboolean dispose_has_run;
45   GstElement *src;
46 };
47
48 #define EMPATHY_GST_VIDEO_SRC_GET_PRIVATE(o) \
49   (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_GST_VIDEO_SRC, \
50     EmpathyGstVideoSrcPrivate))
51
52 static void
53 empathy_video_src_init (EmpathyGstVideoSrc *obj)
54 {
55   EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (obj);
56   GstElement *scale, *rate, *colorspace, *capsfilter;
57   GstPad *ghost, *src;
58   GstCaps *caps;
59
60   /* allocate any data required by the object here */
61   scale = gst_element_factory_make ("videoscale", NULL);
62   rate = gst_element_factory_make ("videorate", NULL);
63   colorspace = gst_element_factory_make ("ffmpegcolorspace", NULL);
64
65   capsfilter = gst_element_factory_make ("capsfilter", NULL);
66   caps = gst_caps_new_simple ("video/x-raw-yuv",
67     "width", G_TYPE_INT, 320,
68     "height", G_TYPE_INT, 240,
69     NULL);
70
71   g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
72
73   priv->src = gst_element_factory_make ("gconfvideosrc", NULL);
74
75   gst_bin_add_many (GST_BIN (obj), priv->src, scale, rate,
76     colorspace, capsfilter, NULL);
77   gst_element_link_many (priv->src, scale, rate, colorspace, capsfilter, NULL);
78
79   src = gst_element_get_static_pad (capsfilter, "src");
80
81   ghost = gst_ghost_pad_new ("src", src);
82   gst_element_add_pad (GST_ELEMENT (obj), ghost);
83
84   gst_object_unref (G_OBJECT (src));
85 }
86
87 static void empathy_video_src_dispose (GObject *object);
88 static void empathy_video_src_finalize (GObject *object);
89
90 static void
91 empathy_video_src_class_init (EmpathyGstVideoSrcClass *empathy_video_src_class)
92 {
93   GObjectClass *object_class = G_OBJECT_CLASS (empathy_video_src_class);
94
95   g_type_class_add_private (empathy_video_src_class,
96     sizeof (EmpathyGstVideoSrcPrivate));
97
98   object_class->dispose = empathy_video_src_dispose;
99   object_class->finalize = empathy_video_src_finalize;
100 }
101
102 void
103 empathy_video_src_dispose (GObject *object)
104 {
105   EmpathyGstVideoSrc *self = EMPATHY_GST_VIDEO_SRC (object);
106   EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (self);
107
108   if (priv->dispose_has_run)
109     return;
110
111   priv->dispose_has_run = TRUE;
112
113   /* release any references held by the object here */
114
115   if (G_OBJECT_CLASS (empathy_video_src_parent_class)->dispose)
116     G_OBJECT_CLASS (empathy_video_src_parent_class)->dispose (object);
117 }
118
119 void
120 empathy_video_src_finalize (GObject *object)
121 {
122   //EmpathyGstVideoSrc *self = EMPATHY_GST_VIDEO_SRC (object);
123   //EmpathyGstVideoSrcPrivate *priv = EMPATHY_GST_VIDEO_SRC_GET_PRIVATE (self);
124
125   /* free any data held directly by the object here */
126
127   G_OBJECT_CLASS (empathy_video_src_parent_class)->finalize (object);
128 }
129
130 GstElement *
131 empathy_video_src_new (void)
132 {
133   return GST_ELEMENT (g_object_new (EMPATHY_TYPE_GST_VIDEO_SRC, NULL));
134 }