mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make sampleQueue thread safe
This commit is contained in:
parent
6b123590ca
commit
eb1210d410
1 changed files with 9 additions and 7 deletions
|
|
@ -32,9 +32,9 @@ import android.util.SparseArray;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facilitates the extraction of data from the MPEG-2 TS container format.
|
* Facilitates the extraction of data from the MPEG-2 TS container format.
|
||||||
|
|
@ -144,10 +144,10 @@ public final class TsExtractor {
|
||||||
public boolean getSample(int track, SampleHolder out) {
|
public boolean getSample(int track, SampleHolder out) {
|
||||||
Assertions.checkState(prepared);
|
Assertions.checkState(prepared);
|
||||||
Queue<Sample> queue = pesPayloadReaders.valueAt(track).sampleQueue;
|
Queue<Sample> queue = pesPayloadReaders.valueAt(track).sampleQueue;
|
||||||
if (queue.isEmpty()) {
|
Sample sample = queue.poll();
|
||||||
|
if (sample == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Sample sample = queue.remove();
|
|
||||||
convert(sample, out);
|
convert(sample, out);
|
||||||
samplePool.recycle(sample);
|
samplePool.recycle(sample);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -473,14 +473,14 @@ public final class TsExtractor {
|
||||||
*/
|
*/
|
||||||
private abstract class PesPayloadReader {
|
private abstract class PesPayloadReader {
|
||||||
|
|
||||||
public final LinkedList<Sample> sampleQueue;
|
public final ConcurrentLinkedQueue<Sample> sampleQueue;
|
||||||
|
|
||||||
private MediaFormat mediaFormat;
|
private MediaFormat mediaFormat;
|
||||||
private boolean foundFirstKeyframe;
|
private boolean foundFirstKeyframe;
|
||||||
private boolean foundLastKeyframe;
|
private boolean foundLastKeyframe;
|
||||||
|
|
||||||
protected PesPayloadReader() {
|
protected PesPayloadReader() {
|
||||||
this.sampleQueue = new LinkedList<Sample>();
|
this.sampleQueue = new ConcurrentLinkedQueue<Sample>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMediaFormat() {
|
public boolean hasMediaFormat() {
|
||||||
|
|
@ -498,8 +498,10 @@ public final class TsExtractor {
|
||||||
public abstract void read(BitArray pesBuffer, int pesPayloadSize, long pesTimeUs);
|
public abstract void read(BitArray pesBuffer, int pesPayloadSize, long pesTimeUs);
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
while (!sampleQueue.isEmpty()) {
|
Sample toRecycle = sampleQueue.poll();
|
||||||
samplePool.recycle(sampleQueue.remove());
|
while (toRecycle != null) {
|
||||||
|
samplePool.recycle(toRecycle);
|
||||||
|
toRecycle = sampleQueue.poll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue