Q:mediacode解码出来的数据的是在GPU上还是在cpu上?
A:https://source.android.com/devices/graphics/arch-bq-gralloc
结论应该是在RAM上,Gralloc内存分配器会分配内存给CPU、GPU。在使用过程中,传输内存句柄。
Q:使用的格式是什么?
A:YUV420/NV12 都有
Q:Android客户端能提供的数据是什么?
A:ByteBuffer buffer = codec.getOutputBuffers()
https://developer.android.com/reference/java/nio/ByteBuffer
PS:这里提供的是Direct buffers
Q: Android客户端期望接受的数据类型是什么?
A:
public interface I420Buffer extends Buffer {
ByteBuffer getDataY();
ByteBuffer getDataU();
ByteBuffer getDataV();
int getStrideY();
int getStrideU();
int getStrideV();
}
Q: 步骤能提供的数据和期望接受的数据类型可有转化的demo?
A:可以参考下面的实现。
private VideoFrame.Buffer copyI420Buffer(
ByteBuffer buffer, int stride, int sliceHeight, int width, int height) {
if (stride % 2 != 0) {
throw new AssertionError("Stride is not divisible by two: " + stride);
}
final int chromaWidth = (width + 1) / 2;
final int chromaHeight = (sliceHeight % 2 == 0) ? (height + 1) / 2 : height / 2;
final int uvStride = stride / 2;
final int yPos = 0;
final int yEnd = yPos + stride * height;
final int uPos = yPos + stride * sliceHeight;
final int uEnd = uPos + uvStride * chromaHeight;
final int vPos = uPos + uvStride * sliceHeight / 2;
final int vEnd = vPos + uvStride * chromaHeight;
I420Buffer frameBuffer = allocateI420Buffer(width, height);
buffer.limit(yEnd);
buffer.position(yPos);
copyPlane(
buffer.slice(), stride, frameBuffer.getDataY(), frameBuffer.getStrideY(), width, height);
buffer.limit(uEnd);
buffer.position(uPos);
copyPlane(buffer.slice(), uvStride, frameBuffer.getDataU(), frameBuffer.getStrideU(),
chromaWidth, chromaHeight);
if (sliceHeight % 2 == 1) {
buffer.position(uPos + uvStride * (chromaHeight - 1)); // Seek to beginning of last full row.
ByteBuffer dataU = frameBuffer.getDataU();
dataU.position(frameBuffer.getStrideU() * chromaHeight); // Seek to beginning of last row.
dataU.put(buffer); // Copy the last row.
}
buffer.limit(vEnd);
buffer.position(vPos);
copyPlane(buffer.slice(), uvStride, frameBuffer.getDataV(), frameBuffer.getStrideV(),
chromaWidth, chromaHeight);
if (sliceHeight % 2 == 1) {
buffer.position(vPos + uvStride * (chromaHeight - 1)); // Seek to beginning of last full row.
ByteBuffer dataV = frameBuffer.getDataV();
dataV.position(frameBuffer.getStrideV() * chromaHeight); // Seek to beginning of last row.
dataV.put(buffer); // Copy the last row.
}
return frameBuffer;
}