This URL has Read-Only access.

Statistics
| Branch: | Tag: | Revision:

root / src / libsharedvideo / writer-example.cpp @ 87335b80

History | View | Annotate | Download (3.3 kB)

1
#include <gst/gst.h>
2
#include <signal.h>
3
#include <string>
4
#include "shared-video.h"
5

    
6

    
7
GstElement *pipeline;
8
GstElement *source;    
9
GstElement *tee;       
10
GstElement *qlocalxv;  
11
GstElement *imgsink;   
12
GstElement *timeoverlay;
13
GstElement *camsource;
14

    
15
std::string socketName;
16
ScenicSharedVideo::Writer *writer;
17

    
18
//clean up pipeline when ctrl-c
19
void
20
leave(int sig) {
21
    g_print ("Returned, stopping playback\n");
22
    gst_element_set_state (pipeline, GST_STATE_NULL);
23

    
24
    g_print ("Deleting pipeline\n");
25
    gst_object_unref (GST_OBJECT (pipeline));
26

    
27
    exit(sig);
28
}
29

    
30
//will create the shared video, reading from the tee element  
31
static gboolean  
32
add_shared_video_writer()
33
{
34
    writer = new ScenicSharedVideo::Writer (pipeline,tee,socketName);
35
    g_print ("Now writing to the shared memory\n");
36
    return FALSE;
37
}
38

    
39
int
40
main (int   argc,
41
      char *argv[])
42
{
43
    (void) signal(SIGINT,leave);
44

    
45
    gst_init (&argc, &argv);
46
    GMainLoop *loop = g_main_loop_new (NULL, FALSE);
47

    
48
    /* Check input arguments */
49
    if (argc != 2) {
50
        g_printerr ("Usage: %s <socket-path>\n", argv[0]);
51
        return -1;
52
    }
53
    socketName.append (argv[1]);
54

    
55

    
56
    /* Create gstreamer elements */
57
    pipeline    = gst_pipeline_new (NULL);
58
    source      = gst_element_factory_make ("videotestsrc",  NULL);
59
    
60
    camsource   = gst_element_factory_make ("v4l2src",  NULL);
61

    
62
    timeoverlay = gst_element_factory_make ("timeoverlay", NULL);
63
    tee         = gst_element_factory_make ("tee", NULL);
64
 
65
    qlocalxv    = gst_element_factory_make ("queue", NULL);
66
    imgsink     = gst_element_factory_make ("xvimagesink", NULL);
67

    
68
    
69
    if (!pipeline || !source || !timeoverlay || !tee || !qlocalxv || !imgsink ) {
70
        g_printerr ("One element could not be created. Exiting.\n");
71
        return -1;
72
    }
73

    
74
    g_object_set (G_OBJECT (imgsink), "sync", FALSE, NULL);
75

    
76
    /*specifying video format*/
77
    // GstCaps *videocaps;  
78
    // videocaps = gst_caps_new_simple ("video/x-raw-yuv",  
79
    //                                        "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'),  
80
    //                                        "framerate", GST_TYPE_FRACTION, 30, 1,  
81
    //                                        "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,  
82
    //                                      /* "width", G_TYPE_INT, 600,  */ 
83
    //                                      /* "height", G_TYPE_INT, 400,  */ 
84
    //                                      "width", G_TYPE_INT, 1920,   
85
    //                                      "height", G_TYPE_INT, 1080,   
86
    //                                        NULL);  
87

    
88
    gst_bin_add_many (GST_BIN (pipeline),
89
                      //source, 
90
                      camsource, 
91
                      timeoverlay, tee, qlocalxv, imgsink, NULL);
92

    
93

    
94
    //shared video can be pluged before or after the pipeline state is set to PLAYING 
95
    g_timeout_add (1000, (GSourceFunc) add_shared_video_writer, NULL);
96
    //add_shared_video_writer();
97

    
98
    /* we link the elements together */
99
    //gst_element_link_filtered (source, timeoverlay,videocaps);
100
    gst_element_link (camsource,timeoverlay);
101
    gst_element_link (timeoverlay, tee);
102
    gst_element_link_many (tee, qlocalxv,imgsink,NULL);
103

    
104
    /* Set the pipeline to "playing" state*/
105
    gst_element_set_state (pipeline, GST_STATE_PLAYING);
106

    
107
    g_print ("Running...\n");
108
    g_main_loop_run (loop);
109

    
110
    /* Out of the main loop, clean up nicely */
111
    g_print ("Returned, stopping playback\n");
112
    gst_element_set_state (pipeline, GST_STATE_NULL);
113
    g_print ("Deleting pipeline\n");
114
    gst_object_unref (GST_OBJECT (pipeline));
115

    
116
    return 0;
117
}