Search in sources :

Example 1 with SubMesh

use of com.google.android.exoplayer2.video.spherical.Projection.SubMesh in project ExoPlayer by google.

the class ProjectionDecoder method parseMesh.

@Nullable
private static Mesh parseMesh(ParsableByteArray input) {
    // Read the coordinates.
    int coordinateCount = input.readInt();
    if (coordinateCount > MAX_COORDINATE_COUNT) {
        return null;
    }
    float[] coordinates = new float[coordinateCount];
    for (int coordinate = 0; coordinate < coordinateCount; coordinate++) {
        coordinates[coordinate] = input.readFloat();
    }
    // Read the vertices.
    int vertexCount = input.readInt();
    if (vertexCount > MAX_VERTEX_COUNT) {
        return null;
    }
    final double log2 = Math.log(2.0);
    int coordinateCountSizeBits = (int) Math.ceil(Math.log(2.0 * coordinateCount) / log2);
    ParsableBitArray bitInput = new ParsableBitArray(input.getData());
    bitInput.setPosition(input.getPosition() * 8);
    float[] vertices = new float[vertexCount * 5];
    int[] coordinateIndices = new int[5];
    int vertexIndex = 0;
    for (int vertex = 0; vertex < vertexCount; vertex++) {
        for (int i = 0; i < 5; i++) {
            int coordinateIndex = coordinateIndices[i] + decodeZigZag(bitInput.readBits(coordinateCountSizeBits));
            if (coordinateIndex >= coordinateCount || coordinateIndex < 0) {
                return null;
            }
            vertices[vertexIndex++] = coordinates[coordinateIndex];
            coordinateIndices[i] = coordinateIndex;
        }
    }
    // Pad to next byte boundary
    bitInput.setPosition(((bitInput.getPosition() + 7) & ~7));
    int subMeshCount = bitInput.readBits(32);
    SubMesh[] subMeshes = new SubMesh[subMeshCount];
    for (int i = 0; i < subMeshCount; i++) {
        int textureId = bitInput.readBits(8);
        int drawMode = bitInput.readBits(8);
        int triangleIndexCount = bitInput.readBits(32);
        if (triangleIndexCount > MAX_TRIANGLE_INDICES) {
            return null;
        }
        int vertexCountSizeBits = (int) Math.ceil(Math.log(2.0 * vertexCount) / log2);
        int index = 0;
        float[] triangleVertices = new float[triangleIndexCount * 3];
        float[] textureCoords = new float[triangleIndexCount * 2];
        for (int counter = 0; counter < triangleIndexCount; counter++) {
            index += decodeZigZag(bitInput.readBits(vertexCountSizeBits));
            if (index < 0 || index >= vertexCount) {
                return null;
            }
            triangleVertices[counter * 3] = vertices[index * 5];
            triangleVertices[counter * 3 + 1] = vertices[index * 5 + 1];
            triangleVertices[counter * 3 + 2] = vertices[index * 5 + 2];
            textureCoords[counter * 2] = vertices[index * 5 + 3];
            textureCoords[counter * 2 + 1] = vertices[index * 5 + 4];
        }
        subMeshes[i] = new SubMesh(textureId, triangleVertices, textureCoords, drawMode);
    }
    return new Mesh(subMeshes);
}
Also used : SubMesh(com.google.android.exoplayer2.video.spherical.Projection.SubMesh) SubMesh(com.google.android.exoplayer2.video.spherical.Projection.SubMesh) Mesh(com.google.android.exoplayer2.video.spherical.Projection.Mesh) ParsableBitArray(com.google.android.exoplayer2.util.ParsableBitArray) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1 ParsableBitArray (com.google.android.exoplayer2.util.ParsableBitArray)1 Mesh (com.google.android.exoplayer2.video.spherical.Projection.Mesh)1 SubMesh (com.google.android.exoplayer2.video.spherical.Projection.SubMesh)1