Cannot hear audio samples pushed into appsrc

Robert Van Gemert rcvangemert at optushome.com.au
Thu Jun 18 03:56:57 PDT 2015


Hi,

With Gstreamer on android my  pipeline runs but I cannot hear output,  Can you help get me past this. Code segments below, can provide full code if needed.

Thanks,
Robert

#define CHUNK_SIZE 1024   /* Amount of bytes we are sending in each buffer */
#define SAMPLE_RATE 44100 /* Samples per second we are sending */
#define AUDIO_CHANNELS 1

Pipeline -
"appsrc name=asource1 ! audioconvert ! audioresample ! autoaudiosink"

Appsrc caps setup using-

  data->asource1 = gst_bin_get_by_name(GST_BIN(data->pipeline), "asource1");
  if(data->asource1==NULL) {
    GST_DEBUG ("asource1 not found");
  }
  else {
    GST_DEBUG ("data->asource1 (%p)", data->asource1);

    gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_S16, SAMPLE_RATE, AUDIO_CHANNELS, NULL);
    audio_caps = gst_audio_info_to_caps (&info);
    g_object_set(data->asource1, "caps", audio_caps, "format", GST_FORMAT_TIME, NULL);
    
    g_signal_connect (data->asource1, "need-data", G_CALLBACK (start_feed1), &data);
  }

Appsrc push data-

static gboolean push_data (GstElement *source, CustomData *data) {
  GstBuffer *buffer;
  GstFlowReturn ret;
  int i;
  GstMapInfo map;
  gint16 *raw;
  gint num_samples = CHUNK_SIZE / 2; /* Because each sample is 16 bits */
  gfloat freq;
      
  /* Create a new empty buffer */
  buffer = gst_buffer_new_and_alloc (CHUNK_SIZE);
//  buffer = gst_buffer_new_allocate (NULL, CHUNK_SIZE, NULL);

  /* Set its timestamp and duration */
  GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale (data->num_samples, GST_SECOND, SAMPLE_RATE);
  GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale (CHUNK_SIZE, GST_SECOND, SAMPLE_RATE);
  
  /* Generate some psychodelic waveforms */
  gst_buffer_map (buffer, &map, GST_MAP_WRITE);
  raw = (gint16 *)map.data;
  data->c += data->d;
  data->d -= data->c / 1000;
  freq = 1100 + 1000 * data->d;
  for (i = 0; i < num_samples; i++) {
    data->a += data->b;
    data->b -= data->a / freq;
    raw[i] = (gint16)(500 * data->a);
  }
  gst_buffer_unmap (buffer, &map);
  
  data->num_samples += num_samples;
  
  //     if(1) return TRUE;

  /* Push the buffer into the appsrc */
  g_signal_emit_by_name (source, "push-buffer", buffer, &ret);

  // ** takes ownership of the buffer **
// gst_app_src_push_buffer (GST_APP_SRC(source), gst_buffer_ref(buffer));
  
  /* Free the buffer now that we are done with it */
  gst_buffer_unref (buffer);
  
  if (ret != GST_FLOW_OK) {
    /* We got some error, stop sending data */
    GST_DEBUG("GST_FLOW_OK error");
    return FALSE;
  }
  
  return TRUE;
}

/* This signal callback triggers when appsrc needs data. Here, we add an idle handler
* to the mainloop to start pushing data into the appsrc */
static void start_feed1 (GstElement *source, guint size, CustomData *data) {
  push_data (source, data);
}

 


More information about the gstreamer-devel mailing list