ges-video-test-source.c 3.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* GStreamer Editing Services
 * Copyright (C) 2010 Brandon Lewis <brandon.lewis@collabora.co.uk>
 *               2010 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
17 18
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
19 20 21
 */

/**
22
 * SECTION:gesvideotestsource
23
 * @title: GESVideoTestSource
24
 * @short_description: produce solid colors and patterns
25 26 27
 */

#include "ges-internal.h"
28
#include "ges-track-element.h"
29
#include "ges-video-test-source.h"
30

31 32
G_DEFINE_TYPE (GESVideoTestSource, ges_video_test_source,
    GES_TYPE_VIDEO_SOURCE);
33

34 35
#define DEFAULT_VPATTERN GES_VIDEO_TEST_PATTERN_SMPTE

36
struct _GESVideoTestSourcePrivate
37
{
38
  GESVideoTestPattern pattern;
39 40
};

41
static GstElement *ges_video_test_source_create_source (GESTrackElement * self);
42 43

static void
44
ges_video_test_source_class_init (GESVideoTestSourceClass * klass)
45
{
46
  GESVideoSourceClass *source_class = GES_VIDEO_SOURCE_CLASS (klass);
47

48
  g_type_class_add_private (klass, sizeof (GESVideoTestSourcePrivate));
49

50
  source_class->create_source = ges_video_test_source_create_source;
51 52 53
}

static void
54
ges_video_test_source_init (GESVideoTestSource * self)
55
{
56
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
57
      GES_TYPE_VIDEO_TEST_SOURCE, GESVideoTestSourcePrivate);
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 68
  GstElement *testsrc, *capsfilter;
  const gchar *props[] = { "pattern", NULL };
69

70 71
  testsrc = gst_element_factory_make ("videotestsrc", NULL);
  capsfilter = gst_element_factory_make ("capsfilter", NULL);
72
  pattern = ((GESVideoTestSource *) self)->priv->pattern;
73 74

  g_object_set (testsrc, "pattern", pattern, NULL);
75 76 77 78

  caps = gst_caps_new_empty_simple ("video/x-raw");
  g_object_set (capsfilter, "caps", caps, NULL);
  gst_caps_unref (caps);
79 80 81

  ges_track_element_add_children_props (self, testsrc, NULL, NULL, props);

82
  return ges_source_create_topbin ("videotestsrc", testsrc, capsfilter, NULL);
83 84
}

85
/**
86 87
 * ges_video_test_source_set_pattern:
 * @self: a #GESVideoTestSource
88 89 90 91
 * @pattern: a #GESVideoTestPattern
 *
 * Sets the source to use the given @pattern.
 */
92
void
93
ges_video_test_source_set_pattern (GESVideoTestSource
94
    * self, GESVideoTestPattern pattern)
95
{
96 97
  GstElement *element =
      ges_track_element_get_element (GES_TRACK_ELEMENT (self));
Edward Hervey's avatar
Edward Hervey committed
98

99
  self->priv->pattern = pattern;
Edward Hervey's avatar
Edward Hervey committed
100

101 102 103 104 105 106 107 108
  if (element) {
    GValue val = { 0 };

    g_value_init (&val, GES_VIDEO_TEST_PATTERN_TYPE);
    g_value_set_enum (&val, pattern);
    ges_track_element_set_child_property (GES_TRACK_ELEMENT (self), "pattern",
        &val);
  }
109 110
}

111
/**
112
 * ges_video_test_source_get_pattern:
113 114
 * @source: a #GESVideoTestPattern
 *
115 116 117
 * Get the video pattern used by the @source.
 *
 * Returns: The video pattern used by the @source.
118 119
 */
GESVideoTestPattern
120
ges_video_test_source_get_pattern (GESVideoTestSource * source)
121
{
122 123 124 125 126
  GValue val = { 0 };

  ges_track_element_get_child_property (GES_TRACK_ELEMENT (source), "pattern",
      &val);
  return g_value_get_enum (&val);
127 128
}

129
/**
130
 * ges_video_test_source_new:
131
 *
132
 * Creates a new #GESVideoTestSource.
133
 *
134 135
 * Returns: (transfer floating) (nullable): The newly created
 * #GESVideoTestSource, or %NULL if there was an error.
136
 */
137 138
GESVideoTestSource *
ges_video_test_source_new (void)
139
{
140
  return g_object_new (GES_TYPE_VIDEO_TEST_SOURCE, "track-type",
141
      GES_TRACK_TYPE_VIDEO, NULL);
142
}