Add audio delay "gstreamer"

Puyol paul9510 at hotmail.fr
Tue May 13 07:21:04 PDT 2014


Bonjour tout le monde, 
j'essaie de coder une application permettant de lire la voix avec gstreamer
et la diffuser vers un client, je veux que le temps d'arrivée de la voix au
client depuis le serveur sera réglable, c'est à dire changer la délai, j'ai
cherché plusieurs tutoriels mais pas de résolution de prob!! 
voici le serveur : 
int 
main (int argc, char *argv[]) 
{ 
  GstElement *audiosrc, *audioconv, *audiores, *audioenc, *audiopay; 
  GstElement *rtpbin, *rtpsink, *rtcpsink, *rtcpsrc; 
  GstElement *pipeline; 
  GMainLoop *loop; 
  GstPad *srcpad, *sinkpad; 

  gst_init (&argc, &argv); 

  pipeline = gst_pipeline_new (NULL); 
  g_assert (pipeline); 

  audiosrc = gst_element_factory_make (AUDIO_SRC, "audiosrc"); 
  g_assert (audiosrc); 
  audioconv = gst_element_factory_make ("audioconvert", "audioconv"); 
  g_assert (audioconv); 
  audiores = gst_element_factory_make ("audioresample", "audiores"); 
  g_assert (audiores); 
  audioenc = gst_element_factory_make (AUDIO_ENC, "audioenc"); 
  g_assert (audioenc); 
  audiopay = gst_element_factory_make (AUDIO_PAY, "audiopay"); 
  g_assert (audiopay); 

  gst_bin_add_many (GST_BIN (pipeline), audiosrc, audioconv, audiores, 
      audioenc, audiopay, NULL); 

  if (!gst_element_link_many (audiosrc, audioconv, audiores, audioenc, 
          audiopay, NULL)) { 
    g_error ("Failed to link audiosrc, audioconv, audioresample, " 
        "audio encoder and audio payloader"); 
  } 

  rtpbin = gst_element_factory_make ("gstrtpbin", "rtpbin"); 
  g_assert (rtpbin); 

  gst_bin_add (GST_BIN (pipeline), rtpbin); 

  rtpsink = gst_element_factory_make ("udpsink", "rtpsink"); 
  g_assert (rtpsink); 
  g_object_set (rtpsink, "port", 5002, "host", DEST_HOST, NULL); 

  rtcpsink = gst_element_factory_make ("udpsink", "rtcpsink"); 
  g_assert (rtcpsink); 
  g_object_set (rtcpsink, "port", 5003, "host", DEST_HOST, NULL); 
  g_object_set (rtcpsink, "async", FALSE, "sync", FALSE, NULL); 

  rtcpsrc = gst_element_factory_make ("udpsrc", "rtcpsrc"); 
  g_assert (rtcpsrc); 
  g_object_set (rtcpsrc, "port", 5007, NULL); 

  gst_bin_add_many (GST_BIN (pipeline), rtpsink, rtcpsink, rtcpsrc, NULL); 

  sinkpad = gst_element_get_request_pad (rtpbin, "send_rtp_sink_0"); 
  srcpad = gst_element_get_static_pad (audiopay, "src"); 
  if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) 
    g_error ("Failed to link audio payloader to rtpbin"); 
  gst_object_unref (srcpad); 

  srcpad = gst_element_get_static_pad (rtpbin, "send_rtp_src_0"); 
  sinkpad = gst_element_get_static_pad (rtpsink, "sink"); 
  if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) 
    g_error ("Failed to link rtpbin to rtpsink"); 
  gst_object_unref (srcpad); 
  gst_object_unref (sinkpad); 
  srcpad = gst_element_get_request_pad (rtpbin, "send_rtcp_src_0"); 
  sinkpad = gst_element_get_static_pad (rtcpsink, "sink"); 
  if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) 
    g_error ("Failed to link rtpbin to rtcpsink"); 
  gst_object_unref (sinkpad); 

  srcpad = gst_element_get_static_pad (rtcpsrc, "src"); 
  sinkpad = gst_element_get_request_pad (rtpbin, "recv_rtcp_sink_0"); 
  if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) 
    g_error ("Failed to link rtcpsrc to rtpbin"); 
  gst_object_unref (srcpad); 
  g_print ("starting sender pipeline\n"); 
  gst_element_set_state (pipeline, GST_STATE_PLAYING); 

  g_timeout_add (1000, (GSourceFunc) print_stats, rtpbin); 

  loop = g_main_loop_new (NULL, FALSE); 
  g_main_loop_run (loop); 

  g_print ("stopping sender pipeline\n"); 
  gst_element_set_state (pipeline, GST_STATE_NULL); 

  return 0; 
} 
et ceci est le client : 
int 
main (int argc, char *argv[]) 
{ 
  GstElement *rtpbin, *rtpsrc, *rtcpsrc, *rtcpsink; 
  GstElement *audiodepay, *audiodec, *audiores, *audioconv, *audiosink; 
  GstElement *pipeline; 
  GMainLoop *loop; 
  GstCaps *caps; 
  gboolean res; 
  GstPadLinkReturn lres; 
  GstPad *srcpad, *sinkpad; 

  gst_init (&argc, &argv); 

  pipeline = gst_pipeline_new (NULL); 
  g_assert (pipeline); 

  rtpsrc = gst_element_factory_make ("udpsrc", "rtpsrc"); 
  g_assert (rtpsrc); 
  g_object_set (rtpsrc, "port", 5002, NULL); 
  caps = gst_caps_from_string (AUDIO_CAPS); 
  g_object_set (rtpsrc, "caps", caps, NULL); 
  gst_caps_unref (caps); 

  rtcpsrc = gst_element_factory_make ("udpsrc", "rtcpsrc"); 
  g_assert (rtcpsrc); 
  g_object_set (rtcpsrc, "port", 5003, NULL); 

  rtcpsink = gst_element_factory_make ("udpsink", "rtcpsink"); 
  g_assert (rtcpsink); 
  g_object_set (rtcpsink, "port", 5007, "host", DEST_HOST, NULL); 
  g_object_set (rtcpsink, "async", FALSE, "sync", FALSE, NULL); 

  gst_bin_add_many (GST_BIN (pipeline), rtpsrc, rtcpsrc, rtcpsink, NULL); 

  audiodepay = gst_element_factory_make (AUDIO_DEPAY, "audiodepay"); 
  g_assert (audiodepay); 
  audiodec = gst_element_factory_make (AUDIO_DEC, "audiodec"); 
  g_assert (audiodec); 
  audioconv = gst_element_factory_make ("audioconvert", "audioconv"); 
  g_assert (audioconv); 
  audiores = gst_element_factory_make ("audioresample", "audiores"); 
  g_assert (audiores); 
  audiosink = gst_element_factory_make (AUDIO_SINK, "audiosink"); 
  g_assert (audiosink); 

  gst_bin_add_many (GST_BIN (pipeline), audiodepay, audiodec, audioconv, 
      audiores, audiosink, NULL); 

  res = gst_element_link_many (audiodepay, audiodec, audioconv, audiores, 
      audiosink, NULL); 
  g_assert (res == TRUE); 

  rtpbin = gst_element_factory_make ("gstrtpbin", "rtpbin"); 
  g_assert (rtpbin); 

  gst_bin_add (GST_BIN (pipeline), rtpbin); 
  srcpad = gst_element_get_static_pad (rtpsrc, "src"); 
  sinkpad = gst_element_get_request_pad (rtpbin, "recv_rtp_sink_0"); 
  lres = gst_pad_link (srcpad, sinkpad); 
  g_assert (lres == GST_PAD_LINK_OK); 
  gst_object_unref (srcpad); 
  srcpad = gst_element_get_static_pad (rtcpsrc, "src"); 
  sinkpad = gst_element_get_request_pad (rtpbin, "recv_rtcp_sink_0"); 
  lres = gst_pad_link (srcpad, sinkpad); 
  g_assert (lres == GST_PAD_LINK_OK); 
  gst_object_unref (srcpad); 
  gst_object_unref (sinkpad); 
  srcpad = gst_element_get_request_pad (rtpbin, "send_rtcp_src_0"); 
  sinkpad = gst_element_get_static_pad (rtcpsink, "sink"); 
  lres = gst_pad_link (srcpad, sinkpad); 
  g_assert (lres == GST_PAD_LINK_OK); 
  gst_object_unref (sinkpad); 
  g_signal_connect (rtpbin, "pad-added", G_CALLBACK (pad_added_cb),
audiodepay); 

  g_signal_connect (rtpbin, "on-ssrc-active", G_CALLBACK
(on_ssrc_active_cb), 
      audiodepay); 

  g_print ("starting receiver pipeline\n"); 
  gst_element_set_state (pipeline, GST_STATE_PLAYING); 
  loop = g_main_loop_new (NULL, FALSE); 
  g_main_loop_run (loop); 

  g_print ("stopping receiver pipeline\n"); 
  gst_element_set_state (pipeline, GST_STATE_NULL); 

  gst_object_unref (pipeline); 

  return 0; 
} 
Merci d'avance !!



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Add-audio-delay-gstreamer-tp4666954.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list