androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.57k stars 373 forks source link

Plans for Android 14 bit-perfect audio support #415

Open OxygenCobalt opened 1 year ago

OxygenCobalt commented 1 year ago

I noticed this section in the Android 14 Beta 2 announcement:

Lossless USB audio Android 14 gains support for lossless audio formats for audiophile-level experiences over USB wired headsets. You can query a USB device for its preferred mixer attributes, register a listener for changes in preferred mixer attributes, and configure mixer attributes using a new AudioMixerAttributes class. It represents the format, such as channel mask, sample rate, and behavior of the audio mixer. The class allows for audio to be sent directly, without mixing, volume adjustment, or processing effects. We are working with our OEM partners to enable this feature in devices later this year.

This would be very helpful for the users of my app, but I don't know if I would have to put in the work to implement this myself, or if ExoPlayer/media3 would automatically handle it for me. Clarification here would be appreciated.

tonihei commented 1 year ago

Our current understanding is that this can be turned on with a relatively simple configuration option we can expose to ExoPlayer users. This won't happen until we update our compile SDK to 34 later this year though and and needs some testing. There are some limitations with this bit-perfect mode (e.g. no mixing of notification sounds at system level), so this will likely end up being an opt-in mode you can turn on if you want to.

kgrevehagen commented 10 months ago

Hey. Any news on this? The year is coming to an end, Android 14 has been released, compile SDK is at 34, so there should be no technical hurdles of adding this?

If not planned in the near future, do you have an idea of where it makes most sense to add this, also potentially accepting a PR that adds it?

alexandru0-dev commented 9 months ago

Any updates?

tonihei commented 9 months ago

You are right, there are no technical hurdles left. The plan as of now is to include this in the next release (1.3.0).

alexandru0-dev commented 7 months ago

You are right, there are no technical hurdles left. The plan as of now is to include this in the next release (1.3.0).

@tonihei I saw that the alpha of 1.3.0 is published. Any update on the USB bit perfect audio?

I would like to contribute but ngl, I wouldn't even know where to start. If u can guide me I can try to help and make a PR eventually

tonihei commented 7 months ago

We have all the pending changes needed for this internally already, but not submitted because there is no device to test this end-to-end yet (it requires some very low-level support in the audio framework that will only be released later). So this likely means it will only go into the next release, assuming we can actually test it until then.

alexandru0-dev commented 7 months ago

I would like to contribute to it. Can u give me more info about the low level framework that needs to be worked on?

If u have time can u make a draft pr with everything that needs to be done so I can contribute and understand what needs to be done? Thx in advance

tonihei commented 7 months ago

I appreciate that you'd like to help, but there is really nothing you can do because the missing piece in the phone-specific low-level hardware layers and needs to be implemented by the people who update the system images of the relevant phone.

alexandru0-dev commented 6 months ago

@tonihei any updates on the topic?

Tolriq commented 3 months ago

@tonihei I got an user trying to convince me that there's now many OEM that have enabled that, but I've never saw any annoncement anywhere. Do have some details about the status on the actual phones and if it's present on some? (Not the ExoPlayer part)

tonihei commented 3 months ago

@Tolriq Did this user refer to any specific devices? I know for certain that the Pixel 8 support is still under development (and this is basically blocking further progress here), so I would be curious to see if there is another device that already supports this output path fully.

Tolriq commented 3 months ago

@tonihei he said that another dev have it working on Samsung S21 + S22 and it works on his Motorola G34, then he explained me that every Android 14 device have and I'm dumb :) So not sure it's reliable.

But at the same time he said he worked with https://play.google.com/store/apps/details?id=com.rhmsoft.omnia dev to add support and that it works in the last version of that app.

Since I only got pixels here I have no idea what to believe.

Is there some details about how it will be added to ExoPlayer so I can quickly add something to have him test ? (Not necessarily full code, but mostly where you'll put the config and pass it down so I already mostly interface the same way to simplify the future?

OxygenCobalt commented 3 months ago

@tonihei he said that another dev have it working on Samsung S21 + S22 and it works on his Motorola G34, then he explained me that every Android 14 device have and I'm dumb :) So not sure it's reliable.

But at the same time he said he worked with https://play.google.com/store/apps/details?id=com.rhmsoft.omnia dev to add support and that it works in the last version of that app.

Since I only got pixels here I have no idea what to believe.

Is there some details about how it will be added to ExoPlayer so I can quickly add something to have him test ? (Not necessarily full code, but mostly where you'll put the config and pass it down so I already mostly interface the same way to simplify the future?

Im under the impression that Omnia is doing manual bit perfect support by hooking into very low level android APIs, as most very old paid players tend to do @Tolriq

Tolriq commented 3 months ago

That's what I would have assumed too, but he only added it like a couple days ago and only for Android 14 so not so sure.

OxygenCobalt commented 3 months ago

That's what I would have assumed too, but he only added it like a couple days ago and only for Android 14 so not so sure.

Eh, I imagine 14's bit-perfect audio support has some VERY low-level or internal APIs that you could hook into if you had enough time and patience to do so (see stuff like pre-marshmellow VolumeManager). The android team is still testing the functionality and working on building userland abstractions for said internal APIs though @Tolriq

Tolriq commented 3 months ago

@OxygenCobalt the API surface and the OEM side part is already defined with corresponding CTS.

https://source.android.com/docs/core/audio/preferred-mixer-attr https://developer.android.com/reference/android/media/AudioMixerAttributes

My understanding is that it was up to the OEM to integrate it. Pixels still have not, so ExoPlayer have not published the high level integration in ExoPlayer, but maybe some OEMs already had added support hence the question.

I'm sure @tonihei will have the answer about that.

alexandru0-dev commented 3 months ago

@Tolriq i made a quick test with my setup on Omnia (Pixel 7a + Moonriver2Ti, on Android 15)

The dac was set to 192KHz by the app by default without any permissions required. Changing the sample rate changed the sample rate of the dac but created some HIGH screeching at the beginning and also the speed of the song in some cases (iykyk)

No dynamic sample rates of the dac as it was fixed even when songs are at a lower or higher sampling rate.

These tests were made using AAudio.

OxygenCobalt commented 3 months ago

@OxygenCobalt the API surface and the OEM side part is already defined with corresponding CTS.

https://source.android.com/docs/core/audio/preferred-mixer-attr https://developer.android.com/reference/android/media/AudioMixerAttributes

My understanding is that it was up to the OEM to integrate it. Pixels still have not, so ExoPlayer have not published the high level integration in ExoPlayer, but maybe some OEMs already had added support hence the question.

I'm sure @tonihei will have the answer about that.

That makes a lot of sense. My guess is that Omnia jumped the gun and added DAC support pretty quickly since they had their own rendering pipeline they could task it onto I guess.

tonihei commented 3 months ago

The explanation @Tolriq gave makes sense to me. To my knowledge, there is no secret low-level API apps can use to integrate with this without the proper hardware support. To test whether bit-perfect audio is supported, you can check the following on a device with a connected DAC:

AudioDeviceInfo audioDevice = audioManager.getAudioDevicesForAttributes(audioAttributes).get(0);
// audioDevice.getType() should be TYPE_USB_DEVICE, TYPE_USB_HEADSET or TYPE_USB_ACCESSORY if a DAC is connected
for (AudioMixerAttributes mixerAttr : audioManager.getSupportedMixerAttributes(audioDevice)) {
  // mixerAttr.getMixerBehavior() has to be MIXER_BEHAVIOR_BIT_PERFECT
}
Tolriq commented 5 days ago

@tonihei For the record I had anonymous analytics about support for this running and now Pixel 9 have support implemented :)

tonihei commented 4 days ago

@Tolriq Thanks for this note! We were talking to the team implementing the Pixel support, and were aware that they recently submitted the necessary code to the system update. Great to see this actually appears on devices :)