517 Commits

Author SHA1 Message Date
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
olly
2086c129fc Suppress discontinuities that don't change the position
This is mostly useful for suppressing the initial position
discontinuity reported by ClippingMediaPeriod.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176758972
2017-11-23 15:10:52 +00:00
olly
494a41c8b2 Improve ClippingMediaSource "cannot clip" behavior
This brings ClippingMediaSource clip failures in line with
what MergingMediaSource does when it cannot merge.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176660123
2017-11-22 18:27:16 +00:00
andrewlewis
31e2cfce9e Pass playback speed to LoadControl and TrackSelection
This allows implementations of those classes to take into account the playback
speed for adaptive track selection and controlling when to resume the player.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176484361
2017-11-21 13:13:35 +00:00
tonihei
a8d867be37 Support multiple transitions to STATE_ENDED in ExoPlayerTestRunner.
Currently testRunner.blockUntilEnded waits for the first transition to
STATE_ENDED or _IDLE before returning. In order to support tests with
player repreparations after one playback finished, this change adds an
option to specifiy the number of expected transitions to ended.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176484047
2017-11-21 13:12:12 +00:00
tonihei
fdb53ac8d1 Correct period index counting in ExoPlayerTestRunner.
The initial period index was counted in onPlayerStateChanged. However, we
actually want to save the period index in the newly introduced onPositionDiscontinuity
after preparation.

While being here, also updated deprecated LinkedList to ArrayList.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176479509
2017-11-21 13:09:17 +00:00
tonihei
aac53cac56 Add reason to onTimelineChanged.
Currently onTimelineChanged doesn't allow to distinguish easily between the
different reasons why it's being called. Especially, finding
out whether a new media source has been prepared or the current source
refreshed dynamically was impossible without tightly coupling the player
operations with the listener.

The new reasons provide this disdinction by either indicating a newly
initialized media source, a dynamic update to an existing timeline
or manifest, or a reset of the player (which usually results in an
empty timeline).

The original onTimelineChanged method without reason is kept in the
DefaultEventListener as deprecated to prevent the need to update all
existing listeners in one go.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176478701
2017-11-21 13:07:46 +00:00
olly
275292cb63 Report additional position discontinuities
- Properly report internal discontinuities
- Add DISCONTINUITY_REASON_SEEK_ADJUSTMENT to distinguish
  seek adjustments from other internal discontinuity events

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176367365
2017-11-21 13:04:47 +00:00
olly
3656230cb1 Use MediaSourceTestRunner in additional source tests
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176366471
2017-11-21 13:01:59 +00:00
tonihei
3f6b4d18a9 Move MockitoUtils to testutils and use it for all Mockito set-ups.
In particular this allows to have the workaround for
https://code.google.com/p/dexmaker/issues/detail?id=2 in one place only.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176340526
2017-11-20 13:40:28 +00:00
olly
82d0a27fd9 Fix some lint issues.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176337058
2017-11-20 13:39:03 +00:00
olly
676f3bfc49 Add MediaSourceTestRunner for MediaSource tests.
- MediaSourceTestRunner aims to encapsulate some of the logic
  currently used in DynamicConcatenatingMediaSourceTest, so it
  can be re-used for testing other MediaSource implementations.
- The change also fixes DynamicConcatenatingMediaSourceTest to
  execute calls on the correct threads, and to release handler
  threads at the end of each test.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176117535
2017-11-17 19:02:14 +00:00
tonihei
525ae7fed7 Add simplified FakeTimeline constructor.
This is helpful for tests which don't care about detailled timeline set-ups
besides the number of windows.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176097369
2017-11-17 18:57:51 +00:00
olly
bd0bc03f64 Inject toKeyframe discard parameter from ExoPlayerImplInternal
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175805139
2017-11-17 18:45:51 +00:00
olly
5301d38136 Some test cleanup
The purpose of this change isn't to fix anything. It's just to
simplify things a little bit. There will be following CLs that
make some changes to get things onto correct threads.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175800354
2017-11-17 18:41:38 +00:00
tonihei
5aa053d91d Add method to FakeMediaSource to trigger source info refresh.
This allows to remove the LazyMediaSource used within
DynamicConcatenatingMediaSourceTest and also allows to write test which
simulates dynamic timeline or manifest updates.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175680371
2017-11-17 18:37:08 +00:00
tonihei
b865259e63 Forward ad group and ad index when creating period from concatanted media sources.
Also added tests which verify the intended behaviour.

GitHub:#3452

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175656478
2017-11-17 18:28:21 +00:00
hoangtc
67bbbed9fe Notify TrackSelection when it's enabled and disabled.
Add onEnable() and onDisable() call-backs to TrackSelection. This allows
TrackSelection to perform interesting operations (like subscribe to
NetworkStatus) and clean up after itself.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175558485
2017-11-13 20:06:06 +00:00
tonihei
d2517b2588 Add javadoc to ExoPlayerTestRunner.
Someone must have forgotten to do this when rewriting this class.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=175296249
2017-11-13 15:17:53 +00:00
olly
2daa098a20 Don't use InputStream.available in ContentDataSource
Issue: #3426

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=174700804
2017-11-07 14:39:51 +00:00
olly
3c201a0491 Pass MediaSource instance through onSourceInfoRefreshed
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173382423
2017-10-27 16:13:59 +01:00
andrewlewis
9306b24c65 Fix some Android Studio inspection warnings
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173085316
2017-10-27 15:54:17 +01:00
olly
d09f872179 Fix positions passed to TrackSelection
- When transitioning to a new period, the value of bufferedDurationUs
  passed to TrackSelection.updateSelectedTrack was incorrectly set to
  0. It should have been set to correctly reflect buffered media in
  previous periods still being played out.
- This change fixes the issue described above, and also propagates the
  playback position through to this method. The position of the next
  load within the period can be calculated by adding the position and
  bufferedDurationUs.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172736101
2017-10-19 16:48:39 +01:00
andrewlewis
1e79d6eb84 Fix seeking with repeated periods
newPlayingPeriodHolder could be set then updated if seeking to a repeated period
that was loaded more than once. This led to MediaPeriodHolders leaking.

Only set newPlayingPeriodHolder once so that any later holders with the same
period identifier get released.

Also add a regression test. FakeMediaSource checks that all created
MediaPeriods were released when it is released.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172591937
2017-10-19 16:39:57 +01:00
tonihei
7038c8fb70 Add chunk size variation to fake adaptive data set.
The chunk size of real video data varies around the given average bitrate.
To account for this fact in the fake adaptive data set, the chunk size varies
randomly with a given standard deviation. The standard deviation used for the
BandwidthProfileSimulator is based on the chunk size variation measured on the
1 hour playlist of real media.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172068110
2017-10-13 19:53:02 +01:00