8207 Commits

Author SHA1 Message Date
tonihei
8a2a527129 Ensure timeline and position are updated even if an error occurs
If an exception is thrown between updating the timeline and updating
the position in playbackInfo, the state may be inconsistent.
Exceptions are expected to be thrown while updating the player state
and we should handle such cases in a consistent way.

Similar to how we handle the same situation in seekToInternal,
the state is updated in a final block such that it gets updated to the
latest state even if an error occurs. Moving both the timeline and
position update together also ensures they always stay consistent.

PiperOrigin-RevId: 290624020
2020-01-24 11:08:55 +00:00
tonihei
21c76b012c No-op restructure of playlist update handling.
This restructure moves all the position resolving code to a static method and
removes the dependency of the MediaPeriodQueue on having an up-to-date timeline.

Both steps allow simplified reasoning about the code as the static method can't change
the state of the player, and there is no risk the queue can use the wrong timeline.

These propoerties allow to fix a bug causing inconsistent states in a follow-up step.

PiperOrigin-RevId: 290616395
2020-01-24 11:08:47 +00:00
samrobinson
df41ae3f42 Add FakeSampleStreamItem to an existing FakeSampleStream.
Allows items to be added to the queue once the sample stream has already been created.
Means tests can simulate data not all being available at the start.

PiperOrigin-RevId: 290613392
2020-01-24 11:08:38 +00:00
ibaker
04d325331b Add default to switch in TtmlDecoder
Also de-dupe a couple of case statements

PiperOrigin-RevId: 290610993
2020-01-24 11:08:30 +00:00
ibaker
9cfc75ff8a Fix warning about adjacent overload methods in TtmlStyle
PiperOrigin-RevId: 290610936
2020-01-24 11:08:21 +00:00
ibaker
f7470c5126 Remove CEA package from null-checking blacklist
PiperOrigin-RevId: 290610312
2020-01-24 11:08:13 +00:00
ibaker
de3f04b721 Delete TtmlStyle#inheritableStyle
It's never assigned or accessed from outside the class.

It was added in
<unknown commit>
then the accessor was removed in
<unknown commit>

PiperOrigin-RevId: 290601998
2020-01-24 11:08:04 +00:00
andrewlewis
0aa47c231c Remove duplicate release note
PiperOrigin-RevId: 290600248
2020-01-24 11:07:49 +00:00
andrewlewis
ea69a3dbb6 Move MpegAudioHeader to MpegUtil
This makes MPEG audio utilities similar to utilities we have for WAV,
AC-3 etc., and moves them out of the extractor package so that an
extractor module can be split out without needing to have a class in the
extractor package in the common library.

PiperOrigin-RevId: 290595089
2020-01-24 11:07:40 +00:00
tonihei
5e2b4117bd Add ID3 genres added in Wimamp 5.6 (2010).
All these genres are currently causing a warning and are not added to the Metadata.Entry.

PiperOrigin-RevId: 290594810
2020-01-24 11:07:32 +00:00
tonihei
747ae64196 Rollback of 72437e4442
*** Original commit ***

Rollback of ff89170b00

*** Original commit ***

Fix some logic in AnalyticsCollector.

All events issued from ExoPlayerImpl (i.e. Player.EventListener events) currently
try to use the media period data from the playing media period as set in the
playback thread queue. This is only correct as long as there no pending masking
operations in ExoPlayerImpl. That's why we currently disable this whenever the timeline
is...

***

PiperOrigin-RevId: 290593700
2020-01-24 11:07:23 +00:00
olly
d899e1fc6e extensions/av1: use -O2 for release builds
+ force arm (over thumb) mode for 32-bit builds

-O2 improves performance ~30-40% over the default -Oz depending on the
resolution; this is similar to what is done for vp9 which uses -O3.

PiperOrigin-RevId: 290318121
2020-01-24 11:07:14 +00:00
bachinger
72437e4442 Rollback of ff89170b00
*** Original commit ***

Fix some logic in AnalyticsCollector.

All events issued from ExoPlayerImpl (i.e. Player.EventListener events) currently
try to use the media period data from the playing media period as set in the
playback thread queue. This is only correct as long as there no pending masking
operations in ExoPlayerImpl. That's why we currently disable this whenever the timeline
is empty or a seek is pending. Since adding all the playlist API methods to the player,
this is no longer the right choice. Moreover,...

***

PiperOrigin-RevId: 290312118
2020-01-24 11:07:05 +00:00
tonihei
4cf614c639 Ensure tracks in PlaybackInfo are always in sync with position.
Currently both are updated by separate setters. If an exception is thrown between
the two setters, the state may not be consistent.

Avoid this problem by always setting them together.

PiperOrigin-RevId: 290293600
2020-01-24 11:06:56 +00:00
tonihei
ff89170b00 Fix some logic in AnalyticsCollector.
All events issued from ExoPlayerImpl (i.e. Player.EventListener events) currently
try to use the media period data from the playing media period as set in the
playback thread queue. This is only correct as long as there no pending masking
operations in ExoPlayerImpl. That's why we currently disable this whenever the timeline
is empty or a seek is pending. Since adding all the playlist API methods to the player,
this is no longer the right choice. Moreover, we don't have a definite API that tells
AnalyticsCollector when a playlist API call has been handled (and we don't want to
have one).

We can fix this by always using the current Player position information as the source
of truth (instead of the media period queue). This is definitely more correct and also
works while a masking operation is pending. To fill in the additional information from
the media period queue, we can look up a matching media period. This may not be the
first one in the list if an operation is pending.

The new methods are similar to the previous tryResolveWindowIndex method, but:
 1. They are always used (i.e. the current Player state is the main source of truth)
 2. They also check the correct ad playback state, that was just ignored previously.

PiperOrigin-RevId: 290284916
2020-01-24 11:06:47 +00:00
olly
9a9ef43976 Release notes: Move download segment merging out of 2.11.2
PiperOrigin-RevId: 290276507
2020-01-17 16:57:59 +00:00
tonihei
460449ce1e Make seek in FakeMediaPeriod more realistic.
Currently seeks are basically ignored. However, it's more realistic to re-queue the
single sample if the seek is to position 0.

PiperOrigin-RevId: 290273564
2020-01-17 16:57:51 +00:00
tonihei
3e41c0a1d2 Rollback of 3c56b113e4
*** Original commit ***

Rollback of d48dc4c159

*** Original commit ***

Move getting-stuck-prevention into DefaultLoadControl.

We recently added code that prevents getting stuck if the buffer is low and
the LoadControl refuses to continue loading (b84bde0252).

Move this logic into DefaultLoadControl to keep the workaround, and also apply the
maximum buffer size check in bytes if enabled. ExoPlayerImplInternal will now
throw if a...

***

PiperOrigin-RevId: 290273295
2020-01-17 16:57:43 +00:00
olly
a7f7d8fb03 Tidy up DownloadService restart. Final change for #6798.
- Add additional Listener methods to DownloadManager, to inform of
  changes to whether the downloads are paused or waiting for requirements.

- Only schedule the Scheduler if we really are waiting for requirements.

- Only restart the service if we're no longer waiting for requirements,
  and if there are queued downloads that will now be restarted.
  Previously the service would be restarted whenever the requirements
  were met, regardless of whether there was any work to do.

- Restart service if it might be stopping, as well as if it's already
  stopped. Also restart service if there's a download state change to a
  state for which the service should be started, if.

Issue: #6798
PiperOrigin-RevId: 290270547
2020-01-17 16:12:49 +00:00
bachinger
c5e1169666 make media source factories reusable
First cl towards DefaultMediaSourceFactory (<unknown commit>) does not change the MediaSourceFactory interface except adding @Nullable anotations to setters.

PiperOrigin-RevId: 290269640
2020-01-17 16:12:41 +00:00
olly
118d690666 2.11.2 release notes and version bump
PiperOrigin-RevId: 290269098
2020-01-17 16:12:27 +00:00
krocard
598538253a Do not hold a codec in OnFrameRenderedListener
Doing so prevent Codec which is a big object with
JNI to be garbage collected.

As the codec can not be hold in the listener, there
is no way to call release, as it must be called on
the same codec.
As a result the release method is also removed.
The downside is that at runtime some callbacks may be
dropped but it should be a short transitive state.

This also simplifies lifecycle of the listener as
the client does not have to know if release needs
to be called or not.

An alternative would have been to hold a weak ref,
but I deemed it too complicated for the
runtime gain.

PiperOrigin-RevId: 290231659
2020-01-17 14:54:48 +00:00
olly
2859a34027 HLS: Fix slow seeking into long MP3 segments
Issue: #6155
PiperOrigin-RevId: 290117324
2020-01-16 20:35:39 +00:00
kimvde
db75012503 FlacExtractor: handle case where last frame < MAX_FRAME_HEADER_SIZE
PiperOrigin-RevId: 290079840
2020-01-16 20:35:30 +00:00
krocard
a99ab62241 Tunneling timestamp use Message instead of Runnable
This avoids allocating a Runnable.

PiperOrigin-RevId: 290079660
2020-01-16 20:35:22 +00:00
olly
cb8391a526 Start service in foreground if allowed
This fixes an issue where a DownloadService implementation
that allows foreground but doesn't provide a scheduler would
not be restarted in the case that it was still in memory but
classed as idle by the platform.

It also speeds up service restart in the case that a
scheduler is provided.

Issue: #6798
PiperOrigin-RevId: 290068960
2020-01-16 20:35:13 +00:00
olly
775a17c498 Split SampleQueue.advanceTo for advance & seek use cases
This method has two use cases:

1. Seeking. Calls are immediately preceded by a call to rewind(), and
   the returned value isn't important unless it's ADVANCED_FAILED (i.e.
   the caller is only interested in success and failure).
2. Advancing. The return value is important unless it's ADVANCED_FAILED,
   in which case the caller wants to treat it as 0.

This change creates separate methods for each use case. The new seekTo
methods automatically rewind and return a boolean. The updated advanceTo
method returns 0 directly in cases where ADVANCED_FAILED was returned.
Arguments that were always hard-coded to true by callers have also been
removed.

This change is a step toward one possible solution for #6155. How we'll
solve that issue is still up for discussion, but this change seems like
one we should make regardless!

Issue: #6155
PiperOrigin-RevId: 290053743
2020-01-16 20:35:04 +00:00
olly
51f2723b90 Fix DownloadService resumption
- DownloadManagerHelper now passes all downloads to the
  DownloadService when the service is attached (and once
  the downloads are known). The service then starts the
  foreground notification updater if necessary. This fixes
  the ref'd issue.
- Don't call getScheduler() if the service is background
  only. This was already documented to be the case on the
  DownloadService constructor.
- If the service is started in the foreground on SDK level
  26 and higher, satisfy the condition to move the service
  to the foreground in onStartCommand rather than in stop().
  It's much more obviously correct, and should produce the
  same end result.

Issue: #6798
PiperOrigin-RevId: 290050024
2020-01-16 13:52:47 +00:00
Oliver Woodman
1ec05199d4 Merge pull request #6603 from TiVo:fix-tunneling-stuck-release
PiperOrigin-RevId: 290041295
2020-01-16 13:52:37 +00:00
tonihei
2e7978a0e2 Reorder renderer changes at period transitions
Currently the following sequence of events happens at automatic period transitions:
1. Update queue (=release old playing period)
2. Disable unused renderers
3. Enable newly needed renderers

This order requires difficult to follow workarounds in AnalyticsCollector for all
events related to step 2 (disable renderers). The current media period has already
been advanced so can't be used. The current workaround saves the last known playing
media period that was published as part of a PlaybackInfo update in ExoPlayerImpl.
This works in most cases, but is inherently wrong because the published state in
ExoPlayerImpl may be completely unrelated to the updates happening on the playback
thread (e.g. if many other operations are pending).

Simplify and fix this problem by changing the order of the events above:
1. Disable unused renderers.
2. Update queue
3. Enable newly needed renderers.
This way the current playing media period can be used for both renderer disable
and renderer enable events, thus it's correct in all cases and the workaround
in AnalyticsCollector can be removed.

PiperOrigin-RevId: 290037225
2020-01-16 13:52:26 +00:00
tonihei
8d2fd383f9 Fix setting maskingPeriodIndex in ExoPlayerImpl
Whenever we set the maskingWindowIndex, we also need to set the masking period index
and the masking position. Otherwise it may cause exception when the period index
is used together with the masking timeline.

PiperOrigin-RevId: 290036973
2020-01-16 13:52:18 +00:00
Oliver Woodman
17d1343375 Merge pull request #6678 from phhusson:feature/enable-multi-metadata-tracks
PiperOrigin-RevId: 290032841
2020-01-16 13:52:08 +00:00
tonihei
cf7b908e94 Fix demo app NPE when selecting unsupported samples.
PiperOrigin-RevId: 290027772
2020-01-16 13:51:58 +00:00
olly
090aed3aca Add non-null by default to source.chunk
PiperOrigin-RevId: 289859343
2020-01-16 13:51:50 +00:00
olly
4a5d788fa6 DASH: Output Format before InitializationChunk load completes
This optimization allows a ChunkSampleStream to output track
formats as soon as they're parsed during an InitializationChunk
load, rather than waiting until after the InitializationChunk
load is completed.

In DASH VOD, a single InitializationChunk typically loads the
moov and sidx atoms in that order. Hence for long form content
where the sidx is a non-trivial size, this may result in the
track formats being output a non-negligible period of time
sooner than was previously the case. This allows downstream
renderers to start codec initialization sooner, potentially
decreasing startup latency.

For a single test stream on a fast & stable network, this
pretty consistently reduced elapsed time until both audio and
video codecs have been initialized from ~0.5s to ~0.3 seconds
on a Galaxy S8. For 5 test runs without and with these patches,
the eventTime logged by EventLogger for the second decoder
init were:

Without (secs): 0.47 0.47 0.45 0.48 0.46
With (secs)   : 0.32 0.33 0.34 0.31 0.40

PiperOrigin-RevId: 289845089
2020-01-16 13:51:42 +00:00
olly
7d0f0b69a3 Optimize chunks to init their outputs before opening the DataSource
The current order of operations means that the Format is only passed
to the chunk's output after the DataSource has been opened. This
means that establishing the network connection and the downstream
renderers initializing their codecs are effectively serialized to
occur one after the other.

In the new order, the Format is passed to the chunk's output before
the DataSource has been opened. This allows the downstream renderers
to initialize their codecs in parallel with the network connection
being established, and hence latency at the start of playback is
reduced.

PiperOrigin-RevId: 289841854
2020-01-16 13:51:34 +00:00
olly
4b234388c8 Move @Nullable annotations to correct positions
PiperOrigin-RevId: 289838473
2020-01-16 13:51:26 +00:00
samrobinson
96c648c2d6 Improve customisability of FakeSampleStream.
PiperOrigin-RevId: 289829592
2020-01-16 13:51:18 +00:00
olly
a225e887fa Move @MonotonicNonNull annotations to their correct positions
PiperOrigin-RevId: 289823804
2020-01-16 13:51:09 +00:00
olly
cea37c60f8 Use customCacheKey in DownloadHelper.createMediaSource
Issue: #6870
PiperOrigin-RevId: 289658261
2020-01-16 13:51:01 +00:00
olly
3feb263cfe Fix nullability issues for testutil.truth
PiperOrigin-RevId: 289658098
2020-01-16 13:50:53 +00:00
andrewlewis
4c74f3cffd Make tests independent
PiperOrigin-RevId: 289521837
2020-01-16 13:50:44 +00:00
olly
ccce9948a9 Align media2 extension tests with other tests
PiperOrigin-RevId: 289494365
2020-01-16 13:50:36 +00:00
olly
f0ce1c3bbb Rename ID3 tag to Afro-Punk
PiperOrigin-RevId: 289490708
2020-01-16 13:50:27 +00:00
tonihei
c0ee312a30 Simplify keeping track of current id in DefaultPlaybackSessionManager
We currently have a currentMediaPeriodId and an activeSessionId that are more
or less tracking the same thing unless the current media period isn't "active" yet.

Simplify this logic by using a single currentSessionId field and the respective
isActive flag of this session. Also move all session creation and activation code in
the same method to make it easier to reason about the code.

This change also fixes a subtle bug where events after a seek to a new window
are not ignored as they should.

PiperOrigin-RevId: 289432181
2020-01-13 19:58:00 +00:00
olly
ad7bcab4c5 DownloadService: No-op cleanup
Issue: #6798
PiperOrigin-RevId: 289424582
2020-01-13 19:57:52 +00:00
tonihei
3c5c43c979 Add a clarifying comment to shouldContinueLoading handling.
PiperOrigin-RevId: 289424321
2020-01-13 19:57:44 +00:00
olly
d7643acd52 Deprecate DownloadService state change methods
As discovered whilst investigating #6798, there are cases
where these methods are not correctly. They were added as
convenience methods that could be overridden by concrete
DownloadService implementations, but since they don't work
properly it's preferable to require application code to
listen to their DownloadManager directly instead.

Notes:

- The original proposal to fix #6798 stored the state change
events in memory until they could be delivered. This approach
is not ideal because the events still end up being delivered
later than they should be. We also want to fix the root cause
in a different way that does not require doing this.
- This change does not fix #6798. It's a preparatory step.

Issue: #6798
PiperOrigin-RevId: 289418555
2020-01-13 19:57:36 +00:00
olly
15f974a277 PlayerTrackEmsgHandler: Release sample queue in release()
This change makes it clear the SampleQueue doesn't outlive
the wrapping PlayerTrackEmsgHandler, and releases it from
PlayerTrackEmsgHandler.release().

This change is a no-op because calling release() is the
same as reset() in this case (the behavior only differs if
a non-dummy DrmSessionManager is being used).

PiperOrigin-RevId: 289416622
2020-01-13 19:57:27 +00:00
aquilescanta
7f7632a38f Split HlsSampleStreamWrapper.init into two methods
As a result, onMediaChunkLoadStarted gets invoked on the loading thread, and
init on the playback thread, matching the thread access comments.

Issue:#6321
PiperOrigin-RevId: 289167981
2020-01-13 19:57:19 +00:00