зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1308405 - p5: Memorize sample buffers in CodecProxy. r=snorp
Differential Revision: https://phabricator.services.mozilla.com/D24591 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c668fd7d06
Коммит
364290c746
|
@ -18,6 +18,8 @@ import org.mozilla.gecko.mozglue.JNIObject;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
|
@ -35,6 +37,9 @@ public final class CodecProxy {
|
|||
private Queue<Sample> mSurfaceOutputs = new ConcurrentLinkedQueue<>();
|
||||
private boolean mFlushed = true;
|
||||
|
||||
private Map<Integer, SampleBuffer> mInputBuffers = new HashMap<>();
|
||||
private Map<Integer, SampleBuffer> mOutputBuffers = new HashMap<>();
|
||||
|
||||
public interface Callbacks {
|
||||
void onInputStatus(long timestamp, boolean processed);
|
||||
void onOutputFormatChanged(MediaFormat format);
|
||||
|
@ -227,11 +232,7 @@ public final class CodecProxy {
|
|||
|
||||
try {
|
||||
Sample s = mRemote.dequeueInput(info.size);
|
||||
if (bytes != null && info.size > 0) {
|
||||
SampleBuffer buffer = mRemote.getInputBuffer(s.bufferId);
|
||||
buffer.readFromByteBuffer(bytes, info.offset, info.size);
|
||||
buffer.dispose();
|
||||
}
|
||||
fillInputBuffer(s.bufferId, bytes, info.offset, info.size);
|
||||
return sendInput(s.set(info, cryptoInfo));
|
||||
} catch (RemoteException | NullPointerException e) {
|
||||
Log.e(LOGTAG, "fail to dequeue input buffer", e);
|
||||
|
@ -243,6 +244,21 @@ public final class CodecProxy {
|
|||
return false;
|
||||
}
|
||||
|
||||
private void fillInputBuffer(final int bufferId, final ByteBuffer bytes,
|
||||
final int offset, final int size) throws RemoteException, IOException {
|
||||
if (bytes == null || size == 0) {
|
||||
Log.w(LOGTAG, "empty input");
|
||||
return;
|
||||
}
|
||||
|
||||
SampleBuffer buffer = mInputBuffers.get(bufferId);
|
||||
if (buffer == null) {
|
||||
buffer = mRemote.getInputBuffer(bufferId);
|
||||
mInputBuffers.put(bufferId, buffer);
|
||||
}
|
||||
buffer.readFromByteBuffer(bytes, offset, size);
|
||||
}
|
||||
|
||||
private boolean sendInput(final Sample sample) {
|
||||
try {
|
||||
mRemote.queueInput(sample);
|
||||
|
@ -308,6 +324,15 @@ public final class CodecProxy {
|
|||
mSurfaceOutputs.clear();
|
||||
}
|
||||
|
||||
for (SampleBuffer b : mInputBuffers.values()) {
|
||||
b.dispose();
|
||||
}
|
||||
mInputBuffers.clear();
|
||||
for (SampleBuffer b : mOutputBuffers.values()) {
|
||||
b.dispose();
|
||||
}
|
||||
mOutputBuffers.clear();
|
||||
|
||||
try {
|
||||
RemoteManager.getInstance().releaseCodec(this);
|
||||
} catch (DeadObjectException e) {
|
||||
|
@ -390,11 +415,16 @@ public final class CodecProxy {
|
|||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return mRemote.getOutputBuffer(id);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "cannot get buffer#" + id, e);
|
||||
return null;
|
||||
SampleBuffer buffer = mOutputBuffers.get(id);
|
||||
if (buffer == null) {
|
||||
try {
|
||||
buffer = mRemote.getOutputBuffer(id);
|
||||
mOutputBuffers.put(id, buffer);
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "cannot get buffer#" + id, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ public final class SampleBuffer implements Parcelable {
|
|||
}
|
||||
try {
|
||||
nativeReadFromDirectBuffer(src, mSharedMem.getPointer(), offset, size);
|
||||
mSharedMem.flush();
|
||||
} catch (NullPointerException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
|
|
@ -85,16 +85,17 @@ public class SharedMemory implements Parcelable {
|
|||
}
|
||||
|
||||
public void flush() {
|
||||
if (mBackedFile == null) {
|
||||
close();
|
||||
if (!mIsMapped) {
|
||||
return;
|
||||
}
|
||||
|
||||
unmap(mHandle, mSize);
|
||||
mHandle = 0;
|
||||
mIsMapped = false;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (mIsMapped) {
|
||||
unmap(mHandle, mSize);
|
||||
mHandle = 0;
|
||||
}
|
||||
flush();
|
||||
|
||||
if (mDescriptor != null) {
|
||||
try {
|
||||
|
|
Загрузка…
Ссылка в новой задаче