Custom AudioSrc for playing indexed sounds

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom AudioSrc for playing indexed sounds

TheGiamig
Hi all, this is my first message in this list.
I'm working on a complex audio project and I'm new to GStreamer.
The application should receive some commands/data from a flight simulation
and reproduce environmental sounds and communications.
The project is at the beginning and I'm valuating if GStreamer can be a good
choice for the backbone.
After some tests to understand basic stuffs, I tried to write an audio src.
What I'm trying to do is a src element that in the init reads some audio raw
files and hold the content in memory. The application can command to play
one sound, or stop it, or play from a certain position.
When the application commands stop, the pipeline cannot stop because other
sources needs to be played (files, noises..).
I tried some implementations deriving from GstBaseSrc and then GstAudioSrc.
The application controls the element through some properties that I check in
the fill/read function.
The application can stop or pause the play in any moment or command a play
of another sound (stopping the actual one).
I have some problems filling the buffer e managing the timestamp. Not sure I
understand how to do that.

Do you have some tips for me? I mean also about the whole application.
Thanks

My fill function:

static GstFlowReturn
gst_audio_clip_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
GstBuffer * buf) {
  GstAudioClipSrc *src;
  guint to_read;
  GstMapInfo info;

  src = GST_AUDIO_CLIP_SRC_CAST (basesrc);

  if (src->status != PLAYING) {
    //Audio out only in play status
    gst_buffer_resize(buf, 0, 0);  //WHAT IS THE RIGHT WAY TO RETURN
SILENCE?
    return GST_FLOW_OK;
  }
 
  gst_buffer_map (buf, &info, GST_MAP_WRITE);

  guint maxLen = src->clip_data_size - src->read_position;
 
  to_read = length;
 
  if (length > maxLen) {
     to_read = maxLen;
  }
 
  gst_buffer_fill(buf, 0, &(src->clip_data[src->read_position]),  to_read);
 
  src->read_position += to_read;

  gst_buffer_unmap (buf, &info);
 
  if (to_read != length)
    gst_buffer_resize (buf, 0, to_read);

  //WHAT THESE CALLS ACTUALLY DOES?
  GST_BUFFER_OFFSET (buf) = offset;
  GST_BUFFER_OFFSET_END (buf) = offset + to_read;

  return GST_FLOW_OK;
}



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Custom AudioSrc for playing indexed sounds

TheGiamig
Hi,
I derived from GstAudioSrc and tried to just push out some silence.
A simple pipeline: mysrc ! fakesink seems to be working (logs say:
PREROLLING NOT NEEDED and then enter in PLAYING state) but I added some
traces to understand the call sequence and I can see only _open/_close
calls.
What I need to do to allow calls to _prepare/_read etc..
My element is just some boilerplate code + some near-to-empty function
callbacks to implement the base class.
Probably I misunderstand something but is not so simple to write the right
code just starting from other projects on internet.
Where I can find ad example about the silence. And what about an example
explaining how to manage the buffer timestamps and offset?
Thanks



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel