From efd0b1e3cfa5f315348c39f03832c8a4d48ce739 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 22 May 2015 21:34:51 +0100 Subject: [PATCH 1/5] Updated all ExoPlayer Eclipse projects to use Java 1.7. --- demo/src/main/.settings/org.eclipse.jdt.core.prefs | 6 +++--- library/src/main/.settings/org.eclipse.jdt.core.prefs | 6 +++--- library/src/test/.settings/org.eclipse.jdt.core.prefs | 4 ++++ 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 library/src/test/.settings/org.eclipse.jdt.core.prefs diff --git a/demo/src/main/.settings/org.eclipse.jdt.core.prefs b/demo/src/main/.settings/org.eclipse.jdt.core.prefs index b080d2ddc8..64cef5023a 100644 --- a/demo/src/main/.settings/org.eclipse.jdt.core.prefs +++ b/demo/src/main/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/library/src/main/.settings/org.eclipse.jdt.core.prefs b/library/src/main/.settings/org.eclipse.jdt.core.prefs index b080d2ddc8..64cef5023a 100644 --- a/library/src/main/.settings/org.eclipse.jdt.core.prefs +++ b/library/src/main/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/library/src/test/.settings/org.eclipse.jdt.core.prefs b/library/src/test/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..64cef5023a --- /dev/null +++ b/library/src/test/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.source=1.7 From 79d557dd80d6d1c38725ef4c49b5ef03c80fbcfa Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 22 May 2015 21:36:35 +0100 Subject: [PATCH 2/5] Move WEBVTT custom header constants. They're current location is annoying, because it creates a dependency from the dash package to the webvtt package. For apps like Play Movies where WEBVTT isn't used, it's nice just to delete the whole package at import time, which requires that this dependency be removed. --- .../java/com/google/android/exoplayer/C.java | 16 ++++++++++++++ .../exoplayer/dash/DashChunkSource.java | 7 +++--- .../exoplayer/text/webvtt/WebvttParser.java | 22 ++++--------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/C.java b/library/src/main/java/com/google/android/exoplayer/C.java index 3c9c679000..2efc751449 100644 --- a/library/src/main/java/com/google/android/exoplayer/C.java +++ b/library/src/main/java/com/google/android/exoplayer/C.java @@ -84,6 +84,22 @@ public final class C { */ public static final int RESULT_END_OF_INPUT = -1; + /** + * A prefix for custom ExoPlayer WebVTT headers. + * + * @hide + */ + public static final String WEBVTT_EXO_HEADER = "EXO-HEADER"; + + /** + * An element of a custom ExoPlayer WebVTT header. An {@code WEBVTT_OFFSET + value} element can + * be added to a custom ExoPlayer WebVTT header to specify an offset time (in microseconds) that + * should be subtracted from the embedded MPEGTS value. + * + * @hide + */ + public static final String WEBVTT_EXO_HEADER_OFFSET = "OFFSET:"; + private C() {} } diff --git a/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java b/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java index c2927e4f50..0bee50176a 100644 --- a/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java @@ -16,6 +16,7 @@ package com.google.android.exoplayer.dash; import com.google.android.exoplayer.BehindLiveWindowException; +import com.google.android.exoplayer.C; import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.TimeRange; import com.google.android.exoplayer.TrackInfo; @@ -43,7 +44,6 @@ import com.google.android.exoplayer.extractor.ChunkIndex; import com.google.android.exoplayer.extractor.Extractor; import com.google.android.exoplayer.extractor.mp4.FragmentedMp4Extractor; import com.google.android.exoplayer.extractor.webm.WebmExtractor; -import com.google.android.exoplayer.text.webvtt.WebvttParser; import com.google.android.exoplayer.upstream.DataSource; import com.google.android.exoplayer.upstream.DataSpec; import com.google.android.exoplayer.util.Clock; @@ -566,8 +566,9 @@ public class DashChunkSource implements ChunkSource { if (representationHolder.vttHeaderOffsetUs != presentationTimeOffsetUs) { // Update the VTT header. headerBuilder.setLength(0); - headerBuilder.append(WebvttParser.EXO_HEADER).append("=") - .append(WebvttParser.OFFSET).append(presentationTimeOffsetUs).append("\n"); + headerBuilder.append(C.WEBVTT_EXO_HEADER).append("=") + .append(C.WEBVTT_EXO_HEADER_OFFSET).append(presentationTimeOffsetUs) + .append("\n"); representationHolder.vttHeader = headerBuilder.toString().getBytes(); representationHolder.vttHeaderOffsetUs = presentationTimeOffsetUs; } diff --git a/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttParser.java b/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttParser.java index 93b52c48aa..41dd74e2b6 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttParser.java +++ b/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttParser.java @@ -40,22 +40,7 @@ import java.util.regex.Pattern; */ public class WebvttParser implements SubtitleParser { - static final String TAG = "WebvttParser"; - - /** - * This parser allows a custom header to be prepended to the WebVTT data, in the form of a text - * line starting with this string. - * - * @hide - */ - public static final String EXO_HEADER = "EXO-HEADER"; - /** - * A {@code OFFSET + value} element can be added to the custom header to specify an offset time - * (in microseconds) that should be subtracted from the embedded MPEGTS value. - * - * @hide - */ - public static final String OFFSET = "OFFSET:"; + private static final String TAG = "WebvttParser"; private static final long SAMPLING_RATE = 90; @@ -73,7 +58,8 @@ public class WebvttParser implements SubtitleParser { private static final String WEBVTT_CUE_SETTING_STRING = "\\S*:\\S*"; private static final Pattern WEBVTT_CUE_SETTING = Pattern.compile(WEBVTT_CUE_SETTING_STRING); - private static final Pattern MEDIA_TIMESTAMP_OFFSET = Pattern.compile(OFFSET + "\\d+"); + private static final Pattern MEDIA_TIMESTAMP_OFFSET = + Pattern.compile(C.WEBVTT_EXO_HEADER_OFFSET + "\\d+"); private static final Pattern MEDIA_TIMESTAMP = Pattern.compile("MPEGTS:\\d+"); private static final String NON_NUMERIC_STRING = ".*[^0-9].*"; @@ -108,7 +94,7 @@ public class WebvttParser implements SubtitleParser { throw new ParserException("Expected WEBVTT or EXO-HEADER. Got null"); } - if (line.startsWith(EXO_HEADER)) { + if (line.startsWith(C.WEBVTT_EXO_HEADER)) { // parse the timestamp offset, if present Matcher matcher = MEDIA_TIMESTAMP_OFFSET.matcher(line); if (matcher.find()) { From 91bcec82f5067cb95296f4caf84ae3633bbaf290 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 22 May 2015 21:37:21 +0100 Subject: [PATCH 3/5] Support an up-front block allocation in DefaultAllocator. --- .../exoplayer/upstream/DefaultAllocator.java | 93 ++++++++++++++++--- 1 file changed, 78 insertions(+), 15 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/DefaultAllocator.java b/library/src/main/java/com/google/android/exoplayer/upstream/DefaultAllocator.java index 1d1b8f4054..a92f7f42e0 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/DefaultAllocator.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/DefaultAllocator.java @@ -25,41 +25,72 @@ import java.util.Arrays; */ public final class DefaultAllocator implements Allocator { - private static final int INITIAL_RECYCLED_ALLOCATION_CAPACITY = 100; + private static final int AVAILABLE_EXTRA_CAPACITY = 100; private final int individualAllocationSize; + private final byte[] initialAllocationBlock; private int allocatedCount; - private int recycledCount; - private Allocation[] recycledAllocations; + private int availableCount; + private Allocation[] availableAllocations; /** - * Constructs an empty pool. + * Constructs an initially empty pool. * * @param individualAllocationSize The length of each individual allocation. */ public DefaultAllocator(int individualAllocationSize) { + this(individualAllocationSize, 0); + } + + /** + * Constructs a pool with some {@link Allocation}s created up front. + *

+ * Note: Initial {@link Allocation}s will never be discarded by {@link #trim(int)}. + * + * @param individualAllocationSize The length of each individual allocation. + * @param initialAllocationCount The number of allocations to create up front. + */ + public DefaultAllocator(int individualAllocationSize, int initialAllocationCount) { Assertions.checkArgument(individualAllocationSize > 0); + Assertions.checkArgument(initialAllocationCount >= 0); this.individualAllocationSize = individualAllocationSize; - this.recycledAllocations = new Allocation[INITIAL_RECYCLED_ALLOCATION_CAPACITY]; + this.availableCount = initialAllocationCount; + this.availableAllocations = new Allocation[initialAllocationCount + AVAILABLE_EXTRA_CAPACITY]; + if (initialAllocationCount > 0) { + initialAllocationBlock = new byte[initialAllocationCount * individualAllocationSize]; + for (int i = 0; i < initialAllocationCount; i++) { + int allocationOffset = i * individualAllocationSize; + availableAllocations[i] = new Allocation(initialAllocationBlock, allocationOffset); + } + } else { + initialAllocationBlock = null; + } } @Override public synchronized Allocation allocate() { allocatedCount++; - return recycledCount > 0 ? recycledAllocations[--recycledCount] - : new Allocation(new byte[individualAllocationSize], 0); + Allocation allocation; + if (availableCount > 0) { + allocation = availableAllocations[--availableCount]; + availableAllocations[availableCount] = null; + } else { + allocation = new Allocation(new byte[individualAllocationSize], 0); + } + return allocation; } @Override public synchronized void release(Allocation allocation) { // Weak sanity check that the allocation probably originated from this pool. - Assertions.checkArgument(allocation.data.length == individualAllocationSize); + Assertions.checkArgument(allocation.data == initialAllocationBlock + || allocation.data.length == individualAllocationSize); allocatedCount--; - if (recycledCount == recycledAllocations.length) { - recycledAllocations = Arrays.copyOf(recycledAllocations, recycledAllocations.length * 2); + if (availableCount == availableAllocations.length) { + availableAllocations = Arrays.copyOf(availableAllocations, availableAllocations.length * 2); } - recycledAllocations[recycledCount++] = allocation; + availableAllocations[availableCount++] = allocation; // Wake up threads waiting for the allocated size to drop. notifyAll(); } @@ -67,11 +98,43 @@ public final class DefaultAllocator implements Allocator { @Override public synchronized void trim(int targetSize) { int targetAllocationCount = Util.ceilDivide(targetSize, individualAllocationSize); - int targetRecycledAllocationCount = Math.max(0, targetAllocationCount - allocatedCount); - if (targetRecycledAllocationCount < recycledCount) { - Arrays.fill(recycledAllocations, targetRecycledAllocationCount, recycledCount, null); - recycledCount = targetRecycledAllocationCount; + int targetAvailableCount = Math.max(0, targetAllocationCount - allocatedCount); + if (targetAvailableCount >= availableCount) { + // We're already at or below the target. + return; } + + if (initialAllocationBlock != null) { + // Some allocations are backed by an initial block. We need to make sure that we hold onto all + // such allocations. Re-order the available allocations so that the ones backed by the initial + // block come first. + int lowIndex = 0; + int highIndex = availableCount - 1; + while (lowIndex <= highIndex) { + Allocation lowAllocation = availableAllocations[lowIndex]; + if (lowAllocation.data == initialAllocationBlock) { + lowIndex++; + } else { + Allocation highAllocation = availableAllocations[lowIndex]; + if (highAllocation.data != initialAllocationBlock) { + highIndex--; + } else { + availableAllocations[lowIndex++] = highAllocation; + availableAllocations[highIndex--] = lowAllocation; + } + } + } + // lowIndex is the index of the first allocation not backed by an initial block. + targetAvailableCount = Math.max(targetAvailableCount, lowIndex); + if (targetAvailableCount >= availableCount) { + // We're already at or below the target. + return; + } + } + + // Discard allocations beyond the target. + Arrays.fill(availableAllocations, targetAvailableCount, availableCount, null); + availableCount = targetAvailableCount; } @Override From 67d0154960b3e4a413b57359ebd6f1004b4636f2 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 22 May 2015 21:40:22 +0100 Subject: [PATCH 4/5] Use Java7 <> syntax --- .../demo/SmoothStreamingTestMediaDrmCallback.java | 2 +- .../exoplayer/demo/player/DashRendererBuilder.java | 12 ++++++------ .../android/exoplayer/demo/player/DemoPlayer.java | 2 +- .../exoplayer/demo/player/HlsRendererBuilder.java | 4 ++-- .../player/SmoothStreamingRendererBuilder.java | 2 +- .../android/exoplayer/DefaultLoadControl.java | 4 ++-- .../google/android/exoplayer/ExoPlayerImpl.java | 2 +- .../android/exoplayer/ExoPlayerImplInternal.java | 2 +- .../android/exoplayer/MediaCodecTrackRenderer.java | 2 +- .../google/android/exoplayer/MediaCodecUtil.java | 2 +- .../com/google/android/exoplayer/MediaFormat.java | 2 +- .../android/exoplayer/chunk/ChunkSampleSource.java | 2 +- .../exoplayer/chunk/VideoFormatSelectorUtil.java | 2 +- .../android/exoplayer/dash/DashChunkSource.java | 2 +- .../mpd/MediaPresentationDescriptionParser.java | 14 +++++++------- .../dash/mpd/UtcTimingElementResolver.java | 2 +- .../google/android/exoplayer/drm/DrmInitData.java | 2 +- .../exoplayer/drm/StreamingDrmSessionManager.java | 2 +- .../exoplayer/extractor/ExtractorSampleSource.java | 2 +- .../exoplayer/extractor/RollingSampleBuffer.java | 2 +- .../android/exoplayer/extractor/mp4/Atom.java | 4 ++-- .../exoplayer/extractor/mp4/AtomParsers.java | 4 ++-- .../extractor/mp4/FragmentedMp4Extractor.java | 2 +- .../exoplayer/extractor/mp4/Mp4Extractor.java | 4 ++-- .../android/exoplayer/extractor/ts/H264Reader.java | 2 +- .../exoplayer/extractor/ts/TsExtractor.java | 2 +- .../extractor/webm/DefaultEbmlReader.java | 2 +- .../exoplayer/extractor/webm/WebmExtractor.java | 4 ++-- .../android/exoplayer/hls/HlsChunkSource.java | 6 +++--- .../android/exoplayer/hls/HlsExtractorWrapper.java | 2 +- .../android/exoplayer/hls/HlsPlaylistParser.java | 8 ++++---- .../android/exoplayer/hls/HlsSampleSource.java | 2 +- .../android/exoplayer/metadata/Id3Parser.java | 2 +- .../SmoothStreamingChunkSource.java | 4 ++-- .../SmoothStreamingManifestParser.java | 10 +++++----- .../android/exoplayer/text/SubtitleLayout.java | 2 +- .../exoplayer/text/eia608/Eia608Parser.java | 2 +- .../exoplayer/text/eia608/Eia608TrackRenderer.java | 2 +- .../android/exoplayer/text/ttml/TtmlNode.java | 4 ++-- .../android/exoplayer/text/ttml/TtmlParser.java | 2 +- .../exoplayer/text/webvtt/WebvttParser.java | 2 +- .../exoplayer/text/webvtt/WebvttSubtitle.java | 2 +- .../exoplayer/upstream/DefaultHttpDataSource.java | 4 ++-- .../android/exoplayer/upstream/NetworkLock.java | 2 +- .../cache/LeastRecentlyUsedCacheEvictor.java | 2 +- .../exoplayer/upstream/cache/SimpleCache.java | 14 +++++++------- .../exoplayer/util/CodecSpecificDataUtil.java | 2 +- .../android/exoplayer/util/ManifestFetcher.java | 4 ++-- .../android/exoplayer/util/SlidingPercentile.java | 2 +- .../google/android/exoplayer/MediaFormatTest.java | 2 +- .../exoplayer/dash/DashChunkSourceTest.java | 14 +++++++------- .../exoplayer/extractor/mp4/Mp4ExtractorTest.java | 2 +- .../extractor/webm/DefaultEbmlReaderTest.java | 2 +- .../android/exoplayer/testutil/FakeDataSource.java | 2 +- .../exoplayer/text/webvtt/WebvttSubtitleTest.java | 7 ++++--- .../google/android/exoplayer/util/UtilTest.java | 4 ++-- 56 files changed, 102 insertions(+), 101 deletions(-) diff --git a/demo/src/main/java/com/google/android/exoplayer/demo/SmoothStreamingTestMediaDrmCallback.java b/demo/src/main/java/com/google/android/exoplayer/demo/SmoothStreamingTestMediaDrmCallback.java index ace3f1ee08..ec4b0c231d 100644 --- a/demo/src/main/java/com/google/android/exoplayer/demo/SmoothStreamingTestMediaDrmCallback.java +++ b/demo/src/main/java/com/google/android/exoplayer/demo/SmoothStreamingTestMediaDrmCallback.java @@ -38,7 +38,7 @@ public class SmoothStreamingTestMediaDrmCallback implements MediaDrmCallback { "http://playready.directtaps.net/pr/svc/rightsmanager.asmx"; private static final Map KEY_REQUEST_PROPERTIES; static { - HashMap keyRequestProperties = new HashMap(); + HashMap keyRequestProperties = new HashMap<>(); keyRequestProperties.put("Content-Type", "text/xml"); keyRequestProperties.put("SOAPAction", "http://schemas.microsoft.com/DRM/2007/03/protocols/AcquireLicense"); diff --git a/demo/src/main/java/com/google/android/exoplayer/demo/player/DashRendererBuilder.java b/demo/src/main/java/com/google/android/exoplayer/demo/player/DashRendererBuilder.java index 150496f2a7..29424e51a4 100644 --- a/demo/src/main/java/com/google/android/exoplayer/demo/player/DashRendererBuilder.java +++ b/demo/src/main/java/com/google/android/exoplayer/demo/player/DashRendererBuilder.java @@ -131,7 +131,7 @@ public class DashRendererBuilder implements RendererBuilder, this.callback = callback; MediaPresentationDescriptionParser parser = new MediaPresentationDescriptionParser(); manifestDataSource = new DefaultUriDataSource(context, userAgent); - manifestFetcher = new ManifestFetcher(url, manifestDataSource, + manifestFetcher = new ManifestFetcher<>(url, manifestDataSource, parser); manifestFetcher.singleLoad(player.getMainHandler().getLooper(), this); } @@ -247,13 +247,13 @@ public class DashRendererBuilder implements RendererBuilder, } // Build the audio chunk sources. - List audioChunkSourceList = new ArrayList(); - List audioTrackNameList = new ArrayList(); + List audioChunkSourceList = new ArrayList<>(); + List audioTrackNameList = new ArrayList<>(); if (audioAdaptationSet != null) { DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent); FormatEvaluator audioEvaluator = new FormatEvaluator.FixedEvaluator(); List audioRepresentations = audioAdaptationSet.representations; - List codecs = new ArrayList(); + List codecs = new ArrayList<>(); for (int i = 0; i < audioRepresentations.size(); i++) { Format format = audioRepresentations.get(i).format; audioTrackNameList.add(format.id + " (" + format.numChannels + "ch, " + @@ -307,8 +307,8 @@ public class DashRendererBuilder implements RendererBuilder, // Build the text chunk sources. DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent); FormatEvaluator textEvaluator = new FormatEvaluator.FixedEvaluator(); - List textChunkSourceList = new ArrayList(); - List textTrackNameList = new ArrayList(); + List textChunkSourceList = new ArrayList<>(); + List textTrackNameList = new ArrayList<>(); for (int i = 0; i < period.adaptationSets.size(); i++) { AdaptationSet adaptationSet = period.adaptationSets.get(i); if (adaptationSet.type == AdaptationSet.TYPE_TEXT) { diff --git a/demo/src/main/java/com/google/android/exoplayer/demo/player/DemoPlayer.java b/demo/src/main/java/com/google/android/exoplayer/demo/player/DemoPlayer.java index 95ab7293ba..8b7c85c1ed 100644 --- a/demo/src/main/java/com/google/android/exoplayer/demo/player/DemoPlayer.java +++ b/demo/src/main/java/com/google/android/exoplayer/demo/player/DemoPlayer.java @@ -207,7 +207,7 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi player.addListener(this); playerControl = new PlayerControl(player); mainHandler = new Handler(); - listeners = new CopyOnWriteArrayList(); + listeners = new CopyOnWriteArrayList<>(); lastReportedPlaybackState = STATE_IDLE; rendererBuildingState = RENDERER_BUILDING_STATE_IDLE; selectedTracks = new int[RENDERER_COUNT]; diff --git a/demo/src/main/java/com/google/android/exoplayer/demo/player/HlsRendererBuilder.java b/demo/src/main/java/com/google/android/exoplayer/demo/player/HlsRendererBuilder.java index a2671554a3..43cf49924e 100644 --- a/demo/src/main/java/com/google/android/exoplayer/demo/player/HlsRendererBuilder.java +++ b/demo/src/main/java/com/google/android/exoplayer/demo/player/HlsRendererBuilder.java @@ -76,7 +76,7 @@ public class HlsRendererBuilder implements RendererBuilder, ManifestCallback playlistFetcher = new ManifestFetcher(url, + ManifestFetcher playlistFetcher = new ManifestFetcher<>(url, new DefaultUriDataSource(context, userAgent), parser); playlistFetcher.singleLoad(player.getMainHandler().getLooper(), this); } @@ -113,7 +113,7 @@ public class HlsRendererBuilder implements RendererBuilder, ManifestCallback> id3Renderer = - new MetadataTrackRenderer>(sampleSource, new Id3Parser(), + new MetadataTrackRenderer<>(sampleSource, new Id3Parser(), player.getId3MetadataRenderer(), mainHandler.getLooper()); Eia608TrackRenderer closedCaptionRenderer = new Eia608TrackRenderer(sampleSource, player, diff --git a/demo/src/main/java/com/google/android/exoplayer/demo/player/SmoothStreamingRendererBuilder.java b/demo/src/main/java/com/google/android/exoplayer/demo/player/SmoothStreamingRendererBuilder.java index 52c7956d14..9aa80915e4 100644 --- a/demo/src/main/java/com/google/android/exoplayer/demo/player/SmoothStreamingRendererBuilder.java +++ b/demo/src/main/java/com/google/android/exoplayer/demo/player/SmoothStreamingRendererBuilder.java @@ -97,7 +97,7 @@ public class SmoothStreamingRendererBuilder implements RendererBuilder, manifestUrl += "/Manifest"; } SmoothStreamingManifestParser parser = new SmoothStreamingManifestParser(); - manifestFetcher = new ManifestFetcher(manifestUrl, + manifestFetcher = new ManifestFetcher<>(manifestUrl, new DefaultHttpDataSource(userAgent, null), parser); manifestFetcher.singleLoad(player.getMainHandler().getLooper(), this); } diff --git a/library/src/main/java/com/google/android/exoplayer/DefaultLoadControl.java b/library/src/main/java/com/google/android/exoplayer/DefaultLoadControl.java index 4c9b9f15f5..b494e990fe 100644 --- a/library/src/main/java/com/google/android/exoplayer/DefaultLoadControl.java +++ b/library/src/main/java/com/google/android/exoplayer/DefaultLoadControl.java @@ -127,8 +127,8 @@ public class DefaultLoadControl implements LoadControl { this.allocator = allocator; this.eventHandler = eventHandler; this.eventListener = eventListener; - this.loaders = new ArrayList(); - this.loaderStates = new HashMap(); + this.loaders = new ArrayList<>(); + this.loaderStates = new HashMap<>(); this.lowWatermarkUs = lowWatermarkMs * 1000L; this.highWatermarkUs = highWatermarkMs * 1000L; this.lowBufferLoad = lowBufferLoad; diff --git a/library/src/main/java/com/google/android/exoplayer/ExoPlayerImpl.java b/library/src/main/java/com/google/android/exoplayer/ExoPlayerImpl.java index 3f5dc3cb0c..a378cd5652 100644 --- a/library/src/main/java/com/google/android/exoplayer/ExoPlayerImpl.java +++ b/library/src/main/java/com/google/android/exoplayer/ExoPlayerImpl.java @@ -55,7 +55,7 @@ import java.util.concurrent.CopyOnWriteArraySet; Log.i(TAG, "Init " + ExoPlayerLibraryInfo.VERSION); this.playWhenReady = false; this.playbackState = STATE_IDLE; - this.listeners = new CopyOnWriteArraySet(); + this.listeners = new CopyOnWriteArraySet<>(); this.rendererEnabledFlags = new boolean[rendererCount]; for (int i = 0; i < rendererEnabledFlags.length; i++) { rendererEnabledFlags[i] = true; diff --git a/library/src/main/java/com/google/android/exoplayer/ExoPlayerImplInternal.java b/library/src/main/java/com/google/android/exoplayer/ExoPlayerImplInternal.java index 2c87cd7133..df55a6f4bc 100644 --- a/library/src/main/java/com/google/android/exoplayer/ExoPlayerImplInternal.java +++ b/library/src/main/java/com/google/android/exoplayer/ExoPlayerImplInternal.java @@ -99,7 +99,7 @@ import java.util.List; this.bufferedPositionUs = TrackRenderer.UNKNOWN_TIME_US; mediaClock = new MediaClock(); - enabledRenderers = new ArrayList(rendererEnabledFlags.length); + enabledRenderers = new ArrayList<>(rendererEnabledFlags.length); // Note: The documentation for Process.THREAD_PRIORITY_AUDIO that states "Applications can // not normally change to this priority" is incorrect. internalPlaybackThread = new PriorityHandlerThread(getClass().getSimpleName() + ":Handler", diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java index 6f8dcbd6be..2d944ba4d3 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecTrackRenderer.java @@ -236,7 +236,7 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer { codecCounters = new CodecCounters(); sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_DISABLED); formatHolder = new MediaFormatHolder(); - decodeOnlyPresentationTimestamps = new ArrayList(); + decodeOnlyPresentationTimestamps = new ArrayList<>(); outputBufferInfo = new MediaCodec.BufferInfo(); codecReconfigurationState = RECONFIGURATION_STATE_NONE; codecReinitializationState = REINITIALIZATION_STATE_NONE; diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java index 5dbe3c5a11..e101d8c5c7 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java @@ -53,7 +53,7 @@ public class MediaCodecUtil { private static final String TAG = "MediaCodecUtil"; private static final HashMap> codecs = - new HashMap>(); + new HashMap<>(); /** * Get information about the decoder that will be used for a given mime type. diff --git a/library/src/main/java/com/google/android/exoplayer/MediaFormat.java b/library/src/main/java/com/google/android/exoplayer/MediaFormat.java index f98ea72f8a..bb266934f4 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaFormat.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaFormat.java @@ -121,7 +121,7 @@ public class MediaFormat { channelCount = getOptionalIntegerV16(format, android.media.MediaFormat.KEY_CHANNEL_COUNT); sampleRate = getOptionalIntegerV16(format, android.media.MediaFormat.KEY_SAMPLE_RATE); pixelWidthHeightRatio = getOptionalFloatV16(format, KEY_PIXEL_WIDTH_HEIGHT_RATIO); - initializationData = new ArrayList(); + initializationData = new ArrayList<>(); for (int i = 0; format.containsKey("csd-" + i); i++) { ByteBuffer buffer = format.getByteBuffer("csd-" + i); byte[] data = new byte[buffer.limit()]; diff --git a/library/src/main/java/com/google/android/exoplayer/chunk/ChunkSampleSource.java b/library/src/main/java/com/google/android/exoplayer/chunk/ChunkSampleSource.java index a023a31244..9287abea88 100644 --- a/library/src/main/java/com/google/android/exoplayer/chunk/ChunkSampleSource.java +++ b/library/src/main/java/com/google/android/exoplayer/chunk/ChunkSampleSource.java @@ -113,7 +113,7 @@ public class ChunkSampleSource implements SampleSource, Loader.Callback { this.eventSourceId = eventSourceId; this.minLoadableRetryCount = minLoadableRetryCount; currentLoadableHolder = new ChunkOperationHolder(); - mediaChunks = new LinkedList(); + mediaChunks = new LinkedList<>(); readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks); sampleQueue = new DefaultTrackOutput(loadControl.getAllocator()); state = STATE_UNPREPARED; diff --git a/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java b/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java index 03adf45819..0866382fc7 100644 --- a/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/chunk/VideoFormatSelectorUtil.java @@ -94,7 +94,7 @@ public final class VideoFormatSelectorUtil { String[] allowedContainerMimeTypes, boolean filterHdFormats, boolean orientationMayChange, int viewportWidth, int viewportHeight) throws DecoderQueryException { int maxVideoPixelsToRetain = Integer.MAX_VALUE; - ArrayList selectedIndexList = new ArrayList(); + ArrayList selectedIndexList = new ArrayList<>(); int maxDecodableFrameSize = MediaCodecUtil.maxH264DecodableFrameSize(); // First pass to filter out formats that individually fail to meet the selection criteria. diff --git a/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java b/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java index 0bee50176a..0f426773c5 100644 --- a/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java @@ -232,7 +232,7 @@ public class DashChunkSource implements ChunkSource { this.trackInfo = new TrackInfo(representations[0].format.mimeType, periodDurationUs); this.formats = new Format[representations.length]; - this.representationHolders = new HashMap(); + this.representationHolders = new HashMap<>(); int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < representations.length; i++) { diff --git a/library/src/main/java/com/google/android/exoplayer/dash/mpd/MediaPresentationDescriptionParser.java b/library/src/main/java/com/google/android/exoplayer/dash/mpd/MediaPresentationDescriptionParser.java index e509ffeefe..4e94a75d1a 100644 --- a/library/src/main/java/com/google/android/exoplayer/dash/mpd/MediaPresentationDescriptionParser.java +++ b/library/src/main/java/com/google/android/exoplayer/dash/mpd/MediaPresentationDescriptionParser.java @@ -112,7 +112,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler : -1; UtcTimingElement utcTiming = null; - List periods = new ArrayList(); + List periods = new ArrayList<>(); do { xpp.next(); if (isStartTag(xpp, "BaseURL")) { @@ -152,7 +152,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler long startMs = parseDuration(xpp, "start", 0); long durationMs = parseDuration(xpp, "duration", mpdDurationMs); SegmentBase segmentBase = null; - List adaptationSets = new ArrayList(); + List adaptationSets = new ArrayList<>(); do { xpp.next(); if (isStartTag(xpp, "BaseURL")) { @@ -188,7 +188,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler int id = -1; ContentProtectionsBuilder contentProtectionsBuilder = new ContentProtectionsBuilder(); - List representations = new ArrayList(); + List representations = new ArrayList<>(); do { xpp.next(); if (isStartTag(xpp, "BaseURL")) { @@ -432,7 +432,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler timeline = parseSegmentTimeline(xpp); } else if (isStartTag(xpp, "SegmentURL")) { if (segments == null) { - segments = new ArrayList(); + segments = new ArrayList<>(); } segments.add(parseSegmentUrl(xpp, baseUrl)); } @@ -499,7 +499,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler protected List parseSegmentTimeline(XmlPullParser xpp) throws XmlPullParserException, IOException { - List segmentTimeline = new ArrayList(); + List segmentTimeline = new ArrayList<>(); long elapsedTime = 0; do { xpp.next(); @@ -642,7 +642,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler */ public void addAdaptationSetProtection(ContentProtection contentProtection) { if (adaptationSetProtections == null) { - adaptationSetProtections = new ArrayList(); + adaptationSetProtections = new ArrayList<>(); } maybeAddContentProtection(adaptationSetProtections, contentProtection); } @@ -654,7 +654,7 @@ public class MediaPresentationDescriptionParser extends DefaultHandler */ public void addRepresentationProtection(ContentProtection contentProtection) { if (currentRepresentationProtections == null) { - currentRepresentationProtections = new ArrayList(); + currentRepresentationProtections = new ArrayList<>(); } maybeAddContentProtection(currentRepresentationProtections, contentProtection); } diff --git a/library/src/main/java/com/google/android/exoplayer/dash/mpd/UtcTimingElementResolver.java b/library/src/main/java/com/google/android/exoplayer/dash/mpd/UtcTimingElementResolver.java index c530bafe84..c275faebd7 100644 --- a/library/src/main/java/com/google/android/exoplayer/dash/mpd/UtcTimingElementResolver.java +++ b/library/src/main/java/com/google/android/exoplayer/dash/mpd/UtcTimingElementResolver.java @@ -124,7 +124,7 @@ public class UtcTimingElementResolver implements Loader.Callback { private void resolveHttp(UriLoadable.Parser parser) { singleUseLoader = new Loader("utctiming"); - singleUseLoadable = new UriLoadable(timingElement.value, uriDataSource, parser); + singleUseLoadable = new UriLoadable<>(timingElement.value, uriDataSource, parser); singleUseLoader.startLoading(singleUseLoadable, this); } diff --git a/library/src/main/java/com/google/android/exoplayer/drm/DrmInitData.java b/library/src/main/java/com/google/android/exoplayer/drm/DrmInitData.java index ae862d0bc9..7123d2d76d 100644 --- a/library/src/main/java/com/google/android/exoplayer/drm/DrmInitData.java +++ b/library/src/main/java/com/google/android/exoplayer/drm/DrmInitData.java @@ -52,7 +52,7 @@ public abstract class DrmInitData { public Mapped(String mimeType) { super(mimeType); - schemeData = new HashMap(); + schemeData = new HashMap<>(); } @Override diff --git a/library/src/main/java/com/google/android/exoplayer/drm/StreamingDrmSessionManager.java b/library/src/main/java/com/google/android/exoplayer/drm/StreamingDrmSessionManager.java index 387d5e42e8..3705e5bb25 100644 --- a/library/src/main/java/com/google/android/exoplayer/drm/StreamingDrmSessionManager.java +++ b/library/src/main/java/com/google/android/exoplayer/drm/StreamingDrmSessionManager.java @@ -139,7 +139,7 @@ public class StreamingDrmSessionManager implements DrmSessionManager { EventListener eventListener) throws UnsupportedSchemeException { HashMap optionalKeyRequestParameters; if (!TextUtils.isEmpty(customData)) { - optionalKeyRequestParameters = new HashMap(); + optionalKeyRequestParameters = new HashMap<>(); optionalKeyRequestParameters.put(PLAYREADY_CUSTOM_DATA_KEY, customData); } else { optionalKeyRequestParameters = null; diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorSampleSource.java b/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorSampleSource.java index b84401eb76..301889a740 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorSampleSource.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/ExtractorSampleSource.java @@ -130,7 +130,7 @@ public class ExtractorSampleSource implements SampleSource, ExtractorOutput, Loa this.remainingReleaseCount = downstreamRendererCount; this.requestedBufferSize = requestedBufferSize; this.minLoadableRetryCount = minLoadableRetryCount; - sampleQueues = new SparseArray(); + sampleQueues = new SparseArray<>(); allocator = new DefaultAllocator(BUFFER_FRAGMENT_LENGTH); pendingResetPositionUs = NO_RESET_PENDING; frameAccurateSeeking = true; diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/RollingSampleBuffer.java b/library/src/main/java/com/google/android/exoplayer/extractor/RollingSampleBuffer.java index a2926d275e..4cc229d847 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/RollingSampleBuffer.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/RollingSampleBuffer.java @@ -57,7 +57,7 @@ import java.util.concurrent.LinkedBlockingDeque; this.allocator = allocator; allocationLength = allocator.getIndividualAllocationLength(); infoQueue = new InfoQueue(); - dataQueue = new LinkedBlockingDeque(); + dataQueue = new LinkedBlockingDeque<>(); extrasHolder = new SampleExtrasHolder(); scratch = new ParsableByteArray(INITIAL_SCRATCH_SIZE); lastAllocationOffset = allocationLength; diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Atom.java b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Atom.java index e87f71f885..aa0861dc40 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Atom.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Atom.java @@ -122,8 +122,8 @@ import java.util.List; public ContainerAtom(int type, long endByteOffset) { super(type); - leafChildren = new ArrayList(); - containerChildren = new ArrayList(); + leafChildren = new ArrayList<>(); + containerChildren = new ArrayList<>(); this.endByteOffset = endByteOffset; } diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/AtomParsers.java b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/AtomParsers.java index 42c3f2e70e..13a45058ab 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/AtomParsers.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/AtomParsers.java @@ -396,7 +396,7 @@ import java.util.List; if (nalUnitLengthFieldLength == 3) { throw new IllegalStateException(); } - List initializationData = new ArrayList(); + List initializationData = new ArrayList<>(); // TODO: We should try and parse these using CodecSpecificDataUtil.parseSpsNalUnit, and // expose the AVC profile and level somewhere useful; Most likely in MediaFormat. int numSequenceParameterSets = parent.readUnsignedByte() & 0x1F; @@ -472,7 +472,7 @@ import java.util.List; int height = parent.readUnsignedShort(); parent.skipBytes(50); - List initializationData = new ArrayList(1); + List initializationData = new ArrayList<>(1); int childPosition = parent.getPosition(); while (childPosition - position < size) { parent.setPosition(childPosition); diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/FragmentedMp4Extractor.java b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/FragmentedMp4Extractor.java index 92543f3493..896d69cc30 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/FragmentedMp4Extractor.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/FragmentedMp4Extractor.java @@ -110,7 +110,7 @@ public final class FragmentedMp4Extractor implements Extractor { nalLength = new ParsableByteArray(4); encryptionSignalByte = new ParsableByteArray(1); extendedTypeScratch = new byte[16]; - containerAtoms = new Stack(); + containerAtoms = new Stack<>(); fragmentRun = new TrackFragment(); parserState = STATE_READING_ATOM_HEADER; } diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Mp4Extractor.java b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Mp4Extractor.java index 06e333d9b6..fb436790ef 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Mp4Extractor.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/mp4/Mp4Extractor.java @@ -71,7 +71,7 @@ public final class Mp4Extractor implements Extractor, SeekMap { public Mp4Extractor() { atomHeader = new ParsableByteArray(Atom.LONG_HEADER_SIZE); - containerAtoms = new Stack(); + containerAtoms = new Stack<>(); nalStartCode = new ParsableByteArray(H264Util.NAL_START_CODE); nalLength = new ParsableByteArray(4); parserState = STATE_READING_ATOM_HEADER; @@ -216,7 +216,7 @@ public final class Mp4Extractor implements Extractor, SeekMap { /** Updates the stored track metadata to reflect the contents of the specified moov atom. */ private void processMoovAtom(ContainerAtom moov) { - List tracks = new ArrayList(); + List tracks = new ArrayList<>(); long earliestSampleOffset = Long.MAX_VALUE; for (int i = 0; i < moov.containerChildren.size(); i++) { Atom.ContainerAtom atom = moov.containerChildren.get(i); diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/ts/H264Reader.java b/library/src/main/java/com/google/android/exoplayer/extractor/ts/H264Reader.java index 2b539d01e7..3178a4c7a0 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/ts/H264Reader.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/ts/H264Reader.java @@ -224,7 +224,7 @@ import java.util.List; byte[] ppsData = new byte[pps.nalLength]; System.arraycopy(sps.nalData, 0, spsData, 0, sps.nalLength); System.arraycopy(pps.nalData, 0, ppsData, 0, pps.nalLength); - List initializationData = new ArrayList(); + List initializationData = new ArrayList<>(); initializationData.add(spsData); initializationData.add(ppsData); diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/ts/TsExtractor.java b/library/src/main/java/com/google/android/exoplayer/extractor/ts/TsExtractor.java index 5a67127aee..a17dce7836 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/ts/TsExtractor.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/ts/TsExtractor.java @@ -85,7 +85,7 @@ public final class TsExtractor implements Extractor, SeekMap { tsPacketBuffer = new ParsableByteArray(TS_PACKET_SIZE); streamTypes = new SparseBooleanArray(); allowedPassthroughStreamTypes = getPassthroughStreamTypes(audioCapabilities); - tsPayloadReaders = new SparseArray(); + tsPayloadReaders = new SparseArray<>(); tsPayloadReaders.put(TS_PAT_PID, new PatReader()); lastPts = Long.MIN_VALUE; } diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/webm/DefaultEbmlReader.java b/library/src/main/java/com/google/android/exoplayer/extractor/webm/DefaultEbmlReader.java index f99c115ec9..83435f0e77 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/webm/DefaultEbmlReader.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/webm/DefaultEbmlReader.java @@ -37,7 +37,7 @@ import java.util.Stack; private static final int VALID_FLOAT64_ELEMENT_SIZE_BYTES = 8; private final byte[] scratch = new byte[8]; - private final Stack masterElementsStack = new Stack(); + private final Stack masterElementsStack = new Stack<>(); private final VarintReader varintReader = new VarintReader(); private EbmlReaderOutput output; diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/webm/WebmExtractor.java b/library/src/main/java/com/google/android/exoplayer/extractor/webm/WebmExtractor.java index f0ed882255..b37d51f00c 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/webm/WebmExtractor.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/webm/WebmExtractor.java @@ -665,7 +665,7 @@ public final class WebmExtractor implements Extractor { durationUs, audioTrackFormat.channelCount, audioTrackFormat.sampleRate, parseVorbisCodecPrivate()); } else if (audioTrackFormat != null && CODEC_ID_OPUS.equals(audioTrackFormat.codecId)) { - ArrayList opusInitializationData = new ArrayList(3); + ArrayList opusInitializationData = new ArrayList<>(3); opusInitializationData.add(audioTrackFormat.codecPrivate); opusInitializationData.add( ByteBuffer.allocate(Long.SIZE).putLong(audioTrackFormat.codecDelayNs).array()); @@ -757,7 +757,7 @@ public final class WebmExtractor implements Extractor { } byte[] vorbisBooks = new byte[codecPrivate.length - offset]; System.arraycopy(codecPrivate, offset, vorbisBooks, 0, codecPrivate.length - offset); - ArrayList initializationData = new ArrayList(2); + ArrayList initializationData = new ArrayList<>(2); initializationData.add(vorbisInfo); initializationData.add(vorbisBooks); return initializationData; diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java index 2873dfcad0..81eae6280a 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java @@ -516,7 +516,7 @@ public class HlsChunkSource { } private static Format[] buildEnabledFormats(List variants, int[] variantIndices) { - ArrayList enabledVariants = new ArrayList(); + ArrayList enabledVariants = new ArrayList<>(); if (variantIndices != null) { for (int i = 0; i < variantIndices.length; i++) { enabledVariants.add(variants.get(variantIndices[i])); @@ -526,8 +526,8 @@ public class HlsChunkSource { enabledVariants.addAll(variants); } - ArrayList definiteVideoVariants = new ArrayList(); - ArrayList definiteAudioOnlyVariants = new ArrayList(); + ArrayList definiteVideoVariants = new ArrayList<>(); + ArrayList definiteAudioOnlyVariants = new ArrayList<>(); for (int i = 0; i < enabledVariants.size(); i++) { Variant variant = enabledVariants.get(i); if (variant.format.height > 0 || variantHasExplicitCodecWithPrefix(variant, "avc")) { diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsExtractorWrapper.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsExtractorWrapper.java index f6c784a5e3..48308ac4b9 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsExtractorWrapper.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsExtractorWrapper.java @@ -60,7 +60,7 @@ public final class HlsExtractorWrapper implements ExtractorOutput { this.startTimeUs = startTimeUs; this.extractor = extractor; this.shouldSpliceIn = shouldSpliceIn; - sampleQueues = new SparseArray(); + sampleQueues = new SparseArray<>(); } /** diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsPlaylistParser.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsPlaylistParser.java index 3ac98a07af..78b9d06648 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsPlaylistParser.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsPlaylistParser.java @@ -106,7 +106,7 @@ public final class HlsPlaylistParser implements UriLoadable.Parser public HlsPlaylist parse(String connectionUrl, InputStream inputStream) throws IOException, ParserException { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - Queue extraLines = new LinkedList(); + Queue extraLines = new LinkedList<>(); String line; try { while ((line = reader.readLine()) != null) { @@ -137,8 +137,8 @@ public final class HlsPlaylistParser implements UriLoadable.Parser private static HlsMasterPlaylist parseMasterPlaylist(LineIterator iterator, String baseUri) throws IOException { - ArrayList variants = new ArrayList(); - ArrayList subtitles = new ArrayList(); + ArrayList variants = new ArrayList<>(); + ArrayList subtitles = new ArrayList<>(); int bitrate = 0; String codecs = null; int width = -1; @@ -202,7 +202,7 @@ public final class HlsPlaylistParser implements UriLoadable.Parser int targetDurationSecs = 0; int version = 1; // Default version == 1. boolean live = true; - List segments = new ArrayList(); + List segments = new ArrayList<>(); double segmentDurationSecs = 0.0; boolean segmentDiscontinuity = false; diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java index d78b23be67..d48f7b3040 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java @@ -120,7 +120,7 @@ public class HlsSampleSource implements SampleSource, Loader.Callback { this.eventListener = eventListener; this.eventSourceId = eventSourceId; this.pendingResetPositionUs = NO_RESET_PENDING; - extractors = new LinkedList(); + extractors = new LinkedList<>(); allocator = new DefaultAllocator(BUFFER_FRAGMENT_LENGTH); } diff --git a/library/src/main/java/com/google/android/exoplayer/metadata/Id3Parser.java b/library/src/main/java/com/google/android/exoplayer/metadata/Id3Parser.java index 836ec7f8f6..d2443d7d74 100644 --- a/library/src/main/java/com/google/android/exoplayer/metadata/Id3Parser.java +++ b/library/src/main/java/com/google/android/exoplayer/metadata/Id3Parser.java @@ -42,7 +42,7 @@ public class Id3Parser implements MetadataParser> { @Override public Map parse(byte[] data, int size) throws UnsupportedEncodingException, ParserException { - Map metadata = new HashMap(); + Map metadata = new HashMap<>(); ParsableByteArray id3Data = new ParsableByteArray(data, size); int id3Size = parseId3Header(id3Data); diff --git a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java index 14292cbb67..2527f1efb4 100644 --- a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java @@ -153,8 +153,8 @@ public class SmoothStreamingChunkSource implements ChunkSource { int trackCount = trackIndices != null ? trackIndices.length : streamElement.tracks.length; formats = new Format[trackCount]; - extractorWrappers = new SparseArray(); - mediaFormats = new SparseArray(); + extractorWrappers = new SparseArray<>(); + mediaFormats = new SparseArray<>(); int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < trackCount; i++) { diff --git a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingManifestParser.java b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingManifestParser.java index c2b4e567eb..15186ddd88 100644 --- a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingManifestParser.java +++ b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingManifestParser.java @@ -96,7 +96,7 @@ public class SmoothStreamingManifestParser implements UriLoadable.Parser>(); + this.normalizedAttributes = new LinkedList<>(); } public final Object parse(XmlPullParser xmlParser) throws XmlPullParserException, IOException, @@ -343,7 +343,7 @@ public class SmoothStreamingManifestParser implements UriLoadable.Parser(); + streamElements = new LinkedList<>(); } @Override @@ -473,7 +473,7 @@ public class SmoothStreamingManifestParser implements UriLoadable.Parser(); + tracks = new LinkedList<>(); } @Override @@ -539,7 +539,7 @@ public class SmoothStreamingManifestParser implements UriLoadable.Parser(); + startTimes = new ArrayList<>(); } private int parseType(XmlPullParser parser) throws ParserException { @@ -602,7 +602,7 @@ public class SmoothStreamingManifestParser implements UriLoadable.Parser(); + this.csd = new LinkedList<>(); } @Override diff --git a/library/src/main/java/com/google/android/exoplayer/text/SubtitleLayout.java b/library/src/main/java/com/google/android/exoplayer/text/SubtitleLayout.java index e82b8f6121..51fa6b56df 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/SubtitleLayout.java +++ b/library/src/main/java/com/google/android/exoplayer/text/SubtitleLayout.java @@ -49,7 +49,7 @@ public final class SubtitleLayout extends ViewGroup { public SubtitleLayout(Context context, AttributeSet attrs) { super(context, attrs); - subtitleViews = new ArrayList(); + subtitleViews = new ArrayList<>(); fontScale = 1; captionStyle = CaptionStyleCompat.DEFAULT; } diff --git a/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608Parser.java b/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608Parser.java index 4beede6eed..9fdf41ba08 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608Parser.java +++ b/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608Parser.java @@ -109,7 +109,7 @@ public class Eia608Parser { /* package */ Eia608Parser() { seiBuffer = new ParsableBitArray(); stringBuilder = new StringBuilder(); - captions = new ArrayList(); + captions = new ArrayList<>(); } /* package */ boolean canParse(String mimeType) { diff --git a/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608TrackRenderer.java b/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608TrackRenderer.java index d2f49d4038..85fffc046e 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608TrackRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608TrackRenderer.java @@ -88,7 +88,7 @@ public class Eia608TrackRenderer extends TrackRenderer implements Callback { formatHolder = new MediaFormatHolder(); sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_NORMAL); captionStringBuilder = new StringBuilder(); - pendingCaptionLists = new TreeSet(); + pendingCaptionLists = new TreeSet<>(); } @Override diff --git a/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlNode.java b/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlNode.java index 4ee1726b91..545c6fce47 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlNode.java +++ b/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlNode.java @@ -76,7 +76,7 @@ import java.util.TreeSet; public void addChild(TtmlNode child) { if (children == null) { - children = new ArrayList(); + children = new ArrayList<>(); } children.add(child); } @@ -93,7 +93,7 @@ import java.util.TreeSet; } public long[] getEventTimesUs() { - TreeSet eventTimeSet = new TreeSet(); + TreeSet eventTimeSet = new TreeSet<>(); getEventTimes(eventTimeSet, false); long[] eventTimes = new long[eventTimeSet.size()]; Iterator eventTimeIterator = eventTimeSet.iterator(); diff --git a/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlParser.java b/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlParser.java index 46fd26cd01..907a1d2e87 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlParser.java +++ b/library/src/main/java/com/google/android/exoplayer/text/ttml/TtmlParser.java @@ -105,7 +105,7 @@ public class TtmlParser implements SubtitleParser { XmlPullParser xmlParser = xmlParserFactory.newPullParser(); xmlParser.setInput(inputStream, inputEncoding); TtmlSubtitle ttmlSubtitle = null; - LinkedList nodeStack = new LinkedList(); + LinkedList nodeStack = new LinkedList<>(); int unsupportedNodeDepth = 0; int eventType = xmlParser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { diff --git a/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttParser.java b/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttParser.java index 41dd74e2b6..289dd9efc6 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttParser.java +++ b/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttParser.java @@ -81,7 +81,7 @@ public class WebvttParser implements SubtitleParser { @Override public WebvttSubtitle parse(InputStream inputStream, String inputEncoding, long startTimeUs) throws IOException { - ArrayList subtitles = new ArrayList(); + ArrayList subtitles = new ArrayList<>(); long mediaTimestampUs = startTimeUs; long mediaTimestampOffsetUs = 0; diff --git a/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitle.java b/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitle.java index e339782ab2..0ef8577a44 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitle.java +++ b/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitle.java @@ -100,7 +100,7 @@ public class WebvttSubtitle implements Subtitle { for (int i = 0; i < numCues; i++) { if ((cueTimesUs[i * 2] <= timeUs) && (timeUs < cueTimesUs[i * 2 + 1])) { if (list == null) { - list = new ArrayList(); + list = new ArrayList<>(); } WebvttCue cue = cues.get(i); if (cue.isNormalCue()) { diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java b/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java index 621c49b32a..e8b22b918f 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java @@ -61,7 +61,7 @@ public class DefaultHttpDataSource implements HttpDataSource { private static final String TAG = "HttpDataSource"; private static final Pattern CONTENT_RANGE_HEADER = Pattern.compile("^bytes (\\d+)-(\\d+)/(\\d+)$"); - private static final AtomicReference skipBufferReference = new AtomicReference(); + private static final AtomicReference skipBufferReference = new AtomicReference<>(); private final boolean allowCrossProtocolRedirects; private final int connectTimeoutMillis; @@ -141,7 +141,7 @@ public class DefaultHttpDataSource implements HttpDataSource { this.userAgent = Assertions.checkNotEmpty(userAgent); this.contentTypePredicate = contentTypePredicate; this.listener = listener; - this.requestProperties = new HashMap(); + this.requestProperties = new HashMap<>(); this.connectTimeoutMillis = connectTimeoutMillis; this.readTimeoutMillis = readTimeoutMillis; this.allowCrossProtocolRedirects = allowCrossProtocolRedirects; diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/NetworkLock.java b/library/src/main/java/com/google/android/exoplayer/upstream/NetworkLock.java index 2576fff1cd..b8c6aa1f65 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/NetworkLock.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/NetworkLock.java @@ -62,7 +62,7 @@ public final class NetworkLock { private int highestPriority; private NetworkLock() { - queue = new PriorityQueue(); + queue = new PriorityQueue<>(); highestPriority = Integer.MAX_VALUE; } diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/cache/LeastRecentlyUsedCacheEvictor.java b/library/src/main/java/com/google/android/exoplayer/upstream/cache/LeastRecentlyUsedCacheEvictor.java index 0c34154a59..577d7b3bbf 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/cache/LeastRecentlyUsedCacheEvictor.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/cache/LeastRecentlyUsedCacheEvictor.java @@ -30,7 +30,7 @@ public class LeastRecentlyUsedCacheEvictor implements CacheEvictor, Comparator(this); + this.leastRecentlyUsed = new TreeSet<>(this); } @Override diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/cache/SimpleCache.java b/library/src/main/java/com/google/android/exoplayer/upstream/cache/SimpleCache.java index 448645b648..ed2001b371 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/cache/SimpleCache.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/cache/SimpleCache.java @@ -50,9 +50,9 @@ public class SimpleCache implements Cache { public SimpleCache(File cacheDir, CacheEvictor evictor) { this.cacheDir = cacheDir; this.evictor = evictor; - this.lockedSpans = new HashMap(); - this.cachedSpans = new HashMap>(); - this.listeners = new HashMap>(); + this.lockedSpans = new HashMap<>(); + this.cachedSpans = new HashMap<>(); + this.listeners = new HashMap<>(); // Start cache initialization. final ConditionVariable conditionVariable = new ConditionVariable(); new Thread() { @@ -71,7 +71,7 @@ public class SimpleCache implements Cache { public synchronized NavigableSet addListener(String key, Listener listener) { ArrayList listenersForKey = listeners.get(key); if (listenersForKey == null) { - listenersForKey = new ArrayList(); + listenersForKey = new ArrayList<>(); listeners.put(key, listenersForKey); } listenersForKey.add(listener); @@ -92,12 +92,12 @@ public class SimpleCache implements Cache { @Override public synchronized NavigableSet getCachedSpans(String key) { TreeSet spansForKey = cachedSpans.get(key); - return spansForKey == null ? null : new TreeSet(spansForKey); + return spansForKey == null ? null : new TreeSet<>(spansForKey); } @Override public synchronized Set getKeys() { - return new HashSet(cachedSpans.keySet()); + return new HashSet<>(cachedSpans.keySet()); } @Override @@ -263,7 +263,7 @@ public class SimpleCache implements Cache { private void addSpan(CacheSpan span) { TreeSet spansForKey = cachedSpans.get(span.key); if (spansForKey == null) { - spansForKey = new TreeSet(); + spansForKey = new TreeSet<>(); cachedSpans.put(span.key, spansForKey); } spansForKey.add(span); diff --git a/library/src/main/java/com/google/android/exoplayer/util/CodecSpecificDataUtil.java b/library/src/main/java/com/google/android/exoplayer/util/CodecSpecificDataUtil.java index 019f7459c0..8a04f8fd27 100644 --- a/library/src/main/java/com/google/android/exoplayer/util/CodecSpecificDataUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/util/CodecSpecificDataUtil.java @@ -132,7 +132,7 @@ public final class CodecSpecificDataUtil { // data does not consist of NAL start code delimited units. return null; } - List starts = new ArrayList(); + List starts = new ArrayList<>(); int nalUnitIndex = 0; do { starts.add(nalUnitIndex); diff --git a/library/src/main/java/com/google/android/exoplayer/util/ManifestFetcher.java b/library/src/main/java/com/google/android/exoplayer/util/ManifestFetcher.java index a626ec20c3..d441a1f6c6 100644 --- a/library/src/main/java/com/google/android/exoplayer/util/ManifestFetcher.java +++ b/library/src/main/java/com/google/android/exoplayer/util/ManifestFetcher.java @@ -146,7 +146,7 @@ public class ManifestFetcher implements Loader.Callback { */ public void singleLoad(Looper callbackLooper, final ManifestCallback callback) { SingleFetchHelper fetchHelper = new SingleFetchHelper( - new UriLoadable(manifestUrl, uriDataSource, parser), callbackLooper, callback); + new UriLoadable<>(manifestUrl, uriDataSource, parser), callbackLooper, callback); fetchHelper.startLoading(); } @@ -219,7 +219,7 @@ public class ManifestFetcher implements Loader.Callback { loader = new Loader("manifestLoader"); } if (!loader.isLoading()) { - currentLoadable = new UriLoadable(manifestUrl, uriDataSource, parser); + currentLoadable = new UriLoadable<>(manifestUrl, uriDataSource, parser); loader.startLoading(currentLoadable, this); notifyManifestRefreshStarted(); } diff --git a/library/src/main/java/com/google/android/exoplayer/util/SlidingPercentile.java b/library/src/main/java/com/google/android/exoplayer/util/SlidingPercentile.java index 961f4d8935..77294f4562 100644 --- a/library/src/main/java/com/google/android/exoplayer/util/SlidingPercentile.java +++ b/library/src/main/java/com/google/android/exoplayer/util/SlidingPercentile.java @@ -67,7 +67,7 @@ public class SlidingPercentile { public SlidingPercentile(int maxWeight) { this.maxWeight = maxWeight; recycledSamples = new Sample[MAX_RECYCLED_SAMPLES]; - samples = new ArrayList(); + samples = new ArrayList<>(); currentSortOrder = SORT_ORDER_NONE; } diff --git a/library/src/test/java/com/google/android/exoplayer/MediaFormatTest.java b/library/src/test/java/com/google/android/exoplayer/MediaFormatTest.java index 6da52e50f9..62e4ce044f 100644 --- a/library/src/test/java/com/google/android/exoplayer/MediaFormatTest.java +++ b/library/src/test/java/com/google/android/exoplayer/MediaFormatTest.java @@ -37,7 +37,7 @@ public class MediaFormatTest extends TestCase { byte[] initData1 = new byte[] {1, 2, 3}; byte[] initData2 = new byte[] {4, 5, 6}; - List initData = new ArrayList(); + List initData = new ArrayList<>(); initData.add(initData1); initData.add(initData2); diff --git a/library/src/test/java/com/google/android/exoplayer/dash/DashChunkSourceTest.java b/library/src/test/java/com/google/android/exoplayer/dash/DashChunkSourceTest.java index cc155827dd..8270620985 100644 --- a/library/src/test/java/com/google/android/exoplayer/dash/DashChunkSourceTest.java +++ b/library/src/test/java/com/google/android/exoplayer/dash/DashChunkSourceTest.java @@ -383,7 +383,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { } private static MediaPresentationDescription generateVodMpd() { - List representations = new ArrayList(); + List representations = new ArrayList<>(); SingleSegmentBase segmentBase1 = new SingleSegmentBase("https://example.com/1.mp4"); Representation representation1 = @@ -399,10 +399,10 @@ public class DashChunkSourceTest extends InstrumentationTestCase { } private static MediaPresentationDescription generateLiveMpdWithTimeline(long startTime) { - List representations = new ArrayList(); + List representations = new ArrayList<>(); - List segmentTimeline = new ArrayList(); - List mediaSegments = new ArrayList(); + List segmentTimeline = new ArrayList<>(); + List mediaSegments = new ArrayList<>(); long byteStart = 0; for (int i = 0; i < LIVE_SEGMENT_COUNT; i++) { segmentTimeline.add(new SegmentTimelineElement(startTime, LIVE_SEGMENT_DURATION_MS)); @@ -423,7 +423,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { private static MediaPresentationDescription generateLiveMpdWithTemplate( boolean limitTimeshiftBuffer) { - List representations = new ArrayList(); + List representations = new ArrayList<>(); UrlTemplate initializationTemplate = null; UrlTemplate mediaTemplate = UrlTemplate.compile("$RepresentationID$/$Number$"); @@ -464,7 +464,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { long seekPositionMs, long seekRangeStartMs, long seekRangeEndMs, long chunkStartTimeMs, long chunkEndTimeMs) { DashChunkSource chunkSource = setupLiveEdgeTimelineTest(startTimeMs, liveEdgeLatencyMs); - List queue = new ArrayList(); + List queue = new ArrayList<>(); ChunkOperationHolder out = new ChunkOperationHolder(); chunkSource.getChunkOperation(queue, seekPositionMs * 1000, 0, out); TimeRange seekRange = chunkSource.getSeekRange(); @@ -482,7 +482,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { long chunkEndTimeMs, boolean limitTimeshiftBuffer) { DashChunkSource chunkSource = setupLiveEdgeTemplateTest(startTimeMs, liveEdgeLatencyMs, limitTimeshiftBuffer); - List queue = new ArrayList(); + List queue = new ArrayList<>(); ChunkOperationHolder out = new ChunkOperationHolder(); chunkSource.getChunkOperation(queue, seekPositionMs * 1000, 0, out); TimeRange seekRange = chunkSource.getSeekRange(); diff --git a/library/src/test/java/com/google/android/exoplayer/extractor/mp4/Mp4ExtractorTest.java b/library/src/test/java/com/google/android/exoplayer/extractor/mp4/Mp4ExtractorTest.java index 9e6c290bec..b53fb3649e 100644 --- a/library/src/test/java/com/google/android/exoplayer/extractor/mp4/Mp4ExtractorTest.java +++ b/library/src/test/java/com/google/android/exoplayer/extractor/mp4/Mp4ExtractorTest.java @@ -267,7 +267,7 @@ public class Mp4ExtractorTest extends TestCase { private static byte[] getStsc() { int samplesPerChunk = -1; - List samplesInChunkChangeIndices = new ArrayList(); + List samplesInChunkChangeIndices = new ArrayList<>(); for (int i = 0; i < SAMPLES_IN_CHUNK.length; i++) { if (SAMPLES_IN_CHUNK[i] != samplesPerChunk) { samplesInChunkChangeIndices.add(i); diff --git a/library/src/test/java/com/google/android/exoplayer/extractor/webm/DefaultEbmlReaderTest.java b/library/src/test/java/com/google/android/exoplayer/extractor/webm/DefaultEbmlReaderTest.java index 2642c71360..7225247290 100644 --- a/library/src/test/java/com/google/android/exoplayer/extractor/webm/DefaultEbmlReaderTest.java +++ b/library/src/test/java/com/google/android/exoplayer/extractor/webm/DefaultEbmlReaderTest.java @@ -173,7 +173,7 @@ public class DefaultEbmlReaderTest extends TestCase { private static final int ID_DURATION = 0x4489; private static final int ID_SIMPLE_BLOCK = 0xA3; - private final List events = new ArrayList(); + private final List events = new ArrayList<>(); @Override public int getElementType(int id) { diff --git a/library/src/test/java/com/google/android/exoplayer/testutil/FakeDataSource.java b/library/src/test/java/com/google/android/exoplayer/testutil/FakeDataSource.java index 1312ab2255..e128159ef9 100644 --- a/library/src/test/java/com/google/android/exoplayer/testutil/FakeDataSource.java +++ b/library/src/test/java/com/google/android/exoplayer/testutil/FakeDataSource.java @@ -169,7 +169,7 @@ public final class FakeDataSource implements DataSource { private boolean simulateUnknownLength; public Builder() { - segments = new ArrayList(); + segments = new ArrayList<>(); } /** diff --git a/library/src/test/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitleTest.java b/library/src/test/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitleTest.java index fc2ac13de7..0943b3a6f6 100644 --- a/library/src/test/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitleTest.java +++ b/library/src/test/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitleTest.java @@ -34,7 +34,7 @@ public class WebvttSubtitleTest extends TestCase { private WebvttSubtitle emptySubtitle = new WebvttSubtitle(new ArrayList(), 0); - private ArrayList simpleSubtitleCues = new ArrayList(); + private ArrayList simpleSubtitleCues = new ArrayList<>(); { WebvttCue firstCue = new WebvttCue(1000000, 2000000, FIRST_SUBTITLE_STRING); simpleSubtitleCues.add(firstCue); @@ -44,7 +44,7 @@ public class WebvttSubtitleTest extends TestCase { } private WebvttSubtitle simpleSubtitle = new WebvttSubtitle(simpleSubtitleCues, 0); - private ArrayList overlappingSubtitleCues = new ArrayList(); + private ArrayList overlappingSubtitleCues = new ArrayList<>(); { WebvttCue firstCue = new WebvttCue(1000000, 3000000, FIRST_SUBTITLE_STRING); overlappingSubtitleCues.add(firstCue); @@ -54,7 +54,8 @@ public class WebvttSubtitleTest extends TestCase { } private WebvttSubtitle overlappingSubtitle = new WebvttSubtitle(overlappingSubtitleCues, 0); - private ArrayList nestedSubtitleCues = new ArrayList(); + @SuppressWarnings("unused") + private ArrayList nestedSubtitleCues = new ArrayList<>(); { WebvttCue firstCue = new WebvttCue(1000000, 4000000, FIRST_SUBTITLE_STRING); nestedSubtitleCues.add(firstCue); diff --git a/library/src/test/java/com/google/android/exoplayer/util/UtilTest.java b/library/src/test/java/com/google/android/exoplayer/util/UtilTest.java index 351e93c339..00d4a60fe4 100644 --- a/library/src/test/java/com/google/android/exoplayer/util/UtilTest.java +++ b/library/src/test/java/com/google/android/exoplayer/util/UtilTest.java @@ -53,7 +53,7 @@ public class UtilTest extends TestCase { } public void testListBinarySearchFloor() { - List values = new ArrayList(); + List values = new ArrayList<>(); assertEquals(-1, Util.binarySearchFloor(values, 0, false, false)); assertEquals(0, Util.binarySearchFloor(values, 0, false, true)); @@ -107,7 +107,7 @@ public class UtilTest extends TestCase { } public void testListBinarySearchCeil() { - List values = new ArrayList(); + List values = new ArrayList<>(); assertEquals(0, Util.binarySearchCeil(values, 0, false, false)); assertEquals(-1, Util.binarySearchCeil(values, 0, false, true)); From ac54b4f696d65fe03533af6e7428c751ceb51b35 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 22 May 2015 21:45:13 +0100 Subject: [PATCH 5/5] Cleanup/Sync with internal tree --- .../demo/player/DashRendererBuilder.java | 3 +-- library/build.gradle | 10 +++++++++ .../android/exoplayer/MediaCodecUtil.java | 3 +-- .../exoplayer/dash/DashChunkSource.java | 21 ++++++++++++------- .../exoplayer/hls/HlsExtractorWrapper.java | 2 +- .../SmoothStreamingChunkSource.java | 21 +++++++++++-------- .../text/eia608/Eia608TrackRenderer.java | 7 +++++-- .../exoplayer/upstream/cache/CacheSpan.java | 3 ++- library/src/test/.classpath | 1 - library/src/test/AndroidManifest.xml | 7 +++++-- .../text/webvtt/WebvttSubtitleTest.java | 1 - library/src/test/project.properties | 1 + 12 files changed, 51 insertions(+), 29 deletions(-) diff --git a/demo/src/main/java/com/google/android/exoplayer/demo/player/DashRendererBuilder.java b/demo/src/main/java/com/google/android/exoplayer/demo/player/DashRendererBuilder.java index 29424e51a4..bfd203c5fa 100644 --- a/demo/src/main/java/com/google/android/exoplayer/demo/player/DashRendererBuilder.java +++ b/demo/src/main/java/com/google/android/exoplayer/demo/player/DashRendererBuilder.java @@ -131,8 +131,7 @@ public class DashRendererBuilder implements RendererBuilder, this.callback = callback; MediaPresentationDescriptionParser parser = new MediaPresentationDescriptionParser(); manifestDataSource = new DefaultUriDataSource(context, userAgent); - manifestFetcher = new ManifestFetcher<>(url, manifestDataSource, - parser); + manifestFetcher = new ManifestFetcher<>(url, manifestDataSource, parser); manifestFetcher.singleLoad(player.getMainHandler().getLooper(), this); } diff --git a/library/build.gradle b/library/build.gradle index 6673253faa..a6c2fa6414 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -38,9 +38,19 @@ android { lintOptions { abortOnError false } + + sourceSets { + androidTest { + assets.srcDirs = ['src/test/assets'] + java.srcDirs = ['src/test/java'] + } + } } dependencies { + androidTestCompile 'com.google.dexmaker:dexmaker:1.2' + androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' + androidTestCompile 'org.mockito:mockito-core:1.9.5' } android.libraryVariants.all { variant -> diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java index e101d8c5c7..c3f3fc85f2 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java @@ -52,8 +52,7 @@ public class MediaCodecUtil { private static final String TAG = "MediaCodecUtil"; - private static final HashMap> codecs = - new HashMap<>(); + private static final HashMap> codecs = new HashMap<>(); /** * Get information about the decoder that will be used for a given mime type. diff --git a/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java b/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java index 0f426773c5..8bf7199da8 100644 --- a/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/dash/DashChunkSource.java @@ -101,7 +101,7 @@ public class DashChunkSource implements ChunkSource { private final TrackInfo trackInfo; private final DataSource dataSource; - private final FormatEvaluator evaluator; + private final FormatEvaluator formatEvaluator; private final Evaluation evaluation; private final Clock systemClock; private final StringBuilder headerBuilder; @@ -117,13 +117,14 @@ public class DashChunkSource implements ChunkSource { private final int adaptationSetIndex; private final int[] representationIndices; - private DrmInitData drmInitData; private MediaPresentationDescription currentManifest; + private boolean finishedCurrentManifest; + + private DrmInitData drmInitData; private TimeRange seekRange; private long[] seekRangeValues; private int firstAvailableSegmentNum; private int lastAvailableSegmentNum; - private boolean finishedCurrentManifest; private boolean lastChunkWasInitialization; private IOException fatalError; @@ -214,7 +215,7 @@ public class DashChunkSource implements ChunkSource { this.adaptationSetIndex = adaptationSetIndex; this.representationIndices = representationIndices; this.dataSource = dataSource; - this.evaluator = formatEvaluator; + this.formatEvaluator = formatEvaluator; this.systemClock = systemClock; this.liveEdgeLatencyUs = liveEdgeLatencyUs; this.elapsedRealtimeOffsetUs = elapsedRealtimeOffsetUs; @@ -268,7 +269,8 @@ public class DashChunkSource implements ChunkSource { @Override public void enable() { - evaluator.enable(); + fatalError = null; + formatEvaluator.enable(); if (manifestFetcher != null) { manifestFetcher.enable(); } @@ -286,7 +288,7 @@ public class DashChunkSource implements ChunkSource { @Override public void disable(List queue) { - evaluator.disable(); + formatEvaluator.disable(); if (manifestFetcher != null) { manifestFetcher.disable(); } @@ -347,7 +349,7 @@ public class DashChunkSource implements ChunkSource { evaluation.queueSize = queue.size(); if (evaluation.format == null || !lastChunkWasInitialization) { - evaluator.evaluate(queue, playbackPositionUs, formats, evaluation); + formatEvaluator.evaluate(queue, playbackPositionUs, formats, evaluation); } Format selectedFormat = evaluation.format; out.queueSize = evaluation.queueSize; @@ -362,6 +364,9 @@ public class DashChunkSource implements ChunkSource { return; } + // In all cases where we return before instantiating a new chunk, we want out.chunk to be null. + out.chunk = null; + RepresentationHolder representationHolder = representationHolders.get(selectedFormat.id); Representation selectedRepresentation = representationHolder.representation; DashSegmentIndex segmentIndex = representationHolder.segmentIndex; @@ -426,7 +431,7 @@ public class DashChunkSource implements ChunkSource { } if (segmentNum == -1) { - out.chunk = null; + // We've reached the end of the stream. return; } diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsExtractorWrapper.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsExtractorWrapper.java index 48308ac4b9..b802d9fb9b 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsExtractorWrapper.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsExtractorWrapper.java @@ -70,7 +70,7 @@ public final class HlsExtractorWrapper implements ExtractorOutput { */ public void init(Allocator allocator) { this.allocator = allocator; - this.extractor.init(this); + extractor.init(this); } /** diff --git a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java index 2527f1efb4..c7a3f2e517 100644 --- a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingChunkSource.java @@ -59,14 +59,11 @@ public class SmoothStreamingChunkSource implements ChunkSource { private static final int MINIMUM_MANIFEST_REFRESH_PERIOD_MS = 5000; private static final int INITIALIZATION_VECTOR_SIZE = 8; - private final ManifestFetcher manifestFetcher; - private final int streamElementIndex; private final TrackInfo trackInfo; private final DataSource dataSource; private final FormatEvaluator formatEvaluator; private final Evaluation evaluation; private final long liveEdgeLatencyUs; - private final int maxWidth; private final int maxHeight; @@ -75,6 +72,9 @@ public class SmoothStreamingChunkSource implements ChunkSource { private final DrmInitData drmInitData; private final Format[] formats; + private final ManifestFetcher manifestFetcher; + private final int streamElementIndex; + private SmoothStreamingManifest currentManifest; private int currentManifestChunkOffset; private boolean finishedCurrentManifest; @@ -174,8 +174,8 @@ public class SmoothStreamingChunkSource implements ChunkSource { extractorWrappers.put(trackIndex, new ChunkExtractorWrapper(extractor)); mediaFormats.put(trackIndex, mediaFormat); } - this.maxHeight = maxHeight; this.maxWidth = maxWidth; + this.maxHeight = maxHeight; Arrays.sort(formats, new DecreasingBandwidthComparator()); } @@ -194,6 +194,7 @@ public class SmoothStreamingChunkSource implements ChunkSource { @Override public void enable() { fatalError = null; + formatEvaluator.enable(); if (manifestFetcher != null) { manifestFetcher.enable(); } @@ -201,6 +202,7 @@ public class SmoothStreamingChunkSource implements ChunkSource { @Override public void disable(List queue) { + formatEvaluator.disable(); if (manifestFetcher != null) { manifestFetcher.disable(); } @@ -248,14 +250,13 @@ public class SmoothStreamingChunkSource implements ChunkSource { out.chunk = null; return; } else if (out.queueSize == queue.size() && out.chunk != null - && out.chunk.format.equals(evaluation.format)) { + && out.chunk.format.equals(selectedFormat)) { // We already have a chunk, and the evaluation hasn't changed either the format or the size - // of the queue. Do nothing. + // of the queue. Leave unchanged. return; } - // In all cases where we return before instantiating a new chunk at the bottom of this method, - // we want out.chunk to be null. + // In all cases where we return before instantiating a new chunk, we want out.chunk to be null. out.chunk = null; StreamElement streamElement = getElement(currentManifest); @@ -290,7 +291,9 @@ public class SmoothStreamingChunkSource implements ChunkSource { // but continue to return the final chunk. finishedCurrentManifest = true; } - } else if (chunkIndex == -1) { + } + + if (chunkIndex == -1) { // We've reached the end of the stream. return; } diff --git a/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608TrackRenderer.java b/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608TrackRenderer.java index 85fffc046e..dbd5859c36 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608TrackRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer/text/eia608/Eia608TrackRenderer.java @@ -230,8 +230,11 @@ public class Eia608TrackRenderer extends TrackRenderer implements Callback { } private void invokeRendererInternal(String cueText) { - Cue cue = new Cue(cueText); - textRenderer.onCues(Collections.singletonList(cue)); + if (cueText == null) { + textRenderer.onCues(Collections.emptyList()); + } else { + textRenderer.onCues(Collections.singletonList(new Cue(cueText))); + } } private void maybeParsePendingSample() { diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/cache/CacheSpan.java b/library/src/main/java/com/google/android/exoplayer/upstream/cache/CacheSpan.java index 4d2ce48afb..ddde6b003c 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/cache/CacheSpan.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/cache/CacheSpan.java @@ -92,7 +92,8 @@ public final class CacheSpan implements Comparable { return new CacheSpan(key, position, file.length(), true, lastAccessTimestamp, file); } - private CacheSpan(String key, long position, long length, boolean isCached, + // Visible for testing. + CacheSpan(String key, long position, long length, boolean isCached, long lastAccessTimestamp, File file) { this.key = key; this.position = position; diff --git a/library/src/test/.classpath b/library/src/test/.classpath index 171a8c3ec8..be2dd156ff 100644 --- a/library/src/test/.classpath +++ b/library/src/test/.classpath @@ -5,6 +5,5 @@ - diff --git a/library/src/test/AndroidManifest.xml b/library/src/test/AndroidManifest.xml index 71bb5c3a66..c9c12992a1 100644 --- a/library/src/test/AndroidManifest.xml +++ b/library/src/test/AndroidManifest.xml @@ -15,16 +15,19 @@ --> - + diff --git a/library/src/test/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitleTest.java b/library/src/test/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitleTest.java index 0943b3a6f6..e8ce0b387c 100644 --- a/library/src/test/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitleTest.java +++ b/library/src/test/java/com/google/android/exoplayer/text/webvtt/WebvttSubtitleTest.java @@ -54,7 +54,6 @@ public class WebvttSubtitleTest extends TestCase { } private WebvttSubtitle overlappingSubtitle = new WebvttSubtitle(overlappingSubtitleCues, 0); - @SuppressWarnings("unused") private ArrayList nestedSubtitleCues = new ArrayList<>(); { WebvttCue firstCue = new WebvttCue(1000000, 4000000, FIRST_SUBTITLE_STRING); diff --git a/library/src/test/project.properties b/library/src/test/project.properties index 00cf62bacc..ef6eb035b6 100644 --- a/library/src/test/project.properties +++ b/library/src/test/project.properties @@ -12,3 +12,4 @@ # Project target. target=android-22 +android.library.reference.1=../main