83 Commits

Author SHA1 Message Date
ibaker
3facfbf542 Assert baseDataSourceFactory non-null in DefaultDataSource.Factory
This gives a faster/clearer failure for Issue: androidx/media#1718.

PiperOrigin-RevId: 675896262
2024-09-18 02:00:03 -07:00
dancho
1c61fbadf7 Downscale bitmaps during decoding in Transformer
Limit input image size in Transformer to be less than 4096x4096.
For very large images, this can reduce memory usage substantially,
and stays away from `GL_MAX_TEXTURE_SIZE` - often 4096

PiperOrigin-RevId: 670555939
2024-09-03 07:53:13 -07:00
kak
2202397758 Automated Code Change
PiperOrigin-RevId: 660491742
2024-08-07 12:28:25 -07:00
rohks
8b7b1b51a9 Add MediaDataSourceAdapter
Added a new data source which acts an adapter to read media data from platform `MediaDataSource`. This enables adding the `setDataSource(MediaDataSource)` API to `MediaExtractorCompat`.

PiperOrigin-RevId: 657564901
2024-07-30 06:16:30 -07:00
rohks
004b9d69fd Handle case where length is unset in FileDescriptorDataSource
- Modified the logic of `open()` and `read()` methods to handle scenarios where length is unset for the `FileDescriptor` provided.
- Added unit test and contract test to handle this case.

Also used `getDeclaredLength()` instead of `getLength()` to set the length of `AssetFileDescriptor` in unit tests and contract tests.

PiperOrigin-RevId: 657551343
2024-07-30 05:29:05 -07:00
rohks
32c9d62d39 Add DataSource contract tests to verify offset and position
These tests addresses two identified gaps in the contract:
 - Ensures that the output buffer offset passed to the `DataSource.read` method is correctly applied.
 - Verifies that the position within the input stream is properly incremented when reading in two parts.

PiperOrigin-RevId: 656358935
2024-07-26 05:14:51 -07:00
Gaëtan Muller
71b8c32a6f Remove Multidex 2024-07-24 16:17:00 +01:00
ibaker
6a9ff95bf0 Bump minSdk to 21 and remove resulting simple dead code
All other AndroidX libraries have already increased their min SDK to
21.

This change renames private symbols to remove `V21` suffixes and
similar, but doesn't change public or protected symbols with similar
names, to avoid needless breakages/churn on users of the library.

Some of the dead code removal is more complex, so I've split it out
into follow-up changes to make it easier to review.

PiperOrigin-RevId: 651776556
2024-07-12 08:11:01 -07:00
ibaker
00d1e70a34 Rollback of 91633e6ae3
PiperOrigin-RevId: 650620012
2024-07-09 07:29:57 -07:00
ibaker
5dd377fb7b Rollback of 91633e6ae3
PiperOrigin-RevId: 650312000
2024-07-08 11:15:18 -07:00
okunhardt
91633e6ae3 Update HttpEngineDataSource to require at least S extension 7.
This earlier version supports [HttpEngine](https://developer.android.com/reference/android/net/http/HttpEngine) and thus this change allows more devices to use HttpEngine.

This fixes Issue: androidx/media#1262, which suggests to do this.

PiperOrigin-RevId: 650224711
2024-07-08 06:13:24 -07:00
rohks
adf1c7915d Add FileDescriptorDataSource
This is a new `DataSource` that can be used to read from a `FileDescriptor`.

Limitations:
- The provided file descriptor must be seekable via lseek.
- There's no way to duplicate a file descriptor with an independent position (it
  would be necessary instead for the app to provide a new FD). Therefore this
  implementation will only work if there's one open data source for a given file
  descriptor at a time.
PiperOrigin-RevId: 649443584
2024-07-04 10:24:25 -07:00
cushon
04ca79182a Fix an invalid javadoc link
PiperOrigin-RevId: 641895590
2024-06-10 07:34:29 -07:00
tonihei
9ed86441e3 Remove module registration from HttpEngineDataSource
It used to be its own module in the first revision, but then moved
into the DataSource module as of 250fc80419.

PiperOrigin-RevId: 639745498
2024-06-03 05:31:01 -07:00
ibaker
4dd8360693 Allow ByteArrayDataSource to resolve the byte array when opened
This is a relatively small change, and massively simplifies the work
needed for an app to consume Kotlin Multiplatform resources (without a
full `KmpResourceDataSource` implementation, which poses some
dependency challenges for now).

Issue: androidx/media#1405
PiperOrigin-RevId: 638991375
2024-05-31 04:33:14 -07:00
ibaker
0f1f6bfa41 Remove deprecated DefaultHttpDataSource constructors
Use `DefaultHttpDataSource.Factory` instead.

PiperOrigin-RevId: 636875524
2024-05-24 05:03:05 -07:00
ibaker
4986fdd1a6 Remove deprecated setContentTypePredicate() methods
Use the suggested alternative on the respective
`XXXDataSource.Factory` instead.

PiperOrigin-RevId: 636560182
2024-05-23 08:32:26 -07:00
ibaker
ed4820cb61 Remove @UnstableApi from package-private files
This annotation is only needed on public classes.

This change also removes the `/* package */` comment from some `public`
classes.

PiperOrigin-RevId: 633864544
2024-05-15 02:26:55 -07:00
Googler
524181d7f2 DefaultHttpDS: Allow forcing cross protocol redirects to original
One can set crossProtocolRedirectsForceOriginal to force cross protocol redirects to use the original protocol. This might cause the connection to fail so it can only used when allowCrossProtocolRedirects is set to false or unset (default false).

PiperOrigin-RevId: 631937956
2024-05-08 15:11:04 -07:00
tonihei
344fc8a8c0 Add IntDef for priority values
This makes it easier to reference these values in documentation
and method parameters.

PiperOrigin-RevId: 629072314
2024-04-29 08:14:20 -07:00
tofunmi
ef2314c404 Move bitmap decoding out of datasource util
PiperOrigin-RevId: 619139208
2024-03-26 04:10:38 -07:00
ibaker
f9032a5893 Add checkNotNull(uri) to DataSpec constructor
This check is already present in `DataSpec.Builder.build()` but there
are many public constructors which bypass the builder (only some of
which are deprecated), so this adds an additional check.

PiperOrigin-RevId: 613908358
2024-03-08 05:59:10 -08:00
ibaker
7f5b1a98e9 Use Guava's toByteArray & fromByteArray methods where possible
Also remove intermediate object allocations in
`Util.toByteArray(int...)`.

`Util.toByteArray(InputStream)` is kept (but deprecated) because it's
been part of the library for a while and might be in use by some apps.
The others are much newer, so the chance of usages outside the library
is very low, so we just remove them directly.

PiperOrigin-RevId: 613878453
2024-03-08 03:27:29 -08:00
ibaker
b1b8b2e6f9 Remove some deprecated DataSpec constructors
PiperOrigin-RevId: 613137809
2024-03-06 02:26:11 -08:00
tofunmi
7a632a43ba Move bitmap decoding into datasource util
PiperOrigin-RevId: 608588505
2024-02-20 06:57:02 -08:00
tofunmi
f1c21f6c07 Rollback of 5a3f18f837
PiperOrigin-RevId: 608551290
2024-02-20 04:09:26 -08:00
tofunmi
5a3f18f837 Make DataSourceBitmapLoader non-final
PiperOrigin-RevId: 608275835
2024-02-19 02:52:58 -08:00
ibaker
3bbb0e7453 Add documented support for android.resource://package/id URIs
These were previously somewhat supported, but the `package` part was
never read (so it only worked if it was either absent or the same as the
current application's package). This change parses and uses the
`package` part.

This partially reverts 35121a2d3d.

This is hard to test for the same reasons as 88f554c74b:

> This is hard to test because to do so robustly requires being able to guaranteed that another test APK will be installed with a known raw resource inside it.

PiperOrigin-RevId: 608270463
2024-02-19 02:28:39 -08:00
Gaëtan Muller
973b717914 Remove unnecessary SDK_INT checks 2024-02-13 10:26:19 +00:00
tofunmi
7f087243bb Add supportsMimeType API to bitmapLoader
PiperOrigin-RevId: 597942459
2024-01-12 13:49:38 -08:00
tofunmi
6879698d7e Move setting bitmapFactory options from interface to implementation
Moves setting bitmapFactory options from BitmapLoader to DatasourceBitmapLoader

BitmapLoader is a general interface for bitmap loading that could use loading implementations other that BitmapFactory, with the rise of Glide being a loader of choice. It's best to correct this interface so that it remains generic

We can't deprecate easily because the other loadBitmap method in that case has a default implementation that relies on the first one, so the change is still breaking. BitmapLoader is public api in common, but it's @UnstableAPI and hasn't been around for very long (be38670391 added it), so it seems this is the best way forward.

PiperOrigin-RevId: 597897098
2024-01-12 11:21:48 -08:00
okunhardt
250fc80419 Move HttpEngineDataSource to the DataSource library.
Since HttpEngineDataSource does not have any external dependencies, it does not need to be in its own package.

PiperOrigin-RevId: 592623750
2023-12-20 12:10:36 -08:00
tonihei
8e33fbd536 Deprecate RAW_RESOURCE_SCHEME and util method
It's better to use the generic Android resource scheme which
is at least as powerful as our own one.

Issue: androidx/media#868
PiperOrigin-RevId: 590168919
2023-12-12 05:34:09 -08:00
ibaker
3a527a888a Split openAssetFileDescriptor from RawResourceDataSource.open
This moves the invocation of `transferInitializing` slightly earlier,
but this is consistent with other `DataSource` implementations like
`OkHttpDataSource`.

PiperOrigin-RevId: 578137236
2023-10-31 04:38:57 -07:00
ibaker
88f554c74b Add cross-package support to RawResourceDataSource
This has been documented to work since this class was created, but until
now we were always trying to resolve using the current application's
`Resources.getIdentifier` method. This commit changes to resolve to the
other app's `Resources` object if the package name doesn't match the
current package.

This will only work if the current app has package-visibility to the
destination package: http://g.co/dev/packagevisibility

This is hard to test because to do so robustly requires being able to
guaranteed that another test APK will be installed with a known raw
resource inside it.

PiperOrigin-RevId: 577864992
2023-10-30 09:17:45 -07:00
ibaker
26789b56c2 Remove unecessary proguard config symlink
PiperOrigin-RevId: 577858121
2023-10-30 08:53:51 -07:00
ibaker
aec6db77fa Add formatting to scheme list in DefaultDataSource javadoc
The current formatting makes the 'scheme' part of the list blend into
the definition, especially when the definition is multi-line.

https://developer.android.com/reference/androidx/media3/datasource/DefaultDataSource

I considered adding another level of nesting, but I think bold will
help distinguish the structure of the list without adding too much HTML
or visual whitespace.

#minor-release

PiperOrigin-RevId: 574514208
2023-10-18 10:17:58 -07:00
ibaker
681eadeb85 Test overriding resource type in RawResourceDataSource
I couldn't work out a good way to set up a test environment with
an asset in a different package, so I'm not adding a test for the
package overriding.

PiperOrigin-RevId: 573843326
2023-10-16 09:58:00 -07:00
ibaker
35121a2d3d Add RawResourceDataSource test for android.resource:///id URI
This is the documented format of this URI. The previous test was
exercising an undocumented format. Support for the previous format is
kept (and documented) because it seems to be relatively common (despite
the package name not being needed or used).

PiperOrigin-RevId: 573756190
2023-10-16 03:06:25 -07:00
ibaker
40459f7212 Test more URI forms in RawResourceDataSourceContractTest
PiperOrigin-RevId: 573220915
2023-10-13 07:57:58 -07:00
rohks
91764baa90 Add nullness annotations to SimpleCache
#fixit

PiperOrigin-RevId: 558783228
2023-08-22 15:33:08 +01:00
andrewlewis
fd284d7de2 Remove unnecessary final on DefaultHttpDataSource.Factory method
PiperOrigin-RevId: 543997872
2023-06-29 23:09:14 +00:00
tonihei
2322462404 Do not trim audio samples by changing their timestamp
MP4 edit lists sometimes ask to start playback between two samples.
If this happens, we currently change the timestamp of the first
sample to zero to trim it (e.g. to display the first frame for a
slightly shorter period of time). However, we can't do this to audio
samples are they have an inherent duration and trimming them this
way is not possible.

#minor-release

PiperOrigin-RevId: 543420218
2023-06-29 22:50:04 +00:00
jbibik
ea0f564c1e Fix missing equals sign in inline-comment parameter names
PiperOrigin-RevId: 542577676
2023-06-23 16:44:33 +00:00
tofunmi
be38670391 Transformer: Decode image in sRGB
The effects pipeline must receive images in the sRGB colorspace due to the color transfers applied in the shaders. Currently the burden to making sure images are in the right colorspaces falls onto apps. This CL ensures that this is not the case anymore.

PiperOrigin-RevId: 542323613
2023-06-22 15:41:55 +00:00
tonihei
51fb72b00d Replace deprecated NullableType from checkerframework with our own one
The existing NullableType has been deprecated 5 years ago and causes
crashes in Kotlin apps because Kotlin doesn't recognize this annotation
as a nullable type annotation.

While we can't align on a single @Nullable annotation yet, we can at
least replace this one by JSR305's @Nonnull(MAYBE) as it fulfils all
requirements, including full Kotlin compatiblity. To avoid the
cumbersome name, we can redefine it as our own @NullableType
annotation. (We can't use @Nullable to avoid name clashes with the main
@Nullable annotation from AndroidX)

Issue: google/ExoPlayer#6792
PiperOrigin-RevId: 540497469
2023-06-19 16:08:20 +01:00
ibaker
7e6dae7b31 Remove exoplayer2-only javadoc machinery from media3
This introduces whitespace-only changes in exoplayer2 due to the way
copybara stripping works.

PiperOrigin-RevId: 537296933
2023-06-05 09:47:58 +00:00
kimvde
04d8edf19e Read Exif orientation data in DataSourceBitmapLoader
PiperOrigin-RevId: 537258424
2023-06-05 09:46:26 +00:00
ibaker
d5f9cf4f19 Add singleVariant publishing config to all published gradle files
Docs:
* https://developer.android.com/build/publish-library/configure-pub-variants#single-pub-var
* https://developer.android.com/reference/tools/gradle-api/8.0/com/android/build/api/dsl/PublishingOptions

This resolves the following warning from Android Gradle Plugin 7.2.2 and
helps unblock the upgrade to AGP 8.0.1:

> Software Components will not be created automatically for Maven
> publishing from Android Gradle Plugin 8.0. To opt-in to the future
> behavior, set the Gradle property
> `android.disableAutomaticComponentCreation=true` in the
> `gradle.properties` file or use the new publishing DSL.
>
> Affected Modules: `lib-cast`, `lib-common`, `lib-container`,
> `lib-database`, `lib-datasource`, `lib-datasource-cronet`,
> `lib-datasource-okhttp`, `lib-datasource-rtmp`, `lib-decoder`,
> `lib-effect`, `lib-exoplayer`, `lib-exoplayer-all (legacy)`,
> `lib-exoplayer-dash`, `lib-exoplayer-hls`, `lib-exoplayer-ima`,
> `lib-exoplayer-rtsp`, `lib-exoplayer-smoothstreaming`,
> `lib-exoplayer-workmanager`, `lib-extractor`, `lib-media2 (legacy)`,
> `lib-mediasession (legacy)`, `lib-muxer`, `lib-session`,
> `lib-transformer`, `lib-ui`, `lib-ui-leanback`, `test-utils`,
> `test-utils-robolectric`

Issue: androidx/media#409
PiperOrigin-RevId: 533464133
2023-05-19 17:22:21 +01:00
ibaker
b3db85133a Add android.namespace to all build.gradle files
This is a pre-requisite for the Android Studio upgrade assistant to
upgrade from AGP 7.2.2 to 8.0.1, otherwise it fails and complains
this is missing.

Issue: androidx/media#409
PiperOrigin-RevId: 533463246
2023-05-19 17:19:15 +01:00