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

HLS MaxAudioBitrate limit not working #6006

Closed
jakoss opened this issue Jun 7, 2019 · 8 comments
Closed

HLS MaxAudioBitrate limit not working #6006

jakoss opened this issue Jun 7, 2019 · 8 comments
Assignees
Labels

Comments

@jakoss
Copy link

jakoss commented Jun 7, 2019

Content description

I'm trying to stream audio only files (AAC and MP3, both codecs have the same issue). I generated 3 different bitrates playlists (256k, 192k and 128k) and then master playlist.
I need to be able to limit max bitrate (if users want to limit their data usage) to set values. So i have code:

private val exoPlayer: SimpleExoPlayer by lazy {
        val adaptiveTrackSelection = AdaptiveTrackSelection.Factory()
        val trackSelector = DefaultTrackSelector(adaptiveTrackSelection)
        trackSelector.setParameters(DefaultTrackSelector.ParametersBuilder()
// here i'm trying to force lowest bitrate for testing purposes
            .setMaxAudioBitrate(128_000)
            .setExceedAudioConstraintsIfNecessary(false)
            .setForceLowestBitrate(true))

        ExoPlayerFactory.newSimpleInstance(this, trackSelector).apply {
            setAudioAttributes(uAmpAudioAttributes, true)
            addAnalyticsListener(EventLogger(trackSelector))
            val debugViewHelper = DebugTextViewHelper(this, debug_text_view)
            debugViewHelper.start()
        }
    }

And i setup hls media source like that (just static test streams):

private fun createMediaSource(): MediaSource {
        val dataSourceFactory = DefaultDataSourceFactory(this, "ExoPlayer")
        val hlsMediaSourceFactory = HlsMediaSource.Factory(dataSourceFactory)
            .setAllowChunklessPreparation(true)
        val track1 = hlsMediaSourceFactory.createMediaSource(Uri.parse("http://10.0.2.2:5000/streams/despacito/master.m3u8"))
        val track2 = hlsMediaSourceFactory.createMediaSource(Uri.parse("http://10.0.2.2:5000/streams/duality/master.m3u8"))
        val track3 = hlsMediaSourceFactory.createMediaSource(Uri.parse("http://10.0.2.2:5000/streams/blackorwhite/master.m3u8"))

        return ConcatenatingMediaSource(track1, track2, track3)
    }

It's playing very well, no issues here, but unfortunetely, with this setup, exoplayer always chooses track with highest bitrate. Logs:

D/EventLogger: tracksChanged [26.35, 0.00, window=1, period=1, 
      Renderer:1 [
        Group:0, adaptive_supported=YES_NOT_SEAMLESS [
          [ ] Track:0, id=0, mimeType=audio/mp4a-latm, bitrate=281600, codecs=mp4a.40.2, supported=YES
          [ ] Track:1, id=1, mimeType=audio/mp4a-latm, bitrate=211200, codecs=mp4a.40.2, supported=YES
          [ ] Track:2, id=2, mimeType=audio/mp4a-latm, bitrate=140800, codecs=mp4a.40.2, supported=YES
        ]
      ]
      Renderer:3 [
        Group:0, adaptive_supported=N/A [
          [X] Track:0, id=ID3, mimeType=application/id3, supported=YES
        ]
      ]
    ]

I found configuring adaptive streaming very confusing, since internet is full of samples with old api versions and i wasn't able to find some official documentation about that.

Link to test content

Whole streamed content: files.zip

Version of ExoPlayer being used

2.10.1

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

Mutiple versions of android on Android Emulator and on physical device (Nokia 8)

@jakoss
Copy link
Author

jakoss commented Jun 7, 2019

Strange thing (but maybe not related) - every time i call player.currentManifest i got null. Same with onTimelineChanged event - i get 3 events (as expected), but manifest is null in all of them

@jakoss
Copy link
Author

jakoss commented Jun 18, 2019

Further information. I had to change HttpDataSource to OkHttp like that:

val httpClient = getUnsafeOkHttpClient()
val dataSourceFactory = OkHttpDataSourceFactory(httpClient, "ExoPlayer")
val hlsMediaSourceFactory = HlsMediaSource.Factory(dataSourceFactory)
        .setAllowChunklessPreparation(true)

to bypass SSL problems with our internal certs. It seems like on OkHttp the exact same code is working fine, just after playback start i get log downstreamFormatChanged [0.38, 0.00, window=0, period=0, id=2, mimeType=null, bitrate=140800, codecs=mp4a.40.34] and player does take right quality. So the problem seems to be with DefaultDataSource

@AquilesCanta
Copy link
Contributor

Hi, sorry for the delay on this. I got confused thinking it was a duplicate of a different issue in the current HLS implementation. I'll have a look soon and reach back.

@jakoss
Copy link
Author

jakoss commented Jun 18, 2019

No worries. Let me know if i can help you more

@AquilesCanta AquilesCanta added bug and removed question labels Jun 18, 2019
@AquilesCanta
Copy link
Contributor

There is a bug in the default track selector, due to which it ignores the maximum audio bitrate when creating the adaptive audio group. A fix for this will be referred in this issue soon.

As a side note, you should not select both a maximum bitrate and forceLowestBitrate, since the latter overrides the former. From what I understand about your usecase, you should stick to maxAudioBitrate.

Final note. I don't know how you got this in the logs:

Renderer:1 [
        Group:0, adaptive_supported=YES_NOT_SEAMLESS [
          [ ] Track:0, id=0, mimeType=audio/mp4a-latm, bitrate=281600, codecs=mp4a.40.2, supported=YES
          [ ] Track:1, id=1, mimeType=audio/mp4a-latm, bitrate=211200, codecs=mp4a.40.2, supported=YES
          [ ] Track:2, id=2, mimeType=audio/mp4a-latm, bitrate=140800, codecs=mp4a.40.2, supported=YES
        ]
      ]

as this would mean that the player has not selected any audio tracks. However, you also mention

It's playing very well,

so I assume there was some confusion here.

@jakoss
Copy link
Author

jakoss commented Jun 18, 2019

I was experimenting with forceLowestBitrate just to check what it does in this issue.

As of the logs - It's playing very well was just about music. It was playing.

Now, when using OkHttpDataSource, Renderer ` gets right track selected, so no problem here :)

ojw28 pushed a commit that referenced this issue Jun 18, 2019
@AquilesCanta
Copy link
Contributor

This should be fixed in the dev branch. Please give maxAudioBitrate a try and let me know if you run into any issues.

ojw28 pushed a commit that referenced this issue Jun 19, 2019
@jakoss
Copy link
Author

jakoss commented Jun 25, 2019

Version 2.10.2 seems to be working fine. Thanks

@google google locked and limited conversation to collaborators Oct 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants