202 Commits

Author SHA1 Message Date
olly
35cd367c4c Throw EOFException if requested position is past end of content
PiperOrigin-RevId: 318046646
2020-06-26 11:13:49 +01:00
gyumin
e250900a57 Add mute/unmute to DeviceComponent
PiperOrigin-RevId: 305648273
2020-04-09 16:43:54 +01:00
gyumin
dbfb6b183c Implement DeviceComponent of SimpleExoPlayer
PiperOrigin-RevId: 305460260
2020-04-08 21:48:27 +01:00
olly
95ba4f85b0 Drop prefix test- from core test methods
This is one step toward following the google3's test naming convention.
See go/java-testing/getting_started#basic-test-template for details
why prefix test isn't necessary.

This CL is generated by following command
$ find -name '*Test.java' | xargs -I{} sed -i 's/^\ \ public\ void\ test\([A-Z]\)\(.*\)$/  public void \L\1\E\2/' {}

PiperOrigin-RevId: 296169886
2020-02-25 21:22:02 +00:00
olly
1cbe3f72e6 DataSpec: Deprecate most constructors
Keeping (Uri) and (Uri, position, length) to avoid needing
Builder for the trivial case.

PiperOrigin-RevId: 294530226
2020-02-13 15:43:54 +00:00
kimvde
22ce744095 Move assets from core to testdata module
PiperOrigin-RevId: 294239472
2020-02-11 17:12:13 +00:00
olly
ccce9948a9 Align media2 extension tests with other tests
PiperOrigin-RevId: 289494365
2020-01-16 13:50:36 +00:00
ibaker
7277df3547 Remove @NonNull where it's implied by @NonNullApi
Also remove it from all tests, these aren't covered by the null-checker

Covered by the following package-info.java files:
- j/c/g/a/exoplayer2/ext/mediasession/package-info.java
- j/c/g/a/exoplayer2/package-info.java
- j/c/g/a/exoplayer2/offline/package-info.java
- j/c/g/a/exoplayer2/video/package-info.java
- j/c/g/a/exoplayer2/ui/package-info.java

PiperOrigin-RevId: 277038916
2019-10-30 08:50:42 +00:00
olly
d720d2c3f6 Simplify androidTest manifests & fix links to use https
PiperOrigin-RevId: 266396506
2019-09-01 22:02:17 +01:00
tonihei
8e80acd18f Use androidx.test and extensions.
This replaces the deprecated usages of RobolectricTestRunner and
RuntimeEnvironent and fully migrates the tests to androidx.

PiperOrigin-RevId: 238011667
2019-03-15 04:53:12 +00:00
olly
0622afe170 Migrate to androidx
Issue: #5489
PiperOrigin-RevId: 234507428

Add missing annotation dependency

Issue: #5489
PiperOrigin-RevId: 234566177
2019-02-19 13:22:54 +00:00
olly
88af944891 Move CachedContentIndex and SimpleCacheSpan tests to robolectric
PiperOrigin-RevId: 223518390
2018-12-01 00:07:48 +00:00
olly
dbf5b073a6 Network type cleanup
1. Remove option to pass null context to Util.getNetworkType. IMO it's
   clearer for the caller to just not call the method in this case.
2. Stop using deprecated DefaultBandwidthMeter.Builder constructor in
   all but one place.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217147091
2018-10-18 23:17:16 +01:00
tonihei
d0161ad18b Fix all error-prone, style, optional suggestion, etc. issues.
This fixes or suppresses all reported issues by the code review linter tools.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=210107759
2018-08-28 16:37:14 +01:00
andrewlewis
5c2dd9ca42 Move all tests to JUnit 4
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209412403
2018-08-24 15:25:56 +01:00
Oliver Woodman
8fa34c1ed6 Delete stray file 2018-07-06 18:26:49 +01:00
hoangtc
c1acf87fba Support handling frame queries for MetadataRetriever.
- Support handling frame queries (i.e get frames at times, output to certain
sizes) from MetadataRetriever.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=203489788
2018-07-06 17:59:21 +01:00
brettchabot
1ee36101f6 Replace references to android.support.test with androidx.test.
The Android Test Support Library is being renamed to AndroidX Test, with its root java namespace changing from android.support.test to androidx.test.
And code location changing from tp/android/android_test_support to tp/android/androidx_test.

More information: []

TAP global presubmit: []

BUG:
79205333

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=202796842
2018-07-03 11:50:39 +01:00
hoangtc
3d3ab1f72e Add VideoRendererOutputCapturer
Added a capturer that can capture output from video renderer into bitmaps. This
class uses SurfaceCapturer to setup a surface, then configures this surface as the
output for a video renderer. Once the output is set, it will capture the
output frames from the video renderer and return them as bitmaps.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=201148184
2018-06-20 18:00:03 +01:00
hoangtc
0cb34dcd1c Add SurfaceCapturer base class, and provide the first implementation
Use PixelCopy API for the first SurfaceCapturer implementation. This supports
devices from API 24+.

Github: #3609.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=197732711
2018-06-05 12:19:00 +01:00
hoangtc
f3e650b8c7 Update InstrumentationTestCase to use JUnit4.
InstrumentationTestCase has been deprecated, and it does not offer some useful
features, such as targeting SDK version level for tests, or skipping tests if
necessary.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=197141082
2018-05-22 09:08:43 +01:00
eguven
8809193266 Add ContentMetadataInternal helper class
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=192596362
2018-04-16 10:34:46 +01:00
tonihei
66d2b76a6c Remove test max SDK version overrides.
These don't seem to be needed anymore. All tests run without them in gradle
and Blaze.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191867518
2018-04-08 16:39:57 +01:00
eguven
5925f92482 Persist content redirected URI in CacheDataSource
Issue: #2360

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=190597773
2018-03-28 00:53:40 +01:00
eguven
bb71b050c9 Add getContentMetadata and applyContentMetadataMutations to SimpleCache
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=189169899
2018-03-27 23:53:23 +01:00
eguven
10a48e778e Make CachedContent serialize whole metadata
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=189166039
2018-03-27 23:51:56 +01:00
eguven
00a7306fd8 Make CachedContent store content length in ContentMetadata
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=188742379
2018-03-13 15:37:45 +00:00
tonihei
b47fb2826b Move extension tests to Robolectric.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=187021822
2018-02-27 11:03:50 +00:00
tonihei
2406785160 Move DownloadManagerTest to Robolectric.
The waiting for a ConditionVariable to be false was replaced by a
CountDownLatch whose count is asserted to be one. The timeout of a
ConditionVariable doesn't work in Robolectric unless someone is
manually increasing the SystemClock time.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=186003125
2018-02-19 13:23:32 +00:00
eguven
c8e950537d Run DownloadManager on a custom thread while testing
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=185674707
2018-02-16 12:02:36 +00:00
tonihei
c14ef75037 Move (almost all) remaining core library instrumentation tests to Robolectric.
There are 4 tests which can't currently be moved:
 - DownloadManagerTest explicitly uses the main looper which isn't easily
   supported because the test runs on this thread.
 - ContentDataSourceTest uses an AssetFileDescriptor which wraps a
   ParcelFileDescriptor. It seems Robolectric doesn't correctly forward the
   inner wrapped file descriptor leading to NPE.
 - CacheContentIndexTest and SimpleCacheSpanTest both work fine with Gradle
   but fail with seemingly valid test failures on Blaze.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=185366678
2018-02-16 11:46:34 +00:00
tonihei
81eed7c2c3 Support isAtomic flag in DynamicConcatenatingMediaSource.
This feature is supported in the ConcatenatingMediaSource and is easily copied to this
media source. Also adding tests to check whether the atomic property works in normal
concatenation and in also in nested use.

Also fixes a bug where timeline methods of the DeferredTimeline were not correctly
forwarded.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184526881
2018-02-08 14:49:00 +00:00
tonihei
4437de4818 Fix potential media source release before media period release.
This could happen when a media source is removed from a
DynamicConcatenatingMediaSource and one of its media periods is still active.
This media period is only removed by the player after the player received
a timeline update and thus we shouldn't release the removed child source
as long as it has active media periods.

Issue:#3796

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184522836
2018-02-08 14:49:00 +00:00
andrewlewis
901dd19e3e Fix media period queue updating for ads
Resolve the media period for ad playback when resolving a subsequent period and
when receiving a timeline where the playing period in range (but wasn't before).

Fix the seek position calculation when a current ad must be skipped and is
followed by another ad.

Check MediaPeriodInfos match when checking MediaPeriodHolders, to handle cases
where a future ad should no longer be played. This may involve playing two
content media periods consecutively.

Issue: #3584

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184514558
2018-02-08 14:49:00 +00:00
eguven
b3da82dc1c Open source DownloadService, DownloadManager and related classes
Issue: #2643

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184844484
2018-02-08 14:47:54 +00:00
tonihei
286977998d Fix bug in DynamicConcatenatingMediaSource at dynamic changes of empty timelines.
When the dynamic media source contains multiple empty timelines in a row and some
of them dynamically change to a non-empty timeline, the window and period indices
are not updated correctly because the index of the changed child source is wrong.

To fix this bug, the child index is added to the media period holder to have direct
access on the current child index to prevent ambiguity.

Furthermore, the uid is changed to be the hash code of the MediaSourceHolder not the
MediaSource itself to allow adding the same MediaSource twice without violating the
unique uid policy.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183973462
2018-02-01 15:06:18 +00:00
tonihei
46c4ca7ddb Add CompositeMediaSource to handle common tasks for composite media sources.
This removes some boiler-plate code for compostite sources and will also
simplify resuing media source in the future (because this class can keep track
of child listeners).

Issue:#3498

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=183387123
2018-02-01 14:33:15 +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
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
aquilescanta
fe1e4fa1f2 Fix preparation of media sources with empty timeline
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182533415
2018-01-23 19:13:39 +00:00
tonihei
9de0123e84 When seeking while player is idle, ensure EPII's position is in sync with EPI.
As soon as the seek gets acknowledged by EPII, EPI returns the actual position
from the playback info again which is set by EPII. Thus, EPII needs to update
the position to reflect the changes expected by EPI.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=182515106
2018-01-23 19:10:45 +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
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