gstreamer c代码中使用“的内部数据流错误”;加法器;元素?

gstreamer c代码中使用“的内部数据流错误”;加法器;元素?,gstreamer,Gstreamer,我想把我的gst启动命令转换成c代码。我不熟悉gstreamer编码。有人能帮我吗 命令:gst-launch-0.10 uridecodebin uri=file:///media/afeb7785-7c21-45bf-b1b7-41d3263022f6/gst/bigcity.wav ! 音频转换!音量='0.9'!音频转换!加法器名称=m!自动音频接收器uridecodebin uri=file:///media/afeb7785-7c21-45bf-b1b7-41d3263022f6/g

我想把我的gst启动命令转换成c代码。我不熟悉gstreamer编码。有人能帮我吗

命令:gst-launch-0.10 uridecodebin uri=file:///media/afeb7785-7c21-45bf-b1b7-41d3263022f6/gst/bigcity.wav ! 音频转换!音量='0.9'!音频转换!加法器名称=m!自动音频接收器uridecodebin uri=file:///media/afeb7785-7c21-45bf-b1b7-41d3263022f6/gst/tereliya.wav ! 音频转换!音量='0.3'!音频转换!m

c代码:

#include <gst/gst.h>
#include <glib.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 *decoder = (GstElement *) data;

  /* We can now link this pad with the vorbis-decoder sink pad */
  g_print ("Dynamic pad created, linking \n");

  sinkpad = gst_element_get_static_pad (decoder, "sink");

  gst_pad_link (pad, sinkpad);

  gst_object_unref (sinkpad);
}



int
main (int   argc,
      char *argv[])
{
  GMainLoop *loop;
  GstElement *pipeline, *source1, *source2, *mixer, *conv, *conv2, *sink;
  GstBus *bus;
  guint bus_watch_id;
  GstPad *adder_sinkpad;
  GstPad *adder_sinkpad2;
  GstPad *conv1_pad;
  GstPad *conv2_pad;
  gchar *pad1name;
  gchar *pad2name;
  /* Initialisation */
  gst_init (&argc, &argv);

  loop = g_main_loop_new (NULL, FALSE);


  /* Check input arguments */
/*  if (argc != 3) {
    g_printerr ("Usage: %s \n", argv[0]);
    return -1;
  }*/


  /* Create gstreamer elements */
  pipeline = gst_pipeline_new ("audio-player");
  source1  = gst_element_factory_make ("uridecodebin",  "uri-source1");
  source2  = gst_element_factory_make ("uridecodebin",  "uri-source2");
  mixer    = gst_element_factory_make ("adder",         "audio-mix");
  conv     = gst_element_factory_make ("audioconvert",  "conv");
  conv2     = gst_element_factory_make ("audioconvert", "conv2");
  sink     = gst_element_factory_make ("alsasink", "audio-output");

  if (!pipeline || !source1 || !source2 || !mixer || !conv || !conv2 || !sink) {
    g_printerr ("One element could not be created. Exiting.\n");
    return -1;
  }

  /* Set up the pipeline */

  /* we set the input filename to the source element */
  g_object_set (G_OBJECT (source1), "uri",  "file:///home/baibhav/gst/shadowoftheday.wav", NULL);
  g_object_set (G_OBJECT (source2), "uri",  "file:///home/baibhav/gst/valentinesday.wav" , NULL);

  g_object_set (G_OBJECT (mixer), "name", "mix", NULL);
  /* we add a message handler */
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  bus_watch_id = gst_bus_add_watch (bus, bus_call, loop);
  gst_object_unref (bus);

  /* we add all elements into the pipeline */
  gst_bin_add_many (GST_BIN (pipeline),
                    source1, conv, mixer, sink, source2, conv2, NULL);


  /* we link the elements together */
  int k,n;
  if((k=gst_element_link (source1, conv)) !=0 ) {
    g_print ("link1 error: %d\n",k);
    g_print ("cannot link source1 with conv\n");
    }
  if((n=gst_element_link (source2, conv2)) != 0) {
    g_print ("link2 error: %d\n",n);
    g_print ("cannot link source2 with conv2\n");
    }

  if(gst_element_link (mixer, sink) != TRUE) {
    g_print ("cannot link sink with mixer\n");
    }

  conv1_pad= gst_element_get_static_pad (conv, "src");
  conv2_pad= gst_element_get_static_pad (conv2, "src");
  adder_sinkpad = gst_element_get_request_pad (mixer, "sink%d");
  pad1name = gst_pad_get_name (adder_sinkpad);
  g_print ("pad1name: %s\n",pad1name );
  adder_sinkpad2 = gst_element_get_request_pad (mixer, "sink%d");
  pad2name = gst_pad_get_name (adder_sinkpad2);
  g_print ("pad2name: %s\n",pad2name );
  int i,j;
  if((i=gst_pad_link (conv1_pad, adder_sinkpad)) != 0) {
    g_print ("pad error: %d\n",i);
    g_print ("cannot link conv1 with adder1\n");
     }

  if((j=gst_pad_link (conv2_pad, adder_sinkpad2))!= 0) {
    g_print ("pad2 error: %d\n",j);
    g_print ("cannot link conv2 with adder2\n");
    }

//  g_signal_connect (conv, "pad-added", G_CALLBACK (on_pad_added), mixer);
//  g_signal_connect (conv2, "pad-added", G_CALLBACK (on_pad_added), mixer);

  /* Set the pipeline to "playing" state*/
  g_print ("Now playing\n");
  gst_element_set_state (pipeline, GST_STATE_PLAYING);


  /* Iterate */
  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_pad_unlink (conv2_pad, adder_sinkpad2);
//  gst_pad_unlink ((conv1_pad, adder_sinkpad);
  gst_object_unref (GST_OBJECT (pipeline));
  g_source_remove (bus_watch_id);
  g_main_loop_unref (loop);

  return 0;
}
#包括
#包括
静态gboolean
总线呼叫(GstBus*总线,
GstMessage*msg,
gpointer数据)
{
GMainLoop*循环=(GMainLoop*)数据;
开关(GST\信息\类型(msg)){
案例GST\信息\ EOS:
g_打印(“流结束\n”);
g_主循环退出(循环);
打破
案例GST\u消息\u错误:{
gchar*调试;
GError*错误;
gst\消息\解析\错误(消息、错误和调试);
g_自由(调试);
g_printerr(“错误:%s\n”,错误->消息);
g_无错误(错误);
g_主循环退出(循环);
打破
}
违约:
打破
}
返回TRUE;
}
静态空隙
在键盘上添加(GstElement*元素,
GstPad*焊盘,
gpointer数据)
{
GstPad*下沉板;
GstElement*解码器=(GstElement*)数据;
/*我们现在可以把这个垫子和vorbis解码器接收器垫子连接起来*/
g_print(“创建动态焊盘,链接”);
sinkpad=gst_元素_get_静态_pad(译码器,“接收器”);
gst_垫_链接(垫、下沉垫);
gst_object_unref(下沉板);
}
int
主(内部argc,
字符*argv[]
{
GMainLoop*循环;
GstElement*管道、*source1、*source2、*mixer、*conv、*conv2、*sink;
GstBus*总线;
吉尼特巴士公司;
GstPad*加法器下沉板;
GstPad*加法器2;
GstPad*conv1_焊盘;
GstPad*conv2_焊盘;
gchar*pad1名称;
gchar*pad2name;
/*初始化*/
gst_init(&argc,&argv);
loop=g_main_loop_new(NULL,FALSE);
/*检查输入参数*/
/*如果(argc!=3){
g_printerr(“用法:%s\n”,argv[0]);
返回-1;
}*/
/*创建gstreamer元素*/
管道=gst_管道_新(“音频播放器”);
source1=gst元素工厂制造(“uridecodebin”、“uri-source1”);
source2=gst元素工厂制造(“uridecodebin”、“uri-source2”);
混音器=gst元素工厂制造(“加法器”、“音频混音”);
conv=gst元素工厂制造(“音频转换”、“conv”);
conv2=gst元件工厂制造(“音频转换”、“conv2”);
接收器=gst元件工厂制造(“ALASINK”、“音频输出”);
如果(!pipeline | | |!source1 | |!source2 | |!mixer | |!conv | |!conv2 | |!sink){
g_printerr(“无法创建一个元素。正在退出。\n”);
返回-1;
}
/*铺设管道*/
/*我们将输入文件名设置为源元素*/
g_对象集(g_对象(source1),“uri”file:///home/baibhav/gst/shadowoftheday.wav“,空);
g_对象集(g_对象(source2),“uri”file:///home/baibhav/gst/valentinesday.wav“,空);
g_对象集(g_对象(混合器),“名称”,“混合”,空);
/*我们添加了一个消息处理程序*/
总线=gst_管道_获取_总线(gst_管道(管道));
bus_watch_id=gst_bus_add_watch(总线、总线调用、环路);
商品及服务税(巴士);
/*我们将所有元素添加到管道中*/
gst_bin_add_many(gst_bin(管道),
source1,conv,mixer,sink,source2,conv2,NULL);
/*我们将这些元素连接在一起*/
int k,n;
如果((k=gst\U元素\U链接(source1,conv))!=0){
g_打印(“链接1错误:%d\n”,k);
g_print(“无法将source1链接到conv\n”);
}
如果((n=gst\u元素\u链接(source2,conv2))!=0){
g_打印(“链接2错误:%d\n”,n);
g_print(“无法将source2链接到conv2\n”);
}
如果(gst_元素_链接(混合器、接收器)!=TRUE){
g_打印(“无法将接收器与混合器链接”\n”);
}
conv1_pad=gst_元素_get_static_pad(conv,“src”);
conv2_pad=gst_元素_get_static_pad(conv2,“src”);
加法器\u sinkpad=gst\u元素\u获取\u请求\u pad(混合器,“接收器%d”);
pad1name=gst\u pad\u get\u name(加法器\u sinkpad);
g_print(“pad1name:%s\n”,pad1name);
加法器\u sinkpad2=gst\u元素\u获取\u请求\u垫(混合器,“接收器%d”);
pad2name=gst\u pad\u get\u name(加法器\u sinkpad2);
g_print(“pad2name:%s\n”,pad2name);
int i,j;
如果((i=gst\u pad\u link(conv1\u pad,adder\u sinkpad))!=0){
g_打印(“焊盘错误:%d\n”,i);
g_print(“无法将conv1链接到ADER1\n”);
}
如果((j=gst\u pad\u链接(conv2\u pad,adder\u sinkpad2))!=0){
g_打印(“pad2错误:%d\n”,j);
g_print(“无法将conv2与adder2链接\n”);
}
//g_信号_连接(conv,“pad added”,g_回调(on_pad_added),混音器);
//g_信号连接(conv2,“添加焊盘”,g_回调(添加焊盘上),混音器);
/*将管道设置为“正在播放”状态*/
g_print(“正在播放”);
gst元素设置状态(管道、gst状态);
/*迭代*/
g_打印(“运行…\n”);
g_主循环运行(循环);
/*离开主回路,好好清理*/
g_print(“返回,停止播放”);
gst\元素\集合\状态(管道,gst\状态\空);
g_print(“删除管道”);
//gst_pad_unlink(conv2_pad,adder_sinkpad2);
//gst_pad_unlink((conv1_pad,adder_sinkpad);
gst_对象_unref(gst_对象(管道));
g_源_移除(总线_监视_id);
g_主回路_unref(回路);
返回0;
}

对于您的应用程序,不需要为pad added signal添加信号处理程序。您只需按如下方式编写应用程序:

#include <gst/gst.h>
#include <glib.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;
    }



int main (int   argc,
    char *argv[])
    {
GMainLoop *loop;
GstElement *pipeline, *source1, *source2, *mixer, *conv, *conv2, *sink;
GstBus *bus;
guint bus_watch_id;
GstPad *adder_sinkpad;
GstPad *adder_sinkpad2;
GstPad *conv1_pad;
GstPad *conv2_pad;
gchar *pad1name;
gchar *pad2name;
/* Initialisation */
gst_init (&argc, &argv);

loop = g_main_loop_new (NULL, FALSE);


/* Check input arguments */
/*  if (argc != 3) {
 *      g_printerr ("Usage: %s \n", argv[0]);
 *          return -1;
 *            }*/


/* Create gstreamer elements */
pipeline = gst_pipeline_new ("audio-player");
source1  = gst_element_factory_make ("audiotestsrc",  "uri-source1");
source2  = gst_element_factory_make ("audiotestsrc",  "uri-source2");
mixer    = gst_element_factory_make ("adder",         "audio-mix");
conv     = gst_element_factory_make ("audioconvert",  "conv");
conv2     = gst_element_factory_make ("audioconvert", "conv2");
sink     = gst_element_factory_make ("alsasink", "audio-output");

if (!pipeline || !source1 || !source2 || !mixer || !conv || !conv2 || !sink) {
    g_printerr ("One element could not be created. Exiting.\n");
    return -1;
}

/* Set up the pipeline */

/* we set the input filename to the source element */
g_object_set (G_OBJECT (source1), "uri",  "file:///home/baibhav/gst/shadowoftheday.wav", NULL);
g_object_set (G_OBJECT (source2), "uri",  "file:///home/baibhav/gst/valentinesday.wav" , NULL);

g_object_set (G_OBJECT (mixer), "name", "mix", NULL);
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
bus_watch_id = gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);

/* we add all elements into the pipeline */
gst_bin_add_many (GST_BIN (pipeline),
        source1, conv, mixer, sink, source2, conv2, NULL);


/* we link the elements together */
int k,n;
if((k=gst_element_link_many (source1, conv,mixer,NULL)== 0) ) {
    g_print ("link1 error: %d\n",k);
    g_print ("cannot link source1 with conv\n");
}
if((n=gst_element_link_many (source2, conv2,mixer,NULL))== 0 ) {
    g_print ("link2 error: %d\n",n);
    g_print ("cannot link source2 with conv2\n");
}

if(gst_element_link (mixer, sink) == 0 ) {
    g_print ("cannot link sink with mixer\n");
}


//    /* Set the pipeline to "playing" state*/
g_print ("Now playing\n");
gst_element_set_state (pipeline, GST_STATE_PLAYING);
//
//
//          /* Iterate */
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_pad_unlink (conv2_pad, adder_sinkpad2);
//  gst_pad_unlink ((conv1_pad, adder_sinkpad);
gst_object_unref (GST_OBJECT (pipeline));
g_source_remove (bus_watch_id);
g_main_loop_unref (loop);

return 0;
#包括
#包括
静态gboolean
总线呼叫(GstBus*总线,
GstMessage*msg,
gpointer数据)
{
GMainLoop*循环=(GMainLoop*)数据;
开关(GST\信息\类型(msg)){
案例GST\信息\ EOS:
g_打印(“流结束\n”);
g_主循环退出(循环);
打破
案例GST\u消息\u错误:{
gchar*调试;
GError*错误;
gst\消息\解析\错误(消息、错误和调试);
g_自由(调试);
#include <gst/gst.h>
#include <glib.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 *decoder = (GstElement *) data;

  /* We can now link this pad with the vorbis-decoder sink pad */
  g_print ("Dynamic pad created, linking \n");

  sinkpad = gst_element_get_static_pad (decoder, "sink");

  gst_pad_link (pad, sinkpad);

  gst_object_unref (sinkpad);
}



int
main (int   argc,
      char *argv[])
{
  GMainLoop *loop;
  GstElement *pipeline, *source1, *source2, *mixer, *conv1, *conv2, *sink;
  GstBus *bus;
  guint bus_watch_id;
  GstPad *adder_sinkpad1;
  GstPad *adder_sinkpad2;
  GstPad *vol1_pad, *vol2_pad;
  gchar *pad1name;
  gchar *pad2name;
  GstElement *vol1, *vol2;
  int n;

  /* Initialisation */
  gst_init (&argc, &argv);

  loop = g_main_loop_new (NULL, FALSE);


  /* Check input arguments */
  if (argc != 3) {
    g_printerr ("Usage: %s file1 file2\n", argv[0]);
    return -1;
  }


  /* Create gstreamer elements */
  pipeline = gst_pipeline_new ("audio-player");
  source1  = gst_element_factory_make ("uridecodebin",  "uri-source1");
  source2  = gst_element_factory_make ("uridecodebin",  "uri-source2");
  mixer    = gst_element_factory_make ("adder",         "audio-mix");
  conv1     = gst_element_factory_make ("audioconvert",  "conv1");
  conv2     = gst_element_factory_make ("audioconvert", "conv2");
  vol1 = gst_element_factory_make("volume", "vol1");
  vol2 = gst_element_factory_make("volume", "vol2");
  sink     = gst_element_factory_make ("alsasink", "audio-output");

  if (!pipeline || !source1 || !source2 || !mixer || !conv1 || !conv2 || !vol1 || !vol2 || !sink) {
    g_printerr ("One element could not be created. Exiting.\n");
    return -1;
  }

  /* Set up the pipeline */

  /* we set the input filename to the source element */

  g_object_set (G_OBJECT (source1), "uri",  argv[1], NULL);
  g_object_set (G_OBJECT (source2), "uri",  argv[2], NULL);

  g_object_set (G_OBJECT (mixer), "name", "mix", NULL);

  g_object_set(G_OBJECT (vol1), "volume", 0.9, NULL);
  g_object_set(G_OBJECT (vol2), "volume", 0.3, NULL);

  /* we add a message handler */
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  bus_watch_id = gst_bus_add_watch (bus, bus_call, loop);
  gst_object_unref (bus);

  /* we add all elements into the pipeline */
  gst_bin_add_many (GST_BIN (pipeline),
                    source1, conv1, vol1, mixer, sink, source2, conv2, vol2, NULL);


  /* we link the elements together */
#if 0 //Doesnt work directly linking elements
  g_print("link elements directly \n");
  if((n=gst_element_link (source1, conv1)) == 0 ) {
    g_print ("link1 error: %d\n",n);
    g_print ("cannot link source1 with conv1\n");
  }

  if((n=gst_element_link (source2, conv2)) == 0) {
    g_print ("link2 error: %d\n",n);
    g_print ("cannot link source2 with conv2\n");
  }
#else
  g_print("use dynamic pads to link elements \n");
  g_signal_connect (source1, "pad-added", G_CALLBACK (on_pad_added), conv1);
  g_signal_connect (source2, "pad-added", G_CALLBACK (on_pad_added), conv2);
#endif

  if((n=gst_element_link (conv1, vol1)) == 0) {
    g_print ("link2 error: %d\n",n);
    g_print ("cannot link conv with vol1\n");
  }

  if((n=gst_element_link (conv2, vol2)) == 0) {
    g_print ("link2 error: %d\n",n);
    g_print ("cannot link conv2 with conv2\n");
  }

  if((n = gst_element_link (mixer, sink)) == 0) {
    g_print ("cannot link sink with mixer\n");
  }
  vol1_pad= gst_element_get_static_pad (vol1, "src");
  vol2_pad= gst_element_get_static_pad (vol2, "src");

  adder_sinkpad1 = gst_element_get_request_pad (mixer, "sink_%u");
  pad1name = gst_pad_get_name (adder_sinkpad1);
  g_print ("pad1name: %s\n",pad1name );
  adder_sinkpad2 = gst_element_get_request_pad (mixer, "sink_%u");
  pad2name = gst_pad_get_name (adder_sinkpad2);
  g_print ("pad2name: %s\n",pad2name );

  int i,j;
  if((i=gst_pad_link (vol1_pad, adder_sinkpad1)) != 0) {
    g_print ("pad error: %d\n",i);
    g_print ("cannot link conv1 with adder1\n");
     }

  if((j=gst_pad_link (vol2_pad, adder_sinkpad2))!= 0) {
    g_print ("pad2 error: %d\n",j);
    g_print ("cannot link conv2 with adder2\n");
    }

  /* Set the pipeline to "playing" state*/
  g_print ("Now playing\n");
  gst_element_set_state (pipeline, GST_STATE_PLAYING);


  /* Iterate */
  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));
  g_source_remove (bus_watch_id);
  g_main_loop_unref (loop);

  return 0;
}