OutOfMemoryError when starting podcast with large cover image
Description
I get a near-immediate crash when opening certain podcasts.
My logcat log starts with java.lang.OutOfMemoryError: Failed to allocate a 36000012 byte allocation with 4194304 free bytes and 13MB until OOM
, the first stack entry that looks VLC-related is at org.videolan.vlc.util.HttpImageLoader.downloadBitmap(HttpImageLoader.kt:5)
, so I presume (rightly or wrongly) that it is to do with downloading an image associated with the specific podcast feed.
The consistently failing feed is https://feeds.simplecast.com/ln6OJKlV.
The image in the failing feed XML is a 3000x3000 pixel JPEG, which I'd guess makes for a roughly 3000*3000*24bpp = 27MB
buffer requirement. My device reports having approx. 3GB (of 6GB) RAM available. Given this (and the arbitrary-looking 4MB free value in the exception) I presume that this is an artificial limit imposed by Android, rather than a device issue (or it is wanting video memory—which I don't have a statistic for—rather than RAM).
An example successful feed is https://feed.podbean.com/qqwithsorenanddaniel/feed.xml, which has a 1400x1400 JPEG as its cover image.
Based on above assumptions, and Google recommendations for loading bitmaps into memory, I have put together a possible mitigation in a fork+branch at https://code.videolan.org/jimbobmcgee/vlc-android/blob/493bd287d8bcc8b3a1cf28b52f08a3215053b2ba/application/tools/src/main/java/org/videolan/tools/HttpImageLoader.kt, whereby I ask the Android SDK BitmapFactory
to attempt to scale the image as it downloads it. However, please note that this is my first time working with both Kotlin and the Android platform, so I have no development environment to speak of (the code was written in the Gitlab IDE), and I don't wish to pollute your codebase with my untested badness -- please feel free to eyeball and advise if you wish me to make a PR of my change (bearing in mind my lack of dev environment).
Expected behavior
The podcast should load and VLC should remain functional, possibly at the expense of loading/displaying the cover image.
Actual behavior
Audio starts, then the Unfortunately VLC has stopped
dialog is displayed. The audio continues until either Report
or OK
is pressed, then the audio stops and VLC restarts. Logcat to follow.
Steps to reproduce
- Open menu, select Stream
- In Enter network address field, enter
https://feeds.simplecast.com/ln6OJKlV
- Click stylised Play button next to field
Screenshot / video
N/A, logcat to follow
Context
App version
VLC 3.2.7 Revision 008a2a28, VLC: 94daf7aa (2020-01-27)
Android version
6.0.1, patch level 5-Jan-2017.
(The device vendor appears not to offer any further updates for this model, via its Wireless Update feature)
Device model
Umidigi Plus E
- CPU: Helio P20 (8-core @ 2.3GHz)
- RAM: 6GB
- Internal storage: 64GB
- Kernel version:
3.18.31\rom@umidigi.com #4\Mon Jun 5 11:03:01 CST 2017
- Build number:
UMIDIGI Plus E.V3.02_20170605
App mode
Smartphone