739 Commits

Author SHA1 Message Date
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
tonihei
b71effb7b0 Fix MobileHarness playback tests.
This change fixes various issues:
 - MobileHarness sometimes allocated devices with SDK < 16. As we have no tests running
   on these SDKs, a new dimension filter for the mobile_test target ensures that only
   devices with SDK >= 16 are selected. A similar filter for SDK version is also added
   to the ABR playback tests to ensure no old devices are selected.
 - DRM specific tests are skipped for Api < 18, but were not able to run because the
   DashTestRunner class tried to link to the MediaDrm constructor. Moved the
   constructor to a seperate Builder class to allow execution on Api levels 16 and 17.
 - DashWidevineOfflineTest also tried to access code for Api >= 18 without checking
   the current level.
 - Action implementations which are waiting for events did not ensure that they have a
   nextAction to wait for. This caused NullPointerExceptions when this next action was
   scheduled.
 - DefaultDrmSession always restored the offline keys when a new license was requested,
   even if the keys were already restored. These repeated slow calls to restoreKeys
   resulted in high numbers of dropped buffers.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171974859
2017-10-13 19:50:20 +01:00
tonihei
030f52b41b Wait for HandlerThread to terminate after calling quit.
Calling HandlerThread.quit() or .quitSafely() doesn't immediately terminate
the thread. It just instructs the Looper not to accept any new messages and
to terminate at the next opportunity. Added a HandlerThread.join() everywhere
where the intention is to close and release all resources and to stop all
threads.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171525241
2017-10-11 12:26:58 +01:00
andrewlewis
09165ab870 Rename droppedOutputBufferCount
Now this counter includes input buffers too, which are dropped as part of
skipping to keyframes for catch up.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171119930
2017-10-11 12:17:25 +01:00
tonihei
d7b4f8a645 Amend seek action in ActionSchedule to optionally wait until playback resumes.
This allows more deterministic action schedules, especially for real media
which may take an arbitrary amount of time to rebuffer after seeking.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171005231
2017-10-11 12:14:39 +01:00
andrewlewis
b3d462df39 Catch up video rendering by dropping to keyframes
If the current output buffer is very late and the playback position is in a
later group of pictures, drop all buffers to the keyframe preceding the
playback position.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170975259
2017-10-11 12:11:58 +01:00
tonihei
7e7fea4068 Add WaitForPlaybackStateChanged action to action schedule.
This works similar to the existing WaitForXXXX actions.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170687058
2017-10-03 08:57:14 +01:00
tonihei
096d7651d2 Execute actions in action schedule immediately.
Run next action immediately without using the handler when the requested
delay is zero. This ensures that no other code can run between these two
actions to improve deterministic test behaviour.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170456852
2017-10-03 08:54:28 +01:00
tonihei
28173991d1 Return requested position when selecting tracks in FakeMediaPeriod.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170360487
2017-10-03 08:53:01 +01:00
andrewlewis
9c7950f342 Add AudioSink interface and use it from audio renderers
This change allows applications to provide custom AudioSinks, which could be
based on android.media.AudioTrack like AudioTrackAudioSink, or could be
completely custom.

The refactoring is mostly mechanical and shouldn't result in any functionality
changes.

Some android.media.AudioTrack-specific details have to appear in the AudioSink
interface so this change modifies the javadoc on the AudioTrack (now AudioSink)
to note that some methods will have no effect.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170311083
2017-10-03 08:47:20 +01:00
tonihei
52de36c5eb Add abstract, default Player event listener.
This allows simplified listener implementations as most listeners
will not listen to all possible notifications.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170177821
2017-10-03 08:44:33 +01:00
olly
55f696e11d Fix spurious failures due to late decoding.
By default, if a codec is instantiated during an ongoing
playback, ExoPlayer will render the first frame that it
receives (so that there's "something other than black"
drawn to the surface). This frame is the key-frame before
the current playback position, and may be as much as 5
seconds behind the current position. ExoPlayer then drops
subsequent frames that are late until it's caught up to
the current position again.

For GTS tests that are counting dropped frames, this is
not desirable behavior, since it will cause spurious test
failures in cases where DummySurface is not supported.
This change overrides the default behavior so that the
player instead skips (rather than drops) frames until it's
caught up to the current playback position, and only then
renders the first frame.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170175944
2017-10-03 08:43:10 +01:00
olly
0ad39c642d Relax test termination for API level 23 and above
This allows test runs to continue when the activity
is paused (but not stopped), which is in line with
what we do in the demo app's PlayerActivity.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168699521
2017-09-15 23:40:43 +01:00
tonihei
7d59383cc4 Add reason to onPositionDiscontinuity.
This allows listeners to easily determine the source of the discontinuity.
Reasons can be period transitions, seeks, and internal reasons.

Listeners still using the deprecated ExoPlayer.EventListener interface were
updated to Player.EventListener.

GitHub: #3252

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168549612
2017-09-15 23:36:46 +01:00
hoangtc
5019da3e7b Update ABR logic in AdaptiveTrackSelection for live streaming case
In live streaming, if the playback position is very close to live edge,
the buffered duration will never reach minDurationForQualityIncreaseMs,
which prevents switching from ever happening. So we will provide the
durationToLiveEdgeUs to AdaptiveTrackSelection in live streaming case,
so it can handle this edge case.

GitHub: #3017

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168535969
2017-09-15 23:33:10 +01:00
tonihei
f9661b5373 Use Handler callback instead of sleep() to catch InteruptedException.
The sleep used to simulate data load times is ignoring InterruptedExceptions.
(This is intended and in line with SystemClock.sleep()). However, when a
Loader cancels an ongoing load, it uses interrupts. To be able to catch these
and to immediately return from the reading data source, a handler callback
is used instead of the sleep() method which allows interuptable waiting.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168212652
2017-09-15 23:28:13 +01:00
tonihei
c4bf83dd1a Support stop() in FakeExoPlayer and release media properly.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168209817
2017-09-15 23:26:56 +01:00
tonihei
c181057550 Fix bug in ActionSchedule.
When having a repeat() action and another subsequent action,
the next action should only be scheduled once (and not repeatedly).
Thus, the "next" pointer in the repeated action needs to be nulled
in the first iteration to prevent repeated scheduling of the next action.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168202212
2017-09-15 23:25:45 +01:00
tonihei
9a91482a1b Release streams in fake adaptive media period.
Releasing the media period should also release the sample streams
to allow resources to be cleaned up.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=168201377
2017-09-15 23:24:28 +01:00
tonihei
8f43dcd424 Clear buffer in fake renderer in each iteration.
This simulates reading from the buffer (which is what actual
renderers would do). Otherwise the buffer always gets expanded
and might cause memory issues.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167994899
2017-09-08 22:24:19 +01:00
tonihei
b2627d63fd Allow ExoPlayerTestRunner to end when Player.stop() is called.
In this case the playback state transitions to IDLE, which isn't
caught so far. (This code is equivalent to the one in ExoHostedTest.java)

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167980981
2017-09-08 22:22:57 +01:00
andrewlewis
7c3fe19d3f Migrate remaining tests to Robolectric
Remaining instrumentation tests either use android.os.Handler or rely on assets.
In the latter case, the tests are difficult to migrate due to differences
between the internal and external build systems, and configuration needed in
Android Studio. In addition, SimpleCacheSpanTest remains as an instrumentation
test because it fails due to a problem with string encoding on the internal
build (and two other tests in its package are kept with it because they depend
on it).

This test removes a dependency from testutils on Mockito, as a different
version of Mockito needs to be used for instrumentation tests vs Robolectric
tests, yet both sets of tests need to rely on testutils. Mockito setup is now
done directly in the tests that need it.

Move OggTestData to testutils so it can be used from both instrumentation and
Robolectric tests.

It may be possible to simplify assertions further using Truth but this is left
for possible later changes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167831435
2017-09-08 22:21:33 +01:00
tonihei
8413dab9de Use clock in action schedule to handle delays.
This allows to use a fake clock and an action schedule with timed delays
together.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167582860
2017-09-06 15:42:39 +01:00
tonihei
2f4a3fe1f3 Add postDelayed operation to Clock interface.
The default implementation is just calling through to handler.postDelayed,
while the fake clock uses its internal time value to trigger the handler
calls at the correct time.

This is useful to apply a fake clock in situations where a handler is used to
post delayed messages.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167567914
2017-09-05 16:34:44 +01:00
tonihei
264f1c903d Fix bug in FakeChunkSource.
In order to retrieve the data set, the track selection index was used, but
the data set is actually indexed by track group indices.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167566049
2017-09-05 16:33:17 +01:00
andrewlewis
0b78837f35 Fix ContentDataSource bytesRemaining calculation
The bytesRemaining didn't always take into account any skipped bytes, which
meant that reaching the end of the file was not correctly detected in read().

Issue: #3216

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167016672
2017-08-31 16:32:28 +01:00
tonihei
30b31b5679 Support empty concatenations and empty timelines in concatenations.
Both cases were not supported so far. Added tests which all failed in the
previous code version and adapted the concatenated media sources to cope with
empty timelines and empty concatenations.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166480344
2017-08-29 23:01:41 +01:00
olly
6907ffb285 Remove unnecessary view casts
findViewById is now defined using generics, which allows
the types to be inferred.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166355555
2017-08-29 22:57:17 +01:00
tonihei
aa712114c6 Force stop hosted test after timeout.
When hosted tests run into a timeout, the outer test method stops.
However, the hosted test itself may continue running and needs to be
forced-stopped to ensure it does not block any resources needed by
subsequent test methods.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=166208204
2017-08-29 22:52:10 +01:00