+++ /dev/null
-/***************************************************************************
- * gstapplication.c
- *
- * Wed Nov 18 15:06:29 2009
- * Copyright 2009 marcin
- * <marcin.miklas@teleca.com>
- ****************************************************************************/
-
-#include <gst/gst.h>
-#include <gst/app/gstappsink.h>
-#include <signal.h>
-
-#include "notaio.h"
-#include "pdu.h"
-
-
-typedef struct
-{
- GstElement *pipe;
- GstElement *src;
- GstElement *flt;
- GstElement *vfl;
- GstElement *vrt;
- GstElement *enc;
- GstElement *sink;
-
- gboolean stop;
-} App;
-
-void quitHandler(int sig);
-void pipeline_init(App *app, gboolean start);
-void pipeline_cleanup(App* app);
-
-App s_app;
-
-int main(int argc, char* argv[])
-{
- App* app = &s_app;
- int frame_counter = 0;
- ServiceMessage* smsg;
- int smsg_len = 0;
-
- /* Service socket to use for connecting to the service node. */
- HSSockID sockid;
- HErrorCode err;
-
- /* The first parameter specifies the service to connect to (SID).
- * The other parameters are reserved for legacy purposes.
- */
- sockid = n_connect(DEFAULT_SID, NULL, NULL);
-
- /* sockid will be the number of the socket we got (>0), if successful,
- * or <0 if something went wrong. Let's check:
- */
- if (sockid < 0) {
- return -1;
- }
-
- printf("Connected socket %d to service '%d'.\n", sockid, DEFAULT_SID);
-
- gst_init (&argc, &argv);
- pipeline_init(app, TRUE);
-
- printf("gstreamer pipeline started\n");
-
- // register CTRL+C handling
- signal(SIGINT, quitHandler);
-
- // flip image
- if(argc>1 && argv[1][0]=='f')
- g_object_set(G_OBJECT(app->vfl), "method", 2, NULL);
-
- while (!app->stop && !gst_app_sink_is_eos (GST_APP_SINK (app->sink))) {
- GstBuffer *buf;
-
- frame_counter += 1;
-
- buf = gst_app_sink_pull_buffer (GST_APP_SINK (app->sink));
- smsg = pack_pdu(PUT_IMAGE, GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf), &smsg_len);
- gst_buffer_unref (buf);
-
- /* Send the through the socket specified by sockid. The last parameter,
- * HSSendBlocking, means we will
- * use blocking mode, i.e. the call to Hsend will only return once all
- * data has been sent (or an error is detected).
- */
- err = n_send(sockid, smsg, smsg_len, HSSendBlocking);
- free(smsg);
- if(err < 0){
- return -1;
- }
-
- /* If no error condition was raised, Hsend will return the
- * number of bytes sent. Let's check this against what we
- * intended to send, just to be sure (with a blocking call, the
- * return value should always be equal to the "data_len" parameter
- * of Hsend).
- */
- if (err == smsg_len)
- printf("Frame %5d send.\n",frame_counter);
- else
- printf("Sent %d out of %d bytes.\n", err, smsg_len);
-
- }
-
- pipeline_cleanup (app);
-
- smsg = pack_pdu (DISCONNECT,NULL, 0, &smsg_len);
- n_send(sockid, smsg, smsg_len, HSSendBlocking);
- free(smsg);
-
- n_disconnect(sockid);
-
- return 0;
-}
-
-void quitHandler(int sig) {
- printf("\nStopping...\n");
- s_app.stop = TRUE;
-}
-
-void pipeline_init(App *app, gboolean start) {
- GstCaps* flt_caps = gst_caps_new_simple ("video/x-raw-yuv",
- "width", G_TYPE_INT, 320,
- "height", G_TYPE_INT, 240,
- "framerate", GST_TYPE_FRACTION, 10, 1,
- NULL);
-
- app->pipe = gst_pipeline_new (NULL);
- app->src = gst_element_factory_make ("v4l2src", NULL);
- app->flt = gst_element_factory_make ("capsfilter", "flt");
- g_object_set (G_OBJECT (app->flt), "caps", flt_caps, NULL);
- app->vrt = gst_element_factory_make ("videorate", "vr");
- app->vfl = gst_element_factory_make ("videoflip", "vfl");
- g_object_set(G_OBJECT(app->vfl), "method", 0, NULL);
- app->enc = gst_element_factory_make ("jpegenc", NULL);
- app->sink = gst_element_factory_make ("appsink", NULL);
-
- gst_bin_add_many (GST_BIN (app->pipe), app->src, app->flt, app->vrt, app->vfl, app->enc, app->sink, NULL);
- gst_element_link_many (app->src, app->flt, app->vrt, app->vfl, app->enc, app->sink, NULL);
-
- if (start)
- gst_element_set_state (app->pipe, GST_STATE_PLAYING);
-}
-
-void pipeline_cleanup(App* app) {
- gst_element_set_state (app->pipe, GST_STATE_NULL);
- //TODO free pipeline
-}