rtsprange: use gst_util_gdouble_to_guint64 in get_seconds
[platform/upstream/gstreamer.git] / tests / examples / app / appsrc_ex.c
1
2
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
6
7 #include <gst/gst.h>
8 #include <gst/app/gstappsrc.h>
9 #include <gst/app/gstappsink.h>
10
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14
15
16 typedef struct _App App;
17 struct _App
18 {
19   GstElement *pipe;
20   GstElement *src;
21   GstElement *id;
22   GstElement *sink;
23 };
24
25 App s_app;
26
27 int
28 main (int argc, char *argv[])
29 {
30   App *app = &s_app;
31   int i;
32
33   gst_init (&argc, &argv);
34
35   app->pipe = gst_pipeline_new (NULL);
36   g_assert (app->pipe);
37
38   app->src = gst_element_factory_make ("appsrc", NULL);
39   g_assert (app->src);
40   gst_bin_add (GST_BIN (app->pipe), app->src);
41
42   app->id = gst_element_factory_make ("identity", NULL);
43   g_assert (app->id);
44   gst_bin_add (GST_BIN (app->pipe), app->id);
45
46   app->sink = gst_element_factory_make ("appsink", NULL);
47   g_assert (app->sink);
48   gst_bin_add (GST_BIN (app->pipe), app->sink);
49
50   gst_element_link (app->src, app->id);
51   gst_element_link (app->id, app->sink);
52
53   gst_element_set_state (app->pipe, GST_STATE_PLAYING);
54
55   for (i = 0; i < 10; i++) {
56     GstBuffer *buf;
57     GstMapInfo map;
58
59     buf = gst_buffer_new_and_alloc (100);
60     gst_buffer_map (buf, &map, GST_MAP_WRITE);
61     memset (map.data, i, 100);
62     gst_buffer_unmap (buf, &map);
63
64     printf ("%d: pushing buffer for pointer %p, %p\n", i, map.data, buf);
65     gst_app_src_push_buffer (GST_APP_SRC (app->src), buf);
66   }
67
68   /* push EOS */
69   gst_app_src_end_of_stream (GST_APP_SRC (app->src));
70
71   /* _is_eos() does not block and returns TRUE if there is not currently an EOS
72    * to be retrieved */
73   while (!gst_app_sink_is_eos (GST_APP_SINK (app->sink))) {
74     GstSample *sample;
75
76     /* pull the next item, this can return NULL when there is no more data and
77      * EOS has been received */
78     sample = gst_app_sink_pull_sample (GST_APP_SINK (app->sink));
79     printf ("retrieved sample %p\n", sample);
80     if (sample)
81       gst_sample_unref (sample);
82   }
83   gst_element_set_state (app->pipe, GST_STATE_NULL);
84
85   return 0;
86 }