384 Commits

Author SHA1 Message Date
ojw28
f6a0cb963b Update CONTRIBUTING.md 2015-02-18 23:42:42 +00:00
ojw28
1649aa6381 Update CONTRIBUTING.md 2015-02-18 23:39:10 +00:00
Oliver Woodman
abac6b7dd6 Fix off-by-one-bug preventing NAL unit detection at the limit. 2015-02-18 19:11:52 +00:00
Oliver Woodman
b03c5c5753 Ensure we always seek after selecting a track.
Some extractor implementations underneath MediaExtractor require a seekTo
call after tracks are selected to ensure samples are read from the correct
position. De-duplicating logic was preventing this from happening in some
cases, causing issues like:

https://github.com/google/ExoPlayer/issues/301

Note that seeking all tracks a side effect of track selection sucks if
you already have one or more tracks selected, because it introduces
discontinuities to the already selected tracks. However, in general, it
*is* necessary to specify the position for the track being selected,
because the underlying extractor doesn't have enough information to know
where to start reading from. It can't determine this based on the read
positions of the already selected tracks, because the samples in these
tracks might be very sparse with respect to time.

I think a more optimal fix would be to change the SampleExtractor
interface to receive the current position as an argument to selectTrack.
For our own extractors, we'd seek the newly selected track to that
position, whilst the already enabled tracks would be left in their
current positions (if possible). For FrameworkSampleExtractor we'd
still have no choice but to call seekTo on the extractor to seek all
of the tracks. This solution ends up being more complex though, because:

- The SampleExtractor then needs a way of telling DefaultSampleSource
  which tracks were actually seeked, so that the pendingDiscontinuities
  flags can be set correctly.
- It's a weird API that requires the "current playback position to seek
  only the track being enabled"

So it may not be worth it! I think this fix is definitely good for now,
in any case.

Issue: #301
2015-02-18 15:15:20 +00:00
Oliver Woodman
cc7a15b79b Fix bad assertion 2015-02-18 15:09:45 +00:00
Oliver Woodman
526c64294a Handle the edge case of zero-length chunks.
Issue: #289
2015-02-17 16:04:44 +00:00
Oliver Woodman
a1e196fe20 Add support for elementary AAC/ADTS streams.
- This change:

1. Extracts HlsExtractor interface from TsExtractor.
2. Adds AdtsExtractor for AAC/ADTS streams, which turned out to be
   really easy.

Selection of the ADTS extractor relies on seeing the .aac extension.
This is at least guaranteed not to break anything that works already
(since no-one is going to be using .aac as the extension for something
that's not elementary AAC/ADTS).

Issue: #209
2015-02-17 15:42:38 +00:00
Oliver Woodman
b46d1fc7cc Bump dev version to 1.3.x 2015-02-16 22:30:28 +00:00
Oliver Woodman
3472e86c36 Correctly reset ADTSreader state 2015-02-16 22:22:25 +00:00
Oliver Woodman
40411269da Use C.SAMPLE_FLAG_SYNC 2015-02-13 20:36:27 +00:00
Oliver Woodman
9d480ecd20 Fix broken javadoc link 2015-02-13 20:34:30 +00:00
Oliver Woodman
bc99435b48 Add C.SAMPLE_FLAG_SYNC and removed InlinedApi suppression in a few places. 2015-02-13 20:20:45 +00:00
Oliver Woodman
5f64a1fde7 Restrict HLS buffering by total buffer size as well as duration.
This prevents excessive memory consumption when switching to
very high bitrate streams.

Issue: #278
2015-02-13 20:13:11 +00:00
Oliver Woodman
c3788c0931 Eliminate memory copy of H264 data through H264 reader.
I think this is the limit of how far we should be pushing complexity
v.s. efficiency. It's a little complicated to understand, but probably
worth it since the H264 bitstream is the majority of the data.

Issue: #278
2015-02-13 20:11:12 +00:00
Oliver Woodman
37e6946cd9 Finally - Remove Sample, fix GC churn + inefficient memory usage.
Use of Sample objects was inefficient for several reasons:

- Lots of objects (1 per sample, obviously).
- When switching up bitrates, there was a tendency for all Sample
  instances to need to expand, which effectively led to our whole
  media buffer being GC'd as each Sample discarded its byte[] to
  obtain a larger one.
- When a keyframe was encountered, the Sample would typically need
  to expand to accommodate it. Over time, this would lead to a
  gradual increase in the population of Samples that were sized to
  accommodate keyframes. These Sample instances were then typically
  underutilized whenever recycled to hold a non-keyframe, leading
  to inefficient memory usage.

This CL introduces RollingBuffer, which tightly packs pending sample
data into a byte[]s obtained from an underlying BufferPool. Which
fixes all of the above. There is still an issue where the total
memory allocation may grow when switching up bitrate, but we can
easily fix that from this point, if we choose to restrict the buffer
based on allocation size rather than time.

Issue: #278
2015-02-13 19:32:01 +00:00
Oliver Woodman
28166d8c0d Rename ParsableByteArray.length() to limit(). Add capacity(). 2015-02-13 19:31:01 +00:00
Oliver Woodman
321005e4b1 Use 'bitrate' not 'bit-rate' consistently. 2015-02-13 19:27:52 +00:00
Oliver Woodman
d1360ad7d2 Pragmatic fix for "stuck-in-ready-state" when seeking near the
end of some streams.
2015-02-13 19:26:49 +00:00
Oliver Woodman
066334dad7 Continue TsExtractor refactor.
- Remove TsExtractor's knowledge of Sample.
- Push handling of Sample objects into SampleQueue as much
  as possible. This is a precursor to replacing Sample objects
  with a different type of backing memory. Ideally, the
  individual readers shouldn't know how the sample data is
  stored. This is true after this CL, with the except of the
  TODO in H264Reader.
- Avoid double-scanning every H264 sample for NAL units, by
  moving the scan for SEI units from SeiReader into H264Reader.

Issue: #278
2015-02-12 17:24:23 +00:00
Oliver Woodman
61a86295fd Fix for video-only playbacks transitioning straight to STATE_ENDED.
The complexity around not enabling the video renderer before it
has a valid surface is because MediaCodecTrackRenderer supports
a "discard" mode where it pulls through and discards samples
without a decoder. This mode means that if the demo app were to
enable the renderer before supplying the surface, the renderer
could discard the first few frames prior to getting the surface,
meaning video rendering wouldn't happen until the following sync
frame.

To get a handle on complexity, I think we're better off just removing
support for this mode, which nicely decouples how the demo app
handles surfaces v.s. how it handles enabling/disabling renderers.
2015-02-12 17:02:34 +00:00
Oliver Woodman
784431f3e0 Move EIA reordering back to the renderer (sorry for churn).
Reordering in the extractor isn't going to work well with the
optimizations I'm making there. This change moves sorting back
to the renderer, although keeps all of the renderer
simplifications. It's basically just moving where the sort
happens from one place to another.
2015-02-12 12:48:27 +00:00
Oliver Woodman
f7fb4d4c35 Optimize NAL unit search.
I'm not really a fan of micro-optimizations, but given this method
scans through every H264 frame in the HLS case, it seems worthwhile.
The trick here is to examine the first 7 bits of the third byte
first. If they're not all 0s, then we know that we haven't found a
NAL unit, and also that we wont find one at the next two positions.
This allows the loop to increment 3 bytes at a time.

Speedup is around 60% on Art according to some ad-hoc benchmarking.
2015-02-12 12:46:58 +00:00
Oliver Woodman
3568ecaf00 Split TsExtractor into multiple files.
There's no code change here at all, except for how TsExtractor's
getLargestSampleTimestamp method works.
2015-02-12 12:09:57 +00:00
Oliver Woodman
92f085bc58 Remove intermediate copy steps in TsExtractor.
1. AdtsReader would previously copy all data through an intermediate
adtsBuffer. This change eliminates the additional copy step, and
instead copies directly into Sample objects.

2. PesReader would previously accumulate a whole packet by copying
multiple TS packets into an intermediate buffer. This change
eliminates this copy step. After the change, TS packet buffers
are propagated directly to PesPayloadReaders, which are required
to handle partial payload data correctly. The copy steps in the
extractor are simplified from:

DataSource->Ts_BitArray->Pes_BitArray->Sample->SampleHolder

To:

DataSource->Ts_BitArray->Sample->SampleHolder

Issue: #278
2015-02-11 14:57:07 +00:00
Oliver Woodman
797fa7f872 Make TsExtractor use ParsableByteArray where possible.
- TsExtractor is now based on ParsableByteArray rather than BitArray.
  This makes is much clearer that, for the most part, data is byte
  aligned. It will allow us to optimize TsExtractor without worrying
  about arbitrary bit offsets.
- BitArray is renamed ParsableBitArray for consistency, and is now
  exclusively for bit-stream level reading.
- There are some temporary methods in ParsableByteArray that should be
  cleared up once the optimizations are in place.

Issue: #278
2015-02-10 22:13:01 +00:00
Oliver Woodman
7c66b6ed3b HLS optimization #1 (refactor).
This is the start of a sequence of changes to fix the ref'd
github issue. Currently TsExtractor involves multiple memory
copy steps:

DataSource->Ts_BitArray->Pes_BitArray->Sample->SampleHolder

This is inefficient, but more importantly, the copy into
Sample is problematic, because Samples are of dynamically
varying size. The way we end up expanding Sample objects to
be large enough to hold the data being written means that we
end up gradually expanding all Sample objects in the pool
(which wastes memory), and that we generate a lot of GC churn,
particularly when switching to a higher quality which can
trigger all Sample objects to expand.

The fix will be to reduce the copy steps to:

DataSource->TsPacket->SampleHolder

We will track Pes and Sample data with lists of pointers into
TsPackets, rather than actually copying the data. We will
recycle these pointers.

The following steps are approximately how the refactor will
progress:

1. Start reducing use of BitArray. It's going to be way too
complicated to track bit-granularity offsets into multiple packets,
and allow reading across packet boundaries. In practice reads
from Ts packets are all byte aligned except for small sections,
so we'll move over to using ParsableByteArray instead, so we
only need to track byte offsets.

2. Move TsExtractor to use ParsableByteArray except for small
sections where we really need bit-granularity offsets.

3. Do the actual optimization.

Issue: #278
2015-02-10 12:25:13 +00:00
Oliver Woodman
b0a3c30a90 Improve EIA608 caption support.
- Also make text renderers respect the decodeOnly flag.
- Also fix AC3 passthrough to always allocate direct buffers.
2015-02-09 17:28:07 +00:00
Oliver Woodman
32f0eb1278 Enhance mp4 parsing. 2015-02-09 17:25:39 +00:00
Oliver Woodman
147bbe6d55 Simplify demo application.
- Remove simple variant. Maintaining both simple + full is
  unnecessary effort.
- Remove need to specify content id in Sample definition,
  except where it's actually required (for DRM requests in
  the Widevine GTS samples)
2015-02-06 11:52:14 +00:00
Oliver Woodman
bfa1de68d8 Move common MP4 parsing code to CommonMp4AtomParsers and Mp4Util.
Also add parseMp4vFromParent and return the track's duration in parseTrak.

This is in preparation for adding a non-fragmented MP4 extractor.
2015-02-06 11:43:37 +00:00
Oliver Woodman
a968e5535b Continue playback of tracks with longer duration than the timesource.
If the timesource track renderer ends, but other track renderers
haven't finished, the player would get stuck in a pending state.
This change enables automatic switching to the media clock in the
case that the timesource renderer has ended, which allows other
renderers to continue to play.
2015-02-06 11:32:46 +00:00
Oliver Woodman
03ef3d148f Add MP4V mimetype. 2015-02-06 11:32:08 +00:00
Oliver Woodman
fbf75e1263 Fix SubtitleView to redraw if text changes but bounds stay the same. 2015-02-06 11:31:13 +00:00
Oliver Woodman
7505944497 Separate leaf/container children in ContainerAtom.
Add a utility for converting named atom types to integers.

Add atom types for non-fragmented MP4 parsing.
2015-02-03 12:44:18 +00:00
Oliver Woodman
5bfc5f373b Bug fixes for ByteArrayDataSource. 2015-02-03 12:43:09 +00:00
Oliver Woodman
0ef28abbec Modified Webvtt parser to handle cue identifiers and tags.
Issue: #268
2015-02-03 12:41:49 +00:00
Oliver Woodman
c1a2f3d0c2 Add AOSP header. 2015-02-02 19:54:56 +00:00
Oliver Woodman
7b9b7c6e3b Handle non-indexed representations.
These may occur in VOD streams where a representation's data
is small enough not to require segmentation or an index. For
example subtitle files.

Issue: #268
2015-02-02 19:54:08 +00:00
Oliver Woodman
d1fe33cdf8 Add DefaultSampleSource and SampleExtractor interface.
SampleExtractor will initially only be implemented by FrameworkSampleExtractor
which delegates to a MediaExtractor, but eventually it will also be implemented
by additional extractors.

The sample extractor can be used as a source of samples via DefaultSampleSource.
2015-02-02 14:59:30 +00:00
Oliver Woodman
6f3ccc3615 Handle byte-order-mark prefix to WebVTT file.
Issue: #268
2015-02-02 14:56:33 +00:00
Oliver Woodman
ed0b02d09b Package restructuring to accommodate incoming features (sorry).
This may be painful in terms of applications having to change their
imports. Sorry about that.
2015-01-27 17:00:46 +00:00
Andrey Udovenko
27c0e7d776 Merge pull request #267 from google/dev-hls
Merge dev-hls -> dev
2015-01-27 11:48:15 -05:00
Oliver Woodman
b7be7bc01b Fix handling of PTS wraparound. 2015-01-27 15:12:33 +00:00
Oliver Woodman
ee83468084 Blacklist playlists that 404/410. 2015-01-27 15:11:44 +00:00
ojw28
c6c6f2d83e Merge pull request #266 from google/dev
dev -> dev-hls
2015-01-27 15:10:34 +00:00
Oliver Woodman
ce2f681bd3 Add directories for extensions + additional demos 2015-01-26 16:18:41 +00:00
Oliver Woodman
db5cc21c33 Revert test 2015-01-26 15:18:27 +00:00
Oliver Woodman
fda8f6d35a Test 2015-01-26 15:12:17 +00:00
Oliver Woodman
7b41741db0 Revert test. 2015-01-26 15:01:25 +00:00
Oliver Woodman
76f44eeb13 Test. 2015-01-26 15:01:00 +00:00