Revision 87335b80 src/libsharedvideo/writer-example.cpp

b/src/libsharedvideo/writer-example.cpp
5 5

  
6 6

  
7 7
GstElement *pipeline;
8

  
9 8
GstElement *source;    
10 9
GstElement *tee;       
11 10
GstElement *qlocalxv;  
......
28 27
    exit(sig);
29 28
}
30 29

  
31

  
32

  
33
static gboolean
34
bus_call (GstBus     *bus,
35
          GstMessage *msg,
36
          gpointer    data)
37
{
38
    GMainLoop *loop = (GMainLoop *) data;
39

  
40
    switch (GST_MESSAGE_TYPE (msg)) {
41

  
42
    case GST_MESSAGE_EOS:
43
	g_print ("End of stream\n");
44
	g_main_loop_quit (loop);
45
	break;
46

  
47
    case GST_MESSAGE_ERROR: {
48
	gchar  *debug;
49
	GError *error;
50

  
51
	gst_message_parse_error (msg, &error, &debug);
52
	g_free (debug);
53

  
54
	g_printerr ("Error: %s\n", error->message);
55
	g_error_free (error);
56

  
57
	g_main_loop_quit (loop);
58
	break;
59
    }
60
    default:
61
	break;
62
    }
63

  
64
    return TRUE;
65
}
66

  
67

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

  
......
78 42
{
79 43
    (void) signal(SIGINT,leave);
80 44

  
81
    /* Initialisation */
82 45
    gst_init (&argc, &argv);
83

  
84 46
    GMainLoop *loop = g_main_loop_new (NULL, FALSE);
85 47

  
86 48
    /* Check input arguments */
......
88 50
	g_printerr ("Usage: %s <socket-path>\n", argv[0]);
89 51
	return -1;
90 52
    }
53
    socketName.append (argv[1]);
54

  
91 55

  
92 56
    /* Create gstreamer elements */
93
    pipeline    = gst_pipeline_new ("shared-video-writer");
94
    source      = gst_element_factory_make ("videotestsrc",  "video-source");
57
    pipeline    = gst_pipeline_new (NULL);
58
    source      = gst_element_factory_make ("videotestsrc",  NULL);
95 59
    
96 60
    camsource   = gst_element_factory_make ("v4l2src",  NULL);
97 61

  
98 62
    timeoverlay = gst_element_factory_make ("timeoverlay", NULL);
99 63
    tee         = gst_element_factory_make ("tee", NULL);
100

  
101 64
 
102 65
    qlocalxv    = gst_element_factory_make ("queue", NULL);
103 66
    imgsink     = gst_element_factory_make ("xvimagesink", NULL);
......
108 71
	return -1;
109 72
    }
110 73

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

  
111 76
    /*specifying video format*/
112
     /* GstCaps *videocaps;  */
113
     /* videocaps = gst_caps_new_simple ("video/x-raw-yuv",  */
114
     /* 				     "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'),  */
115
     /* 				     "framerate", GST_TYPE_FRACTION, 30, 1,  */
116
     /* 				     "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,  */
117
     /* 				     /\* "width", G_TYPE_INT, 600,  *\/ */
118
     /* 				     /\* "height", G_TYPE_INT, 400,  *\/ */
119
     /* 				      "width", G_TYPE_INT, 1920,   */
120
     /* 				      "height", G_TYPE_INT, 1080,   */
121
     /* 				     NULL);  */
122

  
123
    /* we add a message handler */
124
    GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
125
    gst_bus_add_watch (bus, bus_call, loop);
126
    gst_object_unref (bus);
127

  
128
    /* we add all elements into the pipeline */
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

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

  
134
    //init before set playing state 
135
    socketName.append (argv[1]);
136
    //writer = new ScenicSharedVideo::Writer (pipeline,tee,socketName);
137 93

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

  
96
    //add_shared_video_writer();
140 97

  
141 98
    /* we link the elements together */
142 99
    //gst_element_link_filtered (source, timeoverlay,videocaps);
143 100
    gst_element_link (camsource,timeoverlay);
144 101
    gst_element_link (timeoverlay, tee);
145 102
    gst_element_link_many (tee, qlocalxv,imgsink,NULL);
146
        
147
    g_object_set (G_OBJECT (imgsink), "sync", FALSE, NULL);
148

  
149 103

  
150 104
    /* Set the pipeline to "playing" state*/
151
    g_print ("Now writing: %s\n", argv[1]);
152 105
    gst_element_set_state (pipeline, GST_STATE_PLAYING);
153
    
154 106

  
155
    
156

  
157
    /* Iterate */
158 107
    g_print ("Running...\n");
159 108
    g_main_loop_run (loop);
160 109

  
161 110
    /* Out of the main loop, clean up nicely */
162 111
    g_print ("Returned, stopping playback\n");
163 112
    gst_element_set_state (pipeline, GST_STATE_NULL);
164

  
165 113
    g_print ("Deleting pipeline\n");
166 114
    gst_object_unref (GST_OBJECT (pipeline));
167 115

  

Also available in: Unified diff