[gst-devel] setting packet time on playbin

René Stadler mail at renestadler.de
Mon Oct 15 19:01:34 CEST 2007


Alfred E. Heggestad schrieb:
> René Stadler wrote:
>> Am Samstag, den 06.10.2007, 15:49 +0200 schrieb Alfred E. Heggestad:
>>> Hi
>>>
>>> I am using the 'playbin' source with my own fakesink callback function
>>> to get the raw pcm data, which works fine.
>>>
>>>
>>> static void handoff_handler(GstFakeSink *fakesink, GstBuffer *buffer,
>>>                 GstPad *pad, gpointer user_data)
>>> {
>>>     /* ... */
>>> }
>>>
>>>
>>> void init(void)
>>> {
>>>     /* Override audio-sink handoff handler */
>>>     g_object_set(G_OBJECT(g->sink), "signal-handoffs", TRUE, NULL);
>>>     g_signal_connect (g->sink, "handoff", G_CALLBACK 
>>> (handoff_handler), g);
>>>     g_object_set(G_OBJECT(g->source), "audio-sink", g->sink, NULL);
>>> }
>>>
>>>
>>>
>>> current the PCM data on the handoff_handler is 44.1kHz/2ch, which gives
>>> 2304 samples each time the function is called. that corresponds to a 
>>> packet
>>> time of ~38 milliseconds.
>>>
>>>
>>> my question is basically; is it possible to set the packet time so my
>>> callback function is called with a packet time of e.g. 20 milliseconds
>>> (i.e. 50 times per second). ?
>>>
>>>
>>> Thanks for this great software
>>>
>>>
>>> /alfred
>>
>> In general, this is not possible.  If you are reading from a raw audio
>> source that is derived from GstBaseSrc, you can set the "blocksize"
>> property however.
>>
>> You can also use GstAdapter in your app.  You would feed all buffers
>> into the adapter and then read from there in any size you desire.
>>
> 
> thanks for your reply.
> 
> I tried the GstAdapter and it was working quite well..
> 
> 
> What I am trying to do is to use "playbin" to play any source (http/file)
> in any format (mp3/ogg/sid) etc., and pipe the raw PCM audio to my 
> application
> in this format:
> 
>   width:        16-bit signed
>   samplerate:   8000 Hz, 16000 Hz or 32000 Hz
>   channels:     1 or 2
>   packet time:  20ms - 100ms
> 
> 
> this is now working for mp3 streams, but I am using libsamplerate to
> resample from 44100Hz to e.g. 8000Hz. Ideally I would also like to use
> gstreamer for the whole pipeline.
> 
> the format of the buffer that is sent to my handler_handler() is dependant
> on the source, I have seen 32-bits float for MP3 source and 16-bit int
> for SID-tune source.
> 
> 
> while it is possible to detect this in run-time using
> gst_structure_get_int(s, "width", &width); on the Buffer's CAPS structure,
> and decode accordingly, I would rather prefer to *always* get the format
> of the GstBuffer in 16-bit signed int. Do you know if this is possible,
> and how this can be achieved when setting up the pipeline, playbin etc?
> 
> 
> thanks again for your help :)
> 
> 
> 
> /alfred

This is usually done with a combination of an audioconvert, 
audioresample and a capsfilter element.  Before your sink, you need to 
have these three elements in a row.  Capsfilter has a property named 
"caps", set this to the fixed caps you want as output.  This forces 
upstream to deliver data in this format, the audioconvert and 
audioresample elements will handle all conversions that are needed.

Since you are using playbin, there is no need to need for audioconvert 
and audioresample since playbin adds these before the audio sink 
already.  So for playbin usage, create a bin which you set as audio-sink 
later.  Inside the bin, put a capsfilter linked to your fakesink.  Add a 
ghost pad named "sink" to the bin which proxies the sink pad of the 
capsfilter.  This makes the bin look like a regular audio sink which 
supports a single format to the outside world.

-- 
Regards,
   René Stadler




More information about the gstreamer-devel mailing list