[gst-devel] alsasink ! alsasrc fixed and timestamp issues

Edgard Niceas Arcoverde Gusmao Lima edgard.lima at indt.org.br
Tue Oct 18 11:49:36 CEST 2005


Hi gstreamer hackers,

Trying to make "gst-launch-0.9 alsasrc ! alsasink" my good friend Dr.
Elvis (epx) has written a simple code that just add a timestamp in the
buffer pushed out by gstbaseaudiosrc. And with that code it works fine,
the snipet of code follows:

static GstFlowReturn
gst_base_audio_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) {
...
GST_BUFFER_DURATION(buf) = src->ringbuffer->samples_per_seg * GST_SECOND
/ src->ringbuffer->spec.rate;
GST_BUFFER_TIMESTAMP(buf) = src->next_timestamp;
src->next_timestamp += GST_BUFFER_DURATION(buf);
...
}

He  said, "gst-launch-0.9 alsasrc ! alsasink doens't work because
alsasrc doens't put a timestamp in the buffer" and said "you can just
lanch gst-launch-0.9 -v alsasrc ! fakesink to see it"

So, a have written a patch (attached and copied at the end of this mail)
that makes "gst-launch-0.9 alsasrc ! alsasink" work fine the way Dr.
Elvis told me to do. And I would like to make question regarding that
solution.

Question 1: Does that code (to add timestamp to gstbaseaudiosrc buffer)
a good/right architecture solution?
Question 2: Whoud it be better to add realtime (gettimeofday) timestamp
instead of the last buffer duration?

I have already made some trials (without apply the patch proposed):

gst-launch-0.9 alsasrc ! alsasink -> does NOT work
gst-launch-0.9 -v alsasrc ! fakesink -> does NOT have timestamp

gst-launch-0.9 alsasrc ! lame ! mad ! alsasink -> works fine
gst-launch-0.9 -v alsasrc ! lame ! fakesink -> does NOT have timestamp
gst-launch-0.9 -v filesrc location=foo.mp3 ! mad ! fakesink -> has timestamp

gst-launch-0.9 alsasrc ! gsmenc ! gsmdec ! alsasink -> works fine
gst-launch-0.9 -v alsasrc ! gsmenc ! fakesink -> has timestamp
gst-launch-0.9 -v filesrc location=foo.gsm ! gsmdec ! fakesink -> has
timestamp

gst-launch-0.9 alsasrc ! alawenc ! alawdec ! alsasink -> does NOT work
gst-launch-0.9 -v alsasrc ! alawenc ! alawdec ! fakesink -> does NOT
have timestamp

Question 3: What is the right way to add timestamp?
a- only in decoder, like lame and mad
b- in both encoder and decoder, like gsmenc and gsm dec?

Question 4: What if I want send it over network,
ex1: gst-launch-0.9 alsasrc ! formatenc ! rtpformatenc ! udpsink
ex2: gst-launch-0.9 udpsrc ! rtpformatdec ! formatdec ! alsasink
Where should I add timestamp?

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


###### Patch below ######

? gstbaseaudiosrc.c-bak
? gstbaseaudiosrc.h-bak
? patch
Index: gstbaseaudiosrc.c
===================================================================
RCS file:
/cvs/gstreamer/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.c,v
retrieving revision 1.13
diff -u -3 -p -r1.13 gstbaseaudiosrc.c
--- gstbaseaudiosrc.c    11 Oct 2005 18:32:01 -0000    1.13
+++ gstbaseaudiosrc.c    18 Oct 2005 17:33:58 -0000
@@ -294,6 +294,7 @@ gst_base_audio_src_event (GstBaseSrc * b
     case GST_EVENT_FLUSH_STOP:
       /* always resync on sample after a flush */
       src->next_sample = -1;
+      src->next_timestamp = 0;
       gst_ring_buffer_clear_all (src->ringbuffer);
       break;
     default:
@@ -334,6 +335,10 @@ gst_base_audio_src_create (GstPushSrc *
 
   src->next_sample = sample + samples;
 
+  GST_BUFFER_DURATION(buf) = src->ringbuffer->samples_per_seg *
GST_SECOND / src->ringbuffer->spec.rate;
+  GST_BUFFER_TIMESTAMP(buf) = src->next_timestamp;
+  src->next_timestamp += GST_BUFFER_DURATION(buf);
+
   gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)));
 
   *outbuf = buf;
@@ -394,6 +399,7 @@ gst_base_audio_src_change_state (GstElem
       if (!gst_ring_buffer_open_device (src->ringbuffer))
         return GST_STATE_CHANGE_FAILURE;
       src->next_sample = 0;
+      src->next_timestamp = 0;
       break;
     case GST_STATE_CHANGE_READY_TO_PAUSED:
       break;
@@ -412,6 +418,7 @@ gst_base_audio_src_change_state (GstElem
     case GST_STATE_CHANGE_PAUSED_TO_READY:
       gst_ring_buffer_release (src->ringbuffer);
       src->next_sample = 0;
+      src->next_timestamp = 0;
       break;
     case GST_STATE_CHANGE_READY_TO_NULL:
       gst_ring_buffer_close_device (src->ringbuffer);
Index: gstbaseaudiosrc.h
===================================================================
RCS file:
/cvs/gstreamer/gst-plugins-base/gst-libs/gst/audio/gstbaseaudiosrc.h,v
retrieving revision 1.4
diff -u -3 -p -r1.4 gstbaseaudiosrc.h
--- gstbaseaudiosrc.h    6 Oct 2005 15:15:04 -0000    1.4
+++ gstbaseaudiosrc.h    18 Oct 2005 17:33:58 -0000
@@ -60,6 +60,9 @@ struct _GstBaseAudioSrc {
   /* the next sample to write */
   guint64     next_sample;
 
+  /* timestamp of next sample */
+  guint64     next_timestamp;
+
   /* clock */
   GstClock    *clock;
 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20051018/1d2ee7e9/attachment.asc>


More information about the gstreamer-devel mailing list