[gst-devel] 2009年05月25日 星期一 14时49分53秒 自动保存草稿

xuxin04072129 xuxin04072129 at 126.com
Tue May 26 15:32:13 CEST 2009


hi all
    i have a trouble when i use gstreamer to develop a small project for sending and receiving udp packets with rtp payloaded 

sender------->server|---------------->receiver_1
                                   |--------------->receiver_2
*****************************************************************
sender:
gst-launch -v gstrtpbin name=rtpbin \
filesrc location=filesrc location=/home/xuxin/desktop/g_p/a.avi ! decodebin name=dec \
dec. ! queue ! x264enc byte-stream=false ! rtph264pay ! rtpbin.send_rtp_sink_0 \
rtpbin.send_rtp_src_0 ! udpsink port=5000 host=172.21.29.177 name=vrtpsink \
dec. ! queue ! audioresample ! audioconvert ! alawenc ! rtppcmapay ! rtpbin.send_rtp_sink_1 \
rtpbin.send_rtp_src_1 ! udpsink port=5002 host=172.21.29.177 ts-offset=0 name=artpsink 

Server( ip:172.21.29.177)
gst-launch -v gstrtpbin name=rtpbin latency=200 \
udpsrc caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264" port=5000 ! rtpbin.recv_rtp_sink_0 \
rtpbin. ! udpsink port=5000 host=224.0.0.1 sync=false ts-offset=0 \
udpsrc caps="application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)PCMA" port=5002 ! rtpbin.recv_rtp_sink_1 \
rtpbin. ! udpsink port=5002 host=224.0.0.1 sync=false ts-offset=0 

receiver (in multigroup)

gst-launch -v gstrtpbin name=rtpbin latency=200 \
udpsrc multigroup="224.0.0.1" caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264" port=5000 ! rtpbin.recv_rtp_sink_0 \
rtpbin. ! rtph264depay ! decodebin ! xvimagesink \
udpsrc multigroup="224.0.0.1" caps="application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)PCMA" port=5002 ! rtpbin.recv_rtp_sink_1 \
rtpbin. ! rtppcmadepay ! decodebin ! audioconvert ! audioresample ! alsasink 
**********************************************************************
 then I write "Server" in C language ,the code is showed below
#include <gst/gst.h>
#include <glib.h>
#include <unistd.h>
#include <stdlib.h>

static gboolean
bus_call (GstBus     *bus,
          GstMessage *msg,
          gpointer    data)
{
  GMainLoop *loop = (GMainLoop *) data;
  switch (GST_MESSAGE_TYPE (msg)) {
    case GST_MESSAGE_EOS:
      g_print ("End of stream\n");
      g_main_loop_quit (loop);
      break;
    case GST_MESSAGE_ERROR: {
      gchar *debug;
      GError *error;
      gst_message_parse_error (msg, &error, &debug);
      g_free (debug);
      g_printerr ("Error: %s\n", error->message);
      g_error_free (error);
      g_main_loop_quit (loop);
      break;
    }
    default:
      break;
  }
  return TRUE;
}

static void on_pad_added(GstElement *element, GstPad *pad, gpointer data)
{
    GstPad *sinkpad;
    GstElement *udpsink = (GstElement *)data;
    
    g_print("Dynamic pad created, linking demuxer/decoder\n");
    sinkpad = gst_element_get_static_pad(udpsink, "sink");
    gst_pad_link(pad, sinkpad);
    gst_object_unref(sinkpad);
}

int main(int argc, char **argv)
{
    GMainLoop *loop;
    GstBus *bus;
    GstPad *pad;
    GstCaps *videocap, *audiocap;
    GstElement *pipeline, *gstrtpbin, *udpsrc1, *udpsrc2,
        *udpsink1, *udpsink2;
    
    gst_init(&argc, &argv);
    loop = g_main_loop_new(NULL, FALSE);
    
    pipeline = gst_pipeline_new("server");
    gstrtpbin = gst_element_factory_make("gstrtpbin", "gst_rtpbin");
    udpsrc1 = gst_element_factory_make("udpsrc", "udpsrc1");
    udpsrc2 = gst_element_factory_make("udpsrc", "udpsrc2");
    udpsink1 = gst_element_factory_make("udpsink", "udpsink1");
    udpsink2 = gst_element_factory_make("udpsink", "udpsink2");
    
    if (argc != 4) {
        g_printerr("argument error");
        return -1;
    }
    
    bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
    gst_bus_add_watch(bus, bus_call, loop);
    gst_object_unref(bus);
    
    videocap = gst_caps_new_simple("application/x-rtp", 
        "media", G_TYPE_STRING, "video",
        "clock-rate", G_TYPE_LONG, 90000,
        "encoding-name", G_TYPE_STRING, "H264", NULL);
        
    audiocap = gst_caps_new_simple("application/x-rtp",
        "media", G_TYPE_STRING, "audio",
        "clock-rate", G_TYPE_LONG, 8000,
        "encoding-name", G_TYPE_STRING, "PCMA", NULL);
    
    g_object_set(G_OBJECT(udpsrc1), "caps", videocap, NULL);
    g_object_set(G_OBJECT(udpsrc2), "caps", audiocap, NULL);
    g_object_set(G_OBJECT(udpsrc1), "port", (gint)atoi(argv[1]), NULL);
    g_object_set(G_OBJECT(udpsrc2), "port", (gint)atoi(argv[2]), NULL);
    g_object_set(G_OBJECT(udpsink1), "port", (gint)atoi(argv[1]), NULL);
    g_object_set(G_OBJECT(udpsink2), "port", (gint)atoi(argv[2]), NULL);
    g_object_set(G_OBJECT(udpsink1), "host", argv[3], NULL);
    g_object_set(G_OBJECT(udpsink2), "host", argv[3], NULL);
    
    gst_caps_unref(videocap);
    gst_caps_unref(audiocap);
        
    gst_bin_add_many(GST_BIN(pipeline), udpsrc1, udpsrc2, gstrtpbin, udpsink1, udpsink2, NULL);
    
    pad = gst_element_get_request_pad(gstrtpbin, "recv_rtp_sink_0");
    gst_pad_link(gst_element_get_pad(udpsrc1, "src"), pad);
    
    pad = gst_element_get_request_pad(gstrtpbin, "recv_rtp_sink_1");
    gst_pad_link(gst_element_get_pad(udpsrc2, "src"), pad);
    
    g_signal_connect(gstrtpbin, "pad-added", G_CALLBACK(on_pad_added), udpsink1);
    g_signal_connect(gstrtpbin, "pad_added", G_CALLBACK(on_pad_added), udpsink2);
    
    gst_element_set_state(pipeline, GST_STATE_PLAYING);
    
    g_print("Running...\n");
    g_main_loop_run(loop);
    
    /* Out of the main loop, clean up nicely */
    g_print("Returned, stopping playback\n");
    gst_element_set_state(pipeline, GST_STATE_NULL);
    
    g_print("Deleting pipeline\n");
    gst_object_unref(GST_OBJECT(pipeline));
    
    return 0;
}
*********************************************************************
when i run the server writed in c on my computer , Error: internal data flow error
when i run the server which is not writed in c , Error : internal streamer error clock problem. 
additional debug info: gstbin.c(2240):gst_bin_do_latency_func() : failed to configure latency of 0:00:00:00000000
 
can anybody help me ,thank you very much 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20090526/9f5cf514/attachment.htm>


More information about the gstreamer-devel mailing list