Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to DefaultTrackSelector to enable cross-sampleRate audio adaptation #3314

Closed
0c6a183d opened this issue Oct 1, 2017 · 5 comments
Assignees

Comments

@0c6a183d
Copy link

0c6a183d commented Oct 1, 2017

Issue description

My .mpd file references 3 audio tracks (No Video).
3 qualities are available 24, 80 and 320Kbps.
The same track has been encoded to M4A using the same tool fdkAAC.exe, but with different output switches/codecs.

Track 1 24k(AAC-HEv2)(mp4a.40.29)(22050) - Codec required to make 24k sound satisfactory
Track 2 80k(AAC-HE)(mp4a.40.5)(22050) - Codec required as AAC-HEv2 only works up to 64K
Track 3 320k(AAC-LC)(mp4a.40.2)(41000) - Codec best for high bit rates, below 100k is starts getting poor

Note the different sample rates detected by the DASH media creation tool. (22050/44100)
This is correct apparently, as Wikipedia states:
"The HE-AAC and HE-AACv2 profiles encode audio using AAC-LC at one half the sample rate, relying on Spectral Band Replication (SBR) to attempt reconstruction of the missing higher frequencies"

When running my app on a physical device (LG G3 Android 5.0) and using a router to control bandwidth, tracks 1&2 are utilized as expected (Adaptive Track Selection Switching between them occurs). But the Adaptive Track Selection will not select track 3.

If I quickly edit the .mpd and change track 3 audioSampleRate from 44100 to 22050 and restart the audio, it works and switches between 1,2 & 3.

Using the same URL with the browser based DASH JavaScript player seems to work OK and all three tracks are utilized.

I am aware that the ability to adaptively switch between tracks encoded with different codecs is a recent feature so am curious to find out if this is a bug, a limitation of my device, or just my dodgy coding. Also I would like to know if editing the mpd sample rate as a work around affects the audio, as it seems to play OK.

Reproduction steps

  1. Using Exoplayer - Attempt to play supplied manifest file 1.mpd (Original) Only tracks 1&2 should work
  2. Using Exoplayer - Attempt to play supplied manifest file 2.mpd (Edited to force 44100 on track 3) Tracks 1&2&3 should be work.

Link to test content

Emailing in links to 2 x manifest files

Version of ExoPlayer being used

2.5.1 & 2.5.3

Device(s) and version(s) of Android being used

LG G3 Android 5.0

A full bug report captured from the device

Not sure if this is required at this state as it may be an non/known issue.

@ojw28
Copy link
Contributor

ojw28 commented Oct 2, 2017

We don't enable adaptation between different sample rates by default. Switching from one sample rate to another requires reconfiguration of the underlying AudioTrack, which I don't think can be performed in a completely seamless way.

@0c6a183d
Copy link
Author

0c6a183d commented Oct 2, 2017

OK - Thank you for confirming so quickly.

Seems to play fine if I edit the mpd so all tracks to use 22050 or 44100. There is no mention of 22050 in the AudioTrack: logcat output at any point when any of the three tracks start playing so it does seem the mpd is not final decision as it seems to play them all at 44100 anyway. As long as all tracks are set at the same sample rate the Adaptive Switching Seems to work fine.

@ojw28
Copy link
Contributor

ojw28 commented Oct 4, 2017

There should be a small discontinuity when switching between tracks of different sample rates. We release and re-initialize the underlying platform AudioTrack when this occurs. This happens here because this.sampleRate == sampleRate in the check above should evaluate to false (this should be true even when you lie about it in the DASH manifest, since the values used in this part of the code are derived from the actual media stream). If you attach a debugger, you'll probably be able to see that reset is being called here.

Perhaps the discontinuity is small enough that you don't really notice (in which case great!). There's no particular reason why we couldn't add an option to DefaultTrackSelector that enables adapting across different sample rate audio tracks. We'd probably keep it defaulted to off, at least initially, and allow the application to enable it if desired. What do you think?

@0c6a183d
Copy link
Author

0c6a183d commented Oct 4, 2017

I think that would be a good addition - And yes, disabled by default to keep the transition as seamless as possible, for those who may have inadvertently generated media tracks with different sample rates. They would then have the option to enable the automatic switching between tracks with differing sample rates and accept a possible minor "discontinuity", or chose to re-encode the media all at the same sample rate.

The switching at my end is near perfect gap-less on my old Lollipop S4 and G3 between the higher bit-rates with different sample rates (80-320Kbps) - Not noticeable when listening to fast dance music, probably a few ms at most. That would only improve I would guess on a high end phone. More noticeable when alternating with the super low 24Kbps but it is a very different quality codec (almost mono) so the majority of the transition effect is probably the loss in stereo effect and increase in the audio compression.

As a temporary workaround to enable the adaptive switching between all audio tracks with differing sample rates in my mpd file, I have removed the entire section audioSamplingRate="xxxxxx" - This seems to work OK and I have not had any issues... yet.

@ojw28 ojw28 changed the title Player does not adaptively switch audio tracks if audioSampleRates are different (M4A,DASH) Add option to DefaultTrackSelector to enable cross-sampleRate audio adaptation Oct 5, 2017
@ojw28 ojw28 assigned AquilesCanta and unassigned ojw28 Jan 8, 2018
@ojw28 ojw28 assigned tonihei and unassigned AquilesCanta Sep 26, 2018
ojw28 added a commit that referenced this issue Oct 31, 2018
Issue: #3314

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=219158729
@tonihei
Copy link
Collaborator

tonihei commented Jan 3, 2019

Closing as all required new options have been added.

@tonihei tonihei closed this as completed Jan 3, 2019
@google google locked and limited conversation to collaborators May 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants