Last active
August 29, 2015 14:13
-
-
Save Forzaferrarileo/885abf8e6166c9f2736a to your computer and use it in GitHub Desktop.
Tee pipeline stall on pause
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (c) Tord Wessman 2013 | |
// Feel free to do what you like with code. | |
// | |
// This simple example demonstrates how to use the tee elements to | |
// display two xvimagesink windows containing one web-cam input (v4l2src). | |
// | |
#include <cstdio> | |
#include <gst/gst.h> | |
#include <unistd.h> | |
GstElement *bin, // the containing all the elements | |
*pipeline, | |
*src, | |
*tee, | |
*q1,*q2, | |
*filesink, | |
*sink, | |
*rtph264, | |
*mp4mux, | |
*encoder, | |
*h264parse; | |
GstBus *bus; //the bus element te transport messages from/to the pipeline | |
int main (int argc, char** argv) { | |
gst_init (NULL, NULL); | |
GstMessage *msg; | |
GstCaps *caps; | |
GstPadTemplate *tee_src_pad_template; | |
GstPad *tee_q1_pad, *tee_q2_pad; | |
GstPad *q1_pad, *q2_pad ; | |
pipeline = gst_pipeline_new ("video_pipeline"); | |
/* create the bus for the pipeline */ | |
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); | |
bin = gst_bin_new ("record bin"); | |
//initializing elements | |
src = gst_element_factory_make ("videotestsrc", "src"); | |
sink = gst_element_factory_make ("autovideosink", "udp sink"); | |
filesink = gst_element_factory_make ("filesink", "filesink"); | |
tee = gst_element_factory_make ("tee", "tee"); | |
q1 = gst_element_factory_make ("queue", "queueone"); | |
q2 = gst_element_factory_make ("queue", "queuetwo"); | |
rtph264 = gst_element_factory_make("videoconvert","rtph264pay"); | |
encoder = gst_element_factory_make("x264enc","encoder"); | |
mp4mux = gst_element_factory_make("mp4mux","mux"); | |
h264parse = gst_element_factory_make("h264parse","parse"); | |
//g_object_set(src, "bitrate", 6000000, NULL); | |
g_object_set(rtph264, "config-interval", 1, NULL); | |
g_object_set(rtph264, "pt" , 96, NULL); | |
//g_object_set(sink, "host", "192.168.1.100" /*ip.c_str()*/ , NULL); | |
//g_object_set(sink, "port", 5000, NULL); | |
g_object_set(filesink, "location", "test.mp4", NULL); | |
/* Add the elements to the pipeline prior to linking them */ | |
gst_bin_add_many(GST_BIN(pipeline), src, tee, q1, sink, q2, filesink,rtph264,encoder,mp4mux,h264parse, NULL); | |
/* Specify caps for the csp-filter (modify this if your hardware requires) */ | |
caps = gst_caps_new_simple("video/x-raw", | |
"width", G_TYPE_INT, 1280, | |
"height", G_TYPE_INT, 720, | |
"framerate", GST_TYPE_FRACTION, 30, 1,NULL); | |
/* link the tee element */ | |
gst_element_link_filtered(src, tee, caps); | |
/* Manually link the Tee, which has "Request" pads */ | |
tee_src_pad_template = gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (tee), "src_%u"); | |
/* Obtaining request pads for the tee elements*/ | |
tee_q1_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL); | |
g_print ("Obtained request pad %s for q1 branch.\n", gst_pad_get_name (tee_q1_pad)); | |
q1_pad = gst_element_get_static_pad (q1, "sink"); | |
tee_q2_pad = gst_element_request_pad (tee, tee_src_pad_template, NULL, NULL); | |
g_print ("Obtained request pad %s for q2 branch.\n", gst_pad_get_name (tee_q2_pad)); | |
q2_pad = gst_element_get_static_pad (q2, "sink"); | |
/* Link the tee to the queue 1 */ | |
gst_pad_link(tee_q1_pad, q1_pad); | |
gst_pad_link(tee_q2_pad, q2_pad); | |
gst_object_unref (q1_pad); | |
gst_object_unref (q2_pad); | |
/* Link the first sink */ | |
gst_element_link_many(q1, rtph264, sink, NULL); | |
gst_element_link_many(q2, encoder , h264parse, mp4mux , filesink, NULL); | |
gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING); | |
bus = gst_element_get_bus (pipeline); | |
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR ); | |
gst_element_release_request_pad (tee, tee_q1_pad); | |
gst_element_release_request_pad (tee, tee_q2_pad); | |
gst_object_unref (tee_q1_pad); | |
gst_object_unref (tee_q2_pad); | |
gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL); | |
gst_object_unref(GST_OBJECT(pipeline)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment