testprogram1

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
#include <stdio.h>
#include <gst/gst.h>

void connect(GstElement *a, GstElement *b) {
  gboolean res = gst_element_link(a, b);
  if(!res) {
    gchar *na, *nb;
    g_object_get(a, "name", &na, NULL);
    g_object_get(b, "name", &nb, NULL);
    printf("cannot connect %s to %s\n", na, nb);
    exit(2);
  }
}

GstElement *player(int argc, char **argv) 
{
  GstElement *bin, *src, *mdspproc, *color1, *color2;
  GstElement *sink;
  GstStateChangeReturn state_change;

  gst_init(&argc, &argv);

  bin      = gst_pipeline_new("video-stream");
  src      = gst_element_factory_make("videotestsrc"    , "videotestsrc");
  mdspproc = gst_element_factory_make("videoscale"      , "videoscale"  );
  color1   = gst_element_factory_make("ffmpegcolorspace", "color1"      );
  color2   = gst_element_factory_make("ffmpegcolorspace", "color2"      );
  sink     = gst_element_factory_make("ximagesink"      , "sink1"        );

  if(!(src && mdspproc && color1 && color2 &&  sink)) {
    printf("ack\n");
    exit(1);
  }
  printf("made elems\n");

  gst_bin_add(GST_BIN(bin), src);
  gst_bin_add(GST_BIN(bin), mdspproc);
  gst_bin_add(GST_BIN(bin), color1);
  gst_bin_add(GST_BIN(bin), sink);
  gst_bin_add(GST_BIN(bin), color2);


  connect(src, color1);
  connect(color1, mdspproc);
  connect(mdspproc, color2);
  connect(color2, sink);

  printf("%d\n", gst_element_set_state(bin, GST_STATE_PLAYING));
  return bin;
}

int main(int argc, char **argv) {
  GMainLoop *loop = g_main_loop_new(NULL, FALSE);
  GstElement *bin = player(argc, argv);
  g_main_loop_run(loop);
  return 0;
}