Adding elements to pipeline after pipeline is running

Bilel Bghiel bilel at scentronix.com
Mon May 2 16:15:11 UTC 2022


Hi,

I'm currently running a pipeline, which streams to twitch. After that is
running, I'm adding new elements which also write to file, which don't seem
to work.

This is my code:

void Pipeline::run(){

if (this->isUserPipeline){
videoWriter = new VideoWriter(VideoWriter::VIDEO_MODE::LANDSCAPE,
"/home/bageltop/Desktop/surfing_crop.flv", this->pipeline, 17);
videoWriter2 = new VideoWriter(VideoWriter::VIDEO_MODE::PORTRAIT,
"/home/bageltop/Desktop/surfing_crop.flv", this->pipeline, 19);
videoWriter3 = new VideoWriter(VideoWriter::VIDEO_MODE::SQUARE,
"/home/bageltop/Desktop/surfing_crop.flv", this->pipeline, 1);
}

std::string teeName = "tee" + pipelineUsername;
this->videoTee = gst_element_factory_make("tee", teeName.c_str());
std::string inputname = "input-selector" + this->pipelineUsername;
this->inputselector = gst_element_factory_make("input-selector", inputname.
c_str());
gst_bin_add_many(GST_BIN(this->pipeline),
this->videoTee,
this->inputselector,
NULL);

for (Camera* cam: this->config->cameras){
if ((this->isUserPipeline && cam->sinkIndex == 1) || (!this->isUserPipeline
&& cam->sinkIndex == 2)){
GstPadTemplate *teeTempl = gst_element_class_get_pad_template (
GST_ELEMENT_GET_CLASS (cam->tee), "src_%u");

GstPad* teepad = gst_element_request_pad (cam->tee, teeTempl, NULL, NULL);

GstPadTemplate *teeTmp = gst_element_class_get_pad_template (
GST_ELEMENT_GET_CLASS (this->inputselector), "sink_%u");

GstPad* sinkPad = gst_element_request_pad (this->inputselector, teeTmp, NULL,
NULL);

std::cout << "Link pads: " << gst_pad_link(teepad, sinkPad) << std::endl;
}
}

gst_element_link(this->inputselector, this->videoTee);

if (!this->isUserPipeline){
this->loop = g_main_loop_new(NULL, FALSE);

currentCam = this->config->cameras.at(1);

// Start main loop
this->loop = g_main_loop_new(NULL, TRUE);
g_timeout_add(20, (GSourceFunc) doWork, this);

// Get message bus
this->pBus = gst_pipeline_get_bus(GST_PIPELINE(this->pipeline));
// Check if message bus exists
g_assert(this->pBus);

// Add message bus watcher
gst_bus_add_watch(this->pBus, (GstBusFunc) bus_message, this);

gst_element_set_state(this->pipeline, GST_STATE_PLAYING);
} else {
currentCam = this->config->cameras.at(0);
}

this->sinkName = "recordsink" + this->pipelineUsername + std::to_string(0);
this->videoName = "/home/bageltop/Desktop/video" + this->pipelineUsername +
std::to_string(currentCam->sinkIndex) + ".mp4";
this->queueName = "queue" + this->pipelineUsername + std::to_string(
currentCam->sinkIndex);
if (this->isUserPipeline)
this->setCameraSource(1);
else
this->setCameraSource(2);
if (!this->isUserPipeline){
//twitch->attachToPipeline(this->videoTee, this->pipeline);
}
//gst_bin_add_many (GST_BIN (this->pipeline), queue, videocrop, avenc_flv,
aspratio, mux, demux, avdec_h264, NULL);

GstPadTemplate *templa = gst_element_class_get_pad_template (
GST_ELEMENT_GET_CLASS (this->videoTee), "src_%u");

// Link to file writers(next steps: Only do when user pipeline)
if (this->isUserPipeline) {
videoWriter->linkToTee(this->videoTee);
videoWriter2->linkToTee(this->videoTee);
videoWriter3->linkToTee(this->videoTee);


}


// Run main loop
GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL,
"pipeline");

if (!this->isUserPipeline){

gst_element_set_state(this->pipeline, GST_STATE_PLAYING);
this->isRunning = true;
g_timeout_add_seconds (1, timeout_cb, loop);
GstPad* src = gst_element_get_static_pad (this->videoTee, "sink");
gst_pad_add_probe (src, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
empathy_video_src_drop_eos, NULL, NULL);

g_main_loop_run(this->loop);

// Stop playing pipeline
gst_element_set_state(this->pipeline, GST_STATE_NULL);

// Free memory
gst_object_unref(this->pBus);
g_main_loop_unref(this->loop);
}
}

void Pipeline::setCameraSource(int index){

currentCam = this->config->getCamera(index);
GstPad *newPad = gst_element_get_static_pad(this->inputselector, "sink_0");

std::cout << "Got new pad: " << newPad << std::endl;

g_object_set(G_OBJECT(this->inputselector), "active-pad", newPad, NULL);
gst_object_unref(newPad);

}


Can somebody help on on this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20220502/c739d3e1/attachment-0001.htm>


More information about the gstreamer-devel mailing list