• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

ROMs C Thread priority for streamig USB Audio problems

ehdroid

Lurker
Aug 23, 2012
1
0
Hi Folks,

I'm building a custom application on a custom device (2.3.5, kernel 2.6.38). The android device is acting as a USB Host, consuming audio from a connected USB media player device using standard USB Audio Class. I do have access to generate a new ROM for the custom device.

In a C thread (record thread), I'm opening a handle to the USB alsa recorder device (/dev/snd/), requesting pcm frames from the attached USB device using the snd_pcm_readi alsa API. Frames are now passed from recorder thread to a C playback thread to be queued to speaker output via ALSA and/or OpenSL.

When my application is in the foreground, the recorder thread runs in a timely manner, and audio playback is seamless. However, when my application gets backgrounded, I run another application in forground, or quickly scroll through any listviews or the home screen tiles, the C recorder thread gets starved. The C recorder thread cannot request USB audio frames fast enough, and music starts to skip. When the forground application idles again or I finish interacting with the UI, the music will once again be seamless.

As I understand, C threads in Android do not (and cannot) have real-time priority, verified by my failed attempts to bump up the pthread priority. My view of the solution is to bump up the recorder thread priority somehow, but not sure how to get beyond the android thread priority limitation. Or is there another solution (like not having a recorder/playback thread, and using builtin media features)?

Open to all suggestions or comments.

TIA,
ehdroid
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones