75 Commits

Author SHA1 Message Date
olly
f623a9dea0 Reduce use of DownloadInternal in DownloadManager
The only state DownloadInternal holds is duplicate of state contained
in Download, but can confusingly be temporarily out of sync. This is
error prone because it's easy to use the wrong variable (e.g.
download.state vs state). DownloadInternals methods are called into
and call out into DownloadManager, which makes some code paths that
are quite hard to follow.

It's possible to simplify DownloadManager quite a lot by removing the
duplicated state in DownloadInternal, at which point DownloadInternal's
methods flatten into DownloadManager, which can just hold an internal
list of Downloads directly.

This is a first step, which makes it clear that DownloadThready only
needs its immutable DownloadAction + an isRemove flag.

PiperOrigin-RevId: 243245288
2019-04-13 01:42:02 +01:00
eguven
8688bd2d88 Rename DownloadState to Download
PiperOrigin-RevId: 242839480
2019-04-13 01:38:25 +01:00
olly
18dcad9b8d Simplify DownloadState to contain its DownloadAction
This makes sense now that DownloadAction is only for downloading,
and not also for removal.

PiperOrigin-RevId: 242561575
2019-04-13 01:36:07 +01:00
olly
0daaba443c Get rid of DownloadState.STATE_REMOVED
It's a transient state whose only use is when passing a removed
download to onDownloadStateChanged. It's a bit strange to have it
as a proper state, since we end up asserting that it's an invalid
value in other places.

This change adds an explicit onDownloadRemoved, which allows
removal of the transient STATE_REMOVED, related assertions, and
uncertainty when dealing with an @State variable whether it's
necessary to handle it being STATE_REMOVED.

PiperOrigin-RevId: 242444128
2019-04-13 01:32:08 +01:00
eguven
facd32e65e Remove DownloadAction.createRemoveAction
PiperOrigin-RevId: 240557315
2019-03-29 16:48:55 +00:00
eguven
d85ee01ae7 Convert DownloadManager.Listener methods no-op default methods
PiperOrigin-RevId: 239019504
2019-03-20 23:26:49 +00:00
tonihei
8e80acd18f Use androidx.test and extensions.
This replaces the deprecated usages of RobolectricTestRunner and
RuntimeEnvironent and fully migrates the tests to androidx.

PiperOrigin-RevId: 238011667
2019-03-15 04:53:12 +00:00
olly
0622afe170 Migrate to androidx
Issue: #5489
PiperOrigin-RevId: 234507428

Add missing annotation dependency

Issue: #5489
PiperOrigin-RevId: 234566177
2019-02-19 13:22:54 +00:00
tonihei
edabbd52d0 Update Robolectric and Truth.
PiperOrigin-RevId: 233612344
2019-02-18 15:59:32 +00:00
olly
ae12b76ac4 Add tests to ensure DefaultRenderersFactory reflection works
Also add explicit Lint.IfChange/ThenChange rules to make it
clearer what needs to be done when changing one of the code
paths that's accessed via reflection.

PiperOrigin-RevId: 233406709
2019-02-18 15:58:11 +00:00
olly
8401097ead Upgrade gradle plugin and friends
PiperOrigin-RevId: 233390513
2019-02-18 15:57:55 +00:00
aquilescanta
891ec2230e Rearrange condition blocking to ensure Handler thread loops
Without this change, any prepare() operation that requires posting to
the DummyMainThread's handler cannot complete preparation.

PiperOrigin-RevId: 233050367
2019-02-18 15:56:54 +00:00
tonihei
cd536a73b1 Add missing removeCallbacksAndMessages to RobolectricUtil.
The Util class already handles removeMessages calls but so far ignored calls
to removeCallbacksAndMessages.

PiperOrigin-RevId: 232312458
2019-02-04 19:39:44 +00:00
tonihei
9779f2c358 Add DashMediaPeriod getStreamKeys implementation and test.
PiperOrigin-RevId: 231385518
2019-01-29 16:44:25 +00:00
tonihei
92bf8e918c Change getStreamKeys to take a list of TrackSelections.
Converting a single track selection to stream keys is only possible if the output
is independent from other track selections being made.

This is not the case for DASH and HLS embedded track groups which should select the
already selected primary track if possible (and thus needs to know  whether a primary
track group is selected).

Also, update the test method to take a period index.

PiperOrigin-RevId: 231385490
2019-01-29 16:44:15 +00:00
tonihei
22413b8037 Add start position to MediaSource.createPeriod.
That's the same position set in MediaPeriod.prepare (where it may be removed
in the future).

Having the position at an earlier point is necessary to fix an
issue with lazy preparation in ConcatenatingMediaSource where the prepare
position was assumed to be known but MediaPeriod.prepare hasn't been called
yet.

Issue:#5350
PiperOrigin-RevId: 229756637
2019-01-17 17:26:24 +00:00
eguven
ec77f737ee Make DownloadManager watch requirements directly
PiperOrigin-RevId: 229544734
2019-01-17 14:37:12 +00:00
tonihei
e8a7cb2546 Remove player and isTopLevelSource parameters from MediaSource.prepare.
They are not longer needed anywhere, are error-prone (because of threading
requirements), and complicate testing and using MediaSources without a player.

PiperOrigin-RevId: 227871157
2019-01-08 07:38:00 +00:00
eguven
7ae768376c Prepare DownloadState for upcoming changes
Made DownloadState top level class.
Replaced action field DownloadAction fields.
Added removing, removed and restarting states.
Renamed started state to downloading.

PiperOrigin-RevId: 227664735
2019-01-08 07:33:23 +00:00
eguven
3d6707e2c4 Don't create Downloads until DownloadManager is initialized
PiperOrigin-RevId: 225824428
2018-12-18 19:45:58 +00:00
olly
d5e53d11f7 Add Player.MetadataComponent for completeness
PiperOrigin-RevId: 225795581
2018-12-18 19:45:06 +00:00
tonihei
1a3d735bc3 Add assertion helper to verify MediaSource/TrackGroups/TrackSelection/StreamKey cycle.
This is useful to write integration tests for MediaSources which check that the
stream keys returned by getStreamKeys are compatible with the respective manifest
parser.

PiperOrigin-RevId: 225542606
2018-12-18 19:44:32 +00:00
eguven
41f76bdb53 Convert DownloadState id to String
For now this id can not be set by client but auto generated using
content cache key and uri.

PiperOrigin-RevId: 225356645
2018-12-14 15:41:18 +00:00
eguven
8cedfc46fb Add failureReason to DownloadState
PiperOrigin-RevId: 225154121
2018-12-14 15:40:26 +00:00
eguven
4bf42bd2ad Rename TaskState to DownloadState
PiperOrigin-RevId: 225145311
2018-12-14 15:40:16 +00:00
eguven
230a798f23 Create only one task for all DownloadActions for the same content
PiperOrigin-RevId: 225060323
2018-12-14 15:40:06 +00:00
tonihei
5776bed190 TrackSelection.Factory clean-up.
We currently have two factory methods where it is completely unclear which one needs
to be overridden.

This change deprecates the old one, adds a Util method to easily map back from the new
to the old behaviour, and updates all implementations of the now deprecated method in
our code.

PiperOrigin-RevId: 224303560
2018-12-10 18:08:50 +00:00
olly
5bbe3ae7d6 Cache data with unknown length by default
We currently default to not caching data if the content length
cannot be resolved once the DataSource has been open. The
reason for this is to avoid caching progressive live streams.
By doing this we were accidentally not caching in other places
where caching is possible, such as DASH/SS/HLS segments during
playback if the server doesn't include a Content-Length header.
Also HLS encryption key chunks, which were very unlikely to be
cached during playback because we explicitly set FLAG_ALLOW_GZIP
(which normally stops content length from resolving) without
setting FLAG_ALLOW_CACHING_UNKNOWN_LENGTH.

It seems like a good idea to flip the default at this point,
and explicitly disable caching in the one case where we want
that to happen.

PiperOrigin-RevId: 223994110
2018-12-05 17:48:34 +00:00
olly
aacb212c17 Remove duplicate CacheAsserts class
PiperOrigin-RevId: 222963935
2018-11-27 15:45:45 +00:00
aquilescanta
5f12b065a4 Support removal of ranges from ShuffleOrders
This allows more efficient range removals and is consistent with addition,
which supports adding multiple elements in a single operation.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=222396310
2018-11-22 12:50:01 +00:00
eguven
527f2cf730 Add TrackSelection.Factory createTrackSelections
createTrackSelections decides whether to create an adaptive or a fixed track seletion to create.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=222231011
2018-11-20 17:43:01 +00:00
eguven
158bc1edac Add TrackBitrateEstimator and WindowedTrackBitrateEstimator
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=220529628
2018-11-14 17:35:16 +00:00
eguven
0afd9c17e6 Add TrackSelectionUtil getBitratesUsingPastInfo
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=220066159
2018-11-06 11:07:06 +00:00
eguven
9d947a56f8 Add MediaChunkListIterator
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=219472988
2018-10-31 17:48:08 +00:00
olly
1ef3efaa90 Automated g4 rollback of changelist 217356705.
*** Reason for rollback ***

Photos regression is resolved by []

*** Original change description ***

Automated g4 rollback of changelist 217189082.

*** Reason for rollback ***

Broke photos (b/117818304)

*** Original change description ***

Add ExoPlayer.setForegroundMode

Issue: #2826

***

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217773278
2018-10-18 23:39:51 +01:00
falhassen
423a954e1b Automated g4 rollback of changelist 217189082.
*** Reason for rollback ***

Broke photos (b/117818304)

*** Original change description ***

Add ExoPlayer.setForegroundMode

Issue: #2826

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217356705
2018-10-18 23:39:31 +01:00
olly
bfd67992f4 Add ExoPlayer.setForegroundMode
Issue: #2826

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217189082
2018-10-18 23:19:09 +01:00
tonihei
a8b851ce34 Add BasePlayer to avoid code duplication for common convenience methods.
A lot of methods just forward to other methods and there is no conceivable
way a player should implement it another way. Moving these methods to a
base player class allows to remove duplicated code across our player
implementations.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=215374192
2018-10-03 22:02:47 +01:00
tonihei
b2e0a365d3 Add convenience methods player.next() and player.previous()
This simplifies code skipping items in a playlist programatically.

Issue:#4863

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=214580742
2018-09-26 13:03:39 +01:00
olly
c57fe1897c Add ExoPlayer.retry convenience method
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=211463309
2018-09-05 12:33:28 +01:00
tonihei
6b9e1824ad Extend updateSelectedTrack method with additional information.
This provides the list of currently buffered media chunks and iterators over
the potential next chunks to the track selection. Having these two parameters
enables more advanced decision logic based on this data.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=210551812
2018-09-03 14:04:45 +01:00
olly
924a76d532 Clean up use of deprecated APIs
- Add @Deprecated on overrides of deprecated method.
- Suppress deprecation warnings where appropriate.
- Use non-deprecated alternatives where appropriate.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=210092434
2018-08-24 16:12:44 +01:00
tonihei
2a9d5c21e2 Clarify doc for Player.getDuration and add Player.getContentDuration.
Similar to getBufferedPosition and getCurrentPosition, getDuration should
mention that it also returns the duration of the current ad.

And, also similar to getContentBufferedDuration and getContentPosition, a
new method getContentDuration simplifies querying the content duration while
playing an ad.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209914696
2018-08-24 15:58:01 +01:00
olly
9f0303b079 Fix a bunch of misc analysis warnings
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209758330
2018-08-24 15:48:58 +01:00
tonihei
d51b98dd1f Replace period index with uid in MediaPeriodId.
The MediaPeriodId with index is only properly defined together with a
timeline containing the index. Changing it to the period uid allows to use
the MediaPeriodId independent of the corresponding timeline.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209430257
2018-08-24 15:32:11 +01:00
olly
bd8a956d53 Use lamdas everywhere
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209162373
2018-08-24 15:19:30 +01:00
christianw
03b04ef23c [third_party] Avoid saving Robolectric shadow instances; instead, save the real framework object, and get its shadow when needed using Shadows.shadowOf(). Call Android framework methods directly on the framework object instead of its shadow whenever possible.
LSC: []
Additional details: []

Cleanup change automatically generated by javacflume/refactory
Refactoring: //third_party/java_src/robolectric/errorprone:ShadowUsageCheck

Tested:
    TAP --sample for global presubmit queue
    []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=207014379
2018-08-06 11:21:13 +01:00
tonihei
656c2172dd Fix event reporting for merging and looping media sources.
The looping media source doesn't convert the media period id to the externally
visible media period id. And the merging media source reports media period
creations multiple times which will break listeners assuming a media period
with a specific id will only be created once.

Also amend the doc for MediaSource.createPeriod to reflect that media periods
created in parallel do not actually have the same id.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=206327241
2018-08-01 13:49:20 +01:00
tonihei
a67c73650e Add helper method to get uid of timeline period.
This removes the need to populate the entire period for the common usage of
getting the uid from the period.

Also add default implementation to get period by uid.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=205638265
2018-07-23 12:22:57 +01:00
hoangtc
7cba5429fc Add supports for frame-capture retrying for MetadataRetriever.
For the MetadataRetriever, for certain queries, after setting up the player to
render a frame (by seeking to the position), sometimes the player will seek to
the same position and ignore the seek, leading to the frame not being captured,
leaving the retriever in deadlock, waiting for the frame forever. This CL adds
a retry timer to avoid this and make sure we can return query result after some
time.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204460200
2018-07-17 20:17:36 +01:00