2013-12-10 4 views
1

I가 그들 중 하나는 UDP 포트로 음성 신호를 전송하고, 다른 하나는 수신기 측에서 동일한 포트 번호들을 수신하여 다음 파이프gstreamer를 소스 코드가 작동 그다지

gst-launch-1.0 -v alsasrc ! audioconvert 
! audio/x-raw,channels=2,depth=16,width=16,rate=44100 ! 
    rtpL16pay ! udpsink 
    host=127.0.0.1 port=5000 //sender 

gst-launch-1.0 udpsrc port=5000 ! "application/x-rtp, 
media=(string)audio, clock-rate=(int)44100, 
encoding-name=(string)L16, channels=(int)2, 
payload=(int)96" ! rtpL16depay ! audioconvert 
! alsasink //receiver 

Gstreamer SDK를 사용하여 소스 코드를 작성하려고합니다. 나는 지금까지왔다 :

#include <gst/gst.h> 
#include <string.h> 
int main(int argc, char *argv[]) { 
    GstElement *pipeline, *source, *audiosink,*rtppay,*rtpdepay,*filter,*filter1,*conv,*conv1,*udpsink,*udpsrc,*receive_resample; 
    GstBus *bus; 
    GstMessage *msg; 
    GstCaps *filtercaps; 
    GstStateChangeReturn ret; 

    /* Initialize GStreamer */ 
    gst_init (&argc, &argv); 

    /* Create the elements */ 
    source = gst_element_factory_make ("alsasrc", "source"); 
    conv= gst_element_factory_make ("audioconvert", "conv"); 
    conv1= gst_element_factory_make ("audioconvert", "conv1"); 
    filter=gst_element_factory_make("capsfilter","filter"); 
    rtppay=gst_element_factory_make("rtpL16pay","rtppay"); 
    rtpdepay=gst_element_factory_make("rtpL16depay","rtpdepay"); 
    udpsink=gst_element_factory_make("udpsink","udpsink"); 
    audiosink = gst_element_factory_make ("autoaudiosink", "audiosink"); 
receive_resample = gst_element_factory_make("audioresample", NULL); 

udpsrc=gst_element_factory_make("udpsrc",NULL); 
    filter1=gst_element_factory_make("capsfilter","filter"); 
    g_object_set(udpsrc,"port",5000,NULL); 
    g_object_set (G_OBJECT (udpsrc), "caps", gst_caps_from_string("application/x-rtp,media=audio,payload=96,clock-rate=44100,encoding-name=L16,channels=2"), NULL); 

    /* Create the empty pipeline */ 
    pipeline = gst_pipeline_new ("test-pipeline"); 

    if (!pipeline || !source || !filter || !conv || !rtppay || !udpsink ) { 
    g_printerr ("Not all elements could be created.\n"); 
    return -1; 
    } 

g_object_set(G_OBJECT(udpsink),"host","127.0.0.1",NULL); 
    g_object_set(G_OBJECT(udpsink),"port",5000,NULL); 

filtercaps = gst_caps_new_simple ("audio/x-raw", 
    "channels", G_TYPE_INT, 2, 
    "width", G_TYPE_INT, 16, 
    "depth", G_TYPE_INT, 16, 
    "rate", G_TYPE_INT, 44100, 
    NULL); 

g_object_set (G_OBJECT (filter), "caps", filtercaps, NULL); 
    gst_caps_unref (filtercaps); 


filtercaps = gst_caps_new_simple ("application/x-rtp", 
    "media",G_TYPE_STRING,"audio", 
    "clock-rate",G_TYPE_INT,44100, 
    "encoding-name",G_TYPE_STRING,"L16", 
    "channels", G_TYPE_INT, 2, 
    "payload",G_TYPE_INT,96, 
    NULL); 

g_object_set (G_OBJECT (filter1), "caps", filtercaps, NULL); 
gst_caps_unref (filtercaps); 

    /* Build the pipeline */ 
    gst_bin_add_many (GST_BIN (pipeline), source,filter,conv,rtppay,udpsink, NULL); 
    if (gst_element_link_many (source,filter,conv,rtppay,udpsink, NULL) != TRUE) { 
    g_printerr ("Elements could not be linked.\n"); 
    gst_object_unref (pipeline); 
    return -1; 
    } 

gst_bin_add_many (GST_BIN (pipeline),udpsrc,rtpdepay,conv1,receive_resample,audiosink,NULL); 
    if (gst_element_link_many (udpsrc,rtpdepay,conv1,receive_resample,audiosink,NULL) != TRUE) { 
    g_printerr ("Elements could not be linked.\n"); 
    gst_object_unref (pipeline); 
    return -1; 
    } 

    /* Modify the source's properties */ 
// g_object_set (source, "pattern", 0, NULL); 

    /* Start playing */ 
    ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); 
    if (ret == GST_STATE_CHANGE_FAILURE) { 
    g_printerr ("Unable to set the pipeline to the playing state.\n"); 
    gst_object_unref (pipeline); 
    return -1; 
    } 

    /* Wait until error or EOS */ 
    bus = gst_element_get_bus (pipeline); 
    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); 

    /* Parse message */ 
    if (msg != NULL) { 
    GError *err; 
    gchar *debug_info; 

    switch (GST_MESSAGE_TYPE (msg)) { 
     case GST_MESSAGE_ERROR: 
     gst_message_parse_error (msg, &err, &debug_info); 
     g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message); 
     g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none"); 
     g_clear_error (&err); 
     g_free (debug_info); 
     break; 
     case GST_MESSAGE_EOS: 
     g_print ("End-Of-Stream reached.\n"); 
     break; 
     default: 
     /* We should not reach here because we only asked for ERRORs and EOS */ 
     g_printerr ("Unexpected message received.\n"); 
     break; 
    } 
    gst_message_unref (msg); 
    } 

    /* Free resources */ 
    gst_object_unref (bus); 
    gst_element_set_state (pipeline, GST_STATE_NULL); 
    gst_object_unref (pipeline); 
    return 0; 
} 

그러나 어떻게 든 나는 수신기에 어떤 음성도받지 않는다. 나는 어떤 종류의 어떤 오류도 얻지 않는다. 왜 그런지 알고 싶습니다.

답변

0

글쎄, 나는 그것을 알아 냈다. 왜 그런지 모르겠지만 소스 코드를 두 개의 개별 코드로 나누었을 때 그 중 하나에서 UDPsink 요소까지 코드를 포함하고 나머지 요소를 포함했습니다 (의미는 udpsrc, rtpdepay 및 audiosink입니다).)을 다른 소스 코드 파일에 저장하고 두 개의 별도 터미널에서 개별적으로 컴파일했습니다. 나는 아직도 그것이 왜 그런지 모르지만, 그것이 효과가있어서 기쁩니다.

0

송신자와 수신자는 두 개의 서로 다른 프로세스로되어 있기 때문에 두 개의 터미널을 사용할 때 작동합니다.

코드에서 두 파이프 라인을 동일한 파이프 라인 요소에 넣고 연주하도록 설정했습니다. 이것은 지원되지 않으므로 다른 파이프 라인을 만들어야합니다.

pipeline1 = gst_pipeline_new ("src-pipeline"); 
pipeline2 = gst_pipeline_new ("sink-pipeline");