~ubuntu-branches/ubuntu/trusty/gstreamer1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/examples/manual/appsrc.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2012-10-08 09:59:20 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20121008095920-3k2vlenl0zf6lu7i
Tags: 1.0.1-1
* New upstream stable release:
  + debian/libgstreamer.symbols:
    - Add new symbols.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*** block  from ../../../docs/manual/advanced-dataaccess.xml ***/
 
3
#include <gst/gst.h>
 
4
 
 
5
static GMainLoop *loop;
 
6
 
 
7
static void
 
8
cb_need_data (GstElement *appsrc,
 
9
              guint       unused_size,
 
10
              gpointer    user_data)
 
11
{
 
12
  static gboolean white = FALSE;
 
13
  static GstClockTime timestamp = 0;
 
14
  GstBuffer *buffer;
 
15
  guint size;
 
16
  GstFlowReturn ret;
 
17
 
 
18
  size = 385 * 288 * 2;
 
19
 
 
20
  buffer = gst_buffer_new_allocate (NULL, size, NULL);
 
21
 
 
22
  /* this makes the image black/white */
 
23
  gst_buffer_memset (buffer, 0, white ? 0xff : 0x0, size);
 
24
  
 
25
  white = !white;
 
26
 
 
27
  GST_BUFFER_PTS (buffer) = timestamp;
 
28
  GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND, 2);
 
29
 
 
30
  timestamp += GST_BUFFER_DURATION (buffer);
 
31
 
 
32
  g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret);
 
33
 
 
34
  if (ret != GST_FLOW_OK) {
 
35
    /* something wrong, stop pushing */
 
36
    g_main_loop_quit (loop);
 
37
  }
 
38
}
 
39
 
 
40
gint
 
41
main (gint   argc,
 
42
      gchar *argv[])
 
43
{
 
44
  GstElement *pipeline, *appsrc, *conv, *videosink;
 
45
 
 
46
  /* init GStreamer */
 
47
  gst_init (&argc, &argv);
 
48
  loop = g_main_loop_new (NULL, FALSE);
 
49
 
 
50
  /* setup pipeline */
 
51
  pipeline = gst_pipeline_new ("pipeline");
 
52
  appsrc = gst_element_factory_make ("appsrc", "source");
 
53
  conv = gst_element_factory_make ("videoconvert", "conv");
 
54
  videosink = gst_element_factory_make ("xvimagesink", "videosink");
 
55
 
 
56
  /* setup */
 
57
  g_object_set (G_OBJECT (appsrc), "caps",
 
58
                gst_caps_new_simple ("video/x-raw",
 
59
                                     "format", G_TYPE_STRING, "RGB16",
 
60
                                     "width", G_TYPE_INT, 384,
 
61
                                     "height", G_TYPE_INT, 288,
 
62
                                     "framerate", GST_TYPE_FRACTION, 0, 1,
 
63
                                     NULL), NULL);
 
64
  gst_bin_add_many (GST_BIN (pipeline), appsrc, conv, videosink, NULL);
 
65
  gst_element_link_many (appsrc, conv, videosink, NULL);
 
66
 
 
67
  /* setup appsrc */
 
68
  g_object_set (G_OBJECT (appsrc),
 
69
                "stream-type", 0,
 
70
                "format", GST_FORMAT_TIME, NULL);
 
71
  g_signal_connect (appsrc, "need-data", G_CALLBACK (cb_need_data), NULL);
 
72
 
 
73
  /* play */
 
74
  gst_element_set_state (pipeline, GST_STATE_PLAYING);
 
75
  g_main_loop_run (loop);
 
76
 
 
77
  /* clean up */
 
78
  gst_element_set_state (pipeline, GST_STATE_NULL);
 
79
  gst_object_unref (GST_OBJECT (pipeline));
 
80
  g_main_loop_unref (loop);
 
81
 
 
82
  return 0;
 
83
  }