Hi,

I'm trying to use the rtpbin element in a pipeline that I want to set up 
initially to receive rtp data but change to send and receive when a 
destination and send codec is known.  I have attached a small test program 
that shows what I am doing.

Basically, I create a pipeline and add rtpbin and rtpdemux elements and set 
the pipeline to playing to start receiving data.  After a few seconds I add 
an audio source, encoder and payloader to the pipeline, link them up and set 
a destination ip and port.  The problem though is that no rtp data ever gets 
to the network and hence the rtp payload callbacks are never called (I'm 
sending to the listen port).  Not sure why this is happening.

However, if I add a fakesrc element to the pipeline and link it to the sink 
pad of the rtpbin and remove it immediately after setting the pipeline to 
playing, sending rtp audio will then be successful.  It seems like a hack to 
me though.  You can activate this behavior in my test program by passing 
the --use-fakesrc argument.  It seems that linking the fakesrc to the rtpbin 
sink causes something to be initialized differently but I don't know what.  
Any ideas?

BTW, I'm using a copy of the latest rtpbin from darcs compiled without jrtp 
and jingle and gstreamer 0.10.10

Thanks,
~Scott
#include <stdio.h>
#include <glib.h>
#include <gst/gst.h>
#include <unistd.h>
#include <assert.h>

void gstNewPayloadType(GstElement *element, gint pt, GstPad *pad, gpointer data)
{
    printf("Received new RTP payload type %d\n", pt);
}

void gstPayloadTypeChange(GstElement *element, gint pt, gpointer data)
{
    printf("RTP payload type changed to %d\n", pt);
}

int main(int argc, char *argv[])
{
    gboolean use_fakesrc = FALSE;

    gst_init(NULL, NULL);

    if (argc == 2)
    {
        if (g_ascii_strncasecmp(argv[1], "--use-fakesrc", 13) == 0)
        {
            printf("Using fakesrc\n");
            use_fakesrc = TRUE;
        }
    }

    GstElement *pipeline = gst_pipeline_new("pipeline");
    GstElement *rtpBin = gst_element_factory_make("rtpbin", NULL);
    GstElement *rtpDemux = gst_element_factory_make("rtpdemux", NULL);
    GstElement *fakeSrc = NULL;

    gst_bin_add_many(GST_BIN(pipeline), rtpBin, rtpDemux, NULL);
    assert(gst_element_link_pads(rtpBin, "src%d", rtpDemux, "sink") == TRUE);

    if (use_fakesrc)
    {
        fakeSrc = gst_element_factory_make("fakesrc", NULL);
        gst_bin_add(GST_BIN(pipeline), fakeSrc);
        assert(gst_element_link(fakeSrc, rtpBin) == TRUE);
    }

    g_object_set(G_OBJECT(rtpBin), "rtcp-support", FALSE, "localport", 6660, NULL);

    g_signal_connect(G_OBJECT(rtpDemux), "new-payload-type", G_CALLBACK(gstNewPayloadType), NULL);
    g_signal_connect(G_OBJECT(rtpDemux), "payload-type-change", G_CALLBACK(gstPayloadTypeChange), NULL);

    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    if (use_fakesrc)
    {
        gst_bin_remove(GST_BIN(pipeline), fakeSrc);
    }

    printf("Starting to receive...\n");
    for (int i = 0; i < 5; ++i)
    {
        printf(".");
        fflush(NULL);
        sleep(1);
    }

    GstElement *audioSrc = gst_element_factory_make("audiotestsrc", NULL);
    GstElement *audioEncoder = gst_element_factory_make("mulawenc", NULL);
    GstElement *audioPayloader = gst_element_factory_make("rtppcmupay", NULL);

    gst_bin_add_many(GST_BIN(pipeline), audioSrc, audioEncoder, audioPayloader, NULL);

    assert(gst_element_link(audioPayloader, rtpBin) == TRUE);
    assert(gst_element_link(audioEncoder, audioPayloader) == TRUE);
    assert(gst_element_link(audioSrc, audioEncoder) == TRUE);

    g_object_set(G_OBJECT(audioSrc), "is-live", TRUE, NULL);
    g_object_set(G_OBJECT(audioSrc), "blocksize", 320, NULL);
    g_object_set(G_OBJECT(audioPayloader), "max_ptime", G_GINT64_CONSTANT(20000000), NULL);
    g_object_set(G_OBJECT(rtpBin), "destinations", "127.0.0.1:6660", NULL);

    gst_element_set_state(audioPayloader, GST_STATE_PLAYING);
    gst_element_set_state(audioEncoder, GST_STATE_PLAYING);
    gst_element_set_state(audioSrc, GST_STATE_PLAYING);

    printf("\nStarting to send...\n");
    for (int i = 0; i < 5; ++i)
    {
        printf(".");
        fflush(NULL);
        sleep(1);
    }

    printf("\ndone.\n");
    return 0;
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Farsight-devel mailing list
Farsight-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/farsight-devel

Reply via email to