[gst-devel] patch to gstbaseaudiosrc.c

Edgard Niceas Arcoverde Gusmao Lima edgard.lima at indt.org.br
Wed Oct 5 17:28:27 CEST 2005



Hi all,

I ve written a patch in order to alsasrc work.
I ve tested it with "gst-launch-0.9 alsasrc ! lame ! mad ! volume
volume=4 ! alsasink"

the patch follows below (and attached)

please someone validate (or show me how to fix) and commit it (or tell
me to commit it by myself)


Thanks Very Much In Advance,
Edgard Lima
edgard.lima at indt.org.br




diff -urNaw gst-plugins-base.orig/ChangeLog gst-plugins-base.supp/ChangeLog
--- gst-plugins-base.orig/ChangeLog     2005-10-05 20:55:10.140969024 -0300
+++ gst-plugins-base.supp/ChangeLog     2005-10-05 21:11:29.300114208 -0300
@@ -1,3 +1,9 @@
+2005-10-05  Edgard Lima <edgard.lima at indt.org.br>
+       * gst-libs/gst/audio/gstbaseaudiosrc.h:
+       * gst-libs/gst/audio/gstbaseaudiosrc.c: (gst_base_audio_src_event),
+       (gst_base_audio_src_create), (gst_base_audio_src_change_state):
+       Fixed gstbaseaudiosrc adding ring buffer sync to it.
+
 2005-10-04  Michael Smith <msmith at fluendo.com>

        * gst/playback/gstplaybasebin.c: (group_destroy),
diff -urNaw gst-plugins-base.orig/gst-libs/gst/audio/gstbaseaudiosrc.c
gst-plugins-base.supp/gst-libs/gst/audio/gstbaseaudiosrc.c
--- gst-plugins-base.orig/gst-libs/gst/audio/gstbaseaudiosrc.c 
2005-10-05 20:55:10.170964464 -0300
+++ gst-plugins-base.supp/gst-libs/gst/audio/gstbaseaudiosrc.c 
2005-10-05 21:12:14.503242288 -0300
@@ -289,8 +289,12 @@
   switch (GST_EVENT_TYPE (event)) {
     case GST_EVENT_FLUSH_START:
       gst_ring_buffer_pause (src->ringbuffer);
+      gst_ring_buffer_clear_all (src->ringbuffer);
       break;
     case GST_EVENT_FLUSH_STOP:
+      /* always resync on sample after a flush */
+      src->next_sample = -1;
+      gst_ring_buffer_clear_all (src->ringbuffer);
       break;
     default:
       break;
@@ -306,6 +310,7 @@
   guchar *data;
   guint len;
   guint res;
+  guint64 sample;

   if (!gst_ring_buffer_is_acquired (src->ringbuffer))
     goto wrong_state;
@@ -315,10 +320,19 @@
   data = GST_BUFFER_DATA (buf);
   len = GST_BUFFER_SIZE (buf);

-  res = gst_ring_buffer_read (src->ringbuffer, -1, data, len);
+  if ( src->next_sample != -1 ) {
+    sample = src->next_sample;
+  } else {
+    sample = 0;
+  }
+
+  res = gst_ring_buffer_read (src->ringbuffer, sample, data, len);
   if (res == -1)
     goto stopped;

+  src->next_sample =
+    sample + len / src->ringbuffer->spec.bytes_per_sample;
+
   gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)));

   *outbuf = buf;
@@ -378,6 +392,7 @@
       }
       if (!gst_ring_buffer_open_device (src->ringbuffer))
         return GST_STATE_CHANGE_FAILURE;
+      src->next_sample = 0;
       break;
     case GST_STATE_CHANGE_READY_TO_PAUSED:
       break;
@@ -394,8 +409,8 @@
       gst_ring_buffer_pause (src->ringbuffer);
       break;
     case GST_STATE_CHANGE_PAUSED_TO_READY:
-      gst_ring_buffer_stop (src->ringbuffer);
       gst_ring_buffer_release (src->ringbuffer);
+      src->next_sample = 0;
       break;
     case GST_STATE_CHANGE_READY_TO_NULL:
       gst_ring_buffer_close_device (src->ringbuffer);
diff -urNaw gst-plugins-base.orig/gst-libs/gst/audio/gstbaseaudiosrc.h
gst-plugins-base.supp/gst-libs/gst/audio/gstbaseaudiosrc.h
--- gst-plugins-base.orig/gst-libs/gst/audio/gstbaseaudiosrc.h 
2005-10-05 20:55:10.170964464 -0300
+++ gst-plugins-base.supp/gst-libs/gst/audio/gstbaseaudiosrc.h 
2005-10-05 21:12:23.115932960 -0300
@@ -57,6 +57,9 @@
   GstClockTime   buffer_time;
   GstClockTime   latency_time;

+  /* the next sample to write */
+  guint64       next_sample;
+
   /* clock */
   GstClock     *clock;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: gst-plugins-base.patch
Type: text/x-patch
Size: 3169 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20051005/20f4aab5/attachment.bin>


More information about the gstreamer-devel mailing list