I have a problem, I want to switch two push instructions, I read that can be done by modifying the factory and triggering the media_configure signal, but now found a problem, After I execute the toggle function (gst_rtsp_media_factory_set_launch (factory, instruction4) Logically, the media_configure signal will be triggered immediately, but in fact, it will be triggered about 10 seconds after triggering the media_configure signal. In addition, when the MEDIA_Configure signal is triggered to switch to the interface, there will be about 3s interface delay. What is the reason?
The specific code is as follows:
int main(void)
{
...
factory = gst_rtsp_media_factory_new ();
g_signal_connect (factory, "media-configure", (GCallback) media_configure, NULL);
...
}
//media_configure function
static void media_configure (GstRTSPMediaFactory * factory, GstRTSPMedia * media,gpointer user_data)
{
printf("******************into media_configure******************\n");
pipeline = gst_rtsp_media_get_element (media);
}
//switch function
void switchFactory(int instNum)
{
printf("into switchFactory\n");
gst_element_set_state(pipeline, GST_STATE_NULL);
char *instruction1 = "(compositor name=mix sink_0::alpha=1 sink_0::xpos=0 sink_0::ypos=0 sink_0::width=640 sink_0::height=480 sink_1::alpha=1 sink_1::xpos=0 sink_1::ypos=165 sink_1::width=180 sink_1::height=150 sink_2::alpha=1 sink_2::xpos=460 sink_2::ypos=165 sink_2::width=180 sink_2::height=150 ! videoconvert ! mpph264enc bps-max=1000 ! h264parse ! rtph264pay name=pay0 pt=96 v4l2src device=/dev/video11 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480,pixel-aspect-ratio=1/1 ! mix.sink_0 v4l2src device=/dev/video12 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480,pixel-aspect-ratio=1/1 ! videoflip video-direction=180 ! mix.sink_1 v4l2src device=/dev/video13 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480,pixel-aspect-ratio=1/1 ! mix.sink_2 )";
char *instruction2 = "(videomixer name=mix sink_0::alpha=1 sink_0::xpos=0 sink_0::ypos=0 sink_1::alpha=1 sink_1::xpos=650 sink_1::ypos=0 sink_2::alpha=1 sink_2::xpos=0 sink_2::ypos=482 sink_3::alpha=1 sink_3::xpos=650 sink_3::ypos=482 ! videoconvert ! mpph264enc bps-max=1000 ! h264parse ! rtph264pay name=pay0 pt=96 v4l2src device=/dev/video11 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix.sink_0 v4l2src device=/dev/video12 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix.sink_1 v4l2src device=/dev/video13 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix.sink_2 v4l2src device=/dev/video14 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix.sink_3)";
char *instruction3 = "(videomixer name=mix sink_0::alpha=1 sink_0::xpos=0 sink_0::ypos=0 sink_1::alpha=1 sink_1::xpos=646 sink_1::ypos=0 sink_2::alpha=1 sink_2::xpos=1292 sink_2::ypos=0 sink_3::alpha=1 sink_3::xpos=1938 sink_3::ypos=0 sink_4::alpha=1 sink_4::xpos=0 sink_4::ypos=486 sink_5::alpha=1 sink_5::xpos=646 sink_5::ypos=486 sink_6::alpha=1 sink_6::xpos=1292 sink_6::ypos=486 sink_7::alpha=1 sink_7::xpos=1938 sink_7::ypos=486 ! videoconvert ! mpph264enc bps-max=1000 ! h264parse ! rtph264pay name=pay0 pt=96 v4l2src device=/dev/video11 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix. v4l2src device=/dev/video12 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix. v4l2src device=/dev/video13 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix. v4l2src device=/dev/video14 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix. v4l2src device=/dev/video3 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix. v4l2src device=/dev/video2 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix. v4l2src device=/dev/video1 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix. v4l2src device=/dev/video0 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=640,height=480 ! videorate ! video/x-raw,framerate=25/1 ! mix.)";
char *instruction4 = "(v4l2src device=/dev/video11 ! video/x-raw,format=NV12,width=1920,height=1080 ! mpph264enc bps-max=1000 ! rtph264pay name=pay0 pt=96 )";
char *instruction5 = "(videomixer name=mix sink_0::alpha=1 sink_0::xpos=0 sink_0::ypos=0 sink_1::alpha=1 sink_1::xpos=960 sink_1::ypos=0 ! videoconvert ! mpph264enc bps-max=1000 ! h264parse ! rtph264pay name=pay0 pt=96 v4l2src device=/dev/video11 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=960,height=540 ! videorate ! video/x-raw,framerate=25/1 ! mix.sink_0 v4l2src device=/dev/video12 ! video/x-raw,format=NV12,width=1920,height=1080 ! videoscale ! video/x-raw,width=960,height=540 ! videorate ! video/x-raw,framerate=25/1 ! mix.sink_1)";
if(instNum == 1){
g_print ("instNum is 1\n");
gst_rtsp_media_factory_set_launch (factory, instruction4);
g_print ("--------instNum is 1 end--------\n");
}
else if(instNum == 2){
g_print ("instNum is 2\n");
gst_rtsp_media_factory_set_launch (factory, instruction5);
g_print ("--------instNum is 2 end--------\n");
}
}