Custom AudioSrc for playing indexed sounds

TheGiamig thegiamig at gmail.com
Fri Sep 21 10:08:34 UTC 2018


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/


More information about the gstreamer-devel mailing list