291 Commits

Author SHA1 Message Date
tonihei
72d99284c1 Make DynamicConcatenatingMediaSource reusable.
Issue:#3498

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183648419
2018-02-01 14:54:51 +00:00
tonihei
d32181e4e9 Use more realistic timeline window duration for playback unit tests.
100ms is unrealistically short and, for example, causes the player to buffer
many periods ahead when looping.

Previously this was not feasible, because ExoPlayerTest as instrumentation test
actually needed to wait for the realtime playback duration.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183646772
2018-02-01 14:49:12 +00:00
olly
67a812c1c2 Make FakeRenderer more realistic
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183643457
2018-02-01 14:47:36 +00:00
olly
91c52a4730 Suppress logging for BufferLengthLogAction
It's really spammy. Decided not to document tag as also
being nullable in case we ever use it for anything else
in the base action class.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183632944
2018-02-01 14:46:00 +00:00
tonihei
1ace5fa95b Make FakeMediaSource reusable.
GitHub:#3498

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183392095
2018-02-01 14:41:22 +00:00
aquilescanta
ac630b616c Propagate RemoteMediaClient's current duration to timeline if necessary
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183390851
2018-02-01 14:36:20 +00:00
aquilescanta
677fc291cf Use long for HLS media sequences
Issue:#3747

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183366339
2018-02-01 14:25:01 +00:00
tonihei
4671c23c4d Migrate ExoPlayerTest to Robolectric.
So far this wasn't possible because Robolectric's Looper and MessageQueue
implementations have multiple shortcomings:
 1. The message loop of new HandlerThreads is an not an actual loop and
    scheduled messages are executed on the thread the message is enqueued
    (not the handler thread).
 2. The scheduler used to replace the message queue is synchronizing all its
    methods. Thus, when a test attempts to add messages to a Handler from
    two different threads, it may easily run into a deadlock.
 3. The scheduler doesn't correctly emulate the order of messages as they
    would be in an actual MessageQueue:
   a. If the message is enqueued on the handler thread, it gets executed
      immediately (and not after all other messages at the same time).
   b. The list of messages is always re-sorted by time, meaning that the
      order of execution for messages at the same time is indeterminate.
 4. Robolectric's SystemClock implementation returns the current scheduler
    time of the main UI thread. So, unless this scheduler is used to add
    messages in the future, the SystemClock time never advances.

This CL adds two helper classes which extend and replace Robolectric's
ShadowLooper and ShadowMessageQueue.
 1. We intercept messages being enqueued or deleted in the message queue.
    Thus Robolectric's faulty scheduler gets never used. Instead, we keep
    a blocking priority queue of messages, sorted first by execution time
    and then by FIFO order to correctly emulate the real MessageQueue.
 2. We also keep a list of deleted messages to know which messages to ignore
    when they come up in the looper.
 3. When a new Looper is started, we override the dummy loop to an actual
    eternal while loop which waits for new messages, checks if they haven't
    been deleted, and runs the messages (similar to what Robolectric's
    MessageQueue would have done at this point).

Because we don't actually use the main UI thread in our tests, we can't rely
on the SystemClock to progress in any sensible manner. To overcome this issue,
we can use the auto-advancing FakeClock also used for the simulation tests.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182912510
2018-01-23 19:30:41 +00:00
tonihei
e991a8015b Use Truth instead of framework asserts in all tests.
This achieves two things:
1. All our tests use the same type of assertions.
2. The tests currently run as instrumentation test can be moved to
   Robolectric without changing the assertions.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182910542
2018-01-23 19:29:12 +00:00
tonihei
32e6cf5509 Remove further potential flakiness from ExoPlayerTest.
These were caused by two issues:
1. The FakeMediaSource can be updated with a new timeline. The setNewSourceInfo
is called from a different thread than prepareSource and both access local
variables without synchronization.
2. For multi-window playback, the FakeRenderer claims that isReady and isEnded
are both set to false if it read the end of the stream. However isReady should be
true because it is able to "render" its data until the end of the stream.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182785169
2018-01-23 19:26:13 +00:00
eguven
05e55f37eb Fix DashDownloaderTest.testDownloadManifestFailure
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182754993
2018-01-23 19:21:43 +00:00
eguven
b3d1635ac4 Fix CacheDataSource and SimpleCache issues
This fixes a very specific case where the data read has non-cached gaps
and a read-only CDS switches to read from upstream in a gap then the
cached data is deleted. When the CDS reaches the end of the gap, it
tries to open the next source. As there is no cached data, it tries to
continue with the already opened upstream data source but as it reached
end of the gap range, the code starts looping.

Also fixes infinite lock which occurs when in the previous case CDS isn't
readonly. It locks the content while filling the gap in the cache. At the
end of the gap, as the following data is deleted it tries to lock the
content for writing but the content is already locked by itself.

The last fix is preventing removal of CachedContent entry from
CachedContentIndex while associated key is locked.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182595426
2018-01-23 19:18:09 +00:00
tonihei
4ba17bb690 Remove potential flakiness from ExoPlayerTest caused by multi-threading.
Some tests in ExoPlayerTest issue commands to the player from the test thread
while the player is actively playing media (playWhenReady=true). Due to the
indeterminate time taken to enqueue the commands on the playback thread, they
may arrive when the player already proceeded to another window or finished
playback.

To ensure the tests are always deterministic, this change pauses playback in
the tests where this may happen before issuing the commands.
Also, for tests where we need to wait for a new window before issuing the
next command, a new action is added which allows to play until a specified
position.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182535096
2018-01-23 19:16:38 +00:00
olly
c577d9d351 Let SimpleExoPlayerView/LeanbackPlayerAdapter bind with any Player
Also sanitize naming (PlayerView/PlayerControlView).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182364487
2018-01-23 19:00:20 +00:00
tonihei
cfed8791b0 Send downStreamFormatChanged notification for embedded streams.
This allows listeners to get notified of any change to the embedded tracks.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181969023
2018-01-23 18:38:17 +00:00
eguven
1fc250a9f3 Make CacheUtil documentation clearer
Also fixed some other Cache related javadoc.

Issue: #3374

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181440687
2018-01-15 11:44:41 +00:00
olly
ff1bb2f702 Apply SeekParameters to DASH + SmoothStreaming playbacks
Issue: #2882

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181314086
2018-01-15 11:34:48 +00:00
tonihei
4ee971052b Improve Extractor partial read tests.
Partial reads were performed once using a partial size of 1 byte.
This was not enough to detect problems which only occur in combination
with IOExceptions. Partial reads are now only applied when no exception
is thrown.

Moreover, the tests didn't check whether the total number of sampled bytes
is what it is supposed to be. Added a field to the data dumps checking
the total number of bytes in the sampled data.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181296545
2018-01-15 11:33:23 +00:00
eguven
d427a1dd62 Make Cache.getCachedSpans return empty set rather than null
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181161289
2018-01-15 11:30:39 +00:00
tonihei
2bc734afec Replace message delay with send at time in playback loop.
This removes the need to calculate the time needed to run the doSomeWork
method. Consequently, we can use both the real Clock/Handler and the
FakeClock without changing the way the playback loop works and without
violating the interfaces of Clock or Handler.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180665647
2018-01-04 15:48:11 +00:00
olly
0821f578e8 Remove HandlerWrapper.Factory
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180558741
2018-01-03 13:34:36 +00:00
tonihei
22f8ee37d4 Clean-up of player message handling.
Some readability fixes for PlayerMessage and the handling in
ExoPlayerImplInternal.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180544294
2018-01-03 13:34:36 +00:00
tonihei
2bd704d833 Add missing override for reevaluateBuffer in FakeAdaptiveMediaPeriod.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180538379
2018-01-03 13:34:36 +00:00
tonihei
f279f3c843 Replace FakeExoPlayer with real player running with fake clock.
This ensures that simulated playbacks always use the current player implementation.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179929911
2018-01-03 13:34:36 +00:00
tonihei
61b9e846a8 Allow setting a Clock for the main playback thread.
This allows to inject a FakeClock for tests. Other playback components
(e.g. some media sources) still use SystemClock but they can be amended
in the future if needed.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179921889
2018-01-03 13:34:36 +00:00
tonihei
c6529344db Introduce Handler interface allowing to switch to other Handlers.
Especially this removes the need for the Clock interface to directly
implement Handler methods. Instead, we have a separate Handler interface
and the FakeClock is able to construct such a Handler.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179918255
2018-01-03 13:34:36 +00:00
tonihei
7fb296dab9 Initialize sample streams in FakeAdaptiveMediaPeriod.
This prevents NPE when release or stop is called before
tracks have been selected.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179911907
2018-01-03 13:34:36 +00:00
tonihei
ec71c05e8b Add possiblity to send messages at playback position.
This adds options to ExoPlayer.sendMessages which allow to specify a window index
and position at which the message should be sent. Additionally, the options can be
configured to use a custom Handler for the messages and whether the message should
be repeated when playback reaches the same position again.

The internal player converts these window positions to period index and position
at the earliest possibility. The internal player also attempts to update these
when the source info is refreshed. A sorted list of pending posts is kept and the
player triggers these posts when the playback position moves over the specified
position.

Issue:#2189

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179683841
2018-01-03 13:34:36 +00:00
tiffanywong
3b633f81b2 Automated g4 rollback of changelist 179563355.
*** Original change description ***

Add possiblity to send messages at playback position.

This adds options to ExoPlayer.sendMessages which allow to specify a window index
and position at which the message should be sent. Additionally, the options can be
configured to use a custom Handler for the messages and whether the message should
be repeated when playback reaches the same position again.

The internal player converts these window positions to period index and position
at the earliest possibility. The internal player also at...

***

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179666357
2018-01-03 13:34:36 +00:00
tonihei
6c2d1e1966 Add possiblity to send messages at playback position.
This adds options to ExoPlayer.sendMessages which allow to specify a window index
and position at which the message should be sent. Additionally, the options can be
configured to use a custom Handler for the messages and whether the message should
be repeated when playback reaches the same position again.

The internal player converts these window positions to period index and position
at the earliest possibility. The internal player also attempts to update these
when the source info is refreshed. A sorted list of pending posts is kept and the
player triggers these posts when the playback position moves over the specified
position.

Issue:#2189

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179563355
2018-01-02 21:36:07 +00:00
olly
539d291fce Fix some lint/analyze errors
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179406910
2018-01-02 21:30:14 +00:00
tonihei
318618d7a2 Fix seek/prepare/stop acks when exception is thrown.
1. The player doesn't acknowledge phantom stops when an exception is thrown anymore.
2. It also makes sure it doesn't reset the pendingPrepareCount unless it's actually
immediately acknowledging these prepares.
3. It ensures a seek is acknowledged even though an exception is thrown during seeking.

Added tests (which previously failed) for all three cases.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178876362
2017-12-13 12:53:39 +00:00
olly
2e3667eeff Expose ability to get adjusted seek position from MediaPeriod
Issue: #2882

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178606133
2017-12-12 19:16:34 +00:00
olly
2b0b39ca38 Public API for setting seek parameters
Issue: #2882

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178370038
2017-12-12 19:05:42 +00:00
hoangtc
88dea59cd2 Add ability for media period to discard buffered media at the back of the queue
In some occasions, we may want to discard a part of the buffered media to
improve playback quality. This CL adds this functionality by allowing the
loading media period to re-evaluate its buffer periodically (every 2s) and discard
chunks as it needs.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177958910
2017-12-12 18:43:26 +00:00
tonihei
aebc7da82b Immediately release temp buffer memory in FakeRenderer.
FakeRenderer only needs to allocate real memory because it extends BaseRenderer
which uses the actual SampleStream implementation. Immediately release the
memory after using it to prevent excessive memory usage when running fast
simulations.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177949628
2017-12-12 18:40:43 +00:00
olly
fbfa43f5a3 Enhance SeekMaps to return SeekPoints
Issue: #2882

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177814974
2017-12-04 17:39:43 +00:00
andrewlewis
fd938fb454 Update internal usages of deprecated AdaptiveMediaSourceEventListener
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177786580
2017-12-04 17:38:11 +00:00
tonihei
80fff0b7ce Discard buffer in FakeExoPlayer.
This is in line with a recent change in ExoPlayerImplInternal. Not discarding the buffer
causes OOM when running simulated playbacks.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177573930
2017-12-04 17:38:11 +00:00
tonihei
e28adb00ff Use Handler to post action schedule finished callback.
Calling it directly might skip other callbacks. For example:
ActionSchedule.Builder().waitForTimelineChanged(...).build().
is currently immediately calling through to
callback.onActionScheduleFinished when the timeline changes.
Depending on the position of the action schedule listener in the
listener set, it may skip other listeners also
listening to timeline changes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177442975
2017-12-04 17:38:11 +00:00
tonihei
ef8fa28163 Use VideoRendererEventListener to resolve unknown resolution.
Some streams don't have the new video resolution in the primary format.
Use the subsequent call to videoListener.onVideoInputFormatChanged to
resolve this unknown resolution.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177433618
2017-12-04 17:38:11 +00:00
tonihei
9e8f50a9c0 Allow multiple video and audio debug listeners in SimpleExoPlayer.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177184331
2017-12-04 17:38:11 +00:00
tonihei
54a1bb186e Allow resetInternal to release MediaSource but keep timeline.
This allows to keep the state synced with ExoPlayerImpl after stopping the player,
but still releases the media source immediately as it needs to be reprepared.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177167980
2017-12-04 17:38:11 +00:00
tonihei
f46cb907b7 Add stop with position reset to Player interface.
The ExoPlayerImpl implementation forwards the stop request with this optional
parameter. To ensure correct masking (e.g. when timeline updates arrive after
calling reset in ExoPlayerImpl but before resetInternal in
ExoPlayerImplInternal), we use the existing prepareAck counter and extend it
also count stop operations. For this to work, we also return the updated
empty timeline after finishing the reset.

The CastPlayer doesn't support the two reset options so far.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177132107
2017-12-04 17:38:11 +00:00
tonihei
95de9c96fe Don't always wait for action schedule in ExoPlayerTestRunner.
Unconditionally waiting for the action schedule to finish in ExoPlayerTestRunner
doesn't work if the action schedule is not intended to be finished.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177024139
2017-11-27 21:28:34 +00:00
tonihei
818d5a0b00 Add final to boolean used within Runnable.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176997767
2017-11-27 13:54:08 +00:00
tonihei
a4fbb45325 Remove race condition when stopping FakeExoPlayer.
A message to stop the playback and to quit the playback thread was posted in release().
The stop message removed all other already queued messages which might include
the second message to quit the thread. That led to infinite waiting in the
release method because the playback thread never got the quit signal.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176997104
2017-11-27 13:52:56 +00:00
tonihei
c4385c738f Temporarily fix flakiness of testPlayEmptyTimeline.
Fixed by explicitly waiting for the timeline update. This shouldn't be
necessary and will be removed as soon as the correct order of events
can be guaranteed (timeline change -> state change -> onSeekProcessed).

The waiting for the timeline update is implemented by introducing the
feature that the test runner also waits until the action schedule has
finished before stopping the test.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176848540
2017-11-27 13:47:48 +00:00
andrewlewis
36255c42cf Test setPlaybackParameters before preparation completes
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176837939
2017-11-27 13:46:33 +00:00
andrewlewis
de476ba4e6 Propagate the player error to ExoPlayerTestRunner
In a test run where no exceptions were thrown on the main thread and the test
did not time out, exceptions from onPlayerError were not correctly propagated to
the test thread (handleException would be called with null).

Fix ExoPlayerTestRunner.onPlayerError to propagate the actual exception from the
player.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176825907
2017-11-27 13:45:19 +00:00