If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

audio noise/distortion due to underruns on a busy system

RESOLVED INCOMPLETE

Status

()

Core
Audio/Video: cubeb
RESOLVED INCOMPLETE
3 years ago
2 years ago

People

(Reporter: liuyong, Unassigned, NeedInfo)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

3 years ago
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0 (Beta/Release)
Build ID: 20140605174243

Steps to reproduce:

1) use browser, play a network  mp4 file that is 10M  bps.

or 
1) use browser, play any network  mp4 file.
2) enter shell: adb root;adb shell;  input " while true;do echo "1111";done;"

   



Actual results:

you can find that audio is tremble.





Expected results:

audio is smooth and fluent
(Reporter)

Comment 1

3 years ago
In gecko/content/media/AudioStream.cpp. long  AudioStream::DataCallback(void* aBuffer, long aFrames)



 if (mState != DRAINING) {
    uint8_t* rpos = static_cast<uint8_t*>(aBuffer) + FramesToBytes(aFrames - underrunFrames);
    memset(rpos, 0, FramesToBytes(underrunFrames));
    if (underrunFrames) {
      PR_LOG(gAudioStreamLog, PR_LOG_WARNING,
             ("AudioStream %p lost %d frames", this, underrunFrames));
    }
    mLostFrames += underrunFrames;
    servicedFrames += underrunFrames;
  }

add :
 memset(rpos, 0, FramesToBytes(underrunFrames)); 

so  audio is tremble.


but for same mp4 file, use android OS browser,play a mp4 file, it is fluent and smooth.
Hardware: x86_64 → ARM
(Reporter)

Updated

3 years ago
Component: General → General
Product: Firefox for Android → Firefox OS

Updated

3 years ago
Component: General → Video/Audio
OS: Linux → Gonk (Firefox OS)
Product: Firefox OS → Core
Adding a bunch of audio folk.

Avoiding underruns is tough; it's unclear we can avoid them entirely.  We may be able to reduce the chances of them occurring under load.  Some Android system apps may be using privileged modes (hard realtime threads) or hardware decoder chains we're not using.

An interesting (though unsafe) test would be to chrt the AudioStream/cubeb/MSG threads to a hard-realtime level.

Also, padenot's changes for MediaStreamGraph reclocking may help here.
Summary: audio add silence when system is busy. → audio noise/distortion due to underruns on a busy system
Android use different priorities, and notably a different scheduling class for audio threads that prevents this. Details in this 2013 video from Google I/O: http://www.youtube.com/watch?v=d3kfEeMZ65c

Also, our media playback architecture at the moment (for regular playback, not webrtc/webaudio/etc., because that's going to change) has an extra layer of buffering (AudioStream.cpp), and thread thread that enqueues data there is likely to have normal priority. Not sure about the media decoding threads.

We should be able to pull directly from decoders' output queues, and I believe kinetik is planning to do that (or at least has started the work with the AudioSink patch), and do some work to avoid starvation on those queues (that is, always have some video decoded).
Also, another useful page I forgot: http://source.android.com/devices/audio_latency.html
This code has been almost totally rewritten and rearchitected since you reported this; can you re-test with current Firefox Nightly?  Thanks!
Component: Audio/Video → Audio/Video: MSG/cubeb/GMP
Flags: needinfo?(liuyong0723)
Component: Audio/Video: MediaStreamGraph → Audio/Video: cubeb

Updated

2 years ago
Status: UNCONFIRMED → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.