Need an example for "How to play an audio data which is in memory as buffer" ?

Devesh Nagar devesh66 at gmail.com
Wed Jul 22 08:25:10 PDT 2015


How to insert stream data to GstBuffer and push it to the pipe line using
appsrc 

I am able to play the audio using g_object_set (G_OBJECT (data.filesrc),
"location", file name, NULL);
then I inserted it to the pipeline. It works fine.

Now I am getting the stream data from trhe buffer. That is, I want to read
the audio file and store it in buffer using fopen(). How to copy that buffer
to GstBuffer using appsrc/memory_mapping  and push it to the pipeline?

Here is my code snippet :

typedef struct _CustomData{
  GstElement *pipeline;
  GstAppSrc  *appsrc;
  GstElement *convert;
  GstElement *parser;
  GstElement *decoder;
  GstElement *sink;
  GstElement *Sampler;
  GstElement *typefind;
  FILE *file;
  guint sourceid;
} CustomData;

main()
{
 CustomData data1;

//i am reading from file StreamData which contains stream data
data1.file =
fopen("/home/polaris/workspace/Gstreamer/myPrograms/StreamData", "r");

//then I createc elements and  and made a link to them and thus creating the
pipeline. After that i am calling start_feed function as,

   g_signal_connect(data1.appsrc, "need-data", G_CALLBACK(start_feed),
&data1);
    g_signal_connect(data1.appsrc, "enough-data", G_CALLBACK(stop_feed),
&data1);

//then we start playing by changing the state to play state using,
gst_element_set_state ((GstElement *)data1.pipeline, GST_STATE_PLAYING)

}


static void start_feed (GstElement * pipeline, guint size, CustomData *data)
{
 if (data->sourceid == 0) {
  GST_DEBUG ("start feeding");
  data->sourceid = g_idle_add ((GSourceFunc) read_data, data);
 }
}

static void stop_feed (GstElement * pipeline,CustomData *data)
{
 if (data->sourceid != 0) {
  GST_DEBUG ("stop feeding");
  g_source_remove (data->sourceid);
  data->sourceid = 0;
 }
}

static gboolean read_data(CustomData *data)
{
 GstBuffer *buffer;
 guint8 *ptr;
 gint size;
 GstFlowReturn ret;
  int i;
GstMemory *memory;
 GstMapInfo info;

 ptr = g_malloc(BUFF_SIZE);
 g_assert(ptr);

 size = fread(ptr, 1, BUFF_SIZE, data->file);

 if(size == 0){
  ret = gst_app_src_end_of_stream(data->appsrc);
  g_debug("eos returned %d at %d\n", ret, __LINE__);
  return FALSE;
 }

    buffer = gst_buffer_new ();
    memory = gst_allocator_alloc (NULL, size, NULL);
    gst_buffer_insert_memory (buffer, -1, memory);
     gst_memory_map (memory, &info, GST_MAP_WRITE);

    for(i=0;i<info.size; i++)
    {
        info.data= ptr[i];
    }

 ret = gst_app_src_push_buffer(data->appsrc, buffer);

}


Is that mapping is proper? 
Is copying the audio data to GstBuffer 
proper?

Please Help



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Need-an-example-for-How-to-play-an-audio-data-which-is-in-memory-as-buffer-tp4672763p4672792.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list