mirror of
https://github.com/samsonjs/media.git
synced 2026-04-10 12:05:47 +00:00
Misc performance/correctness tweaks.
This commit is contained in:
parent
f1fe109bfa
commit
3a9d08edb5
9 changed files with 58 additions and 41 deletions
|
|
@ -53,6 +53,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||
@SuppressLint("HandlerLeak")
|
||||
public ExoPlayerImpl(int rendererCount, int minBufferMs, int minRebufferMs) {
|
||||
Log.i(TAG, "Init " + ExoPlayerLibraryInfo.VERSION);
|
||||
this.playWhenReady = false;
|
||||
this.playbackState = STATE_IDLE;
|
||||
this.listeners = new CopyOnWriteArraySet<Listener>();
|
||||
this.rendererEnabledFlags = new boolean[rendererCount];
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ public class MediaFormat {
|
|||
public int hashCode() {
|
||||
if (hashCode == 0) {
|
||||
int result = 17;
|
||||
result = 31 * result + mimeType == null ? 0 : mimeType.hashCode();
|
||||
result = 31 * result + (mimeType == null ? 0 : mimeType.hashCode());
|
||||
result = 31 * result + maxInputSize;
|
||||
result = 31 * result + width;
|
||||
result = 31 * result + height;
|
||||
|
|
|
|||
|
|
@ -80,9 +80,11 @@ import java.util.ArrayList;
|
|||
public final static class ContainerAtom extends Atom {
|
||||
|
||||
public final ArrayList<Atom> children;
|
||||
public final int endByteOffset;
|
||||
|
||||
public ContainerAtom(int type) {
|
||||
public ContainerAtom(int type, int endByteOffset) {
|
||||
super(type);
|
||||
this.endByteOffset = endByteOffset;
|
||||
children = new ArrayList<Atom>();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -139,7 +139,6 @@ public final class FragmentedMp4Extractor implements Extractor {
|
|||
private final ParsableByteArray atomHeader;
|
||||
private final byte[] extendedTypeScratch;
|
||||
private final Stack<ContainerAtom> containerAtoms;
|
||||
private final Stack<Integer> containerAtomEndPoints;
|
||||
private final TrackFragment fragmentRun;
|
||||
|
||||
private int parserState;
|
||||
|
|
@ -174,7 +173,6 @@ public final class FragmentedMp4Extractor implements Extractor {
|
|||
atomHeader = new ParsableByteArray(ATOM_HEADER_SIZE);
|
||||
extendedTypeScratch = new byte[16];
|
||||
containerAtoms = new Stack<ContainerAtom>();
|
||||
containerAtomEndPoints = new Stack<Integer>();
|
||||
fragmentRun = new TrackFragment();
|
||||
psshData = new HashMap<UUID, byte[]>();
|
||||
}
|
||||
|
|
@ -258,7 +256,6 @@ public final class FragmentedMp4Extractor implements Extractor {
|
|||
}
|
||||
}
|
||||
containerAtoms.clear();
|
||||
containerAtomEndPoints.clear();
|
||||
enterState(STATE_READING_ATOM_HEADER);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -267,7 +264,7 @@ public final class FragmentedMp4Extractor implements Extractor {
|
|||
switch (state) {
|
||||
case STATE_READING_ATOM_HEADER:
|
||||
atomBytesRead = 0;
|
||||
if (containerAtomEndPoints.isEmpty()) {
|
||||
if (containerAtoms.isEmpty()) {
|
||||
rootAtomBytesRead = 0;
|
||||
}
|
||||
break;
|
||||
|
|
@ -300,11 +297,12 @@ public final class FragmentedMp4Extractor implements Extractor {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (PARSED_ATOMS.contains(atomType)) {
|
||||
if (CONTAINER_TYPES.contains(atomType)) {
|
||||
Integer atomTypeInteger = atomType; // Avoids boxing atomType twice.
|
||||
if (PARSED_ATOMS.contains(atomTypeInteger)) {
|
||||
if (CONTAINER_TYPES.contains(atomTypeInteger)) {
|
||||
enterState(STATE_READING_ATOM_HEADER);
|
||||
containerAtoms.add(new ContainerAtom(atomType));
|
||||
containerAtomEndPoints.add(rootAtomBytesRead + atomSize - ATOM_HEADER_SIZE);
|
||||
containerAtoms.add(new ContainerAtom(atomType,
|
||||
rootAtomBytesRead + atomSize - ATOM_HEADER_SIZE));
|
||||
} else {
|
||||
atomData = new ParsableByteArray(atomSize);
|
||||
System.arraycopy(atomHeader.data, 0, atomData.data, 0, ATOM_HEADER_SIZE);
|
||||
|
|
@ -339,9 +337,7 @@ public final class FragmentedMp4Extractor implements Extractor {
|
|||
results |= onLeafAtomRead(new LeafAtom(atomType, atomData));
|
||||
}
|
||||
|
||||
while (!containerAtomEndPoints.isEmpty()
|
||||
&& containerAtomEndPoints.peek() == rootAtomBytesRead) {
|
||||
containerAtomEndPoints.pop();
|
||||
while (!containerAtoms.isEmpty() && containerAtoms.peek().endByteOffset == rootAtomBytesRead) {
|
||||
results |= onContainerAtomRead(containerAtoms.pop());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -343,8 +343,8 @@ public class SmoothStreamingChunkSource implements ChunkSource {
|
|||
TrackElement trackElement = streamElement.tracks[trackIndex];
|
||||
String mimeType = trackElement.mimeType;
|
||||
if (streamElement.type == StreamElement.TYPE_VIDEO) {
|
||||
MediaFormat format = MediaFormat.createVideoFormat(mimeType, -1, trackElement.maxWidth,
|
||||
trackElement.maxHeight, Arrays.asList(trackElement.csd));
|
||||
MediaFormat format = MediaFormat.createVideoFormat(mimeType, MediaFormat.NO_VALUE,
|
||||
trackElement.maxWidth, trackElement.maxHeight, Arrays.asList(trackElement.csd));
|
||||
format.setMaxVideoDimensions(streamElement.maxWidth, streamElement.maxHeight);
|
||||
return format;
|
||||
} else if (streamElement.type == StreamElement.TYPE_AUDIO) {
|
||||
|
|
@ -355,8 +355,8 @@ public class SmoothStreamingChunkSource implements ChunkSource {
|
|||
csd = Collections.singletonList(CodecSpecificDataUtil.buildAudioSpecificConfig(
|
||||
trackElement.sampleRate, trackElement.numChannels));
|
||||
}
|
||||
MediaFormat format = MediaFormat.createAudioFormat(mimeType, -1, trackElement.numChannels,
|
||||
trackElement.sampleRate, csd);
|
||||
MediaFormat format = MediaFormat.createAudioFormat(mimeType, MediaFormat.NO_VALUE,
|
||||
trackElement.numChannels, trackElement.sampleRate, csd);
|
||||
return format;
|
||||
} else if (streamElement.type == StreamElement.TYPE_TEXT) {
|
||||
return MediaFormat.createFormatForMimeType(streamElement.tracks[trackIndex].mimeType);
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ public class SmoothStreamingManifest {
|
|||
Assertions.checkState(chunkIndex < chunkStartTimes.size());
|
||||
String chunkUrl = chunkTemplate
|
||||
.replace(URL_PLACEHOLDER_BITRATE, Integer.toString(tracks[track].bitrate))
|
||||
.replace(URL_PLACEHOLDER_START_TIME, Long.toString(chunkStartTimes.get(chunkIndex)));
|
||||
.replace(URL_PLACEHOLDER_START_TIME, chunkStartTimes.get(chunkIndex).toString());
|
||||
return Util.getMergedUri(baseUri, chunkUrl);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class SubtitleView extends View {
|
|||
|
||||
Resources resources = getContext().getResources();
|
||||
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
|
||||
int twoDpInPx = Math.round((2 * displayMetrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT);
|
||||
int twoDpInPx = Math.round((2f * displayMetrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT);
|
||||
cornerRadius = twoDpInPx;
|
||||
outlineWidth = twoDpInPx;
|
||||
shadowRadius = twoDpInPx;
|
||||
|
|
|
|||
|
|
@ -53,10 +53,17 @@ public final class NetworkLock {
|
|||
*/
|
||||
public static final int DOWNLOAD_PRIORITY = 10;
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
/** Guarded by {@link #lock}. */
|
||||
private final PriorityQueue<Integer> queue;
|
||||
|
||||
/** Guarded by {@link #lock}. */
|
||||
private int highestPriority;
|
||||
|
||||
private NetworkLock() {
|
||||
queue = new PriorityQueue<Integer>();
|
||||
highestPriority = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,9 +71,11 @@ public final class NetworkLock {
|
|||
*
|
||||
* @param priority The priority of the task that would like to proceed.
|
||||
*/
|
||||
public synchronized void proceed(int priority) throws InterruptedException {
|
||||
while (queue.peek() < priority) {
|
||||
wait();
|
||||
public void proceed(int priority) throws InterruptedException {
|
||||
synchronized (lock) {
|
||||
while (highestPriority < priority) {
|
||||
lock.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,8 +85,10 @@ public final class NetworkLock {
|
|||
* @param priority The priority of the task that would like to proceed.
|
||||
* @return Whether the passed priority is allowed to proceed.
|
||||
*/
|
||||
public synchronized boolean proceedNonBlocking(int priority) {
|
||||
return queue.peek() >= priority;
|
||||
public boolean proceedNonBlocking(int priority) {
|
||||
synchronized (lock) {
|
||||
return highestPriority >= priority;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,10 +97,11 @@ public final class NetworkLock {
|
|||
* @param priority The priority of the task that would like to proceed.
|
||||
* @throws PriorityTooLowException If the passed priority is not high enough to proceed.
|
||||
*/
|
||||
public synchronized void proceedOrThrow(int priority) throws PriorityTooLowException {
|
||||
int highestPriority = queue.peek();
|
||||
if (highestPriority < priority) {
|
||||
throw new PriorityTooLowException(priority, highestPriority);
|
||||
public void proceedOrThrow(int priority) throws PriorityTooLowException {
|
||||
synchronized (lock) {
|
||||
if (highestPriority < priority) {
|
||||
throw new PriorityTooLowException(priority, highestPriority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -100,8 +112,11 @@ public final class NetworkLock {
|
|||
*
|
||||
* @param priority The priority of the task.
|
||||
*/
|
||||
public synchronized void add(int priority) {
|
||||
queue.add(priority);
|
||||
public void add(int priority) {
|
||||
synchronized (lock) {
|
||||
queue.add(priority);
|
||||
highestPriority = Math.min(highestPriority, priority);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -109,9 +124,12 @@ public final class NetworkLock {
|
|||
*
|
||||
* @param priority The priority of the task.
|
||||
*/
|
||||
public synchronized void remove(int priority) {
|
||||
queue.remove(priority);
|
||||
notifyAll();
|
||||
public void remove(int priority) {
|
||||
synchronized (lock) {
|
||||
queue.remove(priority);
|
||||
highestPriority = queue.isEmpty() ? Integer.MAX_VALUE : queue.peek();
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -317,8 +317,8 @@ public final class Util {
|
|||
} else if (matcher.group(9).equalsIgnoreCase("Z")) {
|
||||
timezoneShift = 0;
|
||||
} else {
|
||||
timezoneShift = ((Integer.valueOf(matcher.group(12)) * 60
|
||||
+ Integer.valueOf(matcher.group(13))));
|
||||
timezoneShift = ((Integer.parseInt(matcher.group(12)) * 60
|
||||
+ Integer.parseInt(matcher.group(13))));
|
||||
if (matcher.group(11).equals("-")) {
|
||||
timezoneShift *= -1;
|
||||
}
|
||||
|
|
@ -328,12 +328,12 @@ public final class Util {
|
|||
|
||||
dateTime.clear();
|
||||
// Note: The month value is 0-based, hence the -1 on group(2)
|
||||
dateTime.set(Integer.valueOf(matcher.group(1)),
|
||||
Integer.valueOf(matcher.group(2)) - 1,
|
||||
Integer.valueOf(matcher.group(3)),
|
||||
Integer.valueOf(matcher.group(4)),
|
||||
Integer.valueOf(matcher.group(5)),
|
||||
Integer.valueOf(matcher.group(6)));
|
||||
dateTime.set(Integer.parseInt(matcher.group(1)),
|
||||
Integer.parseInt(matcher.group(2)) - 1,
|
||||
Integer.parseInt(matcher.group(3)),
|
||||
Integer.parseInt(matcher.group(4)),
|
||||
Integer.parseInt(matcher.group(5)),
|
||||
Integer.parseInt(matcher.group(6)));
|
||||
if (!TextUtils.isEmpty(matcher.group(8))) {
|
||||
final BigDecimal bd = new BigDecimal("0." + matcher.group(8));
|
||||
// we care only for milliseconds, so movePointRight(3)
|
||||
|
|
|
|||
Loading…
Reference in a new issue