[gst-devel] audioresample

Cai Yuanqing yuanqing.cai at tieto.com
Thu Jan 13 02:48:21 CET 2011


  Hi Suresh:
     Your application have a little problem. :-)


On 01/12/2011 08:41 PM, Jesu Anuroop Suresh wrote:
> Hi Sean,
>
> Yes, what I was trying is to resample the decoded mp3 data to the 
> fixed (22KHZ S16LE) formate,
>
> no matter what is the input rate using a C application.
>
> Thanks for your response.
>
> Here is the piece of the code for the same but it does not work  with 
> audioresample with the caps filter 'resmux'. This code does work 
> without the caps filter 'resmux'.
>
>         GstElement *source, *demuxer, *decoder, *conv, *sink, 
> *resample, *resmux;
>         GstCaps *caps;
>
>         gst_init(NULL, NULL);
>
>         /* Create gstreamer elements */
>         musicPlayer.playPipeline = gst_pipeline_new ("audio-player");
>         source   = gst_element_factory_make ("filesrc", "file-source");
>         sink     = gst_element_factory_make ("alsasink", "audio-output");
>         resample = gst_element_factory_make ("audioresample", 
> "audio-resample");
>         conv     = gst_element_factory_make ("audioconvert", 
>  "converter1");
>
>         caps = gst_caps_new_simple ("audio/x-raw-int",
>                                      "width", G_TYPE_INT, 16,
>                                      "depth", G_TYPE_INT, 16,
>                                      "rate",  G_TYPE_INT, 22050,
>                                      "channels",G_TYPE_INT, 2, NULL
>                                      );
>
>         if (!musicPlayer.playPipeline || !source || !sink ||
>             !resample || !resmux || !caps || !conv)
>         {
>             g_print ("NO MEM Exiting.\n");
>             return 1;
>         }
resmux is not initialized yet,here maybe some random value,you'd better 
remove it from check list.

>
>         /* we set the input filename to the source element */
>         g_object_set (G_OBJECT (source), "location", filePath, NULL);
>
>         demuxer  = gst_element_factory_make ("id3demux", "id3-demuxer");
>         decoder  = gst_element_factory_make ("mad", "mp3-decoder");
>
>          if (!demuxer || !decoder || !conv1)
conv1 ? dose it should be conv?

>          {
>                     g_print ("NO MEM Exiting.\n");
>                     return 1;
>           }
>
>          g_object_set (G_OBJECT (resmux), "caps", caps, NULL);
>          gst_caps_unref (caps);
>
as I said before,resmux haven't initialized ,that's not quite right.
and I suggest you to remove these two lines.

>          /* file-source -> demuxer -> decoder ->  alsa-output */
>         gst_bin_add_many (GST_BIN (musicPlayer.playPipeline),
>                          source, demuxer, decoder, conv, resample, 
> resmux,sink, NULL);
>
>         gst_element_link (source, demuxer);
>         gst_element_link_many (decoder, conv, resample,resmux,sink, NULL);
You can use gst_element_link_filtered to link resample and sink with 
caps instead of this way.
something like:
     gst_element_link (source, demuxer);
     gst_element_link_many (decoder, conv, resample, NULL);
     if ( !gst_element_link_filtered(resample,sink,caps) ){
         g_printerr("Failed to link elements resample and alsa-sink");
     }


>         g_signal_connect (demuxer, "pad-added", G_CALLBACK 
> (on_pad_added), decoder);
>
>         GstBus *bus = 
> gst_pipeline_get_bus(GST_PIPELINE(musicPlayer.playPipeline));
>         gst_bus_add_watch(bus, bus_call, NULL);
>         gst_object_unref(bus);
>
>         gst_element_set_state(GST_ELEMENT(musicPlayer.playPipeline), 
> GST_STATE_PLAYING);
>
>         musicPlayer.playLoop = g_main_loop_new(NULL, FALSE);
>
>         g_main_loop_run(musicPlayer.playLoop);
>
>         gst_element_set_state(GST_ELEMENT(musicPlayer.playPipeline), 
> GST_STATE_NULL);
>         gst_object_unref(GST_OBJECT(musicPlayer.playPipeline));
>
>
>
>
> With Warm Regards
> Jesu Anuroop Suresh
>
> "Any intelligent fool can make things bigger, more complex, and more 
> violent. It takes a touch of genius -- and a lot of courage -- to move 
> in the opposite direction."
> "Anyone who has never made a mistake has never tried anything new."
>
>
I attached my modified source code ,you can try it.
Hope it helps.

Thanks.


-- 
B.R

Cai Yuanqing

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 6087 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20110113/dbb57b38/attachment.c>


More information about the gstreamer-devel mailing list