After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 660170 - alsasrc: broken timestamps lead to alsasrc ! audiorate endless loop
alsasrc: broken timestamps lead to alsasrc ! audiorate endless loop
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
git master
Other Linux
: Normal blocker
: 0.10.36
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on: 635256
Blocks:
 
 
Reported: 2011-09-26 19:51 UTC by Brian G. Marete
Modified: 2011-10-03 09:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Log of `gst-launch --gst-debug-no-color --gst-debug=alsa:5,audiorate:5 alsasrc ! audiorate ! filesink location=/dev/null' (16.42 KB, application/octet-stream)
2011-09-26 20:32 UTC, Brian G. Marete
  Details
alsasrc: fail gracefully when ALSA does not give timestamps (3.20 KB, patch)
2011-09-26 23:27 UTC, Vincent Penquerc'h
none Details | Review
alsasrc: fail gracefully when ALSA does not give timestamps (4.39 KB, patch)
2011-09-27 10:08 UTC, Vincent Penquerc'h
committed Details | Review

Description Brian G. Marete 2011-09-26 19:51:20 UTC
Using audiorate to smooth out the stream produced by alsasrc causes excessive CPU usage. On my machine, a Core i5 that has 2 cores and 4 hyperthreads, it uses more than 1 hyperthread.

This pipeline trivially reproduces the problem:

gst-launch alsasrc  ! audiorate ! wavenc ! filesink location=/dev/null

Redirecting the filesink location to an actual file shows that audiorate is producing an excessive number of samples (many thousands a second -- see the attached log also) and will produce a multi-gigabyte file within a minuite.

Attached is a debug log generating by setting alsasrc and audiorate to debug logging levels.
Comment 1 Brian G. Marete 2011-09-26 20:03:29 UTC
In fact, the following simpler test-case also demonstrates the bug (and removes wavenc from consideration)

gst-launch alsasrc ! audiorate ! filesink location=/dev/null
Comment 2 Brian G. Marete 2011-09-26 20:11:36 UTC
In fact, the following simpler test-case also demonstrates the bug (and removes wavenc from consideration)

gst-launch alsasrc ! audiorate ! filesink location=/dev/null
Comment 3 Brian G. Marete 2011-09-26 20:32:37 UTC
Created attachment 197512 [details]
Log of `gst-launch --gst-debug-no-color  --gst-debug=alsa:5,audiorate:5 alsasrc ! audiorate ! filesink location=/dev/null'
Comment 4 Tim-Philipp Müller 2011-09-26 22:36:32 UTC
It's not excessive CPU usage, it's spinning in an almost-endless loop to insert samples between timestamp 0 and (almost) infinity, because alsasrc outputs broken timestamps:

$ gst-launch-0.10 alsasrc ! identity ! queue ! fakesink -v 2>&1 | grep chain | head -n 2
3528 bytes, timestamp: 5124095:34:33.309596968, offset: 0, offset_end:  441
3528 bytes, timestamp: 5124095:34:33.309596968, offset: 18522, offset_end:  18963
...

no wonder...

This got broken as part of

 commit 0b774e0b7cf7a8ef1780fb6100228ca6e8ca8bcf
 Author: Pontus Oldberg <pontus.oldberg@invector.se>
 Date:   Mon May 9 11:50:05 2011 +0200

    alsasrc: Improve timestamp accuracy
    
    Fixes bug #635256.
Comment 5 Brian G. Marete 2011-09-26 23:21:55 UTC
And indeed, I can confirm that reverting 0b774e0b7cf7a8ef178 fixes the problem.
Comment 6 Vincent Penquerc'h 2011-09-26 23:27:50 UTC
Created attachment 197534 [details] [review]
alsasrc: fail gracefully when ALSA does not give timestamps
Comment 7 Brian G. Marete 2011-09-27 00:24:49 UTC
Thanks Vincent. Your patch now makes the pipeline referenced above work normally. That is: gst-launch alsasrc ! audiorate ! filesink location=/dev/null works.

But now this:
gst-launch alsasrc device=hw:0,0 ! audiorate ! filesink location=/dev/null 
results in the following message:

New clock: GstAudioSrcClock
WARNING: from element /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0: Can't record audio fast enough
Additional debug info:
gstbaseaudiosrc.c(840): gst_base_audio_src_create (): /GstPipeline:pipeline0/GstAlsaSrc:alsasrc0:
Dropped 88576 samples. This is most likely because downstream can't keep up and is consuming samples too slowly.

and directing the output to a file shows the original problem (too many samples too quickly).

In other words, the problem remains even with your patch if the `device' parameter is used.

Perhaps this is unrelated to the original problem that this bug was opened for?

Thanks!
Comment 8 Vincent Penquerc'h 2011-09-27 10:08:12 UTC
Created attachment 197553 [details] [review]
alsasrc: fail gracefully when ALSA does not give timestamps
Comment 9 Vincent Penquerc'h 2011-09-27 10:09:46 UTC
Indeed, for some unknown reason I get timestamps when using the device parameter, and these start at some large offset.
So I've updated the patch to timestamp from the first offset we get from ALSA, if it gives one.
Comment 10 Brian G. Marete 2011-09-27 10:37:55 UTC
Vincent, I can confirm that your new patch works in all cases, with and without the `device' property.

Looks like this fixes the bug

Thanks!
Comment 11 Sebastian Dröge (slomo) 2011-10-03 09:14:29 UTC
commit c7282a5718c7f31f84fb31b2c38fab0f9a38e2b0
Author: Vincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Date:   Tue Sep 27 00:26:29 2011 +0100

    alsasrc: fail gracefully when ALSA does not give timestamps
    
    https://bugzilla.gnome.org/show_bug.cgi?id=660170