Commit graph

72 commits

Author SHA1 Message Date
andrewlewis
6031f89fe9 Limit the maximum number of sources to buffer.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125698923
2016-07-07 20:32:47 +01:00
andrewlewis
aa313f234d Set TrackStreams to be final on renderers that will be disabled.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125691172
2016-07-07 20:32:11 +01:00
olly
494510d6ad Fix ready and ended conditions.
1. The readiness of the timeline is only relevant if there
   aren't any enabled renderers. It's also only ready if
   the source after the playing source is actually prepared
   (if not, we're waiting for preparation).
2. Prevent early transition to the ENDED state when the
   playback position hits the duration, but we're not at the
   final entry in the playlist.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125685193
2016-07-07 20:31:38 +01:00
olly
5055a4aa91 Some restructing to make ExoPlayerImplInternal clearer.
- Update playbackInfo duration/position/bufferedPosition in a
  single place.
- Remove sampleSource variable, and remove side effects from
  getSampleSource. There was actually a subtle bug where
  getSampleSource wasn't called by anything where no renderers
  where enabled (meaning the source never transitioned).
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125676540
2016-07-07 20:30:22 +01:00
olly
8eb1f3f57c Remove resumeInternal from ExoPlayerImplInternal.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125670965
2016-07-07 20:29:45 +01:00
olly
291b210be3 A source is fully buffered if it has no enabled tracks.
Also, getBufferedPosition shouldn't be called if no tracks
are selected.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125670213
2016-07-07 20:29:11 +01:00
olly
79cbd390ab bufferedPositionUs cannot be UNSET.
Also do some naming cleanup + do ms->us seek conversion
in ExoPlayerImpl, since that's where we now do all the
conversions coming out of the player.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125662973
2016-07-07 20:27:53 +01:00
andrewlewis
e1d3c932fa Only update track streams in updateTrackStreams.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125661172
2016-07-07 20:27:14 +01:00
andrewlewis
fc2cdef208 Don't return a TrackStream from TrackRenderer.disable.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125659817
2016-07-07 20:26:37 +01:00
olly
3e6c0ced82 A mini bit of Timeline simplification.
Pretty sure this does the same thing.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125581858
2016-07-07 20:24:45 +01:00
olly
5eca669474 Move renderers into Timeline.
The outer class should only deal with the enabled renderers.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125579652
2016-07-07 20:24:01 +01:00
andrewlewis
2073f3fce3 Expose source indices via ExoPlayer (playlists #5).
ExoPlayer.EventListener.onPositionDiscontinuity is notified during seeking and
transitioning from one source to the next.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125578976
2016-07-07 20:23:21 +01:00
olly
f9fa54cd5d Have seekTo return new position directly.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125476407
2016-07-07 20:22:38 +01:00
andrewlewis
66a5c96c5a Calculate ExtractorSampleSource duration if unknown (playlists #4).
When buffering playlist items after the currently-playing one,
continueBuffering should take a position that is negative because the playback
position is before the start of the source being buffered. This change makes
sure that ExtractorSampleSources always have a known duration when they are
fully buffered, which means that the correct (negative) source-relative
position can be calculated.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124949409
2016-06-15 20:25:26 +01:00
andrewlewis
7ae9bf409b Play a sequence of sources (playlists #3).
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124713796
2016-06-15 19:42:58 +01:00
olly
afa1ad1a6a Keep playback position advancing when all renderers are disabled.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123977520
2016-06-15 19:42:04 +01:00
olly
ed19a582a7 Suppress source release failures.
This is similar to suppression of failures disabling the
renderers (in the block above).
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123847812
2016-06-15 19:42:02 +01:00
olly
7f70ee911b Clean up chunked Sample/Chunk sources.
- Remove need for SampleSources to ref ChunkSources.
- Correctly propagate errors loading manifests through
  ChunkSource components.
- Fix some misc warnings.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123732918
2016-06-15 19:42:02 +01:00
andrewlewis
c2b89d6285 Add SampleSourceProvider as a factory for SampleSources (playlists #2).
Initially only the first source index is used. In a later change,
ExoPlayerImplInternal will create SampleSources for different playlist item
indices as necessary.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123312595
2016-06-15 19:41:35 +01:00
olly
10329eb111 Allow delivery to multiple messages in a single message.
Where multiple messages are required to be sent in order
to perform a player reconfiguration, it will usually be
desirable to process all messages in a single "transaction"
(i.e. without any rendering happening when only some of
the messages have been applied).
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123228334
2016-06-15 19:41:34 +01:00
olly
a43144decf Don't require playback Looper to build DRM session manager.
This is required because in V2 we'll be instantiating DRM
session managers before the ExoPlayer instance (and hence
we wont have the Looper). This logic will be further cleaned
up in later CLs that overhaul DrmSessionManager in more
depth.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=122453765
2016-06-15 19:41:32 +01:00
olly
6977c8f455 Bit of naming/documentation cleanup.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=122423250
2016-06-15 19:41:32 +01:00
andrewlewis
845d250442 Restore renderer.isEnded check when updating the playback position.
If rendererMediaClock is non-null, the rendererMediaClockSource is enabled or
started, so remove the check in updatePositionUs.

When disabling renderers for track selection, renderers with changing track
selections always transition from started -> enabled.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120819483
2016-06-15 19:39:35 +01:00
olly
90b7081824 Propagate resets at the source rather than track level.
- Code is simpler. We only ever reset all tracks.
- Allows the standalone media clock to be updated properly. This
  allows simpler recovery for live streams in ExtractorSampleSource.
- Fixes #1285 and paves the way for a fix for #758.

Issue: #1285
Issue: #758
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120530682
2016-06-15 19:39:10 +01:00
olly
2e0518f47b Apply Android studio code analysis suggestions.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120326293
2016-06-15 19:39:09 +01:00
olly
c99250d9c5 Constant simplification.
- Use same constant for unknown/unset microsecond times/durations.
- Change constant values to be nowhere near the "normal" range.
- Misc cleanup.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=119944019
2016-06-15 19:39:08 +01:00
andrewlewis
e4ee19513c Remove ExoPlayer.STATE_PREPARING.
prepare(SampleSource) is renamed to setSource(SampleSource). The player
immediately transitions to STATE_BUFFERING when the source is set, at which
point doSomeWork is called.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=119838825
2016-06-15 19:39:08 +01:00
andrewlewis
e594eccd4d Merge SampleSourceTrackRenderer into TrackRenderer.
TrackRenderer and SampleSourceTrackRenderer both now use a TrackStream
so they can be merged.

(This may also be useful for adding playlist support, in case TrackStreams need
to be replaced during playback.)
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=119743228
2016-06-15 19:39:07 +01:00
olly
5f37e3c8fb Ensure we re-enter the correct state after seeking.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=118579021
2016-06-15 19:39:05 +01:00
olly
d8e6b096c4 Refine fix for limbo state.
This fixes some nuances with the initial solution. Mainly,
that the TrackStreams returned by selectTrack could not be
used safely until after endTrackSelection was invoked. It
also reduces the need for member variables to track state
between the track selection methods.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=118556651
2016-06-15 19:39:05 +01:00
olly
98fb6d150d Tighten when various SampleSource methods can be called.
This removes the need for each SampleSource implementation to
implement 3x "if(condition) {noop}" tests (ChunkSampleSource
and SingleSampleSource were missing some of these checks).
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=118036233
2016-06-15 19:39:04 +01:00
olly
b3ce415e88 Fix SampleSource limbo state by introducing explicit "selecting tracks" state.
1. SampleSource now has an explicit track selection state. This state is entered
   after the source is prepared, and also by calling startTrackSelection.
2. endTrackSelection commits selection changes, and is responsible for doing the
   right thing w.r.t starting/stopping/restarting load operations.
3. All sources now start or restart a load in the case of a new track selection.
   This fixes a problem where a source could be advanced by repeatedly disabling
   and re-enabling whilst paused. Some sources didn't restart a load in this case,
   since the position was unchanged, however the downstream renderer would then
   consume media up to the first keyframe in order to render something. Hence
   each disable/re-enable would advance by a keyframe.
4. This change will enable a subsequent change where we'll discard media for
   non-selected tracks earlier than we do currently (i.e. we'll hook the extractor
   to a dummy track output, so the samples will never be written to a rolling
   buffer). This will enable a further subsequent change where buffer contributions
   are per-renderer rather than per-source.

Issue: #1041
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=118024436
2016-06-15 19:39:04 +01:00
olly
e7a27245e7 Use new-style for loops specifically for arrays.
As per: http://developer.android.com/training/articles/perf-tips.html
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117716743
2016-06-15 19:38:06 +01:00
olly
2469f631ae Restore SampleSource.disable API
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117701759
2016-06-15 19:38:06 +01:00
olly
1eff6cf210 Bring back multi-audio and VTT support for HLS.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117338865
2016-06-15 19:38:05 +01:00
olly
eeddd6d8df Allow multiple renderers with MediaClock as long as only one is enabled.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117236319
2016-06-15 19:38:04 +01:00
olly
9a40a4c77d Clean up enabled renderers + processing of resets.
- Made enabledRenderers an array to avoid loads of method calls.
- Made if so that enabled renderers are always called in a consistent
  order, rather than their order changing if they're enabled/disabled
  over time. This is likely to make performance more predictable.
- Split out reading of resets into a separate method. This method is
  now called directly after seeking on the source, so as to ensure
  instant propagation of the new position from source->renderers in
  the common case.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117225639
2016-06-15 19:37:45 +01:00
olly
d3d63101d1 [Refactor - Step #5] Introduce TrackSelector
Notes:

- The way this works is that every time the player needs to
  select some tracks it invokes the TrackSelector. When a
  track selection is actually activated (i.e. "hits the
  screen") it gets passed back to the TrackSelector, which
  allows it to expose the current tracks through an API that
  it may choose to define. Since playlist support doesn't exist
  yet, it's currently the case that the pass-back always occurs
  immediately.
- A TrackSelector can invalidate its previous selections if its
  selection criteria changes. This will force the player to invoke
  it again to make a new selection. If the new selection is the
  same as the previous one for a renderer then the player handles
  this efficiently (i.e. turns it into a no-op).
- DefaultTrackSelector supports disabling/enabling of renderers.
  Separately, it supports overrides to select specific formats.
  Since formats may change (playlists/periods), overrides are
  specific to not only the renderer but also the set of formats
  that are available to it. If the formats available to a renderer
  change then the override will no longer apply. If the same set
  of formats become available at some point later, it will apply
  once more. This will nicely handle cases like ad-insertion where
  the ads have different formats, but all segments of main content
  use the same set of formats.
- In general, in  multi-period or playlist cases, the preferred
  way of selecting formats will be via constraints (e.g. "don't play
  HD", "prefer higher quality audio") rather than explicit format
  selections. The ability to set various constraints on
  DefaultTrackSelector is future work.

Note about the demo app:

- I've removed the verbose log toggle. I doubt anyone has
  ever used it! I've also removed the background audio option.
  Without using a service it can't be considered a reference
  implementation, so it's probably best to leave developers to
  figure this one out. Finally, listening to AudioCapabilities
  has also gone. This will be replaced by having the player
  detect and handle the capabilities change internally in a
  future CL. This will work by allowing a renderer to invalidate
  the track selections when its capabilities change, much like
  how a selector is able to invalidate the track selections in
  this CL.
- It's now possible to enable ABR with an arbitrary subset of
  tracks.
- Unsupported tracks are shown grayed out in the UI. I'm not
  showing tracks that aren't associated to any renderer, but we
  could optionally add that later.
- Every time the tracks change, there's logcat output showing
  all of the tracks and which ones are enabled. Unassociated
  tracks are displayed in this output.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117122202
2016-06-15 18:54:51 +01:00
olly
73400907fc Introduce TrackGroupArray.
This change replaces TrackGroup[] with TrackGroupArray. This is
to allow equality based hashCode and equals implementations.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=115563146
2016-06-15 18:54:51 +01:00
olly
6ba4fa3b51 Make SampleSource interfaces right for TrackSelector.
The TrackSelector API will look like:

TrackSelection[] selectTrack(
    TrackRenderer[] renderers, TrackGroup[] trackGroups);

In this CL:

- SampleSources return TrackGroup[], so that the result can be easily
  passed to the selector.
- TrackStream gets its own file to sit alongside other Track* classes.
- A TrackSelection object is introduced to encapsulate group and track
  indices.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=115251331
2016-06-15 18:54:51 +01:00
olly
39a924451a Return format and adaptation support from single method.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=114963314
2016-06-15 18:54:51 +01:00
olly
0e60335064 Add structure to ExoPlaybackException.
- Add a top level failure type (source/renderer/unexpected),
  and convenience methods for retrieving the underlying cause
  without needing to cast.
- Also add renderer index in the case of renderer failures.
- setIndex/getIndex is a little . . . unclean, but alternatives
  involve either having the top line of the stack trace be a
  non-interesting line, or loads of try/catch blocks in
  ExoPlayerImplInternal.

Issue: #777
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=114763073
2016-06-15 18:54:51 +01:00
olly
a7adcce018 One Format object to rule them all.
- Format can represent both container and sample formats.
  If a container contains a single track (as is true in
  DASH and SmoothStreaming) then the container Format can
  also contain sufficient information about the samples
  to allow for track selection. This avoids the Format to
  MediaFormat conversions that we were previously doing in
  ChunkSource implementations.

- One important result of this change is that adaptive
  format evaluation and static format selection now use the
  same format objects, which is a whole lot less confusing
  for someone who wants to implement both initial selection
  and subsequent adaptation logic. It's not in the V2 doc,
  but it may well make sense if the TrackSelector not only
  selects the tracks to enable for an adaptive playback, but
  also injects a FormatEvaluator when enabling them that will
  control the subsequent adaptive selections. That would make
  it so that all format selection logic originates from the
  same place.

- As part of this change, the adaptiveX variables are removed
  from the format object; they don't really correspond to a
  single format. This also saves on having to inject the max
  video dimensions through a bunch of classes.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=114546777
2016-06-15 18:54:50 +01:00
olly
335bb0aff2 Implement decoder capability checks in MediaCodecTrackRenderers.
[Step 4 - Partial, of []

- The capabilities checks previously performed in VideoFormatSelectorUtil
  are now performed in MediaCodecVideoTrackRenderer. This means they'll be
  useful for non-chunk use cases (e.g. when using ExtractorSampleSource).
- Added capabilities checks for audio in MediaCodecAudioTrackRenderer. We
  didn't check audio capabilities previously.
- Added functionality to allow a TrackRenderer to indicate the extent of
  its adaptive support.

The idea here is that a TrackSelector (to be introduced) will have access to:

(a) TrackGroups from the SampleSource that indicate whether they support
adaptive playbacks and the formats of each individual track.
(b) TrackRenderers that indicate whether they support adaptive playbacks as
well as how capable they are of rendering formats of individual tracks.

This is everything that a TrackSelector needs from the player components in
order to decide how to wire things up. Note that a TrackSelector may opt to
treat FORMAT_EXCEEDS_CAPABILITIES as FORMAT_HANDLED at its own risk, if it
thinks that it (or the user) knows better. This is a request that we've seen
from third parties for better handling cases where capabilities aren't
accurately reported by the underlying platform.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=114427428
2016-06-15 18:54:50 +01:00
olly
be47148940 ExoPlayer V2 Refactor - Step 4
Notes:
1. The logic in ExoPlayerImplInternal is very temporary, until we
   have proper TrackSelector implementations. Ignore the fact that
   it's crazy and has loads of nesting.
2. This change removes all capabilities checking. TrackRenderer
   implementations will be updated to perform these checks in a
   subsequent CL.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=113151233
2016-06-15 18:54:26 +01:00
olly
6cb20525cb ExoPlayer V2 Refactor - Step 3
Move binding of tracks<->renderers to ExoPlayerImplInternal.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=113046018
2016-06-15 18:54:26 +01:00
olly
cdae9ac5d2 ExoPlayer V2 Refactor - Steps 1/2.
GitHub note - Apologies for the cryptic change descriptions,
they relate to a design doc that's not externally visible.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=113043764
2016-06-15 18:53:40 +01:00
olly
be2aedbd53 Don't consider switching tracks as "joining".
I'm not really sure how best to document this in TrackRenderer;
it's a bit of a weird feature. For now, I've gone with the vague
approach.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=112150939
2016-01-14 17:13:32 +00:00
Oliver Woodman
d96fe37c05 Don't use getClass().getSimpleName() where it's pointless to do so 2015-11-17 15:52:58 +00:00
Oliver Woodman
765d1659be Return "seeked to" position immediately after seek. 2015-09-18 18:25:25 +01:00