f71eca8bb1135705b3290b8cc412475e84625319
[platform/upstream/gst-editing-services.git] / ges / ges-video-test-source.c
1 /* GStreamer Editing Services
2  * Copyright (C) 2010 Brandon Lewis <brandon.lewis@collabora.co.uk>
3  *               2010 Nokia Corporation
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * SECTION:ges-video-test-source
23  * @short_description: produce solid colors and patterns
24  */
25
26 #include "ges-internal.h"
27 #include "ges-track-element.h"
28 #include "ges-video-test-source.h"
29
30 G_DEFINE_TYPE (GESVideoTestSource, ges_video_test_source, GES_TYPE_SOURCE);
31
32 #define DEFAULT_VPATTERN GES_VIDEO_TEST_PATTERN_SMPTE
33
34 struct _GESVideoTestSourcePrivate
35 {
36   GESVideoTestPattern pattern;
37 };
38
39 static GstElement *ges_video_test_source_create_element (GESTrackElement *
40     self);
41
42 static void
43 ges_video_test_source_class_init (GESVideoTestSourceClass * klass)
44 {
45   GESTrackElementClass *track_element_class = GES_TRACK_ELEMENT_CLASS (klass);
46
47   g_type_class_add_private (klass, sizeof (GESVideoTestSourcePrivate));
48
49   track_element_class->create_element = ges_video_test_source_create_element;
50 }
51
52 static void
53 ges_video_test_source_init (GESVideoTestSource * self)
54 {
55   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
56       GES_TYPE_VIDEO_TEST_SOURCE, GESVideoTestSourcePrivate);
57
58   self->priv->pattern = DEFAULT_VPATTERN;
59 }
60
61 static GstElement *
62 ges_video_test_source_create_element (GESTrackElement * self)
63 {
64   gint pattern;
65   GstElement *ret;
66   gchar *bin_desc;
67
68
69   pattern = ((GESVideoTestSource *) self)->priv->pattern;
70   bin_desc =
71       g_strdup_printf
72       ("videotestsrc pattern=%i name=testsrc ! capsfilter caps=video/x-raw",
73       pattern);
74   ret = gst_parse_bin_from_description (bin_desc, TRUE, NULL);
75   g_free (bin_desc);
76
77   return ret;
78 }
79
80 /**
81  * ges_video_test_source_set_pattern:
82  * @self: a #GESVideoTestSource
83  * @pattern: a #GESVideoTestPattern
84  *
85  * Sets the source to use the given @pattern.
86  */
87 void
88 ges_video_test_source_set_pattern (GESVideoTestSource
89     * self, GESVideoTestPattern pattern)
90 {
91   GstElement *element =
92       ges_track_element_get_element (GES_TRACK_ELEMENT (self));
93
94   self->priv->pattern = pattern;
95
96   if (element)
97     gst_child_proxy_set (GST_CHILD_PROXY (element), "testsrc::pattern",
98         (gint) pattern, NULL);
99 }
100
101 /**
102  * ges_video_test_source_get_pattern:
103  * @source: a #GESVideoTestPattern
104  *
105  * Get the video pattern used by the @source.
106  *
107  * Returns: The video pattern used by the @source.
108  */
109 GESVideoTestPattern
110 ges_video_test_source_get_pattern (GESVideoTestSource * source)
111 {
112   return source->priv->pattern;
113 }
114
115 /**
116  * ges_video_test_source_new:
117  *
118  * Creates a new #GESVideoTestSource.
119  *
120  * Returns: The newly created #GESVideoTestSource, or %NULL if there was an
121  * error.
122  */
123 GESVideoTestSource *
124 ges_video_test_source_new (void)
125 {
126   return g_object_new (GES_TYPE_VIDEO_TEST_SOURCE, "track-type",
127       GES_TRACK_TYPE_VIDEO, NULL);
128 }