3068 Commits

Author SHA1 Message Date
olly
bb744e5f9b DownloadManager.Task: Remove top level thread interrupt
DownloadManager doesn't know enough about the Downloader implementations to
know that interrupting the thread is the right thing to do. In particular,
if a Downloader implementation wants to delegate work to additional worker
threads, then it will probably not want its main thread to be interrupted
on cancelation. Instead, it will want to cancel/interrupt its worker threads,
and keep its main thread blocked until work on those worker threads has
stopped (download() must not return whilst the Downloader is still touching
the cache).

This change moves control over what happens to the individual Downloader
implementations.

Issue: #5978
PiperOrigin-RevId: 309419177
2020-05-01 19:51:14 +01:00
olly
32516d85be Simplify thread interruption for downloads.
- Stop throwing InterruptedException from CacheUtil. When a CacheUtil operation
  throws or returns, the caller should always check its own state to determine
  whether they canceled the operation. If a caller is trying to catch
  InterruptedException separately to IOException to do something different in
  that case, they're probably doing the wrong thing. So it's simpler, and probably
  less error prone, just to throw an IOException in the case of interruption.
- Throwing InterruptedIOException is also consistent with what our Extractor and
  DataSource implementations do.

Issue: #5978
PiperOrigin-RevId: 309411556
2020-05-01 19:51:05 +01:00
olly
36b43780d3 Catch correct exception from Context.startService
Issue: #7306
PiperOrigin-RevId: 309392633
2020-05-01 19:50:34 +01:00
aquilescanta
0774ee1da9 Merge LoadErrorHandlingPolicy cleanup methods
Issue: #7309
PiperOrigin-RevId: 309387483
2020-05-01 19:49:24 +01:00
aquilescanta
956514ad9b Add internal demo flavor that uses MediaParser for progressive media
PiperOrigin-RevId: 309258505
2020-05-01 19:49:16 +01:00
tonihei
85bc1d6e14 Fix message indexing bug.
We keep an index hint for the next pending player message. This hint
wasn't updated correctly when messages are removed due to a timeline
update.

This change makes sure to only use the hint locally in one method so
that it doesn't need to be updated anywhere else and also adds the "hint"
suffix to the variable name to make it clearer that it's just a hint and
there are no guarantees this index actually exists anymore.

issue:#7278
PiperOrigin-RevId: 309217614
2020-05-01 19:48:14 +01:00
olly
1950905990 Don't allow bad MediaSource release implementation to crash player.
This also allows subsequent MediaSource instance in the list to still
be released successfully.

Issue: #7168
PiperOrigin-RevId: 309202170
2020-05-01 19:48:06 +01:00
aquilescanta
c4f65eb84a Add LoadErrorHandlingPolicy cleanup callbacks
Implementors should use the new callbacks to
clean up any resources associated with the
corresponding LoadEventInfo ids.

PiperOrigin-RevId: 309198455
2020-05-01 19:47:57 +01:00
olly
f6a2fad6b6 DownloadManagerTest: Clean up the tests themselves
PiperOrigin-RevId: 309022070
2020-05-01 19:47:40 +01:00
ibaker
b74b4f3c35 In-line WebvttSubtitleTest helper methods
testSubtitleEventTimes/IndicesHelper make assertions that only happen
to be the same because values in two different constants match up. It
seems much better to explicitly put the assertions in each test.

The other assert methods are just obscuring the underlying call to
Truth.

PiperOrigin-RevId: 309022044
2020-05-01 19:47:31 +01:00
ibaker
767b29f159 Implement the rest of WebVTT's line computation
Steps 4-10 of https://www.w3.org/TR/webvtt1/#cue-computed-line

This part is harder to fit into our code structure because it depends on
how many cues are simultaneously visible - so it has to go in
WebvttSubtitle not WebvttCueParser (which only deals with individual
cues in isolation).

This removes the `isNormal()` method that was trying to approximate
the correct behaviour.

PiperOrigin-RevId: 309021686
2020-05-01 19:47:23 +01:00
olly
c98caa86e9 DownloadManagerTest: Flatten downloader list
PiperOrigin-RevId: 308999582
2020-05-01 19:47:14 +01:00
olly
b65e682957 DownloadManagerTest: Disambiguate between download and removal
PiperOrigin-RevId: 308997845
2020-05-01 19:47:05 +01:00
olly
ec34c083f4 DownloadManagerTest: Make posting consistent
PiperOrigin-RevId: 308991602
2020-05-01 19:46:56 +01:00
andrewlewis
625c734726 Enable nullness checking for the IMA extension
adPlaybackState is now non-null, and the uninitialized case is covered by a new
boolean hasAdPlaybackState. Position progress updates are now non-null and
initialized with IMA's VIDEO_TIME_NOT_READY constant.

Also fix some misc code issues:
- Remove empty branch for SmoothStreaming (Android Studio warns about this).
- Tidy onTimelineChanged and onPositionDiscontinuity and the methods they call
  to improve naming.
- Remove logging for IMA events after release, as these methods are expected to
  be called in the current IMA SDK behavior.

PiperOrigin-RevId: 308977116
2020-05-01 19:46:22 +01:00
andrewlewis
dcbdbe5341 Fix handling of ad timelines without prerolls
The player's initial PlaylistTimeline has no ad cue points, so its first
MediaPeriodId has no nextAdGroupIndex. When the AdsMediaSource provides its
first timeline, the cue points become known. For the case where a preroll cue
point appeared, the preroll was detected due to isAd changing on the
MediaPeriodId.  For the case where a midroll/postroll cue point appeared, the
MediaPeriodId was actually treated as the same, which leads to keeping the
unclipped original MediaPeriod.

Fix this behavior by checking for nextAdGroupIndex becoming set or decreasing.

PiperOrigin-RevId: 308974490
2020-05-01 19:46:13 +01:00
bachinger
b22783f895 Rename sourceUri to uri
PiperOrigin-RevId: 308918151
2020-05-01 19:46:04 +01:00
ibaker
284b843da0 Add fall-back behaviour for vertical cues if rendering isn't supported
PiperOrigin-RevId: 308854072
2020-05-01 19:45:55 +01:00
olly
2d494861ec Cleanup and document TestDownloadManagerListener
PiperOrigin-RevId: 308843488
2020-05-01 19:45:29 +01:00
olly
8ab709c677 DownloadManagerTest: Remove DownloadRunner
Its only real purpose is to encapsulate a download ID, but it doesn't actually save
any code, and arguably makes it more complicated by having multiple lists of
Downloader instances, indexed by key, and also because it's another (undocumented)
class to understand.

This CL retains the multiple Downloader lists, but they will be flattened in a
child CL.

PiperOrigin-RevId: 308838026
2020-05-01 19:45:12 +01:00
olly
528104919f Add DownloadManager.getApplicationLooper
This is equivalent to the method ExoPlayer provides. It's nice for consistency,
and for retrieving the looper from test code.

PiperOrigin-RevId: 308830288
2020-05-01 19:44:54 +01:00
olly
c746885ca2 DownloadManagerTest: Don't make Downloaders ahead of the manager
DownloadRunner.getDownloader was creating Downloader instances before the actual
DownloadManager under test would have created them. Tests were then asserting and
manipulating these Downloader instances, which is quite confusing. In particular
FakeDownloader.assertDoesNotStart() is an assertion on a Downloader instance that
only makes sense when called on an instance that DownloadManager would not have
created by itself.

This change replaces FakeDownloader.assertDoesNotStart() with an assertion on
DownloadRunner that no Downloader instance has been created.

PiperOrigin-RevId: 308822398
2020-05-01 19:44:45 +01:00
olly
413b7a94de DownloadManagerTest: Remove method chaining
- Assertion chaining is generally discouraged. For example, because it's harder
  to determine which assertion failed given a line number.
- Also removed chaining of the form obj.actionX().assertY(), because it's easy
  for someone editing the test to accidentally delete actionX() when deleting
  assertY(), where-as actionX() may often be important for subsequent assertions.

PiperOrigin-RevId: 308820503
2020-05-01 19:44:36 +01:00
olly
37d9e2f485 DownloadManagerTest: Improve thread interactions
- Remove assertReleased and replace it with a proper condition variable
  that's opened when Downloader.download or Download.remove finish. As
  far as I can tell assertReleased was basically implementing "sleep for
  10 seconds after the Downloader starts". Note fixing this properly
  also makes the tests run much faster!
- Use ConditionVariable instead of CountDownLatch(1).
- Use AtomicInteger instead of volatile int because it's clearer and
  allows removal of explanatory comments.

PiperOrigin-RevId: 308819204
2020-05-01 19:44:27 +01:00
olly
1c34029e87 ConditionVariable: Fix block(long) to correctly handle large timeouts
PiperOrigin-RevId: 308815613
2020-05-01 19:44:10 +01:00
olly
be07b3cad5 ConditionVariable: Improve documentation and allow clock injection
- Improve documentation explaining the benefits of ExoPlayer's ConditionVariable
  over the one that the platform provides
- Allow Clock injection
- Create TestUtil method for obtaining a ConditionVariable whose block(long)
  method times out correctly when used in a Robolectric test
- Add basic unit tests for ConditionVariable

PiperOrigin-RevId: 308812698
2020-05-01 19:44:01 +01:00
tonihei
c9ff3ef62f Create opt-in to throw when Player is accessed on wrong thread.
This allows users to verify their own usage before the default
value is changed to an opt-out.

issue:#4463
PiperOrigin-RevId: 308808722
2020-05-01 19:43:52 +01:00
aquilescanta
b5112492be Add loadTaskId to LoadEventInfo
To be used by the LoadErrorHandlingPolicy.

PiperOrigin-RevId: 308657905
2020-05-01 19:43:34 +01:00
olly
0ba397cd4e SegmentDownloader: Pull manifest loading up to base class.
This will make it a bit easier to push manifest loads to an Executor.

Issue: #5978
PiperOrigin-RevId: 308608155
2020-05-01 19:43:25 +01:00
olly
2e1024f0d1 Add CacheDataSourceFactory getters
A previous change added these getters to CacheDataSource, but it can
also be useful to retrieve these components directly from the factory.
This is useful for tasks where we're going to need to build multiple
CacheDataSource instances (e.g., to make requests in parallel), and
also need to operate directly on the same components. It's a bit more
natural to retrieve them from the factory than from an arbitrary
CacheDataSource in this case, since it can avoid unnatural code where
you create a CacheDataSource instance earlier than you would otherwise
just to use its getters, and/or create one just to use its getters and
then throw it away.

PiperOrigin-RevId: 308606020
2020-05-01 19:43:16 +01:00
olly
86fb3dfede DownloadManagerTest: Remove spurious tests and start to simplify
PiperOrigin-RevId: 308597964
2020-05-01 19:43:07 +01:00
olly
2e9ed51503 Use Executor instead of ExecutorService for parallel downloads
- Executor is a superclass of ExecutorService, so this is arguably a little
  more flexible.
- It removes the need to use null for direct execution, because Runnable::run
  is a direct executor that can be trivially used instead.
- Removing the error-prone "cannot be a direct executor" restriction in the
  parallel version of SegmentDownloader requires not relying on the futures
  returned from ExecutorService.submit() anyway.

Issue: #5978
PiperOrigin-RevId: 308586620
2020-04-27 11:34:30 +01:00
Ian Baker
a03f8a1c95 Merge pull request #7199 from TiVo:p-fix-stuckcaption
PiperOrigin-RevId: 308229206
2020-04-27 11:18:56 +01:00
tonihei
bf5b52e288 Make sure finishAllSessions() can be called without removing listener
Currently, this method is only supposed to be called before removing
the listener from the player or when releasing the player.

If called at other times, it will throw an exception later when
a playback session is ended automatically.

issue:#7193
PiperOrigin-RevId: 308254993
2020-04-27 10:41:50 +01:00
tonihei
e9511a56ea Deprecate onSeekProcessed.
PiperOrigin-RevId: 308246116
2020-04-27 10:41:50 +01:00
aquilescanta
30c55d117e Fix NPE when reading from a SampleQueue from a loading thread
Issue: #7273
PiperOrigin-RevId: 308238035
2020-04-27 10:41:50 +01:00
tonihei
4df7470da5 Remove onSeekProcessed dependency from playback stats tracking.
The method is used to finish a brief "seeking" state that can be removed entirely
now state changes for seeking are masked.

PiperOrigin-RevId: 308237009
2020-04-27 10:41:50 +01:00
sneelavara
b3dc05933d Modified the Cea608Decoder constructor 2020-04-27 10:41:50 +01:00
sneelavara
f4f13d9132 Pass the Clock interface into the constructor 2020-04-27 10:41:50 +01:00
Sadashiva Neelavara
0ef38fcd1a Replacing Flush with Collection.emptyList 2020-04-27 10:41:50 +01:00
Sadashiva Neelavara
59b8552ac0 Fix to remove CEA-608 caption stuck on screen with timeout
This changes fixes issue #7181.  Removing CEA-608 captions that timeout after 16 seconds without a
clear.
2020-04-27 10:41:50 +01:00
bachinger
1323dd63d5 Remove Sample from SampleChooserActivity
Unmarshal from json to MediaItem instead of Sample. Further the playlist
of MediaItems is converted to Intent extras which are read by the
PlayerActivity.

PiperOrigin-RevId: 308141231
2020-04-27 10:41:33 +01:00
krocard
7c3b461b64 Make DefaultAudioSink.getFramesPerEncodedSample endianness independent
While most ExoPlayer code parsing ByteBuffers is called with buffers in big
endian, in certain situation, buffers in little endian are used too.

MediaCodec produced ByteBuffers are in little endian, while buffers
receive from the sources are in big endian (ByteBuffer's default).

As a result, some code called from AudioSink in passthrough parsed
bytebuffer in little endian. This is not correct because those
format are specified in BigEndian.

Changing the endianness of the ByteBuffer returned from MediaCodec
would impact a lot more code that can currently be tested in the
current COVID lockdown situation.

As a result, this patch instead make the parsing code independent
of the ByteBuffer.order() set. All the code that is called from
DefaultAudioSink now parses the buffer explicitly in Big Endian.

Additionally, the MPEG big endian header data of size 4 bytes was
retrieved with ByteBuffer.get, which only returns one byte.

PiperOrigin-RevId: 308116173
2020-04-27 10:41:33 +01:00
tonihei
e250fe6277 Make sure not to create new playback sessions while still IDLE.
The first session should only be created once we have the media items
and/or called prepare. Otherwise the first session is created with
an EventTime having an empty timeline making it less useful.

issue:#7193
PiperOrigin-RevId: 308100555
2020-04-27 10:41:33 +01:00
olly
63db847bf6 Make download progress updates thread safe
Issue: #5978
PiperOrigin-RevId: 308076851
2020-04-27 10:41:33 +01:00
aquilescanta
25f17acd21 Move LoadEventInfo creation to the caller
LoadEventInfo needs to also be sent to the LoadErrorHandlingPolicy.

PiperOrigin-RevId: 308066998
2020-04-27 10:41:33 +01:00
ibaker
a042346102 Reshuffle the way listeners are attached to MediaSources
This better supports custom listener types defined by MediaSource
subclasses.

Part of issue:#6765

PiperOrigin-RevId: 308050575
2020-04-27 10:40:01 +01:00
olly
84faa1ae3f SegmentDownloader cleanup
This is just some trivial cleanup to get things into a better state to
implement parallel segment downloads.

Issue: #5978
PiperOrigin-RevId: 308041996
2020-04-27 10:40:01 +01:00
aquilescanta
17fff2d0f4 Fix AdsMediaSource parameter when reporting load error
PiperOrigin-RevId: 308041841
2020-04-27 10:40:01 +01:00
olly
c452d6dfc2 Remove deprecated LoadControl method
PiperOrigin-RevId: 308031992
2020-04-27 10:40:01 +01:00