172 lines
4.4 KiB
Java
172 lines
4.4 KiB
Java
package org.webrtc;
|
|
|
|
import androidx.annotation.Nullable;
|
|
import c.d.b.a.a;
|
|
import java.nio.ByteBuffer;
|
|
import java.util.concurrent.TimeUnit;
|
|
public class EncodedImage implements RefCounted {
|
|
public final ByteBuffer buffer;
|
|
public final long captureTimeMs;
|
|
public final long captureTimeNs;
|
|
public final int encodedHeight;
|
|
public final int encodedWidth;
|
|
public final FrameType frameType;
|
|
@Nullable
|
|
public final Integer qp;
|
|
private final RefCountDelegate refCountDelegate;
|
|
public final int rotation;
|
|
|
|
public static class Builder {
|
|
private ByteBuffer buffer;
|
|
private long captureTimeNs;
|
|
private int encodedHeight;
|
|
private int encodedWidth;
|
|
private FrameType frameType;
|
|
@Nullable
|
|
private Integer qp;
|
|
@Nullable
|
|
private Runnable releaseCallback;
|
|
private int rotation;
|
|
|
|
private Builder() {
|
|
}
|
|
|
|
public EncodedImage createEncodedImage() {
|
|
return new EncodedImage(this.buffer, this.releaseCallback, this.encodedWidth, this.encodedHeight, this.captureTimeNs, this.frameType, this.rotation, this.qp);
|
|
}
|
|
|
|
public Builder setBuffer(ByteBuffer byteBuffer, @Nullable Runnable runnable) {
|
|
this.buffer = byteBuffer;
|
|
this.releaseCallback = runnable;
|
|
return this;
|
|
}
|
|
|
|
@Deprecated
|
|
public Builder setCaptureTimeMs(long j) {
|
|
this.captureTimeNs = TimeUnit.MILLISECONDS.toNanos(j);
|
|
return this;
|
|
}
|
|
|
|
public Builder setCaptureTimeNs(long j) {
|
|
this.captureTimeNs = j;
|
|
return this;
|
|
}
|
|
|
|
public Builder setEncodedHeight(int i) {
|
|
this.encodedHeight = i;
|
|
return this;
|
|
}
|
|
|
|
public Builder setEncodedWidth(int i) {
|
|
this.encodedWidth = i;
|
|
return this;
|
|
}
|
|
|
|
public Builder setFrameType(FrameType frameType) {
|
|
this.frameType = frameType;
|
|
return this;
|
|
}
|
|
|
|
public Builder setQp(@Nullable Integer num) {
|
|
this.qp = num;
|
|
return this;
|
|
}
|
|
|
|
public Builder setRotation(int i) {
|
|
this.rotation = i;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public enum FrameType {
|
|
EmptyFrame(0),
|
|
VideoFrameKey(3),
|
|
VideoFrameDelta(4);
|
|
|
|
private final int nativeIndex;
|
|
|
|
private FrameType(int i) {
|
|
this.nativeIndex = i;
|
|
}
|
|
|
|
@CalledByNative("FrameType")
|
|
public static FrameType fromNativeIndex(int i) {
|
|
FrameType[] values = values();
|
|
for (int i2 = 0; i2 < 3; i2++) {
|
|
FrameType frameType = values[i2];
|
|
if (frameType.getNative() == i) {
|
|
return frameType;
|
|
}
|
|
}
|
|
throw new IllegalArgumentException(a.j("Unknown native frame type: ", i));
|
|
}
|
|
|
|
public int getNative() {
|
|
return this.nativeIndex;
|
|
}
|
|
}
|
|
|
|
@CalledByNative
|
|
private EncodedImage(ByteBuffer byteBuffer, @Nullable Runnable runnable, int i, int i2, long j, FrameType frameType, int i3, @Nullable Integer num) {
|
|
this.buffer = byteBuffer;
|
|
this.encodedWidth = i;
|
|
this.encodedHeight = i2;
|
|
this.captureTimeMs = TimeUnit.NANOSECONDS.toMillis(j);
|
|
this.captureTimeNs = j;
|
|
this.frameType = frameType;
|
|
this.rotation = i3;
|
|
this.qp = num;
|
|
this.refCountDelegate = new RefCountDelegate(runnable);
|
|
}
|
|
|
|
public static Builder builder() {
|
|
return new Builder();
|
|
}
|
|
|
|
@CalledByNative
|
|
private ByteBuffer getBuffer() {
|
|
return this.buffer;
|
|
}
|
|
|
|
@CalledByNative
|
|
private long getCaptureTimeNs() {
|
|
return this.captureTimeNs;
|
|
}
|
|
|
|
@CalledByNative
|
|
private int getEncodedHeight() {
|
|
return this.encodedHeight;
|
|
}
|
|
|
|
@CalledByNative
|
|
private int getEncodedWidth() {
|
|
return this.encodedWidth;
|
|
}
|
|
|
|
@CalledByNative
|
|
private int getFrameType() {
|
|
return this.frameType.getNative();
|
|
}
|
|
|
|
@Nullable
|
|
@CalledByNative
|
|
private Integer getQp() {
|
|
return this.qp;
|
|
}
|
|
|
|
@CalledByNative
|
|
private int getRotation() {
|
|
return this.rotation;
|
|
}
|
|
|
|
@Override // org.webrtc.RefCounted
|
|
public void release() {
|
|
this.refCountDelegate.release();
|
|
}
|
|
|
|
@Override // org.webrtc.RefCounted
|
|
public void retain() {
|
|
this.refCountDelegate.retain();
|
|
}
|
|
}
|