- Christo K S
- April 3, 2024
EarlyAudio in Android Automotive
Introduction
Android Automotive OS (AAOS) is designed to provide a seamless and integrated experience for drivers and passengers, offering features such as navigation, media playback, communication, and vehicle controls. Android Automotive OS is built on the same foundation as the Android operating system used in smartphones and tablets but tailored and optimized for the automotive environment. It allows automakers to incorporate familiar Android-based interfaces and applications into their vehicles, providing users with a more intuitive and connected driving experience. In-Vehicle Infotainment is the most popular feature of the Android Automotive OS (AAOS).
Consider the scenario when the audio system shuts off when the car is powered down. When the car is powered back up, the time delay for the music playback to restart is substantial, often in the range of 25 to 60 seconds. This is the result of a significantly long boot time in the case of AAOS.
The main reason for this delay is caused by the inability of the Linux part of the AAOS. In Android, the audio is managed by the Audio Manager service. Audio playback is not possible until the audio services are available which takes some time. This is addressed by the EarlyAudio service. EarlyAudio service bypasses the boot process and starts the playback without the interaction of the Audio Manager and continues until the AAOS is up and running.
When the AAOS is fully operational, the EarlyAudio service hands over the playback task to the music player application. The end user will perceive it as if the music player application opens directly after AAOS boots up.
Android boot sequence
Like every other OS, the boot loader is the entry point to the AAOS which then starts the kernel. Once the kernel is loaded, it initiates the init process, following which init starts the system services. Stock Android running on mobile phones typically takes 25 seconds to boot, whereas stock AAOS takes similar time just to start the kernel. Even after the kernel is up and running, it takes another 60+ seconds for the overall system to be fully up. This essentially means that the system will be ready to respond to user interactions only after approximately 1.5 minutes.
You can read more about the booting process of Android devices here.
EarlyAudio Architecture
As mentioned above, the prime motive behind the design of EarlyAudio is to overcome the delay that the stock AAOS has. EarlyAudio is designed in such a way that as soon as the init starts, an instance of the EarlyAudio service will be spawned immediately before starting the rest of the system
services.
The playback will be triggered only if the user was listening to music prior to power off. This prior usage can be detected by checking the cached data handled and updated by the music player application. The music player application creates and updates the playback details in real-time during its operation. So, when the power is turned off while music was being played by the music player application, it would’ve written that info into the cache. This is then used by the EarlyAudio service to control its operation.
If the EarlyAudio service detects that music was being played before power off, the EarlyAudio service loads the last-played music file path and playback position from the cached data. After the audio file is identified, the EarlyAudio service starts decoding from the last playback position using the integrated software decoders. At this stage, the Android system still be in its early booting stage. As a result, many of the decoders that the OS provides won’t be available. This is the reason why software decoders are chosen instead of using the inbuild decoders provided by the OS.
Once the decoding starts, the EarlyAudio service takes the decoded raw PCM data from the software decoder and writes to the hardware device for playback. For this, we have an Android architecture preferred method of using the Android audio services which provide high quality audio playback. But those come at the cost of time to start playback. To avoid this time loss, EarlyAudio utilizes TinyALSA. This is a simple audio library written on top of ALSA components and doesn’t have any dependencies with Android and will be loaded by the kernel itself. After the EarlyAudio service writes the PCM data to the hardware device using TinyALSA, the playback starts immediately. The playback occurs in the background almost instantaneously.
After the completion of the AAOS booting process, the EarlyAudio service launches the music player application and hands over the playback to it. After a gap less transition of playback from the EarlyAudio service to the music player application, EarlyAudio service stops the playback and releases all the resources it had acquired while it was in control.
Tools used
Decoder
- MPEG 2 Audio decoder
This was used since there was a need for a lighter library for the decoding task with no dependencies.
Audio API
- TinyALSA
TinyALSA is a small library to interface with ALSA in the Linux kernel. It provides a basic PCM API that can be used to write audio stream to the hardware device and will be ready to use as soon as kernel is loaded.
For more details, click here
Music Player
- ExoPlayer
It is an application-level media player for Android. It provides an alternative to Android’s MediaPlayer API for playing audio and video both locally and over the Internet. It adds additional conveniences such as support for multiple streaming protocols, default audio and video renderers, and components that handle media buffering.
For more details, click here
Results
Demo Video
The kernel is loaded, and display is ready within 3 seconds and within 6 seconds after power-on, the playback starts seamlessly at the precise audio frame at which playback had stopped prior to power-down.
Conclusion
EarlyAudio is a very simple and efficient approach for improving the audio playback user experience after a vehicle power-down and subsequent restart. With EarlyAudio, the playback is started automatically even before the AAOS boots up. This happens within 6 seconds at most.