a175dd59d951994bbe521f975aecc24fa80790bb
[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:gesvideotestsource
23  * @title: GESVideoTestSource
24  * @short_description: produce solid colors and patterns
25  */
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "ges-internal.h"
31 #include "ges-track-element.h"
32 #include "ges-video-test-source.h"
33
34 #define DEFAULT_VPATTERN GES_VIDEO_TEST_PATTERN_SMPTE
35
36 struct _GESVideoTestSourcePrivate
37 {
38   GESVideoTestPattern pattern;
39 };
40
41 G_DEFINE_TYPE_WITH_PRIVATE (GESVideoTestSource, ges_video_test_source,
42     GES_TYPE_VIDEO_SOURCE);
43
44 static GstElement *ges_video_test_source_create_source (GESTrackElement * self);
45
46 static void
47 ges_video_test_source_class_init (GESVideoTestSourceClass * klass)
48 {
49   GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_CLASS (klass);
50
51   source_class->create_source = ges_video_test_source_create_source;
52 }
53
54 static void
55 ges_video_test_source_init (GESVideoTestSource * self)
56 {
57   self->priv = ges_video_test_source_get_instance_private (self);
58
59   self->priv->pattern = DEFAULT_VPATTERN;
60 }
61
62 static GstElement *
63 ges_video_test_source_create_source (GESTrackElement * self)
64 {
65   GstCaps *caps;
66   gint pattern;
67   GstElement *testsrc, *capsfilter, *res;
68   const gchar *props[] = { "pattern", NULL };
69   GPtrArray *elements;
70
71   testsrc = gst_element_factory_make ("videotestsrc", NULL);
72   capsfilter = gst_element_factory_make ("capsfilter", NULL);
73   pattern = ((GESVideoTestSource *) self)->priv->pattern;
74
75   g_object_set (testsrc, "pattern", pattern, NULL);
76
77   elements = g_ptr_array_new ();
78   g_ptr_array_add (elements, capsfilter);
79   caps = gst_caps_new_empty_simple ("video/x-raw");
80   g_object_set (capsfilter, "caps", caps, NULL);
81   gst_caps_unref (caps);
82
83   ges_track_element_add_children_props (self, testsrc, NULL, NULL, props);
84
85   res = ges_source_create_topbin ("videotestsrc", testsrc, elements);
86   g_ptr_array_free (elements, TRUE);
87
88   return res;
89 }
90
91 /**
92  * ges_video_test_source_set_pattern:
93  * @self: a #GESVideoTestSource
94  * @pattern: a #GESVideoTestPattern
95  *
96  * Sets the source to use the given @pattern.
97  */
98 void
99 ges_video_test_source_set_pattern (GESVideoTestSource
100     * self, GESVideoTestPattern pattern)
101 {
102   GstElement *element =
103       ges_track_element_get_element (GES_TRACK_ELEMENT (self));
104
105   self->priv->pattern = pattern;
106
107   if (element) {
108     GValue val = { 0 };
109
110     g_value_init (&val, GES_VIDEO_TEST_PATTERN_TYPE);
111     g_value_set_enum (&val, pattern);
112     ges_track_element_set_child_property (GES_TRACK_ELEMENT (self), "pattern",
113         &val);
114   }
115 }
116
117 /**
118  * ges_video_test_source_get_pattern:
119  * @source: a #GESVideoTestPattern
120  *
121  * Get the video pattern used by the @source.
122  *
123  * Returns: The video pattern used by the @source.
124  */
125 GESVideoTestPattern
126 ges_video_test_source_get_pattern (GESVideoTestSource * source)
127 {
128   GValue val = { 0 };
129
130   ges_track_element_get_child_property (GES_TRACK_ELEMENT (source), "pattern",
131       &val);
132   return g_value_get_enum (&val);
133 }
134
135 /**
136  * ges_video_test_source_new:
137  *
138  * Creates a new #GESVideoTestSource.
139  *
140  * Returns: (transfer floating) (nullable): The newly created
141  * #GESVideoTestSource, or %NULL if there was an error.
142  */
143 GESVideoTestSource *
144 ges_video_test_source_new (void)
145 {
146   return g_object_new (GES_TYPE_VIDEO_TEST_SOURCE, "track-type",
147       GES_TRACK_TYPE_VIDEO, NULL);
148 }