summaryrefslogtreecommitdiff
path: root/tests/examples/shapewipe/shapewipe-example.c
blob: 3b57bcc80009f1e07b578db4a064ccc7bc4dbed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* GStreamer
 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
 *
 * 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
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <gst/gst.h>
#include <gst/controller/gstcontroller.h>
#include <gst/controller/gstlfocontrolsource.h>

static gboolean
on_message (GstBus * bus, GstMessage * message, gpointer user_data)
{
  GMainLoop *loop = (GMainLoop *) user_data;

  switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_ERROR:
      g_warning ("Got ERROR");
      g_main_loop_quit (loop);
      break;
    case GST_MESSAGE_WARNING:
      g_warning ("Got WARNING");
      g_main_loop_quit (loop);
      break;
    case GST_MESSAGE_EOS:
      g_main_loop_quit (loop);
      break;
    default:
      break;
  }

  return TRUE;
}

gint
main (gint argc, gchar ** argv)
{
  GstElement *pipeline;
  GstElement *shapewipe;
  GstController *ctrl;
  GstLFOControlSource *csource;
  GValue val = { 0, };
  GMainLoop *loop;
  GstBus *bus;
  gchar *pipeline_string;

  if (argc != 2) {
    g_print ("Usage: shapewipe mask.png\n");
    return -1;
  }

  gst_init (&argc, &argv);
  gst_controller_init (&argc, &argv);

  pipeline_string =
      g_strdup_printf
      ("videotestsrc ! video/x-raw-yuv,width=640,height=480 ! shapewipe name=shape ! videomixer name=mixer ! ffmpegcolorspace ! autovideosink     filesrc location=%s ! typefind ! decodebin2 ! ffmpegcolorspace ! videoscale ! queue ! shape.mask_sink    videotestsrc pattern=snow ! video/x-raw-yuv,width=640,height=480 ! queue ! mixer.",
      argv[1]);

  pipeline = gst_parse_launch (pipeline_string, NULL);
  g_free (pipeline_string);

  if (pipeline == NULL) {
    g_print ("Failed to create pipeline\n");
    return -2;
  }

  shapewipe = gst_bin_get_by_name (GST_BIN (pipeline), "shape");

  if (!(ctrl = gst_controller_new (G_OBJECT (shapewipe), "position", NULL))) {
    g_print ("can't control shapewipe element\n");
    return -3;
  }

  csource = gst_lfo_control_source_new ();

  gst_controller_set_control_source (ctrl, "position",
      GST_CONTROL_SOURCE (csource));

  g_value_init (&val, G_TYPE_FLOAT);
  g_value_set_float (&val, 0.5);
  g_object_set (G_OBJECT (csource), "amplitude", &val, NULL);
  g_value_set_float (&val, 0.5);
  g_object_set (G_OBJECT (csource), "offset", &val, NULL);
  g_value_unset (&val);

  g_object_set (G_OBJECT (csource), "frequency", 0.5, NULL);
  g_object_set (G_OBJECT (csource), "timeshift", 500 * GST_MSECOND, NULL);

  g_object_unref (csource);

  loop = g_main_loop_new (NULL, FALSE);

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_signal_watch (bus);
  g_signal_connect (G_OBJECT (bus), "message", G_CALLBACK (on_message), loop);
  gst_object_unref (GST_OBJECT (bus));

  if (gst_element_set_state (pipeline,
          GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
    g_error ("Failed to go into PLAYING state");
    return -4;
  }

  g_main_loop_run (loop);

  gst_element_set_state (pipeline, GST_STATE_NULL);

  g_main_loop_unref (loop);

  g_object_unref (G_OBJECT (ctrl));
  gst_object_unref (G_OBJECT (pipeline));

  return 0;
}