google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.72k stars 6.03k forks source link

After ExoPlayer updates can't increase buffer size on DefaultLoadControl #3905

Closed RafaelMagalhaesN closed 6 years ago

RafaelMagalhaesN commented 6 years ago

Issue description

I am having a problem while increasing the buffer size of my streaming. I did all the necessary settings, using the class "DefaultLoadControl" but after version 2.6.1, even changing to any value makes no difference.

Reproduction steps

Link to test content

https://github.com/RafaelMagalhaesN/ExoPlayerFm

Version of ExoPlayer being used

2.7.0

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

Samsung Galaxy J7 Android 7.0

erdemguven commented 6 years ago

How do you check the buffer size if increased or not? Please share the code you use to create DefaultLoadControl and check the buffer size.

RafaelMagalhaesN commented 6 years ago

DefaultLoadControl (MainActivity.java):

 private void set() {
        Handler mainHandler = new Handler();
        DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        eventLogger = new EventLogger();
        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
        DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
       // Here
        DefaultLoadControl loadControl = new DefaultLoadControl(allocator, 360000, 600000, 2500, 5000, -1, true); 
      //***
        player = ExoPlayerFactory.newSimpleInstance(mContext, trackSelector, loadControl);

        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(mContext,
                Util.getUserAgent(mContext, "ExoPlayer2"), bandwidthMeter);

        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();

        mediaSource = new HlsMediaSource(SOURCE, dataSourceFactory, minLoadableRetryCount, mainHandler, eventLogger);
        player.addMetadataOutput(eventLogger);
        player.addListener(eventLogger);

        if (player != null) {
            if (!isReady) {
                player.seekTo(60000);
                player.prepare(mediaSource);
                isReady = true;
            }

            player.setPlayWhenReady(true);
        }
    }

EventLogger (BufferSize): I check the size of the buffer through the EventLogger. In the logcat (search for: "onLoadCompleted") you can see the downloaded segments inside the .m3u8 file (https://stream.vagalume.fm/hls/14660048951600695455/aac.m3u8). After v2.6.1+, it always makes the three-segment buffer only. In v2.6.0, the same code (without params: targetBufferBytes, prioritizeTimeOverSizeThresholds of DefaultLoadControl) makes the eight segment buffer..You can reproduce with this repository: https://github.com/RafaelMagalhaesN/ExoPlayerFm

Check buffer (EventLogger.java)

@Override
    public void onLoadCompleted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) {
        Log.e(TAG, "onLoadCompleted: [ "+ dataSpec.uri.toString() +" ]");
    }
tonihei commented 6 years ago

I tested your DefaultLoadControl parameters with the "HLS - Apple AAC media playlist" from our demo app (the stream you provided gives me a 404 error). In our current version it loads a lot more than 3 segments at a time. Can you check whether the current release version (2.7) still has this problem?

RafaelMagalhaesN commented 6 years ago

Yes, I checked the latest version (2.7.0) and the problem continues. Can you try another stream?

https://stream.vagalume.fm/hls/1470154983100588/aac.m3u8 https://stream.vagalume.fm/hls/14619606471054026608/aac.m3u8 https://stream.vagalume.fm/hls/1499715905423293/aac.m3u8

To exemplify my problem: (Version 2.7.0 | 2.6.1) The buffer size always starts from the segment position highlighted in yellow and downloads the other two in blue, keeping three segments cached. When I change the max_buffer and min_buffer values of the DefaultLoadControl the buffersize remains the same thrid aac

(Version 2.6.0) The buffer size, from the highlighted green segment position (starts where I want) and downloads the others highlighted in cyan, holding sixteen (+/-) cached segments. bla aac

tonihei commented 6 years ago

The player only loads 3 segments because it's close to the live edge.

I think the actual problem is that your seek isn't handled because you call prepare after the seek. The second (optional) parameter of prepare is resetPosition which is true by default. That's why, the position is reset to the default.

To solve this, either pass false to resetPosition or seek after prepare.

RafaelMagalhaesN commented 6 years ago

Solved @tonihei 🎉🎉🎉 Tnks!!