Skip to content

Commit

Permalink
Bug 1308405 - p3: Use sample buffer class directly. r=snorp
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D24589

--HG--
rename : mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/SharedMemBuffer.java => mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/SampleBuffer.java
extra : moz-landing-system : lando
  • Loading branch information
jhlin committed Mar 28, 2019
1 parent 385270e commit 529784a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.os.Parcelable;

import org.mozilla.gecko.annotation.WrapForJNI;
import org.mozilla.gecko.mozglue.SharedMemory;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand All @@ -25,14 +24,7 @@ public final class Sample implements Parcelable {
EOS.info.set(0, 0, Long.MIN_VALUE, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
}

public interface Buffer extends Parcelable {
int capacity();
void readFromByteBuffer(ByteBuffer src, int offset, int size) throws IOException;
void writeToByteBuffer(ByteBuffer dest, int offset, int size) throws IOException;
void dispose();
}

public Buffer buffer;
public SampleBuffer buffer;
@WrapForJNI
public BufferInfo info = new BufferInfo();
public CryptoInfo cryptoInfo;
Expand All @@ -44,7 +36,7 @@ public interface Buffer extends Parcelable {
private static int sPoolSize = 1;

public Sample() { }
public Sample(Buffer bytes) {
public Sample(SampleBuffer bytes) {
buffer = bytes;
}

Expand Down Expand Up @@ -160,7 +152,7 @@ private synchronized Sample obtainSample(final Parcel in) {
} else {
s = new Sample();
}
s.buffer = in.readParcelable(Sample.class.getClassLoader());
s.buffer = in.readParcelable(SampleBuffer.class.getClassLoader());
s.readInfo(in);
s.readCrypto(in);
return s;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.media;

import android.os.Parcel;
import android.os.Parcelable;

import org.mozilla.gecko.mozglue.SharedMemory;
import org.mozilla.gecko.media.Sample;

import java.io.IOException;
import java.nio.ByteBuffer;

public final class SharedMemBuffer implements Sample.Buffer {
public final class SampleBuffer implements Parcelable {
private SharedMemory mSharedMem;

/* package */
public SharedMemBuffer(final SharedMemory sharedMem) {
public SampleBuffer(final SharedMemory sharedMem) {
mSharedMem = sharedMem;
}

protected SharedMemBuffer(final Parcel in) {
mSharedMem = in.readParcelable(Sample.class.getClassLoader());
protected SampleBuffer(final Parcel in) {
mSharedMem = in.readParcelable(SampleBuffer.class.getClassLoader());
}

@Override
Expand All @@ -33,24 +34,22 @@ public int describeContents() {
return 0;
}

public static final Creator<SharedMemBuffer> CREATOR = new Creator<SharedMemBuffer>() {
public static final Creator<SampleBuffer> CREATOR = new Creator<SampleBuffer>() {
@Override
public SharedMemBuffer createFromParcel(final Parcel in) {
return new SharedMemBuffer(in);
public SampleBuffer createFromParcel(final Parcel in) {
return new SampleBuffer(in);
}

@Override
public SharedMemBuffer[] newArray(final int size) {
return new SharedMemBuffer[size];
public SampleBuffer[] newArray(final int size) {
return new SampleBuffer[size];
}
};

@Override
public int capacity() {
return mSharedMem != null ? mSharedMem.getSize() : 0;
}

@Override
public void readFromByteBuffer(final ByteBuffer src, final int offset, final int size)
throws IOException {
if (!src.isDirect()) {
Expand All @@ -65,7 +64,6 @@ public void readFromByteBuffer(final ByteBuffer src, final int offset, final int

private native static void nativeReadFromDirectBuffer(ByteBuffer src, long dest, int offset, int size);

@Override
public void writeToByteBuffer(final ByteBuffer dest, final int offset, final int size)
throws IOException {
if (!dest.isDirect()) {
Expand All @@ -80,7 +78,6 @@ public void writeToByteBuffer(final ByteBuffer dest, final int offset, final int

private native static void nativeWriteToDirectBuffer(long src, ByteBuffer dest, int offset, int size);

@Override
public void dispose() {
if (mSharedMem != null) {
mSharedMem.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private Sample allocateSharedMemorySample(final int size) {
throw new UnsupportedOperationException(e);
}

return new Sample(new SharedMemBuffer(shm));
return new Sample(new SampleBuffer(shm));
}

private synchronized void recycle(final Sample recycled) {
Expand Down
4 changes: 2 additions & 2 deletions mozglue/android/SharedMemNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern "C" {

JNIEXPORT
void JNICALL
Java_org_mozilla_gecko_media_SharedMemBuffer_nativeReadFromDirectBuffer(
Java_org_mozilla_gecko_media_SampleBuffer_nativeReadFromDirectBuffer(
JNIEnv* jenv, jclass, jobject src, jlong dest, jint offset, jint size) {
uint8_t* from = static_cast<uint8_t*>(jenv->GetDirectBufferAddress(src));
if (from == nullptr) {
Expand All @@ -36,7 +36,7 @@ Java_org_mozilla_gecko_media_SharedMemBuffer_nativeReadFromDirectBuffer(

JNIEXPORT
void JNICALL
Java_org_mozilla_gecko_media_SharedMemBuffer_nativeWriteToDirectBuffer(
Java_org_mozilla_gecko_media_SampleBuffer_nativeWriteToDirectBuffer(
JNIEnv* jenv, jclass, jlong src, jobject dest, jint offset, jint size) {
uint8_t* from = reinterpret_cast<uint8_t*>(src);
if (from == nullptr) {
Expand Down

0 comments on commit 529784a

Please sign in to comment.