[gst-devel] How to write multi-pipeline in one application?
linguang_wang at astrocom.cn
linguang_wang at astrocom.cn
Mon Mar 19 09:35:23 CET 2007
gstreamer-develHi,all!
I'm writting a application.It includes speech and video display.This application is about
two live source in two pipelines,The codes as follow:
-----------------------------------------------------------------------------------------
static GstElement *
make_video_pipeline (const gchar * ip)
{
GstElement *vSource, *vEncoder, *vRtppay, *vUdpsend ,*vUdprecv, *vRtpdepay, *vDecoder;
GstElement *vcPipeline,*vsPipeline,*vPipeline;
GstCaps *vCaps;
vCaps = gst_caps_from_string (".........");
/* video line create elements */
vcPipeline = gst_pipeline_new (NULL);
vsPipeline = gst_pipeline_new (NULL);
vPipeline = gst_pipeline_new (NULL);
vSource = gst_element_factory_make("v4l2src", NULL);
vEncoder = gst_element_factory_make ("myencoder", NULL);
vRtppay = gst_element_factory_make ("myrtppay", NULL);
vUdpsend = gst_element_factory_make ("udpsink", NULL);
vUdprecv = gst_element_factory_make("udpsrc", NULL);
vRtpdepay = gst_element_factory_make ("myrtpdepay", NULL);
vDecoder = gst_element_factory_make ("mydecoderandsink", NULL);
g_object_set(G_OBJECT(vUdpsend),"port",6000,NULL);
g_object_set(G_OBJECT(vUdpsend),"host",ip,NULL);
g_object_set(G_OBJECT(vUdprecv),"port",6000,NULL);
g_object_set(G_OBJECT(vUdprecv),"caps",vCaps,NULL);
g_object_set(G_OBJECT(vDecoder),"sync",FALSE,NULL);
gst_bin_add(GST_BIN (vsPipeline),vSource);
gst_bin_add(GST_BIN (vsPipeline),vEncoder);
gst_bin_add(GST_BIN (vsPipeline),vRtppay);
gst_bin_add(GST_BIN (vsPipeline),vUdpsend);
gst_bin_add(GST_BIN (vcPipeline),vUdprecv);
gst_bin_add(GST_BIN (vcPipeline),vRtpdepay);
gst_bin_add(GST_BIN (vcPipeline),vDecoder);
gst_bin_add(GST_BIN (vPipeline),vsPipeline);
gst_bin_add(GST_BIN (vPipeline),vcPipeline);
gst_element_link(vSource , vEncoder);
gst_element_link(vEncoder,vRtppay);
gst_element_link(vRtppay , vUdpsend);
gst_element_link(vUdprecv, vRtpdepay);
gst_element_link(vRtpdepay, vDecoder);
return vPipeline;
}
static GstElement *
make_speech_pipeline (const gchar * ip)
{
GstElement *aSource, *aEncoder, *aRtppay, *aUdpsend ,*aUdprecv, *aRtpdepay, *aDecoder,*aSink , *aQueue;
GstElement *acBin,*asBin,*acPipeline,*asPipeline,*aPipeline;
GstCaps *aCaps;
aCaps = gst_caps_from_string ("...");
aPipeline = gst_pipeline_new (NULL);
acPipeline = gst_pipeline_new (NULL);
asPipeline = gst_pipeline_new (NULL);
aSource = gst_element_factory_make("osssrc", NULL);
aEncoder = gst_element_factory_make ("myencoder", NULL);
aRtppay = gst_element_factory_make ("myrtppay",NULL);
aUdpsend = gst_element_factory_make ("udpsink", NULL);
aUdprecv = gst_element_factory_make("udpsrc", NULL);
aRtpdepay = gst_element_factory_make ("myrtpdepay", NULL);
aDecoder = gst_element_factory_make ("mydecoder", NULL);
aSink = gst_element_factory_make ("osssink", NULL);
g_object_set(G_OBJECT(aUdprecv),"caps",aCaps,NULL);
g_object_set(G_OBJECT(aSink),"sync",FALSE,NULL);
g_object_set(G_OBJECT(aUdpsend),"port",5000,NULL);
g_object_set(G_OBJECT(aUdpsend),"host",ip,NULL);
g_object_set(G_OBJECT(aUdprecv),"port",5000,NULL);
gst_bin_add(GST_BIN (asPipeline),aSource);
gst_bin_add(GST_BIN (asPipeline),aEncoder);
gst_bin_add(GST_BIN (asPipeline),aRtppay);
gst_bin_add(GST_BIN (asPipeline),aUdpsend);
gst_bin_add(GST_BIN (acPipeline),aUdprecv);
gst_bin_add(GST_BIN (acPipeline),aRtpdepay);
gst_bin_add(GST_BIN (acPipeline),aDecoder);
gst_bin_add(GST_BIN (acPipeline),aSink);
gst_bin_add(GST_BIN (aPipeline),asPipeline);
gst_bin_add(GST_BIN (aPipeline),acPipeline);
gst_element_link(aSource , aEncoder);
gst_element_link(aEncoder , aRtppay);
gst_element_link(aRtppay , aUdpsend);
gst_element_link(aUdprecv , aRtpdepay);
gst_element_link(aRtpdepay , aDecoder);
gst_element_link(aDecoder , aSink);
return aPipeline;
}
int main(int argc, char *argv[])
{
GstStateChangeReturn res;
GstElement *ap,*vp,*pipeline;
const char* ip="192.168.1.226";
gst_init (&argc, &argv);
ap = make_speech_pipeline(ip);
vp = make_video_pipeline(ip);
pipeline=gst_pipeline_new(NULL);
gst_bin_add(GST_BIN (pipeline),vp);
gst_bin_add(GST_BIN (pipeline),ap);
printf ("ready...\n");
res = gst_element_set_state (vp, GST_STATE_READY);
res = gst_element_set_state (ap, GST_STATE_READY);
if ( res != GST_STATE_CHANGE_SUCCESS) {
g_print ("could not play\n");
return -1;
}
/* Now set to playing and iterate. */
printf ("Setting to PLAYING\n");
gst_element_set_state (vp, GST_STATE_PLAYING);
gst_element_set_state (ap, GST_STATE_PLAYING);
printf ("Running\n");
char ch;
scanf("%c",&ch);
printf ("Starting to stop!\n");
gst_element_set_state (ap, GST_STATE_NULL);
gst_element_set_state (vp, GST_STATE_NULL);
printf ("ended to stop!\n");
gst_object_unref (GST_OBJECT(vp));
gst_object_unref (GST_OBJECT(ap));
printf ("Deleting pipeline\n");
return 0;
}
-----------------------------------------------------------------------------------------------------------
I'm sorry that the code is so long! When I played this app,It would block on the sound card after a few minutes.
But if I only play audio speech, that is ok.Is there some wrong for using in this two pipelines? Hoping that one of you
can help me out.Thanks in advance!
linguang_wang at astrocom.cn
2007-03-19
More information about the gstreamer-devel
mailing list