[FFmpeg-devel] Add protocol for Android content providers

Matthieu Bouron matthieu.bouron at gmail.com
Wed Feb 14 00:50:08 EET 2024


Hi,

On Android, content providers are used for accessing files through shared
mechanisms. One typical case would be an app willing to open a video from
Google Photos, gallery apps, TikTok, Instagram or some other providers.
A content URI looks something like "content://authority/path/id", see:
https://developer.android.com/reference/android/content/ContentUris
https://developer.android.com/guide/topics/providers/content-provider-basics

It can currently be somehow managed through clumsy means such as using a "fd:"
filename and crafting a special AVOption, which also has the drawback of
requiring the third party to carry around opened file descriptors (with the
multiple opened file limitations implied). Custom AVIOContexts are also an
option. Both options will have to deal with the JNI though and end users will
have to re-implement the same exact thing.

This patchset addresses this by adding a content provider protocol, which has
an API fairly similar to fopen. Android 11 appears to provide something
transparent within fopen(), but FFmpeg doesn't use it in the file protocol, and
Android < 11 are still widely used.

The first part move the JNI infrastructure from avcodec to avutil (it remains
internally shared, there is little user implication), and then the URLProtocol
is added, along with a few cleanups.

Regards,

-- 
Matthieu



More information about the ffmpeg-devel mailing list