1 /***************************************************************************
4 * Wed Nov 18 15:06:29 2009
5 * Copyright 2009 marcin
6 * <marcin.miklas@teleca.com>
7 ****************************************************************************/
10 #include <gst/app/gstappsink.h>
30 void quitHandler(int sig);
31 void pipeline_init(App *app, gboolean start);
32 void pipeline_cleanup(App* app);
36 int main(int argc, char* argv[])
39 int frame_counter = 0;
43 /* Service socket to use for connecting to the service node. */
47 /* The first parameter specifies the service to connect to (SID).
48 * The other parameters are reserved for legacy purposes.
50 sockid = n_connect(DEFAULT_SID, NULL, NULL);
52 /* sockid will be the number of the socket we got (>0), if successful,
53 * or <0 if something went wrong. Let's check:
59 printf("Connected socket %d to service '%d'.\n", sockid, DEFAULT_SID);
61 gst_init (&argc, &argv);
62 pipeline_init(app, TRUE);
64 printf("gstreamer pipeline started\n");
66 // register CTRL+C handling
67 signal(SIGINT, quitHandler);
70 if(argc>1 && argv[1][0]=='f')
71 g_object_set(G_OBJECT(app->vfl), "method", 2, NULL);
73 while (!app->stop && !gst_app_sink_is_eos (GST_APP_SINK (app->sink))) {
78 buf = gst_app_sink_pull_buffer (GST_APP_SINK (app->sink));
79 smsg = pack_pdu(PUT_IMAGE, GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf), &smsg_len);
80 gst_buffer_unref (buf);
82 /* Send the through the socket specified by sockid. The last parameter,
83 * HSSendBlocking, means we will
84 * use blocking mode, i.e. the call to Hsend will only return once all
85 * data has been sent (or an error is detected).
87 err = n_send(sockid, smsg, smsg_len, HSSendBlocking);
93 /* If no error condition was raised, Hsend will return the
94 * number of bytes sent. Let's check this against what we
95 * intended to send, just to be sure (with a blocking call, the
96 * return value should always be equal to the "data_len" parameter
100 printf("Frame %5d send.\n",frame_counter);
102 printf("Sent %d out of %d bytes.\n", err, smsg_len);
106 pipeline_cleanup (app);
108 smsg = pack_pdu (DISCONNECT,NULL, 0, &smsg_len);
109 n_send(sockid, smsg, smsg_len, HSSendBlocking);
112 n_disconnect(sockid);
117 void quitHandler(int sig) {
118 printf("\nStopping...\n");
122 void pipeline_init(App *app, gboolean start) {
123 GstCaps* flt_caps = gst_caps_new_simple ("video/x-raw-yuv",
124 "width", G_TYPE_INT, 320,
125 "height", G_TYPE_INT, 240,
126 "framerate", GST_TYPE_FRACTION, 10, 1,
129 app->pipe = gst_pipeline_new (NULL);
130 app->src = gst_element_factory_make ("v4l2src", NULL);
131 app->flt = gst_element_factory_make ("capsfilter", "flt");
132 g_object_set (G_OBJECT (app->flt), "caps", flt_caps, NULL);
133 app->vrt = gst_element_factory_make ("videorate", "vr");
134 app->vfl = gst_element_factory_make ("videoflip", "vfl");
135 g_object_set(G_OBJECT(app->vfl), "method", 0, NULL);
136 app->enc = gst_element_factory_make ("jpegenc", NULL);
137 app->sink = gst_element_factory_make ("appsink", NULL);
139 gst_bin_add_many (GST_BIN (app->pipe), app->src, app->flt, app->vrt, app->vfl, app->enc, app->sink, NULL);
140 gst_element_link_many (app->src, app->flt, app->vrt, app->vfl, app->enc, app->sink, NULL);
143 gst_element_set_state (app->pipe, GST_STATE_PLAYING);
146 void pipeline_cleanup(App* app) {
147 gst_element_set_state (app->pipe, GST_STATE_NULL);