media icon indicating copy to clipboard operation
media copied to clipboard

Fix initial network type

Open balachandarlinks opened this issue 1 year ago • 2 comments

Issue: NetworkTypeObserver initialises the default network type as C.NETWORK_TYPE_UNKNOWN and then registers for connectivity change callback. This works fine if we receive a connectivity change update quickly.

But, sometimes this callback takes time and so DefaultBandwidthMeter assumes network type as unknown and initialises the initial bitrateEstimate as 1Mbps (DEFAULT_INITIAL_BITRATE_ESTIMATE). This initial bitrate estimate is used to select the initial track in playback and so it is vital to get the correct initial bitrate estimate based on the network type. Otherwise even when using a high-speed Wifi connection, initial bitrate estimate will be 1Mbps and forces the player to select a representation with initial bitrate as 1 Mbps (1Mbps X BANDWIDTH_FRACTION).

Eg from Pixel2:

15:33:36.221 12556-12556 DefaultBandwidthMeter          D  InitialBitrateEstimate: 1000000
15:33:36.348 12556-12556 NetworkTypeObserver            D  Network type changed from 0 to 2

Note that there was a 127ms interval between the time when the NetworkTypeObserver was queried by DefaultBandwidthMeter and the time when the NetworkTypeObserver was able to update itself based on the connectivity change update.

Related discussion explains that it was done this way to differentiate between 4G and 5G NSA. But it affects more playbacks as we get network type as unknown even for wifi or ethernet connections.

Solution: Use ConnectivityManager#ActiveNetworkInfo to pick an optimal initial network type and then let connectivity-change-update callbacks to alter the network type.

balachandarlinks avatar May 09 '23 16:05 balachandarlinks

I encountered this issue in a different way. Related PR: https://github.com/google/ExoPlayer/pull/10729

vishnuchilakala avatar May 22 '23 13:05 vishnuchilakala

@microkatz Any updates on this? TIA.

balachandarlinks avatar Mar 04 '24 12:03 balachandarlinks